Pages

Monday, November 30, 2009

Docking container with events. my code

*& -–-------------------------------------------*
*& Title : Report for Garnishing Data (0194)
*& Author : Asinha
*& Description : Functional Description
*& Created : 21/07/2009
*& Modified : ModifiedDate
*& Modification History : Changes made to the code
*& Notes : Miscellaneous Comment (ifany)
*&----------------------------------------------*

REPORT ytestgarn2.
*Tables
TABLES: pernr,pa0194.

INFOTYPES : 0194 NAME gt_garn,
0000.

* Global Includes
INCLUDE ytestgarn2_top.


******************************
* Selection Screen *
******************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: p_orign FOR pa0194-orign OBLIGATORY DEFAULT 'AL',
p_gprio FOR pa0194-gprio.
SELECTION-SCREEN END OF BLOCK b1.

******************************
* At Selection Screen Events *
******************************

START-OF-SELECTION.

GET pernr.

LOOP AT gt_garn INTO wa_garn WHERE gprio IN p_gprio
AND orign IN p_orign.
IF sy-subrc = 0.

"move to final table
PERFORM get_data USING wa_garn CHANGING wa_outtab.
* gv_cnt_ma = gv_cnt_ma + 1.
* wa_outtab-num = gv_cnt_ma.
APPEND wa_outtab TO gt_outtab1.
CLEAR wa_outtab.

ENDIF.

ENDLOOP.


END-OF-SELECTION.

** For sumation of no. of records
* LOOP AT gt_outtab1 INTO wa_outtab.
* MOVE wa_outtab TO wa_outtab2.
* AT NEW jurs.
* gv_cnt_ma = gv_cnt_ma + 1.
* wa_outtab2-num = gv_cnt_ma.
* APPEND wa_outtab2 TO gt_outtab2.
* CLEAR wa_outtab2.
* ENDAT.
* ENDLOOP.

IF gt_outtab1 IS NOT INITIAL.
PERFORM fcat_build.
PERFORM alv_tree_display.
ELSE.
MESSAGE 'No data to display' TYPE 'I'.
ENDIF.


*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_GARN text
* <--P_WA_OUTTAB text
*----------------------------------------------------------------------*
FORM get_data USING p_wa_garn TYPE p0194
CHANGING p_wa_outtab TYPE ty_outtab.

p_wa_outtab-pernr = p_wa_garn-pernr.
p_wa_outtab-jurs = p_wa_garn-orign.
p_wa_outtab-case_no = p_wa_garn-gcase.
p_wa_outtab-prio = p_wa_garn-gprio.
p_wa_outtab-status = p_wa_garn-gstat.
p_wa_outtab-type = p_wa_garn-orcod.
p_wa_outtab-org_name = p_wa_garn-ornam.
p_wa_outtab-org_city = p_wa_garn-orort.
p_wa_outtab-org_zip = p_wa_garn-orplz.
p_wa_outtab-org_info = p_wa_garn-rulnr.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form alv_tree_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_tree_display .

CALL SCREEN 0001.

ENDFORM. " alv_tree_display
*&---------------------------------------------------------------------*
*& Module STATUS_0001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0001 OUTPUT.
SET PF-STATUS 'PF_STATUS'.
* SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0001 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0001 INPUT.

CASE sy-ucomm.
WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
* §5. Call dispatch to process toolbar functions
* Toolbar events are registered in constructur method of
* CL_ALV_TREE_BASE as application events. So the dispatch call
* is a must if you want to use the standard toolbar.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.

ENDMODULE. " USER_COMMAND_0001 INPUT
*&---------------------------------------------------------------------*
*& Module ALV_CALL OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE alv_call OUTPUT.
* Perform ALV Tree build
IF g_alv_tree IS INITIAL.
PERFORM init_tree.

CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Automation Queue failure'(801)
txt1 = 'Internal error:'(802)
txt2 = 'A method in the automation queue'(803)
txt3 = 'caused a failure.'(804).
ENDIF.
ENDIF.


ENDMODULE. " ALV_CALL OUTPUT
*&---------------------------------------------------------------------*
*& Form init_tree
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_tree .

DATA: l_tree_container_name(30) TYPE c.
DATA:g_conatiner TYPE REF TO cl_gui_custom_container.
l_tree_container_name = 'CC_CONTAINER'.

CREATE OBJECT g_custom_container
EXPORTING
ratio = 95.

* CREATE OBJECT g_custom_container
* EXPORTING
* container_name = l_tree_container_name
* EXCEPTIONS
* cntl_error = 1
* cntl_system_error = 2
* create_error = 3
* lifetime_error = 4
* lifetime_dynpro_dynpro_link = 5.
* IF sy-subrc <> 0.
* MESSAGE x208(00) WITH 'ERROR'(100).
* ENDIF.

* create tree control
CREATE OBJECT g_alv_tree
EXPORTING
parent = g_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
* no_html_header = 'X'
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.


* §2. Create Hierarchy-header
* The simple ALV Tree uses the text of the fields which were used
* for sorting to define this header. When you use
* the 'normal' ALV Tree the hierarchy is build up freely
* by the programmer this is not possible, so he has to define it
* himself.
DATA lv_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING lv_hierarchy_header.
* §3. Create empty Tree Control
* IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
* (even after this method call). You can change data of your table
* by calling methods of CL_GUI_ALV_TREE.
* Furthermore, the output table 'gt_outtab' must be global and can
* only be used for one ALV Tree Control.

DATA: o_event TYPE REF TO lcl_event_receiver.

PERFORM set_headings CHANGING gt_header.

CALL METHOD g_alv_tree->set_table_for_first_display
EXPORTING
* I_STRUCTURE_NAME =
it_list_commentary = gt_header
is_hierarchy_header = lv_hierarchy_header
CHANGING
it_outtab = gt_empty "table must be empty !
it_fieldcatalog = gt_fcat
.


*CALL METHOD g_alv_tree->create_report_header
* EXPORTING
* it_list_commentary = gt_header
** I_LOGO =
** I_BACKGROUND_ID =
** I_SET_SPLITTER_HEIGHT =
** I_MODEL_MODE =
* .


* call method g_alv_tree->set_table_for_first_display
* exporting
* i_structure_name = 'YDBGARN'
* is_hierarchy_header = l_hierarchy_header
* changing
* it_outtab = gt_YDBGARN. "table must be empty !


* §4. Create hierarchy (nodes and leaves)
PERFORM create_hierarchy.

* §5. Send data to frontend.
CALL METHOD g_alv_tree->frontend_update.

ENDFORM. " init_tree
*&---------------------------------------------------------------------*
*& Form build_hierarchy_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_L_HIERARCHY_HEADER text
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING p_l_hierarchy_header
TYPE treev_hhdr.

p_l_hierarchy_header-heading = 'Jurisdiction/Personnel Number'(300).
p_l_hierarchy_header-tooltip = 'PERNR per Jurisdiction'(400).
p_l_hierarchy_header-width = 30.
p_l_hierarchy_header-width_pix = ' '.

ENDFORM. " build_hierarchy_header
*&---------------------------------------------------------------------*
*& Form create_hierarchy
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_hierarchy .

DATA: lv_jur_key TYPE lvc_nkey,
lv_pernr_key TYPE lvc_nkey,
lv_case_key TYPE lvc_nkey,
lv_count TYPE i .
data: lv_wa_outtab type ty_outtab.

sort gt_outtab1 stable by jurs.

LOOP AT gt_outtab1 INTO wa_outtab.

* to hold values for At end operation
move wa_outtab to lv_wa_outtab.

* Top level nodes:
* Jurisdiction node
IF wa_outtab-jurs <> gv_jurs_last. "on change of Jurisdiction
gv_jurs_last = wa_outtab-jurs.

*Providing no key means that the node is added on top level:
PERFORM add_jurs USING wa_outtab
''
CHANGING lv_jur_key.
lv_count = 1.

ELSE.
lv_count = lv_count + 1.

ENDIF.

* PERNR nodes:
* (always inserted as child of the last Jurisdiction
* which is identified by 'lv_jur_key')
IF wa_outtab-pernr <> gv_pernr_last. "on change of PERNR
gv_pernr_last = wa_outtab-pernr.
PERFORM add_pernr_line USING wa_outtab
lv_jur_key
CHANGING lv_pernr_key.
ENDIF.

at END OF jurs.

PERFORM add_cases USING lv_count
lv_wa_outtab
lv_jur_key
CHANGING lv_case_key.
endat.

ENDLOOP.

ENDFORM. " create_hierarchy
*&---------------------------------------------------------------------*
*& Form add_jurs
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_OUTTAB_JURS text
* -->P_0381 text
* <--P_LV_JUR_KEY text
*----------------------------------------------------------------------*
FORM add_jurs USING p_wa_outtab TYPE ty_outtab
p_relat_key
CHANGING p_node_key.

DATA: lv_node_text TYPE lvc_value.

lv_node_text = p_wa_outtab-jurs.
* add node:
* ALV Tree firstly inserts this node as a leaf if you do not provide
* IS_NODE_LAYOUT with field ISFOLDER set. In form 'add_carrid_line'
* the leaf gets a child and thus ALV converts it to a folder
* automatically.
*

CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = lv_node_text
is_outtab_line = wa_empty "pass empty since top node should
IMPORTING
e_new_node_key = p_node_key. "not show data



ENDFORM. " add_jurs
*&---------------------------------------------------------------------*
*& Form add_pernr_line
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_OUTTAB text
* -->P_LV_JUR_KEY text
* <--P_LV_PERNR_KEY text
*----------------------------------------------------------------------*
FORM add_pernr_line USING p_wa_outtab TYPE ty_outtab
p_relat_key
CHANGING p_node_key.

DATA: l_node_text TYPE lvc_value.
data: lwa_layout type LVC_S_LAYN.

* add node
* ALV Tree firstly inserts this node as a leaf if you do not provide
* IS_NODE_LAYOUT with field ISFOLDER set. In form 'add_carrid_line'
* the leaf gets a child and thus ALV converts it to a folder
* automatically.
*
l_node_text = p_wa_outtab-pernr.

PERFORM person_node_layout CHANGING lwa_layout.

CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = p_wa_outtab
IS_NODE_LAYOUT = lwa_layout
IMPORTING
e_new_node_key = p_node_key.


ENDFORM. " add_pernr_line

*&---------------------------------------------------------------------*
*& Form add_cases
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_OUTTAB text
* -->P_LV_JUR_KEY text
* <--P_LV_PERNR_KEY text
*----------------------------------------------------------------------*
FORM add_cases USING p_lv_count
p_wa_outtab TYPE ty_outtab
p_lv_jur_key
CHANGING p_lv_case_key.

DATA: l_node_text TYPE lvc_value,
lv_leaf TYPE string,
lv_jurs TYPE string,
lv_cnt_leaf TYPE string.
data: lwa_layout type LVC_S_LAYN,
lt_item_layout type LVC_T_LAYI,
lwa_item_layout type LVC_S_LAYI.
* add node
* ALV Tree firstly inserts this node as a leaf if you do not provide
* IS_NODE_LAYOUT with field ISFOLDER set. In form 'add_cases'
* the leaf gets a child and thus ALV converts it to a folder
* automatically.
MOVE p_lv_count TO lv_cnt_leaf.
MOVE p_wa_outtab-jurs TO lv_jurs.
CLEAR p_wa_outtab.
CONCATENATE 'No. of cases under' lv_jurs
'is:'lv_cnt_leaf INTO lv_leaf
SEPARATED BY space.
p_wa_outtab-case_no = lv_leaf.

l_node_text = 'Summation'.

PERFORM sum_node_layout CHANGING lwa_layout.

CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_lv_jur_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = p_wa_outtab
IS_NODE_LAYOUT = lwa_layout
* IT_ITEM_LAYOUT = lt_item_layout
IMPORTING
e_new_node_key = p_lv_case_key.


ENDFORM. " add_cases

*&---------------------------------------------------------------------*
*& Form node_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LWA_LAYOUT text
*----------------------------------------------------------------------*
form sum_node_layout changing p_lwa_layout type LVC_S_LAYN.

p_lwa_layout-STYLE = cl_gui_column_tree=>style_intensifd_critical.
p_lwa_layout-n_image = icon_sum.


endform. " node_layout

*&---------------------------------------------------------------------*
*& Form person_node_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LWA_LAYOUT text
*----------------------------------------------------------------------*
form person_node_layout changing p_lwa_layout type LVC_S_LAYN.

p_lwa_layout-STYLE = cl_gui_column_tree=>STYLE_INTENSIFIED.
p_lwa_layout-n_image = icon_manager.

endform. " person_node_layout


*&---------------------------------------------------------------------*
*& Form fcat_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fcat_build .

CONSTANTS: lc_final TYPE string VALUE 'GT_OUTTAB1'.

wa_fcat-fieldname = 'PERNR'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Personnel Number'.
wa_fcat-col_pos = 1.
wa_fcat-no_merging = 'X'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'JURS'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Jurisdiction'.
wa_fcat-col_pos = 2.
wa_fcat-no_merging = 'X'.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'CASE_NO'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'CASE NUM'.
wa_fcat-col_pos = 3.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'PRIO'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Priority'.
wa_fcat-col_pos = 4.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'STATUS'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Garnishment Status '.
wa_fcat-col_pos = 5.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'TYPE'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Garnishment Originator Type'.
wa_fcat-col_pos = 6.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'ORG_NAME'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Garnishment Originator Name'.
wa_fcat-col_pos = 7.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'ORG_CITY'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Garnishment Originator City'.
wa_fcat-col_pos = 8.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'ORG_ZIP'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Garnishment Originator Zip'.
wa_fcat-col_pos = 9.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'ORG_INFO'.
wa_fcat-tabname = lc_final.
wa_fcat-coltext = 'Garnishment Remittance Info'.
wa_fcat-col_pos = 9.
APPEND wa_fcat TO gt_fcat.
CLEAR wa_fcat.
ENDFORM. " fcat_build
*&---------------------------------------------------------------------*
*& Form set_headings
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_HEADER text
*----------------------------------------------------------------------*
FORM set_headings CHANGING p_gt_header LIKE gt_header.

wa_header-typ = 'H'.
wa_header-key = ''.
wa_header-info = 'Garnishments Information Report'.
APPEND wa_header TO p_gt_header.

wa_header-typ = 'S'.
wa_header-key = ''.
wa_header-info = sy-uname.
APPEND wa_header TO p_gt_header.

wa_header-typ = 'S'.
wa_header-key = ''.
wa_header-info = sy-datum.
APPEND wa_header TO p_gt_header.

ENDFORM. " set_headings






*&---------------------------------------------------------------------*
*& Include YTESTGARN2_TOP
*&---------------------------------------------------------------------*

* Global Types

TYPES: BEGIN OF ty_outtab,
jurs TYPE char3,
pernr TYPE char8,
num TYPE i,
case_no TYPE char35,
prio TYPE char3,
status TYPE char1,
type TYPE char1,
org_name TYPE char30,
org_city TYPE char30,
org_zip TYPE char10,
org_info TYPE char5,
END OF ty_outtab.
TYPES: BEGIN OF ty_empty,
empty TYPE string,
END OF ty_empty.

* Global Internal tables
DATA: gt_outtab1 TYPE STANDARD TABLE OF ty_outtab,
gt_outtab2 TYPE STANDARD TABLE OF ty_outtab,
wa_outtab TYPE ty_outtab,
wa_outtab2 TYPE ty_outtab,
wa_garn TYPE p0194.
DATA: gt_empty TYPE STANDARD TABLE OF ty_outtab,
wa_empty TYPE ty_outtab,
gt_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat,
gt_fcat1 TYPE lvc_t_fcat, "created for empty tables
wa_fcat1 TYPE lvc_s_fcat. "created for empty tables

* Global variables
DATA: gv_cnt_ma TYPE i, " Counter for MA ecords
gv_cnt_il TYPE i. " Counter for IL ecords
DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree,
g_custom_container TYPE REF TO cl_gui_docking_container.
* g_custom_container type ref to cl_gui_custom_container.

DATA:w_toolbar TYPE stb_button."For toolbar
DATA: gt_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader.
* Global Constants
CONSTANTS: gc_ma TYPE char2 VALUE 'MA',
gc_il TYPE char2 VALUE 'IL'.

DATA: gv_jurs_last TYPE char3,
gv_pernr_last TYPE char8.
*
* Global Class declaration
CLASS lcl_event_receiver DEFINITION.
* event receiver definitions for ALV actions
PUBLIC SECTION.
METHODS:
* Node double click
handle_node_double_click
FOR EVENT node_double_click OF cl_gui_alv_tree
IMPORTING NODE_KEY,
* Tool bar
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
* Status bar
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_receiver DEFINITION

* Global Class implementation

CLASS lcl_event_receiver IMPLEMENTATION.
* Create the relevant Text to be dispalyed at top of page
METHOD handle_node_double_click.
check node_key is not initial.
PERFORM node_click CHANGING NODE_KEY wa_outtab.
ENDMETHOD. "handle_top_of_page
* create the relevant buttons on the toolbars
METHOD handle_toolbar.
* This method handles the user interaction with the tool bar.
* PERFORM toolbar.
APPEND w_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
* In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
PERFORM user_command USING e_ucomm.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_receiver IMPLEMENTATION

No comments:

Post a Comment