Forums  

Go Back   Forums > Acucorp Customer Forum > General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2003, 07:16 AM
larryt larryt is offline
Registered User
 
Join Date: Apr 2003
Posts: 14
Dynamic change of a variable's length size

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
. . .
Reply With Quote
  #2  
Old 09-18-2003, 12:17 AM
gforseth gforseth is offline
Super Moderator
 
Join Date: Nov 2002
Location: Norway
Posts: 1,259
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.
Reply With Quote
  #3  
Old 09-19-2003, 06:30 AM
larryt larryt is offline
Registered User
 
Join Date: Apr 2003
Posts: 14
Dynamic change of a variable's length size

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.
Reply With Quote
  #4  
Old 09-22-2003, 12:54 AM
gforseth gforseth is offline
Super Moderator
 
Join Date: Nov 2002
Location: Norway
Posts: 1,259
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.
Reply With Quote
  #5  
Old 10-06-2003, 06:35 AM
MerlinM MerlinM is offline
Registered User
 
Join Date: Dec 2002
Posts: 78
Have you tried this?

Question:
How come you don't set your external data area to the largest possible size?

Merlin
Reply With Quote
  #6  
Old 10-07-2003, 10:38 AM
larryt larryt is offline
Registered User
 
Join Date: Apr 2003
Posts: 14
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
Reply With Quote
  #7  
Old 10-07-2003, 10:50 AM
MerlinM MerlinM is offline
Registered User
 
Join Date: Dec 2002
Posts: 78
another question?

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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 12:56 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.