How to populate one internal table from another using field symbols

Hi Gurus,
  I have a problem. I have to populate one internal table (sructure t_otput) from another internal table (sructure t_from) using field symbol.
Structure for from table.
types: begin of t_from,
         year(4) type c,
         ww(2) type c,
         site type marc-werks,
         demand type i,
       end of t_from.
Structure for output table.
types: begin of t_display,
         title(30),
         WW1(10),
         WW2(10),
         WW3(10),
       end of t_display.
The from table looks like this:
Year | WW | Site | Demand
2005 | 1  | OR1  | 12.00
2005 | 2  | OR1  | 13.00
2005 | 3  | OR1  | 14.00
The display table which has to be populated should look like this:
Title  | WW1   | WW2   | WW3
OR1    |       |       |
Demand | 12.00 | 13.00 | 14.00
How to populate display table using field symbol?
Please give code snippets
Thanks,
Gopal

Gopal,
Here is the code, however I am not vary clear about the ORG1 and Demand display that you have shown in the display. I am sure with this code it should not be a big deal to tweak in whatever manner you want.
TABLES : marc.
TYPES: BEGIN OF type_display,
title(30),
ww1(10),
ww2(10),
ww3(10),
END OF type_display.
TYPES: BEGIN OF type_from,
year(4) TYPE c,
ww(2) TYPE c,
site TYPE marc-werks,
demand TYPE i,
END OF type_from.
data : t_from type table of type_from,
       t_display type table of type_display.
field-symbols : <fs_from> type type_from,
                <fs_display> type type_display.
data : wa_from type type_From,
       wa_display type type_display.
wa_from-year = '2005'.
wa_from-ww   = '1'.
wa_from-site = 'OR1'.
wa_from-demand = '12.00'.
insert wa_from  into table t_from.
wa_from-year = '2005'.
wa_from-ww   = '2'.
wa_from-site = 'OR1'.
wa_from-demand = '13.00'.
insert wa_from  into table t_from.
wa_from-year = '2005'.
wa_from-ww   = '3'.
wa_from-site = 'OR1'.
wa_from-demand = '14.00'.
insert wa_from  into table t_from.
data : variable(3) type c.
field-symbols : <fs_any> type any.
break-point.
Loop at t_from assigning <fs_from>.
variable = 'WW'.
wa_display-title = <fs_from>-site.
concatenate variable <fs_from>-ww into variable.
assign component variable of structure wa_display to <fs_any>.
<fs_any> = <fs_from>-demand.
endloop.
append wa_display to t_display.
clear wa_display.
loop at t_display assigning <Fs_display>.
  write :/ <fs_display>.
endloop.
Note : Please award points if this helps you.
Regards,
Ravi

Similar Messages

  • How to populate an internal table from a string variable

    Hi Experts,
    My internal table contains a field of length 255 characters.
    I have a string variable. I need to populate the internal table from the string variable.
    How should I code for this.
    Thanks,
    Sangeeta.

    Hi Sangeetha,
    <li>Try this way.
    REPORT ztest_notepad.
    DATA: BEGIN OF it_file OCCURS 0,
           data TYPE c LENGTH 255,
          END OF it_file.
    DATA str     TYPE string.
    DATA g_len   TYPE i.
    DATA g_off   TYPE i.
    DATA g_loops TYPE i.
    CONCATENATE
    '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890x'
    '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890y'
    '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890z'
    '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789m'
    INTO str SEPARATED BY space.
    g_len   = STRLEN( str ).
    g_loops = g_len / 255.
    g_off = 1.
    DO g_loops TIMES.
      IF g_loops NE sy-index.
        IF sy-index EQ 1.
          it_file-data = str+0(255).
        ELSE.
          it_file-data = str+g_off(255).
        ENDIF.
        APPEND it_file.
        CLEAR  it_file.
        g_off = sy-index * 255.
      ELSE.
        g_len = g_len - g_off.
        it_file-data = str+g_off(g_len).
        APPEND it_file.
        CLEAR  it_file.
      ENDIF.
    ENDDO.
    LOOP AT it_file.
      WRITE:/ it_file-data.
    ENDLOOP.
    Thanks
    Venkat.O

  • How to populate dynamic internal table according to the field names

    Hi ,
          Iam having a dynamic internal table <DYN_TABLE> , it has fields like
    MATNR   MAKTX       MEINS    BISMT     MTART  ...
    Now my requirement is i need to fill them according to the fieldname from another internal table (static) .
    The order of  internal table (static) and dynamic internal are not same. 
    kindly help me.

    Hi,
    Here is the code. Please reward points if helpful.
    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
          text
    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.                    "get_structure
    *&      Form  create_dynamic_itab
          text
    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.                    "create_dynamic_itab
    *&      Form  get_data
          text
    FORM get_data.
    Select Data from table.
      SELECT * INTO TABLE <dyn_table>
                 FROM (p_table).
    ENDFORM.                    "get_data
    *&      Form  write_out
          text
    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.                    "write_out

  • How to populate an internal table from three different tables

    My requirement is to populate an itab by retrieving data from three diff db tables,
    ekko,ekpo and Ekbe.
    below is the code for data retrieval .
    SELECT EBELN INTO TABLE IT_EKKO FROM EKKO WHERE EBELN IN S_EBELN.
      IF NOT IT_EKKO[] IS INITIAL.
        SELECT  EBELP TXZ01 NETWR BUKRS INTO CORRESPONDING FIELDS OF TABLE IT_EKPO FROM EKPO FOR ALL ENTRIES IN IT_EKKO
          WHERE EBELN EQ IT_EKKO-EBELN.
    IF NOT IT_EKPO[] IS INITIAL.
          SELECT  EMATN WAERS WERKS GJAHR BEWTP INTO CORRESPONDING FIELDS OF TABLE IT_EKBE FROM EKBE FOR ALL ENTRIES IN IT_EKPO
            WHERE EBELN EQ IT_EKPO-EBELN
             AND  EBELP EQ IT_EKPO-EBELP
             AND  BEWTP EQ 'E' OR BEWTP EQ 'Q'.
            ENDIF.
            ENDIF.
    please tell me how to populate data from it_ekko,it_ekpo and it_ekbe into an internal table ITAB.

    Hi Mayana,
    You take one final structure & final internal table, & within that structure take all the fields which is required to be displayed as a final output.
    for data fetching from different table, you take three different structures & three internal table for that, because into corresponding fields of table is not good for performance wise. Use into table syntax.
    follow the below example:(similarly)
    sort it_klah by key fields.
    LOOP AT IT_KSSK INTO WA_KSSK.
        READ TABLE IT_KLAH INTO WA_KLAH WITH KEY CLINT = WA_KSSK-CLINT
                                                 KLART = WA_KSSK-KLART.
        IF SY-SUBRC EQ 0.
          MOVE:  WA_KLAH-OBJEK to WA_final-OBJEK.
    Read another table........(2nd one)
    IF SY-SUBRC EQ 0.
          MOVE:  ....................................
          APPEND WA_final TO IT_final.
        ENDIF.
    clear wa_final.
      ENDLOOP.
    finally display it_final records.
    Hope this can solve your problems.
    Regards,
    Tutun

  • How to assign an internal table record to a field symbol

    I am working in an exit and I can see the following internal table while in debug mode. SAP has saved it to memory prior to the exit being called. It is not passed to the func module.  I can see the values in the table in Debug mode by accessing that particular itab name but I cannot find a way to access a specific field value ?
    Internal table name
    (SAPMV50A)XLIPS
    I can assign (SAPMV50A)XLIPS  ..
    but not this .,,,(SAPMV50A)XLIPS[1]  which is what I want to do..??
    any ideas
    ,,BAR

    Hi bar,
    1. Do like this , and it will work.
    2. I just tried now.
    3. In mycase, the program name, and table name is different,
    so accordingly, change your code.
    4. t001 is the record 1 i want to read.
    *--- IMPORTANT VARIABLES
      <b>data : t001 like t001.</b>
      <b>field-symbols : <F> type table.</b>
      <b>data : varname(35) type c.</b>
      BREAK-POINT.
    ASSIGNMENT - NOTE []
      varname = '(ZAM_TEMP00)T001[]'.
      assign (varname) to <F>.
    READ RECORD 1 - WE CAN READ ANY
      read table <F> into t001 index 1.
    regards,
    amit m.

  • How to scan data from one internal table to another

    Hi All,
    let me know how to scan all from one internal table to another internal table. Pls provide me the syntax and code.
    i am very thankful to you all in advance.
    Thanks & Regards,
    Nagarjuna.

    if u want to copy data from itab1 to itab2  then use
    itab2[] = itab1[].
    if u want to compare whether both itab1 and itab2 are same or not,use
    if itab1[] = itab2[].
    *--same
    else.
    *--not same
    endif.
    if u want to compare itabs based on primary key....
    loop at itab1.
    read table itab2 with key f1 = itab1-f1.
    if sy-subrc <> 0.
    *--not same....
    endif.
    endloop.
    if u want to copy only few lines(say from 1 to 3) of itab1 to itab2 then use...
    append lines of itab1 from 1 to 3 to itab2.
    if internal tables don't have same structure,
    say only fields f1 and f2 are common,then
    loop at itab1.
    itab2-f1 = itab1-f1.
    itab2-f2 = itab1-f2.
    append itab2.
    clear itab2.
    endloop.
    if there are many common fields then...
    loop at itab1.
    move-corresponding itab1 to itab2.
    append itab2.
    clear itab2.
    endloop.
    Please don't forget to reward points....!!!
    Regards
    vasu

  • How to insert select columns from one internal table to another

    Hi,
    How to insert select columns from one internal table to another based on condition as we do from a standart table to internal table.
    regards,
    Sriram

    Hi,
    If your question is for copying data from 1 int table to other ;
    we can use
    APPEND LINES OF it_1 TO it_2.
    or if they have different columns then:
    loop at it_1 into wa_it1.
    move wa_it1-data to wa_it2-d1.
    apped wa_it2 to it_2.
    clear wa_it2.
    endloop.
    thnxz

  • Moving few contents of one internal table to another internal table

    Hi
    I want to move some contents of one internal table to another internal table, which records match our condition
    (without loop)
    Example:
    1  aa
    2  aa
    3  aa
    4  bb 
    5  cc
    6  aa
    7  cc
    8  dd
    now i want to move records which contain aa to one internal table  without using loop.
    is there any statemnt to achieve this
    Reagrds
    Srinivasu

    Hi Srinivasu,
    Just create an another internal table say itab2 having the same structure.
    Then use the following code:
    itab2[] = itab1[]
    delete itab2 where field2 <> 'aa'.
    Hope this will help.
    Regards,
    Nitin.
    Edited by: Nitin Karamchandani on Nov 21, 2008 8:51 AM

  • Copying an  internal table data to a field symbol(only corresponding field)

    Hi,
       Iam having field symbol type standard table which has 4 fields in it already.
    I am having an internal table which has 10 columns in it.
    Now i want to copy the data from internal table to field symbol .But the problem is the fields which are matched in field symbol alone should be copied from the internal table.
    for eg.
    field symbol type table.
    field1.
    field2.
    field3.
    itab type internal table.
    field1
    field2
    field3
    field4
    field5
    field6.
    i want to copy the first 3 fields alone from the internal table itab to the field symbols. Can anyone help me on  how to do this. thanks...
    Regards,
    Rose.

    Hi,
    Chk below example, and match with ur scenario.
    data: begin of itab,
          a , b ,c , d,e,
          end of itab,
          wa like itab,
          jtab like table of itab,
          begin of fsy,
          a, b ,c,
          end of fsy.
    field-symbols:<fs> type any.
         assign fsy to <fs>.
         wa-a = 'x'. wa-b = 'y'. wa-c = 'z'. wa-d = 'r'.
         append wa to jtab.
          loop at jtab into wa.
            move-corresponding wa to <fs>.
          endloop.
    REGARDS,
    SENTHIL KUMAR.S

  • Moving data from one internal table to another

    Hi,
    I have one internal table populated with a list of material codes and another with all the material numbers.
    ITAB1: MCODE KSCHL KNUMH MATNR
    ITAB2:  MCODE MATNR
    The matnr field in itab1 is blank initially. It needs to be populated with all the material numbers from itab2. How can I achieve this?
    Thanks,
    ap

    Hi
    Lets say that there is only one record in itab1 and for that there is correspondingly 10 records in itab2.
    that means that the one record in itab1 should be changed to the first material number in itab2 and there should be nine more records created in itab1 according to the values in itab2.
    Hope this is what you mean.
    If this is the logic then the following code should work
    then lets have a third internal table the same type as itab1
    Loop at itab1 into wa_itab1
    *readt table itab2 into wa_itab2 with key mcode = wa_itab1-mcode.
    *IF sy-subrc eq 0.
    loop at itab2 into wa_itab2 where mcode = wa_itab1-mcode.
    wa_itab1-matnr = wa_itab2-matnr
    append wa_itab1 to itab3.
    endloop.
    *ENDIF.
    *modify itab1 from wa_itab1.
    endloop.
    itab3 will contain all the values that you require

  • Copy contents of one internal table to another

    Hi,
    I have one internal table IT1 which has following fields HKONT, DMBTR and DESC. Here DESC row is empty and rest of the fields are filled.
    Now there is another IT2 which has DESC field and this is filled.
    I have to copy the IT2-DESC into IT1-desc.
    How to do that?

    Hi Anurodh,
    if u want to collate data from 2 tables, there should be atleast one common field.
    As from ur query i can see that the field in ques id Description of some other field, say F1.
    If i am right, then fetch F1 field in both the tables and then using Loop and Read statements you can add DESC to IT1 table.
    Hope it helps.
    Reward points if useful.
    Regards,
    Preeti

  • Assigning Table/Structure Types using Field-Symbols

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

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

  • HOW TO TRANSFER DATA FROM ONE INTERNAL TABLE TO ANOTHER

    FOR PERTICULAR OBJECT ID ONE INT TABLE JTAB CONTAINS ONE RECORD(ROW) AND ANOTHER INT TABLE KTAB CONTAINS 3 RECORDS(ROWS). THEN HOW I SHOULD TRANSFER DATA FROM KTAB TO JTAB? WHAT R THE VARIOUS WAYS TO DO THAT. PLS HELP ME OUT. THANKS IN ADVANCE

    Try something like
    If you want one record per ktab :
    LOOP AT jtab.
      MOVE-CORRESPONDING jtab TO itab.
      LOOP AT ktab WHERE id = jtab-id.
        MOVE-CORRESPONDING ktab TO itab.
        APPEND itab.
      ENDLOOP.
    ENDLOOP.
    or
    LOOP AT ktab.
      READ TABLE jtab WITH KEY id = ktab-id. " binary implicit if sorted type
      MOVE-CORRESPONDING jtab TO itab.
      MOVE-CORRESPONDING ktab TO itab.
      APPEND itab.
    ENDLOOP. 
    If you want to sum ktab ratio into itab for each jtab
    LOOP AT jtab.
      MOVE-CORRESPONDING jtab TO itab.
      LOOP AT ktab WHERE id = jtab-id.
        ADD-CORRESPONDING ktab TO itab.
        APPEND itab.
      ENDLOOP.
    ENDLOOP.
    Use sorted type table when LOOP AT WHERE, else SORT table is enough.
    Regards

  • How to transfer an internal table from one FUNCTION to another

    Hi,
       In Normal Enabled Function, I have created an External Parameter as
         ZTEMP LIKE ZSTR.  (ZSTR is a structure).
       In Source Code, am using an Internal Table(ZINT) which is of the same structure type.
    I have populated the internal table. Now I have to export these internal table values to another function.
    I tried to assign the internal table to the exporting parameter. But this shows error as ZTEMP is not an internal table.
       So, How to transfer this??
       Give me sample Code.
    Regards,
    Kalai.
    Message was edited by:
            Kalaivani Pachiappan

    Hi Ramesh,
      Thanks for ur reply. Actually I am a beginner. So I dint get u. Can u first clear me one doubt: If I give ZTEMP LIKE ZSTR as export parameter, will it create ZTEMP as a table with all fields as in ZSTR ( or ) ZTEMP itself as a structure???
      Then How can I transfer the internal table using Import/Export?
       Actually FUNCTION1 is giving some input to FUNCTION2. FUNCTION2processes and stores the result in Internal Table. Now I have to export these internal table contents to FUNCTION1. 
       How can I do this??
    Thanks and Regards,
    Kalai

  • How  to copy data from one internal table to another

    i am using some function module to get some data for my function module
    and the retrieved data is not getting populated in mu fumctional module
    i am sucessful in getting the data to an internal table in my function module but dont know how to pass it to my table parameter
    thanks in advance

    Hi Naval,
    Declare an internal table of type table parameter structure and pass it the table parameters of the Function module.
    Check the code for this function module.
    DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
    SELECT * FROM MARA UP TO 10 ROWS INTO TABLE IT_MARA.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME                = 'C:\TEST.TXT'.      FILETYPE                = 'ASC'
          WRITE_FIELD_SEPARATOR   = 'X'
    <b>    TABLES
          DATA_TAB                = IT_MARA</b>
        EXCEPTIONS
          FILE_WRITE_ERROR        = 1
          NO_BATCH                = 2
          GUI_REFUSE_FILETRANSFER = 3
          INVALID_TYPE            = 4
          NO_AUTHORITY            = 5
          UNKNOWN_ERROR           = 6
          HEADER_NOT_ALLOWED      = 7
          SEPARATOR_NOT_ALLOWED   = 8
          FILESIZE_NOT_ALLOWED    = 9
          HEADER_TOO_LONG         = 10
          DP_ERROR_CREATE         = 11
          DP_ERROR_SEND           = 12
          DP_ERROR_WRITE          = 13
          UNKNOWN_DP_ERROR        = 14
          ACCESS_DENIED           = 15
          DP_OUT_OF_MEMORY        = 16
          DISK_FULL               = 17
          DP_TIMEOUT              = 18
          FILE_NOT_FOUND          = 19
          DATAPROVIDER_EXCEPTION  = 20
          CONTROL_FLUSH_ERROR     = 21
          OTHERS                  = 22.
      IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Thanks,
    Vinay

Maybe you are looking for