Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

how to pass variable length dynamically in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sarath16581

New User


Joined: 11 Jun 2005
Posts: 8

PostPosted: Mon Oct 13, 2008 3:53 pm    Post subject: how to pass variable length dynamically in cobol
Reply with quote

Hi,

Can i pass length of a variable in a cobol program dynamically from outside? If its possible can anyone suggest me how to do this?
Back to top
View user's profile Send private message

Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Oct 13, 2008 4:41 pm    Post subject:
Reply with quote

Do you mean JCL PARM or other cobol program?
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Mon Oct 13, 2008 4:46 pm    Post subject: Reply to: how to pass variable length dynamically in cobol
Reply with quote

Hi,
Please elaborate a little more on your requirement.

Cris
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1226
Location: Israel

PostPosted: Mon Oct 13, 2008 4:47 pm    Post subject: Reply to: how to pass variable length dynamically in cobol
Reply with quote

You can use the same format that DB2 uses for its VARCHAR fields:
Code:
10  MY-VAR-FIELD.
    49  MY-VAR-FIELD-LNG   PIC S9(4) COMP.
    49  MY-VAR-FIELD-TEXT  PIC X(1700).

Such a field can be passed to your program in many ways:
in a dataset, a DB2 table, as a parameter in a calling program
and so on.

Is that what you need ?
Back to top
View user's profile Send private message
sarath16581

New User


Joined: 11 Jun 2005
Posts: 8

PostPosted: Mon Oct 13, 2008 10:38 pm    Post subject: Reply to: how to pass variable length dynamically in cobol
Reply with quote

To explain in detail if i have a working storage variabe with pic x(25). Can i pass the length 25 externally through JCL or in some other way. Can i declare 25 as some other variable and pass it from outside.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7992
Location: Bellevue, IA

PostPosted: Mon Oct 13, 2008 10:40 pm    Post subject:
Reply with quote

The length of a variable in COBOL WORKING-STORAGE is declared at compile time and cannot be changed. You may use part of it, or all of it, via reference modification but the length will not ever, under any circumstances, change from the compiled length.
Back to top
View user's profile Send private message
sarath16581

New User


Joined: 11 Jun 2005
Posts: 8

PostPosted: Mon Oct 13, 2008 10:45 pm    Post subject:
Reply with quote

Ok i have a routine and we want to make it a one time program. We have to pass variables from different programs to use this routine via linkage section.
The variables we pass from main programs to this routine may vary from program to program. So we wanted to make the length of variable as a dynamically allocated one, so that who ever wants to use it can pass the length as per their requirement.
Is this possible?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7992
Location: Bellevue, IA

PostPosted: Mon Oct 13, 2008 10:59 pm    Post subject:
Reply with quote

You can pass it in LINKAGE SECTION with a variable length; if the LINKAGE SECTION data is moved to WORKING-STORAGE the W-S length needs to accommodate the largest possible length since the W-S variable is fixed length. Something like this could be used:
Code:
LINKAGE SECTION.
01  LS-VALUES.
    05  LS-LENGTH    PIC S9(09) COMP.
    05  LS-VAR       OCCURS 1 TO ???
                     DEPENDING ON LS-LENGTH.
where ??? is your maximum length.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Mon Oct 13, 2008 11:18 pm    Post subject: Re: how to pass variable length dynamically in cobol
Reply with quote

Robert,

LS-LENGTH must be a halfword and LS-VAR can be defined as PIC X(100). Then LS-LENGTH can be used in reference modification.

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

Global Moderator


Joined: 06 Jun 2008
Posts: 7992
Location: Bellevue, IA

PostPosted: Mon Oct 13, 2008 11:40 pm    Post subject:
Reply with quote

Bill: if he's passing from JCL, yeah it's half-word and 100 bytes. But he's talking about calling from a program, so the JCL limits don't apply, based on this quote:
Quote:
We have to pass variables from different programs to use this routine via linkage section.
The variables we pass from main programs to this routine may vary from program to program.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Oct 15, 2008 6:24 pm    Post subject:
Reply with quote

Hi Sarath,

Yes, you can pass the length of the variable as a param along w/the variable.

The CALLed pgm then uses the length in a refmoded COBOL stmt, e.g.
Code:
MOVE PARAM-DATA(1:PARAM-LEN) TO ABC


Just make sure the PARAM-DATA fiel in the CALLed pgm is big enough to hold the largest string passed by any CALLing pgm.

One problem you may face is a mismatch between the passed length and the length of the actual data.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us