# The Longest Record of a File

**URL:** <https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-Basics-on-Linux-Unix-Windows, Adabas-on-Windows-UNIX, Adabas-on-Linux\
**Created:** [June 2, 2006, 5:56pm UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033 "2006-06-02T17:56:37Z")\
**Posts on this page:** 9\
**Page:** 1

<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 2, 2006, 5:56pm UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/1 "2006-06-02T17:56:37Z")

</div>

Hello all!

With the utility ADAFIN, I can find out the longest record of a file (in bytes). Here’s the output of my adafin … usage=ds

```auto
Records: Number = 941,385
          Length: max = 3,170 , min = 79 , avg = 417.80
```

Is there a way to find out the ISN of this 3170-byte-record? I think there is a special reason, why this particular record is so long. But I have to prove this…

My best idea is: make a ADAULD of the whole file and write a script which does the wanted investigations by reading the unloaded file. But this solution would be very time consuming.

Any better ideas?

---

<div class="post-metadata">

**Author:** ![Peter\_Dowson](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@Peter\_Dowson](https://techcommunity.softwareag.com/u/Peter_Dowson)\
**Post date:** [June 6, 2006, 6:55pm UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/2 "2006-06-06T18:55:09Z")

</div>

Instead of trying to use Adabas utilities, why not write a little Natural program to read the whole file and get it to tell you.

Peter

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [June 7, 2006, 12:46am UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/3 "2006-06-07T00:46:35Z")

</div>

Because Natural returns decompressed records - they will all be the same length. Your “little program” would have to mimic Adabas’ compression routine. (Perhaps deleting trailing blanks in alpha fileds would be a close-enough approximation.) An unload (without decompression) will give you variable-length records, so you’d be able to find the longest one.

If you’re presuming that the differences in length are a factor of the number of PE and/or MU entries, then the “little program” could list ISNs for the records with the largest count fields (C\*).

---

<div class="post-metadata">

**Author:** ![zarchasmpgmr](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/zarchasmpgmr/32/126_2.png) [@zarchasmpgmr](https://techcommunity.softwareag.com/u/zarchasmpgmr)\
**Post date:** [June 7, 2006, 2:31am UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/4 "2006-06-07T02:31:48Z")

</div>

You can get this info - both the compressed and uncompressed length - by writing your own direct call program, either in NAT or C.

If you issue an Lx command, the additions 2 field contains 2 half words, the first being the compressed length and the second is the uncompressed length.

If you write a program in NAT, use the USR1043N interface to make the direct call.

At one time I had a NAT program that read an entire file physically using an L2 call and calculated the longest and average lengths (compressed and uncompressed). A quick cursory look of my personal archive doesn’t find it, but if I do find it, I will upload it.

Kind regards,  
Ray Mullins

---

<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 8, 2006, 5:34pm UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/5 "2006-06-08T17:34:46Z")

</div>

> [@Ray Mullins](#):
>
> If you issue an Lx command, the additions 2 field contains 2 half words, the first being the compressed length and the second is the uncompressed length.

Good hint! This helps me! Here’s my try - it’s working! 🙂

```auto
define data local
*
1 CONTROL-BLOCK (A80)
1 REDEFINE CONTROL-BLOCK
[snip] /* please have a look at USR1043P
1 RESPONSE (I04)
*
1 #ISN (I04)
1 #length-B (B02)
1 REDEFINE #length-B
  2 #COMPRESSED-LENGTH (I02)
*
end-define
*
REPEAT
*
RESET CB-DBID CB-FNR CB-RSP CB-ISN CB-ISL CB-ISQ CB-FBL
      CB-RBL CB-SBL CB-VBL CB-IBL CB-RESERVED
*
  CB-CMD := 'L2' /* read physical Command
  CB-CID := '0001' /* Command ID
  CB-RSP := 010 /* UDB
  CB-FNR := 010 /* File
  CB-FBL := H'03' /* Format buffer length
  CB-RBL := H'01' /* Record buffer length
  FORMAT-BUFFER := 'AA.' /* any field
*
  CALLNAT 'USR1043N'
    CONTROL-BLOCK FORMAT-ADDR RECORD-ADDR SEARCH-ADDR
    VALUE-ADDR ISN-ADDR RESPONSE
*
  IF RESPONSE = 0
    #length-B := CB-ADD2
    #ISN := CB-ISN
    display CB-ISN CB-ADD2 (EM=HHHHHHHH) #ISN #COMPRESSED-LENGTH
  ELSE
    ESCAPE BOTTOM
  END-IF
*
END-REPEAT
*
IF RESPONSE NE 0 AND RESPONSE NE 3
  WRITE 'ADABAS response code (L2):' RESPONSE
END-IF
*
RESET CB-DBID CB-FNR CB-RSP CB-ISN CB-ISL CB-ISQ CB-FBL
      CB-RBL CB-SBL CB-VBL CB-IBL CB-RESERVED
*
CB-CMD := 'RC' /* Release Command
CB-CID := H'00000000'
*
CALLNAT 'USR1043N'
  CONTROL-BLOCK FORMAT-ADDR RECORD-ADDR SEARCH-ADDR
  VALUE-ADDR ISN-ADDR RESPONSE
*
IF RESPONSE NE 0
  WRITE 'ADABAS response code (RC):' RESPONSE
END-IF
*
END
```

---

<div class="post-metadata">

**Author:** ![zarchasmpgmr](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/zarchasmpgmr/32/126_2.png) [@zarchasmpgmr](https://techcommunity.softwareag.com/u/zarchasmpgmr)\
**Post date:** [June 9, 2006, 3:17am UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/6 "2006-06-09T03:17:02Z")

</div>

Great! Glad I could help! 😃

---

<div class="post-metadata">

**Author:** ![Peter\_Dowson](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@Peter\_Dowson](https://techcommunity.softwareag.com/u/Peter_Dowson)\
**Post date:** [June 9, 2006, 4:47pm UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/7 "2006-06-09T16:47:13Z")

</div>

Please to see that a little Natural program solved your issues :lol:

Peter

---

<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 9, 2006, 7:32pm UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/8 "2006-06-09T19:32:08Z")

</div>

> [@Peter Dowson](#):
>
> Please to see that a little Natural program solved your issues :lol:

But you have to admit that the ADABAS L2-command does the job, not the NATURAL-Program 😉

---

<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:39pm UTC](https://techcommunity.softwareag.com/t/the-longest-record-of-a-file/58033/9 "2021-04-02T14:39:00Z")

</div>


