Dynamic field name in an assignment statement

Greetings,
Is it possible to make the field name of an assignment dynamic?
For example if I have two text fields called P1_F1 and P1_F2. Is it possible to
do something like this?
declare
X number := 0;
begin
X := 1;
:P1_F || X   = 'value1';
X := 2;
:P1_F || X   = 'value2';
end;Any suggestions would be appreciated.
Thanks
Larry

Use the <tt>apex_util.set_session_state</tt> API method.

Similar Messages

  • Dynamic field names in internal operations

    Dear experts,
    I have a period range in selection screen (peri_from and peri_to); I have to work on an internal table (defined like COSP) where I have amount1 amount2...amount16, in other words one field for each period...
    I have to sum up only amounts within the period range as in selection screen...
    How can I do this dynamic summation ?
    Example:
    peri_from = 004
    peri_to = 006
    Then my code must calculate:
    result = amount4 + amount5 + amount6.
    Thanks in advance for any useful suggestion (field symbol ?)
    Bye,
    Roberto

    Hi roberto,
    1. We have to use
       a) field-symbols
       b) dynamic variable name (for field1,field2)
    2. Just as u want.
       (just copy paste)
    3. It will ask
        a) from , to
        b) print the sum
    4.
    report abc.
    DATA : AMOUNT1 TYPE I,
           AMOUNT2 TYPE I,
           AMOUNT3 TYPE I,
           AMOUNT4 TYPE I,
           AMOUNT5 TYPE I.
    DATA : VARNAME(30) TYPE C.
    FIELD-SYMBOLS : <fs>.
    DATA : CTR TYPE I.
    DATA : CTRC(2) TYPE C.
    DATA : TOT TYPE I.
    PARAMETERS : MYFROM TYPE I DEFAULT 2.
    PARAMETERS : MYTO TYPE I DEFAULT 5.
    start of selection
    START-OF-SELECTION.
      AMOUNT1 = 1.
      AMOUNT2 = 2.
      AMOUNT3 = 3.
      AMOUNT4 = 4.
      AMOUNT5 = 5.
      CTR = MYFROM - 1.
      DO.
        CTR = CTR + 1.
        IF CTR > MYTO.
          EXIT.
        ENDIF.
        CTRC = CTR.
        CONCATENATE 'AMOUNT' CTRC INTO VARNAME.
        ASSIGN (VARNAME) TO <FS>.
        TOT = TOT + <FS>.
        WRITE :/ <FS>.
      ENDDO.
    WRITE TOTAL
    WRITE :/ TOT.
    regards,
    amit m.

  • Dynamic field names in ALV (referencing to the month)

    Hi,
    I have 12 fields in my ALV, named Monthly Sales 1, Monthly Sales 2 and so on until Monthly Sales 12.
    Monthly Sales 12 corresponds to the current month and Monthly Sales 1 is the current month minus 11 months (in terms of the month.)
    So the user has requested that instead of Monthly Sales 12, it should display M 06/2007 as the field name.
    Or Monthly Sales 11 should display M 05/2007 and so on.
    How can this be done?
    Please help.
    Points will be awarded and all responses will be greatly appreciated.
    Thanks,
    John

    Hi,
    I have done some coding for this which is as follows:
    TYPE-POOLS : abap, slis.
    DATA : BEGIN OF itab OCCURS 0,
            month1 TYPE char2,
            month2 TYPE char2,
            month3 TYPE char2,
            month4 TYPE char2,
            month5 TYPE char2,
            month6 TYPE char2,
            month7 TYPE char2,
            month8 TYPE char2,
            month9 TYPE char2,
            month10 TYPE char2,
            month11 TYPE char2,
            month12 TYPE char2,
            month13 TYPE char2,
           END OF itab.
    DATA wa LIKE LINE OF itab.
    DATA : it_fieldcat     TYPE     slis_t_fieldcat_alv WITH HEADER LINE.
    DATA : is_layout     TYPE     slis_layout_alv.
    DATA : len TYPE i VALUE 0,
            text TYPE string,
            date TYPE sy-datum,
            index TYPE numc3.
    DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
    DATA : l_t_fields TYPE abap_compdescr_tab.
    DATA : fs_fields  TYPE abap_compdescr.
    *To get the fields of internal table
    ref_table_des ?=
            cl_abap_typedescr=>describe_by_data( wa ).
    APPEND LINES OF ref_table_des->components TO l_t_fields.
    DESCRIBE TABLE l_t_fields LINES len.
    DO len TIMES.
      index = sy-index - 1.
      CLEAR date.
      READ TABLE l_t_fields INTO fs_fields INDEX sy-index.
      CALL FUNCTION 'CCM_GO_BACK_MONTHS'
        EXPORTING
          currdate   = sy-datum
          backmonths = index
        IMPORTING
          newdate    = date.
      CONCATENATE date4(2) date0(4) INTO text SEPARATED BY '/'.
      it_fieldcat-fieldname = fs_fields-name.
      it_fieldcat-tabname = 'ITAB'.
      it_fieldcat-seltext_l = text.
      APPEND it_fieldcat.
    ENDDO.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        it_fieldcat   = it_fieldcat[]
      TABLES
        t_outtab      = itab[]
      EXCEPTIONS
        program_error = 1
        OTHERS        = 2.
    I feel this is bit generic.
    Copy & execute this program.
    Reward if its useful.
    Regards,
    Sail

  • Accessing dynamic field names?

    I want to be able to create text fields with unique names and
    set values in them within a For-loop without having to reference
    the field names in the code.
    Consider the following code snippet:
    this.createTextField("field" + i, this.getNextHighestDepth(),
    x1, y1, 250, 20);
    It places a text field into a movie clip with name that is a
    composite of a literal value and a variable value resulting in
    names like field1, field2, etc. My question: Is there anyway to use
    a composite field name to access the field properties? For example:
    Can I set the text for the field using the same composite name
    without having to express it as a literal field name? If I can't
    then what is the point of having the composite name capability?

    You can drop the last question because the answer to the
    prior one(s) is "yes".
    this["field"+i].text = "whatever";
    the bracket notation causes a string to be evaluated as an
    object/instance.

  • Create dynamic field names

    I'm creating a PDF form using iText which takes information from a webpage which has multiple order entries. On my PDF i need to loop through this list and create individual PdfFormFields. The problem is I do not know how many items are ordered. How can I create different form fields?
    i.e.
    for(int i=0; i<orderVector.size(); i++) {
    PdfFormField qty = text.getTextField();
    // each time it loops i need qty to be a different name like qty1, qty2....
    // how do I accomplish this?
    Thanks for you help.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    How can I create different form fields?You can't dynamically set variable names. But the good news is that you don't
    have to.PdfFormField[] qtyArr = new PdfFormField[orderVector.size()];
    for(int i = 0; i < orderVector.size(); i++) {
        qtyArr[i] = text.getTextField();
    }This creates just the right number of form fields, referred to as qtyArr[0], qtyArr[1], etc.
    Is there some reason why you are using Vector and not ArrayList?

  • Create Dynamic table name in the select statement.

    I use oracle reports 6i to make myrep.rdf , this report created using certain select query Q1, I created a formula column in this report,
    in the formula column  I write pl/sql block statements to select the data from certain table depends on the output of a column in Q1,
    I want to make the pl/sql block dynamically enough to change the user which I select the data from depends on the connected user
    Ex: if I connected with user = 'KAM14'
    the pl/sql block will be
    select x into v_value from kam13.bil_file where .....;
    and if  I connected with user = 'KAM13'
    the pl/sql block will be
    select x into v_value from kam12.bil_file where .....;
    and so on
    how can I do this in the pl/sql block ...
    Thanks in Advance.

    I am not sure I understood properly, but I think you should create bil_file table under a different user and create synonyms  under KAM1x users.
    Regards

  • Dynamic column name for Oracle Server Procedure

    hello,
    May be it's not a right place for my question, but I hope that some of you can help me.
    I have source table A that has data of the same kind in 62 fields, let's say employee count for 62 departments. I do some processing with these counts(sum(emp_count) of the same departments for different locations) and store these counts in the variables EC1, EC2, EC3 .. EC62.
    Then I need to insert them into my table that has very simple structure let's say table B (dept_no Number(3),
    emp_count Number(6))
    I want to do a loop and use dynamic colunm EMP_COUNT, something like this:
    FOR k in 1..62 LOOP
    EMP_COUNT := 'EC'&#0124; &#0124;k;
    IF EMP_COUNT <> O THEN
    insert into B
    VALUES ( K , EMP_COUNT);
    END IF;
    END LOOP;
    I understand that I need to take a Value of my dynamic colunm EMP_COUNT. Is it possible to do in Oracle Server Procedure? Any idea?
    Any help will be apreciated.
    null

    After having worked in other environments where you can manipulate data records with postitional parameters, Oracle can be frustrating because it demands the explicit use of field names in DML/Select statements. A way around this is to use DBMS_SQL or Dynamic Sql. I have used DBMS_SQL to create and execute dynamic statements with great success. Since you are creating, compiling, and running a dynamic block every time you execute your procedure, this is not recommended except in the rare instances when there is no better way around it.
    Oracle8i introduces native dynamic SQL, an alternative to DBMS_SQL. Using native dynamic SQL, you can place dynamic SQL statements directly into PL/SQL blocks.
    In most situations, native dynamic SQL can replace DBMS_SQL. Native dynamic SQL is easier to use and performs better than DBMS_SQL.
    Example of Dynamic SQL<------------------------
    BEGIN
    -- bulk fetch the list of office locations
    SELECT location BULK COLLECT INTO loc_array
    FROM offices;
    -- for each location, give a raise to employees with the given 'job'
    FOR i IN loc_array.first..loc_array.last LOOP
    dml_str := 'UPDATE emp_' &#0124; &#0124; loc_array(i)
    &#0124; &#0124; ' SET sal = sal * (1+(:raise_percent/100))'
    &#0124; &#0124; ' WHERE job = :job_title';
    EXECUTE IMMEDIATE dml_str USING raise_percent, job;
    END LOOP;
    Look for more information on dynamic SQL by
    searching for DBMS_SQL.
    Good Luck
    null

  • Materialized view with dynamic column names !

    hello,
    i need some help , i'm trying ( i got no where so far :) ) to create a materialized
    view that has dynamic field name values , so every time the view is refreshed
    the fields are renamed.
    i have been asked to create a decade summary view and to assign year values to field names,the years should be table columns ( not rows !? ) and thus i should reflect this fact to the column names.
    i know its a wierd request but is there anway to do it ?
    i dunno about it at least,
    Thanks !

    ...or you could define the materialised view neutrally e.g. with columns like YEAR1, YEAR2 etc.
    Then create a dynamically-defined view on top of this view, after it's refreshed, using the relevant years as column names. SELECT year1 AS "1991", year2 AS "1992" etc.
    I still don't see how anybody is going to use these views as they won't know what the "year" columns are called.
    And if the same materialised view is going to have different sets of data each time it's refreshed i.e. different sets of years, are you re-defining the selection criteria each time? If so, why not just define separate views?
    It's a weird world out there...

  • BAPI Structure populating using field name and field value frm internal tbl

    Hi Experts,
                     Need your help, my requirement is to populate BAPI import structure using its field name and filed value  stored in a internal table.  Please advise the best approach.
    Regards
    Ram.

    Hi, in an ABAP program you can make use of FIELD-SYMBOLS and the ASSIGN statement for filling the BAPI fields based on the fieldname found in the internal table. Hopes it answer your question. Succes

  • Can't I use Field NE SPACE in READ statement ?

    What is wrong with the below statments 
    READ TABLE t_zdadp_rpt WITH TABLE KEY t_zdadp_rpt-zdesc NE SPACE.
       READ TABLE t_zdadp WITH TABLE KEY zdesc NE SPACE.
    Could you pleae help

    Hi,
    In the first statement u have to specify only field name also in read statement no need for table key its just key..U cannot use NE symbol for read statement.
    READ TABLE t_zdadp_rpt WITH TABLE KEY t_zdadp_rpt-zdesc NE SPACE.
    READ TABLE t_zdadp WITH TABLE KEY zdesc NE SPACE.
    plz correct the code like this
    READ TABLE t_zdadp WITH  KEY zdesc Eq SPACE.
    if sy-subrc ne 0.
    do what ever u want.
    endif.
    reward if helpful.
    Regards,
    nagaraj

  • Dynamic Column name in a Cursor

    Hello there,
    How can I access data in cursor's field with dynamic fields names, more illustration follows:
    My table has columns named as C1,C2,C3 so on
    defined a cursor cursor_name on that table,
    I need to access the fields by a loop like this:
    OPEN cursor_name;
    Fetch cursor_name into rec;
    for i in 1 .. 10 loop
    if rec.ci = 1Then
    end if;
    end loop
    close cursor_name;
    where rec,ci represents the name of the cursor fields, so that I loop over them,
    how can I implement such an idea,
    thanks in advance
    regards

    Thanks Bily, and user10715047,
    actually the reason behind the need of such an approach, is as following:
    assume that I have table of set of logical conditions, " LOGICAL CONDITIONS" has three columns: ID, Condition_name and the logical_condition, example:
    1, c1,  x = 1
    5, c2,  y = 2
    10, c3, p = 3 where ID is just a sequence to identify the records from each other "primary key"
    assume that I need to provide the possible combination of the result of applying each of the conditions, for example :
    if c1 = 1 ,c2= 0 and c3= 1 then  my result must be 1 ' This according some predefined rulesso that I created table which contains all the possible logical conditions, ( as the max number of logical conditions are known)
    defined as follows : combination( combination_ID, c1, c2, c3, c4, ....cmax, result)
    sample record:
    combination_ID, c1,  c2, c3, .. c max, result
              100,   1,    0,   1, ....., 1, 1in the PL/SQL procedure, I would get all the needed combination, into a cursor, then to optimized the code, I need to access the fields ( which is the Ci) in a loop
    for i in 1..3 loop
    if cursor_rec.ci = 1 then
    Action
    end if;
    end loop;the dynamic name I meant in my first post was this : cursor_rec.ci ,
    so that I can access the cursor's fields without the need to name them one by one, as there could be long sequence of conditions to be checked.
    hope that I made the idea clearer, Any suggestions, please !
    anyway I will give the DBMS_SQL cursors a shot , try if I can use to implement the purpose,
    as I know similar dynamical variable names, is available in Java,
    Regards,

  • Hash in database field name

    I have a field name that has a hash (#) symbol in the name. I
    have no control over the naming structure of this particular
    database. I need to output this field. How the heck do I do this? I
    know how if the output has a # in it, but what about the actual
    field name?
    Thanks,

    Your best bet is to alias the field name in SQL before you
    start dealing with your recordset in CF. You should be able to
    escape the hash using ## instead of #.
    If for some reason you can't alias the field name in your SQL
    statement, you can output query data in the following format:
    QueryName["FieldName"][RowNumber]
    I bet you can do something like this:
    qMyQuery["Hash##Field"][1]

  • 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

  • Dynamic Assign Statement is not working in 4.6C

    Hi Team,
    I have done the following coding to get teh dynamic value sof a field but the assign statement is failing... Its returing the sy-subrc as 4.
    LOOP AT <t_tab> INTO <s_tab>.
        LOOP AT t_flds.
          CONCATENATE '<s_tab>-' t_flds-fieldname INTO v_fldval.
          ASSIGN (v_fldval) TO <fldval>.
         endloop
       endloop.
    Appericiate your suggestions.
    Thnx,
    Ankur..

    Hi Ankur,
    I am facing the same problem.........wit no solution in hand, cud u plz let me knw if u have got some solution over this.....
    The problem occurs, maybe because the internal table field symbol <t_tab> (and hence <s_tab>) does not contain the fieldname for which u r tryin to get the value in <v_fldval>
    Is there a way to chk if a particular fieldname exists in the <t_tab>, so tht if v dont get it, we wud avoid the ASSIGN statement, so tht v dont get a dump
    Appreciate ur inputs.....
    Regards,
    Aparna.

  • Is it possible to store a field name in a variable, then assign it a value?

    Good day, everyone!
    I am working on a program in which there are many different amount fields in which an amount may be assigned.  For reusability purposes, I was wondering if it would be possible to write a routine that identifies the target amount field, stores it in a variable that is passed back to the calling program, and then assigns a value to it.  There may be different structures having the same field name; what I'm trying to do is avoid having to code a huge IF or CASE statement for each structure.  For example:
    Structures S1, S2, and S3 have some fields identically named.  Call one of them F1.
    What I'd like to do is call a routine that identifies "F1" as my target field to populate.  Then, upon return, I can assign it to the desired structure.  Kinda like this:
    S1-fieldname = 24.17.  (but fieldname isn't a true field in the structure -- it would hold the value of the true field, "F1").
    I realize this might not even be possible, but given how talented the folks are on this forum, I thought I should at least pose the question.
    As always, points given for all helpful answers, and thank you!!
    Dave

    Ok.  I gave that a shot, but what happens is that my ASSIGN COMPONENT statement doesn't work.  It gets a sy-subrc of 4, and <column> remains unassigned.  The program then abends on the line to assign <a1>-trbtr's value to the field because of <column> being unassigned.
      DATA:
        w_setname         TYPE setleaf-setname,
        w_column_name(20) TYPE c.
        ASSIGN COMPONENT w_column_name OF STRUCTURE wa_expense_ng_report
                      TO <column>.
        <column> = <a1>-trbtr.
    Any thoughts on what I might be doing wrong?

Maybe you are looking for