Page 1 of 1

CALL MEMORY

PostPosted: Sat Dec 06, 2008 1:55 am
by gurzi
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!

Re: CALL MEMORY

PostPosted: Sat Dec 06, 2008 3:28 am
by dick scherrer
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.

Re: CALL MEMORY

PostPosted: Sat Dec 06, 2008 4:03 am
by gurzi
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

Re: CALL MEMORY

PostPosted: Sat Dec 06, 2008 4:19 am
by dick scherrer
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.

Re: CALL MEMORY

PostPosted: Sat Dec 06, 2008 4:27 am
by gurzi
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.

Re: CALL MEMORY

PostPosted: Sat Dec 06, 2008 5:09 am
by dick scherrer
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.