Page 1 of 1

COBOL CALL

Posted: Tue Apr 21, 2015 7:06 pm
by Gurugars
Dear friends,

I've a doubt on the below scenario. Please help me out understanding the same.

There is copybook as below

Code: Select all

copybook: COPYMAIN

01 COPY-MAIN.
     05 COPY-INPUT-FIELDS.
          07 INPUT-1 PIC X(02)
          07 INPUT-2 PIC X(03)
          07 INPUT-3 PIC X(04)
     05 COPY-OUTPUT-FIELDS.
          07 OUTPUT-1 PIC X(02)
          07 OUTPUT-2 PIC X(03)
          07 OUTPUT-3 PIC X(04)

.
.
.
PROCEDURE DIVISION.
.
.
.

CALL "PROG1" USING COPY-INPUT-FIELDS.

in the called program (PROG1)

Code: Select all

Linkage section

COPY COPYMAIN

PROCEDURE DIVISION USING COPY-MAIN.

           Move values for OUTPUT-* fields and Go BACK

Now, I have few questiosn on this.

I've called the program using part of the copybook variables, and in return I'll receive the data in output variables too. This is working fine for me. But is it a effective way.? Should I call the program with COPY-MAIN.? what is the difference if I'm calling with COPY-MAIN and COPY-INPUT-FIELDS.

Posted: Tue Apr 21, 2015 10:36 pm
by William Collins
With the copybook as it is at the moment, you will get the same results using COPY-MAIN or COPY-INPUT-FIELDS. This is because the start addresses of those two fields coincide.

It is much better to use COPY-MAIN in the CALL ... USING ... 1) it is clearer to the human reader 2) if someone defines data before COPY-INPUT-FIELDS, so the addresses no longer coincide, then it will no longer work.

There are no other differences. I'd also suggest that when defining new copybooks, if site standards allow, do so without the 01-level, so that it can be defined with different 01-level names.

Posted: Wed Apr 22, 2015 11:50 am
by Gurugars
Thanks William. This solves my doubts.