# How to do Space trimming for an alphanumeric file : Natural Version:3.1

**URL:** <https://techcommunity.softwareag.com/t/how-to-do-space-trimming-for-an-alphanumeric-file-natural-version-3-1/98765>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [October 21, 2011, 12:58pm UTC](https://techcommunity.softwareag.com/t/how-to-do-space-trimming-for-an-alphanumeric-file-natural-version-3-1/98765 "2011-10-21T12:58:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aseem\_sharma](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@aseem\_sharma](https://techcommunity.softwareag.com/u/aseem_sharma)\
**Post date:** [October 21, 2011, 12:58pm UTC](https://techcommunity.softwareag.com/t/how-to-do-space-trimming-for-an-alphanumeric-file-natural-version-3-1/98765/1 "2011-10-21T12:58:51Z")

</div>

I have a 4000 fixed length file in whcih the fields are “|” delimited .I need to COMPRESS the fields ans make it variable length “|” delimited.Currently i am not able to use EXAMINE and COMPRESS for the same as the maximum length allowed in this version for an elementary variable in 253 . Alpha-253 and EXAMINE and COMPRESS does not work on group vairable .

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [October 21, 2011, 4:53pm UTC](https://techcommunity.softwareag.com/t/how-to-do-space-trimming-for-an-alphanumeric-file-natural-version-3-1/98765/2 "2011-10-21T16:53:28Z")

</div>

How about:

```auto

DEFINE DATA LOCAL
1 #RECORD (A4000)
1 #A (A/2000) DYNAMIC
1 #B (A) DYNAMIC
END-DEFINE
*
READ WORK FILE 1 #RECORD
  SEPARATE #RECORD INTO #A(*) WITH DELIMITERS '|'
  COMPRESS #A(*) INTO #B WITH DELIMITERS '|'
  WRITE WORK FILE 2 VARIABLE #B
END-READ
END
```

---

<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:** [October 21, 2011, 9:28pm UTC](https://techcommunity.softwareag.com/t/how-to-do-space-trimming-for-an-alphanumeric-file-natural-version-3-1/98765/3 "2011-10-21T21:28:40Z")

</div>

Natural 3.1! Yikes!! Jerome seems to have missed that detail, because DYNAMIC variables weren’t available until Natural 4.

Here’s a solution that uses a vector, but be warned that it will burn a bit of CPU. I used Natural 6.3, so you’ll have to verify its results in your own environment - I offer neither guarantees nor warranties.

```auto
DEFINE DATA LOCAL
1 #MAX (I4) CONST <50> /* record length
1 #R (A1/#MAX)     
                   1 REDEFINE #R /* debug
  2 #REC (A50) /* debug
1 #T (A1/#MAX)
1 #I (I4)
1 #J (I4)
1 #C (I4)
END-DEFINE
DEFINE WORK FILE 1 'c:\ProgramData\Software AG\Natural\Natapps\Fuser\'
                 - 'Open-Src\Res\COMPREC.TXT'
READ WORK 1 #R (*)
  WRITE 'Before:' #REC /* debug
  /*
  FOR #I = 1 #MAX /* right-to-left
    ASSIGN #J = #MAX - #I + 1
    ASSIGN #T (#J) = #R (#I)
  END-FOR
  /*
  ASSIGN #I = 1
  ASSIGN #J = #MAX
  REPEAT /* compress
    IF #T (#I) = '|'
     AND #T (#I + 1) = ' '
      THEN
        ASSIGN #T (#I + 1 : #MAX - 1) = #T (#I + 2 : #MAX)
        RESET #T (#MAX)
      ELSE
        ADD 1 TO #I
    END-IF
    IF #I >= #MAX
     OR #I >= #J
      THEN
        ESCAPE BOTTOM
    END-IF
  END-REPEAT
  /*
  FOR #C = #MAX 1 -1 /* record length
    IF #T (#C) <> ' '
      THEN
        ESCAPE BOTTOM
    END-IF
  END-FOR
  RESET #R (*)
        #J
  FOR #I = 1 #C /* left-to-right
    ASSIGN #J = #C - #I + 1
    ASSIGN #R (#J) = #T (#I)
  END-FOR
  WRITE ' After:' #REC / /* debug
  /* WRITE WORK 2 VARIABLE #R (1:#C) /* <<<
END-WORK
END
```

```auto
Page 1 10/21/11 12:03:26
 
  Before: 123 | abcd |456 | | |
   After: 123| abcd|456|||
 
  Before: 123 |abcd |456 | | | |
   After: 123|abcd|456||||
```

Push for a Natural upgrade, Aseem. Jerome’s solution demonstrates several ways in which the language has improved, but there are many more.

---

<div class="post-metadata">

**Author:** ![aseem\_sharma](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@aseem\_sharma](https://techcommunity.softwareag.com/u/aseem_sharma)\
**Post date:** [October 24, 2011, 5:38pm UTC](https://techcommunity.softwareag.com/t/how-to-do-space-trimming-for-an-alphanumeric-file-natural-version-3-1/98765/4 "2011-10-24T17:38:17Z")

</div>

thanks

---

<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, 3:01pm UTC](https://techcommunity.softwareag.com/t/how-to-do-space-trimming-for-an-alphanumeric-file-natural-version-3-1/98765/5 "2021-04-02T15:01:08Z")

</div>


