Question

9
Question You are asking that is it necessary to take custom container on screen for displaying ALV by OOPS method. It all depends on the class you are using . If you are using the class cl_gui_alv_grid then you have to create a screen that containing the custom container. If you are using the class cl_salv_table then don't need to define any custom container for getting the ALV grid. Here I am copying the Example of both the classes . Now its all depends upon you which class you prefer to use. Example 1 : cl_gui_alv_grid * o + Global data definitions for ALV 1. ALV Grid instance reference DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid . * o + 1. Name of the custom control added on the screen DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' . * o + 1. Custom container instance reference DATA gr_ccontainer TYPE REF TO cl_gui_custom_container . * o +

description

Questions

Transcript of Question

QuestionYou are asking that is it necessary to take custom container on screen for displaying ALV by OOPS method.It all depends on the class you are using .If you are using the class cl_gui_alv_grid then you have to create a screen that containing the custom container.If you are using the class cl_salv_table then don't need to define any custom container for getting the ALV grid.Here I am copying the Example of both the classes .Now its all depends upon you which class you prefer to use.Example 1 : cl_gui_alv_grid * o + Global data definitions for ALV 1. ALV Grid instance referenceDATA gr_alvgrid TYPE REF TO cl_gui_alv_grid . * o + 1. Name of the custom control added on the screenDATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV' . * o + 1. Custom container instance referenceDATA gr_ccontainer TYPE REF TO cl_gui_custom_container . * o + 1. Field catalog tableDATA gt_fieldcat TYPE lvc_t_fcat . * o + 1. Layout structureDATA gs_layout TYPE lvc_s_layo . * o + 1. Internal table holding list dataDATA BEGIN OF gt_list OCCURS 0 .INCLUDE STRUCTURE SFLIGHT .*--In further sections, some additional fields will added here*--for some functionalityDATA END OF gt_list .DATA :gt_sflight like standard TABLE OF gt_list.START-OF-SELECTION.CALL SCREEN '0400'.&----

*& Module STATUS_0400 OUTPUT&----

text-

MODULE STATUS_0400 OUTPUT.SET PF-STATUS 'ZMNU'.perform display_alv.ENDMODULE. " STATUS_0400 OUTPUT&----

*& Module USER_COMMAND_0400 INPUT&----

text-

MODULE USER_COMMAND_0400 INPUT.CASE SY-UCOMM.WHEN 'BACK' OR 'EXIT' OR 'RW'.LEAVE PROGRAM.ENDCASE.ENDMODULE. " USER_COMMAND_0400 INPUT&----

*& Form display_alv&----

text-

form display_alv.SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT UP TO 30 ROWS.IF gr_alvgrid IS INITIAL .*----Creating custom container instanceCREATE OBJECT gr_ccontainerEXPORTINGcontainer_name = gc_custom_control_nameEXCEPTIONScntl_error = 1cntl_system_error = 2create_error = 3lifetime_error = 4lifetime_dynpro_dynpro_link = 5others = 6 .IF sy-subrc 0. --Exception handlingENDIF.*----Creating ALV Grid instanceCREATE OBJECT gr_alvgridEXPORTINGi_parent = gr_ccontainerEXCEPTIONSerror_cntl_create = 1error_cntl_init = 2error_cntl_link = 3error_dp_create = 4others = 5 .IF sy-subrc 0. *--Exception handlingENDIF.*----Preparing field catalog.PERFORM prepare_field_catalog CHANGING gt_fieldcat .*----Preparing layout structurePERFORM prepare_layout CHANGING gs_layout .*----Here will be additional preparations*--e.g. initial sorting criteria, initial filtering criteria, excluding*--functionsCALL METHOD gr_alvgrid->set_table_for_first_displayEXPORTING I_STRUCTURE_NAME = 'SFLIGHT' IS_VARIANT = I_SAVE = I_DEFAULT = 'X'is_layout = gs_layout IS_PRINT = IT_SPECIAL_GROUPS = IT_TOOLBAR_EXCLUDING = IT_HYPERLINK =CHANGINGit_outtab = gt_sflight[]it_fieldcatalog = gt_fieldcatEXCEPTIONSinvalid_parameter_combination = 1program_error = 2too_many_lines = 3OTHERS = 4 .IF sy-subrc 0. --Exception handlingENDIF.ELSE .CALL METHOD gr_alvgrid->refresh_table_display EXPORTING IS_STABLE = I_SOFT_REFRESH =EXCEPTIONSfinished = 1OTHERS = 2 .IF sy-subrc 0.*--Exception handlingENDIF.ENDIF .endform. "display_alv&----

*& Form prepare_field_catalog&----

text-

-->PT_FIELDCATtext-

FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .*---Preparing field catalog manually*DATA ls_fcat type lvc_s_fcat .*ls_fcat-fieldname = 'CARRID' .*ls_fcat-inttype = 'C' .*ls_fcat-outputlen = '3' .*ls_fcat-coltext = 'Carrier ID' .*ls_fcat-seltext = 'Carrier ID' .*ls_fcat-drdn_hndl = '1' .*APPEND ls_fcat to pt_fieldcat .*CLEAR ls_fcat .*ls_fcat-fieldname = 'CONNID' .*ls_fcat-ref_table = 'SFLIGHT' .*ls_fcat-ref_table = 'CONNID' .*ls_fcat-outputlen = '3' .*ls_fcat-coltext = 'Connection ID' .*ls_fcat-seltext = 'Connection ID' .*APPEND ls_fcat to pt_fieldcat .*---Preparing field catalog semi-automaticallyDATA ls_fcat type lvc_s_fcat .CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'EXPORTINGi_structure_name = 'SFLIGHT'CHANGINGct_fieldcat = pt_fieldcat[]EXCEPTIONSinconsistent_interface = 1program_error = 2OTHERS = 3.IF sy-subrc 0.*--Exception handlingENDIF.LOOP AT pt_fieldcat INTO ls_fcat .CASE ls_fcat-fieldname .WHEN 'CARRID' .ls_fcat-outputlen = '10' .ls_fcat-coltext = 'Airline Carrier ID' .ls_fcat-drdn_hndl = '1' .MODIFY pt_fieldcat FROM ls_fcat .WHEN 'PAYMENTSUM' .ls_fcat-no_out = 'X' .MODIFY pt_fieldcat FROM ls_fcat .ENDCASE .ENDLOOP .ENDFORM . "prepare_field_catalog&----

*& Form prepare_layout&----

text-

-->PS_LAYOUT text-

FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.ps_layout-zebra = 'X' .ps_layout-grid_title = 'Flights' .ps_layout-smalltitle = 'X' .ENDFORM. " prepare_layoutExample 2: cl_salv_tabledata: gt_outtab type table of sflight.data: toolbar type ref to cl_salv_functions_list .data: gr_table type ref to cl_salv_table.data: lr_aggregations type ref to cl_salv_aggregations.data: lr_groups type ref to cl_salv_sorts .select * from sflight into corresponding fields of table gt_outtab.call method cl_salv_table=>factoryimportingr_salv_table = gr_tablechangingt_table = gt_outtab.lr_aggregations = gr_table->get_aggregations( ).toolbar = gr_table->get_functions( ) .toolbar->set_all(value = if_salv_c_bool_sap=>true).lr_aggregations->clear( ).lr_groups = gr_table->get_sorts( ) .lr_groups->clear( ).try.lr_groups->add_sort(columnname = 'CARRID'position = 8subtotal = abap_truesequence = if_salv_c_sort=>sort_up ).catch cx_salv_not_found cx_salv_data_error cx_salv_existing.endtry.try.lr_aggregations->add_aggregation( columnname = 'SEATSMAX' ).catch cx_salv_not_found cx_salv_data_error cx_salv_existing.endtry.gr_table->display( ).

Containers in sap module poolAs we know thata SAP Container is a control that accommodates other controls, such as the SAP Tree Control, SAP Picture Control, SAP Text edit Control, SAP Splitter Control, and so on. It manages these controls logically in a collection, and provides a physical area in which they are displayed. All controls live in a container. Since containers are themselves controls, you can nest them. There are five kinds of SAP Containers:SAP Custom Container: display controls in an area defined on a normal screen using the Screen Painter. Class: CL_GUI_CUSTOM_CONTAINER. The default size of the control that you place in the Custom Container is the same as that of the container itself.Chk demo program:RSDEMO_CUSTOM_CONTROL

SAP Dialog Box Container: display controls in a modal dialog box or full screen. It is displayed in a movable modelless dialog box which can have a title.Class: CL_GUI_DIALOGBOX_CONTAINERChk demo program:RSDEMO_DIALOGBOX_CONTROLSAP Docking Container: The SAP Docking Container allows you to attach a control to any of the four edges of a screen as a resizable screen area. You can also detach it so that it becomes an independent modal dialog box. Class: CL_GUI_DOCKING_CONTAINERSAP Splitter Container: to display more than one control in a given area by dividing it into cells. Class: CL_GUI_SPLITTER_CONTAINERSAP Easy Splitter Container:this container allows us to divide an area into two cells with a control in each. The cells are separated by a moveable splitter bar.Class: CL_GUI_EASY_SPLITTER_CONTAINER.For e.g.CREATE OBJECT EXPORTINGparent = rows = columns = .Here we display the functionality of docking container.SAP Docking container can be attached on or more areas of screen. To reattach the docking container to a different edge of the screen we use DOCK_AT method. To switch the status of the Docking Container between fixed (docking) and free (floating) we use the method FLOAT.

CL_GUI_ALV_GRID:This is a control.The ALV grid control tool allows you to display and print non-hierarchial lists in a standardized format.The list data is displayed as a table on the screen.Chk demo program:BCALV*For ALV:http://www.sapdevelopment.co.uk/reporting/alvhome.htm