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
------------------------------
Original Message:
Sent: Sun January 29, 2023 02:46 PM
From: Denis FALLAI
Subject: COBOL conditional compilation - When to use, when not to use
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
------------------------------