View previous topic :: View next topic
|
Author |
Message |
xiinus
New User
Joined: 12 Mar 2007 Posts: 13 Location: india
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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....
Bill |
|
Back to top |
|
|
xiinus
New User
Joined: 12 Mar 2007 Posts: 13 Location: india
|
|
|
|
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 |
|
|
xiinus
New User
Joined: 12 Mar 2007 Posts: 13 Location: india
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
any reason when loading the table for not keeping a count of the entries ??? |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
The person that supplies the table should also supply the number of active entries.
Otherwise, you have to look for it. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
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... |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
Another hint: Use the Cobol function LENGTH to calculate the length values, don't hardcode the values, by all means |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
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... and it fits the owner's "requirements".... |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
|