On Saturday, 2 April 2016 23:12:42 UTC+1, Bill Woodger  wrote:
...
> 
> If it *could* be NULL (you CALL your program from another program, perfectly 
> possible, no messing about with "main" programs for COBOL on an IBM 
> Mainframe), then you said "if the field does not have an address, move one to 
> the filed". Which will get you a S0C4 for sure, as you know it has no address 
> and you've not subsequently given it an address.
> 
> For your situations, I'd put iterate in the WORKING-STORAGE. IF address of 
> linkage-item = NULL, move 1 to the working-storage item, else move the 
> linkage item to the working-storage item. Use the working-storage item in the 
> TIMES.
> 
> A more obscure way to do it:
> 
> WORKING-STORAGE SECTION.
> 01  our-default-value PIC 9(5) VALUE 1.
> 
> PROCEDURE DIVISION USING iterate.
> IF ADDRESS OF iterate = NULL
>     SET ADDRESS OF iterate TO ADDRESS OF our-default-value
> END-IF
> 

...

A discussion elsewhere leads me to clarify on the above advice.

This does not relate directly to any program which execute due to with EXEC 
PGM=, but relates instead to other CALLed programs.

If you were to have a general-use sub-program which was documented as "if you 
call it with a value, that will be used, if you call it without a value, the 
default value will be used", what that means is:

     CALL (either literal or data-name) USING 
field-of-correct-type-and-size-with-value

or 

     CALL (either literal or data-name) USING OMITTED

If you instead do this, thinking it means the same thing, your program may not 
work, and if it works now, it may not work if you change something else in the 
program, or particular compile options.

     CALL (either literal or data-name)

The first CALL will "pass" the address of the field. The second will "pass" a 
NULL address. The third will not "pass" anything, but the CALLed program won't 
know that, and it will use whatever happens to be lying around in the parameter 
list (which may be "null", or may not, and if it is, may change).

This does not only apply when there is one parameter. If you "pass" three 
parameters, but you want the third to be NULL, then specify the third as 
OMITTED, don't just leave it off the CALL.

This does also mean if you see OMITTED as the last parameter to a CALL don't 
think "Oh, I can just remove that, it's not needed". It is needed.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to