2023 May 10 5:38 AM
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.
2023 May 10 6:36 AM
To "pass" a line of a table to a structure you have to use the read statement of Internal table :
When you do this, you cannot specify the column desired, but you could move the full structure to a short structure using statement :
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
2023 May 10 7:10 AM
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.
2023 May 10 7:53 AM
jens_michaelsen I think you are scratching the content of PARAM with the contennt of VALUE
2023 May 10 8:10 AM
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.
2023 May 10 8:20 AM
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 ).
2023 May 10 8:30 AM
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"?
2023 May 10 9:29 AM
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.
2023 May 10 12:29 PM
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.
2023 May 10 5:55 PM
My bad, then t's quite a major issue in the original code and in the way the question is asked 😄
2023 May 15 8:31 AM
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.