Case Study OO ALV Interactive
Case Study OO ALV Interactive
Case Study OO ALV Interactive
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 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
Page 1
02/28/2015
Then click the layout button of the screen and place a custom container and name it as
CC_ALV_BASIC.
Page 2
02/28/2015
Screen 101.
Then click the layout button of the screen and place a custom container and name it as
CC_ALV_INTERACTIVE.
Page 3
02/28/2015
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.
Page 4
02/28/2015
Page 5
02/28/2015
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
02/28/2015
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
02/28/2015
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
02/28/2015
Page 9
02/28/2015
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
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
02/28/2015
*----------------------------------------------------------------------*
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
02/28/2015
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.
Page 12
02/28/2015
Page 13
02/28/2015
Page 14
02/28/2015