Example: Field catalog – KEY, COL_POS

VN:F [1.9.3_1094]
Rating: 7.7/10 (6 votes cast)

In this post, you will find the detailed exaplanation of properties (fields) KEY & COL_POS of field catalog (SLIS_T_FIELDCAT_ALV) with example.

As explained in my previous post (Introduction to Field Catalog ( SLIS_T_FIELDCAT_ALV )) :

KEY : This field indicates if the respective column is the key field in the tabular data to be displayed. The columns marked as ‘Key’ fields will always be positioned before the non-key fields.

COL_POS : Specifies the position of column in the ALV display. If this property is not specified, the columns/fields of data table will appear in ALV display in the order in which their “fieldname” appear in the field catalog. “Key” fields will always have higher priority than non-key fields. You are free to use the same position number for key fields & non-key fields. However, if two key fields or non-key fields have been assigned the same position number, they will be displayed in the order in  their “fieldname” appear in the field catalog.

Here, you would be able to experience the real effect of these properties.

Lets, begin with an ALV list where only the mandatory field FIELD_NAME is provided for each of the columns in field catalog. So, the code for field catalog looks as below:

FORM e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘PRICE’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CURRENCY’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CARRID’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CONNID’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘FLDATE’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

ENDFORM.

The above ALV field catalog produces the output as shown below:

ALV with only FIELDNAME specified in Field catalog

ALV with only FIELDNAME specified in Field catalog

Now, lets introduce the property KEY for some of the columns to be displayed on ALV. Find below the modified code:

FORM e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘PRICE’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CURRENCY’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CARRID’.

ls_fieldcat-key       = ‘X’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CONNID’.

ls_fieldcat-key       = ‘X’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘FLDATE’.

ls_fieldcat-key       = ‘X’.

APPEND ls_fieldcat TO e01_lt_fieldcat.

ENDFORM.

Just, notice the effect:

ALV with KEY specified in Field catalog

ALV with KEY specified in Field catalog

You would notice two important effects:

1. All the columns marked as KEY fields are positioned before non-key fields. This preference of key fields over non-key fields can not be altered by  any other property in field catalog.

2. All the columns marked as KEY fields are highlighed.

Having, understood the effect of property KEY in the field catalog, lets proceed to the usage of property COL_POS.

Property COL_POS is used to arrange the key fields and non-key fields within themselves. If specified, the columns will appear in the ascending order of COL_POS. In case of conflict e.g. two key fields or two non-key fields having same COL_POS, they will be positioned in the order in which they appear in the field catalog internal table.

Lets observe the effect of changed code with COL_POS property incorporated.

FORM e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘PRICE’.

ls_fieldcat-col_pos   = 2.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CURRENCY’.

ls_fieldcat-col_pos   = 1.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CARRID’.

ls_fieldcat-key       = ‘X’.

ls_fieldcat-col_pos   = 2.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CONNID’.

ls_fieldcat-key       = ‘X’.

ls_fieldcat-col_pos   = 2.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘FLDATE’.

ls_fieldcat-key       = ‘X’.

ls_fieldcat-col_pos   = 1.

APPEND ls_fieldcat TO e01_lt_fieldcat.

ENDFORM.

Here’s the output:
ALV with COL_POS specified in Field catalog

ALV with COL_POS specified in Field catalog

You would notice that the key fields continue to display before non-key fields, even though the non-key fields with lesser COL_POS value are placed before key fields in the fields catalog internal table.
Apart from this, you will find the following effects because of the COL_POS property introduction over the previous output.
1. Non-key fields CURRENCY & PRICE have arranged themselves in the ascending order of their COL_POS value.
2. Among key fields, FLDATE is positioned first, since it has COL_POS value of ‘1′ and is not facing any dispute. However, there’s a dispute between columns CARRID & CONNID both having COL_POS value of ‘2′. So, here the conflict is resolved based on the order in which they are placed in field catalog internal table. Since, CARRID appears before CONNID, CARRID wins over CONNID.
Hope, the above example clarifies the usage of properties KEY & COL_POS in field catalog (SLIS_T_FIELDCAT_ALV). Please, do comment in case you find anything missing or needing correction in the above example.
FORM e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘PRICE’.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘CURRENCY’.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘CARRID’.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘CONNID’.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘FLDATE’.
APPEND ls_fieldcat TO e01_lt_fieldcat.
ENDFORM.
VN:F [1.9.3_1094]
Rating: 7.7/10 (6 votes cast)
Example: Field catalog - KEY, COL_POS, 7.7 out of 10 based on 6 ratings
Hey friends!!! Don't forget to promote the post by pressing the buttons below, if you liked it...
  • Digg
  • del.icio.us
  • StumbleUpon
  • Twitthis
  • Yahoo! Buzz
  • Facebook
  • Technorati
  • LinkedIn

1 comment to Example: Field catalog – KEY, COL_POS

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>