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

Calling sub program using CALL verb


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

New User


Joined: 07 Aug 2008
Posts: 10
Location: chennai

PostPosted: Fri Apr 06, 2012 4:37 pm
Reply with quote

Hi,

My main program is A

I am calling a sub program B as below;

Code:
CALL BRX03-PGM USING  WS-ACCOUNT-NUMBER   
                      WS-CBR-HIT-NUM       
                      API-CBR-DETAIL       
                      RQ-PROC-RETURN-STATUS

My sub program has linkage varible as below;
Code:
01  WS-ACCOUNT-NUMBER             PIC X(18).       
01  WS-CBR-HIT-NUM                PIC 9(02).       
01  API-CBR-DETAIL.                                 
    10  API-CBR-HIT                    PIC 9(02).   
    10  API-CBR-LEN                    PIC 9(08).   
    10  API-CBR-RPT                    PIC X(204800).
01  RQ-PROC-RETURN-STATUS          PIC S9(06) COMP.


and procedure division as :

Code:
PROCEDURE DIVISION USING WS-ACCOUNT-NUMBER     
                         WS-CBR-HIT-NUM       
                         API-CBR-DETAIL       
                         RQ-PROC-RETURN-STATUS.

But the values are not passed correctly.
In main program,
Code:
WS-ACCOUNT-NUMBER is 9632900XXXXXXXXA84.

But in sub program, it is displayed as all Zeroes.

Please let me know if anything is going wrong in calling subprogram and passing values.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 06, 2012 4:43 pm
Reply with quote

No, calling Cobol sub-programs s something that happens scrillions of times a day.

You've coded something wrong that you haven't yet showed us.

From what you have shown your linkage is correct. You haven't shown why you would think it is wrong.
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 Apr 06, 2012 8:19 pm
Reply with quote

Hello,

The use of WS* field names in the linkage section is confusing at best. . .

Suggest a different prefix (i.e. lk- or link-) for the linkage section variables to make the code more understandable and maintainable.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 06, 2012 8:39 pm
Reply with quote

You only gave us 3/4 of the necessary data -- what do the variables look like in the CALLING program?
Back to top
View user's profile Send private message
malathys

New User


Joined: 07 Aug 2008
Posts: 10
Location: chennai

PostPosted: Mon Apr 09, 2012 4:12 pm
Reply with quote

Hi All,

Thanks for your response. I am not sure where I am going wrong. If everything is ok, then the values should get passed to sub-program from the main program. But all values are passed as Zeroes or getting reset when going into the sub-program. I am not initializing the variales anywhere in sub-program.

Here is the varible declaration in main-program:
Code:
01 WS-ACCOUNT-NUMBER        PIC  X(18).
01 CBR-HIT-NUM               PIC  9(02).
01  API-CBR-DETAIL.                                 
    10  API-CBR-HIT                    PIC 9(02).   
    10  API-CBR-LEN                    PIC 9(08).   
    10  API-CBR-RPT                    PIC X(204800).
01 RQ-PROC-RETURN-STATUS PIC S9(06) COMP.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 09, 2012 4:22 pm
Reply with quote

How/when are you getting values into those fields in the calling program?

How do you know (show the code and relating to the CALL statement) what the account number contains before the call?

How do you know what it contains inside the called program?

The last one like this that I remember, the fields were being set and then the ADDRESS of the whole thing was being changed with a SET statement. You doing anything like that?
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: Mon Apr 09, 2012 8:27 pm
Reply with quote

Hello,

What is shown is you DISPLAY the account-number immediately before the CALL and also display the account-number as the first executable instruction in the called module?

I suspect there may be multiple definitions for the problem fields. . . Or an addressing problem . . .
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Apr 09, 2012 8:36 pm
Reply with quote

Are either of these CICS programs? Have you looked at the output listing of the compiles to see if the CALL USING matches up with PROCEDURE DIVISION USING?
Back to top
View user's profile Send private message
malathys

New User


Joined: 07 Aug 2008
Posts: 10
Location: chennai

PostPosted: Tue Apr 10, 2012 3:32 pm
Reply with quote

I just tried decalring all the variables under group variable to avoid confusion. CBR-RPT-RETRIEVE is the group variable.

calling pgm:
***********
Code:
MOVE API-ACCOUNT-NUMBER TO CBR-ACCT-NUM.
MOVE API-CBR-HIT-NUM TO CBR-HIT-NUM.     
                                         
DISPLAY 'CBR-ACCT-NUM:'  CBR-ACCT-NUM   
DISPLAY 'CBR-HIT-NUM :'  CBR-HIT-NUM     

CALL BRX03-PGM USING  CBR-RPT-RETRIVE


called program:
************
Code:
Linkage section:
01  CBR-RPT-RETRIVE.                                     
    05 CBR-ACCT-NUM                       PIC  X(18).   
    05 CBR-HIT-NUM                        PIC  9(02).   
    05 CBR-DETAIL.                                       
        10  CBR-HIT                       PIC 9(02).     
        10  CBR-LEN                       PIC 9(08).     
        10  CBR-RPT                       PIC X(204800).
    05 HRCR-RETURN-STATUS                 PIC S9(6) COMP.

Procedure division is coded as:
PROCEDURE DIVISION USING CBR-RPT-RETRIVE


I am using trace master tool to track what it had in calling program and what it has in called program. By that way I could see that my valuesa re getting reset. And I am not resettin the values either by address of variables or varibale itself.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 10, 2012 3:37 pm
Reply with quote

And the output from the displays is?

And where are the displays in the called module? And their output?

And have you answered all Craq's questions?
Back to top
View user's profile Send private message
malathys

New User


Joined: 07 Aug 2008
Posts: 10
Location: chennai

PostPosted: Tue Apr 10, 2012 4:20 pm
Reply with quote

Yes everything matches. call using and procedure division using both matches. This is not a CICS program. This is COBOL-DB2 program.

In Called module, I have not put displays. I am debugging using trace master tool. I am adding watch variables in it and tracking the variables. There I could see that the variables are getting reset.

Also, I am having a logic in called module to search a table if account number in able matches the account number passed in program. There I could see that it is searching for account number all Zeroes in table and the condition not satisfying which returned SQL +100.
Back to top
View user's profile Send private message
Naish

New User


Joined: 07 Dec 2006
Posts: 82
Location: UK

PostPosted: Tue Apr 10, 2012 4:37 pm
Reply with quote

I feel you might have INITIALIZEd the linkage variable/s somewhere. Anyway too early to comment since only you are aware of your code/processing. It would be helpful to all if you can share more details.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 10, 2012 4:39 pm
Reply with quote

OK, so what do you see as the values when the called program is entered?

Nothing is getting "reset", which would mean set back to some starting value. Something may well be being changed, but then that is likely down to the code in the program.

If the values are correct when the program is entered, then something is changing the values (or where they are) in the program or in another program which is called (if there are any).
Back to top
View user's profile Send private message
Ron Masters
Currently Banned

New User


Joined: 21 Dec 2011
Posts: 24
Location: UK

PostPosted: Tue Apr 10, 2012 5:28 pm
Reply with quote

Insert this statement
Code:
DISPLAY CBR-ACCT-NUM
immediately before your CALL statement. This will show you what you are passing.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Apr 10, 2012 8:11 pm
Reply with quote

You're passing four arguments to the sub-program so therefore, in the sub-program LINKAGE Section you MUST specify four parameters, matching the Called program arguments exactly, but represented as 01 levels.

In the PROCEDURE Division of the Called sub-program, the USING must specify these four parameters.

In the Assembler under the covers, the Calling program builds a 16-Byte PARMLIST, which consists of the four argument addresses and is subsequently pointed to by R1 (Register 1) before the CALL (which is a BALR 14,15).

When the sub-program gains control, the PARMLIST is addressed and each four-byte address is assigned to each 01 level in Linkage.

The number of arguments passed by the Calling program in the USING must be matched by the same number of parms, defined as 01 level items in the Called sub-program.

Confused at best.... icon_eek.gif
Back to top
View user's profile Send private message
Ron Masters
Currently Banned

New User


Joined: 21 Dec 2011
Posts: 24
Location: UK

PostPosted: Tue Apr 10, 2012 8:18 pm
Reply with quote

Have you checked you linked the right object modules together?
Back to top
View user's profile Send private message
pvmr moorthy

New User


Joined: 12 Apr 2012
Posts: 1
Location: india

PostPosted: Thu Apr 12, 2012 10:05 am
Reply with quote

Hi,

Try to initialize the values of working storeage variable with some default values.... And try to use the display statement for the 01 level.

It will clear about the confusion that values are initializing inside the procedure or not.....
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 Using API Gateway from CICS program CICS 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
No new posts Calling an Open C library function in... CICS 1
No new posts DB2 Event passed to the Application P... DB2 1
Search our Forums:

Back to Top