Skip to Content
avatar image
Former Member

Read dynamic internal table - addressing certain field

Hi experts,

I'm new to a dynamic itabs. How do I read a value of a particular field from such a table?

I've found the below code by which I'm able to read a name of the field and later on the value. The problem is, that I need to address all the values from the line directly from the field - e.g. <dyn_wa>-kokrs.

LOOP AT <dyn_table> INTO <dyn_wa>. "ASSIGNING

LOOP AT fields_table ASSIGNING <field>.

CONCATENATE '<dyn_wa>' <field>-name INTO w_field

SEPARATED BY '-'.

ASSIGN (w_field) TO <aux>.

  • WRITE: <aux>.

APPEND <aux> TO itab_fin.

write:/ <dyn_wa>.

Is it possible or do I need to copy the values into a non-dynamic itab with predefined structure - because in this case I quite lose the biggest advantage of dynamic itabs;)

Thanks,

Petr

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Jul 22, 2009 at 10:22 AM

    Hi,

    Make use of ASSIGN COMPONENT Statement.

    LOOP AT <dyn_table> INTO <dyn_wa>.
     LOOP AT fields_table ASSIGNING <field>.
    
     ASSIGN COMPONENT <field>-name OF STRUCTURE <dyn_wa>
    to <AUX>.
    if <aux> is assigned.
     APPEND <aux> TO itab_fin.
    endif.
    unassign <aux>.
    
    ENDLOOP.
    ENDLOOP.

    Check this wiki for more details.

    [http://wiki.sdn.sap.com/wiki/x/UYA_Bg]

    Regards,

    Ankur Parab

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 22, 2009 at 10:26 AM

    Refer this code

    DATA: wa_konp LIKE LINE OF it_konp.

    FIELD-SYMBOLS: <w_knumh> TYPE ANY.

    DATA: wa_final TYPE ty_final.

    FIELD-SYMBOLS:

    <fl> TYPE ANY,

    <fs_knumh> TYPE ANY.

    *Looping and assigning each record in <FS> to <FS1>

    LOOP AT <fs> ASSIGNING <fl>.

    ASSIGN COMPONENT 'VKORG' OF STRUCTURE <fl> TO <fs_knumh>.

    wa_final-vkorg = <fs_knumh>.

    UNASSIGN <fs_knumh>.

    ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fl> TO <fs_knumh>.

    wa_final-matnr = <fs_knumh>.

    UNASSIGN <fs_knumh>.

    ASSIGN COMPONENT 'DATAB' OF STRUCTURE <fl> TO <fs_knumh>.

    wa_final-datab = <fs_knumh>.

    UNASSIGN <fs_knumh>.

    ASSIGN COMPONENT 'KSCHL' OF STRUCTURE <fl> TO <fs_knumh>.

    wa_final-kschl = <fs_knumh>.

    UNASSIGN <fs_knumh>.

    ASSIGN COMPONENT 'KNUNH' OF STRUCTURE <fl> TO <fs_knumh>.

    READ TABLE it_konp INTO wa_konp WITH KEY knumh = <fs_knumh>.

    IF sy-subrc EQ 0.

    *move-the data from wa_konp to it_final work area

    • wa_FINAL-KBETR = wa_KONP-KBETR.

    wa_final-konwa = wa_konp-konwa.

    wa_final-kpein = wa_konp-kpein.

    wa_final-kmein = wa_konp-kmein.

    wa_final-loevm_ko = wa_konp-loevm_ko.

    • FL_FINAL-VKORG = <FL>-VKORG.

    ENDIF.

    APPEND wa_final TO it_final.

    CLEAR : wa_konp,<fl>,wa_final,<fs_knumh>.

    ENDLOOP.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 22, 2009 at 10:30 AM

    Hi ,

    check this link and follow the syntax for dynamic internal table.

    [http://www.sap-img.com/ab030.htm]

    Please let me know if you still need any more help.

    Thanks and regards,

    Rajeshwar

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 30, 2009 at 12:57 PM

    Hello,

    Check if this link helps.

    creating-dynamic-table

    Thanks,

    Augustin.

    Add comment
    10|10000 characters needed characters exceeded