Application Development 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: 

How to pass specific columns of an internal table to a local structure?

walkerist
Participant
0 Kudos
964

Hello,

I'm trying to pass this LT_LAYOUT into LX_LAYOUT but only the columns PARAM and VALUE.

LT_LAYOUT is from FM LT_DBDATA_READ_FROM_LTDX and I would like to use to to REUSE_ALV_GRID_DISPLAY to change the layout of the excel file according to the layout assigned by the user.

DATA: lt_fieldcat TYPE STANDARD TABLE OF ltdxdata,
lt_sort_info TYPE STANDARD TABLE OF ltdxdata,
lt_layout TYPE STANDARD TABLE OF ltdxdata,
lx_layout1 type slis_layout_alv,
lt_filter TYPE STANDARD TABLE OF ltdxdata.
SELECT *
FROM ltdx
INTO @DATA(lx_ltdx_fg)
UP TO 1 ROWS
WHERE variant = @x_variant-variant
ORDER BY PRIMARY KEY.
ENDSELECT.
IF sy-subrc = 0.
DATA(lx_varkey_fg) = CORRESPONDING ltdxkey( lx_ltdx_fg ).
ENDIF.
CALL FUNCTION 'LT_DBDATA_READ_FROM_LTDX'
EXPORTING
I_TOOL = 'LT'
is_varkey = lx_varkey_fg
tables
t_dbfieldcat = lt_fieldcat
T_DBSORTINFO = lt_sort_info
T_DBFILTER = lt_filter
T_DBLAYOUT = lt_layout
EXCEPTIONS
NOT_FOUND = 1
WRONG_RELID = 2
OTHERS = 3
.
IF sy-subrc = 0.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_background_id = 'ALV_BACKGROUND'
is_layout = lt_layout
it_fieldcat = t_fieldcat[]
it_special_groups = t_sp_group[]
it_sort = t_sort[]
i_save = v_save
is_variant = x_variant
it_events = t_events
is_print = x_print
tables
t_outtab = t_output
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
ENDIF.
10 REPLIES 10

FredericGirod
Active Contributor
0 Kudos
863

To "pass" a line of a table to a structure you have to use the read statement of Internal table :

  • READ TABLE
  • LOOP AT

When you do this, you cannot specify the column desired, but you could move the full structure to a short structure using statement :

  • MOVE
  • MOVE-CORRESPONDING

Even if you play with new statement using FOR, more or less it will do the same

Otherwise you have new statement like

my_little_structure = corresponding #( my_table[ my_line_index ] ).

But you have to be sure, the index exist

jens_michaelsen
Participant
0 Kudos
863

Do you mean something like this:

FIELD-SYMBOLS: <target> TYPE any.

LOOP AT lt_layout ASSIGNING FIELD-SYMBOL(<lt_layout>).
ASSIGN COMPONENT <lt_layout>-param OF STRUCTURE lx_layout TO <target>.
IF sy-subrc EQ 0.
<target> = <lt_layout>-value.
ENDIF.
ENDLOOP.

FredericGirod
Active Contributor
0 Kudos
863

jens_michaelsen I think you are scratching the content of PARAM with the contennt of VALUE

jens_michaelsen
Participant
863

Frederic Girod I thought that we have in the column PARAM of table LT_LAYOUT the fieldnames for the columns in the structure LX_LAYOUT. That goes for some columns like 'ZEBRA', but not for all. 😞

It seems to be the fieldnames for LVC Layout.

Sandra_Rossi
Active Contributor
0 Kudos
863

Probably it means that LT_DBDATA_READ_FROM_LTDX may possibly query several ALV layout variants but if you query exactly one variant, you can always do this as Frederic suggested:

DATA(lx_layout) = VALUE #( lt_layout[ 1 ] OPTIONAL ).

jens_michaelsen
Participant
0 Kudos
863

sandra.rossi I don't think so. LX_LAYOUT1 has the structure SLIS_LAYOUT_ALV, LT_LAYOUT has the structure of LTDXDATA. I think, it's not possible to convert the data with that statement.

But I wonder, why it's necessary to pass the lines at all.

If we want to display an ALV-grid with specific layout, it's not enough to process the ALV-grid with this layout using the specific parameter "Variant"?

xiswanto
Active Participant
0 Kudos
863

walkerist i don't think the lt_layout that you declared could be used in the 'REUSE_ALV_GRID_DISPLAY' as it is using a different structure, might cause run time error.

raymond_giuseppi
Active Contributor
863

The structures you get from this FM do not comply to the format expected by ALV FM or class. You have to convert them, search where-used of structure and FM, look at some FM such as LT_FC_LOAD, etc.

Sandra_Rossi
Active Contributor
0 Kudos
863

My bad, then t's quite a major issue in the original code and in the way the question is asked 😄

jens_michaelsen
Participant
0 Kudos
863

For your requirement to use FM REUSE_ALV_GRID_DISPLAY to change the layout of the excel file according to the layout assigned by the user forget FM LT_DBDATA_READ_FROM_LTDX. You don't need it.

Write a report using FM REUSE_ALV_GRID_DISPLAY with user's variant, which shows total normally the data.

Then write a second report, which calls the first report using the same parameter, but using CL_SALV_BS_RUNTIME_INFO to suppress the display of ALV-GRID and to get the ALV-data and metadata.

After that you can put together data and metadata in an excel file (Classes cl_salv_ex_util and cl_salv_bs_lex ) according to the layout assigned by the user and send the file to an email.

I know, it seems a little bit crazy, but it's a way to do it.