*For Function module ALV (report)
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF it_fieldcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'EKKO'
CHANGING
ct_fieldcat = it_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_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.
*For object ALV (Screen)
DATA: gd_fieldcat2 type LVC_T_FCAT.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'EKKO'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
CHANGING
ct_fieldcat = gd_fieldcat2
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
* Building a fieldcatalog based on an internal table
* This method relies on the internal table(IT_EKKO) having been
* declared within an include(i.e. ZDEMO_ALVGRID_STRUCTURE) using
* version 4.0 method of declaration:
* data: begin of it_ekko occurs 0,
* ebeln like ekko-ebeln,
* ...
* end of it_ekko.
data: gd_fieldcat type slis_fieldcat_alv occurs 0.
* Include to store internal table structure required for FM
* 'REUSE_ALV_FIELDCATALOG_MERGE'.
include: ZDEMO_ALVGRID_STRUCTURE.
-----------------------------
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = 'ZDEMO_ALVGRID'
i_internal_tabname = 'IT_EKKO_ALT'
i_inclname = 'ZDEMO_ALVGRID_STRUCTURE'
changing
ct_fieldcat = gd_fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
* Another way is to build the fieldcatalog manualy by populating the
* internal table fields individually and then appending the rows.
* This method can be the most time consuming but can also allow you
* more control of the final product.
* Beware though, there are many fields that can be populated and you
* need to ensure that those fields required are populated.
* When using some of functionality available via ALV such as total.
* You may need to provide more information than if you were simply
* displaying the result
* I.e. Field type may be required in-order for
* the total function to work.
data: fieldcatalog type slis_t_fieldcat_alv with header line.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.