Menu

IS NUMERIC Behaviour quesiton

Anonymous
2021-09-01
2024-06-29
  • Anonymous

    Anonymous - 2021-09-01

    Are the results below the way the Standard COBOL works or is it special to GNU COBOL? It looks like the class test IS NUMERIC is not recognized unless literal text is moved to the numeric field. Thank you.

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    
    01 N3   PIC 999.
    01 X4   PIC XXXX.
    01 X3   PIC XXX.
    
    PROCEDURE DIVISION.
    
    MOVE "ABC" TO X4. 
    MOVE X4 TO N3.
    IF N3 IS NUMERIC THEN
    DISPLAY X4 SPACE 'NUMERIC'                *> THIS DISPLAYS !!!
    ELSE DISPLAY X4 SPACE "NOT NUMERIC".
    
    MOVE "ABC " TO N3. 
    IF N3 IS NUMERIC THEN
    DISPLAY X4 SPACE 'NUMERIC'           
    ELSE DISPLAY "ABC" SPACE "NOT NUMERIC".   *> THIS DISPLAYS
    
    MOVE "ABC" TO X3. 
    MOVE X3 TO N3.
    IF N3 IS NUMERIC THEN
    DISPLAY X3 SPACE 'NUMERIC'                *> THIS DISPLAYS !!!
    ELSE DISPLAY X3 SPACE "NOT NUMERIC".
    
    MOVE "ABC" TO N3. 
    IF N3 IS NUMERIC THEN
    DISPLAY X3 SPACE 'NUMERIC'               
    ELSE DISPLAY "ABC" SPACE "NOT NUMERIC".   *> THIS DISPLAYS
    .
    STOP RUN.
    
     

    Last edit: Simon Sobisch 2021-09-01
    • DaveR

      DaveR - 2021-09-01

      Compiled under my old DOS compiler. Had to shorten the name

      D:\Source\xcobol hello.cob;
      Microsoft (R) COBOL Optimizing Compiler Version 5.0
      
      COBOL software by Micro Focus
      Copyright (C) Microsoft Corporation 1984,1993.  All rights reserved.
      Copyright (C) Micro Focus Ltd. 1984,1993.  All rights reserved.
      
          18     MOVE "ABC " TO N3.
      *1026-E*********************                                                 **
      **    Source literal is non-numeric - substituting zero
          29     MOVE "ABC" TO N3.
      *1026-E********************                                                  **
      **    Source literal is non-numeric - substituting zero
      * Checking complete with no serious errors - starting code generation
      * Data = 000000450 Code = 000000681
      
      D:\Source\>link hello;
      
      Microsoft (R) Segmented Executable Linker  Version 5.31.009 Jul 13 1992
      Copyright (C) Microsoft Corp 1984-1992.  All rights reserved.
      
      D:\Source\>hello
      ABC  NUMERIC
      ABC  NUMERIC
      ABC NUMERIC
      ABC NUMERIC
      
       

      Last edit: Simon Sobisch 2021-09-01
      • Emmad

        Emmad - 2021-09-01

        Thank you for this test. I see that the warning is useful. This made me recompiled the code with -Wall and got warning message at explicit moves.

         
  • Simon Sobisch

    Simon Sobisch - 2021-09-01
    $ cobc test.cob -xj -free
    test.cob:32: warning: ignoring redundant . [-Wothers]
    ABC  NUMERIC
    ABC NOT NUMERIC
    ABC NUMERIC
    ABC NOT NUMERIC
    
    $ cobc test.cob -xj -free -std=mf
    test.cob:18: warning: source is non-numeric - substituting zero [-Wothers]
    test.cob:29: warning: source is non-numeric - substituting zero [-Wothers]
    test.cob:32: warning: ignoring redundant . [-Wothers]
    ABC  NUMERIC
    ABC  NUMERIC
    ABC NUMERIC
    ABC NUMERIC
    

    :-)

    Explanation why the first one is numeric but the second isn't - as is in current GnuCOBOL implementation:

    • the first and third one are handled as a move from alphanumeric (in both cases only the first 3 bytes are handled) to numeric USAGE DISPLAY, during that invalid data is found and the target set to zero as a result
    • the second and last one directly sets the memory of the field (optimization) - which is then invalid -> not numeric



    What does "standard COBOL" say? Just rechecked (from the standard draft, "MOVE statement, General Rules"): the NOT NUMERIC is correct because of this rule (6.c):

    When the receiving data item is described with the same usage specification as the sending operand, the data in the sending operand is transferred to the receiving data item without change.

    --> both are USAGE DISPLAY, everything fine

    The others seem to be handled as according to 6d)

    When a numeric or numeric-edited item is the receiving item, and General rule 6c does not apply [it actually does]: [...] When the sending operand is described as alphanumeric or national, the sending operand is treated as if it were an unsigned integer of category numeric

    And as this does not have valid data in a "zero" may be seen as correct (like "undefined") - but as noted, should not happen if it has the same USAGE, which is the case here.

    If that analysis is correct then the answer is "neither Micro Focus [or its old variant Microsoft COBOL] nor GnuCOBOL" do that correctly and all fields should be considered to be NOT NUMERIC (the "obvious" solution is to check before doing the MOVE).

    It would be interesting to see the result with IBM.

     
    👍
    1

    Last edit: Simon Sobisch 2021-09-01
    • Emmad

      Emmad - 2021-09-01

      Thank you for your detailed reply. The compilation was made using cobc -x -free *.cobc -o main using this site:
      I wish I had access to IBM Enterprise Cobol to try it.

      Looking at Dave R message above, I changed the compilation flags to include -Wall. The compiler produced 2 warnings at lines 18, 29 containing MOVE "ABC " TO N3. However, the messages did not say that a zero was assumed.

       

      Last edit: Emmad 2021-09-01
      • Brian Tiffin

        Brian Tiffin - 2021-09-12

        I wish I had access to IBM Enterprise Cobol to try it.

        We kinda do. Old school though. ANS 1972. Hercules emulator, MVS 3.8j, backward/forward compatible to z/OS. x3270 (or other favourite 3270 emulator (I usually use the c3270 character mode) interface).

        Start here, http://wotho.ethz.ch/tk4-/ and then watch some of these, https://www.youtube.com/c/moshix/videos?view=0&sort=da&flow=grid

        There is also the Master the Mainframe educational program for any and all, but people with student id's can also compete for prizes. I think it was renamed this year, so it might change soonish https://www.ibm.com/it-infrastructure/z/education/master-the-mainframe

        I've never signed up, find the MVS 3.8 and the constraint of ANS COBOL 72 is more fun, having sysprog and operator powers, but I hear they use vscode and a plugin as an interface instead of 3270 screens. Booo... ;-) People seem to like having the accounts on real iron though. COBOL compiler is available for job submits, being part of the student challenges. You are free to use the account to explore (I'm led to believe), but the challenges include things like TSO/E basics and some JCL to get started. Accounts last a year(ish).

        Cheers,
        Blue

         
        👍
        1
        • Emmad

          Emmad - 2021-09-12

          Thank you for providing all this useful information. I hope I get a chance to use it.
          You are great help.

           
  • Mickey White

    Mickey White - 2021-09-01

    IBM Enterprise COBOL for z/OS 4.2.0
    Does not compile.

    PA3005-S "'ABC '" and "N3 (NUMERIC INTEGER)" did not follow t
             compatibility rules.  The statement was discarded.   
    

    Here:

                        IDENTIFICATION DIVISION.                                               
            PROGRAM-ID. TESTNUM.                                                   
            DATA DIVISION.                                                         
            WORKING-STORAGE SECTION.                                               
            01 N3   PIC 999.                                                       
            01 X4   PIC XXXX.                                                      
            01 X3   PIC XXX.                                                       
            PROCEDURE DIVISION.                                                    
                MOVE "ABC" TO X4.                                                  
                MOVE X4 TO N3.                                                     
                IF N3 IS NUMERIC THEN                                              
                DISPLAY X4 SPACE 'NUMERIC'                                   !     
                ELSE DISPLAY X4 SPACE "NOT NUMERIC".                               
                MOVE "ABC " TO N3.                                                 
    
    A3005-S "'ABC '" and "N3 (NUMERIC INTEGER)" did not follow the "MOVE" statement
            compatibility rules.  The statement was discarded.                     
    
                IF N3 IS NUMERIC THEN                                              
                DISPLAY X4 SPACE 'NUMERIC'                                         
                             ELSE DISPLAY "ABC" SPACE "NOT NUMERIC".                            
                 MOVE "ABC" TO X3.                                                  
                 MOVE X3 TO N3.                                                     
                 IF N3 IS NUMERIC THEN                                              
                 DISPLAY X3 SPACE 'NUMERIC'                                   !     
                 ELSE DISPLAY X3 SPACE "NOT NUMERIC".                               
                 MOVE "ABC" TO N3.                                                  
    
    PA3005-S "'ABC'" and "N3 (NUMERIC INTEGER)" did not follow the "MOVE" statement 
             compatibility rules.  The statement was discarded.                     
    
                 IF N3 IS NUMERIC THEN                                              
                 DISPLAY X3 SPACE 'NUMERIC'                                         
                 ELSE DISPLAY "ABC" SPACE "NOT NUMERIC".                            
                 STOP RUN.
    
     

    Last edit: Simon Sobisch 2021-09-01
    • Emmad

      Emmad - 2021-09-01

      Thank you for your effort. I guess the compiler took a defensive path by not compiling program considering the move a sever error - I assume it rejected the statements where an explicit literal was moved to a numeric field.

       
    • Simon Sobisch

      Simon Sobisch - 2021-09-01

      That's interesting: I guess the compiler says "the literal is alphabetic" - and "alphabetic" may not be moved to a numeric item per standard (but then, per standard there are only alphanumeric literals, which are always of class and category alphanumeric).

      @jamesbwhite Can you please recompile the code with MOVE "1B2" TO N3 and see if the result is different? And if it is numeric: please output its value, too.

       

      Last edit: Simon Sobisch 2021-09-01
      • Mickey White

        Mickey White - 2021-09-01

        Fails, same error.

         
        👍
        1
  • Graham Knight

    Graham Knight - 2021-09-12

    When I worked with COBOL II you would get an OC6 system error(I think, it's a long time ago) because the hex characters did start with an F. Eg x"F0" for 0. The right most character would start with a C or D depending on whether it was positive or negative.

     
  • Venkatesh Srinivas

    In my program a default \000 is getting moved to a WS variable with no values clause and this is causing issues when this variable is getting used in computations. I want to either initialize it with binary zero or stop the default initialization, how can i achieve this using compiler directives.

     
  • Simon Sobisch

    Simon Sobisch - 2024-06-21

    \000 = binary zero so you already have what you want ?!?

    In any case you may want to check cobc --help | grep -A2 defaultbyte (or checking the GnuCOBOL manual for its entry on that).

     
  • Venkatesh Srinivas

    Sorry for confusion, what I meant was that, I didnt want to initialize with an octal zero or binary zero but a decimal one, or simply put, I wanted a behaviour similar to having "Value Zero" (ofcourse the variable doesnt have any VALUE clause in this program I inherited from an old z/os system). Since it's an old program that we are trying to move to GNU, I can't code VALUE clause for all variables used inside.

    The issue here is that , the presence of " \" is causing the -debug option i used in the compiler dialect, to throw a runtime abend in my program by saying that the value here is not numeric. I used the -debug option to catch any S0C7 issues, but this issue is giving me new headache.

    I used the "-fcorrect-numeric" directive later and this seems to have corrected this issue to some extent, but, in a different program where a floating point comp3 variable without Value clause got initialized with 0x000000, the presence of 'x' seems to have spooked the -debug directive, causing the program to throw a runtime error saying the value is not numeric.

    So, how do i make the program feel safe with '\' or 'x' inside these numeric variables, or, not have them used while default initialization by GNU.

    I am new to this, so, sorry for any confusion.

     

    Last edit: Venkatesh Srinivas 2024-06-27
    • Mickey White

      Mickey White - 2024-06-27

      Can you redefine the variable as pic 9(01). and initialize it?

       
    • Simon Sobisch

      Simon Sobisch - 2024-06-28

      That's a quite different question...

      While the program would very likely behave differently outside of GnuCOBOL when it is about the init: drop correct-numeric, use

      -fdefaultbyte=init
      

      default initialization for fields without VALUE, may be one of; character in quotes; decimal 0..255 representing a character; “init” to initialize to PICTURE/USAGE; “none” to do no explicit initialization; default: “init”

       
      • Venkatesh Srinivas

        I haven't used this directive of "-fdefaultbyte" till now, but, even if i have to use it, since you said "init" is default, then, even when i don't use it, I am assuming that the program would behave as if i used it with "init", since it is the default, is that a correct assumption ?

         
        • Simon Sobisch

          Simon Sobisch - 2024-06-28

          -std changes a lot of options at once, including -fdefaultbyte (mainframe dialects all use zero since aome 3.x version)

           
          • Anonymous

            Anonymous - 2024-06-29

            Sorry, i didnt understand your comment here Simon, are you saying that for -fdefaultbyte i should be using some other option? I have GNU cobol V3.2

             
            • Simon Sobisch

              Simon Sobisch - 2024-06-29

              No, what I've meant is: if you use any -std then you override the default for that option and want to explicitly set it back to "init" afterwards.

               
  • Anonymous

    Anonymous - 2024-06-28

    There are many variables, some in subprograms and in copybooks, so, it would be too many changes

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.