Skip to main content
Question

procedure division header where define the varible

  • February 26, 2026
  • 5 replies
  • 52 views

M Carmen De Paz
Forum|alt.badge.img+2
Good morning, I have been working in COBOL for over 20 years and I have always believed that when a main program (PA) calls a second program (PB) using `CALL PB USING field1 field2 field3` and the procedure in PB is `PROCEDURE USING field1 field2 field3`, the parameters that are put in the `using` procedure of a program (PB) should be defined in the `linkage` section, but I see in the documentation this“ Data-name-1 must be defined as a level 01 or a level 77 entry in the Linkage Section , File Section or Working-Storage Section”
This raises a lot of questions for me.
Has this always been the case? If the variables in PB are defined in the working storage section, what relationship do the variables in PA have with those in PB? How does assigning values ​​to variables in PB affect the variables defined in PA? Could the call be made from PA without passing those parameters?

5 replies

Chris Glazier
Forum|alt.badge.img+3

Hello,

This is a Rocket COBOL extension.

When you pass a parameter to a subprogram and the subprogram’s procedure division using statement specifies the parameter in the working-storage or file-section then it is  as if the parameter were actually passed in the linkage section and then its contents are moved to the data item in working-storage or the file section. If you modify this item in the subprogram, it will not affect the parameter in the main program. This is documented under General rules for format 1 of the procedure division header USING statement, general rules 4 which states:

 

rocket If data-name-1 is defined as a level 01 or a level 77 entry in the File Section or Working-Storage Section then the activated runtime element operates as if a data item had been declared in the Linkage Section with the same data declaration as data-name-1 and the contents of that data item were moved to data-name-1 prior to executing the first statement in the activated runtime element. In an initial program, these values are overwritten by the initialization of the program's working storage data and are therefore not available to the called program.

 


It is possible to share a data-item between a main program and a subprogram without passing it on the CALL statement by specifying the data item as being EXTERNAL in both programs.

01 my-param  pic x(5) external.

When you share data like this it means that the data item does not belong to any one program but can be shared between all programs in the run-unit defining it this way.

 

 


M Carmen De Paz
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • March 5, 2026
Good morning Chris, I'm very interested in this option, but I've never used it before. Could you show me an example or give me a link to the documentation?

Chris Glazier
Forum|alt.badge.img+3

Good morning!

I am assuming that you are referring to using EXTERNAL data items.

The following simple example will demonstrate its use.

identification division.
program-id. mainprog.
data division.
working-storage section.
01 my-external-data is external.
05 my-field-1 pic x(20).
05 my-field-2 pic 9(5).
procedure division.

move "my shared data" to my-field-1
move 12345 to my-field-2
call "subprog"
display "back from subprog"
display my-field-1
display my-field-2

goback.
 identification division.
program-id. subprog.
data division.
working-storage section.
01 my-external-data is external.
05 my-field-1 pic x(20).
05 my-field-2 pic 9(5).
procedure division.

display "in subprog"
display my-field-1
display my-field-2
move "set in subprog" to my-field-1
move 98765 to my-field-2
goback.

end program subprog.

 


M Carmen De Paz
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • March 5, 2026
Is there a limit to the size of variables defined as EXTERNAL?

Chris Glazier
Forum|alt.badge.img+3

According to the docs page covering size limits it says it is “not specifiable”.

I believe this means that it has the same limits as a non-external data item.

Size and Number of Data Items