‎2020 Aug 26 6:38 AM
Hi,
does anyone have a sample how to handle a dynamic internal table to generate excel with multiple sheet?
‎2020 Aug 26 7:52 AM
Hello theejaydee
What do you want the logic to do with multiple sheets?
The basic for using dynamic internal table to create an Excel spreadsheet is to use of field symbols. For example:
DATA:
ld_row TYPE REF TO data.
FIELD-SYMBOLS:
<lv_field> TYPE any,
<ls_row> TYPE any.
CREATE ld_row LIKE LINE OF it_internal_table.
ASSIGN ld_row->* TO <ls_row>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <ls_row> TO <lv_field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
" code below is just a mock-up
lo_excel->set_cell( <lv_field>
ENDDO.Kind regards,‎2020 Aug 26 7:52 AM
Hello theejaydee
What do you want the logic to do with multiple sheets?
The basic for using dynamic internal table to create an Excel spreadsheet is to use of field symbols. For example:
DATA:
ld_row TYPE REF TO data.
FIELD-SYMBOLS:
<lv_field> TYPE any,
<ls_row> TYPE any.
CREATE ld_row LIKE LINE OF it_internal_table.
ASSIGN ld_row->* TO <ls_row>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <ls_row> TO <lv_field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
" code below is just a mock-up
lo_excel->set_cell( <lv_field>
ENDDO.Kind regards,‎2020 Aug 26 8:56 AM
Hi Mateusz,
I think you got me at the Do.. Enddo. part. Will test this one out and check further.
Basically sample scenario is I have more than one dynamic internal table for each table i need to create a sheet. Without knowing the number of fields each table, how will i pass it to using the tool.
‎2020 Aug 26 9:12 AM
In this case I'd do a method/procedure which would take in the internal table and the name of spreadsheet that has to be created/filled. Then in the method/procedure open/create the spreadsheet and use my example code to fill it with data.
‎2020 Aug 26 9:48 AM
‎2020 Aug 26 10:00 AM
Jay Dy You may load easily any internal table with abap2xlsx, whatever it's a static or dynamic internal table, with the method worksheet->bind_table.
‎2020 Aug 26 10:24 AM
‎2020 Aug 26 8:48 AM
With abap2xlsx, you probably have no difficulty to generate multiple sheets (ZDEMO_EXCEL4 : abap2xlsx Demo: Create XLXS with multiple sheets).
So, your problem can be simplified to create one internal table per worksheet and fill the internal tables from the dynamic internal table, and your question is maybe how to read the dynamic internal table? (abap2xlsx is no more implied in the question) If so -> see Mateusz answer.