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

Occurs clause using varaible


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
phdraju

New User


Joined: 30 Aug 2010
Posts: 2
Location: pune

PostPosted: Thu Sep 02, 2010 5:30 pm
Reply with quote

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." icon_sad.gif

Thanks in advance. icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Sep 02, 2010 5:44 pm
Reply with quote

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
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Thu Sep 02, 2010 5:50 pm
Reply with quote

Suggest you read about
Code:
OCCURS DEPENDING ON


http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.aix.cbl.doc/rlddeoc2.htm
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 02, 2010 6:58 pm
Reply with quote

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
View user's profile Send private message
baichunli2010

New User


Joined: 26 Aug 2010
Posts: 3
Location: China

PostPosted: Thu Sep 02, 2010 7:14 pm
Reply with quote

Bharath Bhat wrote:
Suggest you read about
Code:
OCCURS DEPENDING ON


http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.aix.cbl.doc/rlddeoc2.htm


this answer is right~
Back to top
View user's profile Send private message
icetigerfan

New User


Joined: 08 Mar 2010
Posts: 13
Location: Nuremberg, Germany

PostPosted: Thu Sep 02, 2010 7:25 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Sep 02, 2010 8:00 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Sep 02, 2010 8:12 pm
Reply with quote

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
View user's profile Send private message
icetigerfan

New User


Joined: 08 Mar 2010
Posts: 13
Location: Nuremberg, Germany

PostPosted: Fri Sep 03, 2010 11:02 am
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Sep 03, 2010 4:19 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Sep 03, 2010 4:20 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Sep 03, 2010 5:03 pm
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Sep 03, 2010 5:15 pm
Reply with quote

PL/I is compiled and does have dynamic arrays.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Sep 03, 2010 5:42 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Sep 03, 2010 5:49 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Sep 03, 2010 5:55 pm
Reply with quote

Yes, in the first line of my response. I went over-broad, Sorry about that. icon_redface.gif. And thanks for the care.

Nice to see people read what I put here..icon_smile.gif
Back to top
View user's profile Send private message
pkmurali
Warnings : 1

Active User


Joined: 15 Dec 2005
Posts: 271

PostPosted: Fri Sep 03, 2010 7:50 pm
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Sep 03, 2010 8:12 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 03, 2010 8:33 pm
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Sep 03, 2010 8:35 pm
Reply with quote

Just 2/100 of a cent worth?
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: Fri Sep 03, 2010 9:29 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 03, 2010 10:48 pm
Reply with quote

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
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 To search DB2 table based on Conditio... DB2 1
No new posts Updating a 1 byte thats in occurs mul... DFSORT/ICETOOL 6
No new posts NOT IN clause in COBOL pgm COBOL Programming 8
No new posts SUSBSCRIPT WITH SIGN IN PIC CLAUSE COBOL Programming 3
No new posts usage of CASE in WHERE clause DB2 10
Search our Forums:

Back to Top