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



RPG always casts any return value as long as it is in the same "family" i.e. numeric, date, or character.

When it does the cast the normal rules of EVAL apply. e.g. character truncation, numeric decimal truncation. And in the case of numerics, an overflow error can occur. Effectively the compiler creates a temp for the returned value of the correct data type and size and then EVALs that temp into the target.

If you use a procedure call as a parameter value then whether the return value is cast or not depends on the prototype of the routine being called. That is when CONST or VALUE is specified the value will be cast. Without those, the compiler would throw an error.

Don't know what Bruce was talking about specifically but most likely he was talking about "lying" to the compiler by specifying an invalid prototype.


Jon P.

On Jul 20, 2023, at 9:06 AM, Osborne, Wynn <Wynn.Osborne@xxxxxxxxxxxxxxxxxx> wrote:

Hi all,

Does RPG implicitly cast a varchar return value (from a procedure) to char when the receiver variable is char?

Sample random code (2 lines):

dcl-s CharacterVariable char(50) inz(' '); //character date type
CharacterVariable = EmailAddress ( 'Bob Saget' ); //EmailAddress has return value defined as varchar(50).

Although this appears to work for some of my teammates I was told by Bruce Vining (remember Bruce??) that if IBM does not explicitly document a behavior then one should never assume it to be true "just because it works for you." (paraphrasing Bruce).
I believe his exact words were, "Bad things can happen." :)

I was thinking of instructing my team to make this practice verboten, but I thought I'd ask the list first.

Unless I'm blind I could find no text in the RPG Reference to address this, much less come close to implying it.

Regards,


[cid:image001.png@01D9BAE8.13979320]
Wynn Osborne
Senior IBM i Programmer-Analyst,Database Administrator
6503 Powell Road | The Villages, FL 32163
Main: 352.750.1515 | Support: 352.674.1530
Direct: 352.674.1563 | Fax: 352.750.1616
wynn.osborne@xxxxxxxxxxxxxxxxxx<mailto:wynn.osborne@xxxxxxxxxxxxxxxxxx> | http://www.TheVillagesTSG.com<http://www.thevillagestsg.com/>


--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.



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.