View previous topic :: View next topic
|
Author |
Message |
phdraju
New User
Joined: 30 Aug 2010 Posts: 2 Location: pune
|
|
|
|
Hi,
Can I do the below mentioned thing:
01 var1 pic 9(01) value 6.
01 var2.
05 var3 occurs var1 times.
Tried but got error that "var1 found in occurs clause. The clause discarded."
Thanks in advance. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
your attitude is very 'trying'.
refer to a cobol language reference manual for the proper syntax.
Manuals button at top of page provide hyperlinks to manuals. |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The message explains itself -- and with the manuals available just a click away, there's no excuse for you not to read them and learn yourself what COBOL allows and doesn't allow. |
|
Back to top |
|
|
baichunli2010
New User
Joined: 26 Aug 2010 Posts: 3 Location: China
|
|
|
|
this answer is right~ |
|
Back to top |
|
|
icetigerfan
New User
Joined: 08 Mar 2010 Posts: 13 Location: Nuremberg, Germany
|
|
|
|
Pease mind, that
Code: |
OCCURS DEPENDING ON variable
|
is very unperformant. You shouldn't use it in online programms.
Every time you will change the contend of the variable the dimension of the accessed storage will change to. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If you define an OCCURS DEPENDING ON Array in WS, the amount of storage is always allocated to the maximum number specified in the "TO".
Whereas, Dynamic Allocation in Linkage allows you to allocate enough storage, based upon the amount needed/requested.
For example, if you had an OCCURS 1 TO 1000 DEPENDING ON MAX-NBR and its allocated in WS, the storage allocation will be based upon the 1000.
If you allocated this in LINKAGE, via "CEEGTST", "GETMAIN" or "STORAGE OBTAIN" then you can specifically request only the amount of storage you need. Note: use XC GETMAIN for CICS. "CEEGTST" is allowed, but the CICS GETMAIN is preferred.
However, MAX-NBR (if less than 1000) must always be used to ensure you have addressability. Otherwise, you'll get a S0C4 if you go beyond the storage boundaries.
Bill |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Angelika wrote: |
Every time you will change the contend of the variable the dimension of the accessed storage will change to.
|
Angelika,
could you expand on that comment, bitte?
an ODO Table will always have the max size allocated at compile time. |
|
Back to top |
|
|
icetigerfan
New User
Joined: 08 Mar 2010 Posts: 13 Location: Nuremberg, Germany
|
|
|
|
I ment the
Code: |
OCCURS DEPENDING ON variable |
without the "1 to xxx " statement. At least i was told so in one of my COBOL trainings.
Sorry, if I was wrong. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Well, COBOL is a compiled-language, so there is no way that it can have "dynamic arrays". If the COBOL Internal Table (loosly called as arrays, whcih is not actually a COBOL term) is defined in Working-Storage with the ODO (occurs depending on) phrase, it will always be mapped to max potential size. The main purpose of ODO is to increase the efficiency of the Binary Search.
The only way to have a "dynamic array" is to acquire storage at runtime basing your size requirement on the number of items you will have. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Also, have you looek at what Bill has already said
Quote: |
For example, if you had an OCCURS 1 TO 1000 DEPENDING ON MAX-NBR and its allocated in WS, the storage allocation will be based upon the 1000 |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Anuj, there are two cases where the maximum amount of storage for an OCCURS DEPENDING ON will not be allocated: if the ODO is in FILE SECTION or LINKAGE SECTION. For FILE SECTION variables, the length of the data read (or written) will be determined by the ODO -- which does leave plenty of potential for problems. And in LINKAGE SECTION, the ODO should reflect the actual number of occurrences passed by the calling program. Note in both cases that COBOL does not allocate any storage for the variables, as this is handled by the operating system (for FILE SECTION) or calling program (for LINKAGE SECTION) outside the context of the COBOL program. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
PL/I is compiled and does have dynamic arrays. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
PL/I is compiled and does have dynamic arrays. |
Sure -- but this is the COBOL forum and the question was asked about COBOL. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
yes it is a cobol forum, but Phil' s reply was disputing the sentence
Quote: |
Well, COBOL is a compiled-language, so there is no way that it can have "dynamic arrays". |
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Yes, in the first line of my response. I went over-broad, Sorry about that. . And thanks for the care.
Nice to see people read what I put here.. |
|
Back to top |
|
|
pkmurali Warnings : 1 Active User
Joined: 15 Dec 2005 Posts: 271
|
|
|
|
Bill,
Can you please pitch it more on dynamic linkage storage using CICS GETMAIN with the below example.
Quote: |
If you allocated this in LINKAGE, via "CEEGTST", "GETMAIN" or "STORAGE OBTAIN" then you can specifically request only the amount of storage you need. Note: use XC GETMAIN for CICS. "CEEGTST" is allowed, but the CICS GETMAIN is preferred.
|
Code: |
LINKAGE SECTION.
01 LS-VAR.
05 LS-CNT PIC S9(04) COMP.
05 VAR1 OCCURS 1 TO 5 TIMES
DEPENDING ON LS-CNT.
10 EMPID PIC 9(5).
10 EMPNAME PIC X(25).
|
How to allocate linkage dynamically?
thanks,
Murali |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
And I also thank you all.
Continuing with PL/I, this is a mainframe forum, and if someone has a requirement easily implemented with dynamic arrays, and also has PL/I, then this suggests they might want to consider using PL/I.
Compiles and links the same, and I believe with the same subroutine protocols and file structures, so should interface with other programs.
Plus, it's a GREAT language. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
When VS/COBOL II was released (somewhere in the mid 80's), it was hailed as this great and wonderful version of "modern" COBOL.
At the time, I was working in a PL/I shop and I marvelled at the "superlative" kudos being thrown at this COBOL.
After reviewing what this COBOL could do, I came to the conclusion that many of its "enhancements" were borrowed (more like stolen) from PL/I, so for me, it wasn't a big whoop.
Even today, I still think PL/I is light years ahead of any COBOL version/release.
Just my .02 cents....
Bill |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Just 2/100 of a cent worth? |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
pkmurali wrote: |
Bill,
Can you please pitch it more on dynamic linkage storage using CICS GETMAIN with the below example.
Quote: |
If you allocated this in LINKAGE, via "CEEGTST", "GETMAIN" or "STORAGE OBTAIN" then you can specifically request only the amount of storage you need. Note: use XC GETMAIN for CICS. "CEEGTST" is allowed, but the CICS GETMAIN is preferred.
|
Code: |
LINKAGE SECTION.
01 LS-VAR.
05 LS-CNT PIC S9(04) COMP.
05 VAR1 OCCURS 1 TO 5 TIMES
DEPENDING ON LS-CNT.
10 EMPID PIC 9(5).
10 EMPNAME PIC X(25).
|
How to allocate linkage dynamically?
thanks,
Murali |
Let's say you need to allocate storage for the above group, but you really only need 3 occurences as opposed to 5.
Code: |
03 WS-FLENGTH PIC S9(08) COMP.
03 WS-FLENGTH-X REDEFINES WS-FLENGTH
PIC X(04).
03 WS-POINTER POINTER.
03 WS-CNT PIC S9(04) COMP VALUE 3.
*
COMPUTE WS-FLENGTH = (LENGTH OF VAR1 * WS-CNT) + LENGTH OF LS-CNT.
*
EXEC CICS GETMAIN SET(WS-POINTER) FLENGTH(WS-FLENGTH) INITIMG(WS-FLENGTH-X) END-EXEC.
*
SET ADDRESS OF LS-VAR TO WS-POINTER.
MOVE WS-CNT TO LS-CNT.
|
By allocating only three occurences you have saved 60-Bytes. Although just an example, if the OCO were 1 to 10000 and each table-entry was 100-Bytes, but you only need 2500, you can save 750,000 Bytes of storage. If this were defined to WS, you'd get the full allocation of 1,000,000 Bytes, regardless.
As long as the calculated FLENGTH is not greater than 16777215, the high-order byte of WS-FLENGTH will equal X'00' and you can use it as your INITIMG (Initialization Image), if you need the storage cleared to X'00's.
INITIMG is an optional keyword.
Bill |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
In the above code -
Code: |
COMPUTE WS-FLENGTH = (LENGTH OF VAR1 * WS-CNT) + LENGTH OF LS-CNT.
|
Needs to be changed to -
Code: |
COMPUTE WS-FLENGTH = (LENGTH OF VAR1 (1) * WS-CNT) + LENGTH OF LS-CNT.
|
Bill |
|
Back to top |
|
|
|