Professional Documents
Culture Documents
Also create a
menu named MYMENU with Functional Keys BACK, CANCEL, and EXIT with respective function
codes.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_double_click.
DATA: l_kunnr TYPE kna1-kunnr.
READ TABLE t_kna1 INDEX es_row_no-row_id INTO l_kunnr.
SELECT kunnr
vbeln
netwr
INTO TABLE t_vbak
FROM vbak
WHERE kunnr = l_kunnr.
IF sy-subrc <> 0.
MESSAGE 'No order for the customer.' TYPE 'I'.
ELSE.
CALL SCREEN '0101'.
ENDIF.
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
PERFORM populate_t_kna1.
CALL SCREEN '100'.
*----------------------------------------------------------------------*
* MODULE status_0100 OUTPUT
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MYMENU'.
PERFORM display_kna1_alv.
ENDMODULE. " STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
* MODULE user_command_0100 INPUT
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK'.
LEAVE TO SCREEN 0.
ELSEIF sy-ucomm = 'CANCEL' OR sy-ucomm = 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form display_kna1_alv
*&---------------------------------------------------------------------*
FORM display_kna1_alv.
CHECK t_kna1 IS NOT INITIAL.
PERFORM populate_kna1_fcat.
*&---------------------------------------------------------------------*
*& Form populate_kna1_layo
*&---------------------------------------------------------------------*
FORM populate_kna1_layo.
CLEAR s_layo_kna1.
s_layo_kna1-zebra = 'X'.
s_layo_kna1-cwidth_opt = 'X'.
ENDFORM. " populate_layout
*&---------------------------------------------------------------------*
*& Form populate_kna1_fcat
*&---------------------------------------------------------------------*
FORM populate_kna1_fcat .
DATA: ls_fcat TYPE lvc_s_fcat.
REFRESH t_fcat_kna1.
ls_fcat-fieldname = 'KUNNR'.
ls_fcat-coltext = 'Customer'.
APPEND ls_fcat TO t_fcat_kna1.
CLEAR ls_fcat.
ls_fcat-fieldname = 'NAME1'.
ls_fcat-coltext = 'Customer Name'.
APPEND ls_fcat TO t_fcat_kna1.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ORT01'.
ls_fcat-coltext = 'City'.
APPEND ls_fcat TO t_fcat_kna1.
CLEAR ls_fcat.
ls_fcat-fieldname = 'LAND1'.
ls_fcat-coltext = 'Country'.
APPEND ls_fcat TO t_fcat_kna1.
CLEAR ls_fcat.
ls_fcat-fieldname = 'PSTLZ'.
ls_fcat-coltext = 'P Code'.
APPEND ls_fcat TO t_fcat_kna1.
CLEAR ls_fcat.
ENDFORM. " populate_fcat
*&---------------------------------------------------------------------*
*& Form populate_t_kna1
*&---------------------------------------------------------------------*
FORM populate_t_kna1 .
SELECT kunnr
name1
ort01
land1
pstlz
FROM kna1 INTO TABLE t_kna1
WHERE kunnr IN s_kunnr.
IF sy-subrc <> 0.
MESSAGE 'No data found for given range.' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " populate_t_kna1
*----------------------------------------------------------------------*
* MODULE status_0101 OUTPUT
*----------------------------------------------------------------------*
MODULE status_0101 OUTPUT.
SET PF-STATUS 'MYMENU'.
PERFORM display_vbak_alv.
ENDMODULE. " STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0101 INPUT.
IF sy-ucomm = 'BACK'.
* SET SCREEN '0100'.
LEAVE TO SCREEN 0.
ELSEIF sy-ucomm = 'CANCEL' OR sy-ucomm = 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE. " USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
*& Form display_vbak_alv
*&---------------------------------------------------------------------*
FORM display_vbak_alv .
CHECK t_vbak IS NOT INITIAL.
PERFORM populate_vbak_fcat.
*&---------------------------------------------------------------------*
*& Form populate_vbak_layo
*&---------------------------------------------------------------------*
FORM populate_vbak_layo .
CLEAR s_layo_vbak.
s_layo_vbak-zebra = 'X'.
s_layo_vbak-cwidth_opt = 'X'.
ENDFORM. " populate_vbak_layo
*&---------------------------------------------------------------------*
*& Form populate_vbak_fcat
*&---------------------------------------------------------------------*
FORM populate_vbak_fcat .
DATA: ls_fcat TYPE lvc_s_fcat.
REFRESH t_fcat_vbak.
ls_fcat-fieldname = 'KUNNR'.
ls_fcat-coltext = 'Customer'.
APPEND ls_fcat TO t_fcat_vbak.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-coltext = 'Order Num.'.
APPEND ls_fcat TO t_fcat_vbak.
CLEAR ls_fcat.
ls_fcat-fieldname = 'NETWR'.
ls_fcat-coltext = 'Net Value'.
APPEND ls_fcat TO t_fcat_vbak.
CLEAR ls_fcat.
ENDFORM. " populate_vbak_fcat
NOTES:
Note-1: As the user of the report keeps moving back and forth in the interactive report the PBO modules
of the respective screen get invoked repeatedly. The objects of CL_GUI_CUSTOM_CONTAINER and
that of CL_GUI_ALV_GRID should be created only when the report is displayed for the first time and not
every time the user moves back and forth. For this reason always verify if the grid is initial or not, and
create the objects only when it has not yet been created. Also, populate the field catalog table, layout
structure; sort table etc only the first time and not every time PBO gets executed.
Note-2: If you want to refresh the data displayed in the output table, use method refresh_table_display.
Method set_table_for_first_display must only be called a second time if the structure of the output table
changes.
Note-3: After a screen transition, when you come back to the screen with the ALV, the scroll information
is lost. Say, you scroll down an ALV report and double click on the 70th row to navigated to the next
report; when you again navigate back the former ALV report doesnt retain the scroll position. To retain
the scroll position on navigating back to the former ALV report add the below snippets of code to the
above program.
Snippet 2: In the event handler method, just before the READ statement add the below snippet of code.
Snippet 3: In the MODULE user_command_0101 INPUT pertaining to PAI of screen 101, while handling
the function code BACK, add the below snippet of code to set the scroll position and then have the code
to navigate back to the former ALV report.
IF sy-ucomm = 'BACK'.
* SET SCREEN '0100'.
*&--- Code to retain scroll position - Start
CALL METHOD r_grid_kna1->set_scroll_info_via_id
EXPORTING
is_row_info = s_rowinfo
is_col_info = s_colinfo.
*&--- Code to retain scroll position - End
LEAVE TO SCREEN 0.
ELSEIF sy-ucomm = 'CANCEL' OR sy-ucomm = 'EXIT'.
LEAVE PROGRAM.
ENDIF.