× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



The null terminator is a Character, value X'00'.
In order to add a character to a string, there must be space for it.

If you want the destination string to contain the null terminator character, then the string should be 1 character greater than the max length of the source string.

If both strings are the same length and the source string has no trailing blanks, then there is no space left in the destination string's allocated memory to add the null terminating character.

The ILE RPG Reference is really quite concise:

"If the length specified as the second parameter of %STR is N, then at most N-1 bytes of the right-hand side can be used, since 1 byte must be reserved for the null-terminator at the end."


If you don't need to actually use the null terminated string for anything, then it would probably be better to do as Brian suggested and allow the prototype's "options(*string)" take care of the Null terminator conversion for you.


I find it simpler to just use a Varchar as the file/path name field.
Then you only need to trim the field once in the processing.


Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of PAPWORTH Paul
Sent: Wednesday, May 10, 2017 3:29 AM
To: rpg400-l@xxxxxxxxxxxx
Subject: Null terminated string question

Hello
Can anybody explain why with the following code which works well , if I have the two fields l_path-1 and l_path_2 declared as char(70) the results from the %str function do not have the null terminator added to the end of the string.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.