|
Alan,
You'd be correct if this was only being called from RPG. It's actually
the prototype in RPG that will do this for you, it will convert to another
data type. (And it doesn't have to be by value, it can be either value or
CONST reference)
However, that's not at all true when calling from CLLE -- which Mike
explicitly said that he wanted.
The CL compiler can't automatically change the data type of the variable,
because it doesn't know which data type the RPG procedure is expecting...
How could it, if there's no prototype to tell it what the data type should
be?!
However, there are ways to do what Mike is looking for, but they are not
quite as elegant.
1) You can use operational descriptors to find out the type of data
passed. Then, you can treat it accordingly (for example, you could use a
pointer to map the parameter to a variable with the appropriate data type.)
2) This is risky, but... a VARYING ("VarChar" is the SQL term) field will
have a 2 or 4 byte prefix containing the length. Bytes that make up
characters are almost always x'40' or higher. So for parameters with a
short max length, if the first byte is < x'40', then it's probably a
VARYING parameter, if it's x'40' or higher it's a fixed-length character.
Otherwise, it's a varying field.
3) As Joep mentioned, you could have a wrapper. One procedure accepts a
fixed-length variable, the other a varying variable. The fixed-length one
could call the varying one. That way, the CL can call the fixed-length
interface, and RPG can call the varying interface.
On 9/29/2014 12:08 AM, Alan Campin wrote:
The procedure will do it for you. If you are passing by value, when youThis is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
pass a char it will automatically map to varchar. The only other thing
that
you need to do is to include the option *Trim to cause the value to be
trimmed when it is passed so you get the actual length.
This mechinism would work from CLLE or RPGLE.
On Sun, Sep 28, 2014 at 9:45 PM, Mike Pantzopoulos <
Mike.Pantzopoulos@xxxxxxxxxx> wrote:
I was wondering if there is any way that a Char value can be passed to a
sub-procedure such that it ends up as a Varchar inside the procedure.
In other words, the parameter interface is defined as Varchar(1024), but
the value passed is defined as Char(512). I want to be able to invoke the
procedure from both RPGLE and CLLE, and as CLLE does not have a native
VARCHAR definition I was hoping to be able to get the parameter passing
mechanism to do this on-the-fly.
I know how to create a VARCHAR like value in CL, but don't want fellow
developers to have to go through this pain to use my sub-procedure..
TIA...
____________________________________________________________
___________________________
The information transmitted in this message and its attachments (if any)
is intended
only for the person or entity to which it is addressed.
The message may contain confidential and/or privileged material. Any
review,
retransmission, dissemination or other use of, or taking of any action in
reliance
upon this information, by persons or entities other than the intended
recipient is
prohibited.
If you have received this in error, please contact the sender and delete
this e-mail
and associated material from any computer.
The intended recipient of this e-mail may only use, reproduce, disclose
or
distribute
the information contained in this e-mail and any attached files, with the
permission
of the sender.
This message has been scanned for viruses.
____________________________________________________________
___________________________
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
--
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
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.