Tom: I have tried to set the length to 50 which would accommodate the lengths of all the fields I want to reference. When I do this and try to get data that is less then the defined length of 50 I get an error. When I look at the value of the variable using debug I can see 50 chars of data in the variable.
Here is my call to the procedure:
FieldToCheck = %addr(filerec.PLCD);
CheckValue = TPLCD;
FillArrayAll(FieldToCheck:CheckValue:ArrayValue);
FieldToCheck is a pointer to the varible that will hold data once a record is read. At this point there is no data. I fill the memory on a read in the called procedure. This field is a 1A field. I do not have any problem if I define the variable in the called procedure as 1A :
P FillArrayAll B
D FillArrayAll PI
D FieldToCheck *
D CheckValue 50A
D ArrayValue 50A
D*
DCheckField S 1A based(FieldToCheck) VARYING
D
D
My question is How do I define the varible CheckField so that when FieldToCheck points to a variable that is say 10A in length Checkfield will adjust accordingly. My understanding from the documentation is that by using BASED(pointer) it should adjust itself but that doesn't seem to be working that way and I was hoping someone has done this before and can tell me what I'm doing wrong or if this can't be done at all.
******************************************
Don Wereschuk
ISD - Programmer/Analyst
Simcoe Parts Service Inc.
Phone: 705-435-7814 Ex: 302
Fax: 705-435-6746
mailto:dwereschuk@xxxxxxxxxxxxxxx
******************************************
"Save the Cheerleader - Save the world" - Hiro Nakamura
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of qsrvbas@xxxxxxxxxxxx
Sent: Monday, January 21, 2008 3:52 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Passing Parameters
Don Wereschuk wrote:
I'm not passing the value in the data file field. I'm passing a pointer to the address of the variable that contains the data. The variable gets updated in the called procedure by reading the records in the data file. On one call I use Field1 from the file which is 1A but on another call I want to use Field2 which could be 10A. I set the length of the variable to 50A which should cover the maximum length of any fields I'm interested in. The problem is that using the Based(pointer) and the field is only 1A the system tries to put 50 chars into a 1 char size field.
Don:
As you say, you're not passing the field; you're passing an address
to some field. (I suppose; I don't see the code from the calling
proc here.)
The VARYING is not adjusting the length to correspond to the actual Field length which is what the help says should happen.
AFAIK, that's because you've set a maximum length of 1. Set the
definition to allow the maximum length that you expect ever to receive.
Because you limited the definition to 1 in the called proc, the
called proc can't (won't?) go past the limit that you set. You told
the proc that the field can only access up to a maximum of [1A] and
that's what you're getting. From the manual -- "The current length
may be any value from 0 to the maximum declared length for the field."
And because it's a BASED field in your proc, it doesn't actually
take up its own memory. It simply overlays the address from the
calling proc with a local definition of that memory.
You might as well define it as length 65535.
Actually, I'm not at all clear on what's going on behind the scenes
when you _try_ to access it as a length 10 field. I'd expect some
kind of run-time error that says the length is invalid.
Tom Liotta
--
Tom Liotta
The PowerTech Group, Inc.
19426 68th Avenue South
Kent, WA 98032
Phone 253-872-7788 x313
253-479-1416
Fax 253-872-7904
http://www.powertech.com
--
This is the RPG programming on the AS400 / 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.
As an Amazon Associate we earn from qualifying purchases.