Você está na página 1de 6

*&---------------------------------------------------------------------*

*& Report ZOBJECT_SPLITTER_TREE_EVENT


*&
*&---------------------------------------------------------------------*
*& A Demo program which explains the scenario of creating a splitter
*& container and display a tree structure in one container and display
*& the results of the node selected upon a double click action.
*&---------------------------------------------------------------------*

REPORT ZOBJECT_SPLITTER_TREE_EVENT.

Tables: vbak,vbap,vbfa.

*&---------------------------------------------------------------------*
*& Structures and Table Declarations
*&---------------------------------------------------------------------*
Data: ls_vbak type vbak,
lt_vbak type table of vbak,
ls_vbap type vbap,
lt_vbap type table of vbap.

Types: begin of ty_vbfa,


vbelv type vbfa-vbelv, "Preceding SD Document
posnv type vbfa-posnv, "Preceding SD Document Item Number
vbeln type vbfa-vbeln, "Subsequent SD Document
posnn type vbfa-posnn, "Subsequent SD Document Item Number
vbtyp_n type vbfa-vbtyp_n, "Subsequent Document Category
vbtyp_v type vbfa-vbtyp_v, "Preceding Document Category
end of ty_vbfa.

Data: ls_vbfa type ty_vbfa,


lt_vbfa type table of ty_vbfa.

Data: ls_vbfa_copy type ty_vbfa,


lt_vbfa_copy type table of ty_vbfa.

Types: begin of ty_vbak,


vbeln type vbak-vbeln, "Contract Number
audat type vbak-audat, "Document Date
ernam type vbak-ernam, "Name of Person who Created the Object
auart type vbak-auart, "Sales Document Type
end of ty_vbak.

Data: ls_vbak_cont type ty_vbak,


lt_vbak_cont type table of ty_vbak.
*&---------------------------------------------------------------------*
*& Type Reference of Various Classes
*&---------------------------------------------------------------------*
Data: ref_split type ref to cl_gui_splitter_container,
ref_cust type ref to cl_gui_custom_container,
ref_alv1 type ref to cl_gui_alv_grid,
ref_alv2 type ref to cl_gui_alv_grid,
ref_cont1 type ref to cl_gui_container,
ref_cont2 type ref to cl_gui_container.
Data: ref_tree type ref to cl_simple_tree_model.
*&---------------------------------------------------------------------*
*& Event Class
*&---------------------------------------------------------------------*
class lcl_event_handler definition.
public section.
methods: node_dc for event node_double_click of cl_simple_tree_model
importing node_key sender.
endclass.

class lcl_event_handler implementation.


method: node_dc.

Data: lt_children type tm_nodekey,


v_so type vbeln,
v_item type posnr.

Data: ls_layout type lvc_s_layo.

CALL METHOD SENDER->NODE_GET_LAST_CHILD


EXPORTING
NODE_KEY = node_key
IMPORTING
CHILD_NODE_KEY = lt_children.

if lt_children is not initial.


CALL METHOD SENDER->EXPAND_NODE
EXPORTING
NODE_KEY = node_key
LEVEL_COUNT = 2.
endif.

split node_key at space into v_so v_item.

refresh: lt_vbap.

select * from vbap


into table lt_vbap
where vbeln = v_so.

if sy-subrc = 0.

ls_layout-grid_title = text-002.
ls_layout-zebra = 'X'.
ls_layout-smalltitle = ''.
ls_layout-cwidth_opt = 'X'.

CALL METHOD REF_ALV2->SET_TABLE_FOR_FIRST_DISPLAY


EXPORTING
I_STRUCTURE_NAME = 'VBAP'
IS_LAYOUT = ls_layout
CHANGING
IT_OUTTAB = lt_vbap.

CALL METHOD REF_ALV2->REFRESH_TABLE_DISPLAY.

endif.

endmethod.
endclass.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
selection-screen: begin of block b1 with frame title text-001.
select-options: s_vbeln for vbak-vbeln, "Document Number
s_audat for vbak-audat, "Document Date
s_ernam for vbak-ernam. "Name who Created the Object
selection-screen: end of block b1.
*&---------------------------------------------------------------------*
*& Start Of Selection
*&---------------------------------------------------------------------*
start-of-selection.
perform Get_Data.

call screen 0100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* Default PBO module
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT


*&---------------------------------------------------------------------*
*& Module OBJECT_CREATION OUTPUT
*&---------------------------------------------------------------------*
* Object Creation for Classes
*----------------------------------------------------------------------*
MODULE OBJECT_CREATION OUTPUT.

CREATE OBJECT REF_CUST


EXPORTING
CONTAINER_NAME = 'SPLIT_CONT'.

CREATE OBJECT REF_SPLIT


EXPORTING
PARENT = ref_cust
ROWS = 1
COLUMNS = 2.

CALL METHOD REF_SPLIT->GET_CONTAINER


EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = ref_cont1.

CALL METHOD REF_SPLIT->SET_COLUMN_WIDTH


EXPORTING
ID = 1
WIDTH = 22.

CALL METHOD REF_SPLIT->GET_CONTAINER


EXPORTING
ROW = 1
COLUMN = 2
RECEIVING
CONTAINER = ref_cont2.

CREATE OBJECT REF_TREE


EXPORTING
NODE_SELECTION_MODE = cl_simple_tree_model=>node_sel_mode_single.

CALL METHOD REF_TREE->CREATE_TREE_CONTROL


EXPORTING
PARENT = ref_cont1.

CREATE OBJECT REF_ALV2


EXPORTING
I_PARENT = ref_cont2.

ENDMODULE. " OBJECT_CREATION OUTPUT


*&---------------------------------------------------------------------*
*& Module PROCESSING_OUTPUT OUTPUT
*&---------------------------------------------------------------------*
* Processing Output of the Table
*----------------------------------------------------------------------*
MODULE PROCESSING_OUTPUT OUTPUT.

Data: ls_node type treemsnodt.

CALL METHOD REF_TREE->ADD_NODE


EXPORTING
NODE_KEY = 'ROOT'
ISFOLDER = 'X'
TEXT = 'Orders'
EXPANDER = 'X'.

loop at lt_vbak into ls_vbak.

ls_node-node_key = ls_vbak-vbeln.

concatenate 'Sales Order#' ':' ls_vbak-vbeln


into ls_node-text
separated by space.

CALL METHOD REF_TREE->ADD_NODE


EXPORTING
NODE_KEY = ls_node-node_key
RELATIVE_NODE_KEY = 'ROOT'
RELATIONSHIP = cl_simple_tree_model=>relat_last_child
ISFOLDER = 'X'
TEXT = ls_node-text
EXPANDER = 'X'.

endloop.

loop at lt_vbap into ls_vbap.

concatenate ls_vbap-vbeln ls_vbap-posnr


into ls_node-node_key
separated by space.

ls_node-relatkey = ls_vbap-vbeln.
concatenate ls_vbap-posnr ls_vbap-matnr
into ls_node-text
separated by space.

CALL METHOD REF_TREE->ADD_NODE


EXPORTING
NODE_KEY = ls_node-node_key
RELATIVE_NODE_KEY = ls_node-relatkey
RELATIONSHIP = cl_simple_tree_model=>relat_last_child
ISFOLDER = ''
TEXT = ls_node-text
EXPANDER = ''.

endloop.

ENDMODULE. " PROCESSING_OUTPUT OUTPUT


*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'E' OR 'ENDE' OR 'ECAN'.
leave to screen 0.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module EVENT_REGISTRATION OUTPUT
*&---------------------------------------------------------------------*
* Double Click Event Registration
*----------------------------------------------------------------------*
MODULE EVENT_REGISTRATION OUTPUT.
Data: lt_events type cntl_simple_events,
ls_event type cntl_simple_event.

Data: event_handler type ref to lcl_event_handler.

CALL METHOD REF_TREE->GET_REGISTERED_EVENTS


IMPORTING
EVENTS = lt_events.

ls_event-eventid = cl_simple_tree_model=>eventid_node_double_click.
append ls_event to lt_events.

CALL METHOD REF_TREE->SET_REGISTERED_EVENTS


EXPORTING
EVENTS = lt_events.

create object event_handler.


set handler event_handler->node_dc for ref_tree.

ENDMODULE. " EVENT_REGISTRATION OUTPUT


*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* Get All the display relevant Data for Tree Structure
*----------------------------------------------------------------------*
FORM GET_DATA .

select vbeln audat ernam auart


from vbak
into table lt_vbak_cont
where vbeln in s_vbeln and
audat in s_audat and
ernam in s_ernam.

if sy-subrc <> 0.
message E001(ZMSG) with 'No Record Found' display like 'I'.
elseif sy-subrc = 0.

select vbelv posnv vbeln posnn vbtyp_n vbtyp_v


from vbfa
into table lt_vbfa
for all entries in lt_vbak_cont
where vbelv = lt_vbak_cont-vbeln and
vbtyp_n = 'C' and
vbtyp_v = 'G'.

if lt_vbfa is initial.
message E002(ZMSG) with 'No Subsequent Record Found' display like 'I'.
else.
select * from vbak
into table lt_vbak
for all entries in lt_vbfa
where vbeln = lt_vbfa-vbeln.

select * from vbap


into table lt_vbap
for all entries in lt_vbak
where vbeln = lt_vbak-vbeln.

endif.
endif.

ENDFORM. " GET_DATA

Você também pode gostar