Search in qualified data strucuture

270 pts.
Tags:
RPGLE
RPGLE Program
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

Add your answer…

Discuss This Question: 16  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • LakNar
    Thanks Tom,How to convert this data strucuture into array or table?
    270 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    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  
    49,600 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • LakNar
    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 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • philpl1jb
    You want to search one field of the data structure array?
    49,600 pointsBadges:
    report
  • LakNar
    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 pointsBadges:
    report
  • LakNar
    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 pointsBadges:
    report
  • philpl1jb
     DDS1 DS QUALIFIED DDV1 DIM(2) LIKEDS(ADDRESSPerhaps like this?C EVAL N1= %LOOKUP(‘NAME2′:DS1.dvcity) 
    49,600 pointsBadges:
    report
  • LakNar
    Exactly philip, but i try this, it is showing error "DVCITY name or indicator is not defined"
    270 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • LakNar
    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 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • LakNar
    thanks tom.. ...
    270 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following