Field Symbol to internal table

Hi all,
I need to fill in a table without konwing in advance its structure. The solution is to use a field symbol and assign its content and <b>that works</b>.
DATA : TAB_DATA TYPE REF TO DATA ...
FIELD-SYMBOLS: <fs> TYPE ANY TABLE ...
ASSIGN tab_data->* TO <fs> ...
OK, I can read the content of my table directly from <fs> and display it in the layout of my BSP.
<b>But Now</b> : I want to sort this table when a user click on the header column of my BSP.
The problem it's that I don't know the structure of my table and the following code :
SORT <fs> BY event->column_key DESCENDING.
gives me the following error :
The specified type has no structure and therefore no component called "EVENT".
Any idea to solve this problem ?
Regards.

Allan,
I am assuming that somehow you will be able to know the name of the column on which the user has clicked at runtime.
See if you can use something like this, provided you can get the name of the column at runtime.
data : column(10) type c value 'Column name'.
sort t_data by (column) descending.
regards,
Ravi
Note : Please mark the helpful answers.
Message was edited by: Ravikumar Allampallam

Similar Messages

  • Passing content of field symbol to internal table

    Hi experts,
    I need to pass the content of a field symbol to a internal table. Below is the following structure of the field symbol and internal table. But I'm encountering a short dump:
    TYPES: BEGIN OF fint_frange,
            fieldname    LIKE rsdstabs-prim_fname,
            fieldtype(1) TYPE c,
            selopt_t     TYPE fint_selopt_t,
           END OF fint_frange.
    TYPES: fint_frange_t TYPE fint_frange OCCURS 10.
    CONSTANTS: lc_save_selections(31) TYPE c VALUE '(RFINTITAR)GT_SAVE_SELECTIONS[]',
    FIELD-SYMBOLS: <fs_save_selections> TYPE STANDARD TABLE.
    ASSIGN (lc_save_selections) TO <fs_save_selections>.
    i_save_selections[] = <fs_save_selections>.
    Short dump: You attempted to move one data object to another.
    This is not possible here because the internal tables concerned
    are neither compatible nor convertible.
    Thanks in advance.

    Hi,
    what is ur internal table structure?
    if structure of both field symbol and internal table is not same,
    u can not put equal betwwen them.
    ur  <fs_save_selections> is having one constanat value lc_save_selections.
    and ur assaigning that to an internal table with some structure ......
    so structure is not same for both..........check it once.
    Regards,
    kk.

  • Field-symbols and internal table

    Hello,
    How do I declare a field-symbol as an intenal table?
    I have a internal table declared, but i need to declare a field symbols as my internal table´s type. How do I do it?
    What I wrote was this:
    DATA: BEGIN OF IT_INTE OCCURS 0,
               FIELD(3) TYPE C,
           END OF IT_INTE.
    FIELD-SYMBOLS:  isn´t defined as an internal table, how do I fix it.
    Thanks!!!
    Gabriel.

    It is very much possible to have a field symbol point to a internal table.  Here is some sample code.
    report  zrich_0001.
    data: begin of itab1 occurs 0,
          fld1(10) type c,
          fld3(10) type c,
          fld5(10) type c,
          end of itab1.
    data: wa1 like line of itab1.
    field-symbols: <fs_table> type table.
    field-symbols: <fs_wa>.
    field-SYMBOLS: <fs_field>.
    * Setup the data
    itab1-fld1 = '0000000001'.
    itab1-fld3 = '0000000002'.
    itab1-fld5 = '0000000003'.
    append itab1.
    itab1-fld1 = '0000000004'.
    itab1-fld3 = '0000000005'.
    itab1-fld5 = '0000000006'.
    append itab1.
    assign itab1[] to <fs_table>.
    assign wa1     to <fs_wa>.
    loop at <fs_table> into <fs_wa>.
    * Write out each field of the line
      do.
           assign COMPONENT sy-index of structure <fs_wa> to <fs_field>.
        if sy-subrc <> 0.
          exit.
          endif.
          write:/ <fs_field>.
      enddo.
      skip 2.
    endloop.
    Regards,
    Rich Heilman

  • Re: field symbols and interna table

    hi,
    here is field symbol which is table type
    FIELD-SYMBOLS: <gt_pos_data> TYPE table.
    there is one internal table it_data.
    how can  move <gt_pos_data> to it_data.
    please help me.
    rgds

    Hi
    You can assign field wise:
    like
    <gt_pos_data>- field to  to it_data-field.
    Field Symbols
    Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.
    Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.
    Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects.
    All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.
    You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.
    Field symbols provide greater flexibility when you address data objects:
    If you want to process sections of fields, you can specify the offset and length of the field dynamically.
    You can assign one field symbol to another, which allows you to address parts of fields.
    Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.
    You can also force a field symbol to take different technical attributes from those of the field assigned to it.
    The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.
    While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.
    For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.
    check the below links u will get the answers for your questions
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
    http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
    Syntax Diagram
    FIELD-SYMBOLS
    Basic form
    FIELD-SYMBOLS <fs>.
    Extras:
    1. ... TYPE type
    2. ... TYPE REF TO cif
    3. ... TYPE REF TO DATA
    4. ... TYPE LINE OF type
    5. ... LIKE s
    6. ... LIKE LINE OF s
    7. ... TYPE tabkind
    8. ... STRUCTURE s DEFAULT wa
    The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.
    Effect
    This statement declares a symbolic field called <fs>. At runtime, you can assign a concrete field to the field symbol using ASSIGN. All operations performed with the field symbol then directly affect the field assigned to it.
    You can only use one of the additions.
    Example
    Output aircraft type from the table SFLIGHT using a field symbol:
    FIELD-SYMBOLS <PT> TYPE ANY.
    DATA SFLIGHT_WA TYPE SFLIGHT.
    ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.
    WRITE <PT>.
    Addition 1
    ... TYPE type
    Addition 2
    ... TYPE REF TO cif
    Addition 3
    ... TYPE REF TO DATA
    Addition 4
    ... TYPE LINE OF type
    Addition 5
    ... LIKE s
    Addition 6
    ... LIKE LINE OF s
    Addition 7
    ... TYPE tabkind
    Effect
    You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.
    This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.
    In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.
    Effect
    Assigns any (internal) field string or structure to the field symbol from the ABAP Dictionary (s). All fields of the structure can be addressed by name: <fs>-fieldname. The structured field symbol points initially to the work area wa specified after DEFAULT.
    The work area wa must be at least as long as the structure s. If s contains fields of the type I or F, wa should have the structure s or at least begin in that way, since otherwise alignment problems may occur.
    Example
    Address components of the flight bookings table SBOOK using a field symbol:
    DATA SBOOK_WA LIKE SBOOK.
    FIELD-SYMBOLS <SB> STRUCTURE SBOOK
    DEFAULT SBOOK_WA.
    WRITE: <SB>-BOOKID, <SB>-FLDATE.
    Related
    ASSIGN, DATA
    Additional help
    Declaring Field Symbols
    Reward points if useful
    Regards
    Anji

  • Usage of field-symbol to internal table generically.

    Hi gurus,
    please tell the usage of field symbol to an internall table.
    how do i use field symbol generically , so that i can use same field symbol for many different internal tables.
    regards,
    krishna
    TABLES: EKKO.
    DATA: ITAB TYPE STANDARD TABLE OF EKKO INITIAL SIZE 1.
    SELECT-OPTIONS: P_EBELN FOR EKKO-EBELN OBLIGATORY.
    FIELD-SYMBOLS <FS> TYPE any.
    SELECT *
    FROM EKKO
    INTO TABLE ITAB
    WHERE EBELN IN P_EBELN.
    LOOP AT ITAB ASSIGNING <FS> casting ekko.
      WRITE:/ <FS>-EBELN, <FS>-BUKRS, <FS>-LIFNR, <FS>-AEDAT, <FS>-EKGRP, <FS>-STATU, <FS>-SPRAS.
    ENDLOOP.

    How about something SIMPLE like this.
    This creates a dynamic table and displays it in an editable grid.
    The key to a real Generic internal table is to use the RTTI  functionality to generate a field catalog of the structure you want to use as an internal table and then create a dynamic table based on the FCAT created from your structure.
    For the code shown below code a simple screen ( SE51) with a custom container on it  called CCONTAINER1.
    Code also a standard status (SE41) with just the BACK, EXIT and CANCEL buttons on it.
    You can use this type of program as a model for ANY dynamic table. Note however that you still can't include DEEP structure in your dynamic table.
    With the program shown below you can edit the grid but you'll have to add your own functionality such as cell selection, double click etc etc.
    All the code is showning you really is how to take any user defined structure and simply without a whole load of fuss, buld an FCAT, a DYNAMIC TABLE, Populate it and display a grid.
    DO NOT EVER USE AGAIN THE OLD SLIS MODULES SUCH AS FM REUSE_ALV_etc.   Go for OO either cl_gui_alv_grid or if you don't need to edit anything the new SALV class.
    If you are still on 4.6 then the SALV class won't exist but the cl_gui_alv_grid class is fine.
    You can see also just by changing a few lines of codeyou can   display a grid of almost any structure you can think of (or populate another dynamic table).
    Note also if you have an actual table defined you can also always code something like your_itab[] = <dyn_table>  so you can retrieve your data easily enough via standard abap.
    All you need to do is define your structure, create the fcat and populate the dynamic table.
    Even if you don't want a a GRID you've got your data in a dynamic table which is what I believe you wanted in the first place. You don't have to display or use a GRID if you don't need to but I've added the code here as lots of applications need to display data in just these types of lists.
    Now surprise your Boss by coding in 10 mins a program he / she thought would take you 1 week. !!!!!.
    program zzz_simple_editable_grid.
    * Define any structure
    types:  begin of s_elements,
      vbeln   type vapma-vbeln,
      posnr   type vapma-posnr,
      matnr   type vapma-matnr,
      kunnr   type vapma-kunnr,
      werks   type vapma-werks,
      vkorg   type vapma-vkorg,
      vkbur   type vapma-vkbur,
      status  type c,
    end of  s_elements.
    * end of your structure
    data lr_rtti_struc type ref to cl_abap_structdescr .
    data:
        zog                     like line of lr_rtti_struc->components .
    data:
      zogt                    like table of zog,
    wa_it_fldcat type lvc_s_fcat,
    it_fldcat type lvc_t_fcat ,
    dy_line            type ref to data,
    dy_table           type ref to data.
    data:  dref               type ref to data.
    field-symbols: <fs> type any,
       <dyn_table>    type  standard table,
       <dyn_wa>.
    data grid_container1 type ref to cl_gui_custom_container .
    data grid1 type ref to cl_gui_alv_grid .
    data: ok_code type sy-ucomm.
    data: struct_grid_lset type lvc_s_layo.
    *now I want to build a field catalog
    * First get your data structure into a field symbol
    create data dref type s_elements.
    assign dref->* to <fs>.
    lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
    * Now get the structure details into a table.
    * table zogt[] contains the structure details
    * From which we can build the field catalog
    zogt[]  = lr_rtti_struc->components.
    loop at zogt into zog.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = zog-name .
      wa_it_fldcat-datatype = zog-type_kind.
      wa_it_fldcat-inttype = zog-type_kind.
      wa_it_fldcat-intlen = zog-length.
      wa_it_fldcat-decimals = zog-decimals.
      wa_it_fldcat-coltext = zog-name.
      wa_it_fldcat-lowercase = 'X'.
      append wa_it_fldcat to it_fldcat .
    endloop.
    * You can perform any modifications / additions to your field catalog
    * here such as your own column names etc.
    * Now using the field catalog created above we can
    * build a dynamic table
    * and populate it
    * First build the dynamic table
    * the table will contain entries for
    * our structure defined at the start of the program
    call method cl_alv_table_create=>create_dynamic_table
           exporting
                it_fieldcatalog = it_fldcat
           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>.
    * Now fill our table with data
    select vbeln posnr matnr kunnr werks vkorg vkbur
           up to 200 rows
           from vapma
           into  corresponding fields of table <dyn_table>.
    * Call the screen to display the grid
    call screen 100.
    * PBO module
    module status_0100 output.
    data: off type int4.
    break-point 1.
    if sy-batch = 'X'.
    call method cl_gui_alv_grid=>offline
    receiving
    e_offline = off.
    endif.
    if sy-batch = 'X'.
    if ( off is initial ).
        create object grid_container1
                exporting
                   container_name = 'CCONTAINER1'.
        create object  grid1
           exporting
              i_parent = grid_container1.
    endif.
    endif.
    if sy-batch ne 'X'.
       if grid_container1 is initial.
         create object grid_container1
                 exporting
                    container_name = 'CCONTAINER1'.
      endif.
        create object  grid1
           exporting
              i_parent = grid_container1.
       if sy-batch ne 'X'.
        struct_grid_lset-edit = 'X'.    "To enable editing in ALV
      endif.
      endif.
        call method grid1->set_table_for_first_display
          exporting is_layout =  struct_grid_lset
          changing
                     it_outtab       = <dyn_table>
                     it_fieldcatalog = it_fldcat.
      set pf-status '001'.
      set titlebar '000'.
    endmodule.
    * PAI module
    module user_command_0100 input.
      case sy-ucomm.
        when 'BACK'.
          leave program.
        when 'EXIT'.
          leave program.
        when 'RETURN'.
          leave program.
        when others.
      endcase.
    endmodule.
    Cheers
    jimbo

  • 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=]

  • Changing the order of fields in an internal table

    Hi all,
    I'm using field symbol as internal table. this table has got a standard database structure.
    I want to make the 3rd column of this internal table as 1st colums keeping rest of the columns as it is.
    Is there any way to do this?
    Thanks,
    Anil.

    Hi
        Instead of directly taking the type as a standard structure , declare the FS  internal table as type of types structure.
    Data: fs_scarr like type_s_scarr.
    FIELD-SYMBOLS <scarr2> TYPE fs_scarr
    In the types put the third column as first one and use into corresponding in select query
    or else
    while displaying the internal table change the order of the columns
    Loop at itab into fs_itab.
    write : col3
    col2
    col4
    endloop.
    Thanks,
    Viquar Iqbal

  • Add field in an internal table

    Hi There,
    How to add a field in an internal table created at the runtime using
    CREATE DATA D1 TYPE TABLE OF (VAR).
    where say var contains name of a DDIC table.
    Rgds,
    deb.

    after creating internal table use the method for creation of dynamic table and try , i am not sure
    DATA: LineType TYPE string,
          ItabRef  TYPE REF TO DATA.
    FIELD-SYMBOLS:   TYPE STANDARD TABLE.
    LineType = 'SFLIGHT'.
    " Create internal table and attach a field-symbol
    CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType).
    ASSIGN ItabRef->* TO .
    <b>after this check this and try</b>
    ******DATA DECLARATION*****************************
    FIELD-SYMBOLS : <it_final> TYPE STANDARD TABLE,
                    <wa_final> TYPE ANY,
                    <w_field> TYPE ANY.
    ***DYNAMIC CREATION OF FIELDCATALOG****************
    *FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,
    *LIKEWISE DYNAMIC FIELDCATALOG IS CREATED
      wa_fieldcatalog-fieldname  = 'FIELD1'.
      wa_fieldcatalog-ref_table  = 'E070'.
      wa_fieldcatalog-outputlen  = '13'.
      wa_fieldcatalog-reptext    = 'Created On'.
      wa_fieldcatalog-seltext    = 'Created On'.
      APPEND wa_fieldcatalog TO it_fieldcatalog.
      CLEAR wa_fieldcatalog.
      wa_fieldcatalog-fieldname  = 'FIELD1'.
      wa_fieldcatalog-ref_table  = 'E070'.
      wa_fieldcatalog-outputlen  = '13'.
      wa_fieldcatalog-reptext    = 'Created On'.
      wa_fieldcatalog-seltext    = 'Created On'.
      APPEND wa_fieldcatalog TO it_fieldcatalog.
      CLEAR wa_fieldcatalog.
      LOOP AT it_mandt WHERE mandt IN s_mandt.
        CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.
        wa_fieldcatalog-inttype    = 'NUMC'.
        wa_fieldcatalog-outputlen  = '14'.
        wa_fieldcatalog-reptext    = it_mandt.
        wa_fieldcatalog-seltext    = it_mandt.
        APPEND wa_fieldcatalog TO it_fieldcatalog.
        CLEAR :wa_fieldcatalog ,it_mandt.
      ENDLOOP.
    ********CREATE DYNAMIC TABLE************************
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = it_fieldcatalog
        IMPORTING
          ep_table                  = new_table
        EXCEPTIONS
          generate_subpool_dir_full = 1
          OTHERS                    = 2.
      IF sy-subrc <> 0.
    *  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      ASSIGN new_table->* TO <it_final>.
    *********CREATE WORK AREA****************************
    CREATE DATA new_line LIKE LINE OF <it_final>.
      ASSIGN new_line->* TO <wa_final>.
    *********INSERTTING WORK AREAR TO INTERNAL TABLE******
        INSERT <wa_final> INTO TABLE <it_final>.
    *******POPULATING DATA******************************* 
      LOOP.
       ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_final> TO <w_field>.
       <w_field> = '12345'.
        ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_final> TO <w_field>.
       <w_field> = '21453DD'.
       FIELD1 AND FIELD2 ARE COMPONENTS OF FIELDCATALOG.
    ENDLOOP.     
      ENDLOOP.

  • Dynamic field access in internal tables

    Hi everyone.
    I woulkd like to know if there is any way to identify the fields of an internal table at runtime. I'm creating a method in a class, and i would like to accept any itab as a paramter and then access the fields of that itab. I currently have the itab passing no problem using field symbols, and i am able to loop at the data, but i am unsure how to get the field names.
    Any suggestions?
    Thanks!

    Hi,
    Check the code below:
    REPORT ZYKTEST3 .
    DATA: d_ref TYPE REF TO data,
    d_ref2 TYPE REF TO data,
    i_alv_cat TYPE TABLE OF lvc_s_fcat,
    ls_alv_cat LIKE LINE OF i_alv_cat.
    TYPES: tabname LIKE dcobjdef-name ,
    fieldname LIKE dcobjdef-name,
    desc LIKE dntab-fieldtext.
    PARAMETER: p_tablen TYPE tabname. -
    > Input table field
    DATA: BEGIN OF itab OCCURS 0.
    INCLUDE STRUCTURE dntab.
    DATA: END OF itab.
    FIELD-SYMBOLS : <f_fs> TYPE table,
    <f_fs1> TYPE table,
    <f_fs2> TYPE ANY,
    <f_fs3> TYPE ANY,
    <f_fs4> type any,
    <f_field> TYPE ANY.
    REFRESH itab.
    CALL FUNCTION 'NAMETAB_GET' -
    > Fetches the fields
    EXPORTING
    langu = sy-langu
    tabname = p_tablen
    TABLES
    nametab = itab
    EXCEPTIONS
    no_texts_found = 1.
    LOOP AT itab .
    ls_alv_cat-fieldname = itab-fieldname.
    ls_alv_cat-ref_table = p_tablen.
    ls_alv_cat-ref_field = itab-fieldname.
    ls_alv_cat-seltext = itab-fieldtext.
    ls_alv_cat-reptext = itab-fieldtext.
    APPEND ls_alv_cat TO i_alv_cat.
    ENDLOOP.
    internal table build
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = i_alv_cat
    IMPORTING
    ep_table = d_ref.
    ASSIGN d_ref->* TO <f_fs>. -
    > Dynamic table creation with fields of the table
    DATA: l_field TYPE fieldname,
    l_field1 type fieldname.
    SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.
    Fetching of the data from the table
    LOOP AT <f_fs> ASSIGNING <f_fs2>.
    Here u can check the validations and process
    ASSIGN COMPONENT 2 OF STRUCTURE <f_fs2> TO <f_fs3>.
    ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.
    IF sy-subrc = 0.
    MOVE <f_fs3> TO l_field.
    MOVE <f_fs4> TO l_field1.
    WRITE:/1 l_field(20),
    22 l_field1(10).
    ENDIF.
    ENDLOOP.
    Regards
    Kannaiah

  • To Find the type of field in the internal table.

    I have internal table i_tab.
    TYPES : BEGIN OF t_makt,
              matnr    TYPE    matnr,
              maktx    TYPE    maktx,
              qty      type    mseg-menge,
              show     type    char01,
            END OF t_makt.
    DATA : i_tab      TYPE t_makt  OCCURS 0 WITH HEADER LINE.
    I want to know the type of the field of the i_tab at some stage in the program.
    is there any piece of code or FM available to find the TYPE of the field of the internal table.

    Check out the following code
    TYPES:
      BEGIN OF my_struct,
        comp_a type i,
        comp_b type f,
      END OF my_struct.
    DATA:
      my_data   TYPE my_struct,
      descr_ref TYPE ref to cl_abap_structdescr.
    FIELD-SYMBOLS:
      <comp_wa> TYPE abap_compdescr.
    START-OF-SELECTION.
      descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).
      WRITE: / 'Typename     :', descr_ref->absolute_name.
      WRITE: / 'Kind         :', descr_ref->type_kind.
      WRITE: / 'Length       :', descr_ref->length.
      WRITE: / 'Decimals     :', descr_ref->decimals.
      WRITE: / 'Struct Kind  :', descr_ref->struct_kind.
      WRITE: / 'Components'.
      WRITE: / 'Name              Kind   Length   Decimals'.
      LOOP AT descr_ref->components ASSIGNING <comp_wa>.
        WRITE: / <comp_wa>-name, <comp_wa>-type_kind,
                 <comp_wa>-length, <comp_wa>-decimals.
      ENDLOOP.

  • Splitting a string into respective fields of dynamic internal table

    Hi,
        I've a string concatenated with a separator. I've to split the string and assign it to the respective fields of an internal table, which is dynamic.
    Table name will be passed through selection screen. The data is coming from another system via RFC.
    Eg : String ITAB :
                                100;89001;EN;Material1;MATERIAL1
                                100;89002;EN;Material2;MATERIAL2
    The String ITAB may contain any master data. Let's say the above data is from MAKT table. So, I want to assign the above data to the respective fields of MAKT internal table(Dynamic).
    I heard, this requirement can be achieved using some standard CLASS.
    Please help me in doing this task.
    Regards,
    Sunny

    Hello,
    you can use dynamic programming for this issue, i.e.:
    DATA: gv_table_name   TYPE string,
          gr_type_desc    TYPE REF TO cl_abap_typedescr,
          gr_struct_desc  TYPE REF TO cl_abap_structdescr,
          gr_table_desc   TYPE REF TO cl_abap_tabledescr,
          gv_t            TYPE c,
          gv_comp         TYPE i,
          gr_table_ref    TYPE REF TO data,
          gr_struc_ref   TYPE REF TO data.
    DATA: gt_itab   TYPE TABLE OF string,
          gt_split  TYPE TABLE OF string,
          gv_str    TYPE string.
    FIELD-SYMBOLS: <table>    TYPE ANY TABLE,
                   <struct>   TYPE ANY,
                   <comp>     TYPE ANY.
    APPEND '100;89001;EN;Material1;MATERIAL1' TO gt_itab.
    APPEND '100;89002;EN;Material2;MATERIAL2' TO gt_itab.
    "go!
    gv_table_name = 'MAKT'.
    cl_abap_tabledescr=>describe_by_name(
          EXPORTING p_name = gv_table_name
          RECEIVING p_descr_ref = gr_type_desc
          EXCEPTIONS type_not_found = 4 ).
    gr_struct_desc ?= gr_type_desc.
    gr_table_desc = cl_abap_tabledescr=>create( gr_struct_desc ).
    CREATE DATA gr_table_ref TYPE HANDLE gr_table_desc.
    CREATE DATA gr_struc_ref TYPE HANDLE gr_struct_desc.
    ASSIGN gr_table_ref->* TO <table>.
    ASSIGN gr_struc_ref->* TO <struct>.
    DESCRIBE FIELD <struct> TYPE gv_t COMPONENTS gv_comp.
    LOOP AT gt_itab INTO gv_str.
      CLEAR: gt_split.
      SPLIT gv_str AT ';' INTO TABLE gt_split.
      DO gv_comp TIMES.
        READ TABLE gt_split INTO gv_str INDEX sy-index.
        ASSIGN COMPONENT sy-index OF STRUCTURE <struct> TO <comp>.
        <comp> = gv_str.
        CLEAR gv_str.
      ENDDO.
      INSERT <struct> INTO TABLE <table>.
    ENDLOOP.
    After this code you will have all data in <table> field symbol in proper type.
    Regards,
    Jacek

  • How to add new field into dynamic internal table

    Hello Expert.
    how to add new field into dynamic internal table.
    PARAMETERS: P_TABLE(30).    "table name
    DATA: I_TAB TYPE REF TO DATA.
    FIELD-SYMBOLS: <TAB> TYPE standard TABLE.
    *Create dynamic FS
    create DATA I_TAB TYPE TABLE OF (p_table).
      ASSIGN I_TAB->* TO <TAB>.
    SELECT * FROM (p_table) INTO TABLE <TAB>.
       here i want to add one more field into <TAB> at LAST position and my 
       Field name  =  field_stype     and
       Field type    =  'LVC_T_STYL'
    could you please helpme out .

    Hi,
    Please find the code below.You can add the field acc to your requirement.
    Creating Dynamic internal table
    TYPE-POOLS: slis.
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  u201C Dynamic internal table name
                   <fs_dyntable>,                     u201C Field symbol to create work area
                   <fs_fldval> type any.              u201C Field symbol to assign values 
    PARAMETERS: p_cols(5) TYPE c.                     u201C Input number of columns
    DATA:   t_newtable TYPE REF TO data,
            t_newline  TYPE REF TO data,
            t_fldcat   TYPE slis_t_fldcat_alv,
            t_fldcat   TYPE lvc_t_fcat,
            wa_it_fldcat TYPE lvc_s_fcat,
            wa_colno(2) TYPE n,
            wa_flname(5) TYPE c. 
    Create fields .
      DO p_cols TIMES.
        CLEAR wa_it_fldcat.
        move sy-index to wa_colno.
        concatenate 'COL'
                    wa_colno
               into wa_flname.
        wa_it_fldcat-fieldname = wa_flname.
        wa_it_fldcat-datatype = 'CHAR'.
        wa_it_fldcat-intlen = 10.
        APPEND wa_it_fldcat TO t_fldcat.
      ENDDO. 
    Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = t_fldcat
        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>.
    Populating Dynamic internal table 
      DATA: fieldname(20) TYPE c.
      DATA: fieldvalue(10) TYPE c.
      DATA: index(3) TYPE c. 
      DO p_cols TIMES. 
        index = sy-index.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
    Set up fieldvalue
        CONCATENATE 'VALUE' index INTO
                    fieldvalue.
        CONDENSE    fieldvalue NO-GAPS. 
        ASSIGN COMPONENT  wa_flname
            OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
        <fs_fldval> =  fieldvalue. 
      ENDDO. 
    Append to the dynamic internal table
      APPEND <fs_dyntable> TO <t_dyntable>.
    Displaying dynamic internal table using Grid. 
    DATA: wa_cat LIKE LINE OF fs_fldcat. 
      DO p_cols TIMES.
        CLEAR wa_cat.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
        wa_cat-fieldname = wa_flname.
        wa_cat-seltext_s = wa_flname.
        wa_cat-outputlen = '10'.
        APPEND wa_cat TO fs_fldcat.
      ENDDO. 
    Call ABAP List Viewer (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = fs_fldcat
        TABLES
          t_outtab    = <t_dyntable>.

  • Extract a value of a fields from an internal table

    hello everyone,
    i need to extract a value of a fields from an internal table, the fields is in a postion "sy-tabix" that i know, so i need to pick this value without using a loop
    thank you.

    Like this?
    DATA: FIELD1 TYPE C,
               FIELD2 TYPE C.
    READ TABLE T_TAB INDEX 3.
    FIELD1 = T_TAB-FIELD1.
    FIELD2 = T_TAB-FIELD2.
    Greetings,
    Blag.

  • Field catalog for internal table in ALV

    In my program the internal table consists many fields from various tables and structure doesn't belong to a single data table.
    In order to get output in ALV grid following FM has been used
    REUSE_ALV_GRID_DISPLAY
    for field catalog the fields are defined specifically.
      l_fieldcat-fieldname  = 'VBELN'.
      l_fieldcat-outputlen  = 10.
      l_fieldcat-seltext_l  = 'Billing doc'.
      l_fieldcat-no_zero = 'X'.
      l_fieldcat-hotspot = 'X'.
      append l_fieldcat to p_fieldtab.
    ..............and so on for all the fields.
    Just wanted to know is there any other method to display all the fields of this internal table automatically so each field is not specified specifically.
    anya

    Hi
    Try this instead:
    *& Form  create_fieldcatalog
    * Create a field catalogue from any internal table
    *      -->PT_TABLE     Internal table
    *      -->PT_FIELDCAT  Field Catalogue
    FORM  create_fieldcatalog
           USING     pt_table     TYPE ANY TABLE
           CHANGING  pt_fieldcat  TYPE lvc_t_fcat.
      DATA:
        lr_tabdescr TYPE REF TO cl_abap_structdescr
      , lr_data     TYPE REF TO data
      , lt_dfies    TYPE ddfields
      , ls_dfies    TYPE dfies
      , ls_fieldcat TYPE lvc_s_fcat
      CLEAR pt_fieldcat.
      CREATE DATA lr_data LIKE LINE OF pt_table.
      lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).
      lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).
      LOOP AT lt_dfies
      INTO    ls_dfies.
        CLEAR ls_fieldcat.
        MOVE-CORRESPONDING ls_dfies TO ls_fieldcat.
        APPEND ls_fieldcat TO pt_fieldcat.
      ENDLOOP.
    ENDFORM.                    "create_fieldcatalog

  • Fields in an internal table

    How to find number of fields in an internal table ?
    my requirement is i have 20 internal tables and the data is being uploaded into an application server. so how to find no of fields in a particular internal table

    concatenate all the fields and move them to final internal table , call the function module "GET_COMPONENT_LIST" and pass the work area of the final internal table in the parameter fieldname
    ***For getting no of FIELDS in an internal table ********
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        PROGRAM          = syrepid
        FIELDNAME        = 't_payr'
      TABLES
        COMPONENTS       = fieldlist.
    describe table fieldlist lines pyr_no_fields.
    ********end of getting no of fields**********
    TRANSFER wa_mat_out_head TO P_FNAME.
    LOOP AT GT_PAYR.
    MOVE:  GT_payr-LIFNR TO T_payr-lifnr,
           GT_payr-ZBUKR TO T_payr-zbukr,
           GT_payr-LAUFD TO T_payr-LAUFD,
           GT_payr-CHECT TO T_payr-CHECT,
           GT_payr-RWBTR TO T_payr-RWBTR.
    Concatenate T_payr-lifnr  t_payr-zbukr T_payr-laufd T_payr-chect
                T_payr-rwbtr into wa_mat_out-rec SEPARATED by ',' .

Maybe you are looking for

  • How to I get the bookmarks on Aurora to be the same for differnt users in the same computer?

    when different users on my macbook login, i wan tehm all to see the same setup and saved bookmarks for Aurora. How can I do this. Trying to export from the one setupproperly sounded like the right thing to do. But when importing, there was too much s

  • Calling a function/procedure from a column link in a report

    Here's what I'm trying to do. I have a hidden page item variable that stores my security settings as a string like so: SETTING_1:SETTING_2:SETTING_3:SETTING_4I have a report that prints out security settings for our site. What I want to do is make th

  • Adapter engine in CC

    we chooose adapter engine as ntegration server in PI 7.0 and we go with adapter engine as central adapter engine in PI 7.1.. is this b cos 7.1 has advanced adapter engine? can u pls clarify?

  • Space after Page Break

    Hi All, i have created a smartform and i use page break for  my requirement now my question is in second page it leave some space and after that dispaying the line item how to remove that space or how display the line item in first with out any space

  • BootCamp not recognizing my windows install CD

    Hello, I'm trying to install BootCamp 1.2 on a fresh MacBook Pro. I'm installed the BC Assistant, run it, partitioned the drive (30GB partition), inserted my Windows XP SP2 install cd, and hit the Start Installation button. BC then reports that I sho