Passing Parameters and Control

  1. Type and length attributes must be the same
  1. Data names may differ
  1. Order in Linkage section not important but order in Procedure Using is important
  1. By Reference and By Content
  1. How control is returned.

PGMCALL1

PGMCALL2

PGMCALL1

PGMCALL2

IBM users guide:

BY REFERENCE means that the subprogram is referring to and processing the

data items in the calling program's storage, rather than working on a copy

of the data.

BY CONTENT means that the calling program is passing only the contents of

the literal, or identifier. With a CALL . . . BY CONTENT, the called

program cannot change the value of the literal or identifier in the

calling program, even if it modifies the variable in which it received the

literal or identifier.

You must know what is being passed from the calling program and set up the

Linkage Section in the called program to accept it. To the called

program, it doesn't matter which clause of the CALL statement you use to

pass the data (BY REFERENCE or BY CONTENT). In either case, the called

program must describe the data it is receiving. It does this in the

Linkage Section.

A called subprogram is in its initial state the first time it is called

within a run unit. It is also in its initial state the first time it is

called after a CANCEL statement. On all other entries into the called

subprogram, it is in its last-used state, and the reinitialization of any

items is the responsibility of the user.

______

| |

| Calling Program Description Called Program Description |

| |

| |

| WORKING_STORAGE SECTION. LINKAGE SECTION. |

| ______|

| |01 PARAM_LIST. | |01 USING_LIST. | |

| | 05 PARTCODE PIC A. |______ÿ| 10 PART_ID PIC X(5). | |

| | 05 PARTNO PIC X(4). | | 10 SALES PIC 9(5). | |

| | 05 U_SALES PIC 9(5). | | | |

| |______| |______| |

| . | . | |

| . | . | |

| . | . | |

| | | |

| PROCEDURE DIVISION. | PROCEDURE DIVISION |

| . | ______|

| . | USING |USING_LIST.| |

| . | |______| |

| | |

| CALL CALLED_PROG |

| ______|

| USING |PARAM_LIST.| In the called program, the code |

| |______| for parts and the part number |

| are combined into one data item |

| In the calling program, the code (PART_ID). In the called |

| for parts (PARTCODE) and the part program, a reference to PART_ID |

| number (PARTNO) are referred to is the only valid reference to |

| separately. them. |

| |

|______|

Figure 96. Common Data Items in Subprogram Linkage

Note that

  1. Program PGMCALL1 should not call itself nor should it be called by a program it has called such as PGMCALL2.( Note recursive calls should be avoided).
  1. If you use a group-name then order and attributes in Linkage Section is important.
  1. Breaking down the group-items in the calling or called programs is allowed (refer to IBM COBOL User’s Guide manual diagram)
  1. The Program Call Stack
  1. EXIT and GOBACK return control to the calling program (at statement following the Call)
  1. * STOP RUN stops the run unit and removes all programs from memory. When STOP RUN is specified, execution of the run unit is terminated, and control is returned to the system.
  1. * The CANCEL statement ensures that the next time the referenced subprogram is called it will be entered in its initial state.

A calls B and B calls C (When A receives control, it can cancel C.)

A calls B and A calls C (When C receives control, it can cancel B.)

  1. Also refer to IBM COBOL/400 User’s Guide (Chapter 12)

*IBM COBOL/400 Reference Manual (Chapter 8)