×
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.
-----Original Message-----
From: Scott Klement [mailto:rpg400-l@xxxxxxxxxxxxxxxx]
Sent: Thursday, April 23, 2020 5:59 PM
To: rpg400-l@xxxxxxxxxxxxxxxxxx
Subject: Re: %str() use discouraged?
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
As an Amazon Associate we earn from qualifying purchases.
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.