IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How CALL statement works in Cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
teethu thomas

New User


Joined: 17 May 2007
Posts: 24
Location: India

PostPosted: Fri May 18, 2007 10:14 am
Reply with quote

Hi,
Can somebody help me with Call statement in Cobol.

I want to know when we pass more than one group variables in the CALL statemnt ( while calling a subroutine ) how the data with in the variables get moved to the called program. Is it getting moved as a byte stream or is it gets moved variable vise.

Just see this example

Call 'abc' using xyz
yxz
zxy.


Suppose this xyz is a group variable of size 50
yxz is a group variable of size 75
zxy is a group variable of size 75

In the called program it is like

Procedure Division USING xyz
cde
ght.


Xyz size 50
cde size 150
ght size 75.

Will the data coming from the zxy go into cde or will it come into ght as we want it.
Back to top
View user's profile Send private message
rameshfoa

New User


Joined: 05 Apr 2007
Posts: 27
Location: chennai

PostPosted: Fri May 18, 2007 12:03 pm
Reply with quote

I believe they are moved variable wise....so zxy would come into ght...also....if a variable in called program has less size than that of calling program...then it will not ovrwrite in next variable instead truncated...

ex,

calling pgm,

xyz is 50
yxz is 75
zxy is 75

called pgm,
xyz is 50
cde is 50
ght is 75


then...part of yxz will not overwrite in ght...instead truncated...
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri May 18, 2007 1:26 pm
Reply with quote

Quote:
Is it getting moved as a byte stream or is it gets moved variable vise.

What did your book say about call?
If you haven't read the book yet then read it first. You will find about CALL BY REFERENCE AND CALL BY VALUE, then you may understand 'call' and 'your own question'.
Back to top
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Fri May 18, 2007 5:53 pm
Reply with quote

CALL in cobol will work as mention below example :

In Variable mention in CALL USING of Main program should be same order as in the linkage section of Sub program , If u interchange the variable in CALL USING corresponding changes to made in the Linkage section OF SUB PROGRAM ,If not then S0C7 abend occurs due to mismatch move occurs

Example :

Main Program :

Code:


WORKING STORAGE SECTION :

 01  CALL-VARIABLE1      PIC X(100)
 01  CALL-VARIABLE2      PIC X(200)
 COPY COPBOOK-NAME

PROCDURE DIVISION:
 
 CALL SUB-PROGRAM NAME USING CALL-VARIABLE1,
                                                    CALL-VARIABLE2,
                                                    COPYBOOK-NAME.



In Sub Program :
Example:

Code:
         
LINKAGE SECTION:
 01  CALL-VARIABLE1      PIC X(100)
 01  CALL-VARIABLE2      PIC X(200)
 COPY COPBOOK-NAME

PROCEDURE DIVSION.
U can use the variable
MOVE CALL-VARIABLE1  TO WS-VARIABLE-NAME.

....


When ABEND Occurs :

Code:
         
LINKAGE SECTION:
  01  CALL-VARIABLE2      PIC X(200)
  01  CALL-VARIABLE1      PIC X(100)
  COPY COPBOOK-NAME

PROCEDURE DIVSION.
U can use the variable
MOVE CALL-VARIABLE1  TO WS-VARIABLE-NAME.

....


Because CALL-VARIABLE1 of 100 bytes moved to 200 bytes of CALL-VARIABLE2 and vicevesa ...

I think u can understand about the CALL
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri May 18, 2007 7:18 pm
Reply with quote

ramfrom84 wrote:
In Variable mention in CALL USING of Main program should be same order as in the linkage section of Sub program , If u interchange the variable in CALL USING corresponding changes to made in the Linkage section OF SUB PROGRAM ,If not then S0C7 abend occurs due to mismatch move occurs
No, they must be in the same order listed on the procedure division line (which you failed to list), but in the linkage section, any order is fine..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 18, 2007 11:56 pm
Reply with quote

Hello,

For this
Quote:
Is it getting moved as a byte stream or is it gets moved variable vise.


Most of the time the data is not moved at all. The called program linkage/using establishes addressability back to the data in the calling program.

Said differently, there is usually only one copy of those data fields.

As was suggested previously, you may want to read more in the manual (which you can link to from this site).
Back to top
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Mon May 21, 2007 3:07 pm
Reply with quote

Sorry.. some code was missing,

Some of member said above , The Call using structure and procedure division using should be same since i have tested. It can't be different .
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon May 21, 2007 6:00 pm
Reply with quote

Quote:
Some of member said above , The Call using structure and procedure division using should be same since i have tested.

what did you test? Please paste the code so that we can understand your point and can give suggestions if needed...
Back to top
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Tue May 22, 2007 8:20 pm
Reply with quote

Hi ,
when i code the program , i want to add new linkage section , i got this abend,, See teh sample code below


In the call i mention as below

Code:

CALL SUB-PROGRAM NAME USING CALL-VARIABLE1,
                                                    CALL-VARIABLE2,
                                                    CALL-VARIABLE3,
                                                    COPYBOOK-NAME.


Similar i mention the procdure division as below
Code:

PROCEDURE DIVSION USING       CALL-VARIABLE1,
                                                    CALL-VARIABLE2,
                                                    COPYBOOK-NAME
                                                    CALL-VARIABLE3.

 


S0C7 Abend occurs due to mismatch in data , When i look into the program i find CALL-VARIABLE3 is moved to COPYBOOK_NAME.Then i correct and run it..

so the order given in the call and Procedure must be same.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed May 23, 2007 12:07 am
Reply with quote

Hello,

Quote:
so the order given in the call and Procedure must be same.

Yes.

Keep in mind that when the CALL is executed the parm list not being passed based on names - what is passed is a list of addresses. The compiler needs the names to resolve lengths and displaces, but the run-time does not use names. You must ensure the calling and called modules are in sync.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top