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



Thanks Chuck. This works perfectly!

I also found the article below.

http://www.itjungle.com/fhg/fhg112906-story01.html


-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of CRPence
Sent: Tuesday, April 16, 2013 10:27 AM
To: midrange-l@xxxxxxxxxxxx
Subject: Re: how to create a command to accept a parm of any length

On 15 Apr 2013 14:11, Stone, Joel wrote:
I would like to create a command to accept a parm of any length.

Must I use VARY(*YES) in the CMD source?

Do I then have to check the 1st two bytes of the parm for the
length?

Yes. The number of bytes of the integer length type *INT# that was
specified for Value Length [second element of the VARY() parameter].

If I state the LEN(500) as the max length, I would like any CL pgm to
use the command with a parm of any length 500 or less.

Normally a program would always declare the same length as the
invoked program to prevent any issues due to parameter length
mismatches. As long as the *VARY parameter is only ever received by the
CPP vs any other CALLable interface, then all can work well.

But the calling pgm forces me to pass a parm of length 500.

Such a restriction was never enforced in older releases. I would be
hesitant to accept that as accurate... without some error message
describing what is meant.

I have tried VARY(*YES), but it seems to not work well.

What is required in addition to VARY(*YES)?

Both "forces" and "not work well" are nebulous. Any concrete
examples? Hopefully my example below will cover what is being attempted.

Nothing more than VARY(*YES) is required on the *CMD. But then one
must code the CPP to properly handle and use the additional data; i.e.
the declaration in the CPP would be for 502 bytes vs 500, to accommodate
the length value that precedes the character data. And the CPP should
use that Length Value to access only that much of the passed character
data in the field [e.g. via %sst]; i.e. neither the entire 500-byte
component nor the overall 502-bytes of the full variable should ever be
accessed.

Treat the PARM as input-only and look only at the data up to the
length provided, and there should be no difficulties. See the following
example, whereby the invoker declares smaller variables and sends
shorter strings:

CPP: crtclpgm qtemp/parm500

pgm parm(&vc500inp) /* CPP for PARM500 command */
dcl &vc500inp *char 502 /* this is an *input-only* parameter */
dcl &vclen *int 2 /* stg(*defined) defvar(&vc500inp 1) */
dcl &chlen *char 3
dcl &dclen *dec 3
dcl &text *char 500 /* local copy of the "500-char" field */
chgvar &vclen %bin(&vc500inp 1 2) /* already set if defined stg */
chgvar &text %sst(&vc500inp 3 &vclen) /* copy only given-portion
into local */
chgvar &dclen &vclen /* setup for message with nbr of bytes: */
chgvar &chlen &dclen
sndpgmmsg msg('**' *bcat &chlen *bcat '**' *bcat &text)
endpgm

CMD: crtcmd qtemp/parm500 qtemp/parm500

PARM500: +
CMD PROMPT('pass a parm as *vary ')
PARM KWD(CHAR500) TYPE(*CHAR) LEN(500) RSTD(*NO) +
PROMPT('Input char String') EXPR(*YES) +
ALWUNPRT(*NO) ALWVAR(*YES) MIN(1) +
PASSATR(*NO) VARY(*YES *INT2)

CLP: crtclpgm qtemp/parm500tst /* tests the CMD+CPP */

dcl &p50 *char 50 '50 byte string is 20'
dcl &p250 *char 250 '250 byte string is thirtyBytes'
dcl &p500 *char 500 '500 byte string is some forty bytes long'
/* three literal calls */
parm500 '50 byte string is 20'
parm500 '250 byte string is thirtyBytes'
parm500 '500 byte string is some forty bytes long'
/* three CL variable calls */
parm500 &p50
parm500 &p250
parm500 &p500

CLP: called; output follows:

call PARM500TST
** 020 ** 50 byte string is 20
** 030 ** 250 byte string is thirtyBytes
** 040 ** 500 byte string is some forty bytes long
** 020 ** 50 byte string is 20
** 030 ** 250 byte string is thirtyBytes
** 040 ** 500 byte string is some forty bytes long

Regards, Chuck

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.