case study oo alv interactive

17
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

Upload: bakkalibilal

Post on 07-Feb-2016

65 views

Category:

Documents


2 download

DESCRIPTION

Case Study OO ALV Interactive

TRANSCRIPT

Page 1: Case Study OO ALV Interactive

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

Page 2: Case Study OO ALV Interactive

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

Page 3: Case Study OO ALV Interactive

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

Page 4: Case Study OO ALV Interactive

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

Page 5: Case Study OO ALV Interactive

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

Page 6: Case Study OO ALV Interactive

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

ENDCLASS. "lcl_event_receiver IMPLEMENTATION*&---------------------------------------------------------------------**& Module display_alv OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*module display_alv output.

if custom_container is initial.

CREATE OBJECT custom_container EXPORTING

Author: Ranjit K Panda Page 6 04/22/2023

Page 7: Case Study OO ALV Interactive

container_name = 'CC_ALV_BASIC' . CREATE OBJECT alv_grid EXPORTING i_parent = custom_container.

*ALV fieldcatalogue PERFORM alv_100_fieldcat.

CALL METHOD alv_grid->set_table_for_first_display EXPORTING* I_BUFFER_ACTIVE =* I_BYPASSING_BUFFER =* I_CONSISTENCY_CHECK = I_STRUCTURE_NAME = 'IT_VBAK'* IS_VARIANT =* I_SAVE =* I_DEFAULT = 'X'* IS_LAYOUT =* IS_PRINT =* IT_SPECIAL_GROUPS =* IT_TOOLBAR_EXCLUDING =* IT_HYPERLINK =* IT_ALV_GRAPHICS =* IT_EXCEPT_QINFO = CHANGING it_outtab = it_vbak[] IT_FIELDCATALOG = field_cat* 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.*Create object of the event class and setting handler for double click CREATE OBJECT event_receiver. SET HANDLER event_receiver->handle_double_click FOR alv_grid.ENDIF.

Author: Ranjit K Panda Page 7 04/22/2023

Page 8: Case Study OO ALV Interactive

endmodule. " display_alv OUTPUT*&---------------------------------------------------------------------**& Form alv_100_fieldcat*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form alv_100_fieldcat .

REFRESH field_cat. CLEAR ty_fld_cat.

ty_fld_cat-row_pos = 1. ty_fld_cat-col_pos = 1. ty_fld_cat-fieldname = 'VBELN'. ty_fld_cat-tabname = 'IT_VBAK'. ty_fld_cat-coltext = 'Sales Order Number'. ty_fld_cat-outputlen = 10. APPEND ty_fld_cat TO field_cat.

ty_fld_cat-row_pos = 1. ty_fld_cat-col_pos = 2. ty_fld_cat-fieldname = 'ERDAT'. ty_fld_cat-tabname = 'IT_VBAK'. ty_fld_cat-coltext = 'Creation Date'. ty_fld_cat-outputlen = 10. APPEND ty_fld_cat TO field_cat.

ty_fld_cat-row_pos = 1. ty_fld_cat-col_pos = 3. ty_fld_cat-fieldname = 'ERNAM'. ty_fld_cat-tabname = 'IT_VBAK'. ty_fld_cat-coltext = 'Created By'. ty_fld_cat-outputlen = 10. APPEND ty_fld_cat TO field_cat.

ty_fld_cat-row_pos = 1. ty_fld_cat-col_pos = 4. ty_fld_cat-fieldname = 'VBTYP'. ty_fld_cat-tabname = 'IT_VBAK'. ty_fld_cat-coltext = 'Document Category'. ty_fld_cat-outputlen = 10.

Author: Ranjit K Panda Page 8 04/22/2023

Page 9: Case Study OO ALV Interactive

APPEND ty_fld_cat TO field_cat.

ty_fld_cat-row_pos = 1. ty_fld_cat-col_pos = 5. ty_fld_cat-fieldname = 'AUART'. ty_fld_cat-tabname = 'IT_VBAK'. ty_fld_cat-coltext = 'Document Type'. ty_fld_cat-outputlen = 10. APPEND ty_fld_cat TO field_cat.

endform. " alv_100_fieldcat*&---------------------------------------------------------------------**& Module display_interactive OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*module display_interactive output.

if c_cont2 is initial.

CREATE OBJECT c_cont2 EXPORTING

container_name = 'CC_ALV_INTERACTIVE' . CREATE OBJECT c_alv2 EXPORTING i_parent = c_cont2.

*ALV layout PERFORM alv_101_layout.

*ALV fieldcatalogue PERFORM alv_101_fieldcat.

*Sorting the output by field position SORT it_vbap BY vbeln.

CALL METHOD c_alv2->set_table_for_first_display EXPORTING* I_BUFFER_ACTIVE =* I_BYPASSING_BUFFER =* I_CONSISTENCY_CHECK = I_STRUCTURE_NAME = 'IT_VBAP'* IS_VARIANT =* I_SAVE =

Author: Ranjit K Panda Page 9 04/22/2023

Page 10: Case Study OO ALV Interactive

* I_DEFAULT = 'X' IS_LAYOUT = ty_lay2* IS_PRINT =* IT_SPECIAL_GROUPS =* IT_TOOLBAR_EXCLUDING =* IT_HYPERLINK =* IT_ALV_GRAPHICS =* IT_EXCEPT_QINFO = CHANGING it_outtab = it_vbap[] IT_FIELDCATALOG = it_fcat* 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.

endif.endmodule. " display_interactive OUTPUT*&---------------------------------------------------------------------**& Form alv_101_layout*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*form alv_101_layout . ty_lay2-grid_title = 'FIELDS'. ty_lay2-zebra = 'X'. ty_lay2-no_toolbar = 'X'.endform. " alv_101_layout*&---------------------------------------------------------------------**& Form alv_101_fieldcat*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text

Author: Ranjit K Panda Page 10 04/22/2023

Page 11: Case Study OO ALV Interactive

*----------------------------------------------------------------------*form alv_101_fieldcat . REFRESH field_cat. REFRESH it_fcat. CLEAR ty_fcat.

ty_fcat-row_pos = 1. ty_fcat-col_pos = 1. ty_fcat-fieldname = 'VBELN'. ty_fcat-tabname = 'IT_VBAP'. ty_fcat-coltext = 'Sales Order Number'. ty_fcat-outputlen = 10. APPEND ty_fcat TO it_fcat.

ty_fcat-row_pos = 1. ty_fcat-col_pos = 2. ty_fcat-fieldname = 'POSNR'. ty_fcat-tabname = 'IT_VBAP'. ty_fcat-coltext = 'Sales Order Item Number'. ty_fcat-outputlen = 10. APPEND ty_fcat TO it_fcat.

ty_fcat-row_pos = 1. ty_fcat-col_pos = 3. ty_fcat-fieldname = 'MATNR'. ty_fcat-tabname = 'IT_VBAP'. ty_fcat-coltext = 'Material Number'. ty_fcat-outputlen = 10. APPEND ty_fcat TO it_fcat.

ty_fcat-row_pos = 1. ty_fcat-col_pos = 4. ty_fcat-fieldname = 'MATKL'. ty_fcat-tabname = 'IT_VBAP'. ty_fcat-coltext = 'Material Group'. ty_fcat-outputlen = 10. APPEND ty_fcat TO it_fcat.

ty_fcat-row_pos = 1. ty_fcat-col_pos = 5. ty_fcat-fieldname = 'PSTYV'. ty_fcat-tabname = 'IT_VBAP'. ty_fcat-coltext = 'Sales Document Category'. ty_fcat-outputlen = 10. APPEND ty_fcat TO it_fcat.endform. " alv_101_fieldcat

Author: Ranjit K Panda Page 11 04/22/2023

Page 12: Case Study OO ALV Interactive

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.

Author: Ranjit K Panda Page 12 04/22/2023

Page 13: Case Study OO ALV Interactive

Author: Ranjit K Panda Page 13 04/22/2023

Page 14: Case Study OO ALV Interactive

Author: Ranjit K Panda Page 14 04/22/2023