Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WTH: "Built-in function %LEN not valid."

782 views
Skip to first unread message

Mr. K.V.B.L.

unread,
Jan 7, 2015, 11:22:31 AM1/7/15
to
Why am I getting this? Using V7R1 here in a CL program. According to the documentation, %LEN() should exist.

All I want to do is test a parameter for empty string.

Danilo Cussini

unread,
Jan 7, 2015, 11:52:48 AM1/7/15
to
Il giorno mercoledì 7 gennaio 2015 17:22:31 UTC+1, Mr. K.V.B.L. ha scritto:
> Why am I getting this? Using V7R1 here in a CL program. According to the
> documentation, %LEN() should exist.

%LEN() is new in 7.2.

Dr.UgoGagliardelli

unread,
Jan 7, 2015, 12:42:05 PM1/7/15
to
Il 07.01.2015 17.22, Mr. K.V.B.L. ha scritto:
> Why am I getting this? Using V7R1 here in a CL program. According to the documentation, %LEN() should exist.
>
> All I want to do is test a parameter for empty string.
>
That's true starting from V7R2, previously you should use som indirect
way as:
RTVMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&TXT) MSGLEN(&LEN)
if (&len *le 0) /* empty string */

assuming &txt were a *CHAR variable and &len a *DEC (5 0) variable, &len
will contain the characters count of &txt before the first blank.
As CPF9897 defines a message length of 512 bytes (that's the maximum
size for the data field of e predefined message too), &txt should not
exceed taht size. If you need a greater size you can still use the c
function strlen. Accordingly to strlen documentation, it will return a 4
bytes integer, and accepts a null terminated string. E.g.

chgvar &str (&txt *tcat &nul)
callprc 'strlen' &str RTNVAL(%BIN(&bin))
chgvar &len %bin(&bin)

where &nul is a 1 char variable with value x'00', &str is a char
variable of any length, &bin is a 4 bytes char variable, &len and &txt
the same as above.
Due to the presence of an external function, you'll compile the cl as a
cl module (seu option 15), then use crtpgm command specifying
BNDDIR(QC2LE) parameter.

CRPence

unread,
Jan 7, 2015, 2:45:43 PM1/7/15
to
On 07-Jan-2015 10:22 -0600, Mr. K.V.B.L. wrote:
> Why am I getting this? Using V7R1 here in a CL program. According
> to the documentation, %LEN() should exist.

The above was commented-on\explained already by others. However, I
will add:

I did not find that doc. Be aware that the KnowledgeCenter allows
multiple release documents to be searched [via "Search Filters"], and
each of the links presented for a search are denoted with the release.
If there is an IBM i 7.1 doc link, then probably worth posting that link
for clarification.

> All I want to do is test a parameter for empty string.

The CL has no concept of an "empty string", so the typical test of a
*CHAR parameter is to compare the value of the fixed-length character
data type [i.e. not a /string/ data type] with a /blank/ character using
the following predicate:
COND(&CHAR_CLVAR *EQ ' ')

If the CL is coded to map an effective\logical VarChar data type to
simulate what might better be described as a string data type, then the
code can review the length portion of the data-structure to determine
the length [or easily set the length]; e.g.:

dcl &varchar *char len(502)
dcl &vc_len *int len( 2) stg(*defined) defvar(&varchar 1)
dcl &vc_data *char len(500) stg(*defined) defvar(&varchar 3)

if cond(&vc_len *eq 0) /* empty string */
...
chgvar (&vc_len) value(0) /* set &varchar as empty string */

--
Regards, Chuck

Mr. K.V.B.L.

unread,
Jan 7, 2015, 3:48:28 PM1/7/15
to
On Wednesday, January 7, 2015 10:22:31 AM UTC-6, Mr. K.V.B.L. wrote:
> Why am I getting this? Using V7R1 here in a CL program. According to the documentation, %LEN() should exist.
>
> All I want to do is test a parameter for empty string.

Thanks everyone. I had found that I happened upon a V7R2 link my accident. I was able to figure out how to get the job done. Thanks again.
0 new messages