search in struct

Author: yves.de.montmollin@aonhewitt.com (yves2m)

 Hello, My question is very basic. But I can't find the answer ... Embarassed  I know I've seen this before ... but where ...  I've a struct : vStruct->$dbgString

[]   [paramsOut]     [requestResult]         [endOfCollection] = F         [firstRowInCollection] = 5         [lastRowInCollection] = 10         [requestStatus] = 0     [collection]         [OCC]             [PE_ASSU_ID] = "350288"             [NOM_ESTE_1] = 437             [PE_PERS_ID] = "329400"             [DADVAL] = 20130823             [NPERSO] = "555891686"             [LPNPER_UPPER] = "ALEXIS"             [ROWNUM] = 5         [OCC]             [PE_ASSU_ID] = "348649"             [NOM_ESTE_1] = 425             [DADVAL] = 20140701             [PE_PERS_ID] = "329403"             [NPERSO] = "555891642"             [LPNPER_UPPER] = "ARNOLD"             [ROWNUM] = 6         [OCC]             [PE_ASSU_ID] = "348660"             [NOM_ESTE_1] = 444             [DADVAL] = 20140715             [PE_PERS_ID] = "329732"             [NPERSO] = "555891689"             [LPNPER_UPPER] = "BERNARD"             [ROWNUM] = 7         [OCC]             [PE_ASSU_ID] = "349399"             [NOM_ESTE_1] = 350             [DADVAL] = 20141231             [PE_PERS_ID] = "330038"             [NPERSO] = "555892227"             [LPNPER_UPPER] = "VIVIANE"             [ROWNUM] = 8         [OCC]             [PE_ASSU_ID] = "349466"             [NOM_ESTE_1] = 730             [PE_PERS_ID] = "330078"             [NPERSO] = "555892253"             [LPNPER_UPPER] = "CASTULE"             [ROWNUM] = 9         [OCC]             [PE_ASSU_ID] = "349286"             [NOM_ESTE_1] = 257             [PE_PERS_ID] = "329955"             [NPERSO] = "555892179"             [LPNPER_UPPER] = "ERNESTINE"             [ROWNUM] = 10

  How can I get the occ for NPERSO = "55589227" ? I don't want to go through all the collection with a loop ... (while / for) Thanks for your help   Yves

3 Comments

  1. Hello Yves, I don't think that there currently is another way then to loop through all the OCC nodes; e.g.

    vSearch = vStruct->paramsOut->collection->OCC ; vSearch => Struct vCollSize = vStruct->paramsOut->collection->OCC->$collsize ; vCollSize => Numeric for i = 1 to vCollSize     if (vSearch{i}->NPERSO = "55589227")         message/info "Found value in OCC{%%i}"         break     endif endfor Hope this helps. Kind regards, Daniel Iseli Uniface Technical Support


    Author: diseli (daniel.iseli@uniface.com)
  2. Hi Yves / Daniel, How about something like this;

    variables struct vStruct string vs_temp, vs_left, vs_buff numeric vn_pos1 endvariables vs_temp = vStruct->$dbgString vs_temp = $replace(vs_temp, 1, "[OCC]", "·;[OCC]", -1) vn_pos1 = $split(vs_temp, 1, "555892227",vs_left) getitem vs_buff, vs_temp, $itemcount(vs_left)

    Your occurence sits in vs_buff.... Regards, Knut


    Author: Knut (knut.dybendahl@gmail.com)
  3. Hi Folks, I got this solution, to be able to find not only the NPERSO but any tag name

    ;Search an occurence in a collection struct ;Needs a new operation if the struct differs ;[] ; [paramsOut] ;   [requestResult] ;   [endOfCollection] = F ;   [firstRowInCollection] = 5 ;   [lastRowInCollection] = 10 ;   [requestStatus] = 0 ; [collection] ;   [OCC] ;     [PE_ASSU_ID] = “348649” ;     [NOM_ESTE_1] = 425 ;     [DADVAL] = 20140701 ;     [PE_PERS_ID] = “329403” ;     [NPERSO] = “555891642” ;     [LPNPER_UPPER] = “ARNOLD” ;     [ROWNUM] = 5 ;   [OCC] ;     [PE_ASSU_ID] = “350288” ;     [NOM_ESTE_1] = 437 ;     [PE_PERS_ID] = “329400” ;     [DADVAL] = 20130823 ;     [NPERSO] = “555891686” ;     [LPNPER_UPPER] = “ALEXIS” ;     [ROWNUM] = 6 ;   [OCC] ;     [PE_ASSU_ID] = “348660” ;     [NOM_ESTE_1] = 444 ;     [DADVAL] = 20140715 ;     [PE_PERS_ID] = “329732” ;     [NPERSO] = “555891689” ;     [LPNPER_UPPER] = “BERNARD” ;     [ROWNUM] = 7 operation findStructRef   params     struct pFullStruct : in     string pName : in ; in this exemple : NPERSO     string pValueToFind : in ; in this exemple : 555891686     struct pSubStruct : out ; in this exemple : ; [] [OCC] [PE_ASSU_ID] = “350288” ... [NPERSO] = “555891686” [LPNPER_UPPER] = “ALEXIS” [ROWNUM] = 6   endparams   variables     string vList     numeric vPos   endvariables   vList = pFullStruct->paramsout->collection->occ->"%%pName%%%"->*->$dbgstring   ; vList = "“555891642”<eol>“555891686”<eol>“555891689”"   vList = $replace (vList, 1, "%%"", "", -1) ; supress the " in vList   vList = $replace (vList, 1, "%%^", "·;", -1) ; remplace eol by <glod>;   vPos = $itemnr(vList, pValueToFind) ; vPos = 2   if(vPos <= 0)     return -2 ; Occurence not found   endif   pSubStructOut = pFullStruct->paramsout->collection->occ->"%%pName%%%"{vPos}->$parent   return 0 end ; findStructRef

    I'll try to get something more generic. But this is already a solution without loop Smile Have a nice week-end   Yves


    Author: yves2m (yves.de.montmollin@aonhewitt.com)