Update from other table

I want to update one table with values from another table. The code I have written looks like
update reservations r
set start_date = (select start_date from sap_update su where su.reservation_id = r.reservationid),
end_date = (select end_date from sap_update su where su.reservation_id = r.reservationid),
impressions_rsvd = (select impressions_rsvd from sap_update su where su.reservation_id = r.reservationid),
sapid = (select sapid from sap_update su where su.reservation_id = r.reservationid),
state = (select reservation_state from sap_update su where su.reservation_id = r.reservationid);
which results in me being told that start_date cannot be set to null.
the intent is to match up records in the reservations table with those in the SAP_UPDATE table (on the reservationid column) and copy the data in corresponding rows from the sap_update to the reservations table.
In passing, I personally find that the more complex inserts and updates are just as nasty as any select query. But all the books I've come across tend to skip over this aspect rather sharply. Are there any good resources on this? I'm also hampered by having rather more SQL Server experience - which seems to have a different handle on updates.
Thanks for your help in anticipation!
Iain

If your subquery is not returning anyrow (i.e. no matching record in Sap_Update table for the given ReservationID), and you don't want to change existing value then in that case you can change it to:
update reservations r
set start_date = (select nvl(su.start_date, r.start_date) from sap_update su
   where su.reservation_id = r.reservationid),
end_date = (select end_date from sap_update su
   where su.reservation_id = r.reservationid),
impressions_rsvd = (select impressions_rsvd from sap_update su
   where su.reservation_id = r.reservationid),
sapid = (select sapid from sap_update su
   where su.reservation_id = r.reservationid),
state = (select reservation_state from sap_update su
   where su.reservation_id = r.reservationid);In similar fashion you can change your other subqueries too. Another suggestion, you can rewrite your query to:
update reservations r
set (start_date, end_date, impressions_rsvd, sapid, state   ) =
(select nvl(su.start_date, r.start_date), end_date , impressions_rsvd, sapid, state
from sap_update su
   where su.reservation_id = r.reservationid)
;Thanks,
Dharmesh Patel

Similar Messages

  • I have an i phone 3 g . i want to udate it to latest os . can i update from other pc also ?,

    have an i phone 3 g . i want to udate it to latest os . can i update from other pc also ?, if answer is yes then if after getting update from other pc i will switch to my older pc then latest softer which i have updated will remain or it will switc over to older software?

    If you update from another computer you may lose some of your content.
    If your computer does not have the latest itunes then it will not worl with the iphone at all once you update it.
    Why do you want to update from another computer?

  • Update Columns in Table from Other Table based on Fund Code

    Hello All!!
    Hope you are doing good!!!
    I like to update 5 columns in X Table based on fund_code. The Fund code and 5 column values come from Y Table. Please let me know how to wirte a sql statement to update all values for 5 columns in X Table. Please post me any template code.
    Thanks.

    I think you are looking for an updatable join,
    Please see the syntax below,
    UPDATE (SELECT b.col1
              FROM table1 b, table2 E
             WHERE b.col_pk = E.col_pk) T
       SET T.col1 = 0Thanks,
    G.

  • Multiple Row Update From Similar Table

    I am attempting to update a table based on similar table if the Entry_Type is D and they have the same log_numbers. I have created queries to show me the results I want but am having some difficulities getting the update to happen. I am getting a single-row subquery returns more than one row error, but I would like to update all necessary rows.
    Here is my sql...
    UPDATE V.MASTER
    SET (MODIFIED_BY, ENTRY_TYPE) = (
         SELECT MODIFIED_BY, ENTRY_TYPE
         FROM J.BACK)
         WHERE LOG_NUMBER IN
         (SELECT LOG_NUMBER FROM V.MASTER
         WHERE ENTRY_TYPE <> 'D' AND LOG_NUMBER = ANY
                   (SELECT LOG_NUMBER FROM J.BACK
                   WHERE ENTRY_TYPE = 'D'))
    I would appreciate any assistance! Thanks!

    You can also use correlated update. This one is from AskTom (http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1197999096334)
    if you have the proper primary keys to assure uniqueness on S and C, this does it (i have the keys
    noted in the creates)
    ops$tkyte@ORA920> create table pgp_person
    2 ( date_of_birth date,
    3 update_by varchar2(10),
    4 update_date date,
    5 load_timestamp date,
    6 person_num int );
    Table created.
    ops$tkyte@ORA920>
    ops$tkyte@ORA920> create table ship_passenger
    2 ( date_of_birth date,
    3 person_num int,
    4 voy_num int,
    5 book_num int,
    6 seq_num int,
    7 primary key (person_num) );
    Table created.
    ops$tkyte@ORA920>
    ops$tkyte@ORA920> create table pgp_cruise_history
    2 ( voy_num int,
    3 book_num int,
    4 seq_num int,
    5 matched_ind int,
    6 primary key(voy_num,book_num,seq_num) );
    Table created.
    ops$tkyte@ORA920>
    ops$tkyte@ORA920> update ( select p.date_of_birth dob1, s.date_of_birth dob2,
    2 p.update_by, p.update_date, p.load_timestamp
    3 from pgp_person p, pgp_cruise_history c, ship_passenger s
    4 where p.person_num = s.person_num
    5 and s.voy_num = c.voy_num
    6 and s.book_num = c.book_num
    7 and s.seq_num = c.seq_num
    8 and c.matched_ind is not null
    9 and s.date_of_birth <> p.date_of_birth )
    10 set dob1 = dob2,
    11 update_by = 'sdm18649',
    12 update_date = trunc(sysdate),
    13 load_timestamp = sysdate;
    0 rows updated.

  • Updating from another table query

    I have tried a merge query and I think I am not doing this right or for what I want to accomplish, it will not work. Here is the problem:
    I have a lookup table
    create table lkp1(
    lkp_id number,
    lkp_name varchar2(100));
    and have a another table
    create table test(
    test_id number,
    lkp_id number,
    lkp_name varchar2(100));
    I am trying to pull in the lkp_id value from lkp1 table into the test table. I have the lkp_name field in the test table so that I can reference back to lkp1 so that I can pull in the lkp_id value. How would I go about doing this if the lkp_name field in test table has the value duplicated over many rows. For example 5 records in the test table might have the lkp_name of 'ORACLE', and its lkp_id from lkp1 table is 25. How do I populate the lkp_id in the test table with the value from the lkp1 table, without specfiying in the where clasue ...lkp_name = 'ORACLE'. There has to be a way. I tried the merge query, and WOW...I was really off.
    Please help!

    scott@ORA92> -- test data:
    scott@ORA92> select * from lkp1
      2  /
        LKP_ID LKP_NAME
             1 name1
             2 Oracle
    2 rows selected.
    scott@ORA92> select * from test
      2  /
       TEST_ID     LKP_ID LKP_NAME
            10            name1
            20            Oracle
            30            Oracle
    3 rows selected.
    scott@ORA92> -- update:
    scott@ORA92> update test set lkp_id =
      2  (select distinct lkp_id from lkp1 where lkp1.lkp_name = test.lkp_name)
      3  where exists (select lkp_id from lkp1 where lkp1.lkp_name = test.lkp_name)
      4  /
    3 rows updated.
    scott@ORA92> -- results:
    scott@ORA92> select * from test
      2  /
       TEST_ID     LKP_ID LKP_NAME
            10          1 name1
            20          2 Oracle
            30          2 Oracle
    3 rows selected.

  • Replace the data in the table from other table

    Iam creating a backup of table Order by this query:
    create table orderbckup as select * from order; - this works
    For the first time i have to create a orderbckup table but every month i have to replace the data in orderbckup from order table. Is there any way where i can copy the data from order and repalce the data in orderbckp - I cannot use insert as it adds the rows. Or do i need to delete the old table and create it again or can i use update. If so can anyone plz let me know

    882431 wrote:
    Iam creating a backup of table Order by this query:
    create table orderbckup as select * from order; - this works
    For the first time i have to create a orderbckup table but every month i have to replace the data in orderbckup from order table. Is there any way where i can copy the data from order and repalce the data in orderbckp - I cannot use insert as it adds the rows. Isn't that exactly what you want to do - add rows?
    If I understand you, the problem isn't with adding new rows; the problem is how to remove the old rows.
    Or do i need to delete the old table and create it again or can i use update. If so can anyone plz let me knowInstead of dropping the table and re-creating it, you can TRUNCATE the table and then use INSERT:
    TRUNCATE TABLE orderbackup;
    -- At this point, orderbackup has 0 rows
    INSERT INTO  orderbackup
    SELECT  *
    FROM    orders       -- ORDER is a reserved word in Oracle, so it's not a good table name
    ;TRUNCATE TABLE is faster than DELETing all the rows, because it doesn't save redo information. (That means you can't ROLLBACK a TRUNCATE statement, but you can rollback a DROP TABLE statement, either.)

  • How to read internal table data and use to retrive from other table.

    Hi all,
        I am trying to generate a report using ooabap.
    In this scenario, I retrieved data from one standard table (zcust) and successfully displayed using structure 'i_zcust_final' ( i_zcust_final is similar structure of zcust).  
        Now I want to get some other data from other standard table  (zpurch) using the data in i_zcust_final. How....???? I am unable to read data from i_zcust_final even i kept in loop.
        I am attaching the code here.. even it too long, please look at the code and suggest me what to do.
    code  **************************
    REPORT  ZBAT_OOPS_REPORT1.
    TABLES: ZCUST.
        D E F I N I T I O N     *****
    CLASS BATLANKI_CLS DEFINITION.
      PUBLIC SECTION.
      DATA : ITAB_ZCUST TYPE STANDARD TABLE OF ZCUST,
             I_ZCUST_FINAL LIKE LINE OF ITAB_ZCUST,
             ITAB_ZCUST1 TYPE STANDARD TABLE OF ZCUST.
      TYPES: BEGIN OF IT_ZPURCH,
              CUSTNUM   TYPE ZPURCH-CUSTNUM,
              PURC_DOC  TYPE ZPURCH-PURC_DOC,
              VENDOR    TYPE ZPURCH-VENDOR,
              STATUS    TYPE ZPURCH-STATUS,
              PURC_ORG  TYPE ZPURCH-PURC_ORG,
            END OF IT_ZPURCH.
      DATA : ITAB_ZPURCH TYPE TABLE OF IT_ZPURCH,
             I_ZPURCH_FINAL LIKE LINE OF ITAB_ZPURCH.
      METHODS: GET_ZCUST,
               PRINT_ZCUST,
               GET_ZPURCH.
    ENDCLASS.
    I N I T I A L I Z T I O N   *****
        SELECT-OPTIONS:S_CUSNUM FOR ZCUST-CUSTNUM.
    INITIALIZATION.
    S_CUSNUM-LOW = '0100'.
    S_CUSNUM-HIGH = '9999'.
    S_CUSNUM-OPTION = 'BT'.
    S_CUSNUM-SIGN   = 'I'.
    APPEND S_CUSNUM.
    CLEAR S_CUSNUM.
    I M P L E M E N T A T I O N *****
    CLASS BATLANKI_CLS IMPLEMENTATION.
      METHOD GET_ZCUST.
      SELECT * FROM ZCUST
        INTO TABLE ITAB_ZCUST
       WHERE CUSTNUM IN S_CUSNUM.
    ENDMETHOD.
      METHOD PRINT_ZCUST.
       LOOP AT ITAB_ZCUST INTO I_ZCUST_FINAL.
       WRITE:/ I_ZCUST_FINAL-CUSTNUM,
               I_ZCUST_FINAL-CUSTNAME,
               I_ZCUST_FINAL-CITY,
               I_ZCUST_FINAL-EMAIL.
       ENDLOOP.
      ENDMETHOD.
       METHOD GET_ZPURCH.
    LOOP AT ITAB_ZCUST INTO ITAB_ZCUST1.
      SELECT CUSTNUM
             PURC_DOC
             VENDOR
             STATUS
             PURC_ORG
        FROM ZPURCH
        INTO CORRESPONDING FIELDS OF TABLE ITAB_ZPURCH
        WHERE CUSTNUM EQ I_ZCUST_FINAL-CUSTNUM.
    ENDLOOP.
         LOOP AT ITAB_ZPURCH INTO I_ZPURCH_FINAL.
         WRITE:/ I_ZPURCH_FINAL-CUSTNUM,
                 I_ZPURCH_FINAL-PURC_DOC,
                 I_ZPURCH_FINAL-VENDOR,
                 I_ZPURCH_FINAL-STATUS,
                 I_ZPURCH_FINAL-PURC_ORG.
         ENDLOOP.
    ENDMETHOD.
    ENDCLASS.
      O B J E C T   *****
    DATA: BATLANKI_OBJ TYPE REF TO BATLANKI_CLS.
    START-OF-SELECTION.
    CREATE OBJECT BATLANKI_OBJ.
    CALL METHOD:
                 BATLANKI_OBJ->GET_ZCUST,
                 BATLANKI_OBJ->PRINT_ZCUST,
                 BATLANKI_OBJ->GET_ZPURCH.
    Can anyone suggest me..
      Thanks in advance,
      Surender.

    Hi Surendar..
    There is mistake in the Work area specification in this method.
    METHOD GET_ZPURCH.
    LOOP AT ITAB_ZCUST INTO ITAB_ZCUST1.
    SELECT CUSTNUM
    PURC_DOC
    VENDOR
    STATUS
    PURC_ORG
    FROM ZPURCH
    INTO CORRESPONDING FIELDS OF TABLE ITAB_ZPURCH
    <b>WHERE CUSTNUM EQ      ITAB_ZCUST1-CUSTNUM.</b>           
                                   "Instead of  I_ZCUST_FINAL-CUSTNUM.
    ENDLOOP.
    LOOP AT ITAB_ZPURCH INTO I_ZPURCH_FINAL.
    WRITE:/ I_ZPURCH_FINAL-CUSTNUM,
    I_ZPURCH_FINAL-PURC_DOC,
    I_ZPURCH_FINAL-VENDOR,
    I_ZPURCH_FINAL-STATUS,
    I_ZPURCH_FINAL-PURC_ORG.
    ENDLOOP.
    ENDMETHOD.
    Now it should work..
    One more thing : From performance point of view you have to Replace that loop using FOR ALL ENTRIES . And avoid CORRESPONDING FIELDS. it will be slow.
    This is the code.
    LOOP AT ITAB_ZCUST INTO ITAB_ZCUST1.
    if ITAB_ZCUST[] IS NOT INITIAL.
    SELECT CUSTNUM
    PURC_DOC
    VENDOR
    STATUS
    PURC_ORG
    FROM ZPURCH
    INTO TABLE ITAB_ZPURCH
    <b>for all entries in ITAB_ZCUST1</b>
    <b>WHERE CUSTNUM EQ      ITAB_ZCUST1-CUSTNUM.</b>           
                                   "Instead of  I_ZCUST_FINAL-CUSTNUM.
    ENDIF.
    ENDLOOP.
    <b>Reward if Helpful.</b>

  • Decode from other table?

    how can i decode a column value from another table? e.g. the view selects an ID from TABLE1 and wants to add a column "Description" that decodes the value of the ID column. The decode() function is usable for a small set of fixed decodings. But what if the decoded values are not fixed and are stored in another table? Is it possible to write such a SELECT statement that decodes values with values from another table (instead of a fixed parameter list9?

    Are you looking for something like this:
    SQL> SELECT e.deptno,
      2         e.ename,
      3         (SELECT dname FROM scott.dept d WHERE d.deptno = e.deptno) description
      4  FROM   scott.emp e;
        DEPTNO ENAME      DESCRIPTION
            20 SMITH      RESEARCH
            30 ALLEN      SALES
            30 WARD       SALES
            20 JONES      RESEARCH
            30 MARTIN     SALES
            30 BLAKE      SALES
            10 CLARK      ACCOUNTING
            20 SCOTT      RESEARCH
            10 KING       ACCOUNTING
            30 TURNER     SALES
            20 ADAMS      RESEARCH
            30 JAMES      SALES
            20 FORD       RESEARCH
            10 MILLER     ACCOUNTING
    14 rows selected.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.3.0 - Production
    SQL>

  • To populate dynamically created int table with data from other table

    Hi everybody,
    I have already created an internal table dynamically, but now want to populate it with data from another IT depending on the plant name.
    My dynamic int table contains fields with plant name like '8001' ,'8002' and so on.
    no I want to read data from the other table and depending on bwkey which contains similar data like plant name , want to append to this new dynamic int table through read key statement.
    I cannot reference the field name hard coded as it does not allow field symbol reference to be hard coded.
    Pls help.

    Hi,
    Check the code below:
    REPORT  ztestdyn.
    TYPE-POOLS : slis.
    TABLES: yyle0003.
    DATA:
      g_exit    TYPE c,
      g_save    VALUE 'A',               "For parameter I_SAVE
      g_repid   LIKE sy-repid,           "For program name
      g_variant TYPE disvariant.         "For parameter IS_VARIANT
    *Tables
      DATA: d_ref TYPE REF TO data,
            d_ref1 TYPE REF TO data,
            i_alv_cat1 TYPE TABLE OF lvc_s_fcat,
            ls_alv_cat1 LIKE LINE OF i_alv_cat1.
      DATA: BEGIN OF total_tab OCCURS 0 ,
            tknum TYPE yyle0003-tknum,
            quantity TYPE p,  "yyle0003-QUANTITY,
            END OF total_tab.
      DATA: BEGIN OF g_scandata_tab OCCURS 0.
              INCLUDE STRUCTURE yyle0003.
      DATA: END OF g_scandata_tab.
      DATA: g_yyle0003_tab LIKE yyle0003 OCCURS 0 WITH HEADER LINE.
      DATA: g_itab1 TYPE TABLE OF yyle0003.
      DATA: wa_itab1 LIKE g_scandata_tab.
      TYPES: BEGIN OF itab2,
             tknum TYPE yyle0003-tknum,
             vhilm TYPE yyle0003-vhilm,
             quantity TYPE p,
             END OF itab2.
      DATA: g_itab3 TYPE TABLE OF itab2.
      DATA: wa_itab3 TYPE itab2.
      DATA: g_itab5 TYPE TABLE OF itab2.
      DATA: wa_itab5 TYPE itab2.
      DATA: g_itab4 TYPE TABLE OF itab2.
      DATA: wa_itab4 TYPE itab2.
      DATA: gv_wa TYPE REF TO data.
      DATA : wa_tab TYPE itab2.
      DATA: BEGIN OF itab6 OCCURS 0,
             vhilm TYPE yyle0003-vhilm,
             quantity TYPE p,
             END OF itab6.
    ******************Start of Internal Table Definition *******************
      DATA:
            g_custom_container_0100 TYPE REF TO cl_gui_custom_container,
            g_alv_grid_0100    TYPE REF TO cl_gui_alv_grid,
            g_container_0100   TYPE scrfname VALUE 'LIST',
            g_mylayout         TYPE lvc_s_layo,
            ok_code            LIKE sy-ucomm.
      FIELD-SYMBOLS :<f_fs> TYPE table,
                     <f_fs11> TYPE table,
                     <f_fs1> TYPE table,
                     <f_fs3> TYPE ANY,
                     <f_fs4> TYPE ANY,
                     <f_field> TYPE ANY,
                     <f_fs5> TYPE ANY.
      FIELD-SYMBOLS: <fs_wa> TYPE ANY.
      DATA: l_var TYPE i,
            l_i   TYPE i.
      DATA: l_var1 TYPE char20,
            l_var2 TYPE char20.
    DATA: l_TOTAL TYPE I,
          L_FILL TYPE i,
          L_TOT  TYPE I.
    DATA: l_int TYPE i,
           l_sum TYPE i.
    FIELD-SYMBOLS: <f_fs2> TYPE  itab2, "
                     <f_fs6> TYPE ANY,
                     <f_fs7> TYPE ANY.
      DATA: l_var3 TYPE char15.
      DATA: l_quant TYPE p.
    FIELD-SYMBOLS: <f_fs8> LIKE itab6, "
                     <f_fs9> TYPE ANY,
                     <f_fs10> TYPE ANY.
    FIELD-SYMBOLS : <f_fs12> TYPE ANY,
                      <f_fs13> TYPE ANY.
      SORT g_scandata_tab BY tknum vhilm.
      LOOP AT g_scandata_tab INTO wa_itab1.
        MOVE-CORRESPONDING wa_itab1 TO wa_itab3.
        APPEND wa_itab3 TO g_itab3.
      ENDLOOP.
      LOOP AT g_itab3 INTO wa_itab3.
        COLLECT wa_itab3 INTO g_itab4.
      ENDLOOP.
      LOOP AT g_itab4 INTO wa_itab4.
        MOVE-CORRESPONDING wa_itab4 TO wa_itab5.
        MOVE-CORRESPONDING wa_itab4 TO itab6.
        APPEND wa_itab5 TO g_itab5.
        COLLECT itab6.
      ENDLOOP.
      CLEAR wa_itab3.
      SORT g_itab4 BY tknum vhilm.
      DELETE ADJACENT DUPLICATES FROM g_itab4 COMPARING vhilm.
      DESCRIBE TABLE g_itab4 LINES l_var.
      l_i = '2'.
      ls_alv_cat1-fieldname = 'TKNUM'.
      ls_alv_cat1-col_pos = 1.
      ls_alv_cat1-coltext ='ShipmentNo.'.
      APPEND ls_alv_cat1 TO i_alv_cat1.
      DATA: l_var4(10) TYPE c,
            l_var5(10) TYPE c,
            l_fieldname(20) TYPE c..
      LOOP AT g_itab4 INTO wa_itab4.
        IF l_var >= 1.
          CONDENSE wa_itab4-vhilm NO-GAPS.
          ls_alv_cat1-fieldname = wa_itab4-vhilm. "l_fieldname.
          ls_alv_cat1-col_pos = l_i.
          ls_alv_cat1-coltext = wa_itab4-vhilm.
          ls_alv_cat1-do_sum  ='X'.
          APPEND ls_alv_cat1 TO i_alv_cat1.
          CLEAR : ls_alv_cat1, l_fieldname.
          l_i = l_i + 1.
        ENDIF.
        AT LAST.
          ls_alv_cat1-fieldname = 'TOTAL'. "l_fieldname.
          ls_alv_cat1-col_pos = l_i.
          ls_alv_cat1-coltext = 'TOTAL'.
          ls_alv_cat1-do_sum  ='X'.
          APPEND ls_alv_cat1 TO i_alv_cat1.
          CLEAR : ls_alv_cat1, l_fieldname.
        ENDAT.
        SORT i_alv_cat1 BY fieldname.
        DELETE ADJACENT DUPLICATES FROM i_alv_cat1.
      ENDLOOP.
      SORT i_alv_cat1 BY col_pos.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = i_alv_cat1
        IMPORTING
          ep_table = d_ref.
      ASSIGN d_ref->* TO <f_fs>.
      CREATE DATA gv_wa LIKE LINE OF <f_fs>.
      ASSIGN gv_wa->* TO <fs_wa>.
      DELETE ADJACENT DUPLICATES FROM <f_fs> COMPARING ALL FIELDS.
        LOOP AT itab6.
        CLEAR wa_itab5.
        wa_itab5-tknum = 'Total'.
        MOVE-CORRESPONDING itab6 TO wa_itab5.
        APPEND wa_itab5 TO g_itab5.
        CLEAR wa_itab5.
      ENDLOOP.
         DESCRIBE TABLE g_itab5 LINES L_TOT.
           LOOP AT TOTAL_TAB.
          L_TOTAL = L_TOTAL + total_tab-quantity.
         ENDLOOP.
      LOOP AT g_final ASSIGNING <f_fs2>.
        ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <f_fs2> TO <f_fs6>.
        ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <fs_wa> TO <f_fs7>.
        <f_fs7> = <f_fs6>.
        CONDENSE <f_fs2>-vhilm NO-GAPS.
        ASSIGN COMPONENT 'VHILM' OF STRUCTURE <f_fs2> TO <f_fs3>.
        ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.
        MOVE <f_fs3> TO l_var1.
        ASSIGN COMPONENT l_var1 OF STRUCTURE <fs_wa> TO <f_fs5>.
        <f_fs5> =  <f_fs4>.
        CLEAR total_tab-quantity.
        READ TABLE total_tab WITH KEY tknum = <f_fs6>.
        IF sy-subrc = 0.
          ASSIGN total_tab-quantity TO <f_fs12>.
          ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.
          <f_fs13> = <f_fs12>.
        ENDIF.
        L_FILL = L_FILL + 1.
        IF L_FILL = L_TOT.
         ASSIGN L_TOTAL TO <f_fs12>.
          ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.
          <f_fs13> = <f_fs12>.
        ENDIF.
        AT END OF <f_fs2>-tknum.
          APPEND <fs_wa> TO <f_fs>.
          CLEAR  <fs_wa>.
        ENDAT.
      ENDLOOP.
      CLEAR: <f_fs6>,
              <f_fs7>.
      CLEAR <fs_wa>.
    CALL SCREEN 0100.
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'ZVKS'.
      SET TITLEBAR 'ZVKS'.
      CHECK sy-ucomm IS INITIAL.
      SORT g_scandata_tab BY tknum vhilm.
      CREATE OBJECT g_custom_container_0100
             EXPORTING container_name = g_container_0100
             EXCEPTIONS
               cntl_error = 1
               cntl_system_error = 2
               create_error = 3
               lifetime_error = 4
               lifetime_dynpro_dynpro_link = 5.
      CREATE OBJECT g_alv_grid_0100
             EXPORTING i_parent = g_custom_container_0100.
      g_mylayout-grid_title = 'Display Scanning data'.
      CALL METHOD g_alv_grid_0100->set_table_for_first_display
        CHANGING
          it_outtab                     = <f_fs>
          it_fieldcatalog               = i_alv_cat1
                    EXCEPTIONS
                      invalid_parameter_combination = 1
                      program_error                 = 2
                      too_many_lines                = 3
                      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.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    Regards
    Kannaiah

  • Procedure to insert in table from other table returning multiple records

    Hi Everybody,
    I am new to oracle. So need your advice guys. I have to insert values to one table from another table. Please let me know , how i can do this.
    E.g:
    INSERT INTO TABLEA(`Name`,`ID`,`another_field`) VALUES ('Somevalue',(SELECT DISTINCT id FROM TABLEB WHERE tb.cat = '5' AND ID NOT IN (select id from TABLEC)), 'somevalue')
    Above thing is not working for me.
    I have to insert ID IN TABLE A by getting value from this query:
    SELECT DISTINCT id FROM TABLEB WHERE tb.cat = '5' AND ID NOT IN (select id from TABLEC)
    This query is returning multiple IDs, so how can i insert all in TABLEA by creating some sp.
    Please help me out of this. I will be very thankful to you all guys. I will really appreciate your suggestions and comments.
    Regards
    Dev

    Why cant you just do this,
    INSERT INTO TABLEA (NAME, ID, another_field)
       SELECT DISTINCT 'Somevalue',
                       ID,
                       'somevalue'
         FROM TABLEB
        WHERE tb.cat = '5'
          AND ID NOT IN (SELECT ID FROM TABLEC)G.

  • How to track the changes to a table and update the other table ?

    Hi Guys,
                   I am looking to track deletion of entries on KONV table and sync these missing entries in an other table which has primary key entries of KONV.
    How to do this.. is ALE change pointer is any good for this purpose ?
    Thanks
    AJ

    Hi Sam,
      In order to track the changes in the KONV table, go to table CDHDR and give objectclass and objectid, you will get all the details.
    Regards,
    ramesh.

  • Updating a column from other table

    Hi all,
    I have a simple update query problem. I have four tables
    activist(activist_id,first_name,last_name,c_state),
    membership(activist_id,g_n_id),
    group_network(g_n_id,g_n_type_id),
    school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
    Here is the query for the states which are null
    select distinct a.activist_id,a.first_name,a.last_name,
    a.c_state,sd.state from activist a,membership m,
    group_network g,school_group_det sd where
    a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
    g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
    order by a.activist_id
    I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
    Pleae any one help me
    Thanks
    Srinivas

    For ur query the reply whay u have got is correct one. For further quries similar to one u had u can download a tool named TOAD (Tools for Oracle Application Developer) from quest site (www.quest.com). Install it a proceed.
    Do let me know how and what u feek about TOAD.

  • Update table based on values from other table

    Hi,
    I am trying to update one table based on the values of another table. Since you can't use From in update statements, how do you execute this?
    For example i have to tables, Table A and Table B. I want to update a column or columns in Table A based on another value in Table B:
    So if the column in Table B was 1 then column in Table A would be Yes, if Table B was 2, then Table A would be Yes, if Table B was 3 then Table A would be N/A and so on...
    Any help would be appreciated.
    thanks,
    scott

    SQL> select * from t1;
    ID ST
    1
    2
    3
    SQL> select * from t2;
    NO
    1
    2
    3
    4
    SQL> update t1 set status=(select decode(no,1,'Y',2,'N','NA') from t2 where t1.id=t2.no);
    3 rows updated.
    SQL> select * from t1;
    ID ST
    1 Y
    2 N
    3 NA
    Daljit Singh

  • Update a table from other table

    Hi Guys,
    I have 2 tables i.e. tableA, tableB both have same structure.
    I want to update tableA with tableB's data using a unique column in both table.
    Which is the easiest way to do that?
    Thanks,

    Yes, good point. I was ok with merge,
    With your example..
    SQL> desc tablea
    Name Null? Type
    COL2 NUMBER(22,2)
    COL3 NUMBER(22,2)
    COL4 NUMBER(22,2)
    SQL> desc tableb
    Name Null? Type
    COL2 NUMBER(22,2)
    COL3 NUMBER(22,2)
    COL4 NUMBER(22,2)
    SQL> ed
    Wrote file afiedt.buf
    1 update tableB b
    2 set ( col3, col4)
    3 = (select col3, col4
    4 from tableA a where a.col2 = b.col2)
    5 where exists
    6* (select 1 tableA a where a.col2 = b.col2)
    SQL> /
    (select 1 tableA a where a.col2 = b.col2)
    ERROR at line 6:
    ORA-00923: FROM keyword not found where expected

  • It is not working when use trigger to check data from other table.

    Please help me with this, I have put a trigger on a table but it can not work as I expect.
    case study: one class has many students, only one of them goes to match.
    The purpose of this trigger is to check when choose a student goes to match, this student must in his class where he belongs to.
    Version of Oracle is 10.2.0.1.0.
    --table:
    DROP TABLE STU;
    DROP TABLE CLASS;
    create table CLASS(
    CID     VARCHAR2(5)   PRIMARY KEY,
    CNAME   VARCHAR2(20)  NOT NULL,
    SCHOSEN VARCHAR2(5));
    create table STU(
    SID     VARCHAR2(5)   PRIMARY KEY,
    SNAME   VARCHAR2(20)  NOT NULL,
    CID     VARCHAR2(5)   NOT NULL REFERENCES CLASS(CID) ON DELETE CASCADE);
    --data:
    --CLASS
    INSERT INTO CLASS(CID,CNAME) VALUES(1,'SUN');
    INSERT INTO CLASS(CID,CNAME) VALUES(2,'MOON');
    INSERT INTO CLASS(CID,CNAME) VALUES(3,'EARTH');
    --STU
    INSERT INTO STU VALUES(1,'JACK',1);
    INSERT INTO STU VALUES(2,'TOM',1);
    INSERT INTO STU VALUES(3,'LILY',2);
    INSERT INTO STU VALUES(4,'DUSTIN',3);
    --TRIGGER
    CREATE OR REPLACE TRIGGER CHECK_SCHOSEN
    BEFORE INSERT OR UPDATE OF SCHOSEN ON CLASS
    FOR EACH ROW WHEN (NEW.SCHOSEN IS NOT NULL)
    DECLARE
    DUMMY INTEGER;
    INVALID_STU EXCEPTION;
    VALID_STU EXCEPTION;
    MUTATING_TABLE EXCEPTION;
    PRAGMA EXCEPTION_INIT(MUTATING_TABLE, -4091);
    CURSOR DUMMY_CURSOR (ST VARCHAR2, CL VARCHAR2) IS
      SELECT SID FROM STU, CLASS
      WHERE STU.SID=ST AND STU.CID=CLASS.CID AND CLASS.CID=CL
        FOR UPDATE OF CLASS.SCHOSEN;
    BEGIN
      OPEN DUMMY_CURSOR(:NEW.SCHOSEN, :NEW.CID);
      FETCH DUMMY_CURSOR INTO DUMMY;
      IF DUMMY_CURSOR%NOTFOUND THEN
        RAISE INVALID_STU;
      ELSE
        RAISE VALID_STU;
      END IF;
      CLOSE DUMMY_CURSOR;
    EXCEPTION
      WHEN INVALID_STU THEN
        CLOSE DUMMY_CURSOR;
        DBMS_OUTPUT.PUT_LINE('PLEASE RE-ENTER CLASS ID AND STUDENT ID AS CLASS OR STUDENT IS NOT VALID.');
      WHEN VALID_STU THEN
        CLOSE DUMMY_CURSOR;
        DBMS_OUTPUT.PUT_LINE('STUDENT CHOOSE SUCCEFULLY!');
      WHEN MUTATING_TABLE THEN
        NULL;
    END;
    /Just copy and paste above and try to run following:
    UPDATE CLASS
    SET SCHOSEN=3
    WHERE CID=1;
    Clearly,you can not choose student which is 3 as match member of class 1. Please help me. Thanks.
    Edited by: 991096 on 01-Mar-2013 02:36
    Edited by: 991096 on 01-Mar-2013 03:03
    Edited by: 991096 on 01-Mar-2013 03:11

    Hi,
    Welcome to the forum!
    Like the others, I can't see a business purpose for this trigger. I assume it's just an experiment to learn how triggers work.
    991096 wrote:
    Please help me with this, I have put a trigger on a table but it can not be triggered.Sorry, I don't understand what you want help with.
    Are you saying the trigger doesn't fire? It does fire; it just raises the mutating table error, so you don't see anything.
    case study: one class has many students, only one of them goes to match.What do you mean when you say "goes to match"?
    --table:
    DROP TABLE STU;
    DROP TABLE CLASS;
    create table CLASS(
    CID VARCHAR2(5) PRIMARY KEY,
    CNAME VARCHAR2(20) NOT NULL,
    SCHOSEN VARCHAR2(5));
    create table STU(
    SID VARCHAR2(5) PRIMARY KEY,
    SNAME VARCHAR2(20) NOT NULL,
    CID VARCHAR2(5) NOT NULL REFERENCES CLASS(CID) ON DELETE CASCADE);
    --data:
    --CLASS
    INSERT INTO CLASS(CID,CNAME) VALUES(1,'SUN');
    INSERT INTO CLASS(CID,CNAME) VALUES(2,'MOON');
    INSERT INTO CLASS(CID,CNAME) VALUES(3,'EARTH');
    --STU
    INSERT INTO STU VALUES(1,'JACK',1);
    INSERT INTO STU VALUES(2,'TOM',1);
    INSERT INTO STU VALUES(3,'LILY',2);
    INSERT INTO STU VALUES(4,'DUSTIN',3);
    --TRIGGER
    CREATE OR REPLACE TRIGGER CHECK_SCHOSEN
    BEFORE INSERT OR UPDATE OF SCHOSEN ON CLASS
    FOR EACH ROW WHEN (NEW.SCHOSEN IS NOT NULL)
    DECLARE
    DUMMY INTEGER;
    INVALID_STU EXCEPTION;
    VALID_STU EXCEPTION;
    MUTATING_TABLE EXCEPTION;
    PRAGMA EXCEPTION_INIT(MUTATING_TABLE, -4091);
    CURSOR DUMMY_CURSOR (ST VARCHAR2, CL VARCHAR2) IS
    SELECT SID FROM STU, CLASS
    WHERE STU.SID=ST AND STU.CID=CLASS.CID AND CLASS.CID=CL
    FOR UPDATE OF CLASS.SCHOSEN;
    BEGIN
    OPEN DUMMY_CURSOR(:NEW.SCHOSEN, :NEW.CID);
    FETCH DUMMY_CURSOR INTO DUMMY;
    IF DUMMY_CURSOR%NOTFOUND THEN
    RAISE INVALID_STU;
    ELSE
    RAISE VALID_STU;
    END IF;
    CLOSE DUMMY_CURSOR;
    EXCEPTION
    WHEN INVALID_STU THEN
    CLOSE DUMMY_CURSOR;
    DBMS_OUTPUT.PUT_LINE('PLEASE RE-ENTER CLASS ID AND STUDENT ID AS CLASS OR STUDENT IS NOT VALID.');
    WHEN VALID_STU THEN
    CLOSE DUMMY_CURSOR;
    DBMS_OUTPUT.PUT_LINE('STUDENT CHOOSE SUCCEFULLY!');
    WHEN MUTATING_TABLE THEN
    NULL;
    END;
    /Thanks for posting the CREATE TABLE, INSERT and CREATE TRIGGER statements; that really helps!
    See the forum FAQ {message:id=9360002} for other helpful tips, such as how to use \ tags to post formatted code.
    Just copy and paste above and try to run following:
    UPDATE CLASS
    SET SCHOSEN=3
    WHERE CID=1;
    Clearly,you can not choose student which is 3 as match member of class 1. The trigger did not be triggered. Please help me. Thanks.You can't do DML, or even query, the class table from a FOR EACH ROW trigger on the same class table.
    Add 3 more calls to put_line to see this:CREATE OR REPLACE TRIGGER CHECK_SCHOSEN
    BEFORE INSERT OR UPDATE OF SCHOSEN ON CLASS
    FOR EACH ROW WHEN (NEW.SCHOSEN IS NOT NULL)
    DECLARE
    DUMMY          INTEGER;
    INVALID_STU      EXCEPTION;
    VALID_STU          EXCEPTION;
    MUTATING_TABLE      EXCEPTION;
    PRAGMA           EXCEPTION_INIT (MUTATING_TABLE, -4091);
    CURSOR DUMMY_CURSOR (ST VARCHAR2, CL VARCHAR2) IS
    SELECT SID
         FROM      STU
         ,     CLASS
         WHERE     STU.SID          = ST
         AND     STU.CID          = CLASS.CID
         AND     CLASS.CID     = CL
         FOR UPDATE OF           CLASS.SCHOSEN;
    BEGIN
    dbms_output.put_line (:NEW.schosen || ' = schosen entering check_schosen');     -- ***** NEW *****
    OPEN DUMMY_CURSOR (:NEW.SCHOSEN, :NEW.CID);
    dbms_output.put_line ('Cursor is open now.');     -- ***** NEW *****
    FETCH DUMMY_CURSOR INTO DUMMY;
    IF DUMMY_CURSOR%NOTFOUND THEN
    RAISE INVALID_STU;
    ELSE
    RAISE VALID_STU;
    END IF;
    CLOSE DUMMY_CURSOR;
    EXCEPTION
    WHEN INVALID_STU THEN
    CLOSE DUMMY_CURSOR;
         DBMS_OUTPUT.PUT_LINE ('PLEASE RE-ENTER CLASS ID AND STUDENT ID AS CLASS OR STUDENT IS NOT VALID.');
    WHEN VALID_STU THEN
         CLOSE DUMMY_CURSOR;
         DBMS_OUTPUT.PUT_LINE ('STUDENT CHOOSE SUCCEFULLY!');
    WHEN MUTATING_TABLE THEN
    DBMS_OUTPUT.PUT_LINE ('MUTATING TABLE');     -- ***** NEW *****
         NULL;
    END;
    Output, when trying to UPDATE class:3 = schosen entering check_schosen
    MUTATING TABLE
    1 row updated.
    Obviously, the trigger fired, since you see the message "3 = schosen entering check_schosen"
    Obviously, the OPEN statement raised an error, since you don't see the message 'Cursor is open now.'
    Obviously, the mutating table error was raised, since you see the message 'MUTATING TABLE'.
    So the trigger fired, and went to the EXCEPTION handler almost immediately.  The EXCEPTION handler printed a message, as instructed, and the trigger ended.  Then the actual UPDATE took place.
    I hope this answers your question.
    If not, what is your question?  It may be very clear to you, but a complete mystery to others.  Ask clear questions, such as "Why did ... happen?  I thought ... would happen, be ... as the PL/SQL manual says at ...".                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • VF02 Print Out Problem

    Hi all, We are facing the problem while taking the print out from VF02. We are using ZFORM designed by our ABAPer. While using standard form (LB_BIL_INVOICE) its working and while using ZFORM, we are able to see the print preview but not able to take

  • Applet function call from javascript

    Hi, I'm haveing a problem with accesing applet's functions from Javascript in Mozilla. IE works fine but in Mozilla I get the following error: Error: document.applets[0] has no properties The code used is: document.applets[0].test(); The applet has t

  • 2 BIW connections to 1 R/3 system

    Hello, We have one R/3 system to which we want to connect 2 BIW systems. The BIW systems will be picking data from the same client in the R/3 system. when i try to configure the rfc connections, it fails since the client can have only one logical nam

  • Can raw files be stored in the cloud ?

    can raw files be stored in the cloud?

  • JSP 2.0 Tag variable

    I'm running Tomcat 5 and I've added a simple tag to use with some JSP pages. The tag appears to be working except for the variable it's trying to set. The doTag function is executed ok, but setting a variable doesn't seem to work when you try it from