Menu

Question about GnuCOBOL 'ACCEPT' of Numeric data

GnuCOBOL
2021-09-30
2021-10-02
  • Steve Millman

    Steve Millman - 2021-09-30

    Realized today that when trying to ACCEPT an amount field in GnuCobol 3.12b, that field is always read from the Left to the Right (like a Alphanumeric field).. despite the field being defined as Numeric and/or Numeric Edited.

    Microsoft COBOL handled this just fine. Is there a trick to tweaking the compiler options or is this one of those silly things we have to code around?

    Thank you,

    Steve

     
    • Simon Sobisch

      Simon Sobisch - 2021-09-30

      In general: a "plain" ACCEPT only works alphanumeric "as keyed into the terminal".
      As soon as you get to "extended" screen io (either by including a SCREEN SECTION or by issuing DISPLAY SPACE EOS) GnuCOBOL does some "magic handling".

      It is intended to then accept numeric and numeric-edited fields in a reasonable way but even in the newest versions this is something "not fully implemented".

      If you only want to use GnuCOBOL - better to "code around" this would be fixing this in GnuCOBOL (libcob/screenio.c) or get someone to do this; if you need your code to be portable to other COBOL environments - accept only PIC X data and adjust this yourself as mentioned in [8e19fd9345] and other posts (search function should help with ways to "code around").

       

      Related

      Discussion: 8e19fd9345

    • Vincent (Bryan) Coen

      On 30/09/2021 01:33, Steve Millman wrote:

      Realized today that when trying to ACCEPT an amount field in GnuCobol
      3.12b, that field is always read from the Left to the Right (like a
      Alphanumeric field).. despite the field being defined as Numeric
      and/or Numeric Edited.

      Microsoft COBOL handled this just fine. Is there a trick to tweaking
      the compiler options or is this one of those silly things we have to
      code around?

      Thank you,

      Steve

      You have to code around it and yes most annoying as MF does it
      automatically and has done since CIS  Cobol was released in the 70's.

       
      👍
      1
      • Steve Millman

        Steve Millman - 2021-10-01

        Solved.. Coded around it.. Had to switch my screen to PIC X logic and rebuild my numeric fields, as Simon and Bryan alluded. Thanks for the feedback, guys.

         
  • Eugenio Di Lorenzo

    Please have a look at

    3.32 How can I properly manage numeric fields with extended screen IO?

    into Brian's FAQ at : https://gnucobol.sourceforge.io/faq/index.html

     
    • Steve Millman

      Steve Millman - 2021-10-01

      Hi Eugenio,
      Thank you. Am looking at your coding example and will try that approach as well. Great job documenting. Excellent work. Thanks again, Steve

       
      • Vincent (Bryan) Coen

        On 01/10/2021 18:20, Steve Millman wrote:

        Hi Eugenio,
        Thank you. Am looking at your coding example and will try that
        approach as well. Great job documenting. Excellent work. Thanks again,
        Steve

        Just had a play and it works but when I remove the decimal-point comma
        so that period works the example doesn't.

        I cannot see why though :(

        Vince

         
        • Steve Millman

          Steve Millman - 2021-10-01

          I just tried a new variation that seems to work okay. I had coded with SPACES and also had a version that inputted the original numeric fields. That, of course, looked wonky, although it appeared the numbers stored properly.

          My latest twist is a simple Display of the Screen field I ACCEPT as Numeric Editied.. and Joila.. it appears as a true number.

          What I am describing is a Screen Pic of Z(6)9.99, a using field of S9(07)V99 and an input amount like 123.45

          After the ACCEPT the field (without the added DISPLAY) looks like 123 .45 on the screen. With the added DISPLAY of the Screen fields, following the Accept, I see a proper representation of 123.45 on the screen.

          Internally, the ACCEPT of numbers as described above, is stored properly in each case.
          I see 00001234E

          I think I am okay with that.

           
          • Steve Millman

            Steve Millman - 2021-10-01

            Slight revision.. Screen field was Z(6).99.. Using the Display after the Accept of the Amount field saved me 35 lines of unnecessary code I had previously installed.. Tested the Add, Inquire and Delete. All good.

             
  • Eugenio Di Lorenzo

    At https://sourceforge.net/p/gnucobol/contrib/HEAD/tree/trunk/tools/TUI-TOOLS/ you will find

    • a complete working application (a sample "masterfile" management with CRUDE Create, Read, Update and DElete ) using ACCEPT with also NUMERIC fields. See attached screenshot GCCRUDxx.COB
    • a USER MNUAL GC00TT-MANUAL-V02-20210308.odt, look at page 66.
     

Log in to post a comment.