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

Similar Messages

  • How to handle field symbols internal table values?

    HI all,
              I declared field string as below.The below code is working fine.
    Data : ITAB TYPE STANDARD TABLE OF YAPOPLN, (Custom table).
              wa_itab like line of ITAB.
    field-symbol : <fs> type ITAB.
    ASSIGN PARAM TO <FS>
    LOOP AT <FS> INTO WA_ITAB.
    WRITE:/ 'ABC'.
    ENDLOOP.
    But my requirement is that I dont want all the fields of the table YAPOPLN.My output contains only 2 fields of the table YAPOPLN,which contains total 4 fields.According to my requirement only 2 fields will be getting into one parameter PARAM(this is function module parameter,which is from ALV classes) from the user entered output,which contains only 2 fields.So the above code is not working properly because wa_itab contains 4 fields and giving short dump.
    If I am declaring the internal table with the required fields(only 2 fields) and referring that internal table to field symbol <FS>
    Data : BEGIN OF ITAB1 OCCURS 0,
             FIELD1 LIKE YAPOPLN-FIELD1,
             FIELD2 LIKE YAPOPLN-FIELD2,
             END OF ITAB1.
    field-symbol : <fs> LIKE ITAB1 OR  <FS> TYPE ANY.
    DATA :WA_ITAB1 LIKE LINE OF ITAB1.
    ASSIGN PARAM TO <FS>
    LOOP AT <FS> INTO WA_ITAB.
    WRITE:/ 'ABC'.
    ENDLOOP.
    But when I am compiling this code i am getting the below error.I am gettting the same below error when even <FS> is also declared as <FS> TYPE ANY.
    .'FS' is not an internal table or defined in TABLES.
    Can anyone help me in this regard?
    Thanks,
    Balaji

    Hello,
    Try this way:
    If both the type of internal tables are same then you can directly assign dynamic internal table to static internal table.
    itab = <itab>.
    Suppose you have field symbol internal table <itab> which is different in structure from ITAB.
    Now, you can create <wa> as follow:
    FIELD-SYMBOLS <wa>.
    DATA wa TYPE REF TO DATA.
    CREATE DATA wa TYPE LINE OF <itab>.
    ASSIGN wa->* to <wa>.
    This way your work area is read.
    Using [ASSIGN COMPONENT|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/content.htm] syntax you can read required component of <wa>.
    Finally you can use that value to load static internal table.
    You can also refer to my thread on [Dynamic table|Re: Creating Dynamic table].
    Hope this helps!
    Thanks,
    Augustin.
    Edited by: Augustarian on Aug 20, 2009 10:06 AM

  • How to move field symbol internal table to internal table with header line?

    Dear all,
    hi...hereby i would like to ask how i can move field symbol internal table to a internal table?
    as i know field symbol internal table is without header line..
    so, may i know how to do this....to move field symbol internal table to internal table which consist of header line and field and record will same as field symbol internal table...in additional, my field symbol internal table is dynamic table mean everytime will have flexible columns..?
    Please advise...
    Thanks
    Regard,
    ToToRo.
    Edited by: @ToToRo@ on Aug 20, 2009 6:16 AM

    Hello,
    Try this way:
    If both the type of internal tables are same then you can directly assign dynamic internal table to static internal table.
    itab = <itab>.
    Suppose you have field symbol internal table <itab> which is different in structure from ITAB.
    Now, you can create <wa> as follow:
    FIELD-SYMBOLS <wa>.
    DATA wa TYPE REF TO DATA.
    CREATE DATA wa TYPE LINE OF <itab>.
    ASSIGN wa->* to <wa>.
    This way your work area is read.
    Using [ASSIGN COMPONENT|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/content.htm] syntax you can read required component of <wa>.
    Finally you can use that value to load static internal table.
    You can also refer to my thread on [Dynamic table|Re: Creating Dynamic table].
    Hope this helps!
    Thanks,
    Augustin.
    Edited by: Augustarian on Aug 20, 2009 10:06 AM

  • Convert Table into string, No FM is working good for this

    Hi all,
    i want to convert a table into string, but while convert, i found out that the string has special lenght , and i am getting only some rows of the table  wihle converting, even if i am using concatinate, i got the same problem,
    please let me know if there is a way to convert all the table into string and not a littel bit of it.
    BR

    I remember that you were facing the problem with the below function module
    types:begin of ty_string,
          field1 type char1024,
          end of ty_string.
    data:it type table of ty_string.
    data:wa type ty_string.
    data:out type string,
    line type string,
    rest type string.
    do 100 times.
      do 1024 times.
        concatenate 'A' wa-field1 into wa-field1.
      enddo.
      append wa to it.
    enddo.
    call function 'CONVERT_TABLE_TO_STRING'
      exporting
        i_tabline_length = '1024'
      importing
        e_string         = out
      tables
        it_table         = it.
    For me the variable out holds 102400 characters.

  • How to read data from field symbol containing Table

    I defined a field symbols for reading output of a BRF plus rule however since fielk symbol is of type any
    I cannot read its contents
    Any inputs are highly appreciated
    Please see attachment explaining problem

    Thanks a lot for your help
    However It did not work for me as it started giving error incompatible types
    Here is my code
    constants:lv_function_id type if_fdt_types=>id value '3440B5B078B21EE3BC9EB53C42F84A45'.
    data:lv_timestamp type timestamp,
          lt_name_value type abap_parmbind_tab,
          ls_name_value type abap_parmbind,
          lr_data type ref to data,
          lv_counter type i value 0,
          lr_target type ref to data,
          lx_fdt type ref to cx_fdt,
          lo_trace type ref to if_fdt_trace,
          lo_lean_trace type ref to if_fdt_lean_trace,
          la_z_string type if_fdt_types=>element_text,
          lv_role_name  type grac_role_name,
          lv_result type string.
    field-symbols <la_any> type any.
    field-symbols <role_name> type grac_s_od_role_detail.
    field-symbols <system> type string.
       types:
        begin of ys_access ,
                  role_name type  string,
                  system_name   type string,
                end of ys_access .
      types:
        yt_access type table of ys_access .
    field-symbols: <access_item> type table,
                    <ls_req_access> type ys_access.
    data con_name type if_fdt_types=>element_text.
    data ls_any type ys_access.
    * All method calls within one processing cycle calling the same function must use the same timestamp.
    * For subsequent calls of the same function, we recommend to use the same timestamp for all calls.
    * This is to improve the system performance.
    * If you are using structures or tables without DDIC binding, you have to declare the respective types
    * by yourself. Insert the according data type at the respective source code line.
    * GET TIME STAMP FIELD lv_timestamp.
    * Process a function and record trace data, passing context data objects via a name/value table.
    * Prepare function processing:
    ls_name_value-name = 'Z_STRING'.
    la_z_string = 'P1'.
    get reference of la_z_string into lr_data.
    ls_name_value-value = lr_data.
    insert ls_name_value into table lt_name_value.
    * Create the data to store the result value after processing the function
    * You can skip the following call, if you already have
    * a variable for the result. Please replace also the parameter
    * EA_RESULT in the method call CL_FDT_FUNCTION_PROCESS=>PROCESS
    * with the desired variable.
      cl_fdt_function_process=>get_data_object_reference( exporting iv_function_id      = lv_function_id
                                                                    iv_data_object      = '_V_RESULT'
                                                                    iv_timestamp        = lv_timestamp
                                                                    iv_trace_generation = abap_true
                                                          importing er_data             = lr_data ).
      assign lr_data->* to <la_any>.
      try.
          cl_fdt_function_process=>process( exporting iv_function_id = lv_function_id
                                                      iv_timestamp   = lv_timestamp
                                                      iv_trace_mode  = if_fdt_constants=>gc_trace_mode_lean
                                                     "iv_trace_mode  = if_fdt_constants=>gc_trace_mode_lean_required
                                            importing ea_result      = <la_any>
                                                      eo_trace       = lo_trace
                                            changing  ct_name_value  = lt_name_value ).
          lo_lean_trace ?= lo_trace.
          lo_lean_trace->save( ).
          catch cx_fdt into lx_fdt.
    * You can check CX_FDT->MT_MESSAGE for error handling.
      endtry.
    * Get context values after processing:
      cl_fdt_function_process=>get_context_value( exporting  iv_function_id = lv_function_id
                                                             iv_trace_generation = abap_true
                                                             iv_timestamp   = lv_timestamp:
                                                             iv_data_object = '3440B5B078B21EE3BC9EFF599C110ADD' "Z_STRING
                                                   importing ev_data             = lv_result ). " Suggested variable: la_z_string
      create data lr_target type grac_s_od_role_detail.
    *  assign <la_any> to <role_name>.
      assign lr_target->* to <la_any>.
       loop at lt_name_value into ls_name_value.
        if ls_name_value-name cs 'RESULT'.
          assign ls_name_value-value  to <la_any>.
            ls_any = ls_name_value-value  .
        endif.
        endloop.
        access_item = <la_any>.
    * assign ( )<la_any> to <access_item>.
    * assign component 1 of structure <la_any> to <rolename>.
    *   assign <la_any> to <ls_req_access>.
    * lr_target = <la_any>.
    * assign lr_target->* to <role_name>.
    * lv_role_name = <role_name>.
      lv_result = lv_result.

  • 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 : internal table

    Dear experts,
    I am trying to put contents of internal table from a standard transaction in this way but i am not getting.
    Further i get last record successfully if i try to follow the code of this link
    http://www.sapdevelopment.co.uk/enhance/enhance_fsymbol.htm
    The code that i use is :
    types: begin of t_type,
    tabix type i,
    color type c,
    selfl type c,
    vbeln like lips-vbeln,
    posnr like lips-posnr,
    kschl like nast-kschl,
    nacha like nast-nacha,
    parvw like nast-parvw,
    pname like kna1-name1,
    pcity like lfa1-ort01,
    vstel type c,
    lfdat like mkpf-budat,
    wadat like mkpf-budat,
    end of t_type.
    data :   pgm(40) value '(SAPLKKBL)T_OUTTAB[]'.
             field-symbols: <fs> type standard table.
    data: i_get type t_type occurs 0 with header line.
    assign (pgm) to <fs>.
    append lines of <fs> to i_get[].
    But not getting,the datatype i have created is only by looking at fields in memory map.Its not exactly of T_OUTPUT[] as it can't be referred

    Hi aditya,
    Please try defining field symbol as of generic type ( TYPE ANY).
    or try this way.
    data :
    pgm(40)
    t_pgm like standard table of pgm.
    field-symbols: <fs> type ANY
    data: i_get type t_type occurs 0 with header line.
    t_pgm =  (SAPLKKBL)T_OUTTAB[].
    Loop at t_pgm into pgm.
    assign pgm to <fs>.
    append <fs> to i_get[].
    ENDLOOP.
    Hope this would help you.
    Good luck
    Narin

  • FIELD-SYMBOLS and table ?

    Hi all,
    in my programm i must check in differents tables some values. Tables are parameters of my program.
    So i thought that i could use field-symbols for access to the table but it's not work for me.
    Just a example, i've 2 tables to check : HRP1002 and HRP1003.
    I can't do that :
    FIELD-SYMBOLS <fs> STANDARD TABLE.
    ASSIGN 'HRP1002' TO <fs>.
    ASSIGN line is in error because no compatible type.
    How can i do this ?
    Regards

    Try this code...
    tables: rsrd1.
    DATA: LineType TYPE string,
          ItabRef  TYPE REF TO DATA,
          lineRef  TYPE REF TO DATA.
    FIELD-SYMBOLS: <fs>  TYPE STANDARD TABLE,
                   <fs1> type any.
    parameter tbl like RSRD1-TBMA_VAL.
    linetype = tbl.
    CREATE DATA ItabRef TYPE STANDARD TABLE OF (LineType).
    ASSIGN ItabRef->* to <fs> .
    create data lineref like line of <fs>.
    assign lineref->* to <fs1>.
    SELECT * FROM (tbl) INTO <fs1>.
    write <fs1>.
    endselect.
    SELECT * FROM (tbl) INTO table <fs>.

  • Reading the data from field symbol internal table //

    Hi,
    There are 2 internal tables defined as Fieldsymbols (type any) and I need to retrive data from second internal table based on a field value in first internal table.
    Let's assue the name internal table 1 is <it_itab1>, 2nd internal table name is <it_itab2> and the work areas are <wa_itab1> and <wa_itab2>.
    The existing logic :
    LOOP at <it_itab1> ASSIGNING <wa_itab1>.
      ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab1> TO l_field6.
      LOOP AT <it_itab2> ASSIGNING <wa_itab2>.
        ASSIGN COMPONENT 'XYZ' OF STRUCTURE <wa_itab2> TO <p_field7>.
        IF <p_field7> = l_field6.
    do the required business.
        ELSE.
          *     do the required business.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
    The requirement of reading second internal table was achieved by putting loop on the internal table but its giving considerable effect on performance !!
    Is there any way to use READ statement in my case OR any way of putting WHERE condition on loop statement of second internal table ??
    Thank you !!

    Use the below Logic.
    Loop at Itab1 into wa_itab1.
        Loop at itab2 into wa_itab2 where p_field7 = wa_itab1-xyz or I_field6.
    do the required business.
        endloop.
        Loop at itab2 into wa_itab2 where p_field7 <> wa_itab1-xyz or I_field6.
    do the required business.
        endloop.
    endloop.
    Hope it is useful...

  • 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.

  • 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.

  • Looping over fields from internal table

    In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
    I first want to check field-by-field and then I want to deal with exceptions.
    Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?

    Hi, you can loop thru the columns(fields) of an internal table like so.
    field-symbols: <fs>.
    loop at itab.
    do.
    * Here you can use the field name instead of SY-INDEX
       assign component sy-index of structure itab to <fs>.
       if sy-subrc <>.
       exit.
       endif.
    * Now that you have access to the field via field symbol, you can compare
    * this value.
    Write:/ <fs>.
    enddo. 
    endloop.
    Regards,
    Rich Heilman

  • How to pass field symbol or table from one view to another view in abap web dynpro?

    I am creating an Inbound Outbound ALV report in ABAP Web Dynpro. However at selection-screen I have select options and fetching is done at view2. Problem is we can pass parameter using inbound outbound parameters but how to pass internal table or field-symbols from one view to another view? I made use of Assistance Class too but its not very clear to me. Please give me some example or code to sort this problem out.

    I am creating an Inbound Outbound ALV report in ABAP Web Dynpro. However at selection-screen I have select options and fetching is done at view2. Problem is we can pass parameter using inbound outbound parameters but how to pass internal table or field-symbols from one view to another view? I made use of Assistance Class too but its not very clear to me. Please give me some example or code to sort this problem out.

  • How can i know the number of lines in field-symbol internal table

    how can i know the number of lines in field-symbol internal table

    Hi,
    If your field symbol has been defined as an internal table :
    Use std describe as
    Data: l type i.
    describe <fs> lines l.
    'l' will contain the number of lines as needed.
    FYI
    The size of this storage area in a field symbols depends on the number of table lines which is not fixed, but determined dynamically at runtime.
    Regards,
    Amit

  • Reg Field-Symbol value trasfer into variable

    Hi,
    I'm using one FIELD-SYMBOL in one of my program. I used this to catch Hotspot Fields in List Report. It catches that required field of BELNR.
    I read the Click event through that FIELD-SYMBOL. Now I used
    DATA: HOTSPOT(18) , "VALUE 'Document No',
          F(18), OFF TYPE I, LIN TYPE I, VAL(40), LEN TYPE I.
    FIELD-SYMBOLS <FS>.
    ASSIGN HOTSPOT TO <FS>.
    WRITE <FS> HOTSPOT COLOR 3 INVERSE ON.
    AT LINE-SELECTION.
    *WINDOW STARTING AT 5 6 ENDING AT 45 20.
    GET CURSOR FIELD F OFFSET OFF
    LINE LIN
    VALUE VAL
    LENGTH LEN.
    data: click_item type bsid-belnr.
    move val to click_item.
    It moves the value into CLICK_ITEM variable. But when I try to run SELECT query with condition BELNR = CLICK_ITEM, query gives no result.
    Can you please point out my fault?
    Thanks.
    Kumar saurav.

    Try using Conversion Routine before the Select Query.
    DATA : T_BELNR TYPE BSID_BELNR.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = CLICK_ITEM
    IMPORTING
        OUTPUT        = T_BELNR
    and pass T_BELNR to the where condition.
    Hope this helps.

Maybe you are looking for