2023 Apr 14 2:04 PM
I want to display an alv report of an internal table which is dynamically generated. The problem is its not showing any output nor is it giving any syntax or runtime errors.
Here is the code:
TABLES : mara,t001l,mchb,marc.
TYPES : BEGIN OF ty_intransit,
werks TYPE werks_d,
matnr TYPE matnr, "Material
maktx TYPE maktx, "Material Description
charg TYPE charg_d, "Batch
lgort TYPE lgort_d, "Storage location
labst TYPE menge_d,
insme TYPE insme, "Quality inspection
einme TYPE einme, "Restricted use
speme TYPE speme, "Blocked
retme TYPE retme, "Return
meins TYPE meins, "Basic Uom
umlme TYPE umlme,
END OF ty_intransit.
DATA : gt_final TYPE TABLE OF ty_intransit,
lt_final_int TYPE TABLE OF ty_intransit,
gs_final TYPE ty_intransit.
DATA :lt_fcat TYPE slis_t_fieldcat_alv.
DATA :ls_fcat TYPE slis_fieldcat_alv.
TYPES: BEGIN OF ty_lgort,
lgort TYPE lgort_d,
END OF ty_lgort.
DATA: it_lgort TYPE TABLE OF ty_lgort,
wa_lgort TYPE ty_lgort.
TYPES: BEGIN OF ty_final,
matnr TYPE matnr,
maktx TYPE maktx,
werks TYPE werks_d,
charg TYPE charg_d,
meins TYPE meins,
END OF ty_final.
DATA: it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
DATA total_sum TYPE p DECIMALS 3.
FIELD-SYMBOLS : <lt_data> TYPE STANDARD TABLE.
DATA lr_data TYPE REF TO data.
DATA lr_datah TYPE REF TO data.
DATA lr_datai TYPE REF TO data.
DATA lr_data_descr TYPE REF TO cl_abap_datadescr.
DATA lr_data_line_descr TYPE REF TO cl_abap_datadescr.
DATA: ref_descr TYPE REF TO cl_abap_structdescr.
DATA: gv_repid TYPE syst-repid,
gt_seltab TYPE TABLE OF rsparams,
gs_seltab TYPE rsparams.
DATA : gv_subrc TYPE sy-subrc.
DATA: otable TYPE REF TO cl_abap_tabledescr,
ostruct TYPE REF TO cl_abap_structdescr,
ref_final_table TYPE REF TO data.
FIELD-SYMBOLS: <fs_final> TYPE STANDARD TABLE.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
matnr FOR mara-matnr,
werks FOR t001l-werks OBLIGATORY,
lgort FOR t001l-lgort,
matart FOR mara-mtart DEFAULT 'FERT'.
PARAMETERS: p_batch AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.
gv_repid = sy-repid.
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = gv_repid
TABLES
selection_table = gt_seltab[].
CLEAR gs_seltab.
gs_seltab-selname = 'NEGATIV'.
gs_seltab-kind = 'P'.
APPEND gs_seltab TO gt_seltab.
gs_seltab-selname = 'NOZERO'.
APPEND gs_seltab TO gt_seltab.
gs_seltab-selname = 'NOVALUES'.
APPEND gs_seltab TO gt_seltab.
gs_seltab-selname = 'PA_HSQ'.
APPEND gs_seltab TO gt_seltab.
gs_seltab-selname = 'XMCHB'.
gs_seltab-low = 'X'.
APPEND gs_seltab TO gt_seltab.
gs_seltab-selname = 'PA_FLT'.
gs_seltab-low = 'X'.
APPEND gs_seltab TO gt_seltab.
gs_seltab-selname = 'PA_SOND'.
gs_seltab-low = 'X'.
APPEND gs_seltab TO gt_seltab.
CLEAR gs_seltab.
gs_seltab-selname = 'P_VARI'.
gs_seltab-kind = 'P'.
APPEND gs_seltab TO gt_seltab.
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_false
data = abap_true ).
TRY .
SUBMIT rm07mlbs WITH SELECTION-TABLE gt_seltab " getting data from mb52
EXPORTING LIST TO MEMORY AND RETURN.
TRY.
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_data ).
ASSIGN lr_data->* TO <lt_data>.
IF <lt_data> IS ASSIGNED.
LOOP AT <lt_data> ASSIGNING FIELD-SYMBOL(<fs_data>).
MOVE-CORRESPONDING <fs_data> TO gs_final.
APPEND gs_final TO gt_final.
ASSIGN COMPONENT 'LGORT' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs>).
IF <fs> IS ASSIGNED.
IF line_exists( it_lgort[ lgort = <fs> ] ).
CONTINUE.
ELSE.
wa_lgort-lgort = <fs>.
APPEND wa_lgort TO it_lgort.
CLEAR wa_lgort.
ENDIF.
UNASSIGN <fs>.
ENDIF.
ENDLOOP.
SORT it_lgort.
it_lgort[ table_line = '' ] = 'None'.
ENDIF.
CATCH cx_salv_bs_sc_runtime_info.
RAISE no_data.
ENDTRY.
CATCH cx_root.
ENDTRY.
otable ?= cl_abap_tabledescr=>describe_by_data( p_data = it_final ).
ostruct ?= otable->get_table_line_type( ).
DATA(p_comp) = ostruct->get_components( ).
DATA: wa_comp LIKE LINE OF p_comp.
wa_comp-type = cl_abap_elemdescr=>get_p(
p_length = 13
p_decimals = 3
).
LOOP AT it_lgort INTO wa_lgort.
wa_comp-name = wa_lgort-lgort.
APPEND wa_comp TO p_comp.
ENDLOOP.
wa_comp-name = 'Total'.
APPEND wa_comp TO p_comp.
DATA(ostruct_new) = cl_abap_structdescr=>create(
p_components = p_comp
).
DATA(otable_new) = cl_abap_tabledescr=>create(
p_line_type = ostruct_new
).
CREATE DATA ref_final_table TYPE HANDLE otable_new.
ASSIGN ref_final_table->* TO <fs_final>.
SELECT matnr, maktx, werks, charg, lgort, meins,
SUM( labst ) AS unrestricted_qty, SUM( insme ) AS quality_qty,
SUM( speme ) AS blocked_qty, SUM( einme ) AS restricted_qty,
SUM( retme ) AS returns_qty
FROM @gt_final AS final_table GROUP BY matnr, maktx, werks, charg, lgort, meins INTO TABLE @DATA(gt_final2).
MOVE-CORRESPONDING gt_final2 TO <fs_final>.
LOOP AT gt_final2 INTO DATA(gs_final2).
READ TABLE <fs_final> ASSIGNING FIELD-SYMBOL(<wa_final>) WITH KEY ('MATNR') = gs_final2-matnr ('WERKS') = gs_final2-werks ('CHARG') = gs_final2-charg.
IF sy-subrc = 0.
total_sum = gs_final2-unrestricted_qty + gs_final2-quality_qty + gs_final2-blocked_qty + gs_final2-restricted_qty + gs_final2-returns_qty.
IF gs_final2-lgort IS INITIAL.
ASSIGN COMPONENT 'NONE' OF STRUCTURE <wa_final> TO FIELD-SYMBOL(<fs_lgort>).
IF <fs_lgort> IS ASSIGNED.
<fs_lgort> = total_sum.
ENDIF.
ELSE.
ASSIGN COMPONENT gs_final2-lgort OF STRUCTURE <wa_final> TO <fs_lgort>.
IF <fs_lgort> IS ASSIGNED.
<fs_lgort> = total_sum.
ENDIF.
ENDIF.
ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <wa_final> TO FIELD-SYMBOL(<fs_total>).
IF <fs_total> IS ASSIGNED.
<fs_total> = <fs_total> + total_sum.
ENDIF.
ENDIF.
ENDLOOP.
DATA: lo_alv TYPE REF TO cl_salv_table.
DATA: gr_columns TYPE REF TO cl_salv_columns_table.
DATA: gr_column TYPE REF TO cl_salv_column_table.
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = abap_false
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = <fs_final> ).
CATCH cx_salv_msg .
ENDTRY.
gr_columns = lo_alv->get_columns( ).
gr_columns->set_optimize( abap_true ).
lo_alv->display( ).
2023 Apr 14 4:29 PM
You can't display ALV if you first indicate to not display ALV (cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false...)
Reset the parameters before executing the DISPLAY method:
cl_salv_bs_runtime_info=>CLEAR( ).
2023 Apr 14 4:29 PM
You can't display ALV if you first indicate to not display ALV (cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false...)
Reset the parameters before executing the DISPLAY method:
cl_salv_bs_runtime_info=>CLEAR( ).
2023 Apr 17 9:47 AM