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

More How to read array backward( in reverse order)


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

New User


Joined: 12 Mar 2007
Posts: 13
Location: india

PostPosted: Thu Apr 22, 2010 11:24 pm
Reply with quote

I read the How to read array backward( in reverse order) thread but
Now, If I don't want to read the whole array, but only from the last entered element. Be it the 12th element.

Like I want to compare the last entered element on that array, no other, to an element. How do I find the last entered element without using loops.

Help??? please.
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 Apr 22, 2010 11:36 pm
Reply with quote

Quote:
How do I find the last entered element without using loops.
Keep track of the last element used when loading the array. Use that to start your array processing. If you don't keep track of the last element used, you cannot avoid using a loop to find the last element.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Apr 22, 2010 11:37 pm
Reply with quote

Fid you understand anything already posted in the thread?
Craq Giegerich wrote:
Real hard to do!

Code:
PERFORM VARYING WS-TEXT-SUB
           FROM 15
             BY -1
          UNTIL WS-TEXT-SUB <  1
             OR WS-TEXT-FOUND = 'Y'

Make the '15' be 'the last entered element' and there you are......
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: Thu Apr 22, 2010 11:57 pm
Reply with quote

Hello,

Why would you even consider "finding" the last element when you had to know it previously? Just hang onto it as Robert mentioned.

If you just want a coding exercise, you could initialize the array with hex "EE"s and after the load, inspect/tally the entire array for x'EE' and do a bit of arithmetic. A great waste of system resources if done every time thru and clutter code for whoever has to maintain it later. I used x'EE' as these are quite rare as opposed to x'FF' which is somewhat common. . .
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 Apr 23, 2010 12:08 am
Reply with quote

In the previous posting that you had read, use the calculated WS-TEXT-SUB-MAX instead of 15.

In case someone changes the OCCURS (and that NEVER happens), WS-TEST-SUB-MAX will always be right.... icon_smile.gif

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

New User


Joined: 12 Mar 2007
Posts: 13
Location: india

PostPosted: Fri Apr 23, 2010 12:12 am
Reply with quote

I have an array table. I need to compare the last entered date on the array with another date.

Following are the ways : -

Read from the last and when I find the last element (not equal to spaces)

Read from the beginning and count the records then compare the element (count ) with another element.

Searching thru the array with an index will find the element equal to won't help in compares. I want to compare.

These are old and long ways.

Is there any other way? I request you IBM gods to help me on this.

Eg: -

Array occurs 20 times

02/11/2001
02/11/2002
02/11/2003
02/11/2004
02/11/2005
spaces
spaces
spaces
:
:
for next 15 times.
Now I have a date 06/11/2005 I want to compare this date only with the last element on the array i.e. 02/11/2005 none other.

Is there are straight and short way to find the last element on the array.

Let me know if you have any questions on this.

Thanks.
Back to top
View user's profile Send private message
xiinus

New User


Joined: 12 Mar 2007
Posts: 13
Location: india

PostPosted: Fri Apr 23, 2010 12:18 am
Reply with quote

1) The table comes loaded, I don't read the records one by one
2) The need is mine
3) The loops and the finding the max are the ways I already know, I don't wanna use them. I need something quicker.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Apr 23, 2010 12:28 am
Reply with quote

any reason when loading the table for not keeping a count of the entries ???
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri Apr 23, 2010 12:39 am
Reply with quote

The person that supplies the table should also supply the number of active entries.
Otherwise, you have to look for it.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Apr 23, 2010 12:50 am
Reply with quote

Code:
MOVE 0 TO MAX-SUSCRIPT.
IF TABLE-DATE (01) NOT = SPACES MOVE  1 TO MAX-SUBSCRIPT.
IF TABLE-DATE (02) NOT = SPACES MOVE  2 TO MAX-SUBSCRIPT.
IF TABLE-DATE (03) NOT = SPACES MOVE  3 TO MAX-SUBSCRIPT.
IF TABLE-DATE (04) NOT = SPACES MOVE  4 TO MAX-SUBSCRIPT.
IF TABLE-DATE (05) NOT = SPACES MOVE  5 TO MAX-SUBSCRIPT.
IF TABLE-DATE (06) NOT = SPACES MOVE  6 TO MAX-SUBSCRIPT.
IF TABLE-DATE (07) NOT = SPACES MOVE  7 TO MAX-SUBSCRIPT.
IF TABLE-DATE (08) NOT = SPACES MOVE  8 TO MAX-SUBSCRIPT.
IF TABLE-DATE (09) NOT = SPACES MOVE  9 TO MAX-SUBSCRIPT.
IF TABLE-DATE (10) NOT = SPACES MOVE 10 TO MAX-SUBSCRIPT.
IF TABLE-DATE (11) NOT = SPACES MOVE 11 TO MAX-SUBSCRIPT.
IF TABLE-DATE (12) NOT = SPACES MOVE 12 TO MAX-SUBSCRIPT.
IF TABLE-DATE (13) NOT = SPACES MOVE 13 TO MAX-SUBSCRIPT.
IF TABLE-DATE (14) NOT = SPACES MOVE 14 TO MAX-SUBSCRIPT.
IF TABLE-DATE (15) NOT = SPACES MOVE 15 TO MAX-SUBSCRIPT.
IF TABLE-DATE (16) NOT = SPACES MOVE 16 TO MAX-SUBSCRIPT.
IF TABLE-DATE (17) NOT = SPACES MOVE 17 TO MAX-SUBSCRIPT.
IF TABLE-DATE (18) NOT = SPACES MOVE 18 TO MAX-SUBSCRIPT.
IF TABLE-DATE (19) NOT = SPACES MOVE 19 TO MAX-SUBSCRIPT.
IF TABLE-DATE (20) NOT = SPACES MOVE 20 TO MAX-SUBSCRIPT.


NO LOOPS, THERE A LOT OF THINGS IN LIFE I WANT BUT WILL NEVER GET AND A LOT OF THINGS I DON'T WANT BUT I AM SURE I WILL GET SOME OF THEM .
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: Fri Apr 23, 2010 2:15 am
Reply with quote

Hello,

Quote:
The loops and the finding the max are the ways I already know, I don't wanna use them. I need something quicker.
What do you mean by quicker? Just some way to write less code?

The process to determine the "last" entry should happen only once so there should not be a "quicker" issue as far as resource usage is concerned.

Do you actually believe your organization is willing to invest much in something because you "don't wanna". . .?
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Apr 23, 2010 10:17 am
Reply with quote

Hi,

Quote:
1) The table comes loaded, I don't read the records one by one
Is the "loaded" table only used by you ?
If that is the case another approach could be to ask the person "supplying" the table to sort and give you in descending order of update so that the last updated date always comes first... icon_biggrin.gif
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Apr 23, 2010 2:13 pm
Reply with quote

If you know that the unused part of the array is initialised with LOW-VALUES or other significant byte value you could do an INSPECT tallying trailing initialisation bytes to find the last byte of the last used element of the array (presumed that byte would not hold an initialisation value).

When you have the position of the last byte you can use the length of the array and the length of each element to calculate the index value of the element. Somewhat awkward, but it uses no loops...

And be sure to document why you are doing so and how...
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Apr 23, 2010 2:22 pm
Reply with quote

that is a good post, Kjeld. seriously.

and even if the last byte(s) of a used item contains an initialization value,
you could use the results of
(length-of-array - tally) / length-of-item
to determine the actual last used item.

only problem would be if the last used item actually contained only initialization values.

but we know this 'unknowable' table contains dates.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Apr 23, 2010 2:37 pm
Reply with quote

Another hint: Use the Cobol function LENGTH to calculate the length values, don't hardcode the values, by all means icon_exclaim.gif
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Apr 23, 2010 2:40 pm
Reply with quote

Hi,
Kjeld wrote:
If you know that the unused part of the array is initialised with LOW-VALUES or other significant byte value you could do an INSPECT tallying trailing initialisation bytes to find the last byte of the last used element of the array (presumed that byte would not hold an initialisation value).

When you have the position of the last byte you can use the length of the array and the length of each element to calculate the index value of the element. Somewhat awkward, but it uses no loops...

And be sure to document why you are doing so and how...
Agree with Dick... That was really nice observation... great solution... icon_smile.gif and it fits the owner's "requirements".... icon_smile.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Fri Apr 23, 2010 6:37 pm
Reply with quote

Nice way to bypass the loop "problem", Kjeld.

xiinus wrote:
These are old and long ways.
...
I don't wanna use them. I need something quicker.
The only acceptable "new way" would be to provide the table with its size.
Because the program that loads the table already knows this value.

BTW,
1. how do you know that "new ways" are shorter and quicker ??
2. How can you be sure that a "new way" you find have not been used by somebody else 25 years ago ???
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 Error to read log with rexx CLIST & REXX 11
No new posts Rotate partition-logical & physic... DB2 0
No new posts Random read in ESDS file by using RBA JCL & VSAM 6
No new posts VSAM return code 23 - for a Random read COBOL Programming 4
No new posts ICETOOL to Read records SMF CEF it is... DFSORT/ICETOOL 4
Search our Forums:

Back to Top