View previous topic :: View next topic
|
Author |
Message |
pradeep_singhm
New User
Joined: 01 Oct 2005 Posts: 9 Location: bangalore
|
|
|
|
hi
i have sub1 and main program i am passing xyz variable to sub1
and i am doing some calculations in sub1 but i want to return the result
through the variable result1 how to do this please explain me in detail
with code please
wheather i have to pass the result1 from main to sub1 or i have declare in
sub1 then pass it or main ?
thanks in advance to all
pradeep singh |
|
Back to top |
|
|
suganthyprabha
New User
Joined: 28 Jul 2005 Posts: 58
|
|
|
|
Hi Pradeep,
Try the foll code.
Main program:
IDENTIFICATION DIVISION.
PROGRAM-ID. PRO1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 A PIC 9(3).
77 B PIC 9(3).
77 C PIC 9(4).
PROCEDURE DIVISION.
PARA.
DISPLAY ' I AM IN CALLING PROGRAM:'.
DISPLAY ' ENTER THE VALUES OF A AND B:'.
ACCEPT A.
ACCEPT B.
CALL 'SUB' USING A B C.
CANCEL 'SUB'.
DISPLAY ' AGAIN I AM IN CALLING PROGRAM:'.
DISPLAY ' THE VALUE OF C IS: C.
STOP RUN.
Sub Program:
IDENTIFICATION DIVISION.
PROGRAM-ID. SUB.
DATA DIVISION.
LINKAGE SECTION.
77 A PIC 9(3).
77 B PIC 9(3).
77 C PIC 9(4).
PROCEDURE DIVISION USING A B C.
PARA.
DISPLAY ' I AM IN SUB PROGRAM:'.
COMPUTE C = A + B.
EXIT PROGRAM.
Correct me if i am wrong.
Thanks and Regards,
Suganthy. |
|
Back to top |
|
|
ikumar
New User
Joined: 02 Aug 2005 Posts: 81
|
|
|
|
Yes you can return the values as suganthy said...Have all the variables that need to be passed and need to be returned in the CALL statement...
(OR)
You can also use PROCEDURE DIVISION RETURNING DATA phrase in called program to return information to the calling program.
code CALL .... RETURNING WS-DATA in the calling program.
Cheers,
Kumar. |
|
Back to top |
|
|
|