Looping the field symbol

Hi friends,
  I have to populate(Display) the data using field symol.
I am providing my code:
data: o_ref type ref to data.
field-symbols: <Lt_table> type standard table.
parameters: p_tab type tabname.
start-of-selection.
create data o_ref type table of (p_tab).
assign o_ref->* to <lt_table>.
select * into table <lt_table> from (p_tab).
I am unable to papulate the data.please help me out.
thanks,
satya

REPORT z_dynamic.
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.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
  PERFORM get_structure.
  PERFORM create_dynamic_itab.
  PERFORM get_data.
  PERFORM write_out.
*       FORM get_structure                                            *
FORM get_structure.
  DATA : idetails TYPE abap_compdescr_tab,
         xdetails TYPE abap_compdescr.
  DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
* Get the structure of the table.
  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 create_dynamic_itab                                      *
FORM create_dynamic_itab.
* Create dynamic internal table and assign to FS
  CALL METHOD cl_alv_table_create=>create_dynamic_table
               EXPORTING
                  it_fieldcatalog = ifc
               IMPORTING
                  ep_table        = dy_table.
  ASSIGN dy_table->* TO <dyn_table>.
* Create dynamic work area and assign to FS
  CREATE DATA dy_line LIKE LINE OF <dyn_table>.
  ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM.
*       FORM get_data                                                 *
FORM get_data.
* Select Data from table.
  SELECT * INTO TABLE <dyn_table>
             FROM (p_table).
ENDFORM.
*       FORM write_out                                                *
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.
  ENDLOOP.
ENDFORM.

Similar Messages

  • 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

  • How to modify the field symbol

    Hello Every1,
    I have a internal table and field symbol with the below structure.
    Data : begin of itab occurs 0,
               matnr like mara-matnr,
               ersda like mara-ersda,
           End   of itab.
    FIELD-SYMBOLS: <Matnr>    TYPE STANDARD TABLE.
    I have the field symbol with 10 records similar to the structure of itab. (Only matnr is populated and date as initial). Now I need to transfer the date value from itab to the field symbol for the matching matnr.
    Please let me know how to do it.
    Thanks,
    Siva.

    Sivaprakash,
    To my knowledge, a field-symbol cannot hold values on its own. It refers to a field or a table and work directly with the values.
    Your scenario cannot be achieved unless there is another internal table besides itab.
    Create a field-symbol of type itab2 and compare matnr with itab-matnr.
    If a record is found then move the date field to <fs>.
    Your code may look like this.
    loop at itab2 assigning <fs>.
       read table itab into wa_itab with key matnr = <fs>-matnr.
    if sy-subrc = 0.
      <fs>-date = wa_itab-date.
    endif.
    endloop
    Thanks,

  • How to check data type of the field symbol at run time

    Hi,
    My code is as following:
          LOOP AT <fs> ASSIGNING <wa_covp_ext>.
            ASSIGN COMPONENT 86 OF STRUCTURE <wa_covp_ext> TO <f_zzname>.
            IF sy-subrc = 0.
              ASSIGN COMPONENT 158 OF STRUCTURE <wa_covp_ext> TO <f_pernr>.
              IF sy-subrc = 0.
                  SELECT SINGLE sname INTO <f_zzname> FROM pa0001
                                WHERE pernr = <f_pernr>
                                AND endda GE sy-datum
                                AND begda LE sy-datum.
             ENDIF.
          ENDIF.
        ENDLOOP.
    This query is giving dump when <f_zzname> is type P length 8 and decimals 2, because it tries to put PA0001-sname into it which is type C length 30. So I want to check the type of <f_zzname> before the select statement. If it is character 30, then I will write the select statement else not.
    How to check data type of the field symbol at run time? If it's not possible, then can somebody suggest a workaround? Thanks.

    check this ...
    write describe statement  ...
    field-symbols : <f_zzname> .
    data : sname like pa0001-sname,
           typ(10).
    assign sname to  <f_zzname>.
    describe  field <f_zzname> type typ.
    write : typ. <-- typ contains character type in this case ..
    U can check if typ is of character(C) if so .. write the select statement ...

  • Looping a Field symbol.

    Hi,
    Can someone explain what to me what the following statement means?
    Data: i_tab  TYPE STANDARD TABLE.
    I looked it up and and it says that it is an ABAP built in type which is generic, but i fail to understand its usage.
    And here is my scenario.
    Field-symbols: <IT_DETAILS >  TYPE STANDARD TABLE,
                          <lines>                TYPE  (Transparent dictionary table)
    LOOP AT <lt_details> ASSIGNING <lines>.
    move <lines>-field to l_variable.
    Endloop
    Upon execution, I get a dump at the Loop statement saying that there is an 'ASSIGN_TYPE_CONFLICT'.You attempted to assign a field to a typed field symbol,but the field does not have the required type.
    How to correct the error
        Adapt the type of the field symbol to the type of the field or use an
        untyped field symbol or use the "CASTING" addition.
    Can someone explain the correct way to type the field symbol and implement the loop construct?
    Any help will be highly appreciated

    Hello,
    Can you tell us the type of the variable l_variable?
    Example:
    FIELD-SYMBOLS:    <pos_data> TYPE ANY,
                                   <gt_pos_data>  TYPE table.
      DATA : lt_csks LIKE gt_csks WITH HEADER LINE.
    LOOP AT <gt_pos_data> ASSIGNING <pos_data>.
        MOVE-CORRESPONDING <pos_data> TO lt_csks.
      ENDLOOP.

  • How to change the Field Symbol, so Adobe Forms takes it as a Table?

    Hi guys,
    I created an Field Symbol, in a Interface which I use for Adobe Forms. The type of the Field Symbol is STANDARD TABLE, and this field symbol I fill with data from another program.
    But the problem is that in adobe forms, this Field Symbol is taken as TEXT FIELD and not as Table... and this shows me a Dump because it can't convert Internal Table to type C (the dump is like that).
    What I need, is how to change the Field Symbol, so Adobe Forms takes it as a Table?
    I looked at Adobe Form, and found this:
    The Type Category of the Field Symbol is DICTIONARY TYPE and I think I need to change it to Internal Table as shown in the right picture.
    Does someone have any idea?

    Hello Taly,
    To what i understand your requirement, you need to pass data from Field symbol to internal table in Adobe form.
    You have done it correct partially. I have replicated your scenario and steps are below -
    1) Create a Z structure
    2) Create Z Table Type
    3) Create Adobe Interface with Table & Field Symbol. Also do coding as shown to assign the internal table populated in driver program to filed symbol.
    4) Design Form as -
    5) Code driver as -
    *& Report  ZR_AF_FS_1
    REPORT  zr_af_fs_1.
    DATA: fm_name           TYPE rs38l_fnam,
           fp_docparams      TYPE sfpdocparams,
           fp_outputparams   TYPE sfpoutputparams,
           it_kna1           TYPE ztt_fs_1.
    * Sets the output parameters and opens the spool job
    CALL FUNCTION 'FP_JOB_OPEN'                   "& Form Processing: Call Form
       CHANGING
         ie_outputparams = fp_outputparams
       EXCEPTIONS
         cancel          = 1
         usage_error     = 2
         system_error    = 3
         internal_error  = 4
         OTHERS          = 5.
    IF sy-subrc <> 0.
    *            <error handling>
    ENDIF.
    *&---- Get the name of the generated function module
    CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'           "& Form Processing Generation
       EXPORTING
         i_name     = 'ZAF_FS_1'
       IMPORTING
         e_funcname = fm_name.
    IF sy-subrc <> 0.
    *  <error handling>
    ENDIF.
    *-- Fetch the Data and store it in the Internal Table
    SELECT kunnr name1 name2 adrnr FROM kna1 INTO TABLE it_kna1 UP TO 15 ROWS.
    * Language and country setting (here US as an example)
    fp_docparams-langu   = 'E'.
    fp_docparams-country = 'US'.
    *&--- Call the generated function module
    CALL FUNCTION fm_name
       EXPORTING
         /1bcdwb/docparams        = fp_docparams
          it_data                   = it_kna1
    *    IMPORTING
    *     /1BCDWB/FORMOUTPUT       =
       EXCEPTIONS
         usage_error           = 1
         system_error          = 2
         internal_error           = 3.
    IF sy-subrc <> 0.
    *  <error handling>
    ENDIF.
    *&---- Close the spool job
    CALL FUNCTION 'FP_JOB_CLOSE'
    *    IMPORTING
    *     E_RESULT             =
       EXCEPTIONS
         usage_error           = 1
         system_error          = 2
         internal_error        = 3
         OTHERS               = 4.
    IF sy-subrc <> 0.
    *            <error handling>
    ENDIF.
    6) Output -
    BR.

  • Displaying the field symbol result in ALV GRID

    hi.
        I have a requirement to display the field symbol in ALV GRID. I am getting a error 'FIELD SYMBOL NOT YET BEEN ASSIGNED'  when i am calling the 'REUSE ALV GRID DISPLAY'. Can any one help me out..

    I have a requirement that i have to display all the GL indicators as a field.
    For that i have created a dynamic internal table so that based upon the GL indicators available in the database table i can create a dynamic internal table with GL indicators as the fieldnames.
    Now i want to populate the corresponding amount with respect to the GL indicators in the dynamic internal table.
    For ex.
    I have a database table as follows:
    Vendor Id GL indicators Amount
    1000 A 2000
    1000 S 3000
    I have to created a field symbol as follows
    Vendor Id A S
    1000 2000 3000.
    Now my requirement is that i want this values to be displayed in ALV GRID.
    At the point of calling REUSE ALV GRID DISPLAY  i am getting the error field symbol is not yet been assigned..

  • Problem with the field-symbols

    Hi all,
            i am unable to delete the  data in the internal table.
            i am sending the code.
          BEGIN OF t_oprtn,
           budat LIKE afru-budat,
           vornr LIKE afru-vornr,
           grund LIKE afru-grund,
           gmein LIKE afru-gmein,
           gmnga LIKE afru-gmnga,
           expfl(1),
           END OF t_oprtn,
    FIELD-SYMBOLS: <fs_collect>         TYPE STANDARD TABLE.
    FIELD-SYMBOLS: <fs_wa_collect>      TYPE ANY.
        CREATE DATA i_collect TYPE STANDARD TABLE OF t_oprtn
                              WITH DEFAULT KEY.
        CREATE DATA wa_collect TYPE t_oprtn.
      ASSIGN i_collect->*       TO <fs_collect>.
      ASSIGN wa_collect->*      TO <fs_wa_collect>.
      SELECT abudat avornr agrund  aarbid astokz darbpl a~aufnr
             bplnbez cmaktx agmnga agmein
             INTO TABLE i_final
             FROM afru AS a INNER JOIN afko AS b
                                       ON aaufnr = baufnr
                            INNER JOIN makt AS c
                                       ON bplnbez = cmatnr
                            INNER JOIN crhd AS d
                                       ON aarbid = dobjid
             WHERE a~budat IN s_budat
    LOOP AT i_final INTO wa_final.
      MOVE-CORRESPONDING wa_final TO <fs_wa_collect>.
        COLLECT <fs_wa_collect> INTO <fs_collect>.
      ENDLOOP
    how to write a delete statement for -  <fs_collect>.
    Plz tell me the delete statement where GMNGA is '0'.   " GMNGA IS A CONFIRM QUANTITY.
    Plz reply its urgent.
    Edited by: hari prasad on May 30, 2008 1:15 PM
    Edited by: hari prasad on May 30, 2008 1:20 PM

    Try:
    field-symbols: <f_temp> type any.
    loop at <fs_collect> assigning <fs_wa_collect>.
       assign component 'GMNGA' of structure <fs_wa_collect> to <f_temp>.
    if <f_temp> is initial.
       delete <fs_collect>.
    endif.
    endloop.
    regards,
    S. Chandramouli.
    Edited by: Chandramouli Subburathinam on May 30, 2008 5:08 PM

  • How can I determine the number of field in the FIELD-SYMBOLS

    Hi, in the following code example I have structure u201Czfsl_sd_credit_balu2019 I define a workarea like that structure and assign that wa to FIELD-SYBOLS. Now can I calculate the number of filed in that FIELD-SYBOLS for further processing on that FIELD-SYBOLS.
    DATA: wa_credit_bal LIKE zfsl_sd_credit_bal.
    "wa_credit_bal-audat = '20081210'.
    wa_credit_bal-vehno = '0as10'.
    wa_credit_bal-VBELN = 'aaad'.
    wa_credit_bal-MOVMT = 'asdfa'.
    wa_credit_bal-quantity = 10.
    wa_credit_bal-recc = 10.
    wa_credit_bal-recb = 10.
    wa_credit_bal-issc = 10.
    wa_credit_bal-issb = 10.
    wa_credit_bal-balc = 10.
    wa_credit_bal-balb = 10.
    wa_credit_bal-cbalc = 10.
    wa_credit_bal-cbalb = 10.
    wa_credit_bal-last_line = 2.
    FIELD-SYMBOLS: <f1>, <f2>, <f3>.
    ASSIGN wa_credit_bal TO <f1>.
    In the bellow u2018FORMu2019
    FORM getsum USING in CHANGING out etext.
      FIELD-SYMBOLS: <f1>, <f2>.
      ASSIGN in TO <f1>.
      out = 0.
      DATA: cin(50),
            iin TYPE i.
      DO 14 TIMES.
        CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
          ASSIGN COMPONENT sy-index OF STRUCTURE <f1> TO <f2>.
          iin = <f2>.
        ENDCATCH.
        IF sy-subrc = 1.
        ELSE.
          ADD: <f2> TO out.
        ENDIF.
      ENDDO.
    I did u201CDO 14 TIMESu201D because I know that there are 14 field in that structure but it will be problem when user will give a different structure like more then 14 fields in it. So I want to get the no of fields and store it to a variable and replace u201814u2019 with that variable
    Kind regards,
    Faisal

    Thanks, Tahir
    my problem has solved
    Kind Regards,
    Faisal

  • Can limit loop on FIELD-SYMBOLS list ?

    i have loop ....
      LOOP AT <GT_TABLE> ASSIGNING <DYN_TABLE1> .
    i want to do
    LOOP AT <GT_TABLE> ASSIGNING <DYN_TABLE1> where
    but i get message that the 'LOOP .. WHERE'
    Have to be statically define

    hi Dakota,
    the WHERE won't work here. The reason is the actual structure of <DY_TABLE1> only determined at runtime.
    The workaround is that when you are in the LOOP already, you have to ASSIGN fields of the dynamic structure (ASSIGN COMPONENT ...) than you can decide if you need that record or not, if not than CONTINUE...
    hope this helps
    ec

  • How to get the current type of a generic Field Symbol

    Hi Experts,
    I have a Field Symbol:
    FIELD-SYMBOLS: <lf_any> TYPE ANY.
    I loop around an internal table with a generic structure and assign their fields to my fieldsymbol:
    LOOP AT it_data ASSIGNING <lf_any>.
    After executing this statement I am able to see the current Absolute Type of the field Symbol in debugger.
    For example this could be TYPE ZX_1 in first loop, TYPE ZX_2 in second loop and so on...
    Question: How can I get this current type within my Loop?
    The Reason is I have to CREATE DATA xxx TYPE "current type of the field symbol".
    Thanks,
    Daniel

    Hello Daniel
    Do you have the RTTI classes available on your system? If so then try the following:
    *& Report  ZUS_SDN_RTTI_GET_TYPE
    REPORT  zus_sdn_rtti_get_type.
    DATA: gt_knb1   TYPE STANDARD TABLE OF knb1,
          gd_type   TYPE string.
    DATA: go_typedescr    TYPE REF TO cl_abap_typedescr,
          go_strucdescr   TYPE REF TO cl_abap_structdescr.
    FIELD-SYMBOLS: <gs_struc> TYPE ANY.
    START-OF-SELECTION.
      APPEND INITIAL LINE TO gt_knb1.
      LOOP AT gt_knb1 ASSIGNING <gs_struc>.
        go_typedescr = cl_abap_typedescr=>describe_by_data( <gs_struc> ).
        go_strucdescr ?= go_typedescr.
        gd_type = go_typedescr->get_relative_name( ).
        WRITE: / 'Type=', gd_type.
        gd_type = go_strucdescr->get_relative_name( ).
        WRITE: / 'Type=', gd_type.
      ENDLOOP.
    END-OF-SELECTION.
    Regards
      Uwe

  • Field symbols in loop

    Hi,
    I need to change this code using Field symbols. Can anybody help me?
      DATA: i_history  TYPE STANDARD TABLE OF mmreq_history INITIAL SIZE 0,
            wa_history TYPE mmreq_history,
            l_menge    LIKE eban-menge.
        LOOP AT i_history INTO wa_history.
          IF wa_history-bstyp EQ dc_plan.
            ADD wa_history-menge TO l_menge.
          ELSEIF wa_history-bstyp EQ dc_abierto.
            CLEAR: wa_history-menge, wa_history-meins.
            SELECT SINGLE ktmng meins
              FROM ekpo
              INTO (wa_history-menge, wa_history-meins)
              WHERE ebeln EQ wa_history-ebeln
                AND ebelp EQ wa_history-ebelp.
            MODIFY i_history FROM wa_history.
            ADD wa_history-menge TO l_menge.
          ENDIF.
        ENDLOOP.
    Thanks!!!
    Carles

    Hi
    Hope it will help you,
    Reward if help.
    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

  • Read Data from the dynamic Field Symbol with key ?

    Dear All,
    I've  2 dynamic internal tables in the form of field symbols.
    Now,I want to loop the item field symbol, read the header field symbol content and then move the corresponding into a final field symbol.
    How to read the field symbol with key ?
    When I'm trying to give the key clause in the paranthesis it's giving a syntax error.
    Any clues ?
    FYI .....
    * Get the Dynamic Field and Value for the Date/Year and convert it into Year value
      LOOP AT <fs_t_son> ASSIGNING <wa_son>.
        ASSIGN COMPONENT gwa_znrows_def-fieldname OF STRUCTURE <wa_son> TO <fs_year>.
        IF sy-subrc = 0.
          CLEAR gv_string.
          MOVE <fs_year> TO gv_string.
          CLEAR gv_year.
          gv_year = gv_string.
          <fs_year> = gv_year.
        ELSE.
    * When the Date/year Field is not in the Table then -->
    * Get the Dynamic Field and Value
          ASSIGN COMPONENT gwa_znrows_def-kfldname OF STRUCTURE <wa_rson> TO <fs_value>.
    * Populate field for Dynamic Where condition
          CLEAR gv_value.
          CONCATENATE '''' <fs_value> '''' INTO gv_value.
          CONCATENATE gwa_znrows_def-kfldname '=' gv_value INTO gt_where SEPARATED BY space.
          APPEND gt_where.
          CLEAR gt_where.
          READ TABLE <fs_t_rson> ASSIGNING <wa_rson> ( gt_where ).  "Key clause
        ENDIF.  " if sy-subrc = 0.  "Assign
      ENDLOOP.
    Thanks & regards,
    Deepu.K

    TYPES: BEGIN OF line,
             col1 TYPE c,
             col2 TYPE c,
           END OF line.
    DATA: wa TYPE line,
          itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1,
          key(4) TYPE c VALUE 'COL1'.
    FIELD-SYMBOLS <fs> TYPE ANY TABLE.
    ASSIGN itab TO <fs>.
    READ TABLE <fs> WITH TABLE KEY (key) = 'X' INTO wa.
    The internal table itab is assigned to the generic field symbol <fs>, after which it is possible to address the table key of the field symbol dynamically. However, the static address
    READ TABLE <fs> WITH TABLE KEY col1 = 'X' INTO wa.
    is not possible syntactically, since the field symbol does not adopt the key of table itab until runtime. In the program, the type specification ANY TABLE only indicates that <fs> is a table. If the type had been ANY (or no type had been specified at all), even the specific internal table statement READ TABLE <fs>  would not have been possible from a syntax point of view.

  • The difference between FIELD-SYMBOL and normal DATA TYPE

    Dear experts,
    Please see the example below, both are output the same result.
    DATA: EXTERNAL_RECORD(4000),
          POSITION TYPE I,
          LENGTH TYPE N,
          ENTRY TYPE STRING.
    EXTERNAL_RECORD = '0005Smith0007Edwards0005Young'.
    DO.
      LENGTH = EXTERNAL_RECORD+POSITION(4).
      IF LENGTH = 0.
        EXIT.
      ENDIF.
      ADD 4 TO POSITION.
      MOVE EXTERNAL_RECORD+POSITION(LENGTH) TO ENTRY.
      WRITE ENTRY.
      ADD LENGTH TO POSITION.
      IF POSITION >= 4000.
        EXIT.
      ENDIF.
    ENDDO.
    --OR It can be written as--
    DATA: EXTERNAL_RECORD(4000),
          POSITION TYPE I,
          LENGTH TYPE N.
    FIELD-SYMBOLS <ENTRY>.
    EXTERNAL_RECORD = '0005Smith0007Edwards0005Young'.
    DO.
      LENGTH = EXTERNAL_RECORD+POSITION(4).
      IF LENGTH = 0.
        EXIT.
      ENDIF.
      ADD 4 TO POSITION.
      ASSIGN EXTERNAL_RECORD+POSITION(LENGTH) TO <ENTRY>.
      WRITE <ENTRY>.
      ADD LENGTH TO POSITION.
      IF POSITION >= 4000.
        EXIT.
      ENDIF.
    ENDDO.
    Is there any special circumstances we need to use FIELD-SYMBOL?
    Why is FIELD-SYMBOL is introduce in the first place?
    Kindly advice with example.
    Thanks in advance for those who can help me on this.

    HI,
    You can use field symbols to make the program more dynamic. In this example the name of a table control is substituted by a field symbol. Thus you cal call the form with any internal table, using the name of the table control as a parameter.
    Example
    form insert_row
    using p_tc_name.
    field-symbols <tc> type cxtab_control. "Table control
    assign (p_tc_name) to <tc>.
    insert 100 lines in table control
    <tc>-lines = 100.
    Field symbols allow you to:
    **     Assign an alias to a data object(for example, a shortened
            name for data objects structured through several hierarchies
            - <fs>-f instead of rec1-rec2-rec3-f)
    **     Set the offset and length for a string variably at runtime
    **     Set a pointer to a data object that you determine at runtime (dynamic ASSIGN)
    **     Adopt or change the type of a field dynamically at runtime
    **     Access components of a structure
    **     (from Release 4.5A) Point to lines of an internal table
            (process internal tables without a separate work area)
    Field symbols in ABAP are similar to pointers in other programming
    languages. However, pointers (as used in PASCAL or C) differ from ABAP
    field symbols in their reference syntax.
    The statement ASSIGN f to <fs> assigns the field f to field
    symbol <fs>. The field symbol <fs> then "points" to the
    contents of field f at runtime. This means that all changes to the
    contents of f are visible in <fs> and vice versa. You declare
    the field symbol <fs> using the statement FIELD-SYMBOLS: <fs>.
    Reference syntax
    Programming languages such as PASCAL and C use a dereferencing symbol
    to indicate the difference between a reference and the object to which
    it refers; so PASCAL would use p^ for a pointer instead of p, C would
    use *p instead of p. ABAP does not have any such dereferencing symbol.
    **     In PASCAL or C, if you assign a pointer p1 to a pointer p2,
    you force p1 to point to the object to which p2 refers (reference semantics).
    **     In ABAP, if you assign a field symbol <fs1> to a field
    symbol <fs2>, <fs1> takes the value of the data object to
    which <fs2> refers (value semantics).
    **     Field symbols in ABAP are always dereferenced, that is,
    they always access the referenced data object. If you want to
    change the reference yourself in ABAP, you can use the ASSIGN statement
    to assign field symbol <fs1> to field symbol <fs2>.
    Using field symbols
    You declare field symbols using the FIELD-SYMBOLS statement.
    They may be declared either with or without a specific type.
    At runtime you assign a field to the field symbol using the ASSIGN
    statement. All of the operations on the field symbol act on the field
    assigned to it.
    When you assign a field to an untyped field symbol, the field symbol
    adopts the type of the field. If, on the other hand, you want to assign
    a field to a typed field symbol, the type of the field and that of the
    field symbol must be compatible.
    A field symbol can point to any data object and from Release 4.5A,
    they can also point to lines of internal tables.
    The brackets (<>) are part of the syntax.
    Use the expression <fs> IS ASSIGNED to find out whether the field
    symbol <fs> is assigned to a field.
    The statement UNASSIGN <fs> sets the field symbol <fs> so
    that it points to nothing. The logical expression <fs>
    IS ASSIGNED is then false. The corresponding negative expression
    is IF NOT <fs> IS ASSIGNED.
    An unassigned field symbol <fs> behaves as a constant with
    type C(1) and initial value SPACE.
    MOVE <fs>
    TO dest     Transfers the initial value SPACE to the variable dest
    MOVE 'A' to <fs>     
    Not possible, since <fs> is a constant
    (runtime error).
    To lift a type restriction, use the CASTING addition in the
    ASSIGN statement. The data object is then interpreted as though
    it had the data type of the field symbol. You can also do this
    with untyped field symbols using the CASTING TYPE <type> addition.
    The danger with pointers is that they may point to invalid areas.
    This danger is not so acute in ABAP, because the language does not
    use address arithmetic (for example, in other languages, pointer p
    might point to address 1024. After the statement p = p + 10, it would
    point to the address 1034). However, the danger does still exist, and
    memory protection violations lead to runtime errors.
    A pointer in ABAP may not point beyond a segment boundary. ABAP does
    not have one large address space, but rather a set of segments.
    Each of the following has its own segment:
    *     All global data
    *     All local data
    *     Each table work area (TABLES)
    *     Each COMMON PART
    You should only let field symbols move within an elementary field or
    structure where ABAP allows you to assign both within the global data
    and beyond a field boundary.
    Rgds
    Umakanth

  • 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

Maybe you are looking for