Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 ISREDIT Macro is not returning back t... nico_neoz CLIST & REXX 4 Sat Nov 18, 2017 7:40 pm
This topic is locked: you cannot edit posts or make replies. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm
No new posts VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts COBOL - EXIT statement weird behavior anthony.pangestu COBOL Programming 0 Fri Oct 27, 2017 9:57 am
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us