Menu

Support for conditional compile

GnuCOBOL
pottmi
2023-05-09
2023-05-09
  • pottmi

    pottmi - 2023-05-09

    COBOL Crew,

    Is there any support conditional compile similar to what is
    implemented for IBM here:

    https://www.ibm.com/docs/en/i/7.4?topic=cd-conditional-compilation

    Or for Micro Focus here:

    https://www.microfocus.com/documentation/visual-cobol/vc60/DevHub/HRLHLHCOMP0J.html

    Or Micro Focus Constants:

    https://www.microfocus.com/documentation/visual-cobol/vc60/DevHub/HRCDRHCDIR24.html

    I would like to find a way to make something like this work:

    CONSTANT MYSUB 10

    01 SOMEVAR PIC X OCCURS MYSUB TIMES.

    That is: I can define a constant and then do a replace anywhere in the
    code with the specified value.

    Similar to what the C preprocessor does with #define.

     
    • Simon Sobisch

      Simon Sobisch - 2023-05-09

      IBM implemented the COBOL2002 CDF and constant definition - GnuCOBOL supports that, too (actually supported it much longer - before any other compiler) with one exception: >> EVALUATE is not implemented yet - patches welcome.
      So in general you should be fine using that. The exact syntax is:

      01 CONSTANT MYSUB 10.
      01 SOMEVAR.
              05 PIC X OCCURS MYSUB TIMES.
      01 SOMERED PIC X(MYSUB) REDEFINES SOMEVAR.
      

      GnuCOBOL also supports the common extension with level 78 constants:

      78 MYSUB VALUE 10.
      01 SOMEVAR.
              05 PIC X OCCURS MYSUB TIMES.
      01 SOMERED PIC X(MYSUB) REDEFINES SOMEVAR.
      

      The programmer's guide likely has documentation on how to use this including how to pass definitions from the command-line.

       

Log in to post a comment.