Export field symbol table out of method

Hi,
i have a report, that takes any xml and converts it into a table structure. In a method I generate the table structure using method cl_alv_table_create=>create_dynamic_table. Later in the same method I have filled the content of the XML file into a table typed as:  FIELD-SYMBOLS: <outtab> type standard table
Now I need to export this <outtab> out of my method. Because it is a unspecific field symbol table, I can not do this, by normal exporting.
In the PAI, where my method is called, I have deffined the table to return into as:
FIELD-SYMBOLS: <itab_message> type standard table.
Any help will be greatly appreciated.
Kind regards
Mikkel

Hi,
Please check this:
REPORT zmaschl_create_data_dynamic .
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
Build fieldcat
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SYST'
CHANGING
ct_fieldcat = it_fcat[].
LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.
MOVE-CORRESPONDING is_fcat TO is_fieldcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-ref_field = is_fcat-fieldname.
is_fieldcat-ref_table = is_fcat-ref_tabname.
APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.
Create a new Table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
Create a new Line with the same structure of the table.
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
Test it...
DO 30 TIMES.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = sy-index.
INSERT <l_line> INTO TABLE <l_table>.
ENDDO.
LOOP AT <l_table> ASSIGNING <l_line>.
ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.
WRITE <l_field>.
ENDLOOP.
Regards,
Shiva Kumar

Similar Messages

  • Copy  Field-symbols table

    My query is :
    I have a class, whenever i create an object the constructor is called which uses an data_tab variable of type TABLE.
    I'm making use of this class in my report which populates all the data into an internal table dynamically adding some other new fields.
    But I have created an class instance in the INITIALIZATION section itself.
    I wanted to pass the final internal table which is created dynamically to the CONSTRUCTOR.
    But when I pass the field-symbol table declared globally the program is getting dump and the message what I got is 'Field symbols is not assigned'.
    Please tell me how to proceed.
    Thanks & Regards
    Santhosh

    First you need to create another table with the structure that you have.
    call method cl_alv_table_create=>create_dynamic_table
         exporting
           it_fieldcatalog = LT_FIELDCATALOG
         importing
           ep_table = <FS_DATA2>
         exceptions
           generate_subpool_dir_full = 1
           others = 2
    field-symbols  : <fs_line1>, <fs_line2>, <fs_tmp1>, <fs_tmp2>.
    assign <FS_DATA2->* to <FS_2>.
    Now FS_1 and FS_2 are the tables.
    Also create work areas for the tables.
    CREATE DATA gw_line1 LIKE LINE OF <fs_1>
    CREATE DATA gw_line2 LIKE LINE OF <fs_2>.
    ASSIGN gw_line1->* TO <fs_line1>.
    assign gw_line2->* to <fs_line2>.
    With field symbols, you cannot move the rows directly, you will have to move it field by field.
    Once all the values are populated in the first table, copy it with the following logic.
    loop at <fs_1> into <fs_line1>
    Loop at   LT_FIELDCATALOG into LS_FIELDCATALOG.
    ASSIGN COMPONENT ls_fieldcatalog-fieldname OF STRUCTURE <fs_line1> TO <fs_tmp1>.
    ASSIGN COMPONENT ls_fieldcatalog-fieldname OF STRUCTURE <fs_line2> TO <fs_tmp2>.
    <fs_tmp2> = <fs_tmp1>
    endloop.
    append <fs_line2> to <fs_2>
    endloop.

  • Creating dynamic internal table(Not field symbol table)

    Hi Experts,
    I am facing problem creating Intarnal table
    I have fieldcatalog, I want create dynamic internal table(Not field symbol table).
    I have written----
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
       i_style_table             =
         it_fieldcatalog           = it_fldcat
          it_fieldcatalog           = me->gt_fieldcat
       i_length_in_byte          =
        IMPORTING
          ep_table                  = lt_new_table
       e_style_fname             =
        EXCEPTIONS
         generate_subpool_dir_full = 1
         OTHERS                    = 2.
        ASSIGN lt_new_table->* TO <gt_dyn_repdata>.
        CREATE DATA ls_new_line LIKE LINE OF <gt_dyn_repdata>.
        ASSIGN ls_new_line->* TO <gs_dyn_repdata>.
    above logic creating dynamic field symbol table.... But I want create normal internal table.
    Thanks,
    Rajasekhar

    Hi
    What do you mean?
    It needs to use the field-symbol, this is the price to pay if it wants a dynamic object
    Max

  • Field-symbols table

    Hi,
    can i transfer data from an internat table (ex: data begin of t occurs 0...) to a field-symbols table (field-symbols: <itab> type any table )?
    Thanx in advance.
    CV

    You mean assign the internal table to the field symbol?
    assign itab[] to <itab>.
    Regards,,
    Rich Heilman

  • Problem in color a cell for field symbol table.

    Hi guru's
    when i'm trying to color a cell based on condition, getting the following error.
    ERROR:   the data object  <line> has no structure and therefore no component called  "cell_colour" .
    providing my code here:
    DATA: wa_cellcolor TYPE lvc_s_scol,
             lv_index     TYPE sy-tabix.
       break satishkumarc.
       LOOP AT <table> ASSIGNING <line>.
         lv_index = sy-tabix.
         ASSIGN COMPONENT 'COMPLIANCE' OF STRUCTURE <line> TO <field>.
         IF <field> EQ 'YES'.
           wa_cellcolor-fname     = 'COMPLIANCE'.
           wa_cellcolor-color-col = col_positive.
           wa_cellcolor-color-int = 0.
           wa_cellcolor-color-inv = 0.
         ELSE.
           wa_cellcolor-fname     = 'COMPLIANCE'.
           wa_cellcolor-color-col = col_negative.
           wa_cellcolor-color-int = 0.
           wa_cellcolor-color-inv = 0.
         ENDIF.
         APPEND wa_cellcolor TO <line>-cell_colour.                                                     "   error line
         MODIFY <table> FROM <line>  INDEX lv_index TRANSPORTING cell_colour.      "  error line
         CLEAR: wa_cellcolor.
       ENDLOOP.
    actually i know  that  <line>-cell_colour  won't work. but i don't know how to achive this functionality .
    could anybody please help me out in this.
    Thanks in Advance.
    regards
    satish
    thank

    hi ashish,
    i'm using
    field-symbols: <line> type any.
    CREATE DATA  mydata  LIKE LINE OF <table>.
           ASSIGN mydata->* TO <line>.
    to make the structure. so i guess i cannot give the structure name while declaring <line>.
    Thanks & regards
    satish

  • Field symbols values passing as parameter to Methods

    Hi ,
    Can we pass fields symbols as parameter to methods ? I want to use field symbols values in my where in clause in methods, thereafter I want to pass my internal table to calling method.
    Thanks,
    Ujjwal

    Hi,
    I have create an class in which have I have create a method to written a select query to extract value from a table. The table name is passed by user. the select used is:
    select * from (tab) into CORRESPONDING FIELDS OF TABLE data.
    this method has 2 parameter:
    tab of type sting (importing).
    data of type ANY TABLE (exporting).
    and i am using the following code to get the data:
    data:  itab TYPE TABLE OF t578w.
    field-SYMBOLS <ab> TYPE any.
    ASSIGN 'T578W' to <ab>.
    CALL METHOD Z_GET_TABLE_DATA=>GET_TABLE " Z_GET_TABLE_DATA is the class name & GET_TABLE  is method name
        EXPORTING
          tab  = <ab>
        IMPORTING
          data = itab.
    You can code in similar way.
    I hope it helps.
    Regards
    Arjun
    Edited by: Arjun Thakur on Apr 23, 2009 3:16 PM

  • Field symbols as Table name and in where condition in a select statement

    Hello All,
    I have a scenario where I need to get user input on table name and old field value and new field value. Then based on user input, I need to select the record from the database. The column name for all the tables in question is different in the database, however there data type is the same and have same values.
    I am not able to use a field symbol for comparing the old field value to fetch the relevant record in my where clause.
    I cannnot loop through the entire table as it has 10 millilon records, please advice on how to add the where clause as field symbol as the table name is also dynamically assigned.
    Here is my code:
    DATA: TAB       LIKE SY-TNAME,
          TAB_COMP1 LIKE X031L-FIELDNAME,
          TAB_COMP2 LIKE X031L-FIELDNAME,
          NO_OF_FLD TYPE N.
    DATA: BEGIN OF BUFFER,
            ALIGNMENT TYPE F,
            C(8000)   TYPE C,
          END OF BUFFER.
    FIELD-SYMBOLS: <WA>   TYPE ANY,
                  <COMP1> TYPE ANY,
                  <COMP2> TYPE ANY.
    GET TABLE NAME GIVEN BY USER IN LOCAL VARIABLE
      TAB = TAB_NAME.
    CREATE FIELD NAME BASED ON THE TABLE NAME ENTERED.
      CASE TAB_NAME.
      WHEN 'OIUH_RV_GL'.
          KEY FIELD
            TAB_COMP1  = 'GL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OPSL'.
          KEY FIELD
            TAB_COMP1  = 'OPSL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'OTAX_GL_SYS_NO'.
            TAB_COMP2  = 'OTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN 'OIUH_RV_GTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'GTAX_GL_SYS_NO'.
            TAB_COMP2  = 'GTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN OTHERS.
            EXIT.
      ENDCASE.
    SET FIELD SYMBOL WITH APPROPRIATE TYPE TO BUFFER AREA.
    ASSIGN BUFFER TO <WA> CASTING TYPE (TAB).
    How to add where clause and remove the if condition in the select -- endselect
    SELECT * FROM (TAB) INTO <WA>. 
      ASSIGN COMPONENT TAB_COMP1 OF STRUCTURE <WA> TO <COMP1>.
      IF NO_OF_FLD = 2.
        ASSIGN COMPONENT TAB_COMP2 OF STRUCTURE <WA> TO <COMP2>.
      ENDIF.
      IF <COMP1> = OLD_SYS_NO.
        code for updating table would come here
          WRITE: 'MATCH FOUND'.
          EXIT.
      ENDIF.
    ENDSELECT.
    Please advice. Thanks much.
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:33 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:34 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:35 PM

    1. Create single column table for holding field name depending on the table entered.
    2. Take input from user: for e.g. table_name
    3. Using case load single column table with required fields
       for e.g.
      CASE TAB_NAME.
       WHEN 'OIUH_RV_GL'.
             Append 'GL_GL_SYS_NO' to KEY_FIELD --> KEY_FIELD is the single line internal table as mentioned in step 1.
       WHEN 'OIUH_RV_OPSL'.
             Append 'OPSL_GL_SYS_NO'.
       WHEN 'OIUH_RV_OTAX'.
             Append 'OTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN 'OIUH_RV_GTAX'.
             Append 'GTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN OTHERS.
          EXIT.
       ENDCASE.
       Now depending on the table name you have required column ready
    4. Create dynamic internal table using following sudo code
       Fill the fieldcatlog using the single column field table and DD03L table, See what all columns from DD03L you want to fill in field catlog table
       loop at internal table with all the fields.
        move it to field catalog.
        append field catalog.
       endloop.
    5. Pass this field catalog table to static method create_dynamic_table method
       DATA table TYPE REF TO DATA. --> data object for holding handle to dynamic internal table.
       call method cl_alv_table_create=>create_dynamic_table
       exporting
          it_fieldcatalog = fieldcatalog_tab
       importing
          ep_table = table.
    6. Now assign table reference to field symbol of type table.
       ASSIGN table->* to <field-tab>.
    7. Also create work area <field-wa> using refrence of table.
       create data object wa LIKE LINE OF <field-tab>.
       ASSIGN wa->* to <field-wa>.
    8. Also define field symbol for field name.
       for e.g. <field_name>
    4. Dynamic internal table is ready
    5. Now execute the select statement as follows:
       SELECT (KEY_FIELD)
         INTO <ITAB> --> created dynamically above
          FROM (TABLE_NAME)
         WHERE (WHERE).  --> WHERE is single line internal table having line type of CHAR72. So for every old value there will be one line
         Where condition is same as like we give in static way only difference in this case it will stored in internal table line wise.
        In this case you need to append all your where condition line by line in to WHERE.     
    5. To fill this dynamic internal table using ASSIGN COMPONENT <Comp_number> OF STRUCTURE <field-wa> TO <field-name>
       So in this case if first field of structure STRUCT1 is user_id then sudo-code will be
       loop at internal table containing list of fields into field_wa --> single column field table
           ASSIGN COMPONENT field_wa OF STRUCTURE <field-wa> TO <field>. "Here field_wa is wa area for single column internal table holding all the fieldnames.
           Now <field-name> points to user_id field. Move some value into it as nornally we do with variables.
           Move <your_new_value> to <field-name>. --> Assign new value
            or
            <field-name> = <your_new_value>.
       Endloop.
    6. After completing all the fields one row will be ready in <field_wa>.
       APPEND <field_wa> to <field_tab>.
    Hope this helps you.
    Thanks,
    Augustin.

  • Field-symbols as parameters to the method of a class

    Hi All,
    I am having an doubt regarding the field-symbols.Can we pass the field-symbols as a parameter to the method of a class.If yes can anyone tell me how to do this. Before posting I have searched regarding it in google but I did not find any better solution.Though I have seen some examples regarding the passing of field symbols as a parameter those scenarios does not match with my report as my report varies dynamically based on selection criteria.
    Below is the snippet of my code regarding the passing of field-symbols as a parameter.
    methods:  final_data importing <fs_h_line>TYPE any
                                                 <fs_h> TYPE STANDARD TABLE
                                   exporting <fs_f_line> TYPE any
                                                 <fs_f> TYPE STANDARD TABLE, 
    CALL METHOD l_obj->final_data exporting <fs_h_line> = <fs_header_line>
                                                                  <fs_h>      = <fs_header>
                                                   importing <fs_f_line> = <fs_final_line>
                                                                 <fs_f>      = <fs_final>.
    With the above code I am getting an error.Check whether it is correct or not.If not suggest the solution to resolve the issue.
    Regards,
    Chakradhar.

    Hi
    Maybe if you change this code below to field-symbol, it can work:
    DATA: tl_header_csv TYPE STANDARD TABLE OF yol_header_arquivo,
          tl_csv_aux    TYPE textline_t                          .
    DATA: wl_header_csv LIKE LINE OF tl_header_csv.
    converter_csv_al11_itab( EXPORTING im_t_csv = tl_csv_aux
                             IMPORTING ex_w_sap = wl_header_csv
                             CHANGING  ex_t_sap = tl_header_csv ).
    METHOD converter_csv_al11_itab.
      IM_T_CSV  Importing  Type  TEXTLINE_T
      EX_W_SAP  Exporting  Type  ANY
      EX_T_SAP  Changing   Type  STANDARD TABLE

  • Field-Symbols as Method Parameter

    Hi all,
    is there a way to create a field symbol within a method and export this field-symbol directly as a method parameter?
    The problem is that we can't pass a field symbol as method parameter unless it's assigned, but we would like to assign the field symbol within a method and give the result back to the calling program.
    We have managed to create a field symbol within the method and give back the result as a reference (we used the type ANY).
    We would like to pass the result field-symbol directly as a Method parameter.
    Any ideas?
    Best regards Dominik

    Hi all,
    thanks for you help. I managed to do the method calls with reference parameters but I'd like to do it with fieldsymbols instead.
    Your suggentions for field-symbold worked, but I could use them only with primitive datatypes.
    In my requirements the table must be created within the method, so the caller doesn't know the tablestructure.
    If a dummy table is assigned to the field-symbol before the call, the error "Two internal tables are neither compatible nor convertible" is produced.
    Is there a solution?
    Thanks in advance
    Dominik
    class ZZX0_CL_TEST definition
      public
      final
      create public .
    public section.
      class-methods FIELD_SYMBOLS_TAB_TEST
        changing
          !FS type ANY .
    METHOD FIELD_SYMBOLS_TAB_TEST .
      DATA: it_t000 TYPE TABLE OF t000.
      FIELD-SYMBOLS <field_symbol> TYPE ANY TABLE.
      ASSIGN it_t000 TO <field_symbol>.
      fs = <field_symbol>.
      EXIT.
    ENDMETHOD.
    REPORT zzx0_mini.
    DATA: it_mara  TYPE TABLE OF mara.
    START-OF-SELECTION.
    * Tabellen test
      FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.
      ASSIGN it_mara TO <fs>.
    *  ASSIGN it_t000 TO <fs>.
      CALL METHOD zzx0_cl_test=>field_symbols_tab_test
        CHANGING
          fs = <fs>.
      EXIT.

  • Loop at  field-symbol  (any table) into string ?

    Hi Everyone,
    I need little help, I have a requirement to extract table content with columns names as the header.
    After doing some search I figured out the best way to this since table name will be only avaialbe at runtime through
    a selection field . my problem is to loop through field-symbol and convert a structure to string value so that I can
    write to the file.
    REPORT  zlab_tbl_export.
    DATA table_name(30) VALUE 'ZSMARTTS_HTML'.
    DATA v_file(100) VALUE 'c:\sap_export.txt'.
    DATA line(1000).
    DATA: o_data TYPE REF TO data.
    CREATE DATA o_data TYPE TABLE OF (table_name).
    FIELD-SYMBOLS: <table> TYPE ANY TABLE.
    ASSIGN o_data->* TO <table>.
    SELECT * UP TO 100 ROWS FROM (table_name) INTO TABLE <table>.
    OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    >>>>>>> LOOP at <table> into line.   >>>>>>>>>>>>  " Here the code breaks and fail
      TRANSFER line to v_file. 
      WRITE :/ line.          
    ENDLOOP.
    CLOSE DATASET v_file.
    Exception Message
    |Error analysis                                                                                |
    |    You attempted to move one data object to another.                                             |
    |    This is not possible here because the conversion of a data object                             |
    |    of type "v" to type "C" is not supported.                                                     |
    |                                                                                |
    |      List of internal ABAP types:                                                                |
    |                                                                                |
    |      C    Text (Character)                                                                       |
    |      N    Numerical text                                                                         |
    |      D    Date (YYYYMMDD)                                                                        |
    |      T    Time (HHMMSS)                                                                          |
    |      X    Hexadecimal                                                                            |
    |      I    Integer                                                                                |
    |      P    Packed number                                                                          |
    |      F    Floating point number                                                                  |
    |                                                                                |
    |      h    Internal table                                                                         |
    |      r    Object reference                                                                       |
    |      l    Data reference                                                                         |
    |      g    String of type C                                                                       |
    |      y    String of type X                                                                       |
    |      s    2-byte integer with plus/minus sign                                                    |
    |      b    1-byte integer without plus/minus sign                                                 |
    |      u    Structure (flat structure)                                                             |
    |      v    Structure (deep structure)                                                             |

    Hi Everyone, I need little help, I have a requirement to extract table content with columns names as the header. After doing some search I figured out the best way to this since table name will be only avaialbe at runtime through a selection field . my problem is to loop through field-symbol and convert a structure to string value so that I can write to the file.
    thie is the code
    REPORT  zlab_tbl_export.
    DATA table_name(30) VALUE 'ZSMARTTS_HTML'.
    DATA v_file(100) VALUE 'c:\sap_export.txt'.
    DATA line(1000).
    DATA: o_data TYPE REF TO data.
    CREATE DATA o_data TYPE TABLE OF (table_name).
    FIELD-SYMBOLS: <table> TYPE ANY TABLE.
    ASSIGN o_data->* TO <table>.
    SELECT * UP TO 100 ROWS FROM (table_name) INTO TABLE <table>.
    OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    LOOP at <table> into line.   " Fail here
      TRANSFER line to v_file. 
      WRITE :/ line.           
    ENDLOOP.
    CLOSE DATASET v_file.
    and this is the exception:
    Error analysis                                                                               
    You attempted to move one data object to another.                                            
        This is not possible here because the conversion of a data object                            
        of type v to type C is not supported.                                                    
    Edited by: Misbah on Jan 7, 2010 11:50 PM

  • FIELD SYMBOL and INTERNAL TABLE

    Hi friends !
    How can i move internal table data to field symbol with a similar structure or diferent strucuture with more some fields  ?
    Thanks.

    Hi Fabrício
    Here is an example containing usage of field symbol as alias of an internal table.
    DATA lv_itab_name(30) TYPE c .
    FIELD-SYMBOLS: <table> TYPE table ,
                   <line> TYPE ANY ,
                   <fvalue> TYPE ANY.
    lv_itab_name = 'GT_ITAB[]' .
    ASSIGN (lv_itab_name) TO <table> .
    IF sy-subrc = 0 .
      LOOP AT <table> ASSIGNING <line> .
        DO .
          ASSIGN COMPONENT sy-index OF STRUCTURE <line> TO <fvalue> .
          IF sy-subrc NE 0 .
            EXIT .
          ENDIF .
          target_field = <fvalue> .
        ENDDO .
      ENDLOOP .
    ENDIF .
    If you know names of the fields, for each field you want to transfer, you can use
    ASSIGN COMPONENT '<field_name>' OF STRUCTURE <line> TO <fvalue> .
    Hope this helps...
    *--Serdar [[ BC ] | https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk sag jiw=]

  • Field-symbol definition for a variable representing transparent tables

    Hi Gurus
    I'm trying to create a very simple report to display table descriptions and their DB number of records:
    Ex:
    MARA 50000
    MARD 123000
    I can't compile this piece of code:
    field-symbols: <table>.
    assign (DD02T-TABNAME) to <table>.
        clear n.
        *SELECT COUNT( * )*
           INTO n
           FROM <table>.
    The problem here is that <table> is not defined in the ABAP dictionary as a a table , projection view or databse view.
    1. Is there a way of defining <table> with a field-symbol data statement to make it work?
    2. Alternatively, how can you produce a list of all table DB entry counts for a dynamic list of transparent tables?
    Thanks
    Nuno

    With the code you have field symbol will "point" to a table contained in DD02T-TABNAME , not its name.
    What you need is to get the table name , not table itself
    field-symbols: <table_name>.
    assign DD02T-TABNAME to <table>.  "get table name, not its content
    clear n.
    SELECT COUNT( * )
    INTO n
    FROM (<table>).
    or simply without field symbol
    SELECT COUNT( * )
    INTO n
    FROM (DD02T-TABNAME).
    Regards
    Marcin

  • Assigning Table/Structure Types using Field-Symbols

    Hello Gurus,
    How can we assign a table or structure type to a particulart internal table?
    What I want to do is to make my data declaration for i_tab reusable.
    i.e.
    DATA: v_tab  TYPE string.
    v_tab = 'MARA'.
    DATA  : i_tab  TYPE STANDARD TABLE OF v_tab.
    The purpose is to make the declaration flexible so program can change v_tab to any table names like LIPS, KNA1...etc making the i_tab flexible and reusable enough. Can anyone help me please? I try to use field-symbols, but I can not achieve what I want. Any bright ideas please?

      DATA: dref TYPE REF TO data.
      FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,
                     <line>  TYPE ANY.
      PARAMETERS: pa_tab TYPE tabname DEFAULT 'BUT000'.
      CREATE DATA dref TYPE STANDARD TABLE OF (pa_tab).
      ASSIGN dref->* TO <table>.
      SELECT * FROM (pa_tab) INTO TABLE <table>
               UP TO 10 ROWS.
    LOOP AT <table> ASSIGNING <line>.
    ENDLOOP.
    <LINE> will take the structure of the table line at runtime.
    This is quite flexible.
    But you can also declare it like this, as we did with the <table>:
    DATA: dref1 TYPE REF TO data.
    CREATE DATA dref1 TYPE (pa_tab).
    ASSIGN dref1->* TO <line>.
    This way <line> will already have the correct structure, even before the <ASSIGNING>.
    Edited by: Micky Oestreich on Mar 24, 2009 8:21 AM

  • Error in field symbol

    Hi all,
    i'm converting a field symbol table to internat table, where field symbol table structure is defined at runtime. for that i'm using
    call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = ifc1
                   importing
                      ep_table        = dy_table.
      assign dy_table->* to <dyn_table>.
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
      LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
      MOVE-CORRESPONDING <dyn_wa> TO dy_line.
      INSERT dy_line INTO TABLE dy_table.
      endloop.
    where
    data: dy_table type ref to data,
          dy_line  type ref to data,
    But in execution time it show a error that dy_table is not a internal table.
    pls give me ur suggestions.

    Hi Ravish,
    pls find yhe code, it;s throwing a error that dyn_table is not a internal table.
    TABLES : SFLIGHT.
    type-pools : abap.
    field-symbols: <dyn_table> type standard table ,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat,
          IFC1 TYPE LVC_T_FCAT.
    selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'SFLIGHT'.
    *FIELD-SYMBOLS <F> TYPE table p_table.
    data : field(10) type c.
    SELECT-OPTIONS : P_FIELD  FOR field.
    selection-screen end of block b1.
    start-of-selection.
      perform get_structure.
      perform get_selected_field.
      perform create_dynamic_itab.
      perform get_data.
      perform write_out.
    form get_structure.
    data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
    data : ref_table_des type ref to cl_abap_structdescr.
      ref_table_des ?=
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
      loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
    endform.
    form get_selected_field.
    data: wa like line of ifc.
    loop at ifc into wa.
    if wa-fieldname in p_field.
    append wa to ifc1.
    endif.
    sy-index = sy-index + 1.
    endloop.
    if ifc1 is initial .
    MESSAGE e000 WITH 'This field is not available in table'.
    endif.
    endform.
    form create_dynamic_itab.
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = ifc1
                   importing
                      ep_table        = dy_table.
      assign dy_table->* to <dyn_table>.
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    endform.
    form get_data.
    SELECT * INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
    FROM (p_table) UP TO 20 ROWS.
    endform.
    form write_out.
    Write out data from table.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index
             of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
    code for convert field symbol internal table to internal table.
      LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
      MOVE-CORRESPONDING <dyn_wa> TO dy_line.
      INSERT dy_line INTO TABLE dy_table.                    <----
      Error point
      endloop.
      endform.

  • Field symbols in Object Oriented ALV

    Hi Friends....Can somebody explain me what is the significance of field symbols in OO ALV. Why it is assigned to Field catalog. Also explain me the basic steps to do Object Oriented ALV. Thanks in advance...

    Hi Satyesh,
    Field symbols are symbolic names to which a memory area can be assigned during program runtime. A field symbol can be used instead of data objects at operand positions of statements.
    Please go through this following code.  This uses field symbols for OO ALV.
      LCL_TABLE_DISPLAY DEFINITION
    CLASS lcl_table_display DEFINITION.
      PUBLIC SECTION.
        TYPE-POOLS: abap, slis.
        CLASS-METHODS: display_list IMPORTING in_data TYPE STANDARD TABLE,
                       display_grid IMPORTING in_data TYPE STANDARD TABLE.
        METHODS: constructor IMPORTING in_data TYPE STANDARD TABLE
                             EXCEPTIONS casting_error
                                        empty_fieldcat.
        METHODS: output_list,
                 output_grid.
        METHODS: set_table_name   IMPORTING in_tabname  TYPE any,
                 set_alv_title    IMPORTING in_title    TYPE any,
                 set_alv_settings IMPORTING in_settings TYPE any,
                 set_alv_layout   IMPORTING in_layout   TYPE any,
                 set_alv_event    IMPORTING in_name     TYPE any
                                            in_form     TYPE any.
      PRIVATE SECTION.
        CLASS-DATA: g_table_object TYPE REF TO lcl_table_display.
        TYPES: BEGIN OF ty_defin,
                 fieldname     TYPE fieldname,
                 ref_tabname   TYPE tabname,
                 ref_fieldname TYPE fieldname,
               END OF ty_defin.
        DATA: g_repid  TYPE repid,
              g_struc  TYPE tabname,
              g_table  TYPE tabname.
        DATA: gt_data  TYPE REF TO data.
        DATA: g_title  TYPE lvc_title,
              gt_fcat  TYPE slis_t_fieldcat_alv,
              gs_sett  TYPE lvc_s_glay,
              gs_layo  TYPE slis_layout_alv,
              gt_evnt  TYPE slis_t_event.
        DATA: gt_defin TYPE TABLE OF ty_defin,
              g_level  TYPE tabname.
        METHODS: output_table IMPORTING data TYPE REF TO data
                                        mode TYPE c,
                 fill_fieldcat IMPORTING repid TYPE repid
                                         struc TYPE tabname
                                CHANGING fcat  TYPE slis_t_fieldcat_alv
                              EXCEPTIONS no_definition,
                 get_definition IMPORTING repid TYPE repid
                                          struc TYPE tabname
                                 CHANGING abap  TYPE rsfb_source,
                 recursive_definition IMPORTING repid TYPE repid
                                       CHANGING abap  TYPE rsfb_source,
                 map_structure IMPORTING source TYPE any
                                CHANGING destin TYPE any.
    ENDCLASS.
      LCL_TABLE_DISPLAY IMPLEMENTATION
    CLASS lcl_table_display IMPLEMENTATION.
      Display table in ALV list
      METHOD display_list.
        IF NOT g_table_object IS INITIAL.
          FREE: g_table_object.
        ENDIF.
        CREATE OBJECT g_table_object EXPORTING in_data = in_data.
        CALL METHOD g_table_object->output_list.
      ENDMETHOD.
      Display table in ALV grid
      METHOD display_grid.
        IF NOT g_table_object IS INITIAL.
          FREE: g_table_object.
        ENDIF.
        CREATE OBJECT g_table_object EXPORTING in_data = in_data.
        CALL METHOD g_table_object->output_grid.
      ENDMETHOD.
      Create table display
      METHOD constructor.
        DATA: ls_data TYPE REF TO data.
        DATA: ob_desc TYPE REF TO cl_abap_structdescr.
        DATA: l_absol TYPE char200,
              l_repid TYPE repid,
              l_struc TYPE tabname.
        FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,
                       <struc> TYPE ANY.
      Get data and store it into attribute
        CREATE DATA me->gt_data LIKE in_data.
        ASSIGN me->gt_data->* TO <table>.
        <table> = in_data.
      Get global data definition
        CREATE DATA ls_data LIKE LINE OF <table>.
        ASSIGN ls_data->* TO <struc>.
        CATCH SYSTEM-EXCEPTIONS assign_casting_illegal_cast = 1.
          ob_desc ?= cl_abap_typedescr=>describe_by_data( <struc> ).
        ENDCATCH.
        IF sy-subrc = 1.
          RAISE casting_error.
        ENDIF.
      Get program name and main type used to define table
        l_absol = ob_desc->absolute_name.
        SPLIT l_absol AT '\TYPE=' INTO l_repid l_struc.
        SHIFT l_repid UP TO '='.
        SHIFT l_repid.
        CHECK l_struc NP '%_*'.
        IF me->g_repid NE l_repid
        OR me->g_struc NE l_struc.
        Set attributes
          me->g_repid = l_repid.
          me->g_struc = l_struc.
          me->g_table = l_struc.
          REPLACE 'TY' WITH 'WT' INTO me->g_table.
        Field catalog
          CALL METHOD fill_fieldcat EXPORTING repid = l_repid
                                              struc = l_struc
                                     CHANGING fcat  = me->gt_fcat.
          IF me->gt_fcat IS INITIAL.
            RAISE empty_fieldcat.
          ENDIF.
        ENDIF.
      ENDMETHOD.
      Output list
      METHOD output_list.
        CALL METHOD output_table EXPORTING data = me->gt_data
                                           mode = 'L'.
      ENDMETHOD.
      Output grid
      METHOD output_grid.
        CALL METHOD output_table EXPORTING data = me->gt_data
                                           mode = 'G'.
      ENDMETHOD.
      Output table
      METHOD output_table.
        DATA: ls_vari TYPE disvariant.
        FIELD-SYMBOLS: <table> TYPE STANDARD TABLE.
        ASSIGN me->gt_data->* TO <table>.
      Get default user variant
        ls_vari-report = me->g_repid.
        ls_vari-username = sy-uname.
        CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
             EXPORTING
                  i_save     = 'U'
             CHANGING
                  cs_variant = ls_vari
             EXCEPTIONS
                  OTHERS     = 0.
      Display table contents
        IF mode = 'G'.
          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
               EXPORTING
                    i_callback_program = me->g_repid
                    i_grid_title       = me->g_title
                    i_grid_settings    = me->gs_sett
                    is_layout          = me->gs_layo
                    it_fieldcat        = me->gt_fcat
                    i_save             = 'U'
                    is_variant         = ls_vari
                    it_events          = me->gt_evnt
               TABLES
                    t_outtab           = <table>
               EXCEPTIONS
                    OTHERS             = 0.
        ELSE.
          CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
               EXPORTING
                    i_callback_program = me->g_repid
                    is_layout          = me->gs_layo
                    it_fieldcat        = me->gt_fcat
                    i_save             = 'U'
                    is_variant         = ls_vari
                    it_events          = me->gt_evnt
               TABLES
                    t_outtab           = <table>
               EXCEPTIONS
                    OTHERS             = 0.
        ENDIF.
      ENDMETHOD.
      Fill field catalog
      METHOD fill_fieldcat.
        DATA: lt_abap   TYPE TABLE OF rssource.
        DATA: ls_defin  TYPE ty_defin.
        DATA: lt_dfies  TYPE TABLE OF dfies,
              ls_dfies  TYPE dfies,
              ls_dd04v  TYPE dd04v,
              ls_dd01v  TYPE dd01v,
              l_flong   TYPE dfies-lfieldname,
              l_dname   TYPE dfies-domname.
        DATA: ls_fcat   TYPE slis_fieldcat_alv,
              ls_fcat2  TYPE slis_fieldcat_alv.
        DATA: l_index   TYPE i,
              l_nbfld   TYPE i.
        FREE: me->gt_defin.
      Process data definition
        CALL METHOD get_definition EXPORTING repid = repid
                                             struc = struc
                                    CHANGING abap  = lt_abap.
      Process sub levels if required
        CALL METHOD recursive_definition EXPORTING repid = repid
                                          CHANGING abap  = lt_abap.
        IF me->gt_defin IS INITIAL.
          RAISE no_definition.
        ENDIF.
        LOOP AT me->gt_defin INTO ls_defin.
          CLEAR: ls_fcat.
          MOVE-CORRESPONDING ls_defin TO ls_fcat.
        Retrieve info about this field
          FREE: ls_dfies, ls_dd04v, ls_dd01v, l_dname.
          l_flong = ls_fcat-ref_fieldname.
          SET LOCALE LANGUAGE 'E'.
          TRANSLATE: ls_fcat-ref_tabname   TO UPPER CASE,
                     ls_fcat-ref_fieldname TO UPPER CASE,
                     l_flong               TO UPPER CASE.
          IF NOT ls_fcat-ref_tabname IS INITIAL.
          Try to get info about field in table
            CALL FUNCTION 'DDIF_FIELDINFO_GET'
                 EXPORTING
                      tabname        = ls_fcat-ref_tabname
                      fieldname      = ls_fcat-ref_fieldname
                      lfieldname     = l_flong
                 IMPORTING
                      dfies_wa       = ls_dfies
                 EXCEPTIONS
                      not_found      = 1
                      internal_error = 2
                      OTHERS         = 3.
            IF sy-subrc = 0.
              MOVE-CORRESPONDING ls_dfies TO ls_fcat.
              ls_fcat-fieldname = ls_defin-fieldname.
              MOVE: ls_dfies-keyflag   TO ls_fcat-key,
                    ls_dfies-scrtext_m TO ls_fcat-seltext_l,
                    ls_dfies-domname   TO l_dname.
            ENDIF.
          ELSE.
          Try to get info about structure
            ls_defin-ref_tabname = ls_defin-ref_fieldname.
            CALL FUNCTION 'DDIF_FIELDINFO_GET'
                 EXPORTING
                      tabname   = ls_defin-ref_tabname
                 TABLES
                      dfies_tab = lt_dfies
                 EXCEPTIONS
                      OTHERS    = 0.
            IF NOT lt_dfies IS INITIAL.
            Process fields of this structure
              LOOP AT lt_dfies INTO ls_dfies.
                CLEAR: ls_fcat.
                MOVE-CORRESPONDING ls_dfies TO ls_fcat.
                CONCATENATE ls_defin-fieldname ls_fcat-fieldname
                       INTO ls_fcat-fieldname
                  SEPARATED BY '-'.
                MOVE ls_dfies-keyflag TO ls_fcat-key.
                MOVE ls_dfies-scrtext_m TO ls_fcat-seltext_l.
                ls_fcat-tabname = me->g_table.
                CLEAR: ls_fcat-col_pos,
                       ls_fcat-offset.
                IF ls_fcat-ref_tabname IS INITIAL.
                  ls_fcat-ddictxt = 'L'.
                ENDIF.
              Display Yes/No fields as checkboxes
                IF ls_dfies-domname = 'XFELD'.
                  ls_fcat-checkbox = 'X'.
                ENDIF.
              Add field to field catalog
                APPEND ls_fcat TO fcat.
              ENDLOOP.
            ELSE.
            Try to get info about data element
              CALL FUNCTION 'DDIF_DTEL_GET'
                   EXPORTING
                        name          = ls_fcat-ref_fieldname
                        langu         = sy-langu
                   IMPORTING
                        dd04v_wa      = ls_dd04v
                   EXCEPTIONS
                        illegal_input = 1
                        OTHERS        = 2.
              IF sy-subrc = 0.
                MOVE-CORRESPONDING ls_dd04v TO ls_fcat.
                MOVE: ls_dd04v-scrtext_m TO ls_fcat-seltext_l,
                      ls_dd04v-domname   TO l_dname.
              ELSE.
              Finally try to get info about domain
                CALL FUNCTION 'DDIF_DOMA_GET'
                     EXPORTING
                          name          = ls_fcat-ref_fieldname
                          langu         = sy-langu
                     IMPORTING
                          dd01v_wa      = ls_dd01v
                     EXCEPTIONS
                          illegal_input = 1
                          OTHERS        = 2.
                IF sy-subrc = 0.
                  MOVE-CORRESPONDING ls_dd01v TO ls_fcat.
                  MOVE: ls_dd01v-ddtext  TO ls_fcat-seltext_l,
                        ls_dd01v-domname TO l_dname.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDIF.
        Table name must be internal table containing data
          ls_fcat-tabname = g_table.
        No offset
          CLEAR: ls_fcat-offset.
        Default text is stored in long text
          IF ls_fcat-ref_tabname IS INITIAL.
            ls_fcat-ddictxt = 'L'.
          ENDIF.
        Display Yes/No fields as checkboxes
          IF l_dname = 'XFELD'.
            ls_fcat-checkbox = 'X'.
          ENDIF.
        Add field to field catalog
          APPEND ls_fcat TO fcat.
        ENDLOOP.
      Link between fields
        DESCRIBE TABLE fcat LINES l_nbfld.
        LOOP AT fcat INTO ls_fcat.
          IF sy-tabix NE l_nbfld.
            l_index = sy-tabix + 1.
            READ TABLE fcat INTO ls_fcat2 INDEX l_index.
            IF sy-subrc = 0.
              IF ls_fcat-datatype = 'CURR'.
              Currency unit
                IF ls_fcat2-datatype = 'CUKY'.
                  ls_fcat-cfieldname = ls_fcat2-fieldname.
                  ls_fcat-ctabname   = ls_fcat2-tabname.
                  MODIFY fcat FROM ls_fcat.
                ELSE.
                  LOOP AT fcat INTO ls_fcat2
                               FROM l_index
                              WHERE datatype = 'CUKY'.
                  First currency unit after field
                    ls_fcat-cfieldname = ls_fcat2-fieldname.
                    ls_fcat-ctabname   = ls_fcat2-tabname.
                    MODIFY fcat FROM ls_fcat.
                    EXIT.
                  ENDLOOP.
                  IF sy-subrc NE 0.
                  No currency unit after field, try before
                    READ TABLE fcat INTO ls_fcat2
                                WITH KEY datatype = 'CUKY'.
                    IF sy-subrc = 0.
                      ls_fcat-cfieldname = ls_fcat2-fieldname.
                      ls_fcat-ctabname   = ls_fcat2-tabname.
                      MODIFY fcat FROM ls_fcat.
                    ENDIF.
                  ENDIF.
                ENDIF.
              ENDIF.
              IF ls_fcat-datatype = 'QUAN'.
              Quantity unit
                IF ls_fcat2-datatype = 'UNIT'.
                  ls_fcat-cfieldname = ls_fcat2-fieldname.
                  ls_fcat-ctabname   = ls_fcat2-tabname.
                  MODIFY fcat FROM ls_fcat.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDLOOP.
      ENDMETHOD.
      Get definition of type from code source
      METHOD get_definition.
        DATA: l_strng TYPE rssource,
              ls_abap TYPE rssource,
              l_fdpos TYPE i,
              l_first TYPE i,
              l_lastr TYPE i.
        DATA: lt_incl TYPE TABLE OF repid,
              ls_incl TYPE repid.
      Get program code
        READ REPORT repid INTO abap.
        CHECK sy-subrc EQ 0.
      Get first line of definition
        CONCATENATE 'BEGIN OF' struc INTO l_strng
                                SEPARATED BY space.
        LOOP AT abap INTO ls_abap.
          IF ls_abap CS l_strng.
            l_fdpos = strlen( l_strng ) + sy-fdpos.
            IF ls_abap+l_fdpos(1) CA ', "'.
              l_first = sy-tabix.
              EXIT.
            ENDIF.
          ENDIF.
        ENDLOOP.
        IF l_first IS INITIAL.
        Table is defined in an include
          CALL FUNCTION 'RS_GET_ALL_INCLUDES'
               EXPORTING
                    program    = repid
               TABLES
                    includetab = lt_incl
               EXCEPTIONS
                    OTHERS     = 1.
          IF sy-subrc = 0.
            LOOP AT lt_incl INTO ls_incl.
            Try to find definition in this include
              READ REPORT ls_incl INTO abap.
              LOOP AT abap INTO ls_abap.
                IF ls_abap CS l_strng.
                  l_fdpos = strlen( l_strng ) + sy-fdpos.
                  IF ls_abap+l_fdpos(1) CA ',. "'.
                    l_first = sy-tabix.
                    EXIT.
                  ENDIF.
                ENDIF.
              ENDLOOP.
              IF NOT l_first IS INITIAL.
                EXIT.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
      Get last line of definition
        CONCATENATE 'END OF' struc INTO l_strng
                              SEPARATED BY space.
        LOOP AT abap INTO ls_abap.
          IF ls_abap CS l_strng.
            l_fdpos = strlen( l_strng ) + sy-fdpos.
            IF ls_abap+l_fdpos(1) CA ',. "'.
              l_lastr = sy-tabix - l_first.
              EXIT.
            ENDIF.
          ENDIF.
        ENDLOOP.
      Keep only relevant code lines
        IF l_first LE 0
        OR l_lastr LE 0.
          REFRESH abap.
        ELSE.
          DELETE abap TO l_first.
          DELETE abap FROM l_lastr.
        ENDIF.
      ENDMETHOD.
      Get definition of type recursively
      METHOD recursive_definition.
        DATA: lt_token TYPE TABLE OF stokex,
              ls_token TYPE stokex,
              lt_state TYPE TABLE OF sstmnt,
              ls_state TYPE sstmnt.
        DATA: ls_defin TYPE ty_defin,
              l_reffld TYPE fieldname.
        DATA: lt_recu  TYPE TABLE OF rssource.
      Retrieve tokens
        SCAN ABAP-SOURCE abap
                  TOKENS INTO lt_token
              STATEMENTS INTO lt_state.
        LOOP AT lt_state INTO ls_state.
          CLEAR: ls_defin.
        Field name
          READ TABLE lt_token INTO ls_token
                             INDEX ls_state-from.
          ls_defin-fieldname = ls_token-str.
        Reference type
          READ TABLE lt_token INTO ls_token
                             INDEX ls_state-to.
          l_reffld = ls_token-str.
        Check if this type is defined in program
          FREE: lt_recu.
          CALL METHOD get_definition EXPORTING repid = repid
                                               struc = l_reffld
                                      CHANGING abap  = lt_recu.
          IF lt_recu IS INITIAL.
            IF NOT g_level IS INITIAL.
             CONCATENATE g_level ls_defin-fieldname INTO ls_defin-fieldname
                                                           SEPARATED BY '-'.
              CONDENSE ls_defin-fieldname.
            ENDIF.
            IF l_reffld CS '-'.
              SPLIT l_reffld AT '-'
                           INTO ls_defin-ref_tabname
                                ls_defin-ref_fieldname.
              IF ls_defin-ref_tabname = 'SY'.
                ls_defin-ref_tabname = 'SYST'.
              ENDIF.
            ELSE.
              ls_defin-ref_fieldname = ls_token-str.
            ENDIF.
            APPEND ls_defin TO me->gt_defin.
          ELSE.
          Process sub levels
            IF me->g_level IS INITIAL.
              me->g_level = ls_defin-fieldname.
            ELSE.
              CONCATENATE me->g_level ls_defin-fieldname INTO me->g_level
                                                 SEPARATED BY '-'.
            ENDIF.
            CALL METHOD recursive_definition EXPORTING repid = repid
                                              CHANGING abap  = lt_recu.
            IF me->g_level CS '-'.
              SHIFT me->g_level RIGHT UP TO '-'.
              SHIFT me->g_level RIGHT.
              SHIFT me->g_level LEFT DELETING LEADING space.
            ELSE.
              CLEAR: me->g_level.
            ENDIF.
          ENDIF.
        ENDLOOP.
      ENDMETHOD.
      Set table name
      METHOD set_table_name.
        me->g_table = in_tabname.
      ENDMETHOD.
      Set title
      METHOD set_alv_title.
        me->g_title = in_title.
      ENDMETHOD.
      Set settings
      METHOD set_alv_settings.
        CALL METHOD map_structure EXPORTING source = in_settings
                                   CHANGING destin = me->gs_sett.
      ENDMETHOD.
      Set layout
      METHOD set_alv_layout.
        CALL METHOD map_structure EXPORTING source = in_layout
                                   CHANGING destin = me->gs_layo.
      ENDMETHOD.
      Add event
      METHOD set_alv_event.
        DATA: ls_evnt TYPE slis_alv_event.
        ls_evnt-name = in_name.
        ls_evnt-form = in_form.
        COLLECT ls_evnt INTO gt_evnt.
      ENDMETHOD.
      Map fields from incoming structure into attribute
      METHOD map_structure.
        DATA: ob_desc  TYPE REF TO cl_abap_structdescr,
              ls_compo TYPE abap_compdescr.
        FIELD-SYMBOLS: <field> TYPE ANY,
                       <struc> TYPE ANY.
        ob_desc ?= cl_abap_typedescr=>describe_by_data( destin ).
        LOOP AT ob_desc->components INTO ls_compo.
          ASSIGN COMPONENT ls_compo-name OF STRUCTURE source TO <field>.
          IF <field> IS ASSIGNED.
            ASSIGN COMPONENT ls_compo-name OF STRUCTURE destin TO <struc>.
            CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
              MOVE <field> TO <struc>.
            ENDCATCH.
            UNASSIGN <field>.
          ENDIF.
        ENDLOOP.
      ENDMETHOD.
    ENDCLASS.
    PLZ REWARD POINTS

Maybe you are looking for