Anda di halaman 1dari 8

Welcome, Guest Login Register

Getting Started Newsletters Store


Search the Comm

Solutions SAP Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Innovation

Browse 1. My Home > 2. Code Gallery > 3. ABAP-7 Steps to create OOPS ALV(for beginners)

Tools

ABAP-7 Steps to create OOPS ALV(for beginners)



Attachments:7 Added by Jayanthi Jayaraman, last edited by Craig Cmehil on Sep 12, 2007 (view change) Author: Jayanthi Jayaraman Submitted: 15.06.07 Related Links:

o o o
http://help.sap.com/saphelp_47x200/helpdata/en/0a/b5533cd30911d2b467006094192fe3/frameset.htm https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907 https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b6cae890-0201-0010-ef8b-f970a9c41d47 Description 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.

CREATE OBJECT o_docking EXPORTING * * * * * * * * * PARENT REPID DYNNR SIDE EXTENSION STYLE LIFETIME CAPTION METRIC RATIO = = = = DOCK_AT_LEFT = 50 = = lifetime_default = =0 = '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.

Step 2: Create a grid inside the container. Use Pattern button to create the same. Make the parent of grid as container.

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. 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 = '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. Step 4: Call the method of grid set_table_for_first_display to display the output.

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. 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 as below. Create GUI Title if required.

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.

Complete Code
data : 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. if o_docking is initial. 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. 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

Labels
tutorial oops alv

Follow SCN
Contact Us SAP Help Portal Privacy Terms of Use Legal Disclosure Copyright