COBOL Linkage Section

COBOL Working-Storage Section COBOL Procedure Division

Advertisements


LINKAGE SECTION describes that the data available to another program by using CALL.

LINKAGE SECTION uses the data items declared to make available the data to another program.

LINKAGE SECTION mainly used in subprograms where to send/receive the data between the programs (from main program/calling program) by using the layouts.

The LINKAGE SECTION used to access the data external to the program.

The LINKAGE SECTION normally coded in the called/sub program which is used to access the working-storage data from calling program.

The LINKAGE SECTION fields needs to be coded when the data sending from JCL through PARM. In this case 2 bytes extra field(s9(4) COMP) needs to be declared to store the length of data in the linkage section additional to the data length passing from JCL.


Syntax:

DATA DIVISION.
LINKAGE SECTION
 [linkage section data item]

The CALL statement in the calling program.


CALL "subprog" USING name,address.

The name, address declaration in CALLED program


IDENTIFICATION DIVISION.
PROGRAM-ID subprog IS INITIAL.
DATA DIVISION.
LINKAGE SECTION.
01  name            PIC X(10).
01  address         PIC X(10).
PROCEDURE DIVISION USING name, address.
	Begin. 
	-----
	GO BACK.

The syntax of the data division is shown below.


DATA DIVISION.
FILE SECTION.
FD/SD filename 
	[RECORD CONTAINS integer CHARACTERS] 
	[BLOCK CONTAINS integer RECORDS]
	[DATA RECORD IS recordname].
	[RECORDING MODE IS {F/V/U/S}]
WORKING-STORAGE  SECTION.
	WS Entries.
LINKAGE SECTION.
	LS Entries.

Practical Example:


Let’s take simple example for calling a subprogram to multiply the inputs passed from main program.

In the below example, MAINPROG is the main program, SUBPROG is the subprogram.

INPUT1, INPUT2 are the inputs passed from MAINPROG during the CALL to SUBPROG.

SUBPROG receives the data into IP1, IP2 from MAINPROG, multiply those and place the result in OP.

SUBPROG will return output to MAINPROG, MAINPROG displays the result as per the below code.


Main program code:



Sub program code:



Jcl:



Output:



COBOL Working-Storage Section COBOL Procedure Division

Advertisements