× 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.



Justin,

Your code is absolutely right.  getenv() returns a pointer to a null-terminated string, and %str() converts that to an RPG VARCHAR.

Francois' code doesn't make any sense and won't compile.  The first parameter to %STR() needs to be a pointer, not a string literal.  Plus, getenv() returns a pointer, but %STR() returns a string -- you can't compare a pointer to a string in RPG.

I do have a suggestion for you, though...   getenv() will return *NULL if the variable isn't found, and %STR() will have a problem with that *NULL value.  So unless you're certain that 'ENV_VAR' will always be found, you should write your code like this:

dcl-s varp pointer;

varp = getenv('ENV_VAR');
if varp<>*null and %str(varp) = 'Literal value here';

That way, there won't be any error if the variable isn't found.   Or, if you prefer the coding style you've shown us, you could put that style in a monitor block.

-SK

On 4/23/2020 12:10 PM, Justin Taylor wrote:
My code works, so maybe my assumption about getenv() returning a null-terminated string was wrong.

-----Original Message-----
From: Francois Lavoie [mailto:Francois.Lavoie@xxxxxxxxxxxxxxxxxxxx]
Sent: Thursday, April 23, 2020 8:34 AM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: %str() use discouraged?

If getenv returns a null-terminated string then the statement should be:

If getenv('ENV_VAR') = %str('Literal value here');

But you would had figured that out



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.