Sample Code
Report ZTEST.
tables : mseg.
type-pools: slis,icon,vimty,abap,truxs.
data: begin of it_mseg occurs 0,
mjahr type mseg-mjahr,
matnr type mseg-matnr,
kdauf type mseg-kdauf,
dmbtr type mseg-dmbtr,
end of it_mseg.
*ALV
data: d_repid type sy-repid,
t_fldcat type slis_t_fieldcat_alv,
t_sort type slis_t_sortinfo_alv,
x_layout type slis_layout_alv,
s_fldcat type slis_fieldcat_alv.
initialization.
perform binit.
select-options: s_kdauf for mseg-kdauf,
s_mjahr for mseg-mjahr.
.
at selection-screen output.
start-of-selection.
at selection-screen.
start-of-selection.
select * into corresponding fields of table it_mseg
from mseg
where kdauf in s_kdauf
and mjahr in s_mjahr.
loop at it_mseg.
multiply it_mseg-dmbtr by 100.
modify it_mseg.
endloop.
perform l_build_layout_ist.
perform build_fieldcat_ist.
perform display_ist.
*
end-of-selection.
*&---------------------------------------------------------------------*
*& Form BINIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form binit .
define f_fldcat.
clear s_fldcat.
s_fldcat-fieldname = &1.
s_fldcat-decimals_out = &2.
s_fldcat-seltext_l = &3.
s_fldcat-outputlen = &4.
s_fldcat-just = &5.
s_fldcat-no_out = &6.
s_fldcat-datatype = &7.
s_fldcat-qfieldname = &8.
s_fldcat-no_zero = &9.
append s_fldcat to t_fldcat.
end-of-definition.
endform. " BINIT
*&---------------------------------------------------------------------*
*& Form L_BUILD_LAYOUT_IST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form l_build_layout_ist .
x_layout-colwidth_optimize = 'X'.
x_layout-info_fieldname = 'LINE_COLOR'.
x_layout-def_status = 'X'.
* x_layout-lights_fieldname = 'TRF_LIGHT'.
* x_layout-lights_tabname = 'I_LIGHTS'.
endform. " L_BUILD_LAYOUT_IST
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT_IST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_fieldcat_ist .
f_fldcat 'MJAHR' '' 'Year' '' 'L' '' 'CHAR' '' '' .
f_fldcat 'KDAUF' '' 'Sales order' '' 'L' '' 'CHAR' '' '' .
f_fldcat 'MATNR' '' 'Material' '' 'L' '' '' '' '' .
f_fldcat 'DMBTR' '0' 'Amount' '' 'R' '' 'DEC' '' '' .
clear s_fldcat.
endform. " BUILD_FIELDCAT_IST
*&---------------------------------------------------------------------*
*& Form DISPLAY_IST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_ist .
d_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = d_repid
i_callback_pf_status_set = 'STAT_SET'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = t_fldcat[]
it_sort = t_sort[]
is_layout = x_layout
i_default = ''
i_save = ''
tables
t_outtab = it_mseg[]
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " DISPLAY_IST
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_UCOMM text
* -->P_SELFIELD text
*----------------------------------------------------------------------*
form user_command using p_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case p_ucomm.
when '&PRO'.
when '&BACK'.
leave to screen 0.
when '&EXIT'.
leave to screen 0.
when '&CNCL'.
leave to screen 0.
endcase.
endform. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form f_status_set
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
form stat_set using rt_extab type slis_t_extab.
set pf-status 'ZALV2'.
endform. "stat_set
No comments:
Post a Comment