Hi,
I used qualified data structure in RPGLE program. How to search in this data structure.
My Coding:
D Address DS
D dvadd 20
D dvphn 20
D dvcity 20
D dvctry 20
D InvoiceInfo DS QUALIFIED
DdvType1 1 2
DdvType2 3 4
D MailAddr LikeDS(Address)
D ShipAddr LikeDS(Address)
-----------------------------------------------
if i want to search city "CITY1" in this data structure..The "CITY1" can either present in MailAddr data structure or ShipAddr data structure. How to search in this data structure ?
Thanks,
LAKNAR
Software/Hardware used:
rpgle
ASKED:
December 11, 2012 5:32 AM
UPDATED:
December 11, 2012 3:24 PM
You can’t “search” through a data structure. Search through a table or array. But in a data structure you just need simple IF-tests. — Tom
Thanks Tom,How to convert this data strucuture into array or table?
I suppose it could be defined as a 2-element array of data structures, but I can’t see any reason to make things more complicated. Why make it more complicated? — Tom
I’m not sure that you mean search. Do you mean to check the field to see if it contains a value? As in:
If InvoiceInfo.dvcity <> *blank
A nested IF-test for the two dvcity fields is the obvious way to do it that I can see. I don’t quite understand using “search” for it unless the intention is that there will be more than perhaps three DSes. With only two of them, “search” doesn’t make sense. And maybe a SELECT/WHEN/OTHER would be best. — Tom
Actually, i want to use %lookup to search the value in my data strucuture. Since it is not possible in data structure, i tried to convert the data strucutre to array.My Code:D ADDRESS DS D dvadd 20 D dvphn 20 D dvcity 20 D dvctry 20 DDS1 DS QUALIFIED DDV1 DIM(2) LIKEDS(ADDRESS) C EVAL N1= %LOOKUP(‘NAME2′:DS1.DV1)But it is showing error as “The second parameter for %LOOKUPxx is not valid.”. DV1 subfields is not considered as array. Please help me to fix the error in my code.
You have created an array of data structures. Try:
C EVAL N1= %LOOKUP(‘NAME2′:DS1.DV1(*).dvcity)I don’t have similar code to test, mostly because it is not a good idea for this. But if yoy want to try it. it’s p to you to figure it out. The documentation for %lookup() has all of the available information. There isn’t any more.
Tom
You want to search one field of the data structure array?
Tom, again it is showing error as “The second parameter for %LOOKUPxx is
not valid.”. When i use LIKEDS in the subfield of a data structure, it
is showing this error. But i declare the length of the subfield (DDV1
80 DIM(2) ). But i want to search the
data in particular subfield of a data strucutre.
Tom, again it is showing error as “The second parameter for %LOOKUPxx is
not valid.”. When i use LIKEDS in the subfield of a data structure, it
is showing this error. But i declare the length of the subfield (DDV1
80 DIM(2) ), it is not showing any error and it is accepting as array . But i want to search the
data in particular subfield of a data strucutre.
DDS1 DS QUALIFIED DDV1 DIM(2) LIKEDS(ADDRESSPerhaps like this?C EVAL N1= %LOOKUP(‘NAME2′:DS1.dvcity)
Exactly philip, but i try this, it is showing error “DVCITY name or indicator is not defined”
DS1 is a qualified DS. It contains an array of DSes named DV1. The DV1 DSes have a subfield named dvcity. The %LOOKUP() documentation says that DS array subfields should be referenced with “(*)” as the array index. My best guess is that “DS1.DV1(*).dvcity” might work. — Tom
Tom, i tried like this ……. EVAL N1= %LOOKUP(‘CITY1′:DS1.DV1(*).dvcity). But it is showing the error “The second parameter for %LOOKUPxx is not valid” . My i series version is V5R3M0.
My i series version is V5R3M0.
There’s the problem. It takes us back to my first comment. You can’t “search” a DS, not until you become current for the OS. I should’ve asked for your OS release early on, but you mentioned wanting to use %LOOKUP() and I mistakenly assumed you were trying to learn a new feature.
Native language support for lookups over nested data structures is a feature of the current release, i 7.1. The V5R3 release is out of support and a number of releases behind. You will need to code your own IF/THEN/ELSE tests or SELECT/WHEN/OTHER. With only two array elements (two structures), it doesn’t make reasonable sense to code a search loop; but you can do it if you really want. The loop would only execute twice at most, of course.
Tom
thanks tom.. …