SAP ALV Tree fieldcatalog creation

The following ABAP code and information is part of the example ALV tree report demo and create a field catalog for an ALV tree report. See main program to see how this code looks within the completed program.

It is much the same as creating one for a standard ALV report, just note the structure of actual fieldcatalogs internal table as it may be different to what you have been using depending on which method of ALV report you have been developing i.e. LIST, GRID or OBJECT version.

Also see here for other ways to create fieldcatalog

----Add to START-OF-SELECTION Event
* Create fieldcatalog for ALVtree report
  PERFORM build_fieldcatalog.
----Add to main prog after START-OF-SELECTION Event
* Build Fields Catalogue
*&-------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&-------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*--------------------------------------------------------------*
form build_fieldcatalog.
* Please not there are a number of differences between the structure of
* ALVtree fieldcatalogs and ALVgrid fieldcatalogs.
* For example the field seltext_m is replace by scrtext_m in ALVtree.
  fieldcatalog-fieldname   = 'EBELN'.           "Field name in itab
  fieldcatalog-scrtext_m   = 'Purchase Order'.  "Column text
  fieldcatalog-coltext     = 'Purchase Order'.  "Column text
  fieldcatalog-col_pos     = 0.                 "Column position
  fieldcatalog-outputlen   = 15.                "Column width
  fieldcatalog-emphasize   = 'X'.               "Emphasize  (X or SPACE)
  fieldcatalog-key         = 'X'.               "Key Field? (X or SPACE)
*  fieldcatalog-do_sum      = 'X'.              "Sum Column?
*  fieldcatalog-no_zero     = 'X'.              "Don't display if zero
  APPEND fieldcatalog TO gd_fieldcat.
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-scrtext_m   = 'PO Item'.
  fieldcatalog-coltext     = 'PO Item'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-scrtext_m   = 'Status'.
  fieldcatalog-coltext     = 'Status'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-scrtext_m   = 'Item change date'.
  fieldcatalog-coltext_m   = 'Item change date'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 3.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-scrtext_m   = 'Material Number'.
  fieldcatalog-coltext   = 'Material Number'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 4.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-scrtext_m   = 'PO quantity'.
  fieldcatalog-coltext     = 'PO quantity'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 5.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-scrtext_m   = 'Order Unit'.
  fieldcatalog-coltext     = 'Order Unit'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 6.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-scrtext_m   = 'Net Price'.
  fieldcatalog-coltext     = 'Net Price'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-datatype     = 'CURR'.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-scrtext_m   = 'Price Unit'.
  fieldcatalog-coltext     = 'Price Unit'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 8.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

Return to ALV Tree main menu for more development information and example ABAP source code


Related Articles

Activate user interaction within SAP ALV tree
Add button to SAP ALV tree toolbar using ABAP code
ABAP ALV Tree tutorial to create a fully working ALVTree Control SAP dynpro program
Create ALV Tree Custom control and add to sap dynpro screen
Final ABAP code for the ALV Tree PBO(..O01) and FORM(..F01) includes
Create SAP ALV Tree Container in ABAP dynpro screen container
Create Container and Object
Create ALV tree main program including Data & Event declaration
Set SAP ALV tree table for first display and user interaction
Build SAP ALV tree Hierarchy
Build SAP ALV tree Hierarchy Header
Add alv tree already exists check to pbo module
Create all includes required for the ALV tree report
Full ABAP code listing of main ALV tree program
Module creation screen
Create SAP ALV Tree object within ABAP dynpro screen container/H1>
Create ok code to store ALV tree user interaction
Example Output from ALV tree display
Create screen control
Create Screen along with PBO and PAI modules
Create Pf-status(screen menu functionality)
Refresh ALVtree
Build Report Header(Title)
ALVtree toolbar processing
Implement user defined buttons to ALVtree toolbar
ALVtree user interaction processing
Implement ALVtree user interaction processing
Setup ALVtree variant
Main Steps to create ALV simple Tree(Using Objects)
Create Add Custom control to screen
Final code for the PBO(..O01) and FORM(..F01) includes
Create Container and Object
Create and register events for user interaction
Create ALVtree Hierarchy
Add already exists check!
Create Includes for ALVtree report
Full ABAP code listing of main program
Create Container and Object
Create screen control
Example Output from ALV simple tree display
Create screen control
Create Screen along with PBO and PAI modules
Create Pf-status(screen menu functionality)