CALL MEMORY



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

CALL MEMORY

Postby gurzi » Sat Dec 06, 2008 1:55 am

Hello Guys,

This is my first post here and i will start my adventure here with a question ( easy one ) about call statement.

I learnt that when we use the call statement we have to pass the same parameters to the procedure division of the callable program, something like:

-> CALL XPTO using PARM1 PARM2 PARM3

So, we need to :

-> Procedure division using PARAM1 PARAM2 PARAM3

But today i saw a program passing 6 PARAMS and the callable program was only receiving 4 in the procedure division . How does it work ? I thought that would crash, am i wrong ? :s

Another doubt, and this is a stupid doubt that are freaking my mind:

Working Storage :

01 PARAM-1 PIC X (32140).
01 PARAM-2 PIC X (32140).
01 PARAM-3 PIC X (32140).

CALL xpto using PARAM-1 PARAM-2 PARAM-3

On the XPTO program they have

PROCEDURE DIVISION USING VAR1 VAR2 VAR3

And on the linkage they are declared something like this

01 VAR1 PIC X (400).
01 VAR2 PIC X (400).
01 VAR3 PIC X (400).

Did you notice that we are actually passing 32140 for each parameter and only receiving 400 for each one ? IDoes t's supposed to work ? HOW ? Compiler tricks ? or just normal ? :ugeek:

Thanks a lot!
gurzi
 
Posts: 4
Joined: Sat Dec 06, 2008 1:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: CALL MEMORY

 

Re: CALL MEMORY

Postby dick scherrer » Sat Dec 06, 2008 3:28 am

Hello and welcome to the forum,

Keep in mind that in your example no data is passed.

When pgmA calls pgmB using some fields, all that pgmB sees is the address to the fields named in the call. There is only one set of the data, not 2. The linkage section and the "using" support the addressability of the data.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: CALL MEMORY

Postby gurzi » Sat Dec 06, 2008 4:03 am

Hmm... But i have values defined in the real case.


I dindt understand, can i pass more params that the ones declared in the callable program ? Call with 4 parms and receive in the procedure only 2 ?


I really didnt understand what did you mean with my question of passing a field with 31240 ( WITH DATA ) to one of just 400 :S

Sorry
gurzi
 
Posts: 4
Joined: Sat Dec 06, 2008 1:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: CALL MEMORY

Postby dick scherrer » Sat Dec 06, 2008 4:19 am

Hello,

my question of passing a field with 31240 ( WITH DATA ) to one of just 400 :S
You are not passing 31240 bytes to 400. You are passing the address of 31240 bytes to the called module.

can i pass more params that the ones declared in the callable program ? Call with 4 parms and receive in the procedure only 2 ?
Yes. Again, you are not passing the actual data, just the address of the data back in the calling program.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: CALL MEMORY

Postby gurzi » Sat Dec 06, 2008 4:27 am

OK thanks.


But if i pass two address of memorry of 32140 each one, and if within the callable program i receive 2 params of 400, it's not supposed to access of the 800bytes of the first 32140 , or it just acces of the first 400bytes of each 31240 passed ? :X

Sorry my questions but i'm a quite new to cobol programming and i'm trying to defeat some doubts.
gurzi
 
Posts: 4
Joined: Sat Dec 06, 2008 1:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: CALL MEMORY

Postby dick scherrer » Sat Dec 06, 2008 5:09 am

Hello,

Sorry my questions but i'm a quite new to cobol programming and i'm trying to defeat some doubts.
Not to worry. We're here to help defeat those doubts :)

if within the callable program i receive 2 params of 400
Once more (and possibly not the last time ;) ) the called program does not "receive 2 params of 400". When the called module is invoked/entered, addressability is established to the actual data in the calling program. The data is not "moved" to the called module. In your example, the called module would be able to use the first 400 bytes of the first 2 parms.

Because of this it is very important that the caller and the called use the same definitions.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post