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

how to pass variable length dynamically in cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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: 1353
Location: Israel

PostPosted: Mon Oct 13, 2008 4:47 pm
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 13, 2008 10:40 pm
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 13, 2008 10:59 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Oct 13, 2008 11:18 pm
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 13, 2008 11:40 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top