View previous topic :: View next topic
|
Author |
Message |
sarath16581
New User
Joined: 11 Jun 2005 Posts: 8
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Do you mean JCL PARM or other cobol program? |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Hi,
Please elaborate a little more on your requirement.
Cris |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
sarath16581
New User
Joined: 11 Jun 2005 Posts: 8
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
sarath16581
New User
Joined: 11 Jun 2005 Posts: 8
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
|