Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

[abap2xlsx] generate excel using dynamic internal table

Former Member
0 Likes
3,451

Hi,

does anyone have a sample how to handle a dynamic internal table to generate excel with multiple sheet?

1 ACCEPTED SOLUTION
Read only

MateuszAdamus
Active Contributor
0 Likes
2,792

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,
Mateusz
7 REPLIES 7
Read only

MateuszAdamus
Active Contributor
0 Likes
2,793

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,
Mateusz
Read only

0 Likes
2,792

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.

Read only

0 Likes
2,792

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.


Kind regards,
Mateusz
Read only

2,792

Thank you very much for your insight!

Read only

2,792

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.

Read only

0 Likes
2,792

Thanks Sandra, I will look into that method as well.

Read only

Sandra_Rossi
Active Contributor
2,792

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.