Insert New Record in Master Data by Code

Hi guys,
I need to insert a new value in an infoobject by code creating:
1 new record in table P (data not time dependent)
1 new record in table S (SID table)
This code could be executed by many tasks in parallel and so it could create problems of concurrency in writing and in quality of the value of new SID selected.
The first question is:
THERE IS A STANDARD CODE THAT INSERT A NEW RECORD ALSO CREATING SIDS, managing concurrency in writing and reading?
The second (if not answer to first)
This is a part of my code (draft)... any suggestions:
insert into TABLE P
INSERT INTO /bic/pzck9idfl VALUES st_p_zck9idfl.
IF sy-subrc = 0.
FLAG = 1.
WHILE FLAG = 0.
    SELECT MAX( sid )
    INTO v_sididfl
    FROM /bic/szck9idfl.
    ADD 1 TO v_sid.
*record for SID table
    st_zck9idfl-sid = v_sid.
    st_zck9idfl-/bic/zck9idfl = v_idfl.
    st_zck9idfl-chckfl = 'X'.
    st_zck9idfl-datafl = 'X'.
    st_zck9idfl-incfl  = 'X'.
insert record in SID Table
    INSERT INTO /bic/szck9idfl VALUES st_zck9idfl.
    COMMIT WORK AND WAIT.
IF Sy-subrc = 0.
SELECT SINGLE FROM /bic/szck9idfl
WHERE SID = v_SID
AND /bic/zck9idfl NE v_idfl.
IF Sy-SUBRC = 0.
FLAG = 1.
ELSE.
FLAG = 0.
ENDIF.
ELSE FLAG = 1.
ENDIF.
ENDWHILE.
Thanks and points to helpful answer!
ciao
C@f

Hi Claudio,
I would not recommend to do this. Please have a look for standard fm to that job of have a look into the class library to find some methods. On the first look at your code here my comments:
SELECT MAX( sid )
INTO v_sididfl
FROM /bic/szck9idfl.
ADD 1 TO v_sid.
Not a pretty good idea, as there is a number range object for getting a sid for each infoobject. If you get your sid like this, all later standard postings will fail with 'duplicate records'.
*record for SID table
st_zck9idfl-sid = v_sid.
st_zck9idfl-/bic/zck9idfl = v_idfl.
st_zck9idfl-chckfl = 'X'.
st_zck9idfl-datafl = 'X'.
st_zck9idfl-incfl = 'X'.
if you mark all these flags with 'X' you will tell the system that this record is used somewhere in masterdata or in a datatarget and you cannot delete it with standard methods.
regards
Siggi

Similar Messages

  • How to insert  new records in Master and detail Forms.

    Hi,
    I am having trouble inserting values in both master and detail view at the same time. The scenarios is I have a Dept Table (View Object-VO1) and Employee Table(View Object -VO2) both linked with a foreign key, as per Default HR schema in Oracle DB XE.
    Now I want to insert new record in both Dept(VO1) and EMP(VO2) table via a New page say ( Page2 ). There is a button on Page1 with button INSERT .I can only drag-drop "CreateInsert" operation on that button for VO1 or VO2. So only text box for Dept records are enable to insert data but not Emp records. Is there a way I can insert data in both the tables at the sametime??
    Thanks,
    MB

    Hi MuradRabbani,
    You can programmatically call both createInsert Operations,
    Add to your pageDef both CreateInsert Operations.
    Create a button tha will call insert method from Master (VO1) and then call insert method for Detail (VO2)
    Here is an Example code of calling the operations:
    DCBindingContainer dcb = ADFUtils.getDCBindingContainer(); //you need ADFUtils.java and JSFUtils.java classes. You can find them in the sample applications in your JDeveloper.
    OperationBinding oper = dcb.getOperationBinding("CreateInsertVO1");
    oper.execute();
    -----------------NOTE: at this point you should have set values that compine the ViewLink on the master in order the detail will know where to link the new record there are many ways to do it.
    As an approach try to overrdi the create Method on the in the ViewRowImpl of your Master vo (VO1)
    e.g.
    @Override
    protected void create(AttributeList attributeList) {
    //before
    attributeList.setAttribute("NameOfAttribute", valueHere);
    super.create(attributeList);
    After that you should call the operation for your detail VO2
    e.g.
    DCBindingContainer dcb = ADFUtils.getDCBindingContainer();
    OperationBinding oper = dcb.getOperationBinding("CreateInsertVO2");
    oper.execute();
    The detail record will now have the values from your master automatically.
    Regards,
    Dimitris.

  • Problem with inserting new records in Oracle Forms

    Hi Friends,
    I am a new user to Oracle Forms and I need a help from you people. The problem is as follows:
    I have a data block in which I can display a number of records. In this data block the user will be able to edit the fields if no child records are found in another table. I have used when-new-record-instance to attain this scenario. All are text items. One item licensee_id which is made invisible by setting the property in property palette and required=no ( as this is the primary key of the table). Also the audit columns are made invisible.
    The code for it is as follows:
    DECLARE
         v_alert_button NUMBER;
         v_cnt                          NUMBER;
    BEGIN
         SELECT COUNT (*)
    INTO v_cnt
    FROM id_rev_contracts
    WHERE licensee_id = :ID_REV_LICENSEES.licensee_id;
    IF v_cnt > 0 THEN
    set_item_property('ID_REV_LICENSEES.LICENSEE_NAME', UPDATE_ALLOWED, PROPERTY_FALSE);
    ELSE
         set_item_property('ID_REV_LICENSEES.LICENSEE_NAME', UPDATE_ALLOWED, PROPERTY_TRUE);
         -- set_item_property('ID_REV_LICENSEES.LICENSEE_NAME', INSERT_ALLOWED, PROPERTY_TRUE);
    END IF;
    END;
    Now in this data block I should also be able to insert new records and for the same I have used PRE-INSERT trigger and the code for it is as follows:
    DECLARE
         v_alert_button NUMBER;
    CURSOR v_licensee_id IS SELECT id_rev_licensees_s.NEXTVAL FROM dual;
    BEGIN
    OPEN v_licensee_id;
    FETCH v_licensee_id INTO :id_rev_licensees.licensee_id;
    CLOSE v_licensee_id;
    IF :id_rev_licensees.licensee_id IS NULL THEN
    Message('Error Generating Next v_licensee_id');
    RAISE Form_Trigger_Failure;
    END IF;
    :ID_REV_LICENSEES.created_by := :GLOBAL.g_login_name;
    :ID_REV_LICENSEES.last_updated_by := :GLOBAL.g_login_name;
    :ID_REV_LICENSEES.create_date := SYSDATE;
    :ID_REV_LICENSEES.last_update_date := SYSDATE;
    EXCEPTION
    WHEN form_trigger_failure
    THEN
    RAISE form_trigger_failure;
    WHEN OTHERS
    THEN
    v_alert_button :=
    msgbox ('ERROR in Pre-Insert - ' || SQLERRM, 'STOP', 'Contact IST');
    RAISE form_trigger_failure;
    END;
    Every thing is compiling fine but at the run time when I am trying to insert a new record I am receiving the following error:
    FRM-40508:ORACLE error:unable to insert record
    I also think the pre-insert record is not firing at the time of inserting a new record and saving it. So I request you to please delve into this problem and suggest me how to overcome this problem. Code snippets would do more help for me. If you need any other things from me please let me know. I will see if I could be of any help in that concern because I may not be able to send the entire form as it is.
    Thanks and regards,
    Vamsi K Gummadi.

    first of all
    pre-insert fires after the implicit/explicit commit/commit_form is issued and before the real insert is submitted to the db.
    i would suggest to remove the error handling part for the moment
    because i believe you might be getting "ora-xxxx cannot insert null"
    and also make visible the primary column to check if the pre-insert is executed.
    it would be better to make visible for a while the not null columns of the table/block
    i suppose that the block is insert allowed and you are using table as the source of the block and not any procedures or something...

  • Urgent help : how when insert new record navigation off

    hi master
    Sir
    when i insert new record by mistake press down key and curser move to next record and my need is
    When I insert new record or change any record that time my form navigation musht be off and no move to next record how I restrict to navigation please give me idea which event and what code I use
    Thanking you
    aamir

    If u want the cursor not to move ahead from a particular field when the records are inserted or updated on that field then u can just write null to the
    key-next-item trigger of that particular item.
    ie IN key-next-item
    null;
    Hope this is what you wanted.

  • Inserting new records into database table at runtime

    Hi all ,
    How to insert new records into database table at runtime on click update?
    Thanks.

    Hi Sasikala,
    Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:
    1) Obtain the reference of your context node.
    2) Fetch all the data present in your table into an internal table using methods of if_wd_context_node
    3) Use your normal ABAP logic to update the database table with the data from your internal table
    In my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.
    data: node_sflight           type ref to if_wd_context_node,
            elem_sflight           type ref to if_wd_context_element,
            lt_elements            type WDR_CONTEXT_ELEMENT_SET,
           stru_sflight           type if_main=>element_sflight_node,
           it_flights             type if_main=>elements_sflight_node.
    "   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
        node_sflight_node = wd_context->get_child_node( name = 'SFLIGHT_NODE'  ).
       lt_elements = node_sflight->get_elements( ).
    "   Get all the rows from the table for saving on to the database
        loop at lt_elements into elem_sflight.
          elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
          append stru_sflight to it_flights.
        endloop.
    " Finally save the entries on to the database
        modify ZSFLIGHT99 from table it_flights.
        if sy-subrc eq 0.
    endif.
    However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|modify the data base table which is comming dynamiclly;.
    Regards,
    Uday

  • How to check the records in Master Data Table?

    Hi,
       I am trying to load the Master Data Table using the Flat File.Now how to check the records in Master Data Table?
    I done the following way:
    Info Provider->Info Object->Right Click->Display Data or Maintain Master Data
    But it's not showing the records.It's asking like CID from......To......
                                                                        CID(SID)from.............To.......
                                                                         here CID means customer id(characteristic).
    and showing some settings.
    Please guide me.
    Thanks & Regards

    Hi Sri,
    Go to T- code RSD1 and type your info object name and open the P- table in the infoobject then select execute symbol to see the updated  data in to master data info object.
    regards
    sap

  • Settings for update/insert new records

    Hi everybody,
    I'm at the beggining of learning the OWB in order to create a Data Warehouse environment.
    I have successfully created a table in the target schema , which is a match of columns found in 4 tables in the source schema.
    Which settings(steps) are necessary in order to update some records according to the update done in 4 tables in source schema , which have already been inserted in the table in target schema- using the execute pop-up menu command?
    Additionally , how can I insert only the new records to the target schema by using the execute command in pop-up menu ...
    Thanks , a lot
    Simon

    Hi Simon,
    If you have constraints set on your target table, and the operator properties are set to "Match by Constraints = All Constraints", then the process recognizes automatically when to update which fields and when to insert new records.
    If you have no constraints on your target then the operator properties are set to"Match by Constraints = No Constraints", and in this case you should set the Loading properties for each attribute (Field) in the target table.
    Greetings,
    Ilona Tielke

  • Fm to create, modify delimit the records in master data for org mag

    hi,
        There is a fm hr_infotype_operation to create, modify, delimit the records for one infotype of pernrs.
    Like this I want fm through which i can create, modify the records to master data of organisational management (OM). Whatever the infotype i will enter in that fm and data it will create a new record in OM master data. 
              If anybody know this, please tell me.
    thanks & regards,
        Sekhar.

    Hi,
    Try RH_UPDATE_INFTY.
    RH_INSERT_INFTY.
    RH_DELETE_INFTY.
    Regards,
    Dilek

  • Receiver JDBC: Error while doing the Deleting and Inserting new records

    Hi All,
              I am doing Idoc to JDBC scenario. In this I am collecting & bundling different type of Idocs and then sending to the JDBC receiver. My requirement is to delete the existing records in the database and insert the new records. I have configures as mentioned in the link
    Re: Combining DELETE and INSERT statements in JDBC receiver
    In the above link its shows for single mapping. In my scenario I am using multi mapping for collecting idocs in BPM. If I configured for normal mapping then it is working fine(Deleting existing records and Inserting new record). Whenever I am using multi mapping then I am getting following error in the receiver JDBC communication channel u201CError while parsing or executing XML-SQL document: Error processing request in sax parser: No 'action' attribute found in XML document (attribute "action" missing or wrong XML structure)u201D . Can you please tell me what might be the problem.
    Thanks & Regards,
    T.Purushotham

    Hi !
    check this out:
    JDBC - No 'action' attribute found in XML document - error
    JDBC receiver adapter: No 'action' attribute found in XML document
    It appears that the inbound payload (the one that is going from XI to the JDBC adapter) does not have the requiered tag to specify which SQL action to execute in the receiver system. Maybe the multimapping is not creating the desired output message format.
    Regards,
    Matias.

  • How do I insert new record and get results on a landing page

    how do I insert new record and get results on a landing page

    It's not clear from your post what you are asking. In a SQL database, you use the INSERT statement to insert a row into a table. You use the SELECT statement to retrieve rows. Here's some basic info on how to do that within PHP
    PHP MySQL Insert Into
    PHP MySQL Select

  • Duplicate records In Master Data

    Hi,
    I don't understant why we get Duplicate records in Master Data though it has got the overwritten functionality..
       Any idea will be appreciated..

    Hi,
    <u>Solution:</u> if the load to master data fails due to duplicate records,
    Goto Monitor screen --> in the details tab --> under processeing find the duplicate record --> on the context menu of the error record select 'Manual update'.
    After the above step is done....trigger the attribute change run for that infoobject.
    This should solve your problem.
    if there is any problem in the reporting, select the data using filter option on the master data.
    Regards,
    Vijay.

  • Duplicate records in master data infoobject...how to delete it...pls help

    hi all,
    how to delete duplicate records in master data infoobject which has no requests because it is a direct update?

    Hi,
    Right click on the info object and
    select Maintain
    in that you will get the Master data table
    from that select the Record and delete it.
    hope this solves your query.
    reward points if useful
    regards,
    ANJI

  • How to insert new record into altered table

    I am using JDBC with MySQL. I altered existing table and want to insert new record using java class. But it is not possible.How to do?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • Duplicate records during master data loading.

    hello guys,
    I am reading one blog where the blogger wrote about 'Various issues in a BW Production project'.....I came across one issue which I couldnot understand...
    Data loading failed due to Duplicate records during master data loading.......
    Why do this error occur?How can we rectify this in a production environment?
    Thanks and Regards,
    S

    Hi SChandx200 ,
          May I ask where you get "Various issues in a BW production project"?
    Many Thanks,

  • Insert new row to master - detail form using bindingsource

    Hi all,
    I have a form to analyse price of product, the form include master (textbox:slip ID,datetimepicker : date) and detail(datagridview:slipID,productID,price..)
    When I insert new row as below code, all inserted to DB but not show on form, I must close and reopen the form the new row will show, how i must to do to fix it 
    please help, thanks
    Select data when form load 
    ds = New DataSet
    damaster = New SqlDataAdapter("select soPTG,ngaybd,ngaykt,khoa = case when sttesign =0 then 'True' else 'False' end from tbl_PTGMaster", conn)
    damaster.Fill(ds, "tbl_ptgMaster")
    dadet = New SqlDataAdapter("select [SoPTG],[Mahang],[gianhap],[thuesuat],[laigop],[giacu],[giamoi] from tbl_PTGDetail", conn)
    dadet.Fill(ds, "tbl_ptgdetail")
    ds.Relations.Add("PTG_rel", ds.Tables("tbl_ptgmaster").Columns("SoPTG"), ds.Tables("tbl_ptgdetail").Columns("SoPTG")).ChildKeyConstraint.UpdateRule = Rule.Cascade
    BindingMaster.DataSource = ds
    BindingMaster.DataMember = "tbl_ptgmaster"
    BindingDetail.DataSource = BindingMaster
    BindingDetail.DataMember = "PTG_rel"
    gridchitiet.DataMember = "tbl_ptgdetail"
    txtptgnumb.DataBindings.Add("text", BindingMaster, "soPTG")
    dtstart.DataBindings.Add("Text", BindingMaster, "ngaybd")
    dtend.DataBindings.Add("Text", BindingMaster, "ngaykt")
    cmdlock.DataBinding.Add("Enabled", BindingMaster, "khoa", True, DataSourceUpdateMode.OnPropertyChanged)
    setStatus()
    SetHeader()
    Dim cmdinsert As New SqlCommand("insert into tbl_PTGMaster(SoPTG,ngaybd,ngaykt) values(@SoPTG,@ngaybd,@ngaykt)", conn)
    cmdinsert.Parameters.Add("@soPTG", SqlDbType.Char, 10).Value = txtptgnumb.Text
    cmdinsert.Parameters.Add("@ngaybd", SqlDbType.DateTime).Value = dtstart.Value
    cmdinsert.Parameters.Add("@ngaykt", SqlDbType.DateTime).Value = dtend.Value
    damaster.InsertCommand = cmdinsert
    damaster.FillSchema(ds, SchemaType.Source)
    cmdinsert = New SqlCommand("insert into tbl_PTGDetail(SoPTG,mahang,gianhap) values(@SoPTG,@mahang,@gianhap)", conn)
    cmdinsert.Parameters.Add("@SoPTG", SqlDbType.Char, 10).Value = txtptgnumb.Text
    cmdinsert.Parameters("@SoPTG").Direction = ParameterDirection.InputOutput
    cmdinsert.Parameters.Add("@mahang", SqlDbType.Char, 10, "mahang")
    cmdinsert.Parameters.Add("@gianhap", SqlDbType.Decimal, 8, "gianhap")
    dadet.InsertCommand = cmdinsert
    dadet.FillSchema(ds, SchemaType.Source)
    gridchitiet.FinishEditing()
    BindingMaster.EndEdit()
    damaster.Update(ds, "tbl_PTGMaster")
    ds.Tables("tbl_PTGMaster").AcceptChanges()
    BindingDetail.EndEdit()
    dadet.Update(ds, "tbl_PTGDetail")
    ds.Tables("tbl_PTGDetail").AcceptChanges()
    BindingMaster.ResetBindings(False)
    BindingDetail.ResetBindings(False)

    Hello,
    The base idea here is if the record is added successfully you would then get the new primary key then manually add the record to the underlying data source. Does not matter if we are talking a single table or a master-detail setup.
    The following shows the basics
    https://code.msdn.microsoft.com/Adding-new-records-into-bff5eaaf 
    All of the above is done without using a DataSet yet the same thing needs to happen with a DataSet, simply focus on the one table.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

Maybe you are looking for

  • HT1349 My Ipod wont open any of my apps, help!

    So when i tried to use my ipod today, it wouldnt open mostly all of my apps. It would open a few. I connected it to my sisters computer yesterday to charge, but she has an Iphone with an Itunes account on her computer, and it gave me all of her apps.

  • File encoding question

    Just attempting to open some file and read it to screen with BufferedReader and no encoding is handled anywhere... I tried to save an html file to .txt and just use that as a test file, but yeah encoding was different from ???(the standard encoding I

  • Attachement linked to purchase order

    I want to know where the attachements linked to purchase order are getting stored in SAP.Since the attachement are linked to purchase order(header level) ,is it possible to link those attachements at item level so when we select a particular item  an

  • All dates of BOM change

    Hello! I'm writing a function that is searching for parts of a model in the BOM. I'm saving the result to a buffer table, so I need to find all dates of BOM change (at all levels). For example: 01.06.2006 -> BOM created 07.06.2006 -> material A added

  • TS1392 11.0.2 has lost visibility to Apple TV despite pingable and youtube, trailers playable on Apple TV

    Since upgrading to 11.0.2 iTunes my Windows XP PC has lost all viisbility of my Apple TV Gen 1 I have tried all troubleshooting steps and no success. The Apple TV (Gen 1) still have full network access, can get TV or film trailers, search YouTube and