Dynamic field modification in Work Area.

Hi,
I want to insert 1 record in a transparent table. (But for time being, let us assume the table is MARA)
The columns and table name to which data is to be inserted are stored in another transparent table say (z1354_inv_rec_dt).
The data to be inserted is specified in a text file.
The value for MATNR, let us assume is hard coded as 1252.
The value for fields ERSDA, ERNAM, LAEDA and AENAM will be specified in input text file.
Also the table z1354_inv_rec_dt, will have rows with values ERSDA, ERNAM, LAEDA and AENAM.
How do I do this, the code specified in form comparedata is not correct one, but just a starting point for code.
<b>So how do I specify the column of work area at run time and assign value to it.</b>
Then I have to append value from work area to internal table.
And from internal table, I will insert to database.
REPORT ZDYN_INS_MARA.
TYPE-POOLS : abap.
DATA:
  lit_z1354_inv_rec_dt  TYPE TABLE OF z1354_inv_rec_dt,
* table z1354_inv_rec_dt contains 2 columns column_name and table_name
* values for column_name are ERSDA, ERNAM, LAEDA and AENAM
* value for table_name is MARA.
  lwa_invoice LIKE  z1354_inv_rec_dt,
  lit_mara TYPE TABLE OF mara,
  lwa_mara LIKE mara.
* To get column names
DATA :
  it_details TYPE abap_compdescr_tab,
  wa_details TYPE abap_compdescr,
  ref_descr TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS : <fs_mara> TYPE mara.
FIELD-SYMBOLS : <fs_wa_mara> LIKE LINE OF lit_mara.
FIELD-SYMBOLS : <dyn_field>.
DATA: int_tabname(30).
int_tabname = 'MARA'.
*Populate internal table with columns to be added to Database
PERFORM populaterecdt.
ref_descr ?= cl_abap_typedescr=>describe_by_name( int_tabname ).
*Get the column names from the Database tables
it_details[] = ref_descr->components[].
PERFORM comparedata.
*&      Form  PopulateRecDt
FORM populaterecdt .
  SELECT column_name table_name FROM z1354_inv_rec_dt
  INTO CORRESPONDING FIELDS OF TABLE lit_z1354_inv_rec_dt
  WHERE table_name = 'MARA' .
ENDFORM.                    " PopulateRecDt
*&      Form  CompareData
FORM comparedata .
*loop through the DB table which holds the column names to be added
LOOP AT lit_z1354_inv_rec_dt INTO lwa_invoice.
*Loop throught table which holds the column names
  ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_wa_mara> TO <dyn_field>.
  <dyn_field> = '1252'   .
  LOOP AT it_details INTO wa_details.
    IF wa_details-name = lwa_invoice-column_name.
* Assign value to column of work area from text file.
      ASSIGN component lwa_invoice-column_name of structure                   <fs_wa_mara> to <dyn_field>.
*Get value for <dyn_field> from text file
        <dyn_field> = 'XYZ212'.
    ENDIF.
  ENDLOOP.
ENDLOOP.
*append work area t to lit_mara.
*Append work area to internal table.
*insert the internal table to DB
ENDFORM.                    " CompareData
Here in this loop, I want to assign to the work area for Mara based on the column values, How do I do it.
Regards,
Vikas

Hi,
This problem has been resolved.
DATA:
    lit_MARA TYPE TABLE OF MARA,
    lit2_MARA TYPE TABLE OF MARA,
    lwa_MARA LIKE MARA,
    lit_inv TYPE TABLE OF z1354_inv_rec_dt,
    wa_inv  LIKE z1354_inv_rec_dt,
    sctemp(100) TYPE c,
    ifs type i,
     p_gs_s_rec_line TYPE string.
  FIELD-SYMBOLS:
    <fs_MARA> TYPE table,
    <ld_column>   TYPE ANY,
    <fs_wa_MARA> LIKE LINE OF lit_MARA.
*Populate Invoice table
  SELECT * FROM  z1354_inv_rec_dt INTO CORRESPONDING FIELDS OF TABLE
  lit_inv WHERE recordtype = 'S' AND table_name = 'MARA' AND
  column_seq > 0.
  p_gs_rec_line = '1234567890000001'.
  lwa_MARA-laufi = '123e'.
  FREE lit_MARA.
  APPEND  lwa_MARA TO lit_MARA.
  ASSIGN lit_MARA[] TO <fs_MARA>.
  UNASSIGN: <fs_wa_MARA>.
* free lit_MARA[] .
* LOOP AT <fs> ASSIGNING <fs1>.
LOOP AT lit_MARA ASSIGNING <fs_wa_MARA>.
  ifs = sy-tabix.
  write: / ifs.
    LOOP AT lit_inv INTO wa_inv.
      WRITE
      p_gs_s_rec_line+wa_inv-start_pos_extrac(wa_inv-chars_to_extract)
      TO sctemp.
      UNASSIGN: <ld_column>.
      ASSIGN COMPONENT wa_inv-column_name OF STRUCTURE <fs_wa_MARA>
      TO <ld_column>.
      <ld_column> =  sctemp.
      IF ( <ld_column> IS ASSIGNED ).
        WRITE: / '.' .
      ENDIF.
      CLEAR wa_inv.
    ENDLOOP.
    MOVE  <fs_wa_MARA> TO lwa_MARA.
    APPEND lwa_MARA TO lit2_MARA.
   CLEAR <fs_wa_MARA>.
  ENDLOOP.
loop at lit2_MARA into lwa_MARA.
  write: / lwa_MARA-filename.
  clear lwa_MARA.
endloop.
insert MARA from table lit2_MARA.
if sy-subrc <> 0.
  write: / ' Insert  :-( '.
endif.

Similar Messages

  • Difference between Field symbols and work area for Internal tables

    Hi,
    In ECC versions we all know that we need to declare the internal tables without headerline, and for handling the internal tables we need to use exclusive work areas.
    Currently i have an issue that we have been asked to use field symbols instead of work areas...can any one help me how to use the field symbols and also let me know how it will improve the performance of the program..
    Thanks and Regards,
    Kathir

    Hi
    DATA: WA TYPE ITAB.
    LOOP AT ITAB INTO WA.
    IF WA-FIELD = .....
    ENDIF.
    ENDLOOP.[(code]
    FIELD-SYMBOLS <WA> TYPE ANY.
    LOOP AT ITAB ASSIGNING <WA>.
    ENDLOOP.
    Now the problem is you can't know the name of the fields of the table at runtime, so you can't write:
    IF <WA>-FIELD = .....
    ENDIF.
    Anyway you can create a field-symbols strcturated like the table:
    [code]FIELD-SYMBOLS <WA> TYPE ITAB.
    LOOP AT ITAB ASSIGNING <WA>.
      IF <WA>-FIELD = .....
      ENDIF.
    ENDLOOP.
    I don't know which are the differences for the performance between to use a field-symbol and to use a structure as work-area.
    The differnce between the field-symbols and work-area is the field-symbol is assigned directly to the record, so u don't need to do a MODIFY statament to change something:
    LOOP AT ITAB INTO WA.
      WA-FIELD =
      MODIFY ITAB FROM WA.
    ENDLOOP.
    LOOP AT ITAB ASSIGNING <WA>.
      <WA>-FIELD =
    ENDLOOP.
    These two pieces of abap code do the same action, so probably the field-symbol improve the performance because it do an access directly to the record without to use an external structure as workarea.
    Max

  • Performance Field Symbols Vs Work Area

    Hi,
    I want to some operations (Validations and Calculations) form each entry of internal table.
    Which is better way to access the data in internal table either using field symbol or using work area?
    I heard that using filed symbols is performance issue. May I know in which cases we should not use field symbols?
    Regards,
    Kumar

    I do not think, the runtime creates a pointer to each line of the itab.
    The developer creates ONE fieldsymbol ( for a loop for example ) --> a pointer, which is iteratively assigned, pointing to only one line at one time.
    With the usage itself it  seems to offer a benefit, which isn't really one, If You only read data.
    People might say, You can omit a clear, if working with fieldsymbols.
    But You have to add a check for sy-subrc, or You will suffer from a dump, which usually never happens, if working with work areas the same way, like fieldsymbols.
    The real benefit only comes into play, if You want to modify the data in the internal table, because You are already acting on the line of the table (pointer to record n ), what allows You, to omit any modify to transfer changed values back to the internal table.
    In terms of performance I must see it technically and I hope, someone can confirm/reject my statement, so that I (if I was wrong) could keep that in mind.
    A fieldsymbol (lets talk about them in technical way, as a pointer) is in fact a variable, which holds an address of another variable( which itself also can hold an address and so on).
    Pointers are either 4 byte or 8 byte. So, it does not matter, how much columns Your internal table has, technically the fieldsymbol is either 4 byte big or 8 byte big. And exactly this amount is used in the ram of the application server.
    In fact pointers even do not have a type, as usual pointers are always integer.
    A workarea is a linear, continous allocation of memory space, exacly matching the data-structure, which is used for declaration. So it is obvious, that this workarea uses much more memory of the ram, as long their elements exceed 4 / 8 bytes.
    Still then it is not more performant, because changed data of a workarea has to be transferred to the internal table, (mostly, if one wants to modify), but with field-symbols this step is removed.
    So in fact there are two technical reasons for using field-symbols.
    One is, You save memory-space and the second is, You save the transferring.
    In an even deeper way, one can say, that , by design, a cpu with its address bus is just intended to understand addresses best ( directly after 0 and 1 and hex ).

  • Field symbol to work area

    Hello experts,
                       I am getting a problem while working with field symbols. I have some data field symbol in the form of structure. The field symbols have the type 'TABLE' so the data fills in runtime, so the structure also changes runtime. We need to get some fields out form them in the work area.
        How can I do that? Is there any code you can give me so that I can use that.
    Please help.
    Thanks,
    Ganesh

    Hello,
    Use the Assign statement.
    Try like this.
      LOOP AT <FS_1> ASSIGNING <FS_2>.
        ASSIGN COMPONENT  'POSIDFROM'
        OF STRUCTURE  <FS_2>  TO <FS_5>.
        LV_POSID = <FS_5>.
    endloop.
    Cheers,
    Vasanth

  • To find the field in the work area and pass to some field

    Hi all,
    My Requirement is something like this .
    i have 2 records in my internal table and i the value which i require may be anywhere in that internal table .
    Eg.
                     NODE     NODEDESC    PSPHI        PARENT      CHILD     ZLEFT       ZRIGHT
                      ASD         XCCC           ASD                            R.00002
                      CDD         CCCCC         CDD             GHJ
                       FGB         FFFF            R.000005     RFG
                       GHJ        CCCC            CDD             CDD         RFG
    Records look like the above pattern so i want to capture the values like R.00002 or any value which resembles R.------
    as i need to pass these things to my another function module my question is R.---- can be in any field so how can i get that values.
    please help me
    Hope i am clear with my question.
    Regards,
    Sana.

    Hi,
    Try this way..
    Suppose my internal table has 3 fields(A1,A2,A3) and i have two records.
    A1 A2 A3
    g1   t 2   R1
    t1   R1   t2
    Loop at itab.
    var1 = itab-A1.
    var2 = itab-a2
    var3 = itab-a3.
    if var1 CA 'R'.
    move var1 to some variable.
    elseif var2 CA '2'.
    move var2 to some variable.
    elseif var3 CA 'R'.
    Move var3 to some variable.
    endif.
    clear : itab,
               var1,
               var2,
              var3.
    endloop.
    Regards,
    Nagaraj

  • Read dynamic field symbol Work Area before append to dynamic table

    Hi experts:
    I have a dynamic work area but before doing an append to the dynamic table, I need to do some validation on some fields of the work area in order to decide to append it or not, but I don't know how...
    More or less this is the example
    loop at so_kschl.
        field = so_kschl-low.
        if <t_dyntable>-field = 0. "if the value of this field in dinamic table is 0.
    don't append
        else.
           APPEND <fs_dyntable> TO <t_dyntable>.  
        endif.
    endloop.
    Thank you very much for your help.
    Miriam

    Check this example, you read the component of the dynamic work area and assign it to a field-symbols. In this case, I validate that the entry is always 'a'.
    DATA: i_lvc TYPE lvc_t_fcat WITH HEADER LINE,
          i_table TYPE REF TO data,
          l_style TYPE lvc_fname,
          l_warea TYPE REF TO data,
          l_name(7) VALUE 'VARCHAR'..
    FIELD-SYMBOLS: <fs> TYPE table,
                  <fs2> TYPE ANY,
                  <fs3> TYPE ANY.
    PARAMETERS p_char TYPE c LOWER CASE.
    START-OF-SELECTION.
      i_lvc-fieldname = 'Varchar'.
      i_lvc-inttype = 'C'.
      i_lvc-intlen = 1.
      APPEND i_lvc.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
      it_fieldcatalog = i_lvc[]
      IMPORTING
      ep_table = i_table
      e_style_fname = l_style.
      ASSIGN i_table->* TO <fs>.
      CREATE DATA l_warea LIKE LINE OF <fs>.
      ASSIGN l_warea->* TO <fs2>.
      <fs2> = p_char.
      ASSIGN COMPONENT l_name OF STRUCTURE <fs2> TO <fs3>.
      IF <fs3> = 'a'.
        WRITE: 'Component VARCHAR is a'.
    *  APPEND <fs2> TO <fs>.
      ELSE.
        WRITE: 'Component VARCHAR is not a'.
      ENDIF.

  • Dynamic access to work area fields

    Hi
    I've got a DataBase table with 20 fields with different names.
    field1
    field2
    field3.
    field20
    I'm using a work area to read values and i wanna read an specific field of this work area.
    The problem is the following:
    I don't know the name of the field i need to access, instead, i have it in a field symbol.
    Is there any way i can get the value of this field???

    Hi,
    Try the following example
      DATA: i_TAB           LIKE PA0001 OCCURS 0 WITH HEADER LINE,
            l_field(50)     TYPE C,
            l_fieldname(50) TYPE C VALUE 'UNAME'.
      FIELD-SYMBOLS: <fieldxx> TYPE ANY,
                     <valxx>   TYPE ANY.
      ASSIGN l_fieldname TO <fieldxx>.
      SELECT * FROM PA0001 INTO TABLE I_TAB.
      LOOP AT I_TAB.
        CONCATENATE 'I_TAB-' <fieldxx> INTO l_field.
        ASSIGN (l_field) TO <valxx>.
        WRITE <valxx>.
      ENDLOOP.

  • How to assign values to a work area which is a Field Symbol?

    Hello Experts!
    I really need your help! this is the problem:
    I need to assign values to fields into a work area which is a field symbol. The values come from a flat file I uploaded and as I can't know the length I had to build the structure dynamically ( That's why I'm using FS). Each field comes from the file separated by ';', I tried using the SPLIT sentence:
    "SPLIT text AT ';' INTO TABLE <dyn_table>." but the values are assigned vertically into the same field instead of horizontally into each field of the table(field-symbol table).
    I know the name of the field dynamically
    (a TEXT + number) and I know I can't do this
    <dyn_wa>-TEXT1 or field_name = 'TEXT1' <dyn_wa>-(field_name).... ohhh I'm blocked, I don't seem to find the answer, please help!
    Thanks in advance!!
    Frinee

    Now that you have a table with the values, you can move them to the work area.
    data: begin of wa,
          fld1(20) type c,
          fld2(20) type c,
          fld3(20) type c,
    *     and so on
          end of wa.
    data: istr type table of string with header line.
    field-symbols: <fs>.
    split text at ';' into table istr.
    loop at istr.
    assign component sy-tabix of structure wa to <fs>.
    if sy-subrc <> 0.
    exit.
    endif.
    <fs> = istr.
    endloop.
    write:/ wa-fld1, wa-fld2, wa-fld3.
    Now, WA has the values in a horizontal fashion.
    Regards,
    Rich Heilman

  • How to read data from dynamic work area.

    Hi guys,
                I have created dynamic table and work area for report.
    i have populated few values in dynamic work area.
    Now i want to read that data from work area again for calculation.
    i can not use local varialbes to store those values as i dont know how many such variables i need to read.
    that will be known only at run time.
    So as per my knowledge i have only 1 option...to read those all values from work area.
    Kindly help me .... how can i read data which is stored in dynamic work area.

    Hi Kiran,
    Following is not exact code, but exact solution to your problem:
      LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
          l_tabix = sy-tabix.
          ASSIGN COMPONENT 'KOTAB' OF STRUCTURE <dyn_wa> TO <l_kotab>.
          IF <l_kotab> IS ASSIGNED AND <l_kotab> IS INITIAL.
            <l_kotab> = gt_tabs-kotab.
            MODIFY <dyn_table> FROM <dyn_wa> INDEX l_tabix.
          ENDIF.
        ENDLOOP.
    I am hardcoding KOTAB as I was sure about that being in the dynamic structure.
    You can loop on the field catalogue, which you used to create dyamic table,  to use the FIELDNAME to read all the fields of the work area (structure) of your dynamic table.
    thanks,
    Aabhas
    Edited by: Aabhas K Vishnoi on Sep 24, 2009 8:12 PM

  • Get the fieldnames of a generic internal table or work area

    Hi All,
           I have one generic work area which I have created in the below manner...
    * ET_DATA itself is a generic table of type ANY...can have any internal table data in it.
    * Create dynamic internal table
      CREATE DATA lv_new_table LIKE et_data.
      ASSIGN lv_new_table->* TO <fs_dyn_table>.
    * Create dynamic work area and assign to fieldsymbol.
      CREATE DATA lv_new_line LIKE LINE OF <fs_dyn_table>.
      ASSIGN lv_new_line->*   TO <fs_dyn_wa>.
    Now...I need to get the field names of this dynamic internal table or work area..
    I have already searched in forum...got many answers..but none them gives me the output.
    Please note that I require the field names and not field position..
    Awaiting your suggestions on how to get field names of this dynamic work area...

      create data wa_ref like line of it_data.
      assign wa_ref->* to <p_data>.
      desc_table ?= cl_abap_tabledescr=>describe_by_data( it_data ).
      desc_struc ?= desc_table->get_table_line_type( ).
      describe field <p_data> type rtty components ncom.
    This one is working in our environment without any error. it_data is an importing parameter in the signature of a method of type any table.

  • ALV Report: How to pass the variable in Work area to the FM ? Please help !

    I want to pass the field in the work area which contains the floating point numbers to FM 'FLTP_CHAR_CONVERSION_FROM_SI'. This the correct FM, I have tested.
    If I specify the field with Tab name in FM , It says its not an internal table with header line.
    Please help me, How should can I proceed further and pass the field to FM and get it back in work area.
    And an other issue is I want to sum the particular field in the output.
    Is there a way to do using 'PF-STATUS', if so how ? or what is the alternative for this ?
    Please help me with my issues.
    I'm new to ALV reports.
    Thanks in Advance !

    Hi,
    For your FM issue, i think you are trying to pass the field in the FM as ITAB-field, while you should be taking the data in the work area first and then pass this work area in the FM as WA_ITAB-field.
    I hope this will resolve your prob.
    I mean loop at the table and take the values into work area, update the internal table with changed value. This way by the end of loop you will have all your fields converted.
    Please explain a little more about your second doubt, it is unclear(to me atleast).
    Edited by: DeepakNagar on Jul 28, 2011 6:08 PM

  • How to merge work areas of same internal table

    Hi Experts,
    I have a requirement to merge two work areas into 3rd work area where all 3 belonging to same internal table like example below.
            person | activity | location |
    wa1: 001     |    A       |              |
            person | activity | location |
    wa2: 001     |              | xyz       |
    after merging the value in wa3 should be as follows:
             person | activity | location |
    wa3: 001      |    A       |  xyz       |
    I am looking for a ABAP command or FM to perform this task.  Please help me on the same.
    Many Thanks,
    Vijay

    Hello,
    Try this:
    Field-symbols: <lfs_wa1> type line of lit1,
                     <lfs_wa2> type line of lit2.
      sort lit2 by field1 ascending.
      loop at lit1 assigning <lfs_wa1>.
        read table lit2 with key field1 = <lfs_wa1>-field1 assigning <lfs_wa2> binary search.
        clear wa3.
        wa3-field1 = <lfs_wa2>-field1.
        wa3-field2 = <lfs_wa2>-field2.
        wa3-field3 = <lfs_wa2>-field3.
        append wa3 to lit3.
      endloop.
    Use sorted internal tables, field symbols and binary search for better performance. In case when different fields in both work areas may be populated for each row, you need to implement some check and move logic inside loop instead of simple value assignment. I assume that the key value is always there for both tables you want to merge.
    best regards,
    Marcin
    Edited by: Marcin Makowski on Oct 20, 2010 7:16 PM
    Edited by: Marcin Makowski on Oct 20, 2010 7:17 PM

  • How to fill Dynamic work area or field symbol?

    HI All,
    I have created dynamic work area(field symbol) by using following code. Now I want to fill the work area with values which are there in other internal table.
    * Create dynamic internal table/structure
      call method cl_alv_table_create=>create_dynamic_table
        exporting
          it_fieldcatalog = it_fieldcat
        importing
          ep_table        = dyn_table.
      assign dyn_table->* to <fs_table>.
    * Create dynamic work area and assign to Field Symbol
      create data dyn_line like line of <fs_table>.
      assign dyn_line->* to <fs_wa>.
    My <FS_WA> contains:
    ROW1
    ROW2
    ROW3
    ROW4 as fields in it without having any data.
    I have other internal table.. where I have FIELDS and Data like following:
    FIELD1  FIELD2   FIELD3
    ID1 ROW1 A1
    ID1 ROW2 A2
    ID1 ROW3 A3
    ID1 ROW4 A4
    ID2 ROW1 B1
    ID2 ROW2 B2
    ID2 ROW3 B3
    ID3 ROW1 C4
    Important thing that I have to share with you is... Source table of my Internal table and Source structure to create my dynamic table are same.
    This dynamic table has fields... with "FIELD2" values.
    Thanks,
    Naveen.I

    Create a dynamic internal table
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = lt_fcat
        IMPORTING
          ep_table        = lt_dy_table.
    Create dynamic work area and assign to FS
      ASSIGN lt_dy_table->* TO <fs_dyn_table>.
      CREATE DATA lt_dy_line LIKE LINE OF <fs_dyn_table>.
      ASSIGN lt_dy_line->* TO <fs_dyn_wa>.
    Define WA
      CREATE DATA dref TYPE (iv_struc_name).
      ASSIGN dref->* TO <fs_final>.
    Populate dynamic table from the file
      OPEN DATASET iv_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
      IF sy-subrc = 0.
        DO.
          READ DATASET iv_path INTO ls_str.
          IF sy-subrc <> 0.
            ev_failed = abap_true.
            EXIT.
          ENDIF.
          SPLIT ls_str AT ';' INTO TABLE lt_dyn_tab.  " columns
          LOOP AT lt_dyn_tab INTO ls_dyn_tab.
            READ TABLE lt_struc_fld INTO ls_struc_fld INDEX sy-tabix.
            IF sy-subrc EQ 0.
              MOVE ls_struc_fld-fieldname TO ls_fieldname.
              ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_dyn_wa> TO <fs_val>.
              IF sy-subrc = 0.
                <fs_val> = ls_dyn_tab.
              ENDIF.
              ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_final> TO <fs_val>.
              IF sy-subrc = 0.
                <fs_val> = ls_dyn_tab.
              ENDIF.
            ENDIF.
          ENDLOOP.
          APPEND <fs_dyn_wa> TO <fs_dyn_table>.
          APPEND <fs_final> TO et_table.
          UNASSIGN: <fs_val>.
        ENDDO.
      ENDIF.
      CLOSE DATASET iv_path.

  • Dynamic Work Area - fields

    HI SDN COMMUNITY..!!
    I HAVE TO USE THE WA_SEKPO-FIELDNAME DYNAMICALLY..
    DATA: BEGIN OF WA_SEKPO,
          EBELN TYPE EBELN,
          BRTWR TYPE BRTWR,
          EFFWR TYPE EFFWR,
          MENGE TYPE MENGE,
          END OF WA_SEKPO.
    DATA: SEKPO LIKE TABLE OF WA_SEKPO.
    DATA: VAR_FNAME TYPE STRING.
    FIELD-SYMBOLS: <FS> TYPE ANY.
    STRUCTURE OF <b>EDITPOS</b>(INTERNAL TABLE)
    |OBJECTID   |TABNAME|FNAME  |   F_NEW    |    F_OLD
    |4500016340 |EKPO   |BRTWR  |       26   |    11
    |4500016340 |EKPO   |EFFWR  |       25   |    12
    |4500016340 |EKPO   |MENGE  |       22   |    13
    INTERNAL TABLE :
    <b>EDITPOS</b> CONTAINS VALUES FOR : BRTWR
                                  EFFWR 
                                  MENGE
    IT MAY CONTAIN VALUES FOR MORE FIELDS.
    NOW PROBLEM IS
    I HAVE TO UPDATE MY INTERNAL TABLE : SEKPO
    FOR FIELDNAMES : BRTWR
                     EFFWR
                     MENGE
    BUT I DONT HAVE TO HARD CODE IT FOR EACH FIELD.
    PLEASE CHECK, HOW THIS CAN BE ACHIVED?
    WA_SEKPO-BRTWR = WA_EDITPOS-F_NEW.
    PLEASE UPDATE THE CODE:
    LOOP AT EDITPOS INTO WA_EDITPOS.
               ASSIGN WA_EDITPOS-FNAME TO <FS>.
               CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
               WA_SEKPO-(<FS>)  = WA_EDITPOS-F_NEW.
    *       MODIFY TABLE SEKPO FROM WA_SEKPO
    *          TRANSPORTING <FS>.
    ENDLOOP.
    HELP WILL BE APPRICIATED
    THANKS IN ADVANCE
    VIJAY RAHEJA

    HI
    STRUCTURE OF EDITPOS(INTERNAL TABLE)
    |OBJECTID |TABNAME|FNAME | F_NEW | F_OLD
    |4500016340 |EKPO |BRTWR | 26 | 11
    |4500016340 |EKPO |EFFWR | 25 | 12
    |4500016340 |EKPO |MENGE | 22 | 13
    LOOP AT EDITPOS INTO WA_EDITPOS.
    IF WA_EDITPOS = 'BRTWR'.
      WA_SEKPO-BRTWR = WA_EDITPOS-F_NEW.
      MODIFY TABLE SEKPO FROM WA_SEKPO
      TRANSPORTING BRTWR.
    ELSEIF WA_EDITPOS = 'EFFWR'.
      WA_SEKPO-EFFWR = WA_EDITPOS-F_NEW.
      MODIFY TABLE SEKPO FROM WA_SEKPO
      TRANSPORTING EFFWR.
    ELSEIF WA_EDITPOS = 'MENGE'.
      WA_SEKPO-EFFWR = WA_EDITPOS-F_NEW.
      MODIFY TABLE SEKPO FROM WA_SEKPO
      TRANSPORTING MENGE.
    ENDIF.
    ENDLOOP.
    I AM TRYING TO ACHIEVE THE ABOVE FUNCTIONALITY DYNAMICALLY,
    AS I AM UNAWARE OF ENTRIES IN Internal Table: EDITPOS.
    It contains values:  BRTWR/EFFWR/MENGE
    But it may contain more,SO i cannot straight away HARD code it for modifying entries in SEKPO.
    for which i have written the code:
    LOOP AT EDITPOS INTO WA_EDITPOS.
    ASSIGN WA_EDITPOS-FNAME TO <FS>.
    CONCATENATE 'WA_SEKPO-' <FS> INTO VAR_FNAME.
    WA_SEKPO-<FS> = WA_EDITPOS-F_NEW.
    MODIFY TABLE SEKPO FROM WA_SEKPO
    TRANSPORTING <FS>.
    ENDLOOP.
    But there it shown Error before Activating the code: that <fs> is not a component of work area wa_sekpo
    WA_SEKPO-<FS>
    that is the problem,How to assign fieldname to a work area Dynamically.
    Regards,
    Vijay Raheja

  • Dynamic Work Area and field symbol

    Hi All,
    I'm have a big internal table like this
    data: begin of data occurs 0,
    Field01,
    Field02,
    Field03,
    *bucket 1
    Field04,
    Field05,
    Field06,
    *bucket 2
    Field04,
    Field05,
    Field06,
    *bucket 3
    Field04,
    Field05,
    Field06,
    Field 1, 2 3 will be the same for pernr, first last name.
    Field 4, 5, 6 are the same format but different numbers (or values ) in different buckets.
    Each bucket can be shown (or not) based on the condition of a person, for example if that person live in 2 states, it will show 2 bucket with 2 address info inside each.
    I will run this under get pernr to sort out each person who have many address or not.
    Can I use dynamic work area and field symbol here? if I can, how?
    Really appreciate your help with points...

    You can use the ASSIGN COMPONENT ... and than APPEND the work area to the table.
    Check out this sample program:
    REPORT  ZTEST_NP.
    DATA: BEGIN OF ITAB OCCURS 0,
          F1    TYPE I,
          F2    TYPE I,
          F3    TYPE I,
          END   OF ITAB.
    DATA: WA_ITAB LIKE ITAB.
    DATA: L_CNT TYPE I.
    FIELD-SYMBOLS: <F_FLD> TYPE ANY.
    DO 10 TIMES.    " I want 10 reocrds
      CLEAR L_CNT.
      DO 3 TIMES.   " I have 3 fields
        L_CNT = L_CNT + 1.
        ASSIGN COMPONENT L_CNT OF STRUCTURE WA_ITAB TO <F_FLD>.
        <F_FLD> = L_CNT.
      ENDDO.
      APPEND WA_ITAB TO ITAB.
      CLEAR  ITAB.
    ENDDO.
    LOOP AT ITAB INTO WA_ITAB.
      WRITE: / WA_ITAB-F1,
               WA_ITAB-F2,
               WA_ITAB-F3.
    ENDLOOP.
    Regards,
    Naimesh Patel

Maybe you are looking for