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

Reg: Hard coding a cobol array.


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

New User


Joined: 23 Dec 2008
Posts: 69
Location: India

PostPosted: Wed Sep 30, 2009 5:10 pm
Reply with quote

Hi all,

I work for a performance tuning task. There is a file used by a cobol program which has only 18 records. I need to remove this file since this is not updated in the past 10 years of time. I need to hard code the values into an Array. I am bit confused with the syntax. Is it possible to give values in occurs clause of working storage section itself??

Please help me with the syntax.. i will be greatful...
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Wed Sep 30, 2009 5:15 pm
Reply with quote

Hello Sija,

Yes Values can be given in occurs clause ...but to provide better solution please specify the declaration of your array variable & value?
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: Wed Sep 30, 2009 5:19 pm
Reply with quote

Code up FILLER elementary variables with the VALUE clauses, use a REDEFINES on the group variable and the OCCURS is on the REDEFINES variable.
Code:
05  TABLE-ITEMS.
    10  FILLER PIC X(20) VALUE 'ABCDEFGHIJKLMNOPQRST'.
    10  FILLER ...
05  TABLE-VALUES REDEFINES TABLE-ITEMS
                 OCCURS 18
                 PIC X(05).
Back to top
View user's profile Send private message
sijayapal

New User


Joined: 23 Dec 2008
Posts: 69
Location: India

PostPosted: Wed Sep 30, 2009 7:32 pm
Reply with quote

That answers my question icon_smile.gif
Thanks robert.
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Wed Sep 30, 2009 7:56 pm
Reply with quote

Hi,
Why not to read this small file and load it into the array at the beginning of the processing? It would amount to have the array the way you want now, but with the advantage of keeping the data separate from the code.
Imagine that you can accidently change the content of this small array during any maintenance you're going to make in this program.
Here, we try to keep every single piece of data away from the code, no matter if it's a single constant. We don't have performance problems because we load all the variables at the beginning of the processing.
Just an opinion.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Sep 30, 2009 8:08 pm
Reply with quote

Hello,

Quote:
Why not to read this small file and load it into the array at the beginning of the processing
I agree - better to keep the "data" out of the "code".

Also, as often happens, someone will identify a need to run with a different set of values (either one-time or permanently). . . If the data is external, a new set of this data could be created more easily than changing/promoting the code.
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: Wed Sep 30, 2009 8:47 pm
Reply with quote

I'm all for Dynamic Arrays, defined to LINKAGE, with the necessary storage allocated based upon (LRECL * NBR-OF-RECORDS) + 4 (the 4 is for the OCCURS DEPENDING ON fullword at the beginning of the ARRAY).

EG:
Code:

01  LS-DYNAMIC-TBL-REC.
    03  LS-DYNAMIC-NBR-ENTRIES PIC  9(008) COMP.
    03  LS-DYNAMIC-ENTRIES     OCCURS 1 TO 1000 TIMES
                               DEPENDING ON LS-DYNAMIC-NBR-ENTRIES
                               INDEXED BY X-LS-DE, X-LS-DE-MAX
                               PIC  X(???).


Is this a QSAM or VSAM file?

Can you be guaranteed that they'll never be more than 18 records in this file?

(Hint: Never say NEVER) icon_wink.gif

I'm specifying 1000 as the maximum number of records that you'll ever have, just as a failsafe. This can be adjusted by you as needed.

Index X-LS-DE-MAX will be set by you, based upon the NBR-OF-RECORDS and used as the high-water mark, avoiding a S0C4.

Also, if your compiler supports COMP-5, then change LS-DYNAMIC-NBR-ENTRIES to COMP-5, which is "Native Binary".

You would use LE Callable Service routines "CEEGTST" to obtain the Dynamic Storage and "CEEFRST" to free the Dynamic Storage or, the Storage will be implicitly freed at step termination.

Bill
Back to top
View user's profile Send private message
jctgf
Currently Banned

Active User


Joined: 04 Nov 2006
Posts: 109

PostPosted: Wed Sep 30, 2009 9:00 pm
Reply with quote

Bill,
I find your suggestion VERY interesting. I think I've read another reply from you in this forum in which you mention the use of a dynamic array.
Could you please provide more examples of how to use it (a piece of code, if possible)?
However, I have a question: if you define the maximum occurrence of your array (depending on...) it isn't a dynamic array truly, isn't it? I mean, you have a limit (in your post, it would be 1000) that will be set during compiling time.
During execution time, it would be impossible to go over this limit, right?
Thanks.
Back to top
View user's profile Send private message
sijayapal

New User


Joined: 23 Dec 2008
Posts: 69
Location: India

PostPosted: Mon Oct 05, 2009 11:31 am
Reply with quote

Hi JCTGF,

U r idea is good and i also thought of the same initially. But the problem here is that the program is a called module. This program is called by more than 1000times. So this idea wont fit here. I want to completely eliminate the I/O. Every one agreed for the hardcoding since the data is not changed for more than 10years of time.

Bill,

I agree your point. I cannot say never here. After consulting with the concerned team i will allocate the space accordingly. And also if they want to add any values.. they need to change the program. Even at that time the table size can be modified. So it wont be a big bottle neck as of now. icon_biggrin.gif


Thanks
Sija
Back to top
View user's profile Send private message
sijayapal

New User


Joined: 23 Dec 2008
Posts: 69
Location: India

PostPosted: Mon Oct 05, 2009 1:09 pm
Reply with quote

Dick,

Usually we keep the data out of the code. But here in this case considering the amount of effort to change now as well as in future.. we find it better to keep the values inside the code.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Oct 05, 2009 8:11 pm
Reply with quote

Quote:
(Hint: Never say NEVER)
You just did Bill. icon_smile.gif
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top