You are on page 1of 9

Field catalog in ALV(OOPS)

Attachments:3 Added by Jayanthi Jayaraman, last edited by Jayanthi Jayaraman on Jul 26, 2007 (view change)

Author: J.Jayanthi Submitted: 26-July-07 Related Links: ABAP-7 Steps to create OOPS ALV(for beginners) Description: This document describes how to do some of the changes we can do in field catalog in ALV using OOPS method.

Procedure
Coltext : Determines the column header of the column. You should assign a value to this field if it does not have a Data Dictionary reference. LOOP AT i_fieldcat ASSIGNING . CASE <fs_fieldcat>-fieldname. when 'FULLTIMEEMPLOYEE'. -coltext = 'Fulltime'. ENDCASE. ENDLOOP. This will make the description of field FULLTIMEEMPLOYEE will appear as Fulltime in output. Checkbox: Making the particular field appear as checkbox in output if set. The checkbox cannot be modified by the user. LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'FULLTIMEEMPLOYEE'. -checkbox = 'X'. ENDCASE. ENDLOOP. Edit: Making the particular field as editable if set. LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'FULLTIMEEMPLOYEE'. -edit = 'X'. ENDCASE.

ENDLOOP. Outputlen: Changing the particular field output length. Determines the column width of the field: ? If the field has a reference to the Data Dictionary, you can leave the field set to its initial value. In this case, the ALV adopts the output length of the relevant domain. ? For fields without reference to the DDIC, you must specify the desired field output length. LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'FULLTIMEEMPLOYEE'. -outputlen = '8'. ENDCASE. ENDLOOP. Key: Making a field as key field if set or non-key field if not set. If this field is set, the ALV Grid Control color-codes the column as a key field and fixes this column during horizontal scrolling. The order of the key columns in the ALV Grid Control can be modified interactively. In contrast to the SAP List Viewer, the ALV Grid Control allows you to directly hide key columns with NO_OUT. LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'ENO'. -key = ' '. ENDCASE. ENDLOOP. No_out: If you set this field, you hide the relevant column in the list. Nevertheless, the column is available in the field selection and can be interactively selected by the user as a display field. The ALV displays the contents of hidden fields on the detail screen for a row in the grid control.LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'AGE'. <fs_fieldcat>-no_out = 'X'. ENDCASE. ENDLOOP. In change layout, the user can select the column and then make the field to appear in output. Just: Relevant only to fields of data type CHAR or NUMC. Justifications: ? 'R': right justified ? 'L': left justified ? 'C': centered How the column header is justified, depends on how the column contents are justified. You cannot justify the column header separately. LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'AGE'. <fs_fieldcat>-just = 'R'. ENDCASE.

ENDLOOP. Now in the output, Age field will come as Right-Justified. Tech: If this field is set, the relevant field is not displayed on the list and cannot be shown interactively. The field is only known in the field catalog. (For example, it must not be specified as a sorting criterion). LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'GENDER'. <fs_fieldcat>-tech = 'X'. ENDCASE. ENDLOOP. If tech is set for a field, the user cannot even select the field in change layout. Emphasize: If the field is set to 'X', the ALV uses a pre-defined color for highlighting the column. If it is set to 'Cxyz' (color code), the remaining numbers have the following meaning: ? x: color number ? y: intensified display on/off ? z: inverse display on/off LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'SALARY'. <fs_fieldcat>-emphasize = 'C411'. ENDCASE. ENDLOOP. Do_sum: If this field is set, the ALV uses this field to calculate the total (this corresponds to the generic totals function in the toolbar.) LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'SALARY'. <fs_fieldcat>-do_sum = 'X'. ENDCASE. ENDLOOP. Tooltip: Determines the text to be used as the tool tip for the column. You should assign a value to this field if it does not have a Data Dictionary reference. LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'ENAME'. <fs_fieldcat>-TOOLTIP = 'Emp. Name'. ENDCASE. ENDLOOP. Eventhough tooltip will appear other fields from field label/Coltext, if tooltip is set, it will override the other values. The database table structure is as follows.

Complete Code
Screen 9000, GUI Status ZSTATUS and GUI Title ZTITLE should be created and in Flow logic of the screen, PBO and PAI should be uncommented. REPORT zzz_jaytest message-id zz. * Data declarations DATA : itab TYPE STANDARD TABLE OF zzztable,"Output table i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,"Field catalog wa TYPE zzztable, 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 FIELD-SYMBOLS : <fs_fieldcat> TYPE lvc_s_fcat. SELECT * FROM zzztable INTO TABLE itab. CALL SCREEN 9000. *&---------------------------------------------------------------------* *& Module STATUS_9000 OUTPUT *&---------------------------------------------------------------------* * PBO *----------------------------------------------------------------------* MODULE status_9000 OUTPUT. IF o_docking IS INITIAL. SET PF-STATUS 'ZSTATUS'. "GUI Status SET TITLEBAR 'ZTITLE'. "Title * Creating Docking Container and grid PERFORM create_object. * Filling the fieldcatalog table PERFORM create_fieldcat. * Modifying the fieldcatalog table

PERFORM modify_fieldcat. * Displaying the output PERFORM display_output. 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 create_object *&---------------------------------------------------------------------* * Creating Docking Container and grid *----------------------------------------------------------------------* FORM create_object . * 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. ENDFORM. " create_object *&---------------------------------------------------------------------* *& Form create_fieldcat *&---------------------------------------------------------------------* * Filling the fieldcatalog table *----------------------------------------------------------------------* FORM create_fieldcat .

* Filling the fieldcatalog table CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'ZZZTABLE' CHANGING ct_fieldcat = i_fieldcat EXCEPTIONS inconsistent_interface = 1 program_error =2 OTHERS = 3. ENDFORM. " create_fieldcat *&---------------------------------------------------------------------* *& Form modify_fieldcat *&---------------------------------------------------------------------* * Making the column as ediable *----------------------------------------------------------------------* FORM modify_fieldcat . LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. CASE <fs_fieldcat>-fieldname. when 'FULLTIMEEMPLOYEE'. <fs_fieldcat>-checkbox = 'X'. <fs_fieldcat>-coltext = 'Fulltime'. <fs_fieldcat>-edit = 'X'. <fs_fieldcat>-outputlen = '8'. when 'ENO'. <fs_fieldcat>-key = ' '. <fs_fieldcat>-coltext = 'Employee Number'. <fs_fieldcat>-edit = ' '. when 'AGE'. <fs_fieldcat>-no_out = 'X'. <fs_fieldcat>-coltext = 'Age'. <fs_fieldcat>-edit = 'X'. <fs_fieldcat>-just = 'R'. when 'GENDER'. <fs_fieldcat>-coltext = 'Gender'. <fs_fieldcat>-outputlen = '6'. <fs_fieldcat>-tech = 'X'. when 'SALARY'. <fs_fieldcat>-emphasize = 'C411'. <fs_fieldcat>-do_sum = 'X'. <fs_fieldcat>-coltext = 'Salary'. <fs_fieldcat>-edit = 'X'. when 'ENAME'. <fs_fieldcat>-coltext = 'Employee Name'. <fs_fieldcat>-edit = 'X'. <fs_fieldcat>-TOOLTIP = 'Emp. Name'.

ENDCASE. ENDLOOP. ENDFORM. " modify_fieldcat *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form display_output *&---------------------------------------------------------------------* * Displaying the output *----------------------------------------------------------------------* FORM display_output . w_variant-report = sy-repid. * Displaying the output CALL METHOD o_grid->set_table_for_first_display EXPORTING is_variant = w_variant i_save ='' 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. ENDFORM. " display_output *&---------------------------------------------------------------------* *& 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

Output

Coltext makes the header of the output as described. Edit makes the employee no. to be non-editable whereas other fields are editable. No_out makes the field AGE not appearing in layout. Whereas the user can select that field from change layout. Tech makes the field Gender not appearing in layout. The user cannot even select that field from change layout.

Outputlen extending the column length in output as mentioned. Do_sum calculates the total of salary as 188,000.00. Emphasize colors the Salary field.

Checkbox makes the field Fulltime appear as Checkbox. Just = 'R' does the right Justification of field Age. Tooltip makes the Emp. Name to appear as tool tip for Employee Name. Key = ' ' makes the Employee no. field to appear as non-key column. Because of this, we cannot the see the default blue color for Key field.

Labels

You might also like