SAP ABAP - ALV Grid WIth Simple OOP Implementation
Define Internal table, work area & Selection screen :
tables : mara.
data: it_mara type table of mara,
wa_mara type mara.
select-options:
s_matnr for mara-matnr,
s_mtart for mara-mtart.
Define class & class implementation :
class mara_class definition.
public section.
methods: getmara.
methods: showalv.
endclass.
class mara_class implementation.
method getmara.
refresh it_mara.
select * from mara into table it_mara where matnr in s_matnr and mtart in s_mtart.
endmethod.
method showalv.
call function 'REUSE_ALV_GRID_DISPLAY_LVC'
exporting
i_callback_program = sy-repid
i_structure_name = 'MARA'
i_save = 'X'
tables
t_outtab = it_mara
exceptions
program_error = 1
others = 2.
endmethod.
endclass.
call class & method :
start-of-selection.
data: mara_class type ref to mara_class.
create object: mara_class.
call method: mara_class->getmara, mara_class->showalv.
Full source code :
report zoop01.
tables : mara.
data: it_mara type table of mara,
wa_mara type mara.
select-options:
s_matnr for mara-matnr,
s_mtart for mara-mtart.
class mara_class definition.
public section.
methods: getmara.
methods: showalv.
endclass.
class mara_class implementation.
method getmara.
refresh it_mara.
select * from mara into table it_mara where matnr in s_matnr and mtart in s_mtart.
endmethod.
method showalv.
call function 'REUSE_ALV_GRID_DISPLAY_LVC'
exporting
i_callback_program = sy-repid
i_structure_name = 'MARA'
i_save = 'X'
tables
t_outtab = it_mara
exceptions
program_error = 1
others = 2.
endmethod.
endclass.
start-of-selection.
data: mara_class type ref to mara_class.
create object: mara_class.
call method: mara_class->getmara, mara_class->showalv.
Run program :D
Comments
Post a Comment