Get max ISN

Hello to all

can you tell me how can i get max ISN (ISN of last record) of one adabas file?

thanks

Unfortunately, there is not a READ IN DESCENDING ISN SEQUENCE.

If this is a small file, and you were only going to do this once, you could:

           READ file BY ISN
           IGNORE
           AT END OF DATA
               WRITE *ISN

You could improve on this by adding a STARTING FROM clause if you knew a value that was less than the max, but hopefully reasonably close to the end.

Actually, this would work reasonably well for a large file as well, as long as you had available a reasonably close estimate of the highest ISN.

If you had a file with non reusable ISNs, and if you had a date field you could

       READ (1) IN DESCENDING SEQUENCE BY DATE

What do you need this ISN for?

steve

Dear Steve Robinson

Thanks for your message

Sorry for my bad english

I am using entirex. and have a sub program that return 10 record from one ISN (READ (10) MY_VIEW STARTING WITH ISN=#I)

I need to have max ISN for check this -> if #I>max ISN or not.

if it is ok, return nothing and return error message.

Thanks

It seems that you want to stop further request for data at EOF.

How about checking number of records on the client side for < 10? You may get a totally blank page if your data is multiple of 10.

We got a related discussion here:
http://tech.forums.softwareag.com/viewtopic.php?t=7099

Use this copycode:

ZTOPISN:

0010 *
0020 * Works out the highest ISN for a file by PSM 7/12/07
0030 *
0040 * Use in conjunction with ZTOPISNL eg:
0050 *
0060 * DEFINE DATA LOCAL USING ZTOPISNL
0070 * LOCAL
0080 * 1 MY-VIEW VIEW OF MY-DDM
0090 * …
0100 * END-DEFINE
0110 * INCLUDE ZTOPISN ‘MY-VIEW’
0120 * WRITE ‘TOP ISN=’ #TOPISN
0130 * END
0140 *
0150 *
0160 #TOPISN := 9999999
0170 RESET #LAST-ISN #LAST-TOPISN
0180 T-RPT. REPEAT
0190 TOPISN. READ (1) &1& BY ISN = #TOPISN
0200 DECIDE FOR FIRST CONDITION
0210 WHEN #LAST-ISN = 0
0220 #TOPISN := #TOPISN * 2
0230 WHEN #LAST-ISN = *ISN(TOPISN.)
0240 #TOPISN := *ISN(TOPISN.)
0250 ESCAPE BOTTOM (T-RPT.)
0260 WHEN #LAST-TOPISN NE 0
0270 #TOPISN := *ISN(TOPISN.) + ((#LAST-TOPISN - *ISN(TOPISN.)) / 2)
0280 WHEN NONE IGNORE
0290 END-DECIDE
0300 #LAST-ISN := *ISN(TOPISN.)
0310 END-READ
0320 IF *COUNTER(TOPISN.) = 0 THEN
0330 IF #LAST-ISN = 0 THEN
0340 #TOPISN := #TOPISN / 2
0350 ELSE
0360 #LAST-TOPISN := #TOPISN
0370 #TOPISN := #LAST-ISN + ((#TOPISN - #LAST-ISN) / 2)
0380 END-IF
0390 END-IF
0400 END-REPEAT

and this LDA ZTOPISNL

 -----------------Local ZTOPISNL ----Lib CORCODES ----

0010 1 #TOPISN (I4)
0020 1 #LAST-ISN (I4)
0030 1 #LAST-TOPISN (I4)

This does a binary search to get the highest isn.

If you reach max isn for the file, you will exit from the READ loop if you are reading by ISN (the READ example you give is not clear/complete). If you are reading by a non-unique descriptor (hence the need for the STARTING WITH ISN clause), then knowing the max ISN is completely useless: if the record with the max ISN has the lowest descriptor value, it will be the first record you read.

If you are reading by ISN, then when you start with an ISN > max isn, your loop count (*COUNTER) will be 0.

If you are reading by a descriptor, starting from an ISN, you will get the next record greater than your starting ISN and descriptor value. Again, knowing the max isn will not be useful in this case.

Using binary search…


DEFINE DATA LOCAL
1 myView VIEW OF SAP_PACIENTE

1 #mas-alto (n10)
1 #inicio-isn (n10)
1 #fin-isn (n10)
1 #busca-isn (n10)
1 #FOUND (l)
1 #pos   (n10)

END-DEFINE

RESET #mas-alto
MOVE 1 TO #inicio-isn
MOVE 999999999 TO #fin-isn
*
if #pos = 0

  REPEAT UNTIL #mas-alto > 0
*
    #busca-isn := ((#fin-isn + #inicio-isn) / 2)

    RESET #FOUND

    r3.
    READ myView  BY ISN FROM #busca-isn
      IF #FOUND /* More than one record

        #inicio-isn := *ISN(r3.)
        RESET #mas-alto
        ESCAPE BOTTOM
      end-if

      MOVE TRUE TO #FOUND
      MOVE *ISN TO #mas-alto
*
    end-read
    IF NOT #FOUND
      #fin-isn := #busca-isn
    end-if
  end-repeat
  #pos  := #mas-alto
else
  #pos  := -1
end-if

write 'max isn : ' #pos
end