I need to compile Cobol sources, on z/OS UNIX, with a Cobol 4 compiler but I only have a Cobol 5 compiler. Is there options to restrict Cobol 5 to a Cobol 4 compilation ? I'm using the cob2 command which I mounted to the IGY520.HFS PDS of my Cobol installation on z/OS. I searched in the IBM documentation but didn't find anything.
3 Answers
No. I strongly recommend you study the migration guide and any SHARE presentations on the topic of migration sadly SHARE no longer makes their excellent content available to non-members.
The most common problems reported have to do with invalid data tolerated by older compilers. Quoting from Tom Ross' SHARE presentation linked above...
77 A1 PIC X(4) VALUE ’00 0’. *> x’F0F040F0’, third byte *> has x’4’ for zone bits. *> OK in PIC X, not valid in *> PIC 9 USAGE DISPLAY 77 A2 REDEFINES A1 PIC 9(4). PROCEDURE DIVISION. IF A2 = ZERO *> Compiler could do character DISPLAY ’ZERO‘ *> or numeric compare ELSE DISPLAY ’NOT ZERO‘ END-IF
Whether the program displays ‘ZERO’ or ‘NOT ZERO’ depends on the compiler options you use in COBOL V4 and earlier and in COBOL V6
Also be aware of differences in how packed data is treated, see this recent question.
The NUMCHECK compile option can assist you in these situations, but be advised that compile options cannot detect invalid data at compile time, they can only generate code to detect invalid data at run time.

- 10,237
- 1
- 28
- 39
-
Thanks for your detailed answer – Timothée Jan 16 '19 at 16:40
Not that I am aware of. I see the following might be useful.
CMPR2, FLAGMIG, and NOCOMPILE compiler options
The COBOL CMPR2, FLAGMIG, and NOCOMPILE options identify source statements that need to be converted to compile under Enterprise COBOL. The CMPR2 and FLAGMIG options are not available in Enterprise COBOL, but you can use your older compilers with these options to flag the statements that need to be changed in order to compile with Enterprise COBOL.
Enterprise COBOL> V4.2 FLAGMIG4 compiler option
A new compiler option, FLAGMIG4, is available with APAR PM93450 for Enterprise COBOL V4.2 to help you migrate to Enterprise COBOL V5 or V6. It is also recommended that you install PTFs for APARs PI12240, PI26838, and PI58762 as these contain updates to the FLAGMIG4 option. The FLAGMIG4 option identifies language elements in Enterprise COBOL V4 programs that are not supported, or that are supported differently in Enterprise COBOL V5 or V6. The compiler generates a warning diagnostic message for all such language elements.

- 31
- 2
COBOL 5 programs are backwards-compatible with COBOL 4 (they can call each other), but COBOL 5 doesn't produce COBOL 4 object modules. Why do you need a COBOL 4 compilation?

- 11
- 2
-
I'm not sure my program will be compatible with most of z/OS if I compile it in COBOL 5. Do a COBOL 5 compiled object need specific installed libraries on the target z/OS or are they just object and there is no way a COBOL 4 object would work and a COBOL 5 doesn't? Also, there is specific COBOL4 syntax in my sources. – Timothée Jan 16 '19 at 16:32
-
1COBOL V5 will compile programs that COBOL V4 could compile; the only syntax issues you'll hit is if your program happens to use something that's a new reserved word in V5, and if so, that's easily fixable. You won't need any libraries at compilation time. You WILL need the V5 runtime when you run a program compiled with V5, but assuming V5 and LE (Language Environment, of which the COBOL runtime is a part) are installed properly, that won't be a problem. – Mike Chase Jan 16 '19 at 20:08
-
1As far as compatibility with other programs, V5 code is compatible with any older COBOL code except for code compiled with OS/VS COBOL. You may see differences in behaviour if any of the COBOL programs in your application use invalid data. I give a quarterly presentation on the challenges of migrating to COBOL V5/V6 that you may want to look through; previous recordings and slides can be found here: https://ibm.ent.box.com/v/COBOLMigrationWorkshops – Mike Chase Jan 16 '19 at 20:08
-
There is one major difference between V4 and V5 compiled code: EC V5 produces object-code in GOFF format that the binder uses to produce program objects instead of load modules. So with V5 it is required that all load libraries are PDSE instead of PDS (I don't know for certain about the object-libraries, but PDSE won't hurt there too). – piet.t Jan 17 '19 at 07:23