You are on page 1of 12

er_data_changed

e_onf4
e_onf4_before
e_onf4_after
e_ucomm
sender.

=========================================================================
*&---------------------------------------------------------------------*
*& Include ZMM_QA_LOGBOOK_DD
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Include ZMM_QA_LOGBOOK_DD
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Type Group *
*----------------------------------------------------------------------*
type-pools : slis.

*----------------------------------------------------------------------*
* Declaration of Tables *
*----------------------------------------------------------------------*
tables : ztb_qa_logbook.

*----------------------------------------------------------------------*
* Declaration of Internal table *
*----------------------------------------------------------------------*
* Internal table for output data ...
data : begin of it_output occurs 0.
include structure ztb_qa_logbook.
data : end of it_output.

data : it_outut_temp like table of it_output.

*----------------------------------------------------------------------*
* Declaration of Work area *
*----------------------------------------------------------------------*
data : wa_output like line of it_output.

*----------------------------------------------------------------------*
* Declaration ALV variable data *
*----------------------------------------------------------------------*
data : ok_code like sy-ucomm,
save_ok like sy-ucomm,
gd_code like sy-ucomm,
gd_container type scrfname value 'QA_CONTAINER',
gt_fieldcat type lvc_t_fcat,
wa_fieldcat type lvc_s_fcat,
gd_layout type lvc_s_layo,
gd_grid type ref to cl_gui_alv_grid,
gd_custom_container type ref to cl_gui_custom_container.

*----------------------------------------------------------------------*
* Ranges *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Constants *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Local class declaration
*----------------------------------------------------------------------*
class lcl_event_receiver definition deferred.
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
class lcl_event_receiver definition.

public section.
methods on_hotspot_click
for event hotspot_click of cl_gui_alv_grid
importing e_row_id
e_column_id
es_row_no.
methods add_button
for event toolbar of cl_gui_alv_grid
importing e_object
e_interactive.

methods handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm.

methods handle_data_changed
for event data_changed of cl_gui_alv_grid
importing er_data_changed
e_onf4
e_onf4_before
e_onf4_after
e_ucomm
sender.

* MEthods DISPLAY_PROTOCOL

private section.

endclass. "lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
class lcl_event_receiver implementation.

method on_hotspot_click.
clear : wa_output.
data : ls_col_id type lvc_s_col.
read table it_output into wa_output
index e_row_id-index.
if sy-subrc eq 0.
if e_column_id-fieldname eq 'MATNR'.
set parameter id 'MAT' field wa_output-matnr.
call transaction 'MM03' and skip first screen.
endif. " IF e_column_id-fieldname EQ 'VBELN'.
endif. " IF sy-subrc EQ 0.READ TABLE it_sale_head INTO wa_sale_head
endmethod. "on_hotspot_click

method add_button.
data : ls_toolbar type stb_button.
clear ls_toolbar.

* ls_toolbar-function = 'ITEM'.
* ls_toolbar-icon = 'ICON_DISPLAY'.
* ls_toolbar-butn_type = '0'.
* ls_toolbar-text = 'Item deails'.
* APPEND ls_toolbar TO e_object->mt_toolbar.

endmethod. "add_button

method handle_user_command.
data : lt_rows type lvc_t_row.
refresh : lt_rows[].
case e_ucomm.
when 'SAVE'.

call method gd_grid->get_selected_rows


importing
et_index_rows = lt_rows
* et_row_no =
.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
if lt_rows[] is not initial.
* PERFORM display_item_details TABLES lt_rows.
else.
message s005(zpkpr) display like 'E'.
* please select atleast one row
endif. "IF lt_rows[] IS NOT INITIAL.
endif. " IF sy-subrc <> 0.
endcase . " CASE e_ucomm.

endmethod. "handle_user_command

* Handle Data Changed


method handle_data_changed .
data : lt_rows type lvc_t_row.
refresh : lt_rows[].
case e_ucomm.
when 'SAVE'.
*
* CALL METHOD gd_grid->get_selected_rows
* IMPORTING
* et_index_rows = lt_rows
** et_row_no =
* .

when others.
endcase.

endmethod. "handle_data_changed

endclass. "lcl_event_receiver IMPLEMENTATION

data : gd_event_receiver type ref to lcl_event_receiver.

===================================================================================
=
*&---------------------------------------------------------------------*
*& Include ZMM_QA_LOGBOOK_SR
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Include ZMM_QA_LOGBOOK_SR
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status 'MENU_0100'.
set titlebar 'TITLE_0100'.

if gd_custom_container is initial.
data : it_output_temp like table of it_output.
* Create a custom container control for alv grid (For that we have to
* pass the container name that created in the 0100 screen)
create object gd_custom_container
exporting
* parent =
container_name = gd_container
* style =
* lifetime = lifetime_default
* repid =
* dynnr =
* no_autodef_progid_dynnr =
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* Create instance for grid (For that we have to pass the custom
* container as parent object) i.e the the grid object will refer the
* custom container
create object gd_grid
exporting
* i_shellstyle = 0
* i_lifetime =
i_parent = gd_custom_container
* i_appl_events = space
* i_parentdbg =
* i_applogparent =
* i_graphicsparent =
* i_name =
* i_fcat_complete = space
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

perform build_fieldcatlog.
* Fill the layout details
gd_layout-grid_title = 'ZADF'.
gd_layout-zebra = 'X'.
gd_layout-sel_mode = 'A'.
* gd_layout-cwidth_opt = 'X'.

* Define a drop down table.


perform set_drdn_table.

create object gd_event_receiver.


set handler gd_event_receiver->on_hotspot_click for gd_grid.
set handler gd_event_receiver->add_button for gd_grid.
set handler gd_event_receiver->handle_user_command for gd_grid.
* set handler gd_event_receiver->handle_data_changed for gd_grid.

it_output_temp[] = it_output[].
* This methos is used for display the output details.
call method gd_grid->set_table_for_first_display
exporting
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
i_structure_name = 'IT_OUTPUT'
* is_variant =
* i_save =
* i_default = 'X'
is_layout = gd_layout
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
changing
it_outtab = it_output[]
it_fieldcatalog = gt_fieldcat
* it_sort =
* it_filter =
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

* Set editable cells to ready for input initially


call method gd_grid->set_ready_for_input
exporting
i_ready_for_input = 1.

call method gd_grid->register_edit_event


exporting
i_event_id = cl_gui_alv_grid=>mc_evt_modified
exceptions
error = 1
others = 2.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno


with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

set handler gd_event_receiver->handle_data_changed for gd_grid.

endif. "IF gd_custom_container IS INITIAL.

endmodule. " STATUS_0100 OUTPUT


*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_fieldcatlog .
* Build field catalog
call function 'LVC_FIELDCATALOG_MERGE'
exporting
* I_BUFFER_ACTIVE =
i_structure_name = 'ZTB_QA_LOGBOOK'
* i_structure_name = 'TY_OUT'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
i_internal_tabname = 'IT_OUTPUT'
changing
ct_fieldcat = gt_fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
loop at gt_fieldcat into wa_fieldcat.
case wa_fieldcat-fieldname.
when 'MATNR'.
wa_fieldcat-hotspot = 'X'.
when 'MENGE'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-checktable = '!'.

when 'MEINS'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-checktable = '!'.

when 'ZBINL'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-checktable = '!'.

when 'HSDAT'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-checktable = '!'.

when 'ZEDATE'.
wa_fieldcat-edit = 'X'.

when 'ZMAT_STA'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-drdn_hndl = '1'.
wa_fieldcat-drdn_alias = 'X'.
wa_fieldcat-checktable = '!'.
wa_fieldcat-outputlen = 15.
when 'ZREASON'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-drdn_hndl = '2'.
wa_fieldcat-drdn_alias = 'X'.
wa_fieldcat-outputlen = 15.
when 'ZDESPOSTN'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-drdn_hndl = '3'.
wa_fieldcat-drdn_alias = 'X'.
wa_fieldcat-outputlen = 15.
when 'REMARK'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-outputlen = 30.

when others.
endcase.
modify gt_fieldcat from wa_fieldcat.
endloop. " LOOP AT it_fieldcat INTO wa_fieldcat.
endif. " IF sy-subrc <> 0.

endform. " BUILD_FIELDCATLOG


*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .

select *
from ztb_qa_logbook
into table it_output
where werks eq p_werks
and matnr eq p_matnr
and charg eq p_charg
and menge eq p_menge
and zmat_sta eq p_zmat_s.

endform. " GET_DATA


*&---------------------------------------------------------------------*
*& Form FILL_OUTPUT_TB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fill_output_tb .

endform. " FILL_OUTPUT_TB


*&---------------------------------------------------------------------*
*& Form FILL_OUTPUT_SS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fill_output_ss .
it_output-werks = p_werks .
it_output-matnr = p_matnr .
it_output-charg = p_charg .
it_output-menge = p_menge .
it_output-zmat_sta = p_zmat_s .

append it_output.
endform. " FILL_OUTPUT_SS
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module exit input.
leave program.
endmodule. " EXIT INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0100 input.
clear : gd_code.
gd_code = ok_code.

data : lt_rows type lvc_t_row .


data : lv_valid type c ,
lv_lines type i.
refresh : lt_rows[].

data : gd_obj_container type ref to cl_gui_container,


lr_alv type ref to cl_gui_alv_grid.

case gd_code.
when 'BACK' or 'CANC'.
leave to screen 0.

when 'SAVE'.

call method gd_grid->check_changed_data


* IMPORTING
* e_valid = lv_valid
changing
c_refresh = lv_valid.

if lv_valid eq 'X'.

endif. "IF lv_valid eq 'X'.

call method gd_grid->get_selected_rows


importing
et_index_rows = lt_rows
* et_row_no =
.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
if lt_rows[] is not initial.
describe table lt_rows lines lv_lines.
if lv_lines eq 1 .
perform display_item_details tables lt_rows
it_output_temp.
else.
message s006(zdeep) display like 'E'.
endif."IF sy-subrc eq 0 .
else.
message s007(zdeep) display like 'E'.
* please select atleast one row
endif. "IF lt_rows[] IS NOT INITIAL.
endif. " IF sy-subrc <> 0.

endcase. " CASE gd_ok_code.

endmodule. " USER_COMMAND_0100 INPUT


*&---------------------------------------------------------------------*
*& Form SET_DRDN_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form set_drdn_table .
data: lt_dropdown type lvc_t_drop,
lt_dropdown_alias type lvc_t_dral.
* ls_dropdown type lvc_s_drop. "declared in perform fill_lt_dropdown

data : lt_tab_a type table of dd07v.

*Getting list values for Field ZMAT_STA from its domain


perform get_domain_values using 'ZMAT_STATUS'
changing lt_tab_a.
* First listbox (handle '1')for field ZMAT_STA.
* we are using this handle in modifying fiedcatlog properties
perform fill_lt_dropdown_alias using '1'
lt_tab_a
changing lt_dropdown_alias.

**Getting list values for Field ZREASON from its domain


perform get_domain_values using 'ZQA_REASON'
changing lt_tab_a.
* First listbox (handle '2')for field ZMAT_STA.
perform fill_lt_dropdown_alias using '2'
lt_tab_a
changing lt_dropdown_alias.

**Getting list values for Field ZREASON from its domain


perform get_domain_values using 'ZDESPOSTN'
changing lt_tab_a.
* First listbox (handle '3')for field ZDESPOSTN.
perform fill_lt_dropdown_alias using '3'
lt_tab_a
changing lt_dropdown_alias.

call method gd_grid->set_drop_down_table


* exporting it_drop_down = lt_dropdown.
exporting it_drop_down_alias = lt_dropdown_alias.

endform. " SET_DRDN_TABLE


*&---------------------------------------------------------------------*
*& Form GET_DOMAIN_VALUES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0422 text
* <--P_LT_TAB_A text
*----------------------------------------------------------------------*
form get_domain_values using p_dom_name
changing p_lt_tab_a type standard table.

*We are not using lt_tab_n in are program anywhere we are passing it
*to avoid dump
data : lt_tab_n type table of dd07v.
clear : lt_tab_n.

call function 'DD_DOMA_GET'


exporting
domain_name = p_dom_name
langu = sy-langu
withtext = 'X'
tables
dd07v_tab_a = p_lt_tab_a
dd07v_tab_n = lt_tab_n
exceptions
illegal_value = 1
op_failure = 2
others = 3.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.

endform. " GET_DOMAIN_VALUES


*&---------------------------------------------------------------------*
*& Form FILL_LT_DROPDOWN_ALIAS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0432 text
*----------------------------------------------------------------------*
form fill_lt_dropdown_alias using p_handle
p_lt_tab_a type standard table
changing p_lt_dropdown_alias type standard table.

data : ls_dropdown_alias type lvc_s_dral, " For dropdown


ls_tab_a type dd07v. " Form FM DD_DOMA_GET
clear : ls_dropdown_alias.

loop at p_lt_tab_a into ls_tab_a.


ls_dropdown_alias-handle = p_handle.
ls_dropdown_alias-value = ls_tab_a-ddtext.
*to Display different values outside(Alias) and Internal values inside.
ls_dropdown_alias-int_value = ls_tab_a-domvalue_l." internal value

append ls_dropdown_alias to p_lt_dropdown_alias.


endloop. "loop at p_lt_tab_a into ls_tab_a.

clear :p_lt_tab_a[],
ls_tab_a.

endform. " FILL_LT_DROPDOWN_ALIAS

*&---------------------------------------------------------------------*
*& Form display_item_details
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ROWS text
*----------------------------------------------------------------------*
form display_item_details tables p_lt_rows structure lvc_s_row
it_output_temp type standard table.

data : ls_rows like line of p_lt_rows,


ls_output_temp like ztb_qa_logbook.
.

loop at p_lt_rows into ls_rows.


clear : it_output_temp,
wa_output.
read table it_output into wa_output
index ls_rows-index.
if sy-subrc eq 0.
read table it_output_temp into ls_output_temp index ls_rows-index.
if sy-subrc eq 0.
if ls_output_temp-menge > it_output-menge .
insert wa_output into it_output index ls_rows-index.

endif.
endif. "IF sy-subrc eq 0.

endif. " IF sy-subrc EQ 0.READ TABLE it_sale_head INTO wa_sale_head


endloop. "LOOP AT p_lt_rows INTO ls_rows.
*
* CALL SCREEN '101' STARTING AT 30 5
* ENDING AT 120 16.

endform. "display_item_details
*&---------------------------------------------------------------------*
*& Form HANDLE_DATA_CHANGED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ER_DATA_CHANGED text
*----------------------------------------------------------------------*
form handle_data_changed using p_er_data_changed.

endform. " HANDLE_DATA_CHANGED

You might also like