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

Static array query


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

New User


Joined: 06 Mar 2006
Posts: 76
Location: Chennai

PostPosted: Thu Dec 28, 2006 5:35 pm
Reply with quote

Hi all,

I have used one static array in my cobol program.

Structure is as follows:

01 W-CLIENT-ARRAY.
03 W-CLIENT-COUNT PIC S9(4) COMP.
03 W-CLIENT-RECORD OCCURS 500 TIMES
INDEXED BY CLT-INDX.
05 W-CLIENT-CLT-NO PIC X(20).
05 W-CLIENT-KEY PIC S9(15) COMP-3.


Whenever i read record i will move to the above array. In the assumption that it will not be more than 500 records for the particular transaction i have declared it as occurs 500. But some of the scenario i got more than 500 records, in my last scenario i got around 506 records for a same transaction. I thought my program will abend as it exceeds 500 records but it went fine. And processed everything properly. Functionality also looks fine. Output files also created as expected.

Is that correct? Or it should abend?

Please help me.

Thanks,
Noor
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Dec 28, 2006 5:52 pm
Reply with quote

Basically, you stepped on what ever storage lays beyond your array. There is a compile parameter that will check for that, bounds or some such I think, but you should be checking anyway.
When I write code and see some impossible condition I don't just ignore it because "It'll never happen".....I do the check and the imperative statement to the IF is abend with a abend code of "SNO#" where # is 0-9 and the SNO stands for "Should Not Occur".... icon_smile.gif
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Thu Dec 28, 2006 7:27 pm
Reply with quote

So.......what William also tries to say is one shouldn't just be satified if the program seems to function correctly: wait till you sit at your desk in the middle of the night swetting to solve a dump/problem caused by some other developer's program who's done just the same
Back to top
View user's profile Send private message
dcshnier

New User


Joined: 28 Dec 2006
Posts: 27
Location: Baltimore, MD 21215

PostPosted: Thu Dec 28, 2006 10:49 pm
Reply with quote

The advice shared by William is very good advice. Whenever you have created a fixed length array (i.e. 500 occurences in your example), always provide some code that will at least alert you to those rare situations when more than the stated occurences are encountered. As to why IBM did not automatically force an ABEND with a 'S0C4', we would have to know more detail. It seems to me that if you tried to move data into the 501st occurence of an array that only allowed for 500 occurences, you should have had a S0C4 ABEND.

A fringe benefit of taking William's advice is that the logic that you will add to check that if the array limit has exceeded, can be inserted before you attempt to move something into the array - that way you can pre-emptively ward off the S0C4 ABEND from happening to begin with. Furthermore, this logic does not have to result in a 'user-forced' ABEND. Instead, you can just issue a warning - or generate an email, or something less harsh than an ABEND. It all depends on how mission critical, will be the result of having the array being too small for that particular iteration.

regards
dcshnier


I
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Dec 28, 2006 11:12 pm
Reply with quote

Quote:
As to why IBM did not automatically force an ABEND with a 'S0C4', we would have to know more detail. It seems to me that if you tried to move data into the 501st occurence of an array that only allowed for 500 occurences, you should have had a S0C4 ABEND.

From the FM:
Quote:
Checking for valid ranges

Use the SSRANGE compiler option to check the following ranges:
v Subscripted or indexed data references
Is the effective address of the desired element within the maximum boundary of the specified table?
v Variable-length data references (a reference to a data item that contains an OCCURS DEPENDING ON clause)
Is the actual length positive and within the maximum defined length for the group data item?
v Reference-modified data references Are the offset and length positive?
Is the sum of the offset and length within the maximum length for the data item?

When the SSRANGE option is specified, checking is performed at run time when both of the following are true:
v The COBOL statement containing the indexed, subscripted, variable-length, or reference-modified data item is performed.
v The CHECK run-time option is ON.

If a check finds that an address is generated outside the address range of the data item that contains the referenced data, an error message is generated and the program stops. The error message identifies the table or identifier that was referenced and the line number where the error occurred. Additional information is provided depending on the type of reference that caused the error.

If all subscripts, indices, or reference modifiers are literals in a given data reference and they result in a reference outside the data item, the error is diagnosed at compile time regardless of the setting of the SSRANGE compiler option.

Performance consideration:
SSRANGE can degrade the performance of your program somewhat because of the extra overhead to check each subscripted or indexed item.
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Fri Dec 29, 2006 12:30 am
Reply with quote

For a final 2 cents: Going beyond the indexed area doesn't defenitely mean a S0C4 since you might be poking in some working storage. S0C4 occurs when you are trying to ruin a protected area. A protected area usually contains pointers and machinecode generated from compilers. So the lesson to be learned is that, like both advisors wrote, defend you fucking boundaries before putting someone else into nighttrouble.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Dec 29, 2006 3:52 am
Reply with quote

Mr Bitneuker,

Do you truly need to use obscenities to express yourself? I find this site to be normally curious and friendly. Language as you have used degrades the site and certainly degrades yourself. By your post, I believe your English proficiency should be high enough to know better. There is no excuse to use this kind of language icon_evil.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Dec 29, 2006 3:59 am
Reply with quote

Oh Dave, relax, I read it as a somewhat over the top act, yes, sometimes you (as a knowledgeable system professional) you do have to "jump down their throats) to give them a little lesson (been there, done that, received the same). icon_rolleyes.gif
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Dec 29, 2006 5:42 am
Reply with quote

William,

I can remember a time, long ago, when IT was a 99% men, foul language and actions were common. But we have come far since then, women are in the work place now, thank goodness, and this is no longer acceptable. I personally find foul language in the work place (including user groups, and forums like this, etc.) unprofessional, either in the spoken word or the written word. Maybe up in hunting camp, or in a factory or on BLOGs, but not here. I find it in myself to overlook an occasionally incident that occurs in the heat of argument in the spoken word; the mouth move faster than the brain thinks. But for most of us, this is not the case with the written word.

I have ?never? used foul language to "jump down their throats) to give them a little lesson?, at least not in the last 25 years since I?ve matured some. It?s unprofessional, and almost always does not accomplish the goal. Don?t get me wrong, in the heat of an argument words have come out of my mouth that would make a teamster blush. But I cannot ever remember, except as a quote, using the ?F? word in correspondence.

True professionals, once shown the error of their way, feel bad enough without this kind of attack.

Just my philosophy, others have theirs.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Dec 29, 2006 5:57 am
Reply with quote

Noor,


As William pointed out, checking subscripts in arrays before populating is very important.

The following is a bit of code I put together that represents closely how I normally do table handling. I like to use subscripts for table handling instead of index by. Don?t ask me why, its just one of those life mysteries.

If you have and questions on the concepts, please let us know.

Code:

01  CLIENT-ARRAY.
    05  CLIENT-RECORD              OCCURS 500 TIMES.
        10 ---
        10 ---
    05  CLIENT-COUNT               PIC S9(4) COMP-3 VALUE 0.
    05  CLIENT-SUB                 PIC S9(4) COMP-3 VALUE 0.
    05  CLIENT-MAX-COUNT           PIC S9(4) COMP-3 VALUE +500.
    05  CLIENT-ARRAY-PCT           PIC S9(4) COMP-3 VALUE 0.
    05  CLIENT-WARNING-PCT         PIC V9(2) COMP-3 VALUE .80.
    05  CLIENT-EMAIL-WARNING       PIC X            VALUE ?N?.
    05  CLIENT-EMAIL-OVERFLOW      PIC X            VALUE ?N?.

    COMPUTE CLIENT-ARRAY-PCT = CLIENT-MAX-COUNT * CLIENT-WARNING-PCT.

    PERFORM P3000-INSERT-CLIENT-RECORD THRU P3000-EXIT.

P3000-INSERT-CLIENT-RECORD.

    COMPUTE CLIENT-SUB = CLIENT-COUNT + 1.
    IF CLIENT-EMAIL-WARNING = ?N?
    AND CLIENT-SUB > CLIENT-ARRAY-PCT
    THEN
        MOVE ?Y?                    TO CLIENT-EMAIL-WARNING
        PERFORM P4000-SEND-WARNING-MSG THRU P4000-EXIT      
    END-IF.
    IF CLIENT-EMAIL-OVERFLOW = ?N?
    AND CLIENT-SUB > CLIENT-MAX-COUNT
    THEN
        MOVE ?Y?                    TO CLIENT-EMAIL-OVERFLOW
        PERFORM P4100-TABLE-OVERFLOW THRU P4100-EXIT
    END-IF.
    MOVE NEW-CLIENT-RECORD          TO CLIENT-RECORD(CLIENT-SUB).
    MOVE CLIENT-SUB                 TO CLIENT-COUNT.

P3000-EXIT.
    EXIT.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Dec 29, 2006 7:03 am
Reply with quote

DavidatK wrote:
I like to use subscripts for table handling instead of index by. Don?t ask me why, its just one of those life mysteries.
David?

They both have their strengths and weaknesses, but do you understand the fundamental difference between indexes and subscripts? If you have and questions on the concepts, please let us know.

Bill
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Dec 29, 2006 10:07 pm
Reply with quote

William Thompson wrote:

David?

They both have their strengths and weaknesses, but do you understand the fundamental difference between indexes and subscripts? If you have and questions on the concepts, please let us know.


Thank you so much for your concern Bill, but indeed, I do understand the differences. My statement was that my preference was to use subscripts over indexes, not that one was better or worse that the other. You want to use indexes, go for it.

PS. Still looking for the Keys?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sat Dec 30, 2006 12:23 am
Reply with quote

icon_rolleyes.gif You missed the point, the reason indexes were created was to improve efficiency in certain table handling functions. To ignore using them where they shine best is to waste cpu time and you know what they say; "Time is Money". icon_lol.gif
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Sat Dec 30, 2006 3:58 am
Reply with quote

Here is my 2 cents worth.

Code:

01 W-CLIENT-ARRAY.
    03 W-CLIENT-COUNT     PIC S9(4) COMP.
    03 W-CLIENT-RECORD    OCCURS 0 to 50000 times
                          depending on w-client-count.
      05 W-CLIENT-CLT-NO  PIC X(20).
      05 W-CLIENT-KEY     PIC S9(15) COMP-3.


read a record

if this is a record I want
  compute w-client-count = w-client-count + 1

  move record-read to w-client-record (w-client-count)
end-if
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sat Dec 30, 2006 4:10 am
Reply with quote

Mickeydusaor,

Always need two more cents icon_biggrin.gif

I understand what you?re getting at; make the array so large that it could not possibly overflow. I've used this on single run 'FIX' programs because you don't have to program for all of these exceptions.

But, what happens when the program is in production for 10 years and the company growth, and acquisitions now puts the client base at more than 50000?


Have a happy holliday,
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sat Dec 30, 2006 4:14 am
Reply with quote

Mickeydusaor,
I'm not quite sure what you are saying, but if that is all the logic and table handling, it seems a toss-up to me......

What happens to w-client-record after this? Is there a further redefinition of the table row?

Awaiting your next "2 cents".... icon_smile.gif
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Tue Jan 02, 2007 3:39 pm
Reply with quote

Ok, considering Dave's remark a little while I feel I have to apologise using the 'F'-word; I'm not used to express myself like. What I actually tried is to tell what my thoughts were at the moment I finally found out why an application abended in the middle of the night. Some of you will certainly have similar experieces: get a call at 23.00, jump in your car to drive to the office, find out the abending program was written by a hired consultant who already left the company. At 03.00 we pinpointed the cause and solved it. The shiftleader then mentioned a similar problem occurred before; same consultant, same error. This consultant was at that time addressed to in order to point out what he caused and why, so he should have learned his lesson. After solving the recent problem we examined all of his programs and all of them still had the same error; though he was told the consequences of his 'bad' programming it seemed he didn't learn the lesson completely.

The remark was not addressed to TS (Topic Starter) so Noor, if I affended you please accept my apology.
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top