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.

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

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

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

CASE lv_ucomm. " STATUS_9000 OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_9000 INPUT *&---------------------------------------------------------------------* * PAI *----------------------------------------------------------------------* MODULE user_command_9000 INPUT. * Creating Docking Container CREATE OBJECT o_docking EXPORTING ratio = '95'. WHEN 'BACK'. " create_object *&---------------------------------------------------------------------* *& Form create_fieldcat *&---------------------------------------------------------------------* * Filling the fieldcatalog table *----------------------------------------------------------------------* FORM create_fieldcat . LEAVE SCREEN. ENDMODULE. . DATA lv_ucomm TYPE sy-ucomm. * Displaying the output PERFORM display_output. ENDCASE. WHEN 'CANCEl' OR 'EXIT'. ENDMODULE. lv_ucomm = sy-ucomm. PERFORM free_objects. IF sy-subrc EQ 0. ENDFORM. ENDIF. * Creating Grid CREATE OBJECT o_grid EXPORTING i_parent = o_docking. PERFORM free_objects.PERFORM modify_fieldcat. ENDIF. LEAVE PROGRAM. " USER_COMMAND_9000 INPUT *&---------------------------------------------------------------------* *& Form create_object *&---------------------------------------------------------------------* * Creating Docking Container and grid *----------------------------------------------------------------------* FORM create_object . SET SCREEN '0'.

when 'ENO'. <fs_fieldcat>-no_out = 'X'. <fs_fieldcat>-do_sum = 'X'. <fs_fieldcat>-coltext = 'Age'. ENDFORM. <fs_fieldcat>-coltext = 'Gender'. . when 'FULLTIMEEMPLOYEE'. <fs_fieldcat>-outputlen = '6'. <fs_fieldcat>-tech = 'X'. when 'GENDER'.* 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. <fs_fieldcat>-coltext = 'Fulltime'. " create_fieldcat *&---------------------------------------------------------------------* *& Form modify_fieldcat *&---------------------------------------------------------------------* * Making the column as ediable *----------------------------------------------------------------------* FORM modify_fieldcat . <fs_fieldcat>-coltext = 'Employee Number'. <fs_fieldcat>-edit = 'X'. when 'SALARY'. <fs_fieldcat>-key = ' '. <fs_fieldcat>-edit = 'X'. <fs_fieldcat>-edit = ' '. <fs_fieldcat>-outputlen = '8'. <fs_fieldcat>-just = 'R'. <fs_fieldcat>-coltext = 'Employee Name'. CASE <fs_fieldcat>-fieldname. <fs_fieldcat>-edit = 'X'. <fs_fieldcat>-TOOLTIP = 'Emp. Name'. <fs_fieldcat>-checkbox = 'X'. <fs_fieldcat>-edit = 'X'. <fs_fieldcat>-emphasize = 'C411'. when 'AGE'. <fs_fieldcat>-coltext = 'Salary'. LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>. when 'ENAME'.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. " modify_fieldcat *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form display_output *&---------------------------------------------------------------------* * Displaying the output *----------------------------------------------------------------------* FORM display_output . CALL METHOD o_grid->free EXCEPTIONS cntl_error =1 cntl_system_error = 2 OTHERS = 3. ENDIF. IF sy-subrc <> 0. w_variant-report = sy-repid. ENDIF. ENDLOOP. IF sy-subrc <> 0.ENDCASE. CALL METHOD o_docking->free EXCEPTIONS . MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDFORM. " display_output *&---------------------------------------------------------------------* *& Form free_objects *&---------------------------------------------------------------------* * Free Objects *----------------------------------------------------------------------* FORM free_objects . * 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. ENDFORM.

Emphasize colors the Salary field. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. IF sy-subrc <> 0. Outputlen extending the column length in output as mentioned. to be non-editable whereas other fields are editable. .000. Edit makes the employee no. No_out makes the field AGE not appearing in layout. " free_objects Output Coltext makes the header of the output as described. ENDIF.cntl_error =1 cntl_system_error = 2 OTHERS = 3.00. Do_sum calculates the total of salary as 188. 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. ENDFORM.

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