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



Hi,

of course, this can „easily" be done using embedded SQL and a bit of regular expression magic:

exec sql select ifnull(regexp_substr(matterid, '^.*?(?=-)', 1), matterid),
ifnull(regexp_substr(matterid, '(?<=-)(.*?)$'), ‚'')
into :clino, :matno
from (values(:mattered)) as t1 (matterid);

It will return the both parts of the matterid - and if no "-" is found, it will return the matterid in clino, and an empty string in matno.

SQL will take care of the data types of the receiving fields.

And for what it’s worth - I would refactor the procedure into 2 procedures, where you can return the correct values, like:

clino = ExtractClinoFromMatterId(matterid);
matno = ExtractMatnoFromMatterId(matterid);

This way, you won’t have any problems, because the implicit „eval“ will assign the value into the correct length.

Just my 2ct of „chewing“ on the problem.

Kind regards,
Daniel


Am 22.12.2021 um 18:39 schrieb Mark Murphy <jmarkmurphy@xxxxxxxxx>:

So the lesson for today is:

If you use option(*varsize) for a varchar, and expect to return a new value
if that parameter, you need to use OpDesc as well, or some other method to
determine the max length of the passed field.

The modified split function is:

dcl-proc Split;
dcl-pi *n OpDesc;
arg Varchar(64) const options(*varsize);
string Varchar(MAX_VARCHAR2) const options(*varsize);
part1 Varchar(MAX_VARCHAR2) options(*varsize);
part2 Varchar(MAX_VARCHAR2) options(*varsize);
end-pi;

dcl-s pos Int(5);
dcl-s dataTp Int(10);
dcl-s pt1len Int(10);
dcl-s pt1max Int(10);
dcl-s pt2len Int(10);
dcl-s pt2max Int(10);
dcl-s fc Like(feedback_t);

ceegsi(%parmnum(part1): dataTp: pt1len: pt1max: fc);
if %subst(fc:6:7) = CEEGSI_FC_NORMAL;
ceegsi(%parmnum(part2): dataTp: pt2len: pt2max: fc);
endif;

pos = %scan(arg: string);
if pos = 0;
part1 = string;
part2 = '';
else;
part1 = Left(string: pos-1);
part2 = Mid(string: pos+%len(arg));
endif;

if %subst(fc:6:7) = CEEGSI_FC_NORMAL;
%len(part1) = %min(pt1max: %len(part1));
%len(part2) = %min(pt2max: %len(part2));
endif;
end-proc;

On Wed, Dec 22, 2021 at 8:23 AM Mark Murphy <jmarkmurphy@xxxxxxxxx> wrote:

32767 Byte is the maximum length for an SQL VarChar (longer character
columns must be then defined as CLOB)

I thought that was 32740 for SQL, maybe that is if it is null capable.

On Tue, Dec 21, 2021 at 11:49 PM Birgitta Hauser <Hauser@xxxxxxxxxxxxxxx>
wrote:

Aren't VARCHAR fields limited to 32765 (or something)
32767 Byte is the maximum length for an SQL VarChar (longer character
columns must be then defined as CLOB)

Mit freundlichen Grüßen / Best regards

Birgitta Hauser


"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
„Train people well enough so they can leave, treat them well enough so
they
don't want to.“ (Richard Branson)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of x y
Sent: Dienstag, 21. Dezember 2021 21:08
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: Anyone care to chew on this for a bit?

MAX_VARCHAR2 is a literal.

Aren't VARCHAR fields limited to 32765 (or something), with the first two
bytes defining the field's length?

What about this? SHouldn't the PI header have the procedure name and
return
code only?
dcl-pi *n Varchar(MAX_VARCHAR2) RtnParm;

On Tue, Dec 21, 2021 at 9:23 AM Mark Murphy <jmarkmurphy@xxxxxxxxx>
wrote:

The error is RNX0115. Length of varying length variable is out of range.

IBM i v7r2

Here is a reproduction of the problem:

**free
ctl-opt DftActGrp(*No) ActGrp(*New)
Option(*NoDebugIo: *SrcStmt: *NoUnref)
Main(SPLITTST);

dcl-c MAX_VARCHAR2 32767;

dcl-proc splittst;
dcl-s matterid Char(25) Inz('LA-Support');
dcl-s clino Varchar(20) Inz('');
dcl-s matno Varchar(20) Inz('');
dcl-s climat Char(20);

split('-': matterid: clino: matno);
climat = left(clino + ' ': 10) + matno;

dsply matterid;
dsply clino;
dsply matno;
dsply climat;

return;
end-proc;

dcl-proc Split;
dcl-pi *n;
arg Varchar(64) const options(*varsize);
string Varchar(MAX_VARCHAR2) const options(*varsize);
part1 Varchar(MAX_VARCHAR2) options(*varsize);
part2 Varchar(MAX_VARCHAR2) options(*varsize);
end-pi;

dcl-s pos Int(5);

pos = %scan(arg: string);
if pos = 0;
part1 = string;
part2 = '';
else;
part1 = Left(string: pos-1);
part2 = Mid(string: pos+%len(arg));
endif;
end-proc;

dcl-proc Left;
dcl-pi *n Varchar(MAX_VARCHAR2) RtnParm;
string Varchar(MAX_VARCHAR2) const options(*varsize);
len Int(5) const;
end-pi;

if len <= 0;
return '';
elseif %len(string) <= len;
return string;
endif;
return %subst(string: 1: len);
end-proc;

dcl-proc Mid;
dcl-pi *n Varchar(MAX_VARCHAR2) RtnParm;
string Varchar(MAX_VARCHAR2) const options(*varsize);
start Int(5) const;
len Int(5) const options(*nopass);
end-pi;

if %len(string) < start;
return '';
elseif %parms() < %parmnum(len);
return %subst(string: start);
elseif len = 0;
return '';
elseif %len(string) < start + len;
return %subst(string: start);
endif;

return %subst(string: start: len);
end-proc;

Everything you need is here. In the real program, the procedures are
in a service program, and the constant is in a separate header file.
But I have consolidated it all down into a single program that exhibits
the problem.
The error is:

Additional Message Information



Message ID . . . . . . : RNX0115 Severity . . . . . . . : 50

Message type . . . . . : Diagnostic

Date sent . . . . . . : 12/21/21 Time sent . . . . . . :
12:07:21


Message . . . . : Length of varying length variable is out of range.

Cause . . . . . : The length of a varying length character or DBCS
variable
is less than 0 or greater than its declared maximum length in RPG
procedure
SPLITTST in program JMMLIB/SPLITTST.

Recovery . . . : Contact the person responsible for program
maintenance
to
determine the cause of the problem.














Bottom
Press Enter to continue.



F3=Exit F6=Print F9=Display message details

F10=Display messages in job log F12=Cancel F21=Select assistance
level




The variables contain:

Evaluate Expression



Previous debug expressions



EVAL matterid:x

00000 D3C160E2 A4979796 99A34040 40404040 - LA-Support

00010 40404040 40404040 40...... ........ - .......

EVAL clino:x

00000 0002D3C1 00000000 00000000 00000000 - ..LA............

00010 00000000 0000.... ........ ........ - ................

EVAL matno:x

00000 0016E2A4 97979699 A3404040 40404040 - ..Support

00010 40404040 4040.... ........ ........ - ..........












Bottom
Debug . . .



F3=Exit F9=Retrieve F12=Cancel F16=Repeat find F19=Left
F20=Right
F21=Command entry F23=Display output




I don't see anything wrong with this.
But it gets better, change the value in matterid to '12345-001' and
the program runs fine!!

Here is that output:

Display Program Messages



Job 195579/MMURPHY/QPADEV0002 started on 12/21/21 at 12:06:21 in
subsystem Q DSPLY 12345-001

DSPLY 12345

DSPLY 001

























Press Enter to continue.







F3=Exit F12=Cancel
--
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.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.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.

Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://amazon.midrange.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.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.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.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com

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.