![]() |
VOOZH | about |
The linkage Section in COBOL is used to declare the variables and it is used in calling the variable from another program. It is used in calling the variable or data from the called program by using the CALL statement.
The linkage Section helps in sending the data to the calling program or receiving the data from the calling program. The declaration of a variable to the Linkage section is nothing but the group, individual or elementary variables. The linkage section is also used in receiving the data from JCL a PARM operand (PARM is nothing but a parameter keyword).
Syntax :
DATA DIVISION.
LINKAGE SECTION.
[variable declaration]
The parameters can be passed in two ways. They are,
Call by Reference is referred to changes made in the sub-program or called the program that will get reflected in the main program or calling program.
Syntax:
CALL SUB-PROGRAM_NAME USING VARIABLE-ENTRIES.
Below is the example for calling the sub-program from the main program. The code is the main program that calls the subprogram using the CALL statement. It has two data items or variables which are employee id and employee name.
Example 1:
The below code is the sub-program which is called by the main program. In the linkage section, it contains the same type of the data-items as declared in the main program. It changes the employee id of the employee under the linkage section using MOVE statement and it will be reflected in the main program when the code is executed.
Output :
I am Sub Program I am Main Program Employee Id : 110 Employee Name : GEEKSFORGEEKS
Call by Content is referred to whatever changes made in the sub-program or called program will not get reflected in the main program or calling program. The content of the data in the main program remains unchanged.
Syntax:
CALL SUB-PROGRAM_NAME USING
BY CONTENT VARIABLE-ENTRIES.
The below code is the main program that calls the subprogram using the CALL statement and BY CONTENT keyword. It has two data-items or variables which are employee id and employee name.
Example 2:
The below code is the sub-program which is called the main program. The linkage section, it contains the same type of the data-items as declared in the main program. It changes the employee id of the employee under the linkage section using the MOVE statement but it will not be reflected in the main program when the code is executed due to the usage of BY CONTENT in the main program.
Output :
I am Sub Program I am Main Program Employee Id : 102 Employee Name : GEEKSFORGEEKS