2009 Sep 17 9:48 AM
Hi ,
I need to upload data from an excel file, the columns in the excel keep on varying
E.g the number of columns in one excel file can be 10, in the second excel file it can be 15.
So in order to upload the data into an internal table the structre of internal table needs to be dynamic and change according to the number of fields in the input file .
Is it possible by using field symbols or is there any other method to do the same
Thanks.
Nishant
Edited by: nishant patel on Sep 17, 2009 10:48 AM
2009 Sep 17 12:18 PM
Hi Nishant,
According to ur requirement, dynamic internal table can be created like below. But database table name has to passed dynacimally.
DATA: ftab TYPE STANDARD TABLE OF ddfield,
ftab_wa TYPE ddfield,
fcat_itab TYPE lvc_t_fcat,
fcat_wa TYPE lvc_s_fcat,
poi_itab TYPE REF TO data.
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = p_table " Pass database table name dynamically
TABLES
ddfields = ftab.
LOOP AT ftab INTO ftab_wa.
fcat_wa-fieldname = ftab_wa-fieldname.
fcat_wa-ref_field = ftab_wa-fieldname.
fcat_wa-ref_table = p_table.
APPEND fcat_wa TO fcat_itab.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fcat_itab
IMPORTING
ep_table = poi_itab
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN poi_itab->* TO <itab>. " <itab> is dynamic internal table
Might help u.
Thanks.
Edited by: Sap Fan on Sep 17, 2009 1:19 PM
Hi ,
I need to upload data from an excel file, the columns in the excel keep on varying
E.g the number of columns in one excel file can be 10, in the second excel file it can be 15.
So in order to upload the data into an internal table the structre of internal table needs to be dynamic and change according to the number of fields in the input file .
Is it possible by using field symbols or is there any other method to do the same
Thanks.
Nishant
Edited by: nishant patel on Sep 17, 2009 10:48 AM
2009 Sep 17 10:00 AM
Try the following..........
PARAMETERS : p_table(10) TYPE C.
DATA: w_tabname TYPE w_tabname,
w_dref TYPE REF TO data,
w_grid TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE,
<w_itab> type any.
w_tabname = p_table.
assign w_tabname to <w_itab>.
CREATE DATA w_dref TYPE TABLE OF (w_tabname).
ASSIGN w_dref->* TO <t_itab>.
SELECT *
FROM (w_tabname) UP TO 20 ROWS
INTO TABLE <t_itab>.
2009 Sep 17 10:07 AM
Hi, if you make a structure with field eq FLD01, FLD02, FLD03 etc. you can use a FIELD SYMBOL.
Code is something like this:
FIELD-SYMBOLS: <fs_fld> TYPE any.
DATA: wa_cnt TYPE i,
wa_fieldname(8) TYPE c,
wa_num1(1) TYPE n,
wa_num2(2) TYPE n.
CLEAR wa_cnt.
WHLIE .......
wa_cnt = wa_cnt + 1.
wa_num2 = wa_cnt.
CONCATENATE 'REC-FLD' wa_num2 INTO wa_fieldname.
ASSIGN (wa_fieldname) TO <fs_fld>.
<fs_fld> = ..
ENDWHILE.
Success.
2009 Sep 17 10:29 AM
If you need to pass the final internal table to ALV try this...
DATA : li_fieldcat TYPE lvc_t_fcat,
lw_fieldcat LIKE LINE OF gi_fieldcat.
DATA: li_new_table TYPE REF TO data,
lw_new_line TYPE REF TO data.
FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE,
<fs_wa> TYPE ANY.
According to number of fields in excel first,build the field catalogue internal table to li_fieldcat
Then pass this internal table >
*/..Method to create dynamic internal table creation
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = li_fieldcat
IMPORTING
ep_table = li_new_table.
ASSIGN li_new_table->* TO <fs_tab>.
CREATE DATA lw_new_line LIKE LINE OF <fs_tab>.
*/..Workarea
ASSIGN lw_new_line->* TO <fs_wa>.
<fs_tab> will have the structure of the excel sheet fields.
2009 Sep 17 11:20 AM
check out this code ->
START-OF-SELECTION.
write : / 'SPFLI', / 'SFLIGHT', / 'Sbook'.
at LINE-SELECTION.
data: tabname TYPE tabname,
dref TYPE REF TO data,
alv TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS : <itab> TYPE ANY TABLE.
read CURRENT LINE LINE VALUE INTO tabname.
CREATE DATA dref TYPE TABLE OF (tabname).
ASSIGN dref->* to <itab>.
CREATE OBJECT alv
EXPORTING i_parent = cl_gui_container=>screen0.
call METHOD alv->set_table_for_first_display
EXPORTING i_structure_name = tabname
CHANGING it_outtab = <itab>.
CALL SCREEN 100.Edited by: Sourabh Jain on Sep 17, 2009 12:21 PM
Edited by: Sourabh Jain on Sep 18, 2009 12:25 PM
2009 Sep 17 12:18 PM
Hi Nishant,
According to ur requirement, dynamic internal table can be created like below. But database table name has to passed dynacimally.
DATA: ftab TYPE STANDARD TABLE OF ddfield,
ftab_wa TYPE ddfield,
fcat_itab TYPE lvc_t_fcat,
fcat_wa TYPE lvc_s_fcat,
poi_itab TYPE REF TO data.
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = p_table " Pass database table name dynamically
TABLES
ddfields = ftab.
LOOP AT ftab INTO ftab_wa.
fcat_wa-fieldname = ftab_wa-fieldname.
fcat_wa-ref_field = ftab_wa-fieldname.
fcat_wa-ref_table = p_table.
APPEND fcat_wa TO fcat_itab.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fcat_itab
IMPORTING
ep_table = poi_itab
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN poi_itab->* TO <itab>. " <itab> is dynamic internal table
Might help u.
Thanks.
Edited by: Sap Fan on Sep 17, 2009 1:19 PM
2009 Sep 17 1:38 PM
Hii SAP FAN,
i have to load the data from the flat file ,so like how will the internal table structure vary according to number of columns in the flat file
Thanks,
Nishant
2009 Sep 17 1:40 PM
Hi Nishnat,
Check this Link
http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html
Thanks
Amresh
2009 Sep 18 11:32 AM
Here's demo ALV prg., close to your requirement.
BCALV_TABLE_CREATE
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |