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
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
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
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.
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
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 16  Replies
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