SAP ABAP - ALV Average Field Value
*&---------------------------------------------------------------------*
*& Report ZALV_AVG
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zalv_avg.
TABLES: ekko, ekpo.
TYPES:
BEGIN OF ty_data,
lifnr TYPE lifnr,
matnr TYPE matnr,
menge TYPE menge_d,
meins TYPE meins,
END OF ty_data.
DATA:
lt_data TYPE TABLE OF ty_data.
DATA:
lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
is_layout TYPE slis_layout_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv.
PARAMETERS:
p_bukrs TYPE bukrs.
SELECT-OPTIONS:
s_matnr for ekpo-matnr,
s_aedat FOR ekko-aedat.
START-OF-SELECTION.
PERFORM get_data.
PERFORM set_fieldcate.
PERFORM display_data.
FORM get_data.
REFRESH lt_data.
SELECT ekko~lifnr, ekpo~matnr, ekpo~menge, ekpo~meins
FROM ekko INNER JOIN ekpo ON ekko~ebeln = ekpo~ebeln
INTO TABLE @lt_data
WHERE ekko~bukrs = @p_bukrs AND ekko~aedat IN @s_aedat and ekpo~matnr in @s_matnr.
ENDFORM.
FORM set_fieldcate.
REFRESH lt_fieldcat.
PERFORM :
append_fieldcat USING 'LIFNR' 'Vendor Code' 'CHAR' '' '' '12' '' 'X' 'LT_DATA' '',
append_fieldcat USING 'MATNR' 'Material' 'CHAR' '' '' '12' '' '' 'LT_DATA' '',
append_fieldcat USING 'MENGE' 'Quantity' 'QUAN' 'MEINS' '' '12' 'C' '' 'LT_DATA' '',
append_fieldcat USING 'MEINS' 'UoM' 'UNIT' '' '' '12' '' '' 'LT_DATA' ''.
is_layout-colwidth_optimize = 'X'.
is_layout-info_fieldname = 'LINECOLOR'.
REFRESH lt_sort.
CLEAR ls_sort.
ls_sort-spos = 1.
ls_sort-fieldname = 'LIFNR'.
ls_sort-up = 'X'.
APPEND ls_sort TO lt_sort.
CLEAR ls_sort.
ls_sort-spos = 2.
ls_sort-fieldname = 'MATNR'.
ls_sort-subtot = 'X'.
ls_sort-up = 'X'.
APPEND ls_sort TO lt_sort.
ENDFORM.
FORM append_fieldcat USING p_fname p_fdesc p_dtype p_qfield p_cfield p_olen p_sum p_key p_tabname p_reftabname.
DATA irows TYPE i.
CLEAR irows.
DESCRIBE TABLE lt_fieldcat LINES irows.
irows = irows + 1.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = irows.
ls_fieldcat-key = p_key.
ls_fieldcat-fieldname = p_fname.
ls_fieldcat-seltext_l = p_fdesc.
ls_fieldcat-seltext_m = p_fdesc.
ls_fieldcat-seltext_s = p_fdesc.
ls_fieldcat-datatype = p_dtype.
ls_fieldcat-qfieldname = p_qfield.
ls_fieldcat-cfieldname = p_cfield.
ls_fieldcat-outputlen = p_olen.
ls_fieldcat-do_sum = p_sum.
ls_fieldcat-tabname = p_tabname.
ls_fieldcat-ref_tabname = p_reftabname.
APPEND ls_fieldcat TO lt_fieldcat.
ENDFORM.
FORM display_data.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = is_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
i_save = 'X'
TABLES
t_outtab = lt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
Comments
Post a Comment