Loop Over Nested Structure

Hello,
Can someone please demonstrate how I would use a cfLoop to
loop over and output the contents of this fictious nested
structure?
Thank You!

mletson wrote:
> I figured it out. If anyone has a better solution,
please let me know.
>
> <cfloop from="1" to="#structCount(student)#"
index="x">
>
> <cfset variables.studentID = "student00" & x>
>
> <tr>
>
<td><cfoutput>#student[studentID]["firstName"]#</cfoutput></td>
>
<td><cfoutput>#student[studentID]["lastName"]#</cfoutput></td>
>
<td><cfoutput>#student[studentID]["phone"]#</cfoutput></td>
> </tr>
>
> </cfloop>
>
A slightly simpler version using the structure form of the
<cfloop...>
tag. It also demonstrates both array notation, that you used,
as well
as dot notation. Finally it puts a single <cfoutput...>
block around
the entire loop. This can provide a small but accumulative
performance
improvement.
<cfoutput>
<cfloop collection="#student#" item="aStudent">
<tr>
<td>#aStudent["firstName"]# OR
#aStudent.firstName#</td>
<td>#aStudent["lastName"]# OR
#aStudent.lastName#</td>
<td>#aStudent["phone"]# OR #aStudent.phone#</td>
</tr>
</cfloop>
</cfoutput>

Similar Messages

  • Looping over Nested Structure

    Hey Guys,
    I have a component that returns a structure. The structure is
    called ContactQuery. ContactQuery has to elements, one called
    Results, and one called Success. Results contains the data I want
    to loop over. If you try looping over the ContactQuery by using
    CFLoop and specify the ContactQuery as the collection, of course it
    only loops twice (once for Results, once for Success). How can I
    loop over the Results structure withing ContactQuery? You can see
    the dump of the structure at:
    http://www.digitalswordsmen.com/cfschedule/admin/Create_Tokens_Table.cfm
    Attached is the code I have. I am just unsure of the syntax
    for looping over the Results section of the structure.
    Thank you.

    Nope. I am dumb and didn't really think about it. The fact
    that it is a query nested in a structure threw me off. The code
    that works was
    <cfloop query="ContactQuery.Results">
    <tr>
    <td></td><td>#firstname#</td><td>#lastname#</td><td>#email#</td><td>#randrange(10000,9999 9)#</td>
    </tr>
    </cfloop>
    Thanks for the help, sorry about that dumb question.

  • Looping over a structure of arrays

    Hi Guys, I am trying to loop over a structure of simple
    arrays. The structure's second column contains a 1 dimentional
    array.
    I can't seem to get the proper syntax for my loop.

    I want to be able to dynamically loop over my query and
    decrypt it as I pass it into my structure. I have figured the code
    out to loop over the query and pass it to the structure. My problem
    now is whn I go to decrypt it I get this Error.
    There has been an error while trying to encrypt or decrypt
    your input string: Input length (with padding) not multiple of 16
    bytes.
    How can I fix this?
    Here is my code could it be because my varchar columns were
    not long enough. Here is my code.

  • Looping over a structure

    How do I loop over this structure to populate it with a Query
    Recordset?
    <cfset myStruct =
    objImage.getSize("images/products/largeImages/#Recordset1.elink#")>
    I really appreciate your help.

    I would like to populate the structure with the image file
    names that are coming from the query. The structure is built from a
    java object. Here is the function to create it.
    <cfcomponent>
    <cffunction name="getSize" returntype="struct"
    access="public" output="No">
    <cfargument name="Image" required="Yes" type="string">
    <cfset myImage = createObject("java",
    "javax.swing.ImageIcon")>
    <cfset myImage.init(expandpath(arguments.Image))>
    <cfset myStruct = StructNew()>
    <cfset myStruct.width = myImage.getIconWidth()>
    <cfset myStruct.height = myImage.getIconHeight()>
    <cfreturn myStruct>
    </cffunction>
    </cfcomponent>
    <cfobject component="imageSize" name="objImage">
    <cfset myStruct =
    objImage.getSize("/images/someimage.jpg")>
    <cfoutput>
    width: #myStruct.width#
    height: #myStruct.height#
    </cfoutput>
    Right now the structure only gives me the first row of the
    query. I have tried using the cfquery loop to populate the
    structure with now results. I suspect I am using the wrong
    syntac.

  • Message-Mapping: nested Loops over Elements

    Hi Experts,
    I have problems with my Message-Mapping in the IR. I have a source and a target structure. In the following I will give you easy examples of these structures:
    <u>source structure:</u>
       <E1EDP01>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
       </E1EDP01>
       <E1EDP01>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
       </E1EDP01>
    <u>target structure:</u>
    <LineItem>
       <IDTNR></IDTNR>
    </LineItem>
    <LineItem>
       <IDTNR></IDTNR>
    </LineItem>
    That means:
    For every <E1EDP01> in the source structure I create one <LineItem> in the target structure. One E1EDP01-Element can contain more than one E1EDP19-Elements. I have to loop over these E1EDP19-Elements, because I have to locate the Element <QUALF> with a given (fixed) value. The Mapping should put the value from the Element <IDTNR> from the source structure - where the QUALF-Element has this given value - in the IDTNR-Element of the target structure.
    I tried it with a UDF, but only the first <IDTNR> in the target structure got filled.
    Thanks for your help
    Christopher

    Thank you,
    but how I can set the Elements IDTNR and QUALF to the context E1EDP01?
    In the splitByValue-Function do I need "each value"?
    best regards
    Christopher

  • Why optimizer prefers nested loop over hash join?

    What do I look for if I want to find out why the server prefers a nested loop over hash join?
    The server is 10.2.0.4.0.
    The query is:
    SELECT p.*
        FROM t1 p, t2 d
        WHERE d.emplid = p.id_psoft
          AND p.flag_processed = 'N'
          AND p.desc_pool = :b1
          AND NOT d.name LIKE '%DUPLICATE%'
          AND ROWNUM < 2tkprof output is:
    Production
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          4           0
    Execute      1      0.00       0.01          0          4          0           0
    Fetch        1    228.83     223.48          0    4264533          0           1
    total        3    228.84     223.50          0    4264537          4           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 108  (SANJEEV)
    Rows     Row Source Operation
          1  COUNT STOPKEY (cr=4264533 pr=0 pw=0 time=223484076 us)
          1   NESTED LOOPS  (cr=4264533 pr=0 pw=0 time=223484031 us)
      10401    TABLE ACCESS FULL T1 (cr=192 pr=0 pw=0 time=228969 us)
          1    TABLE ACCESS FULL T2 (cr=4264341 pr=0 pw=0 time=223182508 us)Development
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.00       0.01          0          4          0           0
    Fetch        1      0.05       0.03          0        512          0           1
    total        3      0.06       0.06          0        516          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 113  (SANJEEV)
    Rows     Row Source Operation
          1  COUNT STOPKEY (cr=512 pr=0 pw=0 time=38876 us)
          1   HASH JOIN  (cr=512 pr=0 pw=0 time=38846 us)
         51    TABLE ACCESS FULL T2 (cr=492 pr=0 pw=0 time=30230 us)
        861    TABLE ACCESS FULL T1 (cr=20 pr=0 pw=0 time=2746 us)

    sanjeevchauhan wrote:
    What do I look for if I want to find out why the server prefers a nested loop over hash join?
    The server is 10.2.0.4.0.
    The query is:
    SELECT p.*
    FROM t1 p, t2 d
    WHERE d.emplid = p.id_psoft
    AND p.flag_processed = 'N'
    AND p.desc_pool = :b1
    AND NOT d.name LIKE '%DUPLICATE%'
    AND ROWNUM < 2
    You've got already some suggestions, but the most straightforward way is to run the unhinted statement in both environments and then force the join and access methods you would like to see using hints, in your case probably "USE_HASH(P D)" in your production environment and "FULL(P) FULL(D) USE_NL(P D)" in your development environment should be sufficient to see the costs and estimates returned by the optimizer when using the alternate access and join patterns.
    This give you a first indication why the optimizer thinks that the chosen access path seems to be cheaper than the obviously less efficient plan selected in production.
    As already mentioned by Hemant using bind variables complicates things a bit since EXPLAIN PLAN is not reliable due to bind variable peeking performed when executing the statement, but not when explaining.
    Since you're already on 10g you can get the actual execution plan used for all four variants using DBMS_XPLAN.DISPLAY_CURSOR which tells you more than the TKPROF output in the "Row Source Operation" section regarding the estimates and costs assigned.
    Of course the result of your whole exercise might be highly dependent on the actual bind variable value used.
    By the way, your statement is questionable in principle since you're querying for the first row of an indeterministic result set. It's not deterministic since you've defined no particular order so depending on the way Oracle executes the statement and the physical storage of your data this query might return different results on different runs.
    This is either an indication of a bad design (If the query is supposed to return exactly one row then you don't need the ROWNUM restriction) or an incorrect attempt of a Top 1 query which requires you to specify somehow an order, either by adding a ORDER BY to the statement and wrapping it into an inline view, or e.g. using some analytic functions that allow you specify a RANK by a defined ORDER.
    This is an example of how a deterministic Top N query could look like:
    SELECT
    FROM
    SELECT p.*
        FROM t1 p, t2 d
        WHERE d.emplid = p.id_psoft
          AND p.flag_processed = 'N'
          AND p.desc_pool = :b1
          AND NOT d.name LIKE '%DUPLICATE%'
    ORDER BY <order_criteria>
    WHERE ROWNUM <= 1;Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Value Mapping: how to loop over a nested context in a adv. user function

    Hello,
    i have the following source structure:
    <rec> (1:1)
    <field1>aaa</field1> (1:1)
    <field2>bbb</field2> (1:1)
    <b><struc> <u>(1:unbounded)</u>
      <name>myName</name>
      <value>myValue</value>
    </struc></b>
    </rec>
    Destination structure:
    <rec> (1:1)
    <field1>aaa</field1> (1:1)
    <field2>bbb</field2> (1:1)
    <b><field3>bbb</field2> (1:1)</b>
    </rec>
    In order to fill the destination field3 i have to loop over the input-structure struc.
    My problem is, that i don't know how to get access to the name/value pair with a
    extended user-defined function. Since each occurrence in struc i not a simple string but consists of 2 fields, i guess it is not enough simply to loop over input String Array.
    Please help.

    just like u have a loop stmt in java prgm. a simple code:
    Here a and b are the strings that comes to the udf
    for(int i=0;i<a.length;i++)
         boolean found = false;
         int j = 0;
         for(j=0;j<b.length;j++)
              if (a<i>.equals(b[j]))
                   found = true;
                   break;
         if (found == true)
              result.addValue(c[j]);
         else
              result.addValue("");
    Message was edited by:
            Prabhu  S

  • Nested structure when using FM XXL_SIMPLE_API

    I use this logic to fill in the headings before calling the FM xxl_simple_api in one of my programs. Is it possible to have nested structure(for <b>i_tab</b> in my code) and still use same kind of logic to fill in the headings? Not sure if this Fm would display data correctly when there is a component of strucutre type. I tried it, the field was blank with no contents in excel.
      DATA : nlines TYPE i,
             tempfile LIKE gxxlt_f-file,
             descr_ref TYPE REF TO cl_abap_structdescr,
             header LIKE gxxlt_v OCCURS 0 WITH HEADER LINE,
             it_print LIKE gxxlt_p OCCURS 0 WITH HEADER LINE.
    *data:               keycol type i.
      FIELD-SYMBOLS:
      <comp_wa> TYPE abap_compdescr,
      tempfile = file_name.
      REFRESH header.
      CLEAR header.
      descr_ref ?= cl_abap_typedescr=>describe_by_data( i_tab ).
      DESCRIBE TABLE descr_ref->components LINES nlines.
      nlines = nlines + 1.
      LOOP AT descr_ref->components ASSIGNING <comp_wa>.
        IF sy-tabix = nlines.
          EXIT.
        ELSE.
          header-col_no = sy-tabix.
          header-col_name = <comp_wa>-name.
          APPEND header.
        ENDIF.
      ENDLOOP.
      CALL FUNCTION 'XXL_SIMPLE_API'
      EXPORTING
        filename = tempfile
    N_KEY_COLS = keycol
      TABLES
       col_text = header[]
    I appreciate your help. Thanks

    Hi,
    It's better to use another FM 'SAP_CONVERT_TO_XLS_FORMAT'
      call function 'SAP_CONVERT_TO_XLS_FORMAT'
                 exporting
                  I_FIELD_SEPERATOR = seper
                  I_LINE_HEADER = 'X'
                     I_FILENAME = P_FILE
                  tables
                      I_TAB_SAP_DATA = itab
                  exceptions
                      CONVERSION_FAILED = 1.
    Svetlin

  • Problem with Message-Mapping: Loop over Elements possible?

    Hi all,
    I want do create a Message-Mapping for an IDoc-to-File Scenario. In the Source Structure there are some Elements which can appear more than once (1..unbounded). I need a mechanism which loops over these elements and search for specified values. From the Element which contains an element with this specified value the mapping should write a value in the target structure.
    Here a simple example (source structure) for better understanding:
    <root>
       <invoice>
          <number> 10 </number>
          <sum> 200.00 </sum>
       </invoice>
       <invoice>
          <number> 20 </number>
          <sum> 150.00 </sum>
       </invoice>
       <invoice>
          <number> 30 </number>
          <sum> 120.00 </sum>
       </invoice>
    </root>
    Now the duty of the Mapping should be to search in the elements <invoice> for the number 30. And then the sum of the invoice with the number 30 should be written in a field of the target structure.
    I tried it out with a constant togehter with an equalsS-function and an ifWithoutElse-function, but it is working only then, if the invoice with the number 30 has the first position in the root context.
    Can anybody help me? Thanks
    With kind regards
    Christopher

    Hi,
    Write a UDF to sum the required values and map to target node.
    See while writing the UDF select the type as queue.
    number -- removecontext-UDF targetnode
    sum----removecontext--/
    number abd sum or the two inputs
    in UDF
    int nsum = 0;
    for(int i;i < number.length;i++){
      if number(i).equals("30") then
         nsum = nsum + valueOf(sum(i));
    result.addValue(nsum); // convert the nsum into string
    Regsrds
    Chilla

  • How to stop a while loop of event structure from a main vi

    Hello;
    sorry for my english
    I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
    any help please or example !!!   
    Solved!
    Go to Solution.
    Attachments:
    stop a while loop and event structure from main vi.png ‏16 KB

    IYED wrote:
    Hello;
    sorry for my english
    I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
    any help please or example !!!   
    If this is an example of how your code looks, I'd clean it up before the developer who has to work on it next hits you over the head with his LabVIEW Style Book. 
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • Looping over fields from internal table

    In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
    I first want to check field-by-field and then I want to deal with exceptions.
    Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?

    Hi, you can loop thru the columns(fields) of an internal table like so.
    field-symbols: <fs>.
    loop at itab.
    do.
    * Here you can use the field name instead of SY-INDEX
       assign component sy-index of structure itab to <fs>.
       if sy-subrc <>.
       exit.
       endif.
    * Now that you have access to the field via field symbol, you can compare
    * this value.
    Write:/ <fs>.
    enddo. 
    endloop.
    Regards,
    Rich Heilman

  • Fill internal table with mutliple entries for nested structure

    Dear ABAP Experts,
    I have a question related to fill internal tables with nested structures.
    I have a structure like this:
    BEGIN OF proto,
              sicht TYPE ysicht,
              version TYPE FAGLFLEXA-RVERS,
              BEGIN OF kons,
    kon TYPE YKONSEINHEIT,
              END OF kons,
              jahr TYPE CHAR04,
    END OF proto.
    Now I need to fill this structure with values (over an internal table), but how can I achieve that I save multiple datas für element "kon" für one single entry of structure "proto"?
    An example could be:
    sicht = '01'
    version = '100'
    kon = 1001 (first entry)
    kon = 1002 (second entry)
    usw... (n entry)
    jahr = '2008'
    Thanks in advance for every helpful answer.
    Regards
    Thomas

    BEGIN OF proto,
               sicht TYPE ysicht,
               version TYPE FAGLFLEXA-RVERS,
               kons TYPE STANDARD TABLE OF YKONSEINHEIT WITH NON-UNIQUE KEY TABLE_LINE,
               jahr TYPE CHAR04,
    END OF proto.
    DATA: ls_proto TYPE proto,
          lt_proto TYPE STANDARD TABLE OF proto,
          ls_kon
    ls_proto-sicht = '01'.
    ls_proto-version = '100'
    INSERT '1001' INTO TABLE ls_proto-kons.
    INSERT '1002' INTO TABLE ls_proto-kons.
    ls_proto-jahr = '2008'.
    INSERT ls_proto INTO TABLE lt_proto
    If you're going to use a more complicated inner table with several components, then you need to define a type for those components. 
    matt

  • HRFORM - difference between Flat Staructure & Nested Structure

    Hi,
    I wish to know the dfifference between deciding nested structure or flat structure in tcode HRFORMS. I have to work on form SAP_PAYSLIP_CA which is a nested structure. I have read that working on flat structure is far easier than working on nested structure. I wish to know what fields i have to add to convert this to flat structure. If i have to work on this nested structure what code i have to add in my interface (e.g. loop at.... for nested structure) for working on employee data. Also i wish to know how can i pull non key field data in my program.
    I nee dthe inputs very urgently.
    Thanks in advance.
    Ajay

    Hi Ajay,
    Please check the link
    http://help.sap.com/saphelp_dimp50/helpdata/en/c5/d69f5b6ccb11d3968b00a0c9306433/content.htm
    This is will partially answer your Query.
    Regards
    JwaliniS

  • Looping Over INSERT

    I've got a form. The form asks the visitor their address
    (first name, last name, street address, apartment number, city,
    state, and zip code... each a separate text field). This form is
    repeated 10 times on the page, allowing the visitor to enter
    multiple addresses. I've given each form field a unique name by
    just appending "_1" or "_2" after it. For example, my fields are
    named...
    FIRST FORM BLOCK
    first_name_1
    last_name_1
    SECOND FORM BLOCK
    first_name_2
    last_name_2
    Each form block (address) will be inserted into a table in my
    database as a new row. Is there a quick and easy way to loop over
    the insert 10 times, rather than have 10 separate INSERT statements
    in my code? A CFLOOP would work just fine if not for dynamic form
    field names, but I would have to take into account the "_X". I want
    to say I've done this before; I'm just overthinking.

    <cfloop from="1" to="10" index="i">
    <cfquery ...>
    INSERT INTO ...
    (aCol,bCol,cCol...)
    <!--- The important part, accessing the form structure
    with array
    notation --->
    #form['first_Name_' & i]#,
    #form['last_Name_' & i]#
    </cfquery>
    </cfloop>
    The array notation for a complex variables is a very powerful
    concept.
    Many advance techniques can be used with it.

  • Looping over cfdirectory

    Hello. I am having an issue with looping over cfdirectory.
    What I am trying to do here is grab the size of the files
    associated with the db. So where #current.Dir.Name# = #DB Column#
    update size etc.... What's happening is it is displaying the same
    id about 90 something times...Nice I know. Can anyone help?
    <cfloop query="qLoadFile">
    <cfoutput>
    <cfdirectory
    directory="/test1/test2/test3/0/#qLoadFile.owner_id#" action="list"
    name="currentDir">
    #qLoadFile.owner_id# <!--- This does display my ids
    correctly if I end the loop here but does not display anything in
    my table if I end the loop here and reopen it--->
    </cfoutput>
    <table border="1" bordercolor="#000000" >
    <tr>
    <td>File Name</td>
    <td>File Size</td>
    <td>Directory Location</td>
    <td>File Type</td>
    </tr>
    <cfloop query="currentDir">
    <tr>
    <cfoutput>
    <form name="updateSize" action="
    http://myURL.com/test2.cfm"
    method="post">
    <td><input type="text" name="name"
    value="#currentDir.Name#" /></td>
    <td><input type="text" name="size"
    value="#currentDir.Size#" /></td>
    <td>#right(currentDir.DIRECTORY, 2)#</td>
    <td>#currentDir.Type#</td>
    </cfoutput>
    </tr>
    </cfloop>
    </cfloop>
    </table> <br />
    <input type="text" name="number_of_directories"
    value="<cfoutput>#valuelist(qLoadFile.owner_id)#</cfoutput>">
    <input type="submit" name="submit" value="submit"/>
    </form>

    I just put your query into a random page of mine, changed the
    query to reflect a local database and got this output (all
    formatted correctly though!)
    Since I dont have the directory setup that you have the
    directory structures are empty, however it seems to be looping
    through fine
    59 File Name File Size Directory Location File Type
    60 File Name File Size Directory Location File Type
    61 File Name File Size Directory Location File Type
    62 File Name File Size Directory Location File Type
    63 File Name File Size Directory Location File Type
    64 File Name File Size Directory Location File Type
    65 File Name File Size Directory Location File Type
    Is this what you are looking for?

Maybe you are looking for

  • Excel Calulates twice when set to Automatic in Office 2013

    I have had a group of users who have raised an issue with Office 2013 running far slower for a number of spreadsheets. After investigating the fault, I have identified the issue as being due to the way in which Excel appears to be handling the calcul

  • Mail merge functionality

    Hi I am trying to import an Excel spreadsheet with highlighted columns I have assigned into a working PDF document with the fields assigned so that it pulls similar to a mail merge in Microsoft Word. Your copy and paste ability on the FormCentral com

  • How to pass datetype parameter in Sql Select Statements to

    public void Mountain()                String dat=lastcollecteddatestr.substring(0,2);                String mon=lastcollecteddatestr.substring(3,5);                String yr=lastcollecteddatestr.substring(6,10);                try                    

  • How can you make a psd gif  have transparent background for use in photoshop ?

    Hi Guys I'm trying to produce a 2d animation within premier pro cc using photoshop cc and i was just intrested if there is some way of changing a gif's  standard background to  a transparent background which i can then import  into premier pro cc to

  • [10g] Down Arrow in a list appears GRAY instead of BLACK

    Hi, I have to migrate 6i forms module to 11g In 6i the list element is displayed in black, in 11g it is displayed in gray. I have set the foreground color to black. What else could I do? Many thanks for your help Edited by: JeanParis on Jan 2, 2011 9