The field catalog contains more than 60 fields, some of which are only used internally. The field catalog is defined in the Data Dictionary through table type LVC_T_FCAT.
We can get field description by calling function module REUSE_ALV_FIELDCATALOG_MERGE. You can see the sample in my post about Simple ALV Report.
In general case, we only use few field to describe output field.
To make it easier I use this form:
FORM f_alv_fieldcatg USING
fu_types "internal table name
fu_fname "Field name of internal table field
fu_reftb "reference table name
fu_refld "reference table field
fu_noout "X= No out
fu_outln "out
fu_fltxt "output length
fu_dosum "X=Do sum (total)
fu_hotsp "X=hotspot on
fu_just. "Justification:L,R,C
CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-ref_tabname = fu_reftb.
t_fieldcat-ref_fieldname = fu_refld.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-no_out = fu_noout.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-hotspot = fu_hotsp.
t_fieldcat-just = fu_just.
APPEND t_fieldcat.
CLEAR t_fieldcat.
ENDFORM. " f_alv_fieldcatg
We can use it in two way:
1. refer to data dictionary:
PERFORM f_alv_fieldcatg USING 'T_REPORT' :
'EQUNR' 'EQUI' 'EQUNR' '' '' '' '' 'X' '',
'SPART' 'VBAK' 'SPART' '' '' '' '' '' ''.
2. or define yourself
PERFORM f_alv_fieldcatg USING 'T_REPORT' :
'FIELD1' '' '' '' '20' 'Text Field1' '' '' ''.
and for field with type number, I use this:
*&---------------------------------------------------------------------*
*& Form f_alv_fieldcatg_number
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_alv_fieldcatg_number USING fu_types
fu_fname
fu_noout
fu_outln
fu_no_sign
fu_no_zero
fu_fltxt
fu_dosum
fu_exponent
fu_decimals_out.
CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-no_zero = fu_no_zero.
t_fieldcat-no_sign = fu_no_sign.
t_fieldcat-exponent = fu_exponent.
t_fieldcat-decimals_out = fu_decimals_out.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-datatype = 'FLTP'.
APPEND t_fieldcat.
CLEAR t_fieldcat.
ENDFORM. " f_alv_fieldcatg_number
For field currency, there are two options, fixed currency or variable currency.
*&---------------------------------------------------------------------*
*& Form f_alv_fieldcatg_curr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_alv_fieldcatg_curr USING fu_types
fu_fname
fu_reftb
fu_refld
fu_noout
fu_outln
fu_fltxt
fu_dosum
fu_hotsp
fu_cfield.
CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-ref_tabname = fu_reftb.
t_fieldcat-ref_fieldname = fu_refld.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-hotspot = fu_hotsp.
t_fieldcat-cfieldname = fu_cfield.
t_fieldcat-ctabname = fu_types.
t_fieldcat-no_zero = 'X'.
APPEND t_fieldcat.
CLEAR t_fieldcat.
ENDFORM. " F_FIELDCATG_CURR
*&---------------------------------------------------------------------*
*& Form f_alv_fieldcatg_curr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_alv_fieldcatg_curr_fixed USING fu_types
fu_fname
fu_reftb
fu_refld
fu_noout
fu_outln
fu_fltxt
fu_dosum
fu_hotsp
fu_curr.
CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-ref_tabname = fu_reftb.
t_fieldcat-ref_fieldname = fu_refld.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-hotspot = fu_hotsp.
* t_fieldcat-cfieldname = fu_cfield.
* t_fieldcat-ctabname = fu_types.
t_fieldcat-datatype = 'CURR'.
t_fieldcat-currency = fu_curr.
t_fieldcat-no_zero = 'X'.
APPEND t_fieldcat.
CLEAR t_fieldcat.
ENDFORM. " F_FIELDCATG_CURR
Serkan AKKAVAK
Computer Engineer
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com
Social Plugin