Reputation: 1461
I have a map in which the user enter two values which are to be updated in the database table. I wrote both the programs but i am unable to know how to pass the two field values entered in the map to another program. I came to knew that i can use Linkage Section. But don't know the syntax or any details on it. Can anyone help me with the syntax. Thank you
Upvotes: 1
Views: 5663
Reputation: 45
You can pass argument just as you would between two batch COBOL programs. However, you must be careful that you also have to pass two mandatory arguments that are DFHEIBLK and DFHCOMMAREA.
Indeed, in your called program, you may see in the compiler listing that those two arguments have been added at the PROCEDURE DIVISION so you need them in your calling program. I advise for readability that you explicitly write them in your source code.
In the end, it would look like this :
Called program :
PROCEDURE DIVISION USING DFHEIBLK DFHCOMMAREA PARM1 PARM2 ... PARMXX.
Calling program :
WORKING-STORAGE SECTION.
01 PGM-NAME PIC X(8).
PROCEDURE DIVISION.
CALL PGM-NAME USING DFHEIBLK DFHCOMMAREA PARM1 PARM2 ... PARMXX
END-CALL.
Upvotes: 0
Reputation: 16928
There should be some WORKING-STORAGE
in the program where values retrieved from CICS maps is held. For example:
01 SCREEN-DATA.
05 SOME-FIELD PIC X(10).
05 SOME-OTHER-FIELD PIC 9(4).
77 PROGRAM-NAME PIC X(8) VALUE 'PROG2'.
Suppose this program is called PROG1
and you want to pass these values a second COBOL program called PROG2
.
Generally, this is done in COBOL using
a dynamic subroutine call. The typical way of accomplishing a dynamic call is to put the name of the
called program into a WORKING-STORAGE variable. I declared PROGRAM-NAME
for this purpose. Data may be
passed to the called program as individual items:
CALL PROGRAM-NAME USING SOME-FIELD, SOME-OTHER-FIELD
Above is a dynamic call to PROG2
which passes SOME-FILED
and SOME-OTHER-FIELD
by reference.
PROG2
receives these data through its linkage section as follows:
LINKAGE SECTION.
01 LINKAGE-DATA.
05 FIELD1 PIC X(10).
05 FILED2 PIC 9(4).
The PROCEDURE DIVISION of PROG2
would look something like this:
PROCEDURE DIVISION USING FIELD1, FIELD2.
Alternatively, you could pass the whole record as a single parameter from PROG1
:
CALL PROGRAM-NAME USING SCREEN-DATA
and in PROG2
PROCEDURE DIVISION USING LINKAGE-DATA.
Finally, when PROG2
has completed its work it should terminate with a GOBACK
or EXIT PROGRAM
. Do not use STOP RUN
as
this will exit the main program (PROG1
) as well.
COBOL calling conventions are similar to most other procedural languages. Parameters may be passed by reference (the default), by value or by content. Most COBOL vendors support all of these parameter passing mechanisms but may have minor differenes in implementation. The above examples are for IBM Enterprise COBOL. If you are using a different version of COBOL it would be a good idea to check your COBOL Reference Guide and COBOL Programming Guide.
You can get the IBM Enterprise COBOL guides on line: Language Reference Guide and Programming Reference Guide
Upvotes: 4