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

COBOL Sub Program Value Passing


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

Active User


Joined: 21 Mar 2007
Posts: 203
Location: India

PostPosted: Thu Oct 22, 2009 4:38 pm
Reply with quote

Hi,

Let us say that JCL passes the operation date to my main COBOL program (referred as A from now on).

This program A calls a sub-program (referred as B from now on).

Now, in B i have a count declared as RECORD-COUNT PIC 9(9) in Linkage section. The value of this is say 001560626.

Now, when I am referring this variable in A, the value changes to 260015606. Can any one please let me know, where exactly I m going wrong.
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: Thu Oct 22, 2009 4:49 pm
Reply with quote

Line 379 of program B.
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: Thu Oct 22, 2009 4:51 pm
Reply with quote

Since you didn't post anything about the parameters passed from A to B, nor how B has them defined, nor anything else code related, just what kind of answer are you expecting us to give you, other than wild guesses? If you give us code (use BBcode please) -- and please do not extract what you think we need to know, give us the relevant sections as they are in the program -- we can provide a better answer.
Back to top
View user's profile Send private message
swapnadeep.ganguly

Active User


Joined: 21 Mar 2007
Posts: 203
Location: India

PostPosted: Thu Oct 22, 2009 5:00 pm
Reply with quote

Main Program A:
Code:

WORKING STORAGE SECTION
05  FILE-NAME                         PIC X(50)  VALUE SPACES.
05  RECORD-COUNT                PIC  9(09) VALUE ZEROES. 
.
.
LINKAGE SECTION.
01  LINK-AREA.
    05  PARM-LENGTH              PIC S9(04) COMP.       
    05  PARM-DATE.                                   
        10  PARM-DATE-YY    PIC  9(02) VALUE ZEROS.
        10  PARM-DATE-MM    PIC  9(02) VALUE ZEROS.
        10  PARM-DATE-DD    PIC  9(02) VALUE ZEROS.

PROCEDURE DIVISION USING LINK-AREA.
CALL "B" USING             
             BY REFERENCE FILE-NAME
             BY REFERENCE RECORD-COUNT

DISPLAY 'RECORD COUNT RCVD: ' RECORD-COUNT 




Declaration in Program B:
Code:

LINKAGE SECTION.                                         
01  LINK-AREA-SUBPROG.                                   
    05  PARM-LENGTH              PIC S9(04) COMP.         
    05  PARM-RECORD.                                     
        10  PARM-RECORD-COUNT    PIC  9(09) VALUE ZEROS. 
    EJECT.                                               

PROCEDURE DIVISION USING FILE-NAME       
                         LINK-AREA-SUBPROG.
.
.
.
.
MOVE WS-RECORDS-PROCESSED  TO PARM-RECORD-COUNT
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: Thu Oct 22, 2009 5:07 pm
Reply with quote

Based on what you've posted, your problem is that program B says USING FILE-NAME LINK-AREA-SUBPROG but FILE-NAME is not an 01 or 77 level in the LINKAGE SECTION. Section 6.1.2.1 of the COBOL Language Reference manual (link at the top of the page) explicitly states that each variable in a USING must be an 01 or 77 level in the LINKAGE SECTION.
Back to top
View user's profile Send private message
swapnadeep.ganguly

Active User


Joined: 21 Mar 2007
Posts: 203
Location: India

PostPosted: Thu Oct 22, 2009 9:19 pm
Reply with quote

Hi,

Even after making the following changes in Sub-Program B, I am still getting the same error:
Code:

LINKAGE SECTION.                                         
01  LINK-AREA.                                   
    05  PARM-LENGTH              PIC S9(04) COMP.         
    05  PARM-RECORD.                                     
        10  FILE NAME            PIC  X(50) VALUE SPACES. 
01  LINK-AREA-SUBPROG.                                   
    05  PARM-LENGTH              PIC S9(04) COMP.         
    05  PARM-RECORD.                                     
        10  PARM-RECORD-COUNT    PIC  9(09) VALUE ZEROS. 
    EJECT.                                               

PROCEDURE DIVISION USING LINK-AREA       
                         LINK-AREA-SUBPROG.
.
.
.
.
MOVE WS-RECORDS-PROCESSED  TO PARM-RECORD-COUNT
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Thu Oct 22, 2009 9:40 pm
Reply with quote

swapnadeep.ganguly wrote:
Hi,

Even after making the following changes in Sub-Program B, I am still getting the same error:
Code:

LINKAGE SECTION.                                         
01  LINK-AREA.                                   
    05  PARM-LENGTH              PIC S9(04) COMP.         
    05  PARM-RECORD.                                     
        10  FILE NAME            PIC  X(50) VALUE SPACES. 
01  LINK-AREA-SUBPROG.                                   
    05  PARM-LENGTH              PIC S9(04) COMP.         
    05  PARM-RECORD.                                     
        10  PARM-RECORD-COUNT    PIC  9(09) VALUE ZEROS. 
    EJECT.                                               

PROCEDURE DIVISION USING LINK-AREA       
                         LINK-AREA-SUBPROG.
.
.
.
.
MOVE WS-RECORDS-PROCESSED  TO PARM-RECORD-COUNT


When calling a subprogram you don't normally have a length for each passed value. In the main program you have a length because the data is being passed from the system.

You sub program linkage should look like this
Code:
LINKAGE SECTION.                                         
01   FILE NAME            PIC  X(50).
01   PARM-RECORD-COUNT    PIC  9(09). 
Back to top
View user's profile Send private message
swapnadeep.ganguly

Active User


Joined: 21 Mar 2007
Posts: 203
Location: India

PostPosted: Thu Oct 22, 2009 10:47 pm
Reply with quote

Thanks for pointing out my mistake.

I made the changes as suggested by you and the same worked....
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 3
No new posts Using API Gateway from CICS program CICS 0
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
Search our Forums:

Back to Top