Case Study: Interactive ALV using OOPS. Business Requirement: To create a Simple Interactive ALV application using ABAP-OOPS concept To have a very simple scenario on this, when the 1 st basic ALV output will come, it will display all the records from Sales order Header Table (VBAK). And when the user will click the 1 st column i.e. Sales Order Number ( VBAK-VBELN) , then in another ALV it will show the details of that particular order number by picking data from Sales Document Item (VBAP) table. Solution: Go to se38 Create a program name as ZINTERACTIVE_ALV_OOPS. Go to tcode SE51 and create two screens by giving screen number 100 and 101. Screen 100 Author: Ranjit K Panda Page 1 06/12/2022
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Case Study: Interactive ALV using OOPS. Business Requirement:
To create a Simple Interactive ALV application using ABAP-OOPS concept
To have a very simple scenario on this, when the 1st basic ALV output will come, it will display all the records from Sales order Header Table (VBAK). And when the user will click the 1st column i.e. Sales Order Number ( VBAK-VBELN) , then in another ALV it will show the details of that particular order number by picking data from Sales Document Item (VBAP) table.
Solution:
Go to se38
Create a program name as ZINTERACTIVE_ALV_OOPS.
Go to tcode SE51 and create two screens by giving screen number 100 and 101.
Screen 100
Author: Ranjit K Panda Page 1 04/22/2023
Then click the layout button of the screen and place a custom container and name it as CC_ALV_BASIC.
Author: Ranjit K Panda Page 2 04/22/2023
Screen 101.
Then click the layout button of the screen and place a custom container and name it as CC_ALV_INTERACTIVE.
Author: Ranjit K Panda Page 3 04/22/2023
Create two module in the PBO section of the screen as shown below. In screen 100 create a module named MODULE display_alv and include the module in the main program.
Also like above process create another module in the PBO section of screen 101 and name the module as MODULE display_interactive.
Then go to SE38 and in the program ZINTERACTIVE_ALV_OOPS ,
Write the following codes.
*Class definition for handling double clickCLASS event_class DEFINITION DEFERRED.
***Declaration For Basic ALVDATA: alv_grid TYPE REF TO cl_gui_alv_grid, custom_container TYPE REF TO cl_gui_custom_container, field_cat TYPE lvc_t_fcat, ty_fld_cat TYPE lvc_s_fcat, layout TYPE lvc_s_layo,
Author: Ranjit K Panda Page 4 04/22/2023
event_receiver TYPE REF TO event_class.
*data declarations for ALV Interactive list
DATA : ty_lay2 TYPE lvc_s_layo, it_fcat TYPE lvc_t_fcat , ty_fcat TYPE lvc_s_fcat , c_alv2 TYPE REF TO cl_gui_alv_grid, c_cont2 TYPE REF TO cl_gui_custom_container.*---------------------------------------------------------------------** Global Types*---------------------------------------------------------------------*TYPES:BEGIN OF ty_vbak, vbeln TYPE vbeln_va, erdat TYPE erdat, ernam TYPE ernam, vbtyp TYPE vbtyp, auart TYPE auart,END OF ty_vbak.
TYPES:BEGIN OF ty_vbap, vbeln TYPE vbeln_va, posnr TYPE posnr_va, matnr TYPE matnr, matkl TYPE matkl, pstyv TYPE pstyv,END OF ty_vbap.
*---------------------------------------------------------------------** Global Internal tables*----------------------------------------------------------------------*DATA: it_vbak TYPE STANDARD TABLE OF ty_vbak INITIAL SIZE 1.DATA: it_vbap TYPE STANDARD TABLE OF ty_vbap INITIAL SIZE 1.
*---------------------------------------------------------------------** Global work Area*----------------------------------------------------------------------*DATA : wa_vbak TYPE ty_vbak, wa_vbap TYPE ty_vbap.
START-OF-SELECTION. PERFORM fetch_data.*&---------------------------------------------------------------------**& Form fetch_data*&---------------------------------------------------------------------*
Author: Ranjit K Panda Page 5 04/22/2023
FORM fetch_data . SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE it_vbak UP TO 20 ROWS.
call screen 100.ENDFORM. " fetch_data
*----------------------------------------------------------------------** CLASS lcl_event_receiver DEFINITION*----------------------------------------------------------------------*CLASS event_class DEFINITION.*Handling double click PUBLIC SECTION. METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row .ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------** CLASS lcl_event_receiver IMPLEMENTATION*----------------------------------------------------------------------*CLASS event_class IMPLEMENTATION. METHOD handle_double_click. DATA : is_vbak LIKE LINE OF it_vbak.*Reading the selected data into a variable READ TABLE it_vbak INDEX e_row-index INTO is_vbak.* *Select the field details of the selected table SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE it_vbap WHERE vbeln EQ is_vbak-vbeln.*calling the ALV containing the field values CALL SCREEN 101. ENDMETHOD. "handle_double_clickENDCLASS. "lcl_event_receiver IMPLEMENTATION
Then save and activate the code. When we will run the program ZINTERACTIVE_ALV_OOPS we will get the output as follows.
This is the basic Alv list and when you will slecte any value from the 1st column i.e. Sales Order Number then we will get the following Interactive List which will show us the data for that particular Sales order number.