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

Linkage Section for Three programs


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

New User


Joined: 16 Jun 2005
Posts: 63

PostPosted: Sat Jun 01, 2013 7:21 pm
Reply with quote

Hi,

I have a basic question in getting a value from a COBOL program.

Let us say Program A calls Program B and Program B calls Program C. Now, I do not want to send any values from A to B or B to C. I actually want to receive a value from Program C which sets in program C. So obviously it has to come through program B to program A. Based on the value which I have received from Program C, I want to write some conditions in Program A.

I have coded in the usual way as below.

Program A

Declared WS in program A
Call program B using WS

Program B
Declared LS in program B with the same structure as Program A
Procedure division using LS
Call program C using LS

Program C
Declared LS in program C with the same structure
Procedure division using LS
Set a value to one of the variables of LS based on some condition

I'm expecting the value got set in program C has to be returned to program A. But I end up with S0C4. I understand I made some silly mistake some where. But not sure whether we have handle some special declarations in this situation. Any help is appreciated.

Thanks
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: Sat Jun 01, 2013 9:42 pm
Reply with quote

Your situation is far from unusual, and what you have described should work.

It means you have made a mistake in the code. Review it. If you still can't find it, you'll need to post the code: the definitions (including which part of the DATA DIVISION they are in), the CALL and the PROCEDURE DIVISION USINGs.
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: Sun Jun 02, 2013 3:30 am
Reply with quote

Hello,

When does the 0c4 happen? In which module?

Possible the MOVE in C?
Back to top
View user's profile Send private message
Mr.Niceguy

New User


Joined: 16 Jun 2005
Posts: 63

PostPosted: Sun Jun 02, 2013 6:14 am
Reply with quote

Hi,

I do not have code handy now to paste here. But I basically use it to switch the flag.

01 WS-SWITCH FLAG.
05 DEFAULT-FLAG PIC X(01) VALUE 'N'.
88 SET-FLAG VALUE 'Y'.

The same structure has been declared in all other sub modules as I have explained earlier. Then the flag is getting set in Program C and Im getting 0C4 in program C.

I tried it by setting in couple of the ways.

a) MOVE 'Y' TO DEFAULT-FLAG.
B) SET SET-FLAG TO TRUE.

Both are ending up with same 0C4 error.

Thanks in advance.
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: Sun Jun 02, 2013 3:05 pm
Reply with quote

As I said, if you have done it exactly as you have described, you will not get a S0C4. Since you get a S0C4, something is not as you have described.

There is no need for the name of the structure to be the same throughout the programs. Indeed, it will be confusing if you have something in the LINKAGE SECTION which is prefixed "WS". The names of items "passed" from one program to another do not matter.

Code:

01  B1 PIC X.
01  B2 PIC X.
01  B3 PIC X.
CALL A USING B1, B2, B3

PROGRAM-ID A.

LINKAGE SECTION.
01  C2 PIC X.
01  C3 PIC X.
01  C1 PIC X.
PROCEDURE DIVISION USING C1 C2 C3.


For the CALL to work, the names of the data are not relevant, nor is the order in which they are defined in either the LINKAGE SECTION or the WORKING-STORAGE SECTION.

The only thing that is important is the order on the CALL ... USING ... and the PROCEDURE DIVISION USING ... The order must be the same.

If you have:

Code:
CALL A USING B1, B2

and

PROCEDURE DIVISION USING C1, C2, C3


Then you will (likely) have S0C4, even if the name C3 is identical to the name B3 that you failed to mention on the CALL.

This is the most likely problem, in either your first or second program.

Next most likely is that you are using SET ADDRESS OF for your data item, and you are giving an incorrect value (impossible, of course, if you are not using SET ADDRESS OF for that data item).

Least likely by far are various weirdnesses caused by "stepping on storage". Only consider these once you've shown good code that should work, but still doesn't.
Back to top
View user's profile Send private message
Mr.Niceguy

New User


Joined: 16 Jun 2005
Posts: 63

PostPosted: Sun Jun 02, 2013 10:07 pm
Reply with quote

Hi Bill,

Thanks for your help. I think I have to review my code in the Order on the call and the Order in which they defined. There are lots of other declarations in the linkage sections. I would have done some mistake in that portion.

Thanks again for all your help. You guys are awesome.
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 Jun 03, 2013 12:40 pm
Reply with quote

I just want to stress again, concentrate on both the USINGs.

The order of data definition in the DATA DIVISION does not matter at all.

A simple way to get your problem is this:

Code:
CALL APROGRAM USING A, B

PROCEDURE DIVISION USING X, Y, Z


Somewhere along the way, Z, although no longer used, was never removed from the USING. Then another data item is simply added "to the end" of the PROCEDURE DIVISION USING and the CALL ... USING, without realising that there were fewer parameters on the CALL ... USING
Code:
CALL APROGRAM USING A, B, NEWW-S

PROCEDURE DIVISION USING X, Y, Z, NEWL


Referencing NEWL will, likely, get a S0C4.
Back to top
View user's profile Send private message
Mr.Niceguy

New User


Joined: 16 Jun 2005
Posts: 63

PostPosted: Tue Jun 04, 2013 9:25 am
Reply with quote

Thanks Bill,

I checked the order, it is all one and the same in all the programs. There are no differences in it. I was getting the same error. Not sure what is wrong and it is just drilling my head.

Will something be there in the static and dynamic call? Because Program A calls B statically and program B calls C dynamically. When I made a slight change in the program B today, the S0C4 started showing in the program B. Below Highlighted are the modification done.

Program A

Declared WS in program A
Call program B using WS

Program B
Declared LS in program B with the same structure as Program A
Declared WS in program B with the same structure

Procedure division using LS
Call program C using WS

MOVE WS to LS

Program C
Declared LS in program C with the same structure
Procedure division using LS
Set a value to one of the variables of LS based on some condition

Once I did the slight changes in the program B, I could receive the value in program B which got set in program C.
But the S0C4 end up in the move statement which I have added newly in the program B. If I could receive the value to Program B, why not to program A. Something is stopping it to get moved to program A. I thoroughly checked the order USING in both CALL and PROCEDURE DIVISION. I will definitely figure this out, but suggestions and help are appreciated.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Tue Jun 04, 2013 11:03 am
Reply with quote

Do you mind pasting the complete code of those three programs?
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 Jun 04, 2013 11:28 am
Reply with quote

Yes, the all the relevant code. Definition of all fields on the CALL ... USING ..., the CALL itself (any and all of them to that program) the definition of the fields on the PROCEDURE DIVISION USING ... and the PROCEDURE DIVISION USING ... itself. Forget program C for now, you have shown that the problem is in program A or program B.

There is no difference between a static or a dynamic CALL for this.
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: Tue Jun 04, 2013 9:31 pm
Reply with quote

Hello,

Suggest you put some DISPLAYs in the modules. Make sure that you are "passing" what you believe you are passing and working with.

It very much sounds like there is a parameter mis-match.
Back to top
View user's profile Send private message
Mr.Niceguy

New User


Joined: 16 Jun 2005
Posts: 63

PostPosted: Wed Jun 05, 2013 5:08 pm
Reply with quote

Hi Dick,

Yes, I put 100 displays to see the flow of the programs and identified the root cause of S0C4. Program C is being called by program B again to process the footer record which made all the mess and where I identify the parameter mis-match. Sorry for troubling you all and finally I conclude the S0C4 is because of the parameter mis-match.

I fixed it and it is working as expected icon_smile.gif.

Thanks again for all your help and suggestions. icon_biggrin.gif
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Jun 05, 2013 5:28 pm
Reply with quote

Glad you figured it out :-)

It is always better if you develop the art of debugging so these issues are resolvable by you at first hand
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 Jun 05, 2013 6:59 pm
Reply with quote

Good to hear it is working - thank you for posting the resolution icon_smile.gif

Good Luck!

d
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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts Fetch data from programs execute (dat... DB2 3
No new posts Passing Parameters to Programs Invoke... PL/I & Assembler 5
No new posts Finding Assembler programs PL/I & Assembler 5
Search our Forums:

Back to Top