Iterate field values and field names of unknown table

form fill_fcontent using it_tab type any table " iterate field values
                   changing it_fcont type rsanm_file_table. " für Z_LIEFZ
  data: lro_structdescr type ref to cl_abap_structdescr,
        lt_components   type cl_abap_structdescr=>component_table,
        lv_row type string.
  constants con_tab type c value cl_abap_char_utilities=>horizontal_tab.
  field-symbols: <ls_comp> like line of lt_components, <fs_field>, <wa> type any.
  loop at it_tab assigning <wa>.
    if lt_components is initial.
      lro_structdescr ?= cl_abap_typedescr=>describe_by_data( <wa> ).
      lt_components = lro_structdescr->get_components( ).
    endif.
    do. "iterate all columns in the row
      assign component sy-index of structure <wa> to <fs_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      read table lt_components assigning <ls_comp> index sy-index.
      lv_row = lv_row && <fs_field> && con_tab.
    enddo.
    append lv_row to it_fcont. clear lv_row.
  endloop.
endform.
 
form fill_fheader using gs_line type any " iterate field names
                 changing it_filcont type rsanm_file_table. " für Z_LIEFZ
  data: lro_structdescr type ref to cl_abap_structdescr,
        lt_components   type cl_abap_structdescr=>component_table,
        lv_row type string.
  constants con_tab type c value cl_abap_char_utilities=>horizontal_tab.
  field-symbols: <ls_comp> like line of lt_components, <fs_field>, <wa> type any.
  clear it_filcont.
  assign gs_line to <wa>.
  if lt_components is initial.
    lro_structdescr ?= cl_abap_typedescr=>describe_by_data( <wa> ).
    lt_components = lro_structdescr->get_components( ).
  endif.
  do.
    assign component sy-index of structure <wa> to <fs_field>.
    if sy-subrc <> 0.
      exit.
    endif.
    read table lt_components assigning <ls_comp> index sy-index.
    lv_row = lv_row && <ls_comp>-name && con_tab.
  enddo.
  append lv_row to it_filcont. clear lv_row.
endform.

Schreibe einen Kommentar



All fields are required. Your email address will not be published.