Updating Primary key while creating entries

Hi All,
I have a requirement to update a primary key while the entry is being created in the database table.
The program uses the INSERT statement to create entries but the primary key is unknown at that time. I want to create this primary key value and update that record before being saved in the database.
Is there a place where i can write this code which gets called while INSERT/UPDATE statements.
Request you urgent help.
Thanks in advance

Hello Archana,
As per my understanding providing BADI implementation is one of the better options you have.
Firstly you have to find out the standard BADI Definition provided by SAP for your functionality. You can search the same in the transaction <b>SE18</b>.
Your BADI definition will have predefined interface methods
(like BEFORE_SAVE, AFTER_SAVE, BEFORE_UPDATE, AFTER_UPDATE ... )
with necessary parameters(parameter types: IMPORTING/EXPORTING/CHANGING/RETURNING). Mind you, you can't add your own methods/parameters to these standard BADI definitions.
Now you can create your own BADI implementation(ie., you can write you code in the one of the predefined methods you have) for the standard BADI definition. For that in your BADI Definition screen go to <i>Implementation</i> in Menu bar and click on <i>Create</i>.
I hope you will definitely have <b>Primary Key</b> as importing parameter so you can write your code logic by using this primary key in one of the methods you have based on your requirement
<b>@</b> Please take Backend expert help in your team for finding out BADI Definition Name & for also BADI Implementation Code if you are not sure about BADI concept.
I hope this answers your question, If YES,  !!! REWARD POINTS !!!
Regards, Srikanth

Similar Messages

  • Checking the initiality of the fields while creating  entries for a table

    While creating entries using table maintenance generator(TMG) i need to check the initiality of the fields.Are there any such events?
    I know i can go and change in the screen by making it mandatory or by writing a module in the PAI of the screen of table maintenance generator. Both of cases i have to change the TMG which is generated by SAP system. I want to know is there a way to achieve this with out changing the TMG possible events?

    hi rahul,
    as far as i know, you have to do your initial valifdation in TMG and you have to change your TMG. However, if you have checked the initial flag while defining the field, you will not have initial value for that particular field.... (if the field is key field, by default it is not initial)
    hope this helps....
    thanks and regards,
    tanmaya

  • How to update primary key column

    Hi,
    Can you suggest me best workaround/algorithm for below task:
    (Oracle 10g, Solaris OS.)
    Situation:
    Table P has primary key column "Code", child tables F1, F2, ..., F15 reference with foreign key column "P_Code" column "P.Code", and we don't know which of the child tables has data for particular "P.Code" value.
    Task:
    Change "P.Code" value from 100 to 200. So that result would be that record P[Code = 100] should be updated as:
    update P set
    Code = 200
    where Code = 100;And child tables column "P_Code" should be updated as:
    update F1, F2, .., F15 set
    P_code = 200
    where P_code = 100;The best solution would be that one very easily can repeat that task.
    Edited by: CharlesRoos on 28.12.2010 12:10

    If you are looking for reusable and repetitive solution, then may be...
    SQL> CREATE TABLE p (p_code NUMBER PRIMARY KEY);
    Table created.
    SQL> INSERT INTO p VALUES(100);
    1 row created.
    SQL> INSERT INTO p VALUES(300);
    1 row created.
    SQL> INSERT INTO p VALUES(500);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> CREATE TABLE F1 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> CREATE TABLE F2 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> CREATE TABLE F3 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> INSERT INTO F1 VALUES(100);
    1 row created.
    SQL> INSERT INTO F3 VALUES(100);
    1 row created.
    SQL> INSERT INTO F2 VALUES(500);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> CREATE OR REPLACE PROCEDURE update_child_parent(pi_p_code_old NUMBER,
      2                                                  pi_p_code_new NUMBER) IS
      3    CURSOR table_to_update IS
      4      SELECT table_name,
      5             to_number(extractvalue(xmltype(DBMS_XMLGEN.getxml('SELECT count(*) c FROM ' ||
      6                                                               table_name ||
      7                                                               ' WHERE p_code=' ||
      8                                                               pi_p_code_old)),
      9                                    '/ROWSET/ROW/C')) cnt
    10        FROM user_tables
    11       WHERE table_name IN ('F1', 'F2', 'F3');
    12 
    13  BEGIN
    14    EXECUTE IMMEDIATE 'ALTER TABLE p DISABLE PRIMARY KEY CASCADE';
    15    UPDATE p SET p_code = pi_p_code_new WHERE p_code = pi_p_code_old;
    16    FOR i IN table_to_update LOOP
    17      IF i.cnt > 0 THEN
    18        EXECUTE IMMEDIATE 'UPDATE ' || i.table_name || ' SET p_code=' ||
    19                          pi_p_code_new || ' WHERE p_code=' || pi_p_code_old;
    20      END IF;
    21    END LOOP;
    22    EXECUTE IMMEDIATE 'ALTER TABLE p ENABLE VALIDATE PRIMARY KEY';
    23  END update_child_parent;
    24  /
    Procedure created.
    SQL> EXECUTE update_child_parent(100,200);
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM p;
        P_CODE
           200
           300
           500
    SQL> SELECT * FROM F1;
        P_CODE
           200
    SQL> SELECT * FROM F2;
        P_CODE
           500
    SQL> SELECT * FROM F3;
        P_CODE
           200
    SQL> INSERT INTO p VALUES(300);
    INSERT INTO p VALUES(300)
    ERROR at line 1:
    ORA-00001: unique constraint (HR.SYS_C005931) violated
    SQL> EXECUTE update_child_parent(500,900);
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM p;
        P_CODE
           200
           300
           900
    SQL>  SELECT * FROM F2;
        P_CODE
           900
    SQL>

  • Update primary key in replication environment.

    Hello all,
    I would appreciate, if you could answer for my question.
    I am using oracle9i advanced asynchronous replication. What would be the issue if we update the primary key. Is it going to create any problem ?. What is the drawback on updating Primary key.
    Thanks
    Govind

    Are you using DDL propagartion?
    You should not have any problems if you have unconditional supplement logging for all columns.
    But, probably it is good idea to do it in this way:
    1 stop capture
    2 change session tag
    3. change table defenition on both sides
    4. enable capture.
    5. perform capture checkpoint right after step 4.
    Regards,
    Sergey

  • Update primary key/delete and reinsert records

    Hi, I have been told to update some fields. The database is new to me, and now I see the field is the primary key (and it has child tables with that as foreign key). The person who told me isn't reachable until next week...
    ...wasn't a bad idea to update pk's? I see it's possible, deferring constraints...
    update primary key
    Re: Update Primary Key
    ...but it's better/safer the script deletes and later re-insert the records, right?
    Thanks

    Always is better be able to undo any change .
    But ¡, why would you update pk's? it's possible but you colud find few problems like:
    - many levels of foreign keys exists.
    - not validate pk
    Look at:
    Re: Novalidate primary key

  • Use multiple primary keys to create DB constraint

    Hi,
    Is it possible to have multiple primary keys within one EJB to create a DB including the constraints, if so how? Is there an example of this or any example which uses multiple primary keys to create a DB?
    Thanks,
    Maarten

    "Is it possible to have multiple primary keys within one EJB..."
    If you mean a composite key, yes. Your PrimaryKeyObject would have one attribute for each column that makes up your composite key. If that's not what you meant, please clarify.
    "...to create a DB including the constraints"
    Not sure what you mean here. Constraints are enforced by the DB, and you don't create databases with EntityBeans.

  • Problem with a primary key when creating a new record in Forms

    My table has a field - MDD_KEY - that is a primary key. It is updated from a sequence with a before-insert database trigger. I know this works properly as the primary key was accurately populated when I inserted 1433 records.
    In Forms 6, I have a form based on that table. I have set the mdd_key as a hidden field because I assume it will be entered by the before-insert trigger. However, when I enter data into the table, and then try to save it, I get a FRM-40202: Field must be entered. - followed by - FRM-40222: Disabled item MDD_KEY failed validation.
    If I set DATA Required to no, when I try to save I get an FRM-40600: Record has already been inserted - but no such record exists in the database. I know this record is unique and does NOT exist because I deliberately made it up.
    In the property palatte, the attributes of the field are:
    DATA Data Type Number
    Required Yes
    DATABASE Database Item Yes
    Primary Key Yes
    Query Only No
    Query Allowed Yes
    Query Length 0
    Insert Allowed Yes
    Update Allowed Yes
    Update Only if Null No
    Lock Record No
    I assume that my problem is that with a new record, the form wants to see the MDD_KEY populated before it saves - but that isn't going to happen until the before insert trigger fires in the database. I assume I have to populate that field within forms, but how do I do that without messing up the database trigger/sequence? I will have to load more data directly into the database - so I need the database trigger in place.
    I have not used primary keys before so I am more than a little bit confused about how and when it should be populated when a new record is created in Forms.
    Any help would be appreciated as I cannot enter new data into my form (works well with existing data).
    Thanks
    Glenn

    hi
    if u have any problem using seq then try that statemetn ur block level in ur form
    PRE-INSERT trigger
    select nvl(max(nvl(srno,0)),0)+1 into :srno from tablename;
    Rizwan

  • Primary key allows duplicate entry in data dictionary

    Hi Friends,
                     I have created table to save contact details. here i have assigned USERID and CELL_NO as primary key but when i am trying to create new entry it allows duplicate value. How can i prevent this ?
    Please review my attached image for more details.
    Thank you Friends.

    Hi Karthi,
                  I think table logic is correct. it mean if you entered both primary key same only it wont allow but here you mentioned same cell no but different ID so it will accepts.
    E.g
         cell no 1234
         user id  xxx
         cell no 1234
        user  id xxx
    above logic wont allows
    but you mentioned
    cell no 1234
    user id xxx
    cell no 1234
    user id xyz
    if you need to remove duplicates mean you should maintain primary key as cell no only not both..
    revert back if you didnt get clear.
    Regards,
       Thangam.P

  • Tabular Form Page - Insert and Update Primary Key

    Hi -
    I am creating a Tabular Form page which will display 2 columns:
    CODE (Text Field), DESCRIPTION(Field)
    The *'CODE'* is a primary key to the table/view and *'DESCRIPTION'* is the corresponding detail information for the *'CODE'*.
    I am trying to create an updateable report on this page which will show these columns and when a user wants to add a new row,they should be able to add a new row with CODE='somecode' and DESCRIPTION='description' but shouldn't be able to update (but should be displayed) the *'CODE'* value once inserted into the table or view.
    Is there a way to do that? Please share your expertise.
    Thanks,
    -Seenu

    I't a bit unclear what you want.
    In your first post it seems that you don't want the user to change the PK.
    In your second post the user can change the PK, but you get a db error.
    Anyway, I guess you don't want the user to change the PK.
    I have a few support tables, which are the source for some LOV's.
    For those I also add records with a manual assigned PK, rather then via a sequence, just to improve consistency across applications.
    The data is protected by foreign keys to the main tables.
    You could further add a trigger to your table which throws an error the moment it detects a change on your PK.

  • Updating primary key with jdbc

    Trying to update a primary key with:
    public static void updateTAXID(String coid,String accountnumber,String oldTAXID,String fundname,String newTAXID){ Properties props = TradeHelper.loadProperties(); Connection conn = null; PreparedStatement st = null; String sql ="update FinancialAccount set taxid=? " + "where dealernumber=? and " + "taxid=? and " + "fundname=? and " + "accountnumber=?"; try{ Class.forName(props.getProperty("driver")); conn = DriverManager.getConnection(props.getProperty("brokerageurl"), props.getProperty("user"),props.getProperty("password")); st = conn.prepareStatement(sql); st.setString(1, newTAXID); st.setString(2, coid); st.setString(3, oldTAXID); st.setString(4, fundname); st.setString(5, accountnumber); st.executeUpdate(); System.out.println("Update: new tx:"+newTAXID+":"+"Ol tx: "+oldTAXID+" act:"+accountnumber); conn.close(); st.close(); }catch(Exception e){ e.printStackTrace(); } }
    I keep getting this error:
    com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '02673025561-QA-SLFCA-' for key 'PRIMARY'         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)         at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)         at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)         at com.mysql.jdbc.PreparedStatement.exe
    Am I not able to update a single field of a composit key with jdbc? Whay is my update failing telling that there is a duplicate when I am trying to update?

    iketurner wrote:
    I keep getting this error:
    com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '02673025561-QA-SLFCA-' for key 'PRIMARY'
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
    at com.mysql.jdbc.PreparedStatement.exeAm I not able to update a single field of a composit key with jdbc? Whay is my update failing telling that there is a duplicate when I am trying to update?If you take the error message at its word then the problem is not that you are not permitted to update a primary key but that the values you are trying to use is already in use.
    I'll leave it you DBA and/or Data Modeler/Architech to decide if it is a good idea to update the value or not.

  • Update primary key

    Hi
    I am using weblogic 7.0 and ejb 2.0
    I have a requirement where i would want to update my primary key. If i understand right , In ejb you are not allowed to update one of the primary key column of composite primary key.
    Now if i have to update this what are the work arounds. Aslo say if i update that row through stored proc, will my ejb state in cache be in sync with latest data. Is ejb load called for sure beofre any method is called on bean.
    Please give me some inputs on this
    Thanks

    Your problem lies within your database (datasource)structure. You need to have two primary keys for that particular entity. The first primay key is internal meaning it is the true key for any specific record in the table. The second "primary key" is external meaning it is not truely a primary key with regards to the formal contstraints of your database. Instead, this is the key your users will see. It is the responsibilty of the application layer to ensure that the external id is unique. This way, you always have a lasting primary key (the internal key), yet your users can change their "primary key" whenever they like.
    As an example, I'm writing a J2EE application that provides our clients with a unique ID to access their records. My table definition would look something like:
    CREATE TABLE Client (
    clientId BIGINT AUTO_INCREMENT NOT NULL,
    externalClientId VARCHAR(15) UNIQUE NOT NULL,
    ... another field,
    ... another field,
    CONSTRAINT pk_foo PRIMARY KEY (clientId)
    The unique constraint isn't really necessary because the application layer should check for this, but it's a good safety precaution.
    On the application side, you would only expose the 'externalClientId' to the clients. This might force you to use BMP, but it keeps the user from ever changing the true Id and is fairly clean.
    Hope this helps.

  • What is the diffrence  between "Key to Select" and "Selected Key" while creating Radio  Buttons?

    While creating radio buttons there is a confusion regarding two properties "Key to Select" and "Selected Key".Can anybody explain it with example?
    Thanks,
    Vimal

    Hi Vimal,
    Please find my explanation as below
    Key to Select: This is the unique key for each radio button to identify which one is selected
    Selected Key: This holds the "KEY" of selected radio button
    Example:
       Let us say we have 2 radio buttons : Male & Female
         Create a context attribute SELECTED_KEY of type STRING.
         Create an action ON_SELECT for radio button select event
         Now,
         the properties for "MALE" radio button as below
              KEY_TO_SELECT = 'M'
              SELECTED_KEY = "bind to the context attribute SELECTED_KEY
              OnSelect = 'ON_SELECT'.
         The properties for 'Female" radio button as below
              KEY_TO_SELECT = 'F'
              SELECTED_KEY = "bind to the context attribute SELECTED_KEY
              OnSelect = 'ON_SELECT'.
    If we select radio button 'Male', we get the key as 'M' and for 'Female' radio button 'F'.
    check inside the event handler method ONACTIONON_SELECT, you get the 'KEY' of selected radio button.
    So, the context attribute 'SELECTED_KEY'  gets filled with the key of selected radio button
    Hope this helps you in distinguishing the 'KEY TO SELECT' & 'SELECTED KEY' .
    Regards,
    Rama

  • Primary Key in Create as Select

    In Oracle, how do we specify a primary key in a create as select statement? I ran a simple statement but received the ORA-00933 error. Do I have to make it two steps with table created first and do alter table to add the key?
    Thanks,
    CREATE TABLE Test as
    SELECT
    FROM Source a
    WHERE a.sys=100
    CONSTRAINT PK1 PRIMARY KEY (AccountID)

    Do I have to make it two steps with table created first and do alter table to add the key? Only if you wish to use the * notation. If you're prepared to specify the columns you can do it in a single step.
    SQL> create table my_emp
      2      (empno constraint myemp_pk primary key
      3      , ename
      4      , sal)
      5  as select empno
      6      , ename
      7      , sal
      8  from
      9  emp
    10  /
    Table created.
    SQL> select * from my_emp
      2  /
         EMPNO ENAME             SAL
          7369 CLARKE            800
          7499 VAN WIJK         1600
          7521 PADFIELD         1250
          7566 ROBERTSON        2975
          7654 BILLINGTON       1250
          7698 SPENCER          2850
          7782 BOEHMER          2450
          7788 RIGBY            3000
          7839 SCHNEIDER        5000
          7844 CAVE             1500
          7876 KULASH           1100
          7900 HALL              950
          7902 GASPAROTTO       3000
          7934 KISHORE          1300
    14 rows selected.
    SQL>Cheers, APC
    blog: http://radiofreetooting.blogspot.com
    Edited by: APC on Apr 9, 2009 1:55 PM
    Forgot to include the CTAS statement. Doh!

  • Update mode options while creating info package

    Hi all .
        while creating info package in update tab  we have different radio buttons as
       FULL UPDATE,DELTA UPDATE,INTIALIZE DELTA PROCESS. could you pls explain this optons.
    Thanks in advance.
    Cheers,
    sami.

    Hi Sami,
    We have two update modes 1)Full update 2)Init Load(to enable delta)
    Full Load --->Master data Load
    Init Load----->Transaction data Load.
    Full Update-To load Historical Data.
    Init-This is done to enable the Delta Upload.
    Delta will be done only if the Init has happened.
    For deltas they are Data source specific which are delta enabled.
    1. Full Load (Extracts whole data available in source)
    2. Initialization (without data transfer): Enables only delta and no data.
    3. Initialization with data: Extracts whole data from source and enables delta.
    4. Delta: Extracts only modified or new data.
    Above modes works for Master as well as Transaction also.
    For further information check this link:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/80/1a65dce07211d2acb80000e829fbfe/frameset.htm
    Cheers,
    Tanish.

  • Who can I update primary key field in master block

    Hi,
    I want to update the primary key field in master block when there are some records are present in detail block, when I edit the primary key filed there is an error FRM-40509 unable to update record. The primary key is also referred by the detail table.
    So kindly give me the solution who can I update the primary key in master block when there is child records exists in detail block?.
    Best regard,
    shahzad

    pls tell us a little more about, why you want to update a PK in a master block.
    I haven't done that my whole time. Maybe you need something different.
    The problem is, that your child-data references to the master-pk, so there is the point you have to go deep into the codings. But better don't do it. Tell us first why. I think there are other solutions for that.
    try it
    Gerd

Maybe you are looking for