SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Dynamic Internal Tables and Structures



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Mon Dec 24, 2007 12:40 am    Post subject: Dynamic Internal Tables and Structures Reply with quote

Author: Rich Heilman

Program Mainline
Code:
report z_dynamic.

type-pools : abap.

field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.

data: dy_table type ref to data,
      dy_line  type ref to data,
      xfc type lvc_s_fcat,
      ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.

start-of-selection.

  perform get_structure.
  perform create_dynamic_itab.
  perform get_data.
  perform write_out.


Get_Structure Form
Code:
form get_structure.

data : idetails type abap_compdescr_tab,
       xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
  ref_table_des ?=
      cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[] = ref_table_des->components[].

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
  endloop.

endform.


Create_Dynamic_Itab Form
Code:

form create_dynamic_itab.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = ifc
               importing
                  ep_table        = dy_table.

  assign dy_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.
endform.


Get_Data Form
Code:

form get_data.

* Select Data from table.
  select * into table <dyn_table>
             from (p_table).

endform.


Write_Out Form
Code:

* Write out data from table.
  loop at <dyn_table> into <dyn_wa>.
    do.
      assign component  sy-index 
         of structure <dyn_wa> to <dyn_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      if sy-index = 1.
        write:/ <dyn_field>.
      else.
        write: <dyn_field>.
      endif.
    enddo.
  endloop.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.