Article ID: 89131 - View products that this article applies to.
This article was previously published under Q89131
This article has been archived. It is offered "as is" and will no longer be updated.
LEN_TRIM may appear to return an incorrect trimmed string length. This occurs when the string in the calling routine is not initialized and the subprogram's formal argument declares the character string smaller than the original string's length.
All bytes in uninitialized strings are set to zero (null characters). When a string is initialized, any unused bytes are padded with spaces to the end of the string. The padding is done to the size that is declared in the routine in which the string is initialized. If a string is passed to a routine that declares the string size to be smaller then it was defined, the string will be incompletely padded with spaces. Upon return to the routine where the string was declared, the string will still have null characters at the end. The LEN_TRIM intrinsic function only parses for spaces and will stop immediately when it detects the final null character. This will appear to be incorrect because most editors display null characters as blanks.
LEN_TRIM works correctly if the string lengths are declared equal in all routines that the use the string. Also, initializing the string to all spaces in the routine in which it is originally declared will also correct the problem.
Code to Reproduce Problem
Code to Correct Problem
Article ID: 89131 - Last Review: October 14, 2013 - Revision: 2.0
Contact us for more help
Connect with Answer Desk for expert help.