0% found this document useful (0 votes)
165 views3 pages

A Simple OOP ALV Report

1) The document describes how to create a simple OOP ALV report in ABAP. It includes populating an internal table with data, creating ALV grid and custom container objects, and displaying the ALV grid on a screen. 2) Key steps are populating an internal table with sample customer data, creating ALV grid and custom container objects, setting layout and field catalog properties, and invoking the display method to show the grid. 3) The code displays a customer list ALV grid on screen 0100 using a custom container, with functionality to go back, cancel, or exit from the menu.

Uploaded by

vvardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views3 pages

A Simple OOP ALV Report

1) The document describes how to create a simple OOP ALV report in ABAP. It includes populating an internal table with data, creating ALV grid and custom container objects, and displaying the ALV grid on a screen. 2) Key steps are populating an internal table with sample customer data, creating ALV grid and custom container objects, setting layout and field catalog properties, and invoking the display method to show the grid. 3) The code displays a customer list ALV grid on screen 0100 using a custom container, with functionality to go back, cancel, or exit from the menu.

Uploaded by

vvardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

A Simple OOP ALV Report

NOTE: As part of screen design create two screens with screen numbers 0100 and 0101. Also create a
menu named MYMENU with Functional Keys BACK, CANCEL, and EXIT with respective function
codes.
Steps to code an OOP ALV:
1) Populate an internal table with data to be displayed in the ALV report.
2) SE51 in the screen paint a Custom Container component.
3) In the report program PBO module:
a) Create an object of CL_GUI_CUSTOM_CONTAINER and associate it with the Custom
Contianer component in the screen.
b) Create
an
obejct
of
CL_GUI_ALV_GRID
by
setting
the
object
of
CL_GUI_CUSTOM_CONTAINER as its parent.
c) Populate layout properties using the structure LVC_S_LAYO.
d) Populate fieldcatalog properties using the table type LVC_T_FCAT.
e) Invoke the method SET_TABLE_FOR_FIRST_DISPLAY on the obejct of
CL_GUI_ALV_GRID and pass the layout, fieldcatalog and the internal table with data.
OOP ALV With Custom Container
To the screen 0100:
Add the menu MYMENU and in the PAI section of the screen provide appropriate code to handle the
functionality for BACK, CANCEL, and EXIT. See MODULE user_command_0100 INPUT in the
code below. To the layout of this screen add a customer control and name it CC_KNA1.
Flow logic of screen 0100:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
***********
REPORT yalv_oop1.
TYPES: BEGIN OF ty_kna1,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1,
ort01 TYPE kna1-ort01,
land1 TYPE kna1-land1,
pstlz TYPE kna1-pstlz,
END OF ty_kna1.
DATA: t_kna1 TYPE TABLE OF ty_kna1,
r_cc_kna1 TYPE REF TO cl_gui_custom_container,
r_grid_kna1 TYPE REF TO cl_gui_alv_grid,
s_layout TYPE lvc_s_layo,
t_fcat TYPE lvc_t_fcat.
DATA: g_kunnr TYPE kna1-kunnr.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

SELECT-OPTIONS: s_kunnr FOR g_kunnr DEFAULT 1000 TO 2000.


SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
SELECT kunnr
name1
ort01
land1
pstlz
FROM kna1 INTO TABLE t_kna1
WHERE kunnr IN s_kunnr.
CALL SCREEN '100'.
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR sy-ucomm = 'CANCEL' OR sy-ucomm = 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
" USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MYMENU'.
PERFORM populate_layout.
PERFORM populate_fcat.
PERFORM display_alv.
ENDMODULE.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Form populate_layout
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM populate_layout .
s_layout-zebra = 'X'.
s_layout-cwidth_opt = 'X'.
ENDFORM.
"populate_layout
*&---------------------------------------------------------------------*
*&
Form populate_fcat
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM populate_fcat .
DATA: ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'KUNNR'.
ls_fcat-coltext = 'Customer'.
APPEND ls_fcat TO t_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'NAME1'.
ls_fcat-coltext = 'Customer Name'.
APPEND ls_fcat TO t_fcat.
CLEAR ls_fcat.

ls_fcat-fieldname = 'ORT01'.
ls_fcat-coltext = 'City'.
APPEND ls_fcat TO t_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'LAND1'.
ls_fcat-coltext = 'Country'.
APPEND ls_fcat TO t_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'PSTLZ'.
ls_fcat-coltext = 'P Code'.
APPEND ls_fcat TO t_fcat.
CLEAR ls_fcat.
ENDFORM.
"populate_fcat
*&---------------------------------------------------------------------*
*&
Form display_alv
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM display_alv .
CREATE OBJECT r_cc_kna1
EXPORTING
container_name = 'CC_KNA1'.
CREATE OBJECT r_grid_kna1
EXPORTING
i_parent = r_cc_kna1.
CALL METHOD r_grid_kna1->set_table_for_first_display
EXPORTING
is_layout
= s_layout
CHANGING
it_outtab
= t_kna1
it_fieldcatalog = t_fcat.
ENDFORM.
"display_alv

You might also like