07-27-2007 7:31 AM
can anybody explain me oops in ALV. do not have knowledge at all on that topic. i would like to have a detailed description on it. Thanks in advance.
07-31-2007 10:28 AM
Hi sandhya rani,
Please read the following steps to build OOPS based ALV.
I hope they really easy to follow.
<b><u>7 Steps to create OOPS ALV</u></b>
Applies to:
SAP R/3Enterprise Version
<b>Summary</b>
This document describes how to create an ALV using OOPS method in few steps. It will help the beginners to start with.
<b>Procedure</b>
<b>
<b>Step 1:</b> Create a container. There are 2 containers. They are docking and custom.</b>
For eg.. Create docking container.
Go to SE38.Create a program. Use Pattern button to create object for docking container. Click ABAP Object Pattern radio button.Click Create object radio button.Give Instance as o_docking and class as cl_gui_docking_contianer.
CREATE OBJECT o_docking
EXPORTING
PARENT =
REPID =
DYNNR =
SIDE = DOCK_AT_LEFT
EXTENSION = 50
STYLE =
LIFETIME = lifetime_default
CAPTION =
METRIC = 0
RATIO = '95'
NO_AUTODEF_PROGID_DYNNR =
NAME =
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
<b>Step 2: Create a grid inside the container.</b>
Use Pattern button to create the same. Make the parent of grid as container.
Click ABAP Object Pattern radio button.Click Create object radio button.Give Instance as o_grid and class as cl_gui_alv_grid.
CREATE OBJECT o_grid
EXPORTING
I_SHELLSTYLE = 0
I_LIFETIME =
i_parent = o_docking
I_APPL_EVENTS = space
I_PARENTDBG =
I_APPLOGPARENT =
I_GRAPHICSPARENT =
I_NAME =
EXCEPTIONS
ERROR_CNTL_CREATE = 1
ERROR_CNTL_INIT = 2
ERROR_CNTL_LINK = 3
ERROR_DP_CREATE = 4
others = 5
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
<b>Step 3: Call the function LVC_FIELDCATALOG_MERGE to get the fieldcatalog.</b>
Pass the structure name.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'MARA'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = i_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
<b>Step 4: Call the method of grid set_table_for_first_display to display the output.</b>
Click ABAP Object Pattern radio button.Click Call Method radio button.Give Instance as o_grid and Class/Interface as cl_gui_alv_grid and Method as set_table_for_first_display.
w_variant-report = sy-repid.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT = w_variant
I_SAVE = 'A'
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
it_outtab = itab
IT_FIELDCATALOG = i_fieldcat
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.
<b>Step 5: Fill the internal table itab with values by using logic.</b>
select * from mara into table itab up to 100 rows.
call screen 9000.
Create a screen by double clicking 9000 in the above line. Fill the description for the screen. In the flow logic, uncomment the PBO and PAI module and create those in main program (for simplicity).
<b>Step 6: Create GUI status. Create GUI Title if required.That can be done by using Display object List(CtrlShiftF5).Then in left side,right click the program and create GUI Status and Title.</b>
<b>Step 7: Free the memory occupied once the 'BACK, EXIT' or 'CANCEL' button is clicked. Use Pattern button to call the method 'FREE' of cl_gui_alv_grid and cl_gui_docking_container.</b>
Click ABAP Object Pattern radio button.Click Call Method radio button.Give Instance as o_grid and Class/Interface as cl_gui_alv_grid and Method as Free.Similarly Click Call Method radio button.Give Instance as o_docking and Class/Interface as cl_gui_docking_container and Method as Free.
Complete Code
*Data Declarationsdata : itab type standard table of mara,"Output Internal table
i_fieldcat type standard table of lvc_s_fcat,"Field catalog
wa type mara,
w_variant type disvariant,
o_docking type ref to cl_gui_docking_container,"Docking Container
o_grid type ref to cl_gui_alv_grid."Grid
select * from mara into table itab up to 100 rows.
call screen 9000.
&----
*& Module STATUS_9000 OUTPUT
&----
text
----
module STATUS_9000 output.
SET PF-STATUS 'ZSTATUS'. "GUI Status
SET TITLEBAR 'ZTITLE'. "Title
Creating Docking Container
CREATE OBJECT o_docking
EXPORTING
RATIO = '95'.
IF sy-subrc eq 0.
Creating Grid
CREATE OBJECT o_grid
EXPORTING
i_parent = o_docking.
ENDIF.
Filling the fieldcatalog table
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
CHANGING
ct_fieldcat = i_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
w_variant-report = sy-repid.
Displaying the output
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
IS_VARIANT = w_variant
I_SAVE = 'A'
CHANGING
it_outtab = itab
IT_FIELDCATALOG = i_fieldcat
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.
endmodule. " STATUS_9000 OUTPUT
&----
*& Module USER_COMMAND_9000 INPUT
&----
PAI
----
module USER_COMMAND_9000 input.
data lv_ucomm type sy-ucomm.
lv_ucomm = sy-ucomm.
CASE lv_ucomm.
WHEN 'CANCEl' OR 'EXIT'.
perform free_objects.
LEAVE PROGRAM.
when 'BACK'.
perform free_objects.
set screen '0'.
leave screen.
ENDCASE.
endmodule. " USER_COMMAND_9000 INPUT
&----
*& Form free_objects
&----
Free Objects
----
form free_objects .
CALL METHOD o_grid->free
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
others = 3.
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 o_docking->free
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
others = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform. " free_objects
If useful plz assign points.
Thanks & Regards
jayaprakash j
07-31-2007 12:19 PM
Hi sandhya,
Read this document..U'll get an idea about ALV.
For object oriented concepts refer this link https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b6cae890-0201-0010-ef8b-f970a9c4...
Assign points if useful..
regards,
Archna
07-31-2007 12:21 PM
Hi,
The first link i gave has oops alv also