‎2006 Jul 21 1:05 PM
hi,
i am new in ABAP OO, i want to develop a simple report in ALV using ABAP OO, please help me to do that.
thanks in advance
‎2006 Jul 21 1:10 PM
Hi Jodinger,
take a look into the class cl_gui_alv_grid on SE24. This is the OO implementation of the ALV Grid. You will find more documentation on that on help.sap.com.
It's possible to subclass this or write a wrapper like this:
* DEFINITION
CLASS lcl_alv_wrapper DEFINITION.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING i_parent TYPE REF TO cl_gui_container OPTIONAL,
set_title
IMPORTING i_title TYPE lvc_s_layo-grid_title,
set_parent
IMPORTING i_parent TYPE REF TO cl_gui_container,
show,
free.
PROTECTED SECTION.
METHODS:
init_outtab
IMPORTING i_tabstruct TYPE dd02l-tabname
CHANGING i_outtab TYPE ANY TABLE,
* Referenz auf Ausgabetabelle
rt_outtab TYPE REF TO data,
* Zeiger auf ALV
r_alv TYPE REF TO cl_gui_alv_grid.
ENDCLASS.
* IMPLEMENTATION
CLASS lcl_alv_wrapper IMPLEMENTATION.
************************************************************************
* Form constructor
************************************************************************
METHOD constructor.
r_parent = i_parent.
CALL METHOD disable_buffer.
ENDMETHOD.
************************************************************************
* Form init_outtab
************************************************************************
METHOD init_outtab.
h_tabstruct = i_tabstruct.
* Referenz auf Ausgabetabelle sichern
GET REFERENCE OF i_outtab INTO rt_outtab.
ENDMETHOD.
************************************************************************
* Form show
************************************************************************
METHOD show.
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
CHECK NOT r_parent IS INITIAL.
ASSIGN rt_outtab->* TO <itab>.
CHECK sy-subrc IS INITIAL.
* erzeuge ALV Grid Objekt
CREATE OBJECT r_alv
EXPORTING i_parent = r_parent.
* Feldkatalog aus übergebener Struktur erzeugen
CALL METHOD build_fieldcat.
CALL METHOD build_sorttab.
CALL METHOD build_colortab.
CALL METHOD build_layout.
CALL METHOD build_variant.
* ALV Grid vorbereiten
CALL METHOD r_alv->set_table_for_first_display
EXPORTING
i_bypassing_buffer = h_use_buffer
is_variant = s_variant
is_layout = s_layout
i_save = 'A'
CHANGING
it_fieldcatalog = it_fieldcat
it_sort = it_sortdef
it_outtab = <itab>.
* ALV bekommt Fokus
CALL METHOD cl_gui_control=>set_focus
EXPORTING control = r_alv.
ENDMETHOD.
METHOD free.
* ALV bekommt Fokus
CALL METHOD r_alv->free.
FREE r_alv.
ENDMETHOD.
ENDCLASS.It's just an extraction of my code so don't expect it to work but it should give you some hints.
Regards,
ok
‎2006 Jul 21 1:12 PM
Hi,
these are the steps to create a report using OO techniques.
1. Create a Control (for Custom and Split Containers only)
2. Instantiate a Container Object (in case of Custom and Split Containers, specify the control which is created by us in Screen painter) CREATE OBJECT <Container Object>
3. Instantiate an Object of the kind of report that has to be displayed (List, Grid or Tree). CREATE OBJECT <List/Grid/Tree>. Here we need to specify the Parent Container as the <Container object> so that it sits in that container.
4. Call appropriate methods to display the report on the screen. CALL METHOD <List/Grid/Tree>-><Method Name>
If you need a sample pgm do let me know.
Regards,
Sumit.
‎2006 Jul 21 1:12 PM
Hi Joginder,
In your screen, create a container element(name is CONTAINER)
In the main program , declare the variables like this
data: container type ref to CL_GUI_CUSTOM_CONTAINER,
alv type ref to CL_GUI_ALV_GRID.
data: itab type table of sflight with header line.
In PBO
-
If container is initial.
create object cont
exporting container_name = 'CONTAINER'.
create object alv
exporting
parent = cont.
SELECT * FROM SFLIGHT INTO TABLE ITAB.
call method alv->set_table_for_first_display
exporting
i_structure_name = 'SFLIGHT'
changing
it_outtab = ITAB[].
endif.
This is the simplest way of creating ALV using OO ABAP.
You can refer this document.
http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
You can explore OOALV through this link.
http://esnips.com/doc/2d953590-e8c5-490c-a607-d1ab7cf517d7/ALV.pdf
Regards,
SP.
‎2006 Jul 21 1:13 PM
Hello,
Please look into the example prgrams
BCALV_GRID_DEMO
or you can also see in se38 BCAL*
Reward points if helps.
Thanks,
Krishna
‎2006 Jul 21 1:13 PM
Hi,
Go to SE38 and search for programs using pattern 'BCALV', you will have many examples in the system or use transaction DWDM for sample programs.
Regards
Appana
‎2006 Jul 21 1:17 PM
Hi Joginder,
Just to brief you....
data: OBJ_CNTR_DETAIL TYPE SCRFNAME VALUE 'ZMPGUI_DETAILS_DISPLAY'(this is name of the custom container created in the screen),
OBJ_GRID_DETAIL TYPE REF TO CL_GUI_ALV_GRID,
OBJ_CUSTOM_DETAIL TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
METHOD CREATE_AND_INIT_ALV.
*--Creating the coustom container object to display item details
IF OBJ_GRID_DETAIL IS INITIAL.
CREATE OBJECT OBJ_CUSTOM_DETAIL
EXPORTING CONTAINER_NAME = OBJ_CNTR_DETAIL.
*--Creating the alv grid object to display item details
CREATE OBJECT OBJ_GRID_DETAIL
EXPORTING I_PARENT = OBJ_CUSTOM_DETAIL.
ELSE.
*--Refreshing the item details table displayed using alv grid
CALL METHOD OBJ_GRID_DETAIL->REFRESH_TABLE_DISPLAY.
ENDIF.
END METHOD.
Now after doing this build a fieldcatalog, layout as we do in normal ALV
now to display the ALV
*--displaying the item details
CALL METHOD OBJ_GRID_DETAIL->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = X_LAYOUT
IS_VARIANT = X_VARIANT
I_SAVE = 'A'
CHANGING
IT_FIELDCATALOG = IT_FLDCAT_DETAILS(field catalog)
IT_OUTTAB = IT_ORDERS[](table to be diaplyed).
Hope this helps.
Regards,
Vidya
‎2006 Jul 21 1:57 PM
Hi Joginder,
Here is the sample example for ALV using ABAP Objects.
Alv report to use double click method.
REPORT ZVASU_ALVGRID_INTERACTIVE1 .
DATA: GRID1 TYPE REF TO CL_GUI_ALV_GRID,
G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GT_FCAT TYPE LVC_T_FCAT,
GS_LAYOUT TYPE LVC_S_LAYO.
DATA: BEGIN OF T_VBAK OCCURS 0.
INCLUDE STRUCTURE VBAK.
DATA: END OF T_VBAK.
DATA: OK_CODE LIKE SY-UCOMM,
REPID LIKE SY-REPID.
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS: HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
ENDCLASS.
DATA GR_EVENT_HANDLER TYPE REF TO LCL_EVENT_HANDLER.
SELECT * FROM KNA1 INTO CORRESPONDING FIELDS OF TABLE T_KNA1 UP TO 10 ROWS.
CALL SCREEN 100.
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
METHOD HANDLE_DOUBLE_CLICK.
SET PARAMETER ID 'AAT' FIELD T_VBAK-AUART.
CALL TRANSACTION 'VA01' AND SKIP FIRST SCREEN.
ENDMETHOD.
ENDCLASS.
&----
*& Module ALV_DISPLAY_100 OUTPUT
&----
text
----
MODULE ALV_DISPLAY_100 OUTPUT.
SELECT * FROM VBAK INTO CORRESPONDING FIELDS OF TABLE T_VBAK UP TO 10 ROWS.
PERFORM PREPARE_FIELD_CATALOG CHANGING GT_FCAT.
PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
PERFORM DISPLAY_ALV.
CREATE OBJECT GR_EVENT_HANDLER.
SET HANDLER GR_EVENT_HANDLER->HANDLE_DOUBLE_CLICK FOR GRID1.
*PERFORM DISPLAY_ALV.
ENDMODULE. " ALV_DISPLAY_100 OUTPUT
*CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*
METHOD HANDLE_DOUBLE_CLICK.
LEAVE PROGRAM.
ENDMETHOD.
*ENDCLASS.
&----
*& Form PREPARE_FIELD_CATALOG
&----
text
----
<--P_GT_FCAT text
----
FORM PREPARE_FIELD_CATALOG CHANGING P_GT_FCAT TYPE LVC_T_FCAT.
DATA: T_FCAT TYPE LVC_S_FCAT.
T_FCAT-COL_POS = '1'.
T_FCAT-FIELDNAME = 'VBELN'.
T_FCAT-SCRTEXT_M = 'ORDER_NUM'.
APPEND T_FCAT TO GT_FCAT.
T_FCAT-COL_POS = '2'.
T_FCAT-FIELDNAME = 'ERDAT'.
T_FCAT-SCRTEXT_M = 'ORDER_DATE'.
APPEND T_FCAT TO GT_FCAT.
T_FCAT-COL_POS = '3'.
T_FCAT-FIELDNAME = 'NETWR'.
T_FCAT-SCRTEXT_M = 'ORDER_VALUE'.
APPEND T_FCAT TO GT_FCAT.
T_FCAT-COL_POS = '4'.
T_FCAT-FIELDNAME = 'AUART'.
T_FCAT-SCRTEXT_M = 'ORDER_TYPE'.
APPEND T_FCAT TO GT_FCAT.
ENDFORM. " PREPARE_FIELD_CATALOG
&----
*& Form PREPARE_LAYOUT
&----
text
----
<--P_GS_LAYOUT text
----
FORM PREPARE_LAYOUT CHANGING P_GS_LAYOUT TYPE LVC_S_LAYO.
P_GS_LAYOUT-ZEBRA = 'X'.
P_GS_LAYOUT-GRID_TITLE = 'CUST_REPORT'.
ENDFORM. " PREPARE_LAYOUT
&----
*& Form DISPLAY_ALV
&----
text
----
--> p1 text
<-- p2 text
----
FORM DISPLAY_ALV .
IF G_CUSTOM_CONTAINER IS INITIAL.
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = 'CCCONTAINER'.
CREATE OBJECT GRID1 EXPORTING
I_PARENT = G_CUSTOM_CONTAINER.
CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT = GS_LAYOUT
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
IT_OUTTAB = T_VBAK[]
IT_FIELDCATALOG = GT_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.
CALL METHOD GRID1->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
FINISHED = 1
others = 2
.
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.
ENDFORM. " DISPLAY_ALV
&----
*& Module USER_AFTER_CLICK_100 INPUT
&----
text
----
MODULE USER_AFTER_CLICK_100 INPUT.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
With Regards
Vasu