270 pts.
 Search in qualified data strucuture
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

Answer Wiki:
Last Wiki Answer Submitted:  Be the first to answer this question.
All Answer Wiki Contributors:  Be the first to answer this question. Michael Tidmarsh   14,060 pts. , LakNar   270 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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

 110,135 pts.

 

Thanks Tom,How to convert this data strucuture into array or table?

 270 pts.

 

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

 110,135 pts.

 

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
 

 44,630 pts.

 

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

 110,135 pts.

 

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.

 270 pts.

 

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

 110,135 pts.

 

You want to search one field of the data structure array?

 44,630 pts.

 

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.

 270 pts.

 

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.

 270 pts.

 

 DDS1 DS QUALIFIED DDV1 DIM(2) LIKEDS(ADDRESSPerhaps like this?C EVAL N1= %LOOKUP(‘NAME2′:DS1.dvcity) 

 44,630 pts.

 

Exactly philip, but i try this, it is showing error “DVCITY name or indicator is not defined”

 270 pts.

 

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

 110,135 pts.

 

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.

 270 pts.

 

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

 110,135 pts.

 

thanks tom.. …

 270 pts.