'Single source for IBM i and z/OS

I am primarily a C developer, not a regular COBOL developer. I would like my COBOL program to have the same source on IBM-i as it does on z/OS.

My COBOL program calls a subroutine. On z/OS I do the call like this:

CALL                                      
  'PBFNInit' USING                        
                    BY VALUE NULL-POINTER,

On IBM i I have to call like this:

    CALL PROCEDURE
      'PBFNInit' USING                        
                        BY VALUE NULL-POINTER,

Is there some way I can dynamically tell the COBOL compiler which format of the CALL statement to use?

I was hoping for some kind of dynamic statement like the debug statement controlled by this

SOURCE-COMPUTER. IBM-3270 WITH DEBUGGING MODE.



Solution 1:[1]

If your compiler supports conditional compilation, you could define a constant with a compiler directive and then...

    >>EVALUATE TRUE
    >>WHEN DEFINED IBM-Z
        CALL 'PBFNInit' USING                        
            BY VALUE NULL-POINTER, [...]
    >>WHEN DEFINED IBM-I
        CALL PROCEDURE 'PBFNInit' USING                        
            BY VALUE NULL-POINTER, [...]
    >>WHEN OTHER
        !non-sequiter, your facts do not coordinate
    >>END-EVALUATE

UPDATE 1 per comment...

You could try combining this answer with that of @SimonSobisch, something like...

    >>IF DEFINED IBM-I
        REPLACE ==CALL== BY ==CALL PROCEDURE==.
    >>END-IF

        CALL 'PBFNInit' USING                        
            BY VALUE NULL-POINTER, [...]

There is nothing currently in the documentation to indicate the text being conditionally compiled must be valid code. Maybe the authors felt this was implicit, or maybe it's a bug.

Solution 2:[2]

The WITH DEBUGGING MODE would be a minor change in each file - but also overlap with an actual COBOL feature.

If "minor change" is ok for you then only code CALL PROCEDURE and use a single

REPLACE ==CALL PROCEDURE== BY ==CALL==.

in the source.

Solution 3:[3]

If all your calls should be procedure calls, it looks like you can set this for all calls with a parameter on the compile or a process option.

https://www.ibm.com/docs/en/i/7.4?topic=program-identifying-linkage-type-called-programs-procedures

It says

the LINKLIT parameter of the CRTCBLMOD and CRTBNDCBL commands, or the associated PROCESS statement option.

The LINKLIT parameter of the CRTCBLMOD and CRTBNDCBL commands allows you to specify, at compile time, the linkage type for all external CALL literal-1, CANCEL literal-1, or SET procedure-pointer-data-item TO ENTRY literal-1 statements in the ILE COBOL program. You do not need to specify the LINKAGE TYPE clause in the SPECIAL-NAMES paragraph or the LINKAGE TYPE phrase with the CALL, CANCEL, or SET…ENTRY statement when the linkage has been defined by the LINKLIT parameter of CRTCBLMOD or CRTBNDCBL.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Simon Sobisch
Solution 3 Barbara Morris