Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Returning value from subroutine in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
pradeep_singhm

New User


Joined: 01 Oct 2005
Posts: 9
Location: bangalore

PostPosted: Tue Oct 25, 2005 12:43 pm    Post subject: Returning value from subroutine in cobol
Reply with quote

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
View user's profile Send private message

suganthyprabha

New User


Joined: 28 Jul 2005
Posts: 58

PostPosted: Tue Oct 25, 2005 2:58 pm    Post subject: Re: Returning value from subroutine in cobol
Reply with quote

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
View user's profile Send private message
ikumar

New User


Joined: 02 Aug 2005
Posts: 81

PostPosted: Tue Oct 25, 2005 3:49 pm    Post subject: Re: Returning value from subroutine in cobol
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us