Dynamic Work Area Field name Assignment.

hi Guru,
  data: it_SFLIGHT type TABLE OF SFLIGHT,
          wa_SFLIGHT TYPE SFLIGHT,
          lv_field TYPE string.
  lv_field =     'CARRID'.   " Field name
    wa_SFLIGHT-<lv_field> = 'vivek'.  " Assigning Value to workarea.
When i try this i am getting the error.
Regards.
Vivekananthan.S

Hi,
assign (p_tc_name) to <tc>.
TYPES:
  BEGIN OF st_mytable,
    name1 TYPE string,
    name2 TYPE string,
    age TYPE i,
  END OF st_mytable.
DATA:
  gi_mytable TYPE STANDARD TABLE OF st_mytable,
  g_mytable  TYPE st_mytable.
* Define field symbols
FIELD-SYMBOLS:
  <myfield1> TYPE ANY,
  <myfield2> TYPE ANY,
  <myfield3> TYPE ANY,
  <myline>  TYPE ANY.
* Fill table with data
g_mytable-name1 = 'John'.
g_mytable-name2 = 'Johnson'.
g_mytable-age   = 25.
APPEND g_mytable TO gi_mytable.
g_mytable-name1 = 'Claudio'.
g_mytable-name2 = 'Jensen'.
g_mytable-age   =  45.
APPEND g_mytable TO gi_mytable.
* The normal way to do it
LOOP AT gi_mytable INTO g_mytable.
  WRITE: / g_mytable-name1, g_mytable-name2 ,g_mytable-age.
ENDLOOP.
SKIP 2.
* Do it with field symbols
LOOP AT gi_mytable ASSIGNING <myline>.
  ASSIGN COMPONENT 1 OF STRUCTURE <myline> TO <myfield1>.
  ASSIGN COMPONENT 2 OF STRUCTURE <myline> TO <myfield2>.
  ASSIGN component 3 OF STRUCTURE <myline> TO <myfield3>.
  WRITE: / <myfield1>,<myfield2>,<myfield3>.
ENDLOOP.
* Unassign field symbols
UNASSIGN <myfield1>.
UNASSIGN <myfield2>.
UNASSIGN <myfield3>.
UNASSIGN <myline>.
Regards,
Prabhudas

Similar Messages

  • 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

  • Code to equate table value to work area field name

    Hello Experts,
    How to match a certain value fetched from table to the internal table field.
    For instance: transparent table has a column containing values as
    AMOUNT
    QUANTITY
    there is another work area structure associated with different internal table consisting of amount and quantity fields.
    Now depending on whether the record from transparent table has fetched AMOUNT or QUANTITY, i have to read either the amount or quantity value from the work area.
    Can any one please suggest a technique to do it?
    Thanks,
    Pankaj

    Hi
    Try This:
    suppose you have zitab table as trans. Table and another table itab1 with work area wa.
    First you need to select values from Zitab to an internal table say itab.
    sort itab by <field name>
    loop at itab.
    read table itab1 into wa with key quantity = itab-quantity
                                      amount = itab-amount.
    endloop.
    This will read table itab1 where quantity and amount from itab table matches.
    hope this will work for you.
    thanks
    Lalit Gupta

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

  • 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

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

  • Work area field value not getting populated in table control grid.

    Hi all,
    I am currently facing an issue where I have declared a variable and have fetched the workarea field name in it. To be exact, the variable contains the workarea name whose value I am finally populating to the table control. Now although the workarea name when manually copied and pasted in field name in debugging mode exhibits the value of the it, Im unable to fetch the same value in the variable as I have only the work area name in it. I need the value of the workarea-field to be in the variable.Please provide your valuable suggestions for this issue...
    Regards,
    Edited by: Vishwanath Sreedharen on Jan 2, 2012 3:25 PM

    Hi Nabheet,
    Please consider the below example...
    DATA: l_var(30) TYPE C.
    CONCATENATE 'wa' '-' I_FIELD2-NAME INTO l_var.
    The i_field2-name contains the name of a custom table field CP_CUSTOM_GRP. So now the l_var contains wa_cp_custom_grp.
    Now consider the wa_cp_custom_grp has a value 'BA'.
    Now my issue is the l_var contains wa_cp_custom_grp but not its value(too obvious)... Would like to know whether is there a way through which the value of this wa_cp_custom_grp  'BA' could be populated to the variable l_var...

  • How to get work area - Variable name at runtime

    hi all,
    in this snippet.
    how can we retrieve the field name.
    this write statement merely writes the contents stored.
    how is it possible to write the field name.............?
    DO.
            ASSIGN COMPONENT sy-index
                   OF STRUCTURE <wa> TO <comp>.
            IF sy-subrc = 0.
              WRITE / <comp>.
            ELSE.
              EXIT.
            ENDIF.
          ENDDO.
    Naveen...

    In More detail....
    Find the help ID for various fields:
    TYPES: MYTYPE LIKE SBOOK-CLASS.
    DATA: F1       LIKE SBOOK-LUGGWEIGHT,
          F2       TYPE MYTYPE,
          F3       LIKE F1,
          HLP(30)  TYPE C,
          NAME(30) TYPE C VALUE 'SBOOK-ORDER_DATE'.
    FIELD-SYMBOLS: <G1>, <G2>.
    DESCRIBE FIELD F1 HELP-ID HLP. WRITE: /(5) 'F1:', HLP.
    DESCRIBE FIELD F2 HELP-ID HLP. WRITE: /(5) 'F2:', HLP.
    DESCRIBE FIELD F3 HELP-ID HLP. WRITE: /(5) 'F3:', HLP.
    ASSIGN (NAME) TO <G1>.
    DESCRIBE FIELD <G1> HELP-ID HLP. WRITE: /(5) '<G1>:', HLP.
    ASSIGN F2 TO <G2>.
    DESCRIBE FIELD <G2> HELP-ID HLP. WRITE: /(5) '<G2>:', HLP.
    Result: The following help IDs are output:
       F1:   SBOOK-LUGGWEIGHT
       F2:   SBOOK-CLASS
       F3:   SBOOK-LUGGWEIGHT
       <G1>:
       <G2>: SBOOK-CLASS

  • How to dynamicly create a field name AND access it

    All,
    I am trying to build a code block that will access what amounts to a table structure inside a table. I have 38 occurances if a set of 3 fields. (Source system had an internal array/occurs clause that was converted for our ODS into individual fields) I am returning a single row as a row type and have addressability to all fields. What I am trying to avoid is coding my logic block 38 times, 1 for each occurance.
    FOR X IN 1 .. 38 LOOP
    V_CAT_CD_X := 'CAT_'||X||'_CD';
    End Loop;
    The following is the display of the correctly built field:
    --> Loop Cat CD: CAT_1_CD Rec count:1 Loop counter:1
    --> Loop Cat CD: CAT_2_CD Rec count:1 Loop counter:2
    --> Loop Cat CD: CAT_3_CD Rec count:1 Loop counter:3
    --> Loop Cat CD: CAT_4_CD Rec count:1 Loop counter:4
    My problem is that my row cursor PP1 is addressable hardcoding PP1.CAT_1_CD or PP1.CAT_2_CD ect, however I am having problems using my created string to access the field.
    What do I need to do to gain accessability via this method?
    I do have the ability to select the column names from the system tables but even then, I am lacking addressability to my ROW type using the selected field name.
    Thanks
    Greg

    Not sure if this is what you are looking for:
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2  my_cur SYS_REFCURSOR;
      3  v_rec mytest%rowtype;
      4  cursor c1 is select column_name from all_tab_cols where table_name = 'MYTEST';
      5  v_sql_stmt VARCHAR2(1000) := NULL;
      6  BEGIN
      7  v_sql_stmt := 'SELECT ';
      8  FOR I IN c1 LOOP
      9  v_sql_stmt := v_sql_stmt||I.column_name||',';
    10  end loop;
    11  v_sql_stmt := RTRIM(v_sql_stmt,',');
    12  v_sql_stmt := v_sql_stmt||' FROM mytest';
    13  open my_cur for v_sql_stmt;
    14  LOOP
    15  FETCH my_cur INTO v_rec;
    16  EXIT WHEN my_cur%NOTFOUND;
    17  dbms_output.put_line(v_rec.a);
    18  END LOOP;
    19 close my_cur;
    20* end;
    SQL> /
    1
    2
    PL/SQL procedure successfully completed.
    SQL> Edited by: AP on Nov 17, 2010 5:29 AM

  • Form works but field names don't carry over to email

    I created a form and set it up to generate an email
    containing the information, which will be transmitted to my client.
    Everything works fine, except I can't get the form field names to
    carry over to the email. For example, I just get the completed
    field info w/o the labels, and I'd like to make it easier for my
    client to disseminate the information.
    Here's the code:
    <form action="
    http://fcdesign.net/v-cgi/forms.cgi"
    method="get"
    enctype="multipart/form-data" name="bwccontact"
    id="bwccontact"
    onsubmit="MM_validateForm('Name','','R','Street_Address','','R','City','','R','State','', 'R','Zip','','R','Phone','','R','Questions_or_Comments','','R');return
    document.MM_returnValue">
    <input type=hidden name="print_blank_fields"
    value="1">
    <table>
    <tr>
    <th width="197" align="right">
    Name: </th>
    <td colspan="3">
    <input name="Name" type="text" size="30" />
    </td>
    </tr>
    <tr>
    <th align="right">
    Street Address: </th>
    <td colspan="3">
    <input type="text" name="Street_Address" size="30" />
    </td>
    </tr>
    <tr>
    <th align="right">
    City: </th>
    <td colspan="3">
    <input type="text" name="City" size="30" />
    </td>
    </tr>
    <tr>
    <th align="right">
    State: </th>
    <td width="27">
    <input name="State" type="text" size="4" maxlength="2"
    /> </td>
    <td width="115"> </td>
    <td width="131"> </td>
    </tr>
    <tr>
    <th align="right">
    Zip: </th>
    <td colspan="3">
    <input name="Zip" type="text" size="12" maxlength="10"
    /> </td>
    </tr>
    <tr>
    <th align="right">
    Phone: </th>
    <td colspan="3">
    <input name="Phone" type="text"
    onblur="MM_changeProp('Phone','','value','','INPUT/TEXT')"
    value="(xxx) xxx-xxxx" size="30" /> </td>
    </tr>
    <tr>
    <th align="right">
    Email: </th>
    <td colspan="3">
    <input name="Email" type="text" size="30" maxlength="35"
    /> </td>
    </tr>
    <tr>
    <th height="40" align="right" valign="top"
    nowrap="nowrap">
    Questions or Comments: </th>
    <td colspan="3">
    <textarea name="Questions_or_Comments" cols="40"
    rows="5"></textarea> </td>
    </tr>
    <tr>
    <th align="right" nowrap="nowrap"> Preferred Contact:
    </th>
    <td colspan="3"><input type="radio"
    name="Preferred_Contact_Method" value="Phone" checked="checked"
    class="checkbox" />
    Phone
    <input type="radio" name="Preferred_Contact_Method"
    value="Email" class="checkbox" />
    Email </td>
    </tr>
    <tr>
    <th align="right" nowrap="nowrap">
    Best Time to Reach You: </th>
    <td colspan="3">
    <input name="Best_Time_to_Reach_You" type="text"
    value="daytime or evening?" size="30" /> </td>
    </tr>
    <tr>
    <th></th>
    <td colspan="3"><input type="submit"
    name="Form_Submit" value="Submit Form" />
    <input name="Form_Reset" type="reset" value="Reset Form"
    /></td>
    </tr>
    <tr>
    <th></th>
    <td colspan="3"> </td>
    </tr>
    </table>
    <input type="hidden" name="_vDeckformid" value="567" />
    </form>

    doh!
    I am truly a nincompoop...it was in the utility provided by
    my web hosting company...nevermind!!!

  • BCD_FIELD_OVERFLOW  error while assigning value to dynamic work area

    Hi guys,
                I am trying following code --it uses dynamic table concept.
           LABSTD2 TYPE P DECIMALS  1,
           LABST_2 TYPE P DECIMALS   1,
           LABST_12 TYPE P DECIMALS 1,
           T_ARTMAS-LABST_12 = T_ARTMAS-LABSTD1 + T_ARTMAS-LABSTD2.
           ASSIGN COMPONENT 'LABST_12' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
           <DYN_FIELD> = T_ARTMAS-LABST_12.
    Value in T_ARTMAS-LABST_12 in debug was 14690.0....still it gave following error-----
    Runtime Error       BCD_FIELD_OVERFLOW
    Except.                CX_SY_CONVERSION_OVERFLOW
    Even i changed decleartion as follows
    LABST_12 TYPE P lenght 10 DECIMALS 1,
    Still it is giving same problem ...
    Kindly help.

    Hi, I think it has nothing to do with an overflow but something with the code. Try this simple (rather stupied) code:
    TYPES: BEGIN OF ty_line,
            fld1      TYPE p DECIMALS 1,
            fld2      TYPE p DECIMALS 1,
            fld3      TYPE p DECIMALS 1,
          END OF ty_line.
    DATA lv_rec       TYPE ty_line.
    DATA lv_count(1)  TYPE n.
    DATA lv_fld1      TYPE p DECIMALS 1.
    DATA lv_fld2      TYPE p DECIMALS 1.
    DATA lv_fld3      TYPE p DECIMALS 1.
    DATA lv_field     TYPE string.
    FIELD-SYMBOLS: <fs_fld> TYPE any.
    BREAK-POINT.
    lv_fld1 = 15211444 / 10.
    lv_fld2 = 54879072 / 10.
    lv_fld3 = lv_fld1 + lv_fld2.
    DO 3 TIMES.
      lv_count = lv_count + 1.
      CLEAR lv_field.
      CONCATENATE 'lv_rec-fld' lv_count INTO lv_field.
      CONDENSE lv_field NO-GAPS.
      ASSIGN (lv_field) TO <fs_fld>.
      <fs_fld> = lv_fld3.
    ENDDO.
    BREAK-POINT.
    Succes.

  • Dynamically stating the field name in the WHERE clause

    Hello All,
    Consider the following select statement.
    SELECT kunnr INTO TABLE gt_kunnr
          FROM kna1
          FOR ALL ENTRIES IN gt_table
          WHERE kunnr = gt_table-<b>cust_id</b>.
    Suppose there is a case where I do not know the name of the internal table field
    (say, "cust_id" in the above case) with which comparison is to be done in the WHERE clause. Only at runtime that fieldname is available. So in the WHERE clause can I mention it dynamically?
    I tried using the following.
    lv_fieldname =  'cust_id'.
    SELECT kunnr INTO TABLE gt_kunnr
          FROM kna1
          FOR ALL ENTRIES IN gt_table
          WHERE kunnr = gt_table-<b>(lv_fieldname).</b>
    But this is  giving a syntax error.
    Could anyone suggest an alternate approach?
    Regards
    Indrajit.

    Hi,
    It is fine with Enterprise version but when I am trying to run the following code in Rel 4.6C, I am getting a syntax error.
    TYPES: BEGIN OF ty_wherecond,
             data(72) TYPE c,
           END OF ty_wherecond.
    DATA: gt_itab1 TYPE STANDARD TABLE OF kna1,
          gt_itab2 TYPE STANDARD TABLE OF kna1.
    DATA:  BEGIN OF gt_kunnr OCCURS 0,
                kunnr TYPE kunnr,
           END OF gt_kunnr.
    PERFORM fill_itabs TABLES gt_itab1
                              gt_itab2.
    *&      Form  fill_itabs
          text
         -->P_T_TABLE  text
    FORM fill_itabs  TABLES   p_t_table
                              pt_table_dummy.
      DATA: lv_fieldname(30)   TYPE c VALUE 'pt_table_dummy-kunnr'.
      DATA: lt_wherecond   TYPE STANDARD TABLE OF ty_wherecond,
            lt_condtab     TYPE STANDARD TABLE OF hrcond,
            ls_condtab     TYPE hrcond.
      FIELD-SYMBOLS <fs_wherecond> TYPE ty_wherecond.
      pt_table_dummy[] = p_t_table[].
      CLEAR ls_condtab.
      REFRESH: lt_wherecond[],
               lt_condtab[].
      ls_condtab-field = 'KUNNR'.
      ls_condtab-opera = 'EQ'.
      ls_condtab-low   = lv_fieldname.
      APPEND ls_condtab TO lt_condtab.
      CALL FUNCTION 'RH_DYNAMIC_WHERE_BUILD'
        EXPORTING
          dbtable         = space " can be empty
        TABLES
          condtab         = lt_condtab
          where_clause    = lt_wherecond
        EXCEPTIONS
          empty_condtab   = 01
          no_db_field     = 02
          unknown_db      = 03
          wrong_condition = 04.
      LOOP AT lt_wherecond ASSIGNING <fs_wherecond>.
        REPLACE '''' WITH '' INTO <fs_wherecond>-data.
        REPLACE '''' WITH '' INTO <fs_wherecond>-data.
      ENDLOOP.
      SELECT kunnr INTO TABLE gt_kunnr
          FROM kna1
          FOR ALL ENTRIES IN pt_table_dummy
          WHERE (lt_wherecond).
      IF sy-subrc EQ 0.
      ENDIF.
    ENDFORM.                    "fill_itabs
    The syntax error says "The WHERE condition does not refer to the FOR ALL ENTRIES table".
    Even after using the FM 'RH_DYNAMIC_WHERE_BUILD' as suggested by you, the syntax error is coming.
    Could you please suggest how to ignore this?
    Regards
    Indrajit.

  • Modify dynamic internal table from dynamic work area using index...

    ASSIGN w_text TO <fs>.
        ASSIGN w_temp TO <fs1>.
        lint_tab_iw49[] = <tab>.
        lint_tab_iw49_t[] = <tab>.
        DELETE ADJACENT DUPLICATES FROM lint_tab_iw49 COMPARING aufnr.
        LOOP AT lint_tab_iw49 INTO lws_tab_iw49.
          READ TABLE lint_object_tab1 INTO lws_object_tab1
                        WITH KEY aufnr = lws_tab_iw49-aufnr.
          IF sy-subrc EQ 0.
    Collect operations in rows of an internal table.
            w_idx = 1.
            WHILE w_idx < 51.
              w_nn = w_idx.
              CONCATENATE 'lws_object_tab1-ZZOPERN' w_nn INTO w_xx.
              ASSIGN (w_xx) TO <fs>.
              CONCATENATE w_text <fs> INTO w_text SEPARATED BY ','.
              w_idx = w_idx + 1.
            ENDWHILE.
    Split operations into an internal table to get operations in rows.
            SPLIT w_text AT ',' INTO TABLE lint_vornr.
            DELETE lint_vornr WHERE vornr = ' '.
            DESCRIBE TABLE lint_vornr LINES w_lines.
    Collect costs in rows of an internal table
            CLEAR: w_idx, w_nn, w_xx, w_text.
            w_idx = 1.
            WHILE w_idx < 51.
              w_nn = w_idx.
              CONCATENATE 'lws_object_tab1-ZZCOST' w_nn INTO w_xx.
              ASSIGN (w_xx) TO <fs>.
              <fs1> = <fs>.
              CONCATENATE w_text <fs1> INTO w_text SEPARATED BY ','.
              w_idx = w_idx + 1.
            ENDWHILE.
    Split costs into an internal table to get costs in rows.
            SPLIT w_text AT ',' INTO TABLE lint_escost.
            DELETE lint_escost WHERE cost = ' '.
            DESCRIBE TABLE lint_escost LINES w_lines_cost.
           Append lines of lint_escost from 1 to w_lines to lint_escost1.
    Collect currencies in rows of an internal table
            CLEAR: w_idx, w_nn, w_xx, w_text.
            w_idx = 1.
            WHILE w_idx < 51.
              w_nn = w_idx.
              CONCATENATE 'lws_object_tab1-ZZCURR' w_nn INTO w_xx.
              ASSIGN (w_xx) TO <fs>.
              <fs1> = <fs>.
              CONCATENATE w_text <fs1> INTO w_text SEPARATED BY ','.
              w_idx = w_idx + 1.
            ENDWHILE.
    Split costs into an internal table to get costs in rows.
            SPLIT w_text AT ',' INTO TABLE lint_curr.
            DELETE lint_curr WHERE curr = ' '.
            DESCRIBE TABLE lint_curr LINES w_lines_curr.
           Append lines of lint_curr from 1 to w_lines to lint_curr1.
          ENDIF.
          PERFORM update_object_tab_for_iw49n.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " modify_object_tab
    *&      Form  update_object_tab_for_IW49N
          text
    -->  p1        text
    <--  p2        text
    FORM update_object_tab_for_iw49n .
      DATA: lws_temp TYPE string VALUE 'where aufnr = lws_tab_iw49-aufnr',
            lw_index TYPE sy-index.
      READ TABLE <tab> TRANSPORTING NO FIELDS WITH KEY ('AUFNR') =
      lws_tab_iw49-aufnr.
      IF sy-subrc EQ 0.
        lw_index = sy-tabix.
        LOOP AT <tab> INTO <wa1> FROM lw_index.
          IF <wa1>-aufnr NE lws_tab_iw49-aufnr.
            EXIT.
          ELSE.
            CLEAR lw_index.
           lw_index = sy-tabix.
            lw_index = 1.
            WHILE lw_index LE w_lines.
              READ TABLE lint_escost INTO lws_escost INDEX lw_index.
              IF sy-subrc EQ 0.
             lw_index = lw_index + 1.
                <wa1>-zzcost1 = lws_escost-cost.
              ENDIF.
              READ TABLE lint_curr1 INTO lws_curr INDEX lw_index.
              IF sy-subrc EQ 0.
                <wa1>-zzcurr1 = lws_curr-curr.
              ENDIF.
              MODIFY <tab> FROM <wa1> "TRANSPORTING ('ZZCOST1') ('ZZCURR1')
                        INDEX sy-tabix.
              IF sy-subrc EQ 0.
              ENDIF.
              lw_index = lw_index + 1.
            ENDWHILE.
          ENDIF.
        ENDLOOP.
      ENDIF. 
    ENDFORM.                    " update_object
    Hi,
    With referene to the code snippet above I want to modify <tab> from <wa1> on specific indices or with specific where condition.
    Is it achievable... How?
    Many thanks in advance.
    Thanks & Regards,
    Shreya

    You might have to split the code in to two parts to keep the formatting intact.

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

Maybe you are looking for