*&---------------------------------------------------------------------*
*& Report ZP_TMP_DATA_PROVIDER
*&
*&---------------------------------------------------------------------*
*& Demo for SCN blog post "The global variable dilemma"
*& This report creates a list of all work center header data
*& used in a production order
*&---------------------------------------------------------------------*
report zp_tmp_data_provider.
parameters p_ordid type aufnr.
class lcl_data_provider definition.
public section.
types gty_t_operations type standard table of afvc with default key.
methods constructor importing iv_orderid type aufnr.
methods get_header returning value(rs_res) type aufk.
methods get_pp returning value(rs_res) type afko.
methods get_operations returning value(rt_res) type gty_t_operations.
private section.
data: ms_order_header type aufk,
ms_order_pp type afko,
mt_operations type gty_t_operations.
endclass.
class lcl_data_provider implementation.
method constructor.
" general order data
select single * from aufk
where aufnr = @iv_orderid
into @ms_order_header.
" production-related order data
select single * from afko
where aufnr = @iv_orderid
into @ms_order_pp.
" order operations
select * from afvc
where aufpl = @ms_order_pp-aufpl
into table @mt_operations.
endmethod.
" getter methods for read-only access to the global data
method get_header.
rs_res = ms_order_header.
endmethod.
method get_pp.
rs_res = ms_order_pp.
endmethod.
method get_operations.
rt_res = mt_operations.
endmethod.
endclass.
class lcl_app definition.
public section.
types: gty_t_crhd type standard table of crhd with default key.
methods constructor importing iv_orderid type aufnr.
methods get_workcenter_list returning value(rt_res) type gty_t_crhd.
private section.
data: mo_data_provider type ref to lcl_data_provider.
methods get_workcenter_oper
importing is_oper type afvc
returning value(rs_res) type crhd.
endclass.
class lcl_app implementation.
method constructor.
" instantiate the data provider
mo_data_provider = new #( iv_orderid ).
endmethod.
method get_workcenter_list.
" use data provider for accessing global data without being able
" to modify it
loop at mo_data_provider->get_operations( ) into data(ls_oper).
data(ls_workcenter) = get_workcenter_oper( ls_oper ).
collect ls_workcenter into rt_res.
endloop.
endmethod.
method get_workcenter_oper.
call function 'CR_WORKSTATION_READ'
exporting
id = is_oper-arbid " Work center ID
msgty = 'E' " Message type
importing
ecrhd = rs_res. " Header data
endmethod.
endclass.
start-of-selection.
cl_demo_output=>display(
new lcl_app( p_ordid )->get_workcenter_list( ) ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
2 | |
2 |