Skip to main content

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
Hm...
I don't believe you can do what you try to accomplish. But it would be better if you explained the context.
I assume these calls you are doing are to C functions? May I ask what these do, and if you have developed them internally, why would you use external variables instead of passing parameters, also wondering why the need for variable sizing, why not just use "one size fits all", these days memory are thrown at your feets for nothing anyway.

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
Of course a task can be accomplished in a variety of different ways.
But consider the following scenario.
There are about 30 old COBOL, existing programs, all using same external variable's names ITEM-CODE and ITEM-DESCRIPTION but in each program they are different size as each of them is working with different table of code/description.
Assuming that those 30 old programs has NOT (or can not) to be changed. A new COBOL program has to call all of them, one by one in the procedure division, facing 2 facts (problems):
- due of external clause ITEM-CODE/DESCRIPTION have to appear only once in the working-storage?
- executing COBOL calls in procedure division should be done with ITEM-CODE/DESCRIPTION size appropriate to calling program, meaning different size for each call.

There would be no problem if those 30 programs CAN BE changed, right? The easiest way would be to make them callable just by using linkage section and in the new program which has to call them use 30 appropriate ITEM-CODE/DESCRIPTION pears, each different in name and size.

However,thanks for interesting deeper into this.

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
The only solution I can think of for this, is to use dynamic memory.
E.g. Assuming your application is the one where the real allocation is taking place, so that the EXTERNAL clause appears in the other applications, I would make the definition in your app to be a PIC X whatever, then, upon the call to each subsequent program, I would dynamic memory for each call and set the address of the external item to this allocation, like:

77 MY-EXTERNAL PIC X.
77 DYNAMIC-PTR USAGE POINTER.
77 MY-REAL-1 PIC X(200).
77 MY-REAL-2 PIC X(300).
* and so on...

PROCEDURE DIV...

CALL "M$ALLOC" USING 200 DYNAMIC-PTR.
SET MY-EXTERNAL TO DYNAMIC-PTR.
CALL "external application to do whatever"
CALL "C$MEMCPY" USING BY REFERENCE MY-REAL-1
BY-VALUE DYNAMIC-PTR 200.
CALL "M$FREE" USING DYNAMIC-PTR.
*Repeat for next program...
CALL "M$ALLOC" USING 300 DYNAMIC-PTR.
SET MY-EXTERNAL TO DYNAMIC-PTR.
CALL "external application to do whatever"
CALL "C$MEMCPY" USING BY REFERENCE MY-REAL-2
BY-VALUE DYNAMIC-PTR 300.
CALL "M$FREE" USING DYNAMIC-PTR.
* And so on...

Hope this helps.

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
The only solution I can think of for this, is to use dynamic memory.
E.g. Assuming your application is the one where the real allocation is taking place, so that the EXTERNAL clause appears in the other applications, I would make the definition in your app to be a PIC X whatever, then, upon the call to each subsequent program, I would dynamic memory for each call and set the address of the external item to this allocation, like:

77 MY-EXTERNAL PIC X.
77 DYNAMIC-PTR USAGE POINTER.
77 MY-REAL-1 PIC X(200).
77 MY-REAL-2 PIC X(300).
* and so on...

PROCEDURE DIV...

CALL "M$ALLOC" USING 200 DYNAMIC-PTR.
SET MY-EXTERNAL TO DYNAMIC-PTR.
CALL "external application to do whatever"
CALL "C$MEMCPY" USING BY REFERENCE MY-REAL-1
BY-VALUE DYNAMIC-PTR 200.
CALL "M$FREE" USING DYNAMIC-PTR.
*Repeat for next program...
CALL "M$ALLOC" USING 300 DYNAMIC-PTR.
SET MY-EXTERNAL TO DYNAMIC-PTR.
CALL "external application to do whatever"
CALL "C$MEMCPY" USING BY REFERENCE MY-REAL-2
BY-VALUE DYNAMIC-PTR 300.
CALL "M$FREE" USING DYNAMIC-PTR.
* And so on...

Hope this helps.

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
Question:
How come you don't set your external data area to the largest possible size?

Merlin

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
As I said ...

"...There are about 30 old COBOL, existing programs, all using same external variable's names ITEM-CODE and ITEM-DESCRIPTION but in each program they are different size as each of them is working with different table of code/description.
Assuming that those 30 old programs has NOT (or can not) to be changed..."

... so the programs have to be used as they are, no chance of changing them.

Thanks and best regards Merlin
Larry

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
Is there a set number of sizes you are working with? Or could it be any size. A simple solution would be:

01 My-Table pic x(n) is external.
03 My-Table-Size-02 redefines My-Table.
05 My-Table-02-Row occurs n/2 times
03 My-Table-Size-05 redefines My-Table.
05 Mt-Table-05-Row occurs n/5 times.

make sure you

initilize My-Table

when you switch table sizes.

The problem is you need to have to declare all your various table sizes at compile time. In your case it should work though.

Merlin

[Migrated content. Thread originally posted on 17 September 2003]

The length size of a variable LK-ITEM has to be changed dynamically several times during the execution of a program.
I've tried as below but it did not worked. Some one has already faced similar and solved it?
Thanks in advance.

77 REASON-FOR-EXPORT-ITEM-SIZE pic x(47).
77 CURRENCY-ITEM-SIZE pic x(24).
77 COUNTRY-ITEM-SIZE pic x(40).
. . .
77 TABLE-ITEM-SIZE pic 9(2).
78 ITEM-SIZE value length of TABLE-ITEM-SIZE.
. . .
01 LK-CODES-AREA is external.
02 LK-ITEM pic x(ITEM-SIZE).
. . .
evaluate true
when REASON-FOR-EXPORT-CODES
set TABLE-ITEM-SIZE to size of REASON-FOR-EXPORT-ITEM-SIZE
call "reason-for-export-codes"
end-call
when CURRENCY-CODES
set TABLE-ITEM-SIZE to size of CURRENCY-ITEM-SIZE
call "currency-codes"
end-call
when COUNTRY-CODES
set TABLE-ITEM-SIZE to size of COUNTRY-ITEM-SIZE
call "country-codes"
end-call
. . .
Is there a set number of sizes you are working with? Or could it be any size. A simple solution would be:

01 My-Table pic x(n) is external.
03 My-Table-Size-02 redefines My-Table.
05 My-Table-02-Row occurs n/2 times
03 My-Table-Size-05 redefines My-Table.
05 Mt-Table-05-Row occurs n/5 times.

make sure you

initilize My-Table

when you switch table sizes.

The problem is you need to have to declare all your various table sizes at compile time. In your case it should work though.

Merlin