Dynamic fields to be displayed in ALV

Hi All,
I've a requirement like this.
I have table type with 10 fields and I use this to display data in ALV.  Now, I need to add few dynamic columns (based on customizing) and show in the same ALV.  Since these fields are dynamic and new fields can also be added in the future, I can not enhance the structure I am using at present.  So, the solution would be to add dynamic columns to the output table that is sent to ALV display.
Adding fields to field catalogue is not a big ask and I am already done with that.  Moreover, I have tried enhancing the current structure with a field of type DATA and populated it. 
But, technically, it is a single field and cannot be split into the different new fields at the time of output. 
How is this possible?  Please provide me with example code also, if you have.
Thanks in advance,
Srinath.

Hi Srinath,
I for this purpose I use my own solution since a couple of years with success. It was originally developed for ALV functions module. In OO the field catalo has a slightly different structure, nut one can be easily converted into the other using function module (don't remember the name right now).
Recently I created a class with static functional methods for this:
METHOD fieldcat_alv .
  TYPE-POOLS:
    sydes.
  DATA:
    lv_desc                               TYPE sydes_desc,
    ls_alv_fieldcat                       TYPE slis_fieldcat_alv,
    lv_longfield                          TYPE dynfnam.
  FIELD-SYMBOLS:
    <typeinfo>                            TYPE sydes_typeinfo,
    <nameinfo>                            TYPE sydes_nameinfo.
  DESCRIBE FIELD it_table INTO lv_desc.                     "#EC *
  LOOP AT lv_desc-types
      ASSIGNING <typeinfo>
      WHERE NOT idx_name IS INITIAL
        AND table_kind IS INITIAL "no entries for deep table like color
        AND back                          = 2. "top-level-entries only.
    READ TABLE lv_desc-names INDEX <typeinfo>-idx_name
      ASSIGNING <nameinfo>.
    CHECK <nameinfo>-name                 <> 'INCLUDE'.
    ls_alv_fieldcat-fieldname             = <nameinfo>-name.
    WHILE NOT <nameinfo>-continue IS INITIAL.
      ADD 1 TO <typeinfo>-idx_name.
      READ TABLE lv_desc-names INDEX <typeinfo>-idx_name
        ASSIGNING <nameinfo>.
      CONCATENATE
        ls_alv_fieldcat-fieldname
        <nameinfo>-name
        INTO ls_alv_fieldcat-fieldname.
    ENDWHILE." not <nameinfo>-continue IS INITIAL.
    READ TABLE lv_desc-names INDEX <typeinfo>-idx_help_id
      ASSIGNING <nameinfo>.
    IF sy-subrc                           = 0.
* Caution: Help-ID may be Tablename-Fieldname and thus longer
* than 30 Chars; ls_alv_fieldcat-rollname is 30 Chars only
      ls_alv_fieldcat-rollname            = <nameinfo>-name.
      lv_longfield                        = <nameinfo>-name.
      WHILE NOT <nameinfo>-continue IS INITIAL.
        ADD 1 TO <typeinfo>-idx_help_id.
        READ TABLE lv_desc-names INDEX <typeinfo>-idx_help_id
          ASSIGNING <nameinfo>.
        CONCATENATE
          lv_longfield
          <nameinfo>-name
          INTO lv_longfield.
      ENDWHILE." not lv_desc-continue is initial.
* help id may be data element or <table>-<field>
      IF lv_longfield CA '-'.
* get datatype for table field
        CALL METHOD get_rollname_4_tabfield
          EXPORTING
            iv_fieldname    = lv_longfield
          CHANGING
            cs_alv_fieldcat = ls_alv_fieldcat.
      ENDIF." lv_longfield ca '-'.
    ELSE.
* No Help-ID: Use Fieldname as text
      ls_alv_fieldcat-seltext_s           =
      ls_alv_fieldcat-seltext_m           =
      ls_alv_fieldcat-seltext_l           =
      ls_alv_fieldcat-reptext_ddic        =
      <nameinfo>-name.
    ENDIF." sy-subrc                      = 0.
* Starting 4.7: get edit mask
    IF NOT <typeinfo>-idx_edit_mask IS INITIAL.
      READ TABLE lv_desc-names INDEX <typeinfo>-idx_edit_mask
        ASSIGNING <nameinfo>.
      ls_alv_fieldcat-edit_mask           = <nameinfo>-name.
      IF NOT <nameinfo>-continue IS INITIAL.
        ADD 1 TO <typeinfo>-idx_edit_mask.
        READ TABLE lv_desc-names INDEX <typeinfo>-idx_edit_mask
          ASSIGNING <nameinfo>.
        CONCATENATE
          ls_alv_fieldcat-edit_mask
          <nameinfo>-name
          INTO ls_alv_fieldcat-edit_mask.
      ENDIF." not <nameinfo>-continue IS INITIAL.
    ENDIF." not <typeinfo>-IDX_EDIT_MASK is initial.
* assign length, output length and decimals
    ls_alv_fieldcat-intlen                = <typeinfo>-length.
    ls_alv_fieldcat-outputlen             = <typeinfo>-output_length.
    ls_alv_fieldcat-decimals_out          = <typeinfo>-decimals.
    ls_alv_fieldcat-inttype               = <typeinfo>-type.
    APPEND ls_alv_fieldcat TO rt_fieldcat.
    CLEAR:  "prevent anything 2 B  taken for subsequent fields
      ls_alv_fieldcat.
  ENDLOOP." at lv_desc-types where not IDX_NAME is in initial.
ENDMETHOD.
Parameters required
    importing
      IT_TABLE type STANDARD TABLE
    returning
      value(RT_FIELDCAT) type SLIS_T_FIELDCAT_ALV .
and
method GET_ROLLNAME_4_TABFIELD .
  FIELD-SYMBOLS:
    <dfies>                               TYPE dfies.
  DATA:
    lv_tabname                            TYPE tabname,
     lt_dfies                             TYPE TABLE OF dfies,
    lv_fieldname                          TYPE fieldname.
  SPLIT iv_fieldname AT '-'
    INTO lv_tabname lv_fieldname.
  CLEAR cs_alv_fieldcat-rollname.
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      tabname                             = lv_tabname
      fieldname                           = lv_fieldname
*   LANGU                                 = SY-LANGU
*   LFIELDNAME                            = ' '
*   ALL_TYPES                             = ' '
* IMPORTING
*   X030L_WA                              =
*   DDOBJTYPE                             =
*   DFIES_WA                              =
*   LINES_DESCR                           =
   TABLES
     dfies_tab                            =  lt_dfies
*   FIXED_VALUES                          =
   EXCEPTIONS
     not_found                            = 1
     internal_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.
  ELSE.
    READ TABLE   lt_dfies ASSIGNING <dfies> INDEX 1.
    cs_alv_fieldcat-rollname               = <dfies>-rollname.
* Und wenn keinerlei Twexte gepflegt sind?
    IF <dfies>-reptext IS INITIAL AND
       <dfies>-scrtext_s IS INITIAL AND
       <dfies>-scrtext_m IS INITIAL AND
       <dfies>-scrtext_l IS INITIAL.
* No Text: Use Fieldname as text
      cs_alv_fieldcat-seltext_s            =
      cs_alv_fieldcat-seltext_m            =
      cs_alv_fieldcat-seltext_l            =
      cs_alv_fieldcat-reptext_ddic         =
        cs_alv_fieldcat-fieldname.
    ENDIF." <dfies>-reptext IS INITIAL AND
  ENDIF.
endmethod.
parameters required
    importing
      IV_FIELDNAME type DYNFNAM
    changing
      value(CS_ALV_FIELDCAT) type SLIS_FIELDCAT_ALV .
Put this into class Z_CL_UTIL using SE80 and generate field catalog dynamically using statement
lt_fieldcat = Z_CL_UTIL=>fieldcat_alv( itab ).
If you have any difficulties with implementation, let me know.
Regards,
Clemens Li

Similar Messages

  • How to get which fields are currently displayed by ALV?

    Hi ,
    I have a program which displays list in the form of ALV . I have a parameter on the screen which takes the layout name from the user. At the same time I have the parameter which takes the filename from the user.
    Now the program should write only those fields to the file which are displayed on the screen depending on the layout.
    How can I get the names of the fields which are displayed on the ALV layout so that I can write only those fields to the file ?
    [Here the requirement is such that we have to provide seperate download to file option even if we have the same functionality provided by the ALV]
    Please suggest.
    Naina

    YOu can use one these FMs before filling up your download table:
    REUSE_ALV_GRID_LAYOUT_INFO_GET
    REUSE_ALV_LIST_LAYOUT_INFO_GET
      IF g_grid IS INITIAL.
        CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_GET'
             IMPORTING
                  es_layout      = g_layout
                  et_fieldcat    = g_fieldcat_tab[]
                  et_sort        = g_sortfields_tab[]
                  et_filter      = g_filter_tab[]
    *           ES_LIST_SCROLL = G_SCROLL
                  es_variant     = g_variant
             EXCEPTIONS
                  no_infos       = 1
                  program_error  = 2
                  OTHERS         = 3.
      ELSE.
        CALL FUNCTION 'REUSE_ALV_LIST_LAYOUT_INFO_GET'
          IMPORTING
            es_layout      = g_layout
            et_fieldcat    = g_fieldcat_tab[]
            et_sort        = g_sortfields_tab[]
            et_filter      = g_filter_tab[]
            es_list_scroll = g_scroll
            es_variant     = g_variant
          EXCEPTIONS
            no_infos       = 1
            program_error  = 2
            OTHERS         = 3.
      ENDIF.
    Regards,
    Naimesh Patel

  • Newly added field not getting displayed in ALV output

    Hi All,
       I'm adding one more field/column to be displayed in an old existing program that uses REUSE_ALV_FIELDCATALOG_MERGE to generate the ALV fieldcat.
    DATA: BEGIN OF it_salary OCCURS 0,
            pernr LIKE pa0000-pernr,
            ename LIKE pa0001-ename,
            rtext like lv_rtext, -
    added field
            waers LIKE pa0008-waers
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         = driver
          i_internal_tabname     = 'IT_SALARY'
          i_client_never_display = 'X'
          i_inclname             = driver
        CHANGING
          ct_fieldcat            = lv_fieldcat[]
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program      = driver
          it_fieldcat             = lv_fieldcat[]
          i_default               = 'X'
          i_save                  = 'A'
          is_variant              = lv_tmplt
          is_layout               = lv_ls_layout
         i_callback_user_command = 'USER_COMMAND'
        TABLES
          t_outtab                = it_salary
        EXCEPTIONS
          program_error           = 1
          OTHERS                  = 2.
    The newly added field is not getting populated in the lv_fieldcat table. Tried running programs BALVBUFDEL,
    BCALV_BUFFER_DEL_SHARED then logging off and logging in but of no help.
    Please provide suggestion for this issue.
    Regards,
    Sridevi S

    Hi,
    Fieldcat is buffered - so use
    I_BYPASSING_BUFFER = 'X'
    Since a while CL_GUI_ALV_GRID is available which does NOT need any fieldcat (is determined internally using RTTI). It is worth playing around whith this class if you have some time. This class is recommended for ALV Output by SAP (but no edit is possible - was never supported officially).
    A simple use would be:
    data: gt_output type standard table of (adjust!).
    *simple ALV output
    data go_alv type ref to cl_salv_table.
    data go_functions type ref to cl_salv_functions_list.
    data go_columns type ref to cl_salv_columns_table.
    data go_column type ref to cl_salv_column_table.
    *Exceprion handlig
    data: go_exception  type ref to cx_root,
          gv_errortext   type string.
    ** fill table gt_output ...
    ** ALV output
    if not gt_output is initial.
        try.
            call method cl_salv_table=>factory
              importing
                r_salv_table = go_alv
              changing
                t_table      = gt_output.
          catch cx_salv_msg into go_exception.
            gv_errortext = go_exception->get_text( ).
            message gv_errortext type 'A'.
        endtry.
    * enable all standard ALV functions
        go_functions =  go_alv->get_functions( ).
        go_functions->set_all( ).
    * hide MANDT
        go_columns = go_alv->get_columns( ).
        go_column ?=  go_columns->get_column( columnname = 'MANDT' ).
        go_column->set_technical( ).
        go_alv->display( ).
    Kind regards,
    Holger

  • New field category not display in ALV report

    Hi,
    Hi, I modifying an existing ALV report.
    I have a problem to insert the new field into the ALV report.
    The field and column title have been populated in alv field category correctly, but when FM 'REUSE_ALV_GRID_DISPLAY'  executed, the new field and column didn't appear.
    Anybody can help me.
    Regards
    Nislina

    hi
    Add that new field in the fieldcatalog and populate the value in the value in the internal table.
    loop at it_fieldcatalog into wa_fieldcatalog.
    wa_fieldcatalog-fieldname = 'NEW_FIELD'.
    wa_fieldcatalog-outputlen = '15'.
    append wa_fieldcatalog to it_fieldcatalog.
    clear wa_fieldcatalog,
    endloop.
    regards
    ravish
    <b>plz reward points if helpful</b>

  • Last 2 fields to be displayed in ALV

    HI Experts,
    I need your help once again.
    My ALV using OOPS has 24 columns and the its is very long. Im not able to scroll to the last field in my ALV .WEven if i scroll only
    22 fields are visible. Please let me know how to scroll to make all the fields visible.
    Thanks in Advance
    SS

    Hi,
    In Layout structure (lvc_s_layo) there is field CWIDTH_OPT, set it to 'X'.
    This will optimize the Column Width.
    Thanks & regards,
    ShreeMohan,

  • ALV display using dynamic field catalog and dynamic internal table

    hi ,
    please guide me for ALV display using dynamic field catalog and dynamic internal table.
    Thank you.

    Hi Rahul,
    maybe thread dynamic program for alv is helpful for you. More information about the [SAP List Viewer (ALV)|http://help.sap.com/saphelp_nw70/helpdata/EN/5e/88d440e14f8431e10000000a1550b0/frameset.htm]. Also have a look into the example programs SALV_DEMO_TABLE*.
    Regards Rudi

  • ALV Report dynamically fields i want to display

    Hi experts,
    how to declare dynamical fields in ALV reports not in oops.can i use fieldcat merge function mod for this requirement.pls write the code if possible.

    Hi,
    how to declare dynamical fields in ALV reports not in oops. ? I didnt understand what exactly you mean ? Do you want to build an internal table which is of dynamic in nature ?
    can i use fieldcat merge function mod for this requirement.  No
    pls write the code if possible. No one writes the code here. Paste your code here !! If there any mistakes, any one of the SDNer will let you know !!
    If you want the internal table to be dynamically created, check the following link:
    Re: Dynamic Table with Validation
    Regards
    Kannaiah

  • Populating two dynamic internal tables and displaying the O/p as ALV

    I want to develop a abap prototype program report for the SD document flow analysis...
    There is a Fm : RV_ORDER_FLOW_INFORMATION in which if we pass the Sales order number it returns the flows as VBFA_TAB.
    I need to populate two dynamic ITAB1 and ITAB2
    the structure of ITAB1 should be like ColNm1....ColNmn
    The values for ColNm1 will be Sales Order ColNm2 as Delivery or smthng else depending on  field vbtyp_n.
    ITAB 2 should have the corresponding values accly to ITAB1.
    Then we need to display in ALV o/p.
    The tables should be populated dynamically.
    Can anybody throw some light on it and plz do write back with sample code to do the logic of it.

    Search in SDN with Dynamic internal tables.
    you get lot of code samples and Discussions related to Dynamic internal tables.
    you can also check with this class CL_ALV_TABLE_CREATE

  • No column text displayed in alv when i use dynamic internal table

    Hi friends,
    when I use dynamic internal table to display the fields in ALV formant, field column text was not displaying ,
    total row of column text was blank.
    can u sujjest me in this...
    with regards,
    prasad.

    Hi
    That depends on how you've filled the catalog table, here u need to insert the description for the labels (short, medium and long) and the description for the layout variant management.
    So u make sure to fill the fields like
    SCRTEXT_L
    SCRTEXT_M
    SCRTEXT_S
    REPTEXT
    Max

  • Download dynamic fields (based on changed layout) from ALV

    Hello All,
    Currently i am displaying 28 firelds in my ALV output.
    I have created my own button for downloading the contents displayed using GUI_DOWNLOAD.
    Say if user changes the layout and say now we have 35 fields in the layout.
    Now when we click the DOWNLOAD button, i want to download these 35 fields instead of 28 fields.
    Can anyone please help me on this...
    Thanks in advance....
    Regards,
    Tarun

    Hi Tarun,
    As the frontend layout is directly connected to this output table, standard excel download would work here (because it already knows which column to display and download).
    But as you want custom solution I think the following might work:
    - get fieldcatalog using GET_FRONTEND_FIELDCATALOG
    - loop through it and check if field is in displayed mode ( NO_OUT ne 'X' ).
    - create (or just copy above entries) to new fieldcatalog table
    - use class CL_ALV_TABLE_CREATE to generate dynamic table with structure of displayed fields only (based on that new fieldcatalog)
    - loop through output table and copy corresponding fields to your dynamic table appending to it
    - download dynamic table using GUI_DOWNLOAD (parameter DATA_TAB here is generic so you can pass any table structure).
    Regards
    Marcin

  • New ALV field is not displaying

    Hi
    I have added the currency field in the existing ALV report.
    The final internal table having the currency field and it has value. Curreny field is not displaying in output. Pls help
    Below is my ALV code for currency.
    PERFORM FILL_FIELDCAT USING
    'WAERS' SPACE SPACE 'CURRENCY' 'CURRENCY' 'CURRENCY'.
    READ TABLE GIT_FIELDCAT INTO LX_FIELDCAT
              WITH KEY FIELDNAME = 'WAERS' .
      LX_FIELDCAT-OUTPUTLEN = 5.
      LX_FIELDCAT-JUST       = 'L'.
      MODIFY GIT_FIELDCAT FROM LX_FIELDCAT INDEX SY-TABIX.
    FORM FILL_FIELDCAT USING    P_FIELDNAME
                                P_NO_OUT
                                P_DO_SUM
                                P_SELTEXT_S
                                P_SELTEXT_M
                                P_SELTEXT_L.                    "#EC *
      DATA: LX_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
      CLEAR LX_FIELDCAT.
      LX_FIELDCAT-TABNAME    = 'GIT_LIST'.
      LX_FIELDCAT-FIELDNAME  = P_FIELDNAME.
      LX_FIELDCAT-NO_OUT     = P_NO_OUT.
      LX_FIELDCAT-DO_SUM     = P_DO_SUM.
      LX_FIELDCAT-SELTEXT_S  = P_SELTEXT_S.
      LX_FIELDCAT-SELTEXT_M  = P_SELTEXT_M.
      LX_FIELDCAT-SELTEXT_L  = P_SELTEXT_L.
      APPEND LX_FIELDCAT TO GIT_FIELDCAT.
    ENDFORM.                               " FILL_FIELDCAT

    You have to [maintain maintenance dialog|http://help.sap.com/SAPHELP_NWPI71/helpdata/EN/a7/513484407a11d1893b0000e8323c4f/frameset.htm] as described in the link.
    Regards,
    Raymond

  • Need to remove space for a field when displayed in ALV Report

    Hi,
    I have material field of length 18, but the content is only 10 char. I need to remove the extra space when it is displayed on ALV Report.
    Is there any option in ALV field catalogue

    use statement condense.
    condense zmatnr.
    also giv output lenth of alv column as 10.

  • How to display the editable fields in output of an ALV report?

    Hi all,
    I have a requirement of displaying values in ALV Grid format and above this grid display i have to put some fields , that are editable.
    I know making ALV grid fields as editable, but here requirement is to display some fields before displaying the ALV grid dispaly and to enable these fields editable to user and when printing this the values entered by user also has tobe printed.
    Please help me on solving this problem? Is it possible to do this with ALV function modules?
    Thanks,
    Vamshi.

    Hi all,
    Thanks for your replies.
    But this is not  my requirement. I mentioned in my question that i too know how to edit the fields in ALV grid report.
    Here my requirement is .
                                             name :_____________
                                             amount:____________
    alv grid display
    Like above i need to display.  after name the user can be enter value and after amount also the user can be enter some value at output . But this is not the header of ALV .
    Is this possible in classical ALV or Classical report? If not please specify alternative?
    Thanks,
    Vamshi.

  • How can we display dynamic fields from a XML CLOB?

    Jdeveloper Version : 11.1.1.4.0 (11g)
    We are calling a database package.procedure from a page VO and it returns a result set. The result set is mainly a XML CLOB. Within XML CLOB, we have various sections which we need to parse and display those on JSF page. Couple of sections within XML are having dynamic fields which means the number of fields returned under that section may change depending upon data conditions. We need to find technical way of displaying those dynamic fields (field name and its data – both are part of XML).
    Please suggest how can this be achieved.
    Thanks

    <?xml version="1.0" encoding="UTF-8" ?>
    <nodes>
    <node>
    <category_id>3</category_id>
    <parent_id>2</parent_id>
    <name>Mobile</name>
    <is_active>1</is_active>
    <position>1</position>
    <level>2</level>
    <children>
    <node name="Nokia" category_id="6" parent_id="3" is_active="1" position="1" level="3">
    <node name="Nokia N79" category_id="7" parent_id="3" is_active="1" position="2" level="3" />
    <node name="Nokia N95" category_id="7" parent_id="3" is_active="1" position="2" level="3" />
    <node name="Nokia N97" category_id="7" parent_id="3" is_active="1" position="2" level="3" />
    </node>
    <node name="Samsung" category_id="7" parent_id="3" is_active="1" position="2" level="3">
    </node>
    </children>
    </node>
    <node>
    <category_id>4</category_id>
    <parent_id>2</parent_id>
    <name>Laptop</name>
    <is_active>1</is_active>
    <position>2</position>
    <level>2</level>
    <children></children>
    </node>
    <node>
    <category_id>5</category_id>
    <parent_id>2</parent_id>
    <name>Monitor</name>
    <is_active>1</is_active>
    <position>3</position>
    <level>2</level>
    <children></children>
    </node>
    <node>
    <category_id>8</category_id>
    <parent_id>2</parent_id>
    <name>Camera</name>
    <is_active>1</is_active>
    <position>4</position>
    <level>2</level>
    <children></children>
    </node>
    </nodes>
    Is this correct format to create dynamic menu?

  • Reg: Dynamic Field catalog in ALV

    Hi ,
    Can any one guide me to build a dynamic field catalog in ALV report?
    Below is the format which i expect..........
    Material    |     Plant1    |    Plant2    |    Plant3    | ....................|    Plant 20      |
    Qty
    Val
    Qty
    Val
    Qty
    Val
    Qty
    Val
    The plant 1 to 20 has to be brought dynamically as headings from T001W table. (Horizontally populate)
    Below each plant i need sub-headings "QTY" and "VAL".                                  (Horizontally populate)
    List of Materials should be brought vertically from MARA table.                          (Vertically populate)
    Can anyone suggest how to bring out this format for populating data accordingly into the o/p format?
    Ur help will be appreciated.
    Thanks,
    K.S.Kannan

    your part of the code is present in routine
    perform dynamic_table.
    *& Report ZCS_NAC_MAT_CHARACTERISTICS
    2/ Description ...: Business requirement is to get all materials
    without any characteristic values maintained in SAP
    which are given in the selection screen.
    REPORT znac_material_char.
    TYPE-POOLS : abap,
    slis.
    TABLES : kssk,
    klah,
    mara,
    makt,
    cabn,
    t134,
    t023.
    DATA : i_fieldcat TYPE slis_t_fieldcat_alv ,
    wa_fieldcat TYPE slis_fieldcat_alv.
    DATA : w_layout TYPE slis_layout_alv.
    DATA : st_layout TYPE slis_layout_alv.
    DATA : t_header TYPE slis_t_listheader,
    w_header TYPE slis_listheader.
    TYPES : BEGIN OF ty_cabn,
    atinn TYPE cabn-atinn,
    atnam TYPE cabn-atnam,
    END OF ty_cabn.
    DATA : i_cabn TYPE STANDARD TABLE OF ty_cabn WITH HEADER LINE.
    DATA : w_cabn LIKE i_cabn.
    TYPES : BEGIN OF ty_ausp,
    objek TYPE ausp-objek,
    atinn TYPE ausp-atinn,
    klart TYPE ausp-klart,
    END OF ty_ausp.
    DATA : i_ausp TYPE STANDARD TABLE OF ty_ausp WITH HEADER LINE.
    DATA : w_ausp LIKE i_ausp.
    TYPES : BEGIN OF ty_mara,
    matnr TYPE mara-matnr,
    mtart TYPE mara-mtart,
    matkl TYPE mara-matkl,
    prdha TYPE mara-prdha,
    mstae TYPE mara-mstae,
    mstde TYPE mara-mstde,
    END OF ty_mara.
    DATA : i_mara TYPE STANDARD TABLE OF ty_mara WITH HEADER LINE.
    DATA : w_mara LIKE i_mara.
    DATA : i_mara_temp TYPE STANDARD TABLE OF ty_mara WITH HEADER LINE.
    DATA : w_mara_temp LIKE i_mara_temp.
    TYPES :BEGIN OF ty_data,
    atnam TYPE cabn-atnam,
    atinn TYPE cabn-atinn,
    objek TYPE ausp-objek,
    klart TYPE ausp-klart,
    matnr TYPE mara-matnr,
    maktx TYPE makt-maktx,
    mtart TYPE mara-mtart,
    matkl TYPE mara-matkl,
    prdha TYPE mara-prdha,
    mstae TYPE mara-mstae,
    mstde TYPE mara-mstde,
    END OF ty_data.
    DATA : i_data TYPE STANDARD TABLE OF ty_data WITH HEADER LINE.
    DATA : w_data LIKE i_data.
    DATA : i_class TYPE STANDARD TABLE OF sclass WITH HEADER LINE.
    DATA : w_class LIKE i_class.
    DATA : i_class_temp TYPE STANDARD TABLE OF sclass WITH HEADER LINE.
    DATA : w_class_temp LIKE i_class_temp.
    DATA : i_objdata TYPE STANDARD TABLE OF clobjdat WITH HEADER LINE.
    DATA : w_objdata LIKE i_objdata.
    TYPES : BEGIN OF ty_objdata_temp.
    TYPES: matnr TYPE mara-matnr.
    TYPES: maktx TYPE makt-maktx.
    INCLUDE STRUCTURE clobjdat.
    TYPES : prdha TYPE mara-prdha.
    TYPES : mstde TYPE mara-mstde.
    TYPES : END OF ty_objdata_temp.
    DATA : i_objdata_temp TYPE STANDARD TABLE OF ty_objdata_temp WITH HEADER LINE.
    DATA : w_objdata_temp LIKE i_objdata_temp.
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
    <fs_dyntable>,
    <fs_fldval> TYPE ANY.
    DATA: t_newtable TYPE REF TO data,
    t_newline TYPE REF TO data,
    fs_fldcat TYPE slis_t_fieldcat_alv,
    t_fldcat1 TYPE lvc_t_fcat,
    wa_it_fldcat TYPE lvc_s_fcat,
    wa_colno(2) TYPE n,
    wa_flname(30) TYPE c.
    DATA: fieldname(20) TYPE c.
    DATA: fieldvalue(40) TYPE c.
    DATA: index(3) TYPE c,
    v_time(60) TYPE c.
    DATA: wa_cat LIKE LINE OF fs_fldcat.
    CONSTANTS : c_nac TYPE klah-class VALUE 'NAC',
    c_klart TYPE ausp-klart VALUE '001',
    c_check TYPE c VALUE 'X' .
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (28) text-001 .
    SELECT-OPTIONS: s_atnam FOR cabn-atnam NO INTERVALS OBLIGATORY. " Characteristic name
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b1 .
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    SELECT-OPTIONS: s_matnr FOR mara-matnr. " material Number
    SELECT-OPTIONS: s_mtart FOR mara-mtart. " material type
    SELECT-OPTIONS: s_matkl FOR mara-matkl. " material type
    SELECT-OPTIONS: s_mstae FOR mara-mstae. " X-Plant material status
    PARAMETERS : s_date LIKE sy-datum OBLIGATORY DEFAULT sy-datum . " date
    SELECTION-SCREEN END OF BLOCK b2 .
    AT SELECTION-SCREEN ON s_atnam.
    SELECT SINGLE * FROM cabn WHERE atnam IN s_atnam.
    IF sy-subrc 0.
    MESSAGE text-003 TYPE 'E'.
    ENDIF.
    AT SELECTION-SCREEN ON s_matnr.
    SELECT SINGLE * FROM mara WHERE matnr IN s_matnr.
    IF sy-subrc 0.
    MESSAGE text-004 TYPE 'E'.
    ENDIF.
    AT SELECTION-SCREEN ON s_mtart.
    SELECT SINGLE * FROM t134 WHERE mtart IN s_mtart.
    IF sy-subrc 0.
    MESSAGE text-005 TYPE 'E'.
    ENDIF.
    AT SELECTION-SCREEN ON s_matkl.
    SELECT SINGLE * FROM t023 WHERE matkl IN s_matkl.
    IF sy-subrc 0.
    MESSAGE text-006 TYPE 'E'.
    ENDIF.
    START-OF-SELECTION.
    PERFORM get_data.
    PERFORM get_data_keydate.
    PERFORM material_all_charname.
    PERFORM get_classification.
    PERFORM dynamic_table.
    *& Form dynamic_table
    text
    --> p1 text
    <-- p2 text
    FORM dynamic_table.
    PERFORM fieldcatalog.
    PERFORM dynamic_table_create.
    PERFORM final_data.
    PERFORM final_fieldcatalog.
    PERFORM layout_build.
    PERFORM grid_display.
    ENDFORM. " fieldcat
    *& Form layout_build
    text
    FORM layout_build .
    st_layout-zebra = c_check.
    st_layout-no_vline = ''.
    st_layout-colwidth_optimize = c_check.
    st_layout-detail_popup = c_check.
    st_layout-detail_initial_lines = c_check.
    st_layout-detail_titlebar = text-021.
    ENDFORM. " layout_build
    *& Form alv_top_of_page
    text
    FORM alv_top_of_page.
    REFRESH t_header.
    CLEAR t_header.
    w_header-typ = 'H'. "H=Header, S=Selection, A=Action
    w_header-key = ' '.
    w_header-info = text-019.
    APPEND w_header TO t_header.
    CONCATENATE sy-datum4(2) '-' sy-datum6(2) '-' sy-datum0(4) ' / ' sy-uzeit0(2) ':' sy-uzeit2(2) ':' sy-uzeit4(2) INTO v_time.
    w_header-typ = 'S'. "H=Header, S=Selection, A=Action
    w_header-key = text-020.
    w_header-info = v_time.
    APPEND w_header TO t_header.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    it_list_commentary = t_header.
    ENDFORM. "alv_top_of_page
    *& Form grid_display
    text
    --> p1 text
    <-- p2 text
    FORM grid_display .
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = sy-repid
    i_callback_top_of_page = 'ALV_TOP_OF_PAGE'
    it_fieldcat = fs_fldcat
    is_layout = st_layout
    i_default = c_check
    i_save = 'A'
    it_events = v_events[]
    TABLES
    t_outtab = <t_dyntable>.
    ENDFORM. " grid_display
    *& Form FINAL_FIELDCATALOG
    text
    --> p1 text
    <-- p2 text
    FORM final_fieldcatalog .
    wa_cat-fieldname = text-009.
    wa_cat-seltext_m = text-015.
    wa_cat-outputlen = 18.
    APPEND wa_cat TO fs_fldcat.
    wa_cat-fieldname = text-011.
    wa_cat-seltext_m = text-016.
    wa_cat-outputlen = 40.
    APPEND wa_cat TO fs_fldcat.
    LOOP AT s_atnam.
    CLEAR wa_cat.
    wa_cat-fieldname = s_atnam-low.
    wa_cat-seltext_m = s_atnam-low.
    wa_cat-outputlen = '15'.
    APPEND wa_cat TO fs_fldcat.
    ENDLOOP.
    wa_cat-fieldname = text-012.
    wa_cat-seltext_m = text-017.
    wa_cat-outputlen = 18.
    APPEND wa_cat TO fs_fldcat.
    wa_cat-fieldname = text-013.
    wa_cat-seltext_m = text-018.
    wa_cat-outputlen = 8.
    APPEND wa_cat TO fs_fldcat.
    ENDFORM. " FINAL_FIELDCATALOG
    *& Form FIELDCATALOG
    text
    --> p1 text
    <-- p2 text
    FORM fieldcatalog .
    wa_it_fldcat-fieldname = text-009.
    wa_it_fldcat-datatype = text-010.
    wa_it_fldcat-intlen = 18.
    APPEND wa_it_fldcat TO t_fldcat1.
    wa_it_fldcat-fieldname = text-011.
    wa_it_fldcat-datatype = text-010.
    wa_it_fldcat-intlen = 40.
    APPEND wa_it_fldcat TO t_fldcat1.
    LOOP AT s_atnam.
    CLEAR wa_it_fldcat.
    wa_it_fldcat-fieldname = s_atnam-low.
    wa_it_fldcat-datatype = text-010.
    wa_it_fldcat-intlen = 30.
    APPEND wa_it_fldcat TO t_fldcat1.
    ENDLOOP.
    wa_it_fldcat-fieldname = text-012.
    wa_it_fldcat-datatype = text-010.
    wa_it_fldcat-intlen = 18.
    APPEND wa_it_fldcat TO t_fldcat1.
    wa_it_fldcat-fieldname = text-013.
    wa_it_fldcat-datatype = text-014.
    wa_it_fldcat-intlen = 8.
    APPEND wa_it_fldcat TO t_fldcat1.
    ENDFORM. " FIELDCATALOG
    *& Form DYNAMIC_TABLE_CREATE
    text
    --> p1 text
    <-- p2 text
    FORM dynamic_table_create .
    Create dynamic internal table and assign to FS
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = t_fldcat1
    IMPORTING
    ep_table = t_newtable.
    ASSIGN t_newtable->* TO <t_dyntable>.
    Create dynamic work area and assign to FS
    CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
    ASSIGN t_newline->* TO <fs_dyntable>.
    ENDFORM. " DYNAMIC_TABLE_CREATE
    *& Form FINAL_DATA
    text
    --> p1 text
    <-- p2 text
    FORM final_data .
    LOOP AT i_objdata_temp INTO w_objdata_temp.
    *assign w_objdata_temp-matnr to <fs_dyntable>.
    AT NEW matnr.
    wa_flname = text-009.
    fieldvalue = w_objdata_temp-matnr.
    CONDENSE fieldvalue NO-GAPS.
    ASSIGN COMPONENT wa_flname
    OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> = fieldvalue.
    ENDAT.
    wa_flname = text-011.
    fieldvalue = w_objdata_temp-maktx.
    CONDENSE fieldvalue NO-GAPS.
    ASSIGN COMPONENT wa_flname
    OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> = fieldvalue.
    wa_flname = w_objdata_temp-atnam.
    fieldvalue = w_objdata_temp-ausp1.
    CONDENSE fieldvalue NO-GAPS.
    ASSIGN COMPONENT wa_flname
    OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> = fieldvalue.
    wa_flname = text-012.
    fieldvalue = w_objdata_temp-prdha.
    CONDENSE fieldvalue NO-GAPS.
    ASSIGN COMPONENT wa_flname
    OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> = fieldvalue.
    wa_flname = text-013.
    fieldvalue = w_objdata_temp-mstde.
    CONDENSE fieldvalue NO-GAPS.
    ASSIGN COMPONENT wa_flname
    OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
    <fs_fldval> = fieldvalue.
    AT END OF matnr.
    APPEND <fs_dyntable> TO <t_dyntable>.
    ENDAT.
    ENDLOOP.
    ENDFORM. " FINAL_DATA
    *& Form GET_CLASSIFICATION
    text
    --> p1 text
    <-- p2 text
    FORM get_classification .
    LOOP AT i_data INTO w_data.
    SELECT SINGLE * FROM klah WHERE class = c_nac.
    IF sy-subrc = 0.
    IF w_data-mstde >= klah-vondt.
    CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
    EXPORTING
    class = c_nac
    classtext = c_check
    classtype = c_klart
    clint = 0
    features = c_check
    language = sy-langu
    object = w_data-objek
    TABLES
    t_class = i_class
    t_objectdata = i_objdata
    EXCEPTIONS
    no_classification = 1
    no_classtypes = 2
    invalid_class_type = 3
    OTHERS = 4.
    LOOP AT i_class INTO w_class.
    MOVE w_class TO w_class_temp.
    APPEND w_class_temp TO i_class_temp.
    ENDLOOP .
    LOOP AT s_atnam.
    READ TABLE i_objdata INTO w_objdata WITH KEY atnam = s_atnam-low.
    IF sy-subrc = 0.
    MOVE w_data-matnr TO w_objdata_temp-matnr.
    MOVE w_data-maktx TO w_objdata_temp-maktx.
    MOVE-CORRESPONDING w_objdata TO w_objdata_temp.
    MOVE w_data-prdha TO w_objdata_temp-prdha.
    MOVE w_data-mstde TO w_objdata_temp-mstde.
    APPEND w_objdata_temp TO i_objdata_temp.
    ENDIF.
    ENDLOOP.
    ENDIF.
    ENDIF.
    ENDLOOP.
    ENDFORM. " GET_CLASSIFICATION

Maybe you are looking for