Ads

Defining Output Fields Characteristics of ALV Report in SAP ABAP

Defining Output Fields Characteristics of ALV Report in SAP ABAP


 In the Previous Post ,we have learnt,ALV Reports Data Declaration,Selecting Optional Variants and now here ,we will learn output fields descriptions which defines the description of fields that resulted in the ALV output.

DEFININING OUTPUT CHARACTERISTICS: PREPARING DISPLAY FIELDS CATALOG

A field catalog is prepared using the internal table (I_FIELDCAT) of type SLIS_T_FIELDCAT_ALV.


Field catalog containing descriptions of the list output fields (usually a subset of the internal output table fields).


 A field catalog is required for every ALV list output to add desired functionality (i.e. Key, Hotspot, Specific headings, Justify, Col. position etc) to certain fields of the output. If not mentioned specifically, then the defaults are taken. The possible values and defaults are listed below.


The field catalog for the output table is built-up in the caller's coding. The build-up can be completely or partially automated by calling the
REUSE_ALV_FIELDCATALOG_MERGE module.


The minimal field catalog is documented below. This can be done in a routine using a local variable. The user can use the other optional parameters to assign output attributes to different fields in the output, which differ from the default.


 A field catalog need not be built-up and passed explicitly only under the following conditions:

1.    The internal table to be output has the same structure as a Data Dictionary structure which is referred to in the internal table declaration using LIKE or INCLUDE STRUCTURE. In this case the attributes of the different fields is taken directly from the table and the attributes (key fields, length, texts etc) need to state explicitly.


 2.    All fields in this structure are to be output
 3.    The structure name is passed to ALV in the parameter I_STRUCTURE_NAME of the function module REUSE_ALV_LIST_DISPLAY.

All the values entered in the catalog are specific to the particular field whose name is entered in the fieldname FIELDNAME of the fieldcat structure. The name of the table is also entered in the corr. Fieldname TABNAME of the structure.


 The different possible attributes are:
 -          Row_pos (row position): Only relevant if the list output is to be multi-line (two or three lines) by default. So, this attribute can be used maintain certain level of alignment in the output.
                   Value set: 0, 1 - 3
 -          Col_pos (column position): This parameter is relevant when the fields in the output are to be different from the sequence of the fields in the internal table used for display.       The parameter specifies the relative column position of the field in the list output. The column order can be changed interactively by the user. If this parameter is initial for all field catalog entries, columns appear in the internal table field sequence.
Value set: 0, 1 - 60
 -          Field name (field name): This is the name of the internal table field for which the parameters are passed in the catalog.
Value set: internal output table field name (required parameter)
                     
-          Tabname (internal output table): Name of the internal output table that contains the field FIELDCAT-FIELDNAME above.


                   Value set: SPACE, internal output table name.

 -          Ref_fieldname (reference field name): Name of the Data Dictionary field referred to. This parameter is only used when the internal output table field described by the current field catalog entry has a reference to the Data Dictionary (not a program field), and the field name in the internal output table is different from the name of the field in the Data Dictionary. If the field names are identical, naming the Data Dictionary structure or table in the FIELDCAT-REF_TABNAME parameter is sufficient.


    Value set: SPACE, Data Dictionary field name.

 -          Ref_tabname (reference table/structure field name): Structure or table name of the referred Data Dictionary field. This parameter is only used when the internal output table field described by the current field catalog entry has a Data Dictionary reference (not a program field).
Value set: SPACE, name of a Data Dictionary structure or table


Link to currency unit
-          Cfieldname (currency unit field name): This is used for currency fields that have a reference to any unit field. This is only relevant for amount columns with associated unit. This parameter contains the Name of the internal output table field containing the currency unit associated with the amount field FIELDCAT-FIELDNAME. The field in FIELDCAT-CFIELDNAME must have its own field catalog entry.


Value set: SPACE, output table field name.
 -          Ctabname (internal currency unit field output table): Name of the internal output table containing the FIELDCAT-CFIELDNAME field.
Value set: SPACE, output table field name.

             Link to measurement unit
-          Qfieldname (measurement unit field name): Only relevant for quantity columns with unit link. Name of the internal output table field containing the measurement unit associated with the quantity field FIELDCAT-FIELDNAME. The field in FIELDCAT-QFIELDNAME must have its own field catalog entry.

Value set: SPACE, output table field name.
 -          Qtabname (internal measurement unit field output table): Name of the internal output table containing the FIELDCAT-QFIELDNAME field.
 Value set: SPACE, output table field name.

 -          Outputlen (column width): This parameter is used if the desired output length for a field is desired to be different from the internal output table field. For fields with a Data Dictionary link this parameter can be left initial. For fields without a Data Dictionary link (program field) the parameter must be given the value of the desired field list output length (column width).
Initial = column width is the output length of the referred Data Dictionary field (domain).
N = column width is n characters.

      Value set: 0 (initial), n.
 -          Key (key column): By default, the system makes some fields in the output as key fields, provided the fields are key fields in their referencing table. Using this parameter, fields other than key fields of the referencing table can be made key field. This parameter is most important if the output needs to contain some field, which are not scrollable or cannot be hidden.
If the internal output table contains fields that are key fields from different tables, then all those fields in the report output becomes un-scrollable and cannot be hidden. So, the fields in the output internal table should not be referenced from tables in which they are key fields. Instead, they should be referenced to the tables in which they are not key fields, incase they are not desired as key field in the output.


'X' = key field (key field output in color) and Key fields cannot be interactively hidden. Parameter FIELDCAT-NO_OUT must be left initial.


      Value set: SPACE, 'X'.


 -          Key_sel (hide-able key column): This parameter is only relevant for the fields which are made key fields using FIELDCAT-KEY = 'X'. Using this parameter the Key field can be hidden interactively.
The key column sequence cannot be changed interactively by the user. The output is controlled by the FIELDCAT-NO_OUT parameter analogously to non-key fields.


Value set: SPACE, 'X'.

 -          No_out (field in field list): This parameter is used to remove certain fields from the output during initial display.  The user can however interactively choose the field for output from the field list in the display variant.
                   'X' = field is not displayed in the current list.
        Value set: SPACE, 'X'.
 -          Tech (technical field): This parameter is used to make certain field display only in the field catalog. The fields with this parameter set cannot be output in the list nor can they be displayed interactively from the catalog.
                    'X' = technical field.
       Value set: SPACE, 'X'.

 -          Emphasize (highlight columns in color): As name suggests, this field parameter is used to highlight certain field with chosen colors.
Value set: SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off ,'1'=on).
'X' = column is colored with the default column highlight color.
                   'Cxyz' = column is colored with a coded color:
                         -  C: Color (coding must begin with C)
                         -  X: color number
                         -  Y: bold
                         -  Z: inverse

 -          Hotspot (column as hotspot): This parameter is used to make certain field appear as hotspot i.e. a hand is displayed if the cursor is positioned on the field value. Single click on such fields cause the PICK OR F2 events to happen.
         Value set: SPACE, 'X'.
                    'X' = column cells are output as hotspots.

 -          Fix_column (fix column): This parameter is used to fix certain columns in the output. All columns to be fixed must have this flag, starting from the left. If a column without this flag is output, only the columns to the left of this column are fixed. The user can change the column fixing interactively.
                   Value set: SPACE, 'X'.
        'X' = column fixed (does not scroll horizontally).
     
-          Do_sum (sum over column): the user can also call this function interactively.
             Value set: SPACE, 'X'.
'X' = a sum is calculated over this internal output table field.
 -          No_sum (sums forbidden): No sum can be calculated over this field, although the data type of the field would allow summing.
         Value set: SPACE, 'X'.
 -          Icon: The parameter displays certain column contents as icons. The internal output table column contents must be valid icon strings.
                    Value set: SPACE, 'X'.
                     'X' = column contents to be output as an icon.
 -          Symbol: The internal output table column must be a valid symbol character.
Value set: SPACE, 'X'
                   'X' = column contents are to be output as a symbol.
 -          Just (justification): This parameter is used for alignment of the contents of the output table. This is only relevant for CHAR or NUMC fields in the output internal table. The justification of the column header always follows the justification of the columns. Independent justification of the column header is not possible.
Value set: SPACE, 'R', 'L', and 'C'.
       ' ' = Default justification for this data type
       'R' = right-justified output
       'L' = left-justified output
       'C' = centered output.

-          Lzero (leading zeros): By default ALV outputs NUMC fields right-justified without leading zeros. Using this parameter only the NUMC fields can be displayed with leading zeroes.
                   Value set: SPACE, 'X'.
                    'X' = output with leading zeros.
 -          No_sign (no +/- sign): This parameter is used to suppress the signs of the output fields. It is only relevant for the value fields.
    Value set: SPACE, 'X'.
                  'X' = value output without +/ sign.
 -          No_zero (suppress zeros): Only relevant for value fields.
             Value set: SPACE, 'X'.
                    'X' = suppress zeros.
 -          Edit_mask (field formatting): To apply the report output formatting options same as in the WRITE statement in report writing.
           Value set: SPACE, template.

The following parameters are used for customizing the texts in the heading of the output of the columns. The texts are taken from the Data Dictionary for fields with a Data Dictionary reference. If this is not desired, the text parameters can also be specified. The Data Dictionary texts are then ignored.


If the user changes the column width interactively, the column header text with the appropriate length is always used.
The interactive function 'Optimize column width' takes account of both the field contents and the column headers: if all field contents are shorter than the shortest column header, the column width depends on the column header.
      The 'long field label' is also used in display variant definition,
        Sort, etc.  Popup.
 -          seltext_l (long field label)
 -          seltext_m (medium field label)
 -          seltext_s (short field label)
 -          reptext_ddic (header) Analogous to the Data element main header
 -          Ddictxt (specify text): You can specify with values 'L', 'M', and 'S', the keyword that should always be used as column header. If the column width changes, no attempt is made in this case to find an appropriate header for the new output width.
Value set: SPACE, 'L', 'M', and 'S'.
 Sample code:
*&---------------------------------------------------------------------*
*&      Form SUB_PREPARE_FIELDCATALOG
*&---------------------------------------------------------------------*
* Prepare field catalog for the main report. State the name of the field, name of internal table, various formatting options etc
*----------------------------------------------------------------------*
Form SUB_PREPARE_FIELDCATALOG.
  X_FIELDCAT-COL_POS = 1.                          * First field to appear in ALV list
  X_FIELDCAT-FIELDNAME           = 'SYM'.                 * Name of the internal table field
  X_FIELDCAT-TABNAME              = 'I_TAB'.              * Name of the internal table
  X_FIELDCAT-SELTEXT_M           = 'Stat'.                   * Heading for the field
  X_FIELDCAT-SYMBOL = 'X'.                       * The field is going to contain a symbol
* Append the specifications to the internal table for field catalog.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 2.                                          * Second field to appear in ALV list
X_FIELDCAT-FIELDNAME             = 'MATNR'.           * Name of the field in the internal table
X_FIELDCAT-TABNAME                = 'I_TAB'.              * Name of the internal table
X_FIELDCAT-SELTEXT_M             = 'MatItem'.           * Heading for the column
* It is going to be the key field.The color for this field is going to be different
X_FIELDCAT-KEY                             = 'X'.
X_FIELDCAT-KEY_SEL    = 'X'.
* Single click on the field will trigger double click event. Also, a hand will appear when the cursor navigates to the field
X_FIELDCAT-HOTSPOT = 'X'.
X_FIELDCAT-FIX_COLUMN          = 'X'.                       * The column and those left to it will not scroll
X_FIELDCAT-REF_TABNAME      = 'MSEG'.               * F1 help will come as it is referenced to DDIC table
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 3.
X_FIELDCAT-FIELDNAME             = 'MAKTG'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Description'.
* X_FIELDCAT-OUTPUTLEN          = 50.
X_FIELDCAT-HOTSPOT = space.
X_FIELDCAT-JUST                            = 'C'.        * The field is centre(C for centre, R and L for left and right) justified
X_FIELDCAT-KEY                             = 'X'.
X_FIELDCAT-FIX_COLUMN          = 'X'.
*X_fieldcat-no_out                             = 'X'.
X_FIELDCAT-FIX_COLUMN          = 'X'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 4.
X_FIELDCAT-FIELDNAME             = 'CHARG'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Batch'.
* X_FIELDCAT-OUTPUTLEN          = 10.
X_FIELDCAT-HOTSPOT = space.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 5.
X_FIELDCAT-FIELDNAME             = 'EBELN'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Purchase Order'.
* X_FIELDCAT-OUTPUTLEN          = 14.
X_FIELDCAT-EMPHASIZE              = 'C511'.                  * The field will be colored differently (Cxyz)
X_FIELDCAT-NO_OUT                    = 'X'.                       * Initially the field will be hidden
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 6.
X_FIELDCAT-FIELDNAME             = 'MBLNR'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Document no'.
* X_FIELDCAT-OUTPUTLEN          = 14.
X_FIELDCAT_EMPHASIZE             = 'C711'.
X_FIELDCAT-NO_OUT    = 'X'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 7.
X_FIELDCAT-FIELDNAME             = 'WERKS'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Plant'.
* X_FIELDCAT-OUTPUTLEN          = 5.
X_FIELDCAT-EMPHASIZE              = 'C310'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 8.
X_FIELDCAT-FIELDNAME             = 'LGORT'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'St.Loc'.
* X_FIELDCAT-OUTPUTLEN          = 7.
* X_FIELDCAT-NO_OUT                 = 'X'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-COL_POS   = 9.
X_FIELDCAT-FIELDNAME             = 'MENGE'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Quantity'.
X_FIELDCAT-OUTPUTLEN             = 12.
X_FIELDCAT-DO_SUM                    = 'X'.                       * Summation is allowed for this field
X_FIELDCAT-REF_TABNAME      = 'MSEG'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 10.
X_FIELDCAT-FIELDNAME             = 'ICN'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = ''.
X_FIELDCAT-OUTPUTLEN             = 2.
X_FIELDCAT-ICON                           = 'X'.
* X_FIELDCAT-NO_OUT                 = 'X'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 11.
X_FIELDCAT-FIELDNAME             = 'MEINS'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Unit'.
X_FIELDCAT-OUTPUTLEN             = 5.
X_FIELDCAT-FIELDNAME             = 'MEINS'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 12.
X_FIELDCAT-FIELDNAME             = 'DMBTR'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = 'Local curr'.
X_FIELDCAT-OUTPUTLEN             = 12.
X_FIELDCAT-INTTYPE    = 'P'.
X_FIELDCAT-JUST                            = 'R'.
X_FIELDCAT-DO_SUM    = 'X'.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
 X_FIELDCAT-COL_POS   = 13.
X_FIELDCAT-FIELDNAME             = 'EXCPT'.
X_FIELDCAT-TABNAME                = 'I_TAB'.
X_FIELDCAT-SELTEXT_M             = ''.
X_FIELDCAT-OUTPUTLEN             = 3.
APPEND X_FIELDCAT TO I_FIELDCAT.
CLEAR X_FIELDCAT.
ENDFORM.                    "SUB_PREPARE_FIELDCATALOG.

SAP ABAP ALV Reports Selecting the Optional variants


Comments

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced