2013 May 07 4:44 PM
Hi Experts,
I have created an dynamic internal table using:
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = C_fieldcat
i_length_in_byte = 'X'
IMPORTING
ep_table = gt_DTAB.
Then I do the following steps:
ASSIGN gt_DTAB->* TO <gf_table>.
CREATE DATA ly_line LIKE LINE OF <gf_table>.
ASSIGN ly_line->* to <fs_tb>.
Q.1 Now my requirment is to read data into <gf_table> from a database table which have few fields different from <gf_table>.
I tired reading the data into an internal table from database table then passing to <gf_table>, but its not working:
LOOP AT gt_001 INTO lwa_001.
ASSIGN COMPONENT sy-index OF STRUCTURE lwa_001 to <fs_tb>.
MOVE-CORRESPONDING <fs_tb> to <gf_table>.
ENDLOOP.
Q.2 Also, I need to declare an internal table say LT_001 which should have the structure same as <gf_table> , how can I achieve this.
Thanks in advance for your inputs.
BR.
2013 May 07 5:59 PM
If you loop through gt_001, then you're looping through the records not the fields. Somewhere, you must have defined the names of the field. Use those with ASSIGN COMPONENT fieldname OF STRUCTURE TO <field>.
Second is easy.
DATA: lr_data TYPE REF TO DATA.
FIELD-SYMBOLS: <newtable> TYPE STANDARD TABLE.
CREATE DATA lr_data LIKE <gf_table>.
ASSIGN lr_data->* TO <newtable>.
2013 May 08 3:34 AM
Hi Matthew,
I appreciate your response.
Please note:
1. Gt_001 contains data (eg. 20 rows and 18 columns) which I want to pass to corresponding column of my dynamic table <gf_table> (eg. 21 columns). Please guide how can I achieve this.
2. The code which you mention creates an field-symbol <newtable> which is table type and have structure as <gf_table>, but I need to create an internal table like one we create with statement: DATA ITAB TYPE STANDARD TABLE OF ST_STRUCTURE.
BR.
2013 May 08 6:10 AM
1)
CREATE DATA lr_data LIKE LINE OF <secondtab>.
ASSIGN <lr_data>->* TO <secondwa>.
LOOP AT <firsttab> ASSIGNING <firstwa>.
MOVE-CORRESPONDING <firstwa> TO <secondwa>.
INSERT <secondwa> INTO TABLE <secondtab>.
ENDLOOP.
2)
TYPES: t_newtab_ty TYPE STANDARD TABLE OF st_structure WITH DEFAULT KEY.
FIELD-SYMBOLS: <newtable> TYPE t_newtab_ty.
CREATE DATA lr_data TYPE t_newtab_ty.
ASSIGN lr_data->* TO <newtable>.
Just think things through logically. How can I get to where I want to be from what I have?