Anda di halaman 1dari 6

http://wiki.sdn.sap.

com/wiki/display/ABAP/7+steps+to+create+OOPS+ ALV
7 steps to create OOPS ALV

Added by Jayanthi Jayaraman, last edited by Jayanthi Jayaraman on Jun 13, 2007 7 Steps to create OOPS ALV

Applies to:
SAP R/3Enterprise Version

Summary
This document describes how to create an ALV using OOPS method in few steps. It will help the beginners to start with.

Procedure
Step 1: Create a container. There are 2 containers. They are docking and custom. 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 EXTENSION STYLE LIFETIME CAPTION METRIC RATIO * * * * * = = lifetime_default = =0 = '95' = = = = DOCK_AT_LEFT = 50 =

NO_AUTODEF_PROGID_DYNNR NAME CNTL_ERROR CNTL_SYSTEM_ERROR CREATE_ERROR =3 = =1 =2

* EXCEPTIONS

* * * .

LIFETIME_ERROR others =6

=4

LIFETIME_DYNPRO_DYNPRO_LINK = 5

IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * ENDIF. Step 2: Create a grid inside the container. 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 * * * * * * * * * * * * . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * ENDIF. Step 3: Call the function LVC_FIELDCATALOG_MERGE to get the fieldcatalog. Pass the structure name. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING * I_BUFFER_ACTIVE I_STRUCTURE_NAME * I_CLIENT_NEVER_DISPLAY * I_BYPASSING_BUFFER = = = 'MARA' = 'X' WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. I_SHELLSTYLE I_LIFETIME i_parent = = o_docking = space = = =0 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

I_APPL_EVENTS I_PARENTDBG I_APPLOGPARENT I_NAME =

I_GRAPHICSPARENT =

* EXCEPTIONS ERROR_CNTL_CREATE = 1 ERROR_CNTL_INIT = 2 ERROR_CNTL_LINK = 3 ERROR_DP_CREATE = 4 others =5

* I_INTERNAL_TABNAME CHANGING ct_fieldcat * EXCEPTIONS * INCONSISTENT_INTERFACE * PROGRAM_ERROR * OTHERS . IF sy-subrc <> 0. =3 = i_fieldcat

=1 =2

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. Step 4: Call the method of grid set_table_for_first_display to display the output. 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 I_SAVE * * * * * * * * I_DEFAULT IS_LAYOUT IS_PRINT IT_SPECIAL_GROUPS IT_TOOLBAR_EXCLUDING IT_HYPERLINK IT_ALV_GRAPHICS IT_EXCEPT_QINFO CHANGING it_outtab IT_FIELDCATALOG * * * * * IT_SORT IT_FILTER EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR =2 = = = itab = i_fieldcat = = = = = = = 'A' = 'X' = = = w_variant = = =

* *

TOO_MANY_LINES others . IF sy-subrc <> 0. =4

=3

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * ENDIF. Step 5: Fill the internal table itab with values by using logic. 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). Step 6: Create GUI status. Create GUI Title if required.That can be done by using Display object List(Ctrl+Shift+F5).Then in left side,right click the program and create GUI Status and Title. 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. 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. WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

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 ENDIF. * Filling the fieldcatalog table CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME CHANGING ct_fieldcat EXCEPTIONS INCONSISTENT_INTERFACE PROGRAM_ERROR OTHERS * Displaying the output CALL METHOD o_grid->set_table_for_first_display EXPORTING IS_VARIANT I_SAVE CHANGING it_outtab IT_FIELDCATALOG EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR TOO_MANY_LINES others 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. = 4. =2 =3 = itab = i_fieldcat = w_variant = 'A' = 3. w_variant-report = sy-repid. =2 =1 = i_fieldcat = 'MARA' = o_docking.

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 others = 3. =1 CNTL_SYSTEM_ERROR = 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. CALL METHOD o_docking->free EXCEPTIONS CNTL_ERROR others = 3. =1 CNTL_SYSTEM_ERROR = 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.
endform. " free_objects

Anda mungkin juga menyukai