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

Parameter from JCL to COBOL


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

New User


Joined: 18 Dec 2008
Posts: 15
Location: Hyderabad

PostPosted: Mon Nov 15, 2010 3:54 pm
Reply with quote

Hi ,

I am trying to write a simple cobol program which receives name parameter from JCL and display it from spool.. Im not able to get the desired result.

Cld anyone pls help ..
My cobol program goes like this

Code:
WORKING-STORAGE SECTION.                                       
01 WS-NAME         PIC X(10) VALUE SPACES.                     
LINKAGE  SECTION.                                             
01 PARM-BUFFER.                                               
   05 PARM-LENGTH PIC S9(4) COMP.                             
   05 PARM-NAME   PIC X(10).                                   
PROCEDURE DIVISION USING PARM-BUFFER.                         
    MOVE 'ABC' TO WS-NAME.                                     
    DISPLAY WS-NAME.                                           
    DISPLAY PARM-NAME.                                         
    DISPLAY PARM-LENGTH.                                       
    STOP RUN.


My Exec JCL is as below .

Code:

//STEP1 EXEC PGM=TEST,                                       
//      PARM='XYZ'                                           
//STEPLIB DD DISP=SHR,DSN=DEV.UT3.CICSLOAD                   
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*



Im getting the below result.

ABC

00010

*************
Pls help me how to get XYZ in spool.
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: Mon Nov 15, 2010 5:52 pm
Reply with quote

I took your code and ran it to receive output of
Code:
 ABC
 XYZ.......
 00003
which is exactly as expected. The 10 length in your post indicates a problem -- parameters passed from JCL usually reflect the actual length, not the length of the variable. Which version of the compiler are you using?
Back to top
View user's profile Send private message
sriraj1122

New User


Joined: 18 Dec 2008
Posts: 15
Location: Hyderabad

PostPosted: Mon Nov 15, 2010 7:26 pm
Reply with quote

Hi Robert,

Firstly Thanks for ur response
Even if I change the length of the variable in linkage section im getting the same result.

WORKING-STORAGE SECTION.
01 WS-NAME PIC X(10) VALUE 'ABC'.
LINKAGE SECTION.
01 PARM-BUFFER.
05 PARM-LENGTH PIC S9(2) COMP.
05 PARM-NAME PIC X(06).

And how to know the version of the compiler we are using ???
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: Mon Nov 15, 2010 7:53 pm
Reply with quote

To make this process entirely flexible, define PARM-NAME (or whenever you want to name it) as PIC X(100), which is the maximum parm-size that can be passed from JCL and then define PARM-LENGTH as PIC S9(04) COMP.

Programmatically, you can then determine whether or not a parm had been passed, by checking PARM-LENGTH for a value of GREATER THAN ZERO, in which case, use REFERENCE MODIFICATION to move it to a WORKING-STORAGE field -

Code:

03  WS-PARM-AREA   PIC  X(100)      VALUE SPACES.

IF  PARM-LENGTH > ZERO
    MOVE PARM-NAME TO WS-PARM-AREA (1:PARM-LENGTH)
END-IF.

You should normally define PARM-LENGTH as PIC S9(04) COMP/COMP-4/BINARY/COMP-5, because PIC S9(01) through PIC S9(04) occupies 2-Bytes (halfword-binary), regardless.

Bill
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: Mon Nov 15, 2010 8:33 pm
Reply with quote

On second thought, because the sending field is in LINKAGE, use REFERENCE MODIFICATION on it as well. This will prevent a S0C4 and cause the compiler to build an MVCL, but I'm over it -

Code:

MOVE PARM-NAME (1:PARM-LENGTH) TO WS-PARM-AREA (1:PARM-LENGTH).

Bill
Back to top
View user's profile Send private message
sriraj1122

New User


Joined: 18 Dec 2008
Posts: 15
Location: Hyderabad

PostPosted: Tue Nov 16, 2010 3:13 pm
Reply with quote

Hi Bill,

thnx for ur reply..but when im using reference modification im getting below outut

ABC
" 0 " 0 " 0 " 0 " 0 " 0 " 0 " 0
00010
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 Nov 16, 2010 4:46 pm
Reply with quote

Something's wrong here. If you pass 'ABC' as your JCL parameter, LINKAGE fields PARM-LENGTH will equal X'0003' and PARM-NAME (1:PARM-LENGTH) will equal 'ABC'.

After moving PARM-NAME (1:PARM-LENGTH) to WS-PARM-AREA (1:PARM-LENGTH), WS-PARM-AREA will equal 'ABC', padded with low-order SPACES (leave the VALUE SPACES clause for this field as-is).

This has been working the same way for over 25 years, since the introduction of VS/COBOL II and reference modification.

You must be doing something wrong.

Use the above example and it will work as described.

Bill
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Nov 16, 2010 5:46 pm
Reply with quote

the ts keeps changing from s9(2) comp to s9(4) comp.
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 2
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
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top