**&---------------------------------------------------------------------*
*& Report YJ_FACTORY_ALV
*&
*&---------------------------------------------------------------------*
*&Author : Jatin Singhal
*&Date : 19/8/2014
*&---------------------------------------------------------------------*
REPORT yj_factory_alv.
TYPES : BEGIN OF ty_equip,
equnr TYPE equnr,
eqart TYPE eqart,
serge TYPE serge,
objnr TYPE objnr,
submt TYPE submt,
ingrp TYPE ingrp,
iloan TYPE iloan,
advisor_action(4) type c,
END OF ty_equip.
DATA gt_equip TYPE TABLE OF ty_equip .
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS: on_user_command FOR EVENT added_function OF cl_salv_events_table
IMPORTING e_salv_function.
METHODS: on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
METHODS: on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_handle_events DEFINITION
*&---------------------------------------------------------------------*
*& Class (Implementation) lcl_handle_events
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
DATA : gr_table TYPE REF TO cl_salv_table,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table,
gr_functions TYPE REF TO cl_salv_functions,
gr_container_head TYPE REF TO cl_gui_custom_container,
gr_handle_event TYPE REF TO lcl_handle_events,
gr_event TYPE REF TO cl_salv_events_table.
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_user_command.
DATA: lr_selections TYPE REF TO cl_salv_selections,
li_rows TYPE salv_t_row,
l_row TYPE i,
l_output TYPE ty_equip,
l_message TYPE string,
l_refresh TYPE flag,
l_ucomm TYPE syucomm.
FIELD-SYMBOLS: <output> TYPE ty_equip.
CLEAR l_refresh.
CASE e_salv_function.
WHEN 'ADVHAN'.
lr_selections = gr_table->get_selections( ).
li_rows = lr_selections->get_selected_rows( ).
LOOP AT li_rows INTO l_row.
CLEAR l_output.
READ TABLE gt_equip INDEX l_row into l_output.
IF sy-subrc EQ 0.
l_output-advisor_action = 'TRUE'.
MODIFY gt_equip FROM l_output INDEX l_row TRANSPORTING advisor_action.
* CALL SCREEN 1000.
ENDIF.
ENDLOOP.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = abap_true.
ENDCASE.
* IF l_refresh EQ abap_true.
* PERFORM refresh.
* ENDIF.
ENDMETHOD. "on_user_command
METHOD on_double_click.
ENDMETHOD. "on_double_click
METHOD on_link_click.
CASE column.
WHEN 'EQUNR'.
PERFORM call_va03 USING row.
WHEN 'EQART'.
PERFORM call_vl03n USING row.
ENDCASE.
ENDMETHOD. "on_link_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION
START-OF-SELECTION.
SELECT equi~equnr equi~eqart equi~serge equi~objnr
equz~submt equz~ingrp
iloa~iloan
INTO TABLE gt_equip
FROM equi
INNER JOIN equz
ON equi~equnr = equz~equnr
INNER JOIN iloa
ON equz~iloan = iloa~iloan.
DELETE gt_equip WHERE serge = space.
SORT gt_equip BY equnr.
END-OF-SELECTION.
CALL SCREEN 1000.
*CALL METHOD cl_salv_table=>factory
* IMPORTING
* r_salv_table = gr_table
* CHANGING
* t_table = gt_equip.
*&---------------------------------------------------------------------*
*& Module STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1000 OUTPUT.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'FACTORY_ALV_DEMO'.
ENDMODULE. " STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
*& Module DISPLAY_ALV OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE display_alv OUTPUT.
Perform show_alv.
ENDMODULE. " DISPLAY_ALV OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT_1000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE exit_1000 INPUT.
CASE SY-UCOMM.
When 'EXIT'.
LEAVE TO SCREEN 0.
Endcase.
ENDMODULE. " EXIT_1000 INPUT
FORM call_va03 USING p_row.
DATA l_output TYPE ty_equip.
CHECK p_row IS NOT INITIAL.
READ TABLE gt_equip INDEX p_row INTO l_output.
SET PARAMETER ID 'AUN' FIELD l_output-equnr.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDFORM. " CALL_VA03
*&---------------------------------------------------------------------*
*& Form CALL_VL03N
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ROW text
*----------------------------------------------------------------------*
FORM call_vl03n USING p_row.
DATA l_output TYPE ty_equip.
CHECK p_row IS NOT INITIAL.
READ TABLE gt_equip INDEX p_row INTO l_output.
SET PARAMETER ID 'VL' FIELD l_output-eqart.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
ENDFORM. " CALL_VL03N
*&---------------------------------------------------------------------*
*& Form SHOW_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM show_alv .
*IF gr_container_head IS INITIAL.
CREATE OBJECT gr_container_head
EXPORTING
container_name = 'C_CONT1'
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.
TRY.
cl_salv_table=>factory(
EXPORTING r_container = gr_container_head
container_name = 'C_CONT1'
IMPORTING r_salv_table = gr_table
CHANGING t_table = gt_equip ).
CATCH cx_salv_msg.
ENDTRY.
*
TRY.
*set functions
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
* add function
gr_functions->add_function(
name = 'ADVHAN'
icon = '@BB@'
text = 'Advisor'
tooltip = 'Handled by advisor'
position = if_salv_c_function_position=>right_of_salv_functions ).
*set column
gr_columns = gr_table->get_columns( ).
gr_columns->set_optimize( abap_true ).
* set hotspot
gr_column ?= gr_columns->get_column( 'EQUNR' ).
gr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
gr_column ?= gr_columns->get_column( 'EQART' ).
gr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
CATCH cx_salv_not_found.
CATCH cx_salv_wrong_call.
CATCH cx_salv_existing.
CATCH cx_salv_data_error.
ENDTRY.
* register events
gr_event = gr_table->get_event( ).
CREATE OBJECT gr_handle_event.
SET HANDLER gr_handle_event->on_user_command FOR gr_event.
SET HANDLER gr_handle_event->on_double_click FOR gr_event.
SET HANDLER gr_handle_event->on_link_click FOR gr_event.
*Display the ALV table.
gr_table->display( ).
*Endif.
ENDFORM. " SHOW_ALV
*& Report YJ_FACTORY_ALV
*&
*&---------------------------------------------------------------------*
*&Author : Jatin Singhal
*&Date : 19/8/2014
*&---------------------------------------------------------------------*
REPORT yj_factory_alv.
TYPES : BEGIN OF ty_equip,
equnr TYPE equnr,
eqart TYPE eqart,
serge TYPE serge,
objnr TYPE objnr,
submt TYPE submt,
ingrp TYPE ingrp,
iloan TYPE iloan,
advisor_action(4) type c,
END OF ty_equip.
DATA gt_equip TYPE TABLE OF ty_equip .
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS: on_user_command FOR EVENT added_function OF cl_salv_events_table
IMPORTING e_salv_function.
METHODS: on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
METHODS: on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_handle_events DEFINITION
*&---------------------------------------------------------------------*
*& Class (Implementation) lcl_handle_events
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
DATA : gr_table TYPE REF TO cl_salv_table,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table,
gr_functions TYPE REF TO cl_salv_functions,
gr_container_head TYPE REF TO cl_gui_custom_container,
gr_handle_event TYPE REF TO lcl_handle_events,
gr_event TYPE REF TO cl_salv_events_table.
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_user_command.
DATA: lr_selections TYPE REF TO cl_salv_selections,
li_rows TYPE salv_t_row,
l_row TYPE i,
l_output TYPE ty_equip,
l_message TYPE string,
l_refresh TYPE flag,
l_ucomm TYPE syucomm.
FIELD-SYMBOLS: <output> TYPE ty_equip.
CLEAR l_refresh.
CASE e_salv_function.
WHEN 'ADVHAN'.
lr_selections = gr_table->get_selections( ).
li_rows = lr_selections->get_selected_rows( ).
LOOP AT li_rows INTO l_row.
CLEAR l_output.
READ TABLE gt_equip INDEX l_row into l_output.
IF sy-subrc EQ 0.
l_output-advisor_action = 'TRUE'.
MODIFY gt_equip FROM l_output INDEX l_row TRANSPORTING advisor_action.
* CALL SCREEN 1000.
ENDIF.
ENDLOOP.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = abap_true.
ENDCASE.
* IF l_refresh EQ abap_true.
* PERFORM refresh.
* ENDIF.
ENDMETHOD. "on_user_command
METHOD on_double_click.
ENDMETHOD. "on_double_click
METHOD on_link_click.
CASE column.
WHEN 'EQUNR'.
PERFORM call_va03 USING row.
WHEN 'EQART'.
PERFORM call_vl03n USING row.
ENDCASE.
ENDMETHOD. "on_link_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION
START-OF-SELECTION.
SELECT equi~equnr equi~eqart equi~serge equi~objnr
equz~submt equz~ingrp
iloa~iloan
INTO TABLE gt_equip
FROM equi
INNER JOIN equz
ON equi~equnr = equz~equnr
INNER JOIN iloa
ON equz~iloan = iloa~iloan.
DELETE gt_equip WHERE serge = space.
SORT gt_equip BY equnr.
END-OF-SELECTION.
CALL SCREEN 1000.
*CALL METHOD cl_salv_table=>factory
* IMPORTING
* r_salv_table = gr_table
* CHANGING
* t_table = gt_equip.
*&---------------------------------------------------------------------*
*& Module STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1000 OUTPUT.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'FACTORY_ALV_DEMO'.
ENDMODULE. " STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
*& Module DISPLAY_ALV OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE display_alv OUTPUT.
Perform show_alv.
ENDMODULE. " DISPLAY_ALV OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT_1000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE exit_1000 INPUT.
CASE SY-UCOMM.
When 'EXIT'.
LEAVE TO SCREEN 0.
Endcase.
ENDMODULE. " EXIT_1000 INPUT
FORM call_va03 USING p_row.
DATA l_output TYPE ty_equip.
CHECK p_row IS NOT INITIAL.
READ TABLE gt_equip INDEX p_row INTO l_output.
SET PARAMETER ID 'AUN' FIELD l_output-equnr.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDFORM. " CALL_VA03
*&---------------------------------------------------------------------*
*& Form CALL_VL03N
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ROW text
*----------------------------------------------------------------------*
FORM call_vl03n USING p_row.
DATA l_output TYPE ty_equip.
CHECK p_row IS NOT INITIAL.
READ TABLE gt_equip INDEX p_row INTO l_output.
SET PARAMETER ID 'VL' FIELD l_output-eqart.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
ENDFORM. " CALL_VL03N
*&---------------------------------------------------------------------*
*& Form SHOW_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM show_alv .
*IF gr_container_head IS INITIAL.
CREATE OBJECT gr_container_head
EXPORTING
container_name = 'C_CONT1'
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.
TRY.
cl_salv_table=>factory(
EXPORTING r_container = gr_container_head
container_name = 'C_CONT1'
IMPORTING r_salv_table = gr_table
CHANGING t_table = gt_equip ).
CATCH cx_salv_msg.
ENDTRY.
*
TRY.
*set functions
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
* add function
gr_functions->add_function(
name = 'ADVHAN'
icon = '@BB@'
text = 'Advisor'
tooltip = 'Handled by advisor'
position = if_salv_c_function_position=>right_of_salv_functions ).
*set column
gr_columns = gr_table->get_columns( ).
gr_columns->set_optimize( abap_true ).
* set hotspot
gr_column ?= gr_columns->get_column( 'EQUNR' ).
gr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
gr_column ?= gr_columns->get_column( 'EQART' ).
gr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
CATCH cx_salv_not_found.
CATCH cx_salv_wrong_call.
CATCH cx_salv_existing.
CATCH cx_salv_data_error.
ENDTRY.
* register events
gr_event = gr_table->get_event( ).
CREATE OBJECT gr_handle_event.
SET HANDLER gr_handle_event->on_user_command FOR gr_event.
SET HANDLER gr_handle_event->on_double_click FOR gr_event.
SET HANDLER gr_handle_event->on_link_click FOR gr_event.
*Display the ALV table.
gr_table->display( ).
*Endif.
ENDFORM. " SHOW_ALV