Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Occurs clause using varaible
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Occurs clause using varaible
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    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Thu Sep 02, 2010 6:58 pm    Post subject:
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    Post subject:
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: 11
Location: Nuremberg, Germany

PostPosted: Thu Sep 02, 2010 7:25 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Sep 02, 2010 8:00 pm    Post subject: Reply to: Occurs clause using varaible
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    Post subject:
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: 11
Location: Nuremberg, Germany

PostPosted: Fri Sep 03, 2010 11:02 am    Post subject:
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

Senior Member


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

PostPosted: Fri Sep 03, 2010 4:19 pm    Post subject:
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

Senior Member


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

PostPosted: Fri Sep 03, 2010 4:20 pm    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Fri Sep 03, 2010 5:03 pm    Post subject:
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

Active Member


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

PostPosted: Fri Sep 03, 2010 5:15 pm    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Fri Sep 03, 2010 5:42 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Fri Sep 03, 2010 5:49 pm    Post subject: Reply to: Occurs clause using varaible
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

Senior Member


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

PostPosted: Fri Sep 03, 2010 5:55 pm    Post subject:
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: 236

PostPosted: Fri Sep 03, 2010 7:50 pm    Post subject:
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

Active Member


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

PostPosted: Fri Sep 03, 2010 8:12 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 03, 2010 8:33 pm    Post subject: Reply to: Occurs clause using varaible
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

Active Member


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

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

Just 2/100 of a cent worth?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts [SQL0029] INTO clause missing from em... HABBIE DB2 2 Fri Sep 04, 2015 3:54 pm
No new posts Multiple OCCURS depending on in same ... muralirajansm COBOL Programming 6 Fri Aug 21, 2015 4:23 pm
No new posts 3-D Table with nested DEPENDING ON Cl... VivekKhanna COBOL Programming 5 Sat Aug 08, 2015 11:18 pm
No new posts when=group clause: question about the... tuxama DFSORT/ICETOOL 2 Thu Mar 26, 2015 12:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us