# Get max ISN

**URL:** <https://techcommunity.softwareag.com/t/get-max-isn/78319>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples\
**Created:** [June 14, 2008, 10:54am UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319 "2008-06-14T10:54:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![noorieh](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@noorieh](https://techcommunity.softwareag.com/u/noorieh)\
**Post date:** [June 14, 2008, 10:54am UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/1 "2008-06-14T10:54:59Z")

</div>

Hello to all

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

thanks

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [June 14, 2008, 4:49pm UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/2 "2008-06-14T16:49:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![noorieh](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@noorieh](https://techcommunity.softwareag.com/u/noorieh)\
**Post date:** [June 15, 2008, 1:17pm UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/3 "2008-06-15T13:17:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bijan](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@Bijan](https://techcommunity.softwareag.com/u/Bijan)\
**Post date:** [June 15, 2008, 1:49pm UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/4 "2008-06-15T13:49:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [June 16, 2008, 12:53pm UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/5 "2008-06-16T12:53:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [September 3, 2009, 11:09am UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/6 "2009-09-03T11:09:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [September 6, 2009, 11:35am UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/7 "2009-09-06T11:35:37Z")

</div>

> [@noorieh](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Angel\_Mendoza\_O1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/angel_mendoza_o1/32/191_2.png) [@Angel\_Mendoza\_O1](https://techcommunity.softwareag.com/u/Angel_Mendoza_O1)\
**Post date:** [February 20, 2010, 1:31am UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/8 "2010-02-20T01:31:35Z")

</div>

Using binary search…

```auto

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
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:50pm UTC](https://techcommunity.softwareag.com/t/get-max-isn/78319/9 "2021-04-02T14:50:30Z")

</div>


