Posted: Sat Nov 24, 2007 12:17 am Post subject: Sales Order Flow – Tree Report
Code:
report z_sales_tree_rpt .
*******************************************************************
* Create a tree report of sales orders to deliveries to invoices *
*******************************************************************
include z_sales_tree_rpt_top.
include z_sales_tree_class_def.
selection-screen begin of block a0 with frame title text-001.
*selection-screen comment 5(60) text-c00 modif id sc1.
selection-screen begin of block b5 with frame title text-s05.
select-options:
s_erdat for vbak-erdat,
s_ernam for vbak-ernam.
parameters: s_vbtyp like vbfa-vbtyp_n default 'C'.
selection-screen end of block b5.
if not itab_data is initial.
* create the application object
* this object is needed to handle the ABAP Objects Events of Controls
create object g_application.
call screen 2000.
else.
message i043(z1).
endif.
end-of-selection.
*----------------------------------------------------------------------*
* Includes
*----------------------------------------------------------------------*
include z_sales_tree_forms.
include z_sales_tree_pbo.
include z_sale_tree_pai.
*----------------------------------------------------------------------*
* INCLUDE Z_SALES_TREE_CLASS_DEF *
*----------------------------------------------------------------------*
class lcl_application definition.
public section.
methods:
handle_node_double_click
for event node_double_click
of cl_gui_list_tree
importing node_key,
handle_expand_no_children
for event expand_no_children
of cl_gui_list_tree
importing node_key,
handle_item_double_click
for event item_double_click
of cl_gui_list_tree
importing node_key item_name,
handle_button_click
for event button_click
of cl_gui_list_tree
importing node_key item_name,
handle_link_click
for event link_click
of cl_gui_list_tree
importing node_key item_name,
handle_checkbox_change
for event checkbox_change
of cl_gui_list_tree
importing node_key item_name checked.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_application IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_application implementation.
method handle_node_double_click.
" this method handles the node double click event of the tree
" control instance
" show the key of the double clicked node in a dynpro field
read table itab_data with key node_key = node_key into wa_data.
if sy-subrc = 0.
select single rfmng rfwrt matnr
into (vbfa-rfmng, vbfa-rfwrt, vbfa-matnr)
from vbfa
where vbelv = wa_data-vbeln
and posnv = wa_data-posnn.
endif.
endmethod.
method handle_item_double_click.
" this method handles the item double click event of the tree
" control instance. You have variables node_key and item_name
" show the key of the node and the name of the item
" of the double clicked item in a dynpro field
read table itab_data with key node_key = node_key into wa_data.
if sy-subrc = 0.
select single rfmng rfwrt matnr
into (vbfa-rfmng, vbfa-rfwrt, vbfa-matnr)
from vbfa
where vbelv = wa_data-vbeln
and posnv = wa_data-posnn.
endif.
endmethod.
method handle_link_click.
" this method handles the link click event of the tree
" control instance
" show the key of the node and the name of the item
" of the clicked link in a dynpro field
* g_event = 'LINK_CLICK'.
* g_node_key = node_key.
* g_item_name = item_name.
endmethod.
method handle_button_click.
" this method handles the button click event of the tree
" control instance
" show the key of the node and the name of the item
" of the clicked button in a dynpro field
* g_event = 'BUTTON_CLICK'.
* g_node_key = node_key.
* g_item_name = item_name.
endmethod.
method handle_checkbox_change.
" this method handles the checkbox_change event of the tree
" control instance
" show the key of the node and the name of the item
" of the clicked checkbox in a dynpro field
* g_event = 'CHECKBOX_CHANGE'.
* g_node_key = node_key.
* g_item_name = item_name.
endmethod.
method handle_expand_no_children.
data: node_table type treev_ntab,
node type treev_node,
item_table type item_table_type,
item type mtreeitm.
* show the key of the expanded node in a dynpro field
* g_event = 'EXPAND_NO_CHILDREN'.
* g_node_key = node_key.
if node_key = 'Child2'. "#EC NOTEXT
* add the children for node with key 'Child2'
* Node with key 'New3'
clear node.
node-node_key = 'New3'. "#EC NOTEXT
node-relatkey = 'Child2'.
node-relatship = cl_gui_list_tree=>relat_last_child.
append node to node_table.
*----------------------------------------------------------------------*
* INCLUDE Z_SALES_TREE_FORMS *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*& Form update_sel_screen_attributes
*&---------------------------------------------------------------------*
form update_sel_screen_attributes.
loop at screen.
if screen-group1 = 'SC1'.
screen-intensified = '1'.
modify screen.
endif.
if screen-group1 = 'ECR' and sy-tcode <> 'ZCMR'.
if not sy-tcode = 'ZCM'.
screen-invisible = '1'.
screen-active = '0'.
modify screen.
endif.
endif.
if screen-group1 = 'ECN' and sy-tcode <> 'ZCMN'.
if not sy-tcode = 'ZCM'.
screen-invisible = '1'.
screen-active = '0'.
modify screen.
endif.
endif.
if screen-group1 = 'ECO' and sy-tcode <> 'ZCMO'.
if not sy-tcode = 'ZCM'.
screen-invisible = '1'.
screen-active = '0'.
modify screen.
endif.
endif.
endloop.
endform. " update_sel_screen_attributes
*&---------------------------------------------------------------------*
*& Form create_and_init_tree
*&---------------------------------------------------------------------*
form create_and_init_tree.
data: node_table type treev_ntab,
item_table type item_table_type,
events type cntl_simple_events,
event type cntl_simple_event.
* create a container for the tree control
create object g_custom_container
exporting
" the container is linked to the custom control with the
" name 'TREE_CONTROL' on the dynpro
container_name = 'TREE_CONTROL'
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
if sy-subrc <> 0.
message a000(tree_control_msg).
endif.
* create a list tree control
create object g_tree
exporting
parent = g_custom_container
node_selection_mode = cl_gui_list_tree=>node_sel_mode_single
item_selection = 'X'
with_headers = ' '
exceptions
cntl_system_error = 1
create_error = 2
failed = 3
illegal_node_selection_mode = 4
lifetime_error = 5.
if sy-subrc <> 0.
message a000(tree_control_msg).
endif.
* define the events which will be passed to the backend
" node double click
event-eventid = cl_gui_list_tree=>eventid_node_double_click.
event-appl_event = 'X'. "
append event to events.
* assign event handlers in the application class to each desired event
set handler g_application->handle_node_double_click for g_tree.
set handler g_application->handle_item_double_click for g_tree.
set handler g_application->handle_expand_no_children for g_tree.
set handler g_application->handle_link_click for g_tree.
set handler g_application->handle_button_click for g_tree.
set handler g_application->handle_checkbox_change for g_tree.
* add some nodes to the tree control
* NOTE: the tree control does not store data at the backend. If an
* application wants to access tree data later, it must store the
* tree data itself.
perform build_node_and_item_table using node_table item_table.
endform. " create_and_init_tree
*&---------------------------------------------------------------------*
*& Form build_node_and_item_table
*&---------------------------------------------------------------------*
form build_node_and_item_table using
node_table type treev_ntab
item_table type item_table_type.
data: node type treev_node,
item type mtreeitm.
* Build the node and item table.
loop at itab_data into wa_data.
clear node.
endform. " build_node_and_item_table
*&---------------------------------------------------------------------*
*& Form create_input_table
*&---------------------------------------------------------------------*
form create_input_table tables p_itab_data like itab_data
p_itab_selection like itab_selection.
data: l_tabix like sy-tabix,
lm_tabix like sy-tabix,
begin of wl_data,
vbeln like vbfa-vbeln,
posnn like vbfa-posnn,
end of wl_data,
t_counter(4) type n,
t_parent(4) type c,
t_parent1(4) type c,
t_exit type flag,
is_del_data like line of itab_data,
it_inv_data type itab_type occurs 0.
* Find any deliveries for this order
loop at it_vbfa where vbtyp_n = 'J'. " Delivery
clear: wa_data.
wa_data-folder = 'X'.
wa_data-node_key = t_counter.
wa_data-relatkey = t_parent.
wa_data-type = it_vbfa-vbtyp_n.
wa_data-vbeln = it_vbfa-vbeln.
wa_data-posnn = it_vbfa-posnn.
wa_data-rfmng = it_vbfa-rfmng.
is_del_data = wa_data.
*
t_parent1 = t_counter.
add 1 to t_counter.
wa_vbelv = it_vbfa-vbeln.
wa_posnv = it_vbfa-posnn.
l_tabix = sy-tabix.
* Find any invoices Warehouse xfers or Goods Movements for this delivery
refresh: it_inv_data.
loop at it_vbfa where vbelv = wa_vbelv
and posnv = wa_posnv.
case it_vbfa-vbtyp_n.
when 'M'. "Invoice
clear: wa_data.
wa_data-folder = ' '.
wa_data-node_key = t_counter.
wa_data-relatkey = t_parent1.
wa_data-type = it_vbfa-vbtyp_n.
wa_data-vbeln = it_vbfa-vbeln.
wa_data-posnn = it_vbfa-posnn.
wa_data-rfmng = it_vbfa-rfmng.
wa_data-rfwrt = it_vbfa-rfwrt.
append wa_data to it_inv_data.
wj_vbelv = it_vbfa-vbeln.
wj_posnv = it_vbfa-posnn.
wa_nodekey = wa_data-node_key.
describe table it_inv_data lines lm_tabix.
add 1 to t_counter.
perform get_payment tables it_inv_data using t_counter.
perform get_returns tables it_inv_data using t_counter.
describe table it_inv_data lines l_tabix.
if l_tabix > lm_tabix.
read table it_inv_data index lm_tabix into wa_data.
wa_data-folder = 'X'.
modify it_inv_data index lm_tabix from wa_data.
endif.
when 'Q' or 'R'. " WMS transfer, or Goods Mvmt
clear: wa_data.
wa_data-folder = ' '.
wa_data-node_key = t_counter.
wa_data-relatkey = t_parent1.
wa_data-type = it_vbfa-vbtyp_n.
wa_data-vbeln = it_vbfa-vbeln.
wa_data-posnn = it_vbfa-posnn.
wa_data-rfmng = it_vbfa-rfmng.
append wa_data to it_inv_data.
add 1 to t_counter.
when others.
endcase.
endloop. " finding any matching invoices
if it_inv_data is initial.
is_del_data-folder = ' '.
endif.
append is_del_data to p_itab_data.
append lines of it_inv_data to p_itab_data.
refresh: it_inv_data.
endloop. " finding any deliveries
endloop.
clear: t_parent, t_parent1, t_exit.
endform. " create_input_table
*&---------------------------------------------------------------------*
*& Form update_selection_table
*&---------------------------------------------------------------------*
form update_selection_table tables itab_selection.
if not s_ernam is initial or
not s_erdat is initial or
not s_vbtyp is initial.
select: vbeln vbtyp into corresponding fields of
table itab_selection
from vbak
where erdat in s_erdat and
ernam in s_ernam and
vbtyp = s_vbtyp.
endif.
endform. " update_selection_table
*&---------------------------------------------------------------------*
*& Form get_payment
*&---------------------------------------------------------------------*
form get_payment tables it_inv_data using pt_counter .
loop at it_vbfa where vbelv = wj_vbelv
and posnv = wj_posnv
and vbtyp_n = '+'.
wa_data-folder = ' '.
wa_data-relatkey = wa_nodekey.
wa_data-node_key = pt_counter.
wa_data-type = it_vbfa-vbtyp_n.
wa_data-vbeln = it_vbfa-vbeln.
wa_data-posnn = it_vbfa-posnn.
wa_data-rfmng = it_vbfa-rfmng.
wa_data-rfwrt = it_vbfa-rfwrt.
append wa_data to it_inv_data.
add 1 to pt_counter.
endloop.
endform. " get_payment
*&---------------------------------------------------------------------*
*& Form get_returns
*&---------------------------------------------------------------------*
form get_returns tables it_inv_data using pt_counter .
data: ld_rfwrt(11) type c,
ld_tabix like sy-tabix.
loop at it_vbfa where vbelv = wj_vbelv
and posnv = wj_posnv
and vbtyp_n = 'H'.
ld_tabix = sy-tabix.
wa_data-folder = ' '.
wa_data-relatkey = wa_nodekey.
wa_data-node_key = pt_counter.
wa_data-type = it_vbfa-vbtyp_n.
wa_data-vbeln = it_vbfa-vbeln.
wa_data-posnn = it_vbfa-posnn.
wa_data-rfmng = it_vbfa-rfmng.
ld_rfwrt = it_vbfa-rfwrt.
concatenate ld_rfwrt '-' into ld_rfwrt.
wa_data-rfwrt = ld_rfwrt.
append wa_data to it_inv_data.
add 1 to pt_counter.
endloop.
endform.
*----------------------------------------------------------------------*
* INCLUDE Z_SALES_TREE_PBO *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_2000 output.
set pf-status 'Z_SALES_TREE_2000'.
set titlebar 'Z_SALES_TREE_2000'.
endmodule. " STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*& Module init_data_2000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module init_data_2000 output.
if g_tree is initial.
" The Tree Control has not been created yet.
" Create a Tree Control and insert nodes into it.
perform create_and_init_tree.
endif.
endmodule.
*----------------------------------------------------------------------*
* INCLUDE Z_SALES_TREE_RPT_TOP *
*----------------------------------------------------------------------*
* Table Definitions
tables: vbak, "Sales Document: Header Data
vbfa. "Sales Document Flow
* Type definitions
types: begin of itab_type,
folder type flag,
node_key type mtreeitm,
relatkey type tv_nodekey,
type like vbak-vbtyp,
vbeln like vbak-vbeln,
posnn like vbfa-posnn,
rfmng(10) type c,
rfwrt(12) type c,
end of itab_type.
types: begin of sel_type,
vbeln like vbak-vbeln,
vbtyp like vbak-vbtyp,
end of sel_type.
* Data Definitions
data: okcode like sy-ucomm,
itab_data type itab_type occurs 0,
itab_selection type sel_type occurs 0.
data: begin of it_vbfa occurs 0.
include structure vbfa.
data: end of it_vbfa,
is_vbfa like line of it_vbfa,
is_vbc06 like vbco6,
wa_vbelv like vbfa-vbelv,
wj_vbelv like vbfa-vbelv,
wa_posnv like vbfa-posnv,
wj_posnv like vbfa-posnv,
wa_nodekey type tv_nodekey,
t_screen(3) type c,
t_dynnr like sy-dynnr,
l_transcode like sy-tcode,
l_ok_zpcr(4) type c value 'MM01',
wa_data type itab_type.
* Tree list definitions
class lcl_application definition deferred.
class cl_gui_cfw definition load.
* CAUTION: MTREEITM is the name of the item structure which must
* be defined by the programmer. DO NOT USE MTREEITM!
types: item_table_type like standard table of mtreeitm
with default key.
data: g_application type ref to lcl_application,
g_custom_container type ref to cl_gui_custom_container,
g_tree type ref to cl_gui_list_tree,
g_ok_code type sy-ucomm.
*----------------------------------------------------------------------*
* INCLUDE Z_SALE_TREE_PAI *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_2000 input.
data: return_code type i.
* CL_GUI_CFW=>DISPATCH must be called if events are registered
* that trigger PAI
* this method calls the event handler method of an event
call method cl_gui_cfw=>dispatch
importing return_code = return_code.
if return_code <> cl_gui_cfw=>rc_noevent.
" a control event occured => exit PAI
clear okcode.
exit.
endif.
case okcode.
when 'EXIT' or 'RETURN'. " Finish program
if not g_custom_container is initial.
" destroy tree container (detroys contained tree control, too)
call method g_custom_container->free
exceptions
cntl_system_error = 1
cntl_error = 2.
if sy-subrc <> 0.
message a000(tree_control_msg).
endif.
clear g_custom_container.
clear g_tree.
endif.
leave to screen 0.
endcase.
clear okcode.
endmodule. " USER_COMMAND_2000 INPUT
* Screen 2000
process before output.
module status_2000.
module init_data_2000.
process after input.
module user_command_2000.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.