# \*TRIM not removing trailing whitespaces from variable

**URL:** <https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, NaturalONE\
**Created:** [November 26, 2024, 5:46am UTC](https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371 "2024-11-26T05:46:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris90](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/chris90/32/36606_2.png) [@Chris90](https://techcommunity.softwareag.com/u/Chris90)\
**Post date:** [November 26, 2024, 5:46am UTC](https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371/1 "2024-11-26T05:46:38Z")

</div>

Hello,

I have a problem which somehow I don’t seem to be able to solve myself. In this case I got a dynamic variable of type (A) which got filled by a subprogram with a password.

That password was read from a work file and may varry in length, that is why I am using dynamic variables. Now however, I want to compress a few string variables along with the password variable into another output string. My problem is, that the password string is keeping the trailing whitespaces and I have a lot of white spaces in the print and write work file results.

Im wondering why TRIM isnt removing the trailing whitespaces in my case.

Here is the code slightly altered for public usage.

DEFINE DATA LOCAL  
1 #password (A) dynamic INIT \<‘22 22 21 23’\> /\* INPUT HEX VALUE  
1 #PASSWORD-A (A) dynamic /\* CONVERTED PASSWORD TO ALPHANUMERIC  
1 #adatext1 (A82) /\* SOME VARIABLE USED FOR COMPRESSION AND OUTPUT

END-DEFINE  
FORMAT LS=250 PS=250  
CALLNAT ‘HEXTOA’ #password #PASSWORD-A /\* HEX INPUT TO A CONVERSION

COMPRESS ‘somestringnumberone’ \*TRIM(#PASSWORD-A) ‘someotherstring2’ INTO #adatext1

PRINT #adatext1 /\* Whitespaces still contained after PASSWORD-A  
WRITE WORK FILE 1 #adatext1  
CLOSE WORK 1  
END

---

<div class="post-metadata">

**Author:** ![Dion\_Kejlberg](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/dion_kejlberg/32/525_2.png) [@Dion\_Kejlberg](https://techcommunity.softwareag.com/u/Dion_Kejlberg)\
**Post date:** [November 26, 2024, 7:29am UTC](https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371/2 "2024-11-26T07:29:40Z")

</div>

Perhaps you should add LEAVING NO at the end of your COMPRESS.

---

<div class="post-metadata">

**Author:** ![Chris90](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/chris90/32/36606_2.png) [@Chris90](https://techcommunity.softwareag.com/u/Chris90)\
**Post date:** [November 26, 2024, 7:34am UTC](https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371/3 "2024-11-26T07:34:44Z")

</div>

Thank you I tried that already and it does not make any difference. The whitespaces after #PASSWORD-A still appear.

---

<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:** [November 26, 2024, 10:14am UTC](https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371/4 "2024-11-26T10:14:04Z")

</div>

The first thing to check is the output of your subprogram. Insert  
`WRITE '=' PASSWORD (EM=H(8)) '=' #PASSWORD-A (EM=H(8))`  
after the CALLNAT. I think you’re getting non-printable characters instead of trailing spaces (H’20’).

The \*TRIM function is redundant. COMPRESS is already removing trailing blanks.

I don’t see the need for dynamic variables. COMPRESS will give you a variable-length result.

---

<div class="post-metadata">

**Author:** ![Chris90](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/chris90/32/36606_2.png) [@Chris90](https://techcommunity.softwareag.com/u/Chris90)\
**Post date:** [November 26, 2024, 10:32am UTC](https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371/5 "2024-11-26T10:32:39Z")

</div>

The “error” might in fact lay in the subprogram itself, as the subprogram takes a dynamic variable and converts the hex values it holds using edit mask to binary and from there on returns it in readable format to the caller.

Since I do not know in advance how long the input parameter is, I was using EDIT MASK with H(16) to convert Hex to String. The whitespaces were caused by the remainder of the H(16) of the EDIT MASK.

I know solved this issue the following way.

DEFINE DATA  
PARAMETER  
1 #HEX-I (A) DYNAMIC /\* INPUT VALUE HEX FORMAT  
1 #HEX-O (A) DYNAMIC /\* OUTPUT VALUE ALPHANUMERIC READABLE  
LOCAL  
1 #LENGTH (N4) /\* COUNTER TO STORE NUMBER OF CHARACTERS  
1 #BIN (B) DYNAMIC  
END-DEFINE

EXAMINE FULL #HEX-I FOR ’ ’ DELETE /\* REMOVE WHITESPACES BETWEEN HEX VALUES FROM INPUT  
EXAMINE FULL #HEX-I FOR ’ ’ GIVING LENGTH #LENGTH /\* COUNT CHARACTERS IN VARIABLE TO BE CONVERTED  
#LENGTH := #LENGTH / 2 /\* DIVIDE BY 2 SINCE HEX VALUES CONSIST OF 2 VALUES

MOVE EDITED #HEX-I TO #BIN(EM=H(32))  
MOVE SUBSTRING(#BIN, 1, #LENGTH) TO #HEX-O /\* RETURN SUBSTRING TO NOT RETURN WHITE SPACES FROM EDIT MASK

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:** [May 25, 2025, 10:32am UTC](https://techcommunity.softwareag.com/t/trim-not-removing-trailing-whitespaces-from-variable/303371/6 "2025-05-25T10:32:43Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
