COBOL

COBOL

COBOL

COBOL is responsible for the efficient, reliable, secure, and unseen day-to-day operations of the world's economy.

 View Only
  • 1.  COBOL conditional compilation - When to use, when not to use

    Posted Sun January 29, 2023 02:47 PM
    Edited by Denis FALLAI Sun January 29, 2023 02:55 PM
      |   view attached
    Hi,

    Conditional compilation appeared in the V6 version of the IBM Enterprise COBOL compiler.
    Many other languages use it, in particular the C/C++ language.

    The use of conditional compilation in COBOL is an internal debate for us. Some are pros, others are cons.
    Some people inside IBM would advise against using conditional compilation in COBOL...

    I would like to have the opinion from the Community, and from the IBM Laboratory in charge of the IBM Enterprise COBOL compiler, and their recommendations regarding the implementation of conditional compilation in COBOL.

    For illustration, see an attached conditional compilation use case : development framework for files management.

    Thanks.

    ------------------------------
    Denis FALLAI
    ------------------------------

    Attachment(s)

    zip
    usecase.zip   108 KB 1 version


  • 2.  RE: COBOL conditional compilation - When to use, when not to use

    Posted Thu February 09, 2023 09:40 AM
    Hi Denis,

    I'm a developer on the IBM Enterprise COBOL compiler team, and I can say that we definitely endorse the use of the conditional compilation feature of Enterprise COBOL.  I'm not sure who has advised you against its use, but that is certainly not our position.  It is possible that the person(s) to whom you were speaking were merely indicating that the application of conditional compilation to a specific problem was not recommended, but I'd need to know more about the scenario to be sure.

    I've taken a look through some of your examples, and it seems like they contain appropriate use of the conditional compilation feature to me, although I can see that you would definitely benefit from a more expressive language in some cases, which would make certain tasks easier for you.  For example, being able to define an actual macro that has a loop construct could drastically simplify some of your code such as this:
           01               RTP.                                            AAADGRUP
               05           RTP1          PIC X VALUE '1'.                  AAADGRUP
           >>if maxNR > 1                                                   AAADGRUP
               05           RTP2          PIC X VALUE '1'.                  AAADGRUP
             >>if maxNR > 2                                                 AAADGRUP
               05           RTP3          PIC X VALUE '1'.                  AAADGRUP
               >>if maxNR > 3                                               AAADGRUP
               05           RTP4          PIC X VALUE '1'.                  AAADGRUP
                 >>if maxNR > 4                                             AAADGRUP
               05           RTP5          PIC X VALUE '1'.                  AAADGRUP
                   >>if maxNR > 5                                           AAADGRUP
               05           RTP6          PIC X VALUE '1'.                  AAADGRUP
                     >>if maxNR > 6                                         AAADGRUP
               05           RTP7          PIC X VALUE '1'.                  AAADGRUP
                       >>if maxNR > 7                                       AAADGRUP
               05           RTP8          PIC X VALUE '1'.                  AAADGRUP
                         >>if maxNR > 8                                     AAADGRUP
               05           RTP9          PIC X VALUE '1'.                  AAADGRUP
                         >>end-if                                           AAADGRUP
                       >>end-if                                             AAADGRUP
                     >>end-if                                               AAADGRUP
                   >>end-if                                                 AAADGRUP
                 >>end-if                                                   AAADGRUP
               >>end-if                                                     AAADGRUP
             >>end-if                                                       AAADGRUP
           >>end-if                                                         AAADGRUP​


    The support we have now in the Enterprise COBOL compiler for conditional compilation is almost exactly as it is defined in the COBOL standard, including all of its limitations.  However, we on the COBOL team are actually interested in continuing to provide improvements and enhancements to our conditional compilation support beyond that, and have given significant thought to adding macro support, which may be a part of a future COBOL standard as well.  We do face significant time constraints,  though, and prioritizing work is a challenge.  But certainly, we will continue to support and improve this feature and encourage its use where appropriate -- you should not worry about that.

    In terms of the general question of where conditional compilation is appropriate -- I would say it is appropriate wherever it helps you to maintain a single source file with code that can be built in different ways to produce slightly different programs.  This is much better than duplicating large pieces of code that may only differ in a few key places.  For example, I know some users may have both Db2 and IMS systems and may have some COBOL processing that is generally identical for both but just the embedded SQL statements are different -- so being able to add code that can be built for Db2 and IMS is a great way to avoid duplicating code and causing a maintenance issue.

    For any language that supports actual macros (potentially COBOL in the future) I would advise against using the macros as a way to implement inline "subroutines", as opposed to using normal language features for writing subroutines.  I've seen this pattern used before too often in various code bases written in languages that support macros and, unfortunately, if macros are overused and used as merely a way to generate inline subroutines, then it results in a code maintenance problem whereby a lot of code is "hidden" behind these macros in various "answer strings" (e.g., PL/I macros).  This makes it hard for developers, language analysis tools, debuggers, etc.  to understand what is actually going on in the code until the code goes through some kind of pre-processing phase that expands macros and allows you to see what the actual final result is.

    That's about all the advice that have on this topic.  Please let me know if you need more info, or have more questions.

    Regards,
    David



    ------------------------------
    David Tremaine
    ------------------------------



  • 3.  RE: COBOL conditional compilation - When to use, when not to use

    Posted Fri February 10, 2023 04:26 PM

    Hi David,

    Thanks for your answer and these informations.

    Regarding the possibility of simplifying the coding, please to consider COBOLVUE-I-28, directive >>PERFORM to manage a loop, and COBOLVUE-I-284, directive >>PUNCH to create a line of source code.

    I also opened other RFEs and Ideas about conditional compilation.

    Regards.

    Denis



    ------------------------------
    Denis FALLAI
    ------------------------------



  • 4.  RE: COBOL conditional compilation - When to use, when not to use

    Posted Fri October 20, 2023 03:47 PM

    Hi

    (sorry for my bad english)
    I did a dissertation on conditional compilation (2002 standard) in cobol.
    It can provide variability, security, allow a certain emulation of OO  while remaining "good old cobol"  (which will therefore not frighten the "old cobolists")

    If you understand French and would like to read it, I will gladly send it to you

    Regards,
    Joel



    ------------------------------
    joel Bauwens
    ------------------------------



  • 5.  RE: COBOL conditional compilation - When to use, when not to use

    Posted Mon October 23, 2023 08:40 AM

    Hi Joel,

    I will certainly not criticize your mastery of English, being French myself and using Google translate before any publication :-)

    I will be happy to discuss with you the implementation of conditional compilation in COBOL, and I can illustrate with what we have implemented on this subject.

    I will send you my professional email address by private message.

    Thanks for your proposition.



    ------------------------------
    Denis FALLAI
    BPCE SI, BPCE group.
    ------------------------------