Fire trigger once when inserting 50 rows

Is there a way to fire a trigger once after inserting several rows in a table within a single transaction.
I dont want the overhead of firing the trigger for each row.

Here is something dirty, but works!
Works with regular inserts.
SQL> select * from emp1;
no rows selected
SQL> create or replace package emp1_pkg as
  2  v_emp_inserts number := 0;
  3  end emp1_pkg;
  4  /
Package created.
SQL> create or replace trigger emp1_tgr
  2  before insert
  3  on emp1
  4  begin
  5       emp1_pkg.v_emp_inserts := emp1_pkg.v_emp_inserts + 1;
  6       if emp1_pkg.v_emp_inserts > 5 then
  7          dbms_output.put_line ('Trigger fired');
  8          emp1_pkg.v_emp_inserts := 0;
  9       end if;
10  end;
11  /
Trigger created.
SQL> set serveroutput on
SQL> insert into emp1 values ('a', 1);
1 row created.
SQL> insert into emp1 values ('b', 2);
1 row created.
SQL> insert into emp1 values ('c', 3);
1 row created.
SQL> insert into emp1 values ('d', 4);
1 row created.
SQL> insert into emp1 values ('e', 5);
1 row created.
SQL> insert into emp1 values ('f', 6);
Trigger fired
1 row created.
SQL> insert into emp1 values ('g', 7);
1 row created.
SQL> select * from emp1;
ENAME            ENUM
a                   1
b                   2
c                   3
d                   4
e                   5
f                   6
g                   7
7 rows selected.

Similar Messages

  • Error: cannot commit (when inserting the row)

    hai,
    I create the trigger like below.
    create or replace trigger proce
    after insert on samp3
    declare
    ass date;
    begin
    select d into ass from samp3;
    updatecourse(ass);
    end;
    when I try to insert the row then the error is come;
    ERROR at line 1:
    ORA-20001: An error was encountered - -4092 -ERROR- ORA-04092: cannot COMMIT in a trigger
    ORA-06512: at "AUROLIVE.UPDATECOURSE", line 22
    ORA-06512: at "AUROLIVE.PROCE", line 5
    ORA-04088: error during execution of trigger 'AUROLIVE.PROCE'
    can any one help me?
    Regards,
    Ramya.S

    If u want to put commit on trigger use pragma
    autonomous_transaction.what it does,it leave the main
    transaction and commit the second transaction.Which can lead to logic problems and corruption of your business data if not used extremely carefully.
    If you start transaction 1 and during that write some other data as transaction 2 using autonomous transactions and then subsequently find that there is an error or some reason not to commit transaction 1 then you cannot automatically roll back transaction 2 and would have to take care of it manually.
    I see too many occurences of developers using autonomous transaction all over the place just because they want to get the data written to the database and then they're wondering why there is so much clutter in their data and the database integrity is poor from a business/logical point of view. The first thing any good design includes is a knowledge of the business transactions and when data should be committed and what the implications of using autonomous transactions are.

  • Insert 50 rows, fire trigger once

    Is there a way to create a trigger that fires once after several inserts, instead of firing for each inserted row.
    I want the trigger to fire once for a transaction.

    An easier way is to use the after update trigger and leave out the "for each row". The trigger will only fire once for each update statement, even if the statement altered a million rows.

  • How to get custom trigger result when insert

    I set a trigger before insert, if the result was $aa = 50;
    how to get $aa?
    it doesn't work
    $ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", $aa);

    I tried this one, actually, {GLOBALS.variable_name} is one of mark-up language,I add echo $a this time, after submit, $a appear on the page, so I think "definea trigger" has been executed successfully, but still got error message
    <br />
    <br />http://uploads.screenshot-program.com/my.php?image=upl2682569831.jpg
    <br />
    <br />code
    <br />--------------------------------------------------
    <br /><?php require_once('Connections/conndb.php'); ?>
    <br /><?php<br />// Load the common classes<br />require_once('includes/common/KT_common.php');<br /><br />// Load the tNG classes<br />require_once('includes/tng/tNG.inc.php');<br /><br />// Make a transaction dispatcher instance<br />$tNGs = new tNG_dispatcher("");<br /><br />// Make unified connection variable<br />$conn_conndb = new KT_connection($conndb, $database_conndb);<br /><br />//start definea trigger<br />function definea(&$tNG) {<br />global $a;<br />$a = 100;<br />}<br />//end definea trigger<br /><br />// Make an insert transaction instance<br />$ins_testtable = new tNG_insert($conn_conndb);<br />$tNGs->addTransaction($ins_testtable);<br />// Register triggers<br />$ins_testtable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "ins");<br />$ins_testtable->registerTrigger("BEFORE", "definea", 50);<br />// Add columns<br />$ins_testtable->setTable("testtable");<br />$ins_testtable->addColumn("t_name", "STRING_TYPE", "POST", "t_name");<br />$ins_testtable->addColumn("t_num", "NUMERIC_TYPE", "VALUE", "{GLOBALS.a}");<br />$ins_testtable->setPrimaryKey("t_id", "NUMERIC_TYPE");<br /><br />// Execute all the registered transactions<br />$tNGs->executeTransactions();<br /><br />// Get the transaction recordset<br />$rstesttable = $tNGs->getRecordset("testtable");<br />$row_rstesttable = mysql_fetch_assoc($rstesttable);<br />$totalRows_rstesttable = mysql_num_rows($rstesttable);<br />?>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <script src="includes/common/js/base.js" type="text/javascript"></script>
    <br />
    <script src="includes/common/js/utility.js" type="text/javascript"></script>
    <br />
    <script src="includes/skins/style.js" type="text/javascript"></script>
    <br />
    <br />
    <br />
    <br /><?php echo $a; ?>
    <br />
    <form id="form1" name="form1" method="post" action="">
    <br />
    <label for="t_name">tname</label>
    <br />
    <input type="text" name="t_name" id="t_name" />
    <br /> <?php<br /> echo $tNGs->getErrorMsg();<br />?>
    <br />
    <input type="submit" name="ins" id="ins" value="submit" />
    <br /></form>
    <br />
    <br />

  • Problem in trigger when inserting in mtl_transactions_interface there is an added row

    hi,
    i have a problem in the trigger when i have a command of 2 lines and do a reception and insertion in table mtl_transactions_interface i found 3 lines, i didn't know where come the 3 row
    create or replace
    TRIGGER TOP_RCV_TRANSACTION_ACC_T2 AFTER
      INSERT ON PO.RCV_TRANSACTIONS FOR EACH ROW DECLARE
      CURSOR org_item_cur
      IS
        SELECT distinct organization_id,
          inventory_item_id
        FROM mtl_system_items_b
        WHERE inventory_item_id=
          (SELECT distinct item_id
          FROM rcv_shipment_lines
          WHERE shipment_line_id=:new.shipment_line_id
          CURSOR item_cur
          IS
          select distinct  RSL.item_id
    from
      RCV_SHIPMENT_HEADERS RSH
      ,RCV_shipment_lines RSL
      where :new.shipment_header_id=RSH.shipment_header_id
      and RSH.shipment_header_id=RSL.shipment_header_id;
      X_att_item      VARCHAR2(10);
      X__bc_ot        VARCHAR2(10);
      X_sum_qty       NUMBER;
      X_receipt_num   VARCHAR2(30);
      X_count_article NUMBER;
      X_item_org      NUMBER;
      X_org_id        NUMBER;
      X_serial_number NUMBER;
      X_dec_dou varchar2(100);
      X_DAE varchar2(100);
      X_LOCATOR_ID  NUMBER;
      X_ITEM_REVISION varchar2(3);
      X_ITEM_ID NUMBER ;
      X_PO_NUMBER VARCHAR2(20) ;
    BEGIN
    FOR item_rec IN item_cur
          LOOP
      IF (:new.transaction_type='DELIVER' and :new.organization_id=83 and (item_rec.item_id=61305 or item_rec.item_id=61306)) THEN
        SELECT distinct receipt_num
        INTO X_receipt_num
        FROM RCV_SHIPMENT_HEADERS
        WHERE shipment_header_id=:new.shipment_header_id;
    SELECT COUNT(*)
        INTO X_count_article
        FROM mtl_system_items_b
        WHERE inventory_item_id=
          (SELECT distinct item_id
          FROM rcv_shipment_lines
          WHERE shipment_line_id=:new.shipment_line_id
          --récupérer le numéro de commande à partir de la table PO_HEADERS_ALL
        select distinct PHA.segment1 
        into X_PO_NUMBER
        from PO_HEADERS_ALL PHA
        where PHA.PO_HEADER_ID=:new.PO_HEADER_ID;
         -- Récupérer la révision de l'article
          select distinct ITEM_REVISION
          into X_ITEM_REVISION
          from rcv_shipment_lines
          WHERE shipment_line_id=:new.shipment_line_id;
        IF (X_count_article > 1) THEN
          FOR org_item_rec IN org_item_cur
          LOOP
            IF (org_item_rec.organization_id=83 and(org_item_rec.inventory_item_id =61305 or org_item_rec.inventory_item_id =61306) ) THEN
              INSERT into inv.mtl_transactions_interface
                  transaction_interface_id,
                  SOURCE_CODE,
                  SOURCE_LINE_ID,
                  SOURCE_header_ID,
                  PROCESS_FLAG,
                  TRANSACTION_MODE,
                  INVENTORY_ITEM_ID,
                  REVISION,
                  ORGANIZATION_ID,
                  SUBINVENTORY_CODE,
                  TRANSACTION_QUANTITY,
                  TRANSACTION_UOM,
                  TRANSACTION_DATE,
                  TRANSACTION_TYPE_ID,
                  TRANSACTION_REFERENCE,
                  TRANSACTION_COST,
                  LAST_UPDATE_DATE,
                  LAST_UPDATED_BY,
                  CREATION_DATE,
                  CREATED_BY,
                  lock_flag,
                  transaction_source_name,
                  transaction_source_type_id,
                  Flow_Schedule,
                  Scheduled_Flag,
                  distribution_account_id ,
                  LOCATOR_ID
                VALUES
                  mtl_transactions_interface_s.nextval,
                  'INTERFACE',
                  0,
                  0,
                  1,
                  3,
                  org_item_rec.inventory_item_id,
                  X_ITEM_REVISION,
                  161,
                  'CENTRAL001',
                  :new.quantity,
                  :new.uom_code,
                  sysdate,
                  202,
                   X_PO_NUMBER,
                    :new.po_unit_price,
                  sysdate,
                  :new.LAST_UPDATED_BY,
                  sysdate,
                  :new.LAST_UPDATED_BY,
                  2,
                  X_receipt_num,
                  13,
                  'Y',
                  2,
                  347783,
                  :new.attribute1
            END IF;
          END LOOP;
          if org_item_cur%ISOPEN then
            close org_item_cur;
            end if;
    END IF;
      END IF;
       END LOOP;
    END;
    please help me and give me solutions to localisate the problem?

    This trigger will fire at the time of every PO receipt and receiving transactions such as Accept, Reject, Deliver, RTV etc.
    May be you forgot to put a WHEN clause in Trigger.

  • How to Fire Trigger, when changes are applied on destination??

    Hi,
    I want to fire the following trigger at destination, when changes are applied from source table (cms.test_2) to destination table(cms.test_2).
    create or replace trigger Ins_and_upd
    after insert or update of send_status on cms.test_2
    declare
    begin
    update cms.test_2
    set RECEIVE_STATUS = 'YES'
    where UPPER(send_status)=upper('YES');
    end;
    Thanks,
    faziarain

    I am using oracle10g stream replication, and database version is "10.2.0.1.0".
    Basically I have 2 machines named:
    --> Site#1_DB ----> Having Table TEST_2 -----> Columns (BID,DBID,Send_Status,Receive_Status,Final_Status).
    --> Center_DB ----> Having Table TEST_2 -----> Columns (BID,DBID,Send_Status,Receive_Status,Final_Status).
    My Senario example is following:
    At Site#1_DB TEST_2 Table contains the following data:
    TEST_2 is updating and set the YES value in "Send_Status" column, and this change will replicated to Center_DB TEST_2 table.
    BID----------DBID----------Send_Status----------Receive_Status----------Final_Status
    1----------2----------YES----------NULL----------NULL----------NULL
    2----------3----------YES----------NULL----------NULL----------NULL
    3----------4----------YES----------NULL----------NULL----------NULL
    4----------5----------YES----------NULL----------NULL----------NULL
    At Center_DB TEST_2 Table contains:
    In My Senario changes are successfully replicated at Center_DB TEST_2 Table and after replication
    Test_2 table is same on both machines.
    But Now I want to write my given trigger at Center_DB and this trigger will be fired when changes are replicated
    from Site#1_DB to Center_DB.
    BID----------DBID----------Send_Status----------Receive_Status----------Final_Status
    1----------2----------YES----------NULL----------NULL----------NULL
    2----------3----------YES----------NULL----------NULL----------NULL
    3----------4----------YES----------NULL----------NULL----------NULL
    4----------5----------YES----------NULL----------NULL----------NULL
    Output After Firing the trigger at Center_DB:
    BID----------DBID----------Send_Status----------Receive_Status----------Final_Status
    1----------2----------YES----------YES----------NULL----------NULL
    2----------3----------YES----------YES----------NULL----------NULL
    3----------4----------YES----------YES----------NULL----------NULL
    4----------5----------YES----------YES----------NULL----------NULL
    Thanks,
    Faziarain.
    Edited by: [email protected] on Mar 30, 2009 10:00 PM
    Edited by: [email protected] on Mar 30, 2009 10:17 PM
    Edited by: [email protected] on Mar 31, 2009 3:48 AM

  • Generate a surregate key only when insert a new row - (SCD1)

    Hi all,
    I&acute;m starting with OWB (10gR2) and I'm creating a simple template dimension with SDC type 1 with one source, one target and a sequence do generate the surrogate key.
    The main properties configurations are:
    - Target property: Loading type = INSERT/UPDATE.
    - Only match the natural key between source and target.
    - Only use the sequence.nextval when inserting a new row.
    - Mapping: Set based.
    The generated code was something like this:
    {color:#000080}+MERGE INTO DIM_DEFAULT+{color}
    {color:#000080}+USING SCR_TABLE+{color}
    {color:#000080}+ON(SCR_TABLE.NATURALKEY=DIM_DEFAULT.NATURALKEY)+{color}
    {color:#000080}+WHEN MATCHED THEN+{color}
    {color:#000080}+UPDATE SET NAME=SCR_TABLE.NAME+{color}
    {color:#000080}+WHEN NOT MATCHED THEN+{color}
    {color:#000080}+INSERT(SK_DEFAULT,NATURALKEY,NAME)+ {color}
    {color:#000080}+VALUES(SQ_DIM_DEFAULT.NEXTVAL,SCR_TABLE.NATURALKEY,SCR_TABLE.NAME)+{color}
    Ok, it works fine! But the merge statement generates a new SK for each merged row even if the action is update! What I want is a new SK only when the process inserts a new row. Hard-coding, I possible solve this problem creating a function to return the nextval from a sequence and put it on the insert clause like this:
    {color:#000080}+MERGE INTO DIM_DEFAULT+{color}
    {color:#000080}+USING SCR_TABLE+{color}
    {color:#000080}+ON(SCR_TABLE.NATURALKEY=DIM_DEFAULT.NATURALKEY)+{color}
    {color:#000080}+WHEN MATCHED THEN+{color}
    {color:#000080}+UPDATE SET NAME=SCR_TABLE.NAME+{color}
    {color:#000080}+WHEN NOT MATCHED THEN+{color}
    {color:#000080}+INSERT(SK_DEFAULT,NATURALKEY,NAME)+ {color}
    {color:#000080}+VALUES(FN_SQC_NEXTVAL('SQ_DIM_DEFAULT'),SCR_TABLE.NATURALKEY,SCR_TABLE.NAME)+{color}
    Hard-coded it works fine as I need and that&acute;s the point that I want to know:
    It&acute;s possible perform this solution using OWB?
    I tried to use Constants but this solution doesn&acute;t work then I tried an expression calling my sequence.nextval function but the result was:
    {color:#000080}+MERGE INTO DIM_DEFAULT+{color}
    {color:#000080}+USING (SELECT FN_SQC_NEXTVAL('SQ_DIM_DEFAULT') AS SK_DEFAULT_0,NATURALKEY,NAME FROM SCR_TABLE) AS SCR_TABLE+{color}
    {color:#000080}+ON(SCR_TABLE.NATURALKEY=DIM_DEFAULT.NATURALKEY)+{color}
    {color:#000080}+WHEN MATCHED THEN+{color}
    {color:#000080}+UPDATE SET NAME=SCR_TABLE.NAME+{color}
    {color:#000080}+WHEN NOT MATCHED THEN+{color}
    {color:#000080}+INSERT(SK_DEFAULT,NATURALKEY,NAME)+ {color}
    {color:#000080}+VALUES(SK_DEFAULT_0,SCR_TABLE.NATURALKEY,SCR_TABLE.NAME)+{color}
    It&acute;s the same of merge the row using the SEQUENCE.NEXTVAL direct.
    Does anyone have a workaround to solve this situation?

    Hi,
    Perhaps this comes a bit late but...
    Have you tried to change attribute properties in the mapping? For simple example you have a source table in sa-stage which have to fields: code (varchar2(2), natural key) and description (varchar2(50)). You want to map those fields to target table where you have 3 fields: id (NUMBER(10), surrogate id, nextval from sequence when new row inserted), code (as from the source, natural key, the field to determine if the coming row is new or one to be merged) and description as in source table. Fields and datatypes are just for an example.
    When you have source and target tables in your mapping (and fields mapped), drag the sequence operator to the mapping and map the nextval to target table's surrogate id field.
    - Change target table operator properties:
    * loading type = UPDATE/INSERT
    * Match by constraint = no constraint
    - Change target table attribute properties for:
    * surrogate id field: Load column when updating row = no; match column when updating row = no; load column when inserting row = yes
    * natural key field(s): Load column when updating row = no; match column when updating row = yes; load column when inserting row = yes
    * all the regular fields: Load column when updating row = yes; match column when updating row = no; load column when inserting row = yes
    - change the deleting rules as you want them to be
    - Validate your mapping. If the green light is shown, the settings in field properties are suitable for merge.
    Hope this is what you wanted to get. I think this kind of solution works fine. Trigger in the table that holds and where one inserts millions of rows sounds scary...
    Regards,
    jk
    Added text: sorry about false alarm. I think that was what you did. The solution above steals the nextvals from sequence. Perhaps no-native-english-reader should be more careful when reading questions ;-)
    Edited by: jkoski on 5.11.2008 1:30

  • Database trigger to insert duplicated rows on audit table

    Hi
    It is possible to insert duplicate rows (at the moment database generate PK violation constraint for one specific table) within an audit table ?
    Certain code like this is not working, always the whole transaction makes a rollback and audit table will be empty:
    CREATE OR REPLACE TRIGGER USER.audit_TABLE_TRG
    before INSERT ON USER.TABLE
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    declare
    V_conteo number(1) := 0;
    duplicate_record EXCEPTION;
    begin
    select count(*)
    into V_conteo
    from USER.TABLE
    where <PK conditions>
    if V_conteo > 0 then
    begin
    INSERT INTO USER.AUDIT_TABLE
    (<>)
    VALUES
    (<>);
    raise duplicate_record;
    exception
    when duplicate_record then
    INSERT INTO USER.AUDIT_TABLE
    (<>)
    VALUES
    (<>);
    raise_application_error(-20019,'Duplicated column1/column2:'||:NEW.column1||'/'||:NEW.column2);
    when others then
    dbms_output.put_line('Error ...'||sqlerrm);
    end;
    end if;
    end;
    END;
    /

    >
    Exactly this is my problem , one only transaction (insert into audit table and try to insert into target table), the reason of this post is to know whether exists another way to insert all the intent duplicate records on target table into one audit table, you right ,maybe I can add one date column and modify the PK on audit table but my main problem still happens.
    >
    Can I ask you why you want to go trigger route for this if your intention is only to capture the duplicate records? Assuming that you are on at least on 10gR2, you can look at DML error table. If you go this route, there is no need for additional overhead of trigger, code failures, etc.
    Oracle can automatically store the failed records in an error table which you could later on investigate and fix it or ignore it.
    Simple example:
    SQL> create table emp (empno number primary key, ename varchar2(10), sal number);
    Table created.
    SQL> insert into emp values(1010, 'Venkat', 100);
    1 row created.
    SQL> commit;
    Commit complete.
    Create error table to log the failed records
    BEGIN
          DBMS_ERRLOG.create_error_log (dml_table_name => 'emp');
    END;
    Now let's insert a duplicate record
    SQL> insert into emp values(1010, 'John', 200) ;
    insert into emp values(1010, 'John', 200)
    ERROR at line 1:
    ORA-00001: unique constraint (VENKATB.SYS_C002813299) violated
    Now use the log table to capture
    SQL> insert into emp values(1010, 'John', 200) LOG ERRORS INTO err$_emp ('INSERT') REJECT LIMIT UNLIMITED;
    0 rows created.
    Now check the error log table and do whatever you want
    SQL> r
      1* select ORA_ERR_MESG$, empno, ename, sal from err$_EMP
    ORA_ERR_MESG$
    EMPNO
    ENAME
    SAL
    ORA-00001: unique constraint (VENKATB.SYS_C00
    2813467) violated
    1010
    John
    200
    1 row selected.This will also capture when you do
    INSERT INTO EMP SELECT * FROM EMP_STAGE LOG ERRORS INTO err$_emp ('INSERT') REJECT LIMIT UNLIMITED;
    You can capture the whole record into the log table. All columns.
    Regards
    Edited : Code

  • How to insert multiple rows in oracle forms when using TEMPLATE FORM

    I got a case study on PO creation nd in that I have to insert multiple rows in form especally when PO creation screen is there.
    I tried by different syntaxes but its not working.I need correct syntax to insert the multiple rows in to the table in oracle forms

    Please Oracle EBS queries on EBS forums.

  • How to lock a table when i insert a row

    hi, friends,
    how to lock a table when i insert a row, then unlock the table

    If you want to lock the whole table so that no-one else can do DML then you go LOCK TABLE <table> IN EXCLUSIVE MODE. This lock remains in force until you commit or rollback.
    There are less powerful locking modes available, but you can look those up in the OTN online documentation.
    APC

  • Duplicate row added when inserting programticaly

    hi am inserting row programaticaly,this is what i have done create a view with Transient attributes ,the view have two table usertable and organisationuser table,what am doing am inserting username in organisationuser from usertable ,but at the same time trying to display the username details like firstname,surname,email,which am trying to dispaly them through the Transient attributes,but now when i click the add button to add it show like it insert two rows but when i go to datanase it has only insert one row which is correct,am in jdeveloper 11.1.1.6.0
    Edited by: adf009 on 2013/03/01 9:53 AM
    Edited by: adf009 on 2013/03/05 11:02 AM

    hi this is the query am using
    the target VO WHICH I i what to insert values is
    <?xml version="1.0" encoding="windows-1252" ?>
    <!DOCTYPE ViewObject SYSTEM "jbo_03_01.dtd">
    <!---->
    <ViewObject
      xmlns="http://xmlns.oracle.com/bc4j"
      Name="DeltMember"
      Version="11.1.1.61.92"
      InheritPersonalization="true"
      BindingStyle="OracleName"
      CustomQuery="false"
      PageIterMode="Full"
      UseGlueCode="false"
      RowClass=model.UpdOrgDetails.DeltMemberRowImpl"
      ComponentClass=model.UpdOrgDetails.DeltMemberImpl"
      FromList="UAM_ORGANISATION_USER UamOrganisationUser, UAM_USERDETAILS UamUserdetails, UAM_ORGANISATIONS UamOrganisations"
      Where="(UamOrganisationUser.USERNAME = UamUserdetails.USERNAME) AND (UamOrganisationUser.ORGANISATIONID = UamOrganisations.ORGANISATIONID)"
      SelectList="UamOrganisationUser.ORGANISATIONID,
           UamOrganisationUser.USERNAME,
           UamUserdetails.SURNAME,
           UamUserdetails.USERNAME AS USERNAME1,
           UamUserdetails.FIRSTNAME,
           UamUserdetails.EMAILADDRESS,
           UamOrganisations.ORGANISATIONID AS ORGANISATIONID1,
           UamOrganisationUser.CREATED_DATE">
      <DesignTime>
        <Attr Name="_codeGenFlag2" Value="Access|Coll|Prog|VarAccess"/>
        <Attr Name="_isCodegen" Value="true"/>
      </DesignTime>
      <Properties>
        <SchemaBasedProperties>
          <LABEL
            ResId=model.UpdOrgDetails.DeltMember_LABEL"/>
        </SchemaBasedProperties>
      </Properties>
      <EntityUsage
        Name="UamOrganisationUser"
        Entity=model.entities.UamOrganisationUser"/>
      <EntityUsage
        Name="UamUserdetails"
        Entity=model.entities.UamUserdetails"
        Association=model.entities.OrguserlinkUserdetailsFkAssoc"
        AssociationEnd=model.entities.OrguserlinkUserdetailsFkAssoc.UamUserdetails"
        SourceUsage=model.UpdOrgDetails.DeltMember.UamOrganisationUser"
        ReadOnly="true"
        Reference="true"
        DeleteParticipant="false"
        JoinType="INNER JOIN">
        <DesignTime>
          <AttrArray Name="_srcAttributes">
            <Item
              Value=model.entities.UamOrganisationUser.Username"/>
          </AttrArray>
          <AttrArray Name="_dstAttributes">
            <Item
              Value=model.entities.UamUserdetails.Username"/>
          </AttrArray>
        </DesignTime>
      </EntityUsage>
      <EntityUsage
        Name="UamOrganisations"
        Entity=model.entities.UamOrganisations"
        Association=model.entities.OrguserlinkOrganisationsFkAssoc"
        AssociationEnd=model.entities.OrguserlinkOrganisationsFkAssoc.UamOrganisations"
        SourceUsage=model.UpdOrgDetails.DeltMember.UamOrganisationUser"
        ReadOnly="true"
        Reference="true"
        DeleteParticipant="false"
        JoinType="INNER JOIN">
        <DesignTime>
          <AttrArray Name="_srcAttributes">
            <Item
              Value=model.entities.UamOrganisationUser.Organisationid"/>
          </AttrArray>
          <AttrArray Name="_dstAttributes">
            <Item
              Value=model.entities.UamOrganisations.Organisationid"/>
          </AttrArray>
        </DesignTime>
      </EntityUsage>
      <ViewAttribute
        Name="firstnameT"
        IsSelected="false"
        IsPersistent="false"
        PrecisionRule="true"
        Type="java.lang.String"
        ColumnType="VARCHAR2"
        AliasName="VIEW_ATTR"
        SQLType="VARCHAR">
        <RecalcCondition><![CDATA[true]]></RecalcCondition>
        <TransientExpression><![CDATA[Firstname]]></TransientExpression>
        <Dependencies>
          <Item
            Value="Firstname"/>
        </Dependencies>
      </ViewAttribute>
      <ViewAttribute
        Name="SurnameT"
        IsSelected="false"
        IsPersistent="false"
        PrecisionRule="true"
        Type="java.lang.String"
        ColumnType="VARCHAR2"
        AliasName="VIEW_ATTR"
        SQLType="VARCHAR">
        <RecalcCondition><![CDATA[true]]></RecalcCondition>
        <TransientExpression><![CDATA[Surname]]></TransientExpression>
        <Dependencies>
          <Item
            Value="Surname"/>
        </Dependencies>
      </ViewAttribute>
      <ViewAttribute
        Name="EmailT"
        IsSelected="false"
        IsPersistent="false"
        PrecisionRule="true"
        Type="java.lang.String"
        ColumnType="VARCHAR2"
        AliasName="VIEW_ATTR"
        SQLType="VARCHAR">
        <RecalcCondition><![CDATA[true]]></RecalcCondition>
        <TransientExpression><![CDATA[Emailaddress]]></TransientExpression>
        <Dependencies>
          <Item
            Value="Emailaddress"/>
        </Dependencies>
      </ViewAttribute>
      <ViewAttribute
        Name="Organisationid"
        IsUpdateable="while_insert"
        IsNotNull="true"
        PrecisionRule="true"
        EntityAttrName="Organisationid"
        EntityUsage="UamOrganisationUser"
        AliasName="ORGANISATIONID">
        <TransientExpression><![CDATA[Organisationid1]]></TransientExpression>
      </ViewAttribute>
      <ViewAttribute
        Name="Username"
        IsNotNull="true"
        PrecisionRule="true"
        EntityAttrName="Username"
        EntityUsage="UamOrganisationUser"
        AliasName="USERNAME">
        <TransientExpression><![CDATA[Username1]]></TransientExpression>
        <Dependencies>
          <Item
            Value="Username1"/>
        </Dependencies>
      </ViewAttribute>
      <ViewAttribute
        Name="Surname"
        IsNotNull="true"
        PrecisionRule="true"
        EntityAttrName="Surname"
        EntityUsage="UamUserdetails"
        AliasName="SURNAME"/>
      <ViewAttribute
        Name="Username1"
        IsNotNull="true"
        PrecisionRule="true"
        EntityAttrName="Username"
        EntityUsage="UamUserdetails"
        AliasName="USERNAME1"
        IsUpdateable="false"/>
      <ViewAttribute
        Name="Firstname"
        IsNotNull="true"
        PrecisionRule="true"
        EntityAttrName="Firstname"
        EntityUsage="UamUserdetails"
        AliasName="FIRSTNAME"
        IsUpdateable="false"/>
      <ViewAttribute
        Name="Emailaddress"
        IsNotNull="true"
        PrecisionRule="true"
        EntityAttrName="Emailaddress"
        EntityUsage="UamUserdetails"
        AliasName="EMAILADDRESS"/>
      <ViewAttribute
        Name="Organisationid1"
        IsUpdateable="false"
        IsNotNull="true"
        PrecisionRule="true"
        EntityAttrName="Organisationid"
        EntityUsage="UamOrganisations"
        AliasName="ORGANISATIONID1"/>
      <ViewAttribute
        Name="CreatedDate"
        PrecisionRule="true"
        EntityAttrName="CreatedDate"
        EntityUsage="UamOrganisationUser"
        AliasName="CREATED_DATE"/>
      <AttrArray Name="KeyAttributes">
        <Item Value="Organisationid"/>
        <Item Value="Username"/>
      </AttrArray>
      <ResourceBundle>
        <PropertiesBundle
          PropertiesFile="model.ModelBundle"/>
      </ResourceBundle>
    </ViewObject>
    my bean code is
        public void addMember(javax.faces.event.ActionEvent actionEvent) {
            List<String> tempTable = new ArrayList<String>();
            //Code to get the bindings for TargetVO :
                 RowKeySet selectedEmps = getEmpTable().getSelectedRowKeys();   
                   Iterator selectedEmpIter = selectedEmps.iterator();
                   DCBindingContainer bindings =
                                     (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
                   DCIteratorBinding empIter = bindings.findIteratorBinding("UserDetailsViewVO1Iterator");
                   RowSetIterator empRSIter = empIter.getRowSetIterator();
                    while(selectedEmpIter.hasNext()){
                      Key key = (Key)((List)selectedEmpIter.next()).get(0);
                      Row currentRow = empRSIter.getRow(key);
                          onRowCreate(currentRow);
        public void onRowCreate( Row currentRow ) {
            UAMAppModuleImpl am = (UAMAppModuleImpl)ADFUtils.getApplicationModuleForDataControl("UAMAppModuleDataControl1");      
            OIDOperations   oIDOperations= new  OIDOperations();
          //  Map<Object,String> mp=new HashMap<Object, String>();
         BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
         //access the name of the iterator the table is bound to.
         DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("DeltMember1Iterator");
         //access the underlying RowSetIterator
         RowSetIterator rsi = dciter.getRowSetIterator();
         //get handle to the last row
         Row lastRow = rsi.last();
         //obtain the index of the last row
         int lastRowIndex = rsi.getRangeIndexOf(lastRow);
         /*check if the user is added already*/
         /*OperationBinding oper2 = (OperationBinding) bindings.get("check if user exists method binding");
         oper2.getParamsMap().put("attributeName1", uniqueUserAttributeValue);
         Object ret = oper2.execute();*/
         //create a new row
              EntityDefImpl accDef =UamOrganisationUserImpl.getDefinitionObject();
              UamOrganisationUserImpl org =    (UamOrganisationUserImpl)accDef.createInstance2(am.getDBTransaction(),null);
         //create a new row
         Row newRow = rsi.createRow();
         String f = (String)currentRow.getAttribute("Firstname");
         String s = (String)currentRow.getAttribute("Surname");
         String u = (String)currentRow.getAttribute("Username"); 
         String n = (String)currentRow.getAttribute("Emailaddress");
            newRow.setAttribute("firstnameT", f);
            newRow.setAttribute("SurnameT", s);
            newRow.setAttribute("Username", u);
            newRow.setAttribute("EmailT", n);
         //initialize the row
         newRow.setNewRowState(Row.STATUS_INITIALIZED);
         //add row to last index + 1 so it becomes last in the range set
         rsi.insertRowAtRangeIndex(lastRowIndex +1,  newRow);
         //make row the current row so it is displayed correctly
         rsi.setCurrentRow(newRow);
          org.setOrganisationid(getorgid());
                    org.setUsername(u);
                    org.setOrguserrole(oIDOperations.UserType());
                    am.getDBTransaction().commit();
        //  mp.put(u,u);
          //          oIDOperations.assignRoleToUsers(getorgname(), mp);
         System.out.println("orgupdated " +getorgname());
           // System.out.println("usradded "+mp);
            System.out.println("Username " + u);
            System.out.println("firstname " + f);
            System.out.println("surname " + s);
            System.out.println("email " + n);
           // refereshpage();
        // return null;
    my jsff two table page is
    <af:table value="#{bindings.UserDetailsViewVO1.collectionModel}"
                                    var="row"
                                    rows="#{bindings.UserDetailsViewVO1.rangeSize}"
                                    emptyText="#{bindings.UserDetailsViewVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
                                    fetchSize="#{bindings.UserDetailsViewVO1.rangeSize}"
                                    rowBandingInterval="0"
                                    selectedRowKeys="#{bindings.UserDetailsViewVO1.collectionModel.selectedRow}"
                                    selectionListener="#{bindings.UserDetailsViewVO1.collectionModel.makeCurrent}"
                                    rowSelection="single"
                                    partialTriggers="::qryId1" id="t4"
                                    inlineStyle="height:219px;" width="718"
                                    columnStretching="last"
                                    binding="#{pageFlowScope.addMember.empTable}">
                            <af:column sortProperty="Username" sortable="false"
                                       headerText="#{bindings.UserDetailsViewVO1.hints.Username.label}"
                                       id="c10">
                              <af:outputText value="#{row.Username}" id="ot1"/>
                            </af:column>
                            <af:column sortProperty="Firstname" sortable="false"
                                       headerText="#{bindings.UserDetailsViewVO1.hints.Firstname.label}"
                                       id="c9">
                              <af:outputText value="#{row.Firstname}" id="ot3"/>
                            </af:column>
                            <af:column sortProperty="Surname" sortable="false"
                                       headerText="#{bindings.UserDetailsViewVO1.hints.Surname.label}"
                                       id="c12">
                              <af:outputText value="#{row.Surname}" id="ot2"/>
                            </af:column>
                            <af:column sortProperty="Emailaddress" sortable="false"
                                       headerText="#{bindings.UserDetailsViewVO1.hints.Emailaddress.label}"
                                       id="c11">
                              <af:outputText value="#{row.Emailaddress}" id="ot4"/>
                            </af:column>
                            <af:column id="c16">
                              <af:commandButton text="Add New" id="cb5"
                                                actionListener="#{pageFlowScope.addMember.addMember}"/>
                            </af:column>
                          </af:table>
                        </af:panelGroupLayout>
                      </af:panelHeader>
                    </af:panelGroupLayout>
                  </af:panelGroupLayout>
                </af:panelHeader>
                <af:panelHeader text="Member In Organisation" id="ph8"
                                inlineStyle="border-color:Navy; border-style:ridge; width:857px;">
                  <f:facet name="context">
                    <af:toolbar id="t10"/>
                  </f:facet>
                  <f:facet name="menuBar"/>
                  <f:facet name="toolbar"/>
                  <f:facet name="legend"/>
                  <f:facet name="info"/>
                  <af:table value="#{bindings.DeltMember1.collectionModel}"
                            var="row" rows="#{bindings.DeltMember1.rangeSize}"
                            emptyText="#{bindings.DeltMember1.viewable ? 'No data to display.' : 'Access Denied.'}"
                            fetchSize="#{bindings.DeltMember1.rangeSize}"
                            rowBandingInterval="0"
                            selectedRowKeys="#{bindings.DeltMember1.collectionModel.selectedRow}"
                            selectionListener="#{bindings.DeltMember1.collectionModel.makeCurrent}"
                            rowSelection="single" id="t5" width="601"
                            partialTriggers="cb9">
                    <af:column sortProperty="firstnameT" sortable="false"
                               headerText="#{bindings.DeltMember1.hints.firstnameT.label}"
                               id="c13">
                      <af:inputText value="#{row.bindings.firstnameT.inputValue}"
                                    label="#{bindings.DeltMember1.hints.firstnameT.label}"
                                    required="#{bindings.DeltMember1.hints.firstnameT.mandatory}"
                                    columns="#{bindings.DeltMember1.hints.firstnameT.displayWidth}"
                                    maximumLength="#{bindings.DeltMember1.hints.firstnameT.precision}"
                                    shortDesc="#{bindings.DeltMember1.hints.firstnameT.tooltip}"
                                    id="it7">
                        <f:validator binding="#{row.bindings.firstnameT.validator}"/>
                      </af:inputText>
                    </af:column>
                    <af:column sortProperty="SurnameT" sortable="false"
                               headerText="#{bindings.DeltMember1.hints.SurnameT.label}"
                               id="c14">
                      <af:inputText value="#{row.bindings.SurnameT.inputValue}"
                                    label="#{bindings.DeltMember1.hints.SurnameT.label}"
                                    required="#{bindings.DeltMember1.hints.SurnameT.mandatory}"
                                    columns="#{bindings.DeltMember1.hints.SurnameT.displayWidth}"
                                    maximumLength="#{bindings.DeltMember1.hints.SurnameT.precision}"
                                    shortDesc="#{bindings.DeltMember1.hints.SurnameT.tooltip}"
                                    id="it11">
                        <f:validator binding="#{row.bindings.SurnameT.validator}"/>
                      </af:inputText>
                    </af:column>
                    <af:column sortProperty="EmailT" sortable="false"
                               headerText="#{bindings.DeltMember1.hints.EmailT.label}"
                               id="c15">
                      <af:inputText value="#{row.bindings.EmailT.inputValue}"
                                    label="#{bindings.DeltMember1.hints.EmailT.label}"
                                    required="#{bindings.DeltMember1.hints.EmailT.mandatory}"
                                    columns="#{bindings.DeltMember1.hints.EmailT.displayWidth}"
                                    maximumLength="#{bindings.DeltMember1.hints.EmailT.precision}"
                                    shortDesc="#{bindings.DeltMember1.hints.EmailT.tooltip}"
                                    id="it6">
                        <f:validator binding="#{row.bindings.EmailT.validator}"/>
                      </af:inputText>
                    </af:column>
                    <af:column id="c17">
                      <af:commandButton actionListener="#{bindings.Delete1.execute}"
                                        text="Delete1"
                                        id="cb9"/>
                    </af:column>
                  </af:table>Edited by: adf009 on 2013/03/07 9:21 AM

  • Query (insert, update or delete) that forms fire to SQL when we click save

    I want to see the query (insert, update or delete) that forms fire to SQL when I click the save button. I am using a master-detail form.
    Could you tell me how can I do it?

    after the commit_form
    you should call a built-in :system.last-query
    :system.last_query will show the query that you have recently perform.

  • TRIGGER TO RECORD WHEN SOMEONE ADDS ROWS

    Hello,
    I am trying to write a trigger that will timestamp who adds rows to a table,
    I must be close but sql developer is telling me that i dont have enough values.. does anybody know what is missing here? my table has 3 cols, the pk, username and date_entered
    thank you Very much in advance
    CREATE OR REPLACE
    TRIGGER REGISTRAR_ENTRADAS
    AFTER INSERT ON EVALUATION
    FOR EACH ROW
    BEGIN
    insert into audit_record_tb1
    values(sys_content('userenv','current_user'),
    sysdate);
    END;
    Alvaro

    thank you to you two very much i dont know how to give a correct one to you two, i know you both have it right but i have exactly this
    CREATE OR REPLACE
    TRIGGER REGISTRAR_ENTRADAS
    AFTER INSERT ON EVALUATION
    FOR EACH ROW
    BEGIN
    insert into audit_record_tb1(user_value, date_recorded)
    values(sys_content('userenv','current_user'),sysdate);
    END;
    and for some strange reason i am getting an error saying that sys_content is an invalid identifier
    and my table, well yes, as easy as in the example create table audit_record_tb1 (user_value varchar2(25), date_recorded date);

  • Insert a row in ALV

    Hi ,
    I need to insert a row in ALV output. On click of a Inser Row button a pop up should show with a parameter.Once the value in entered in the parameter enter is hit , the first column of the new row should have value put in that parameter as non editable field.
    The Insert row of standard toolbar inserts a blank row . Is there any way to incorporate the above logic in the standard toolbar?
    I'm using CL_GUI_ALV_GRID to display the ALV.
    It would be helpful if you provide sample coding.
    Thanks.
    Ajith
    Edited by: Ajith  Krishna on Oct 28, 2008 8:01 PM

    Hello Ajith
    The enhanced version of sample report ZUS_SDN_ALVGRID_EDITABLE_8A demonstrates how to implement your requirement.
    *& ZUS_SDN_ALVGRID_EDITABLE_8A
    *& Thread: Insert a row in ALV
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1105097"></a>
    *& Thread: Blanking values on ALV Grid Row Duplicate
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1057161"></a>
    *& Thread: Delete line event in ALV
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="945471"></a>
    REPORT  zus_sdn_alvgrid_editable_8a.
    TYPES: BEGIN OF ty_s_outtab.
    INCLUDE TYPE knb1.
    TYPES: END OF ty_s_outtab.
    TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                          WITH DEFAULT KEY.
    DATA:
      gd_okcode        TYPE ui_func,
      gd_repid         TYPE syst-repid,
      gt_fcat          TYPE lvc_t_fcat,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_grid          TYPE REF TO cl_gui_alv_grid.
    DATA:
      gt_outtab        TYPE ty_t_outtab.
    *       CLASS lcl_eventhandler DEFINITION
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA:
          mt_sel_rows     TYPE lvc_t_row.
        CLASS-METHODS:
          handle_toolbar
            FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING
              e_object
              sender,
          handle_user_command
            FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING
              e_ucomm
              sender.
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    *       CLASS lcl_eventhandler IMPLEMENTATION
    CLASS lcl_eventhandler IMPLEMENTATION.
      METHOD handle_toolbar.
    * define local data
        DATA: ls_button     TYPE stb_button.
        LOOP AT e_object->mt_toolbar INTO ls_button.
          CASE ls_button-function.
            when cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW.
              ls_button-function = 'INSERT_ROW'.
              MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
            WHEN cl_gui_alv_grid=>mc_fc_loc_delete_row.
              ls_button-function = 'DELETE_ROW'.
              MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
            WHEN cl_gui_alv_grid=>mc_fc_loc_copy_row OR
                 cl_gui_alv_grid=>mc_fc_loc_copy.
              ls_button-function = 'COPY_ROW'.
              MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
            WHEN OTHERS.
              CONTINUE.
          ENDCASE.
        ENDLOOP.
      ENDMETHOD.                    "handle_toolbar
      METHOD handle_user_command.
    * define local data
        DATA: lt_rows       TYPE lvc_t_row,
              ls_row        TYPE lvc_s_row.
        REFRESH: mt_sel_rows.
        CASE e_ucomm.
          when 'INSERT_ROW'.
          WHEN 'DELETE_ROW'.
          WHEN 'COPY_ROW'.
          WHEN OTHERS.
            RETURN.
        ENDCASE.
        "   User wants to delete or copy rows => store them in class attribute
        "   and trigger PAI afterwards where we actually delete /copy the rows
        "   and do the recalculations (in case of deletion)
        CALL METHOD sender->get_selected_rows
          IMPORTING
            et_index_rows = mt_sel_rows
    *        et_row_no     =
    *   Trigger PAI
        CALL METHOD cl_gui_cfw=>set_new_ok_code
          EXPORTING
            new_code = e_ucomm
    *      IMPORTING
    *        rc       =
      ENDMETHOD.                    "user_command
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    PARAMETERS:
      p_bukrs      TYPE bukrs  DEFAULT '2000'  OBLIGATORY.
    START-OF-SELECTION.
      SELECT  * FROM  knb1 INTO CORRESPONDING FIELDS OF TABLE gt_outtab
             UP TO 15 ROWS
             WHERE  bukrs  = p_bukrs.
      PERFORM init_controls.
      SET HANDLER:
        lcl_eventhandler=>handle_toolbar      FOR go_grid,
        lcl_eventhandler=>handle_user_command FOR go_grid.
      " Used to replace standard toolbar function code with custom FC
      go_grid->set_toolbar_interactive( ).
    * Link the docking container to the target dynpro
      gd_repid = syst-repid.
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = gd_repid
          dynnr                       = '0100'
    *      CONTAINER                   =
        EXCEPTIONS
          OTHERS                      = 4.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    * ok-code field = GD_OKCODE
      CALL SCREEN '0100'.
    END-OF-SELECTION.
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.
    *  SET TITLEBAR 'xxx'.
    **      CALL METHOD go_grid1->refresh_table_display
    ***        EXPORTING
    ***          IS_STABLE      =
    ***          I_SOFT_REFRESH =
    **        EXCEPTIONS
    **          FINISHED       = 1
    **          others         = 2
    **      IF sy-subrc <> 0.
    ***       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    ***                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    **      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE user_command_0100 INPUT.
      CASE gd_okcode.
        WHEN 'BACK' OR
             'END'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN 'INSERT_ROW'.
          perform INSERT_ROW.
        WHEN 'DELETE_ROW'.
          PERFORM delete_rows.
        WHEN 'COPY_ROW'.
          PERFORM copy_rows.
        WHEN OTHERS.
      ENDCASE.
      CLEAR: gd_okcode.
      CALL METHOD go_grid->refresh_table_display
    *      EXPORTING
    *        IS_STABLE      =
    *        I_SOFT_REFRESH =
        EXCEPTIONS
          finished       = 1
          OTHERS         = 2
      IF sy-subrc <> 0.
    *     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  BUILD_FIELDCATALOG_KNB1
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM build_fieldcatalog_knb1 .
    * define local data
      DATA:
        ls_fcat        TYPE lvc_s_fcat.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
    *     I_BUFFER_ACTIVE              =
          i_structure_name             = 'KNB1'
    *     I_CLIENT_NEVER_DISPLAY       = 'X'
    *     I_BYPASSING_BUFFER           =
    *     I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = gt_fcat
        EXCEPTIONS
          inconsistent_interface       = 1
          program_error                = 2
          OTHERS                       = 3.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    * Only non-key fields are editable
      ls_fcat-edit = 'X'.
      MODIFY gt_fcat FROM ls_fcat
        TRANSPORTING edit
        WHERE ( key NE 'X' ).
    ENDFORM.                    " BUILD_FIELDCATALOG_KNB1
    *&      Form  INIT_CONTROLS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM init_controls .
    * Create docking container
      CREATE OBJECT go_docking
        EXPORTING
          parent = cl_gui_container=>screen0
          ratio  = 90
        EXCEPTIONS
          OTHERS = 6.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    * Create ALV grid
      CREATE OBJECT go_grid
        EXPORTING
          i_parent = go_docking
        EXCEPTIONS
          OTHERS   = 5.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    * Build fieldcatalog and set hotspot for field KUNNR
      PERFORM build_fieldcatalog_knb1.
    * Display data
      CALL METHOD go_grid->set_table_for_first_display
        CHANGING
          it_outtab       = gt_outtab
          it_fieldcatalog = gt_fcat
        EXCEPTIONS
          OTHERS          = 4.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " INIT_CONTROLS
    *&      Form  delete_rows
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM delete_rows .
    * define local data
      DATA: ls_row    TYPE lvc_s_row.
      SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
      LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
        DELETE gt_outtab INDEX ls_row-index.
      ENDLOOP.
      " After deleting rows do RE-CALCULATION
    *  perform RECALCULATION.
    ENDFORM.                    " delete_rows
    *&      Form  COPY_ROWS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM copy_rows .
    * define local data
      DATA: ld_next   TYPE i,
            ls_row    TYPE lvc_s_row,
            ls_outtab TYPE ty_s_outtab.
      SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
      LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
        READ TABLE gt_outtab INTO ls_outtab INDEX ls_row-index.
        CLEAR: ls_outtab-akont. " In your case: clear GUID
        ld_next = ls_row-index + 1.
        INSERT ls_outtab INTO gt_outtab INDEX ld_next.
      ENDLOOP.
    ENDFORM.                    " COPY_ROWS
    *&      Form  INSERT_ROW
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form INSERT_ROW .
    * define local data
      DATA: ld_value1  type SPOP-VARVALUE1,
            ls_outtab  TYPE ty_s_outtab.
      CALL FUNCTION 'POPUP_TO_GET_ONE_VALUE'
        EXPORTING
          textline1            = 'Enter Value (4 Chars):'
    *     TEXTLINE2            = ' '
    *     TEXTLINE3            = ' '
          titel                = 'Enter Value'
          valuelength          = 4
        IMPORTING
    *     ANSWER               =
          VALUE1               = ld_value1
        EXCEPTIONS
          TITEL_TOO_LONG       = 1
          OTHERS               = 2.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      ls_outtab-kunnr = ld_value1.
      ls_outtab-bukrs = ld_value1.
      append ls_outtab to gt_outtab.
    endform.                    " INSERT_ROW
    Regards
      Uwe

  • How do I insert multiple rows from a single form ...

    How do I insert multiple rows from a single form?
    This form is organised by a table. (just as in an excel format)
    I have 20 items on a form each row item has five field
    +++++++++++ FORM AREA+++++++++++++++++++++++++++++++++++++++++++++++++++++
    +Product| qty In | Qty Out | Balance | Date +
    +------------------------------------------------------------------------+
    +Item1 | textbox1 | textbox2 | textbox3 | date +
    + |value = $qty_in1|value= &qty_out1|value=$balance1|value=$date1 +
    +------------------------------------------------------------------------+
    +Item 2 | textbox1 | textbox2 | textbox4 | date +
    + |value = $qty_in2|value= $qty_out1|value=$balance2|value=$date2 +
    +------------------------------------------------------------------------+
    + Item3 | textbox1 | textbox2 | textbox3 | date +
    +------------------------------------------------------------------------+
    + contd | | | +
    +------------------------------------------------------------------------+
    + item20| | | | +
    +------------------------------------------------------------------------+
    + + + SUBMIT + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Database Structure
    +++++++++++++++++
    + Stock_tabe +
    +---------------+
    + refid +
    +---------------+
    + item +
    +---------------+
    + Qty In +
    +---------------+
    + Qty Out +
    +---------------+
    + Balance +
    +---------------+
    + Date +
    +++++++++++++++++
    Let's say for example user have to the use the form to enter all 10 items or few like 5 on their stock form into 4 different textbox field each lines of your form, however these items go into a "Stock_table" under Single insert transaction query when submit button is pressed.
    Please anyone help me out, on how to get this concept started.

    Hello,
    I have a way to do this, but it would take some hand coding on your part. If you feel comfortable hand writing php code and doing manual database calls, specificaly database INSERT calls you should be fine.
    Create a custom form using the ADDT Custom Form Wizard that has all the rows and fields you need. This may take a bit if you are adding the ability for up to 20 rows, as per your diagram of the form area. The nice thing about using ADDT to create the form is that you can setup the form validation at the same time. Leave the last step in the Custom Form Wizard blank. You can add a custom database call here, but I would leave it blank.
    Next, under ADDT's Forms Server Behaviors, select Custom Trigger. At the Basic tab, you enter your custom php code that will be executed. Here you are going to want to put your code that will check if a value has been entered in the form and then do a database INSERT operation on the Stock_table with that row. The advanced tab lets you set the order of operations and the name of the Custom Trigger. By default, it is set to AFTER. This means that the Custom Trigger will get executed AFTER the form data is processed by the Custom Form Transaction.
    I usually just enter TEST into the "Basic" tab of the Custom Trigger. Then set my order of operations in the "Advanced" tab and close the Custom Trigger. Then I go to the code view for that page in Dreamweaver and find the Custom Trigger function and edit the code manually. It's much easier this way because the Custom Trigger wizard does not show you formatting on the code, and you don't have to keep opening the Wizard to edit and test your code.
    Your going to have to have the Custom Trigger fuction do a test on the submitted form data. If data is present, then INSERT into database. Here's a basic example of what you need to do:
    In your code view, the Custom Trigger will look something like this:
    function Trigger_Custom(&$tNG) {
    if($tNG->getColumnValue("Item_1")) {
    $item1 = $tNG->getColumnValue("Item_1");
    $textbox1_1 = $tNG->getColumnValue("Textbox_1");
    $textbox1_2 = $tNG->getColumnValue("Textbox_2");
    $textbox1_3 = $tNG->getColumnValue("Textbox_3");
    $date1 = $tNG->getColumnValue("Textbox_3");
    $queryAdd = "INSERT INTO Stock_table
    (item, Qty_In, Qty_Out, Balance, Date) VALUES($item1, $textbox1_1, $textbox1_2, $textbox1_3, $date1)"
    $result = mysql_query($queryAdd) or die(mysql_error());
    This code checks to see if the form input field named Item_1 is set. If so, then get the rest of the values for the first item and insert them into the database. You would need to do this for each row in your form. So the if you let the customer add 20 rows, you would need to check 20 times to see if the data is there or write the code so that it stops once it encounters an empty Item field. To exit a Custom Trigger, you can return NULL; and it will jump out of the function. You can also throw custom error message out of triggers, but this post is already way to long to get into that.
    $tNG->getColumnValue("Item_1") is used to retrieve the value that was set by the form input field named Item_1. This field is named by the Custom Form Wizard when you create your form. You can see what all the input filed names are by looking in the code view for something like:
    // Add columns
    $customTransaction->addColumn("Item_1", "STRING_TYPE", "POST", "Item_1");
    There will be one for each field you created with the Custom Form Wizard.
    Unfortunately, I don't have an easy way to do what you need. Maybe there is a way, but since none of the experts have responded, I thought I would point you in a direction. You should read all you can about Custom Triggers in the ADDT documentation/help pdf to give you more detailed information about how Custom Triggers work.
    Hope this helps.
    Shane

Maybe you are looking for