Regarding "Update .. From Table" Statement

Hi,
I have an existing piece of code which I'm trying to understand.
There are two scenarios regarding the UPDATE statement.
1) Scenario 1:
There exists a database table with around 100 or more fields/columns [Eg: DB_TABLE1].
An Internal Table exists with the same key as the above database table [EG: I_TABLE1].
code:
loop at I_TABLE1.
  update DB_TABLE1
  set kf1 = I_TABLE1-kfa
   kf2 = I_TABLE1-kfb
   kf3 = I_TABLE1-kfc
   kf4 = I_TABLE1-kfd
  where key1 = I_TABLE1-keya AND key2 = I_TABLE1-keyb.
Endloop.
In the above scenario the records in database table [DB_TABLE1] with matching condition are updated and the rest of the fields are not touched.  - Correct me if I am wrong.
2) Scenario 2:
There exists a database table with around 100 or more fields/columns [Eg: DB_TABLE1].
Two Internal Tables exist with the same key as the above database table [EG: I_TABLE1 And  I_TABLE2].
Code part a:
SELECT * FROM DB_TABLE1 INTO TABLE I_TABLE2
      WHERE  KF1 <> 0.
Internal Table 1 has some data.
Code part b:
loop at I_TABLE1.
  update DB_TABLE1
  set kf1 = I_TABLE1-kfa
   kf2 = I_TABLE1-kfb
   kf3 = I_TABLE1-kfc
   kf4 = I_TABLE1-kfd
  where key1 = I_TABLE1-keya AND key2 = I_TABLE1-keyb.
Endloop.
Code part c:
update DB_TABLE1 FROM TABLE I_TABLE2.
In the second scenario what will be the final effect of DB_TABLE1?
As i understand it, there is no use of Code part b. Am I right?
I thought that the records in I_TABLE2 with matching key in DB_TABLE1 will be updated and the rest of the records will be deleted.
But actually there is not change in the DB_TABLE1 when the above code is executed.
Help is appreciated.
Thanks.

Hi Joey,
Scenario 1: In the above scenario the records in database table DB_TABLE1 with matching condition are updated and the rest of the fields are not touched.
- That's right.
Scenario 2: As i understand it, there is no use of Code part b.
- Exactly because of the following reasons:
1. Code part a shows data selected from DB_TABLE1 INTO TABLE I_TABLE2.
2. Code part c shows DB_TABLE1 updated from TABLE I_TABLE2 whereas Code part b uses ONLY internal table I_TABLE1.
3. If there are any operations performed in Code Part b on 'I_TABLE2', then this would have been different.
Regards,
Pranav.

Similar Messages

  • URGENT : select from table statement in ABAP OO

    Hi all,
    I am an absolute ABAP OO beginner and need some quick help from an expert. How can I make a selection from an existing table (eg MARA) in an BADI which is programmed according to ABAP OO principles.
    In the old ABAP school you could make a TABLES statement at the beginning and the do a SELECT¨* FROM but this does not work in ABAP OO.
    How should i define such simple selections from existing tables. Anyone ?
    Thanks a lot,
    Eric Hassenberg

    *define internal table
    data: i_mara like standard table of mara.
    *select to this table
    select * from mara into table i_mara.
    Also you have to define work area for this internal table in order to use it.
    data:w_mara like line of i_mara.

  • Update From Select statement

    I'm very new to Oracle so please bear with me.
    I need to Update a table ( T1) with dates selected from another table (T2). However, because of the size of the tables (the second one has upwards of 3,000,000 rows) I have to do it incrementally, say 10k rows at a time. However, there's no field in T1 that I can use as a flag to say the row's been updated. But I do have an ascending numeric field that I can do a Max() function on. My thought was to capture the max numeric function in local variable and use it in a where clause so I only get the rows I need to update. Pseudo-ish code follows:
    DECLARE
    mDoc NUMBER
    maxNum NUMBER
    BEGIN
    mDoc = 0;
    SELECT MAX(doc_id_n) INTO maxNum FROM T2;
    WHILE NOT mDoc > maxNum
    LOOP
    SELECT MAX(doc_id_n) INTO mDoc FROM T2
    WHERE doc_id_n > mDoc AND rownum < 10001;
    UPDATE T1 SET scan_d =
    (select to_date(t.ddate,'MM/DD/YYYY') as ndate
    from T2 t, T1 i
    where i.stor_rep_id = 'HRPAYROLL1' and
    t.doc_id_n = i.doc_id_n and rownum < 10001
    AND NOT t.doc_id_n > mDoc
    ORDER BY t.doc_id_n)
    END LOOP;
    END;

    You say:
    <However, there's no field in T1 that I can use as a flag to say the row's been updated.
    That's fine, you needn't nor might you want to do this incrementally. Instead, what basis or values in table(T1) are you using to determine which rows are updated? For example, you might want to use a particular field as your 'filter' between the two tables. Still it's not fun :)
    UPDATE T1 SET date_column = (SELECT inserted_date FROM T2 WHERE customer = 'ABC')
    WHERE customer = 'ABC';
    UPDATE T1 SET date_column = (SELECT inserted_date FROM T2 WHERE customer = 'XYZ')
    WHERE customer = 'XYZ';
    Hope this helps.

  • Need help regarding Dynamic Read Table statement

    Hello
    I know that the syntax for dymanic read table statement is
    READ TABLE  <ITAB> WITH KEY (KEY1) = VALUE1  (KEY2) = VALUE2 .....(KEYN) = VALUEN
    Here is my problem..
    I am dynamically creating an internal table based on parameter table entered by user.
    The key for this table can be determined only at runtime.
    The table entered might have by one field as key field or 10 key fields..
    How can I use the dynamic read in this situation ?
    Thanks for your help in advance,
    Santosh
    Edited by: Santosh Kulkarni on Jan 3, 2010 6:58 AM
    Edited by: Santosh Kulkarni on Jan 3, 2010 7:01 AM

    Hello Santosh,
    please check out the following solution. The program demonstrates how to use the dynamic read statement with three key field conditions. Additional key fields can be added in the same way.
    REPORT z_dynamic_read.
    DATA: gt_itab TYPE REF TO data,
          ge_key_field1 TYPE char30,
          ge_key_field2 TYPE char30,
          ge_key_field3 TYPE char30,
          go_descr_ref TYPE REF TO cl_abap_tabledescr.
    FIELD-SYMBOLS: <gt_itab> TYPE STANDARD TABLE,
                   <gs_key_comp> TYPE abap_keydescr,
                   <gs_result> TYPE ANY.
    PARAMETERS: pa_table TYPE tabname16 DEFAULT 'SPFLI',
                pa_cond1 TYPE string DEFAULT sy-mandt,
                pa_cond2 TYPE string DEFAULT 'LH',
                pa_cond3 TYPE string DEFAULT '0123'.
    START-OF-SELECTION.
    * Create and populate internal table
      CREATE DATA gt_itab TYPE STANDARD TABLE OF (pa_table).
      ASSIGN gt_itab->* TO <gt_itab>.
      SELECT * FROM (pa_table) INTO TABLE <gt_itab>.
    * Get the key components into the fields ge_key_field1, ...
      go_descr_ref ?= cl_abap_typedescr=>describe_by_data_ref( gt_itab ).
      LOOP AT go_descr_ref->key ASSIGNING <gs_key_comp>.
        CASE sy-tabix.
          WHEN 1.
            ge_key_field1 = <gs_key_comp>-name.
          WHEN 2.
            ge_key_field2 = <gs_key_comp>-name.
          WHEN 3.
            ge_key_field3 = <gs_key_comp>-name.
        ENDCASE.
      ENDLOOP.
    * Finally, perform the search
      READ TABLE <gt_itab> ASSIGNING <gs_result>
              WITH KEY (ge_key_field1) = pa_cond1
                       (ge_key_field2) = pa_cond2
                       (ge_key_field3) = pa_cond3.
      IF sy-subrc = 0.
        WRITE / 'Record found.'.
      ELSE.
        WRITE / 'No record found.'.
      ENDIF.
    One note: When an internal table is created dynamically like in my program above, the table key is not the key defined in the DDIC structure -- instead, the default key for the standard table is used (i.e. all non-numeric fields).
    Hope this helps,
    David

  • Performance issue and functional question regarding updates on tables

    A person at my site wrote some code to update a custom field on the MARC table that was being copied from the MARA table.  Here is what I would have expected to see as the code.  Assume that both sets of code have a parameter called p_werks which is the plant in question.
    data : commit_count type i.
    select matnr zfield from mara into (wa_marc-matnr, wa_marc-zfield).
      update marc set zfield = wa_marc-zfield
         where werks = p_werks and matnr = wa_matnr.
      commit work and wait.
    endselect.
    I would have committed every 200 rows instead of every one row, but here's the actual code and my question isn't around the commits but something else.  In this case an internal table was built with two elements - MATNR and WERKS - could have done that above too, but that's not my question.
                DO.
                  " Lock the record that needs to be update with material creation date
                  CALL FUNCTION 'ENQUEUE_EMMARCS'
                    EXPORTING
                      mode_marc      = 'S'
                      mandt          = sy-mandt
                      matnr          = wa_marc-matnr
                      werks          = wa_marc-werks
                    EXCEPTIONS
                      foreign_lock   = 1
                      system_failure = 2
                      OTHERS         = 3.
                  IF sy-subrc <> 0.
                    " Wait, if the records not able to perform as lock
                    CALL FUNCTION 'RZL_SLEEP'.
                  ELSE.
                    EXIT.
                  ENDIF.
                ENDDO.
                " Update the record in the table MARC with material creation date
                UPDATE marc SET zzdate = wa_mara-zzdate
                           WHERE matnr = wa_mara-matnr AND
                                 werks = wa_marc-werks.    " IN s_werks.
                IF sy-subrc EQ 0.
                  " Save record in the database table MARC
                  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                    EXPORTING
                      wait   = 'X'
                    IMPORTING
                      return = wa_return.
                  wa_log-matnr   = wa_marc-matnr.
                  wa_log-werks   = wa_marc-werks.
                  wa_log-type    = 'S'.
                  " text-010 - 'Material creation date has updated'.
                  wa_log-message = text-010.
                  wa_log-zzdate  = wa_mara-zzdate.
                  APPEND wa_log TO tb_log.
                  CLEAR: wa_return,wa_log.
                ELSE.
                  " Roll back the record(un save), if there is any issue occurs
                  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
                    IMPORTING
                      return = wa_return.
                  wa_log-matnr   = wa_marc-matnr.
                  wa_log-werks   = wa_marc-werks.
                  wa_log-type    = 'E'.
                  " 'Material creation date does not updated'.
                  wa_log-message = text-011.
                  wa_log-zzdate  = wa_mara-zzdate..
                  APPEND wa_log TO tb_log.
                  CLEAR: wa_return, wa_log.
                ENDIF.
                " Unlock the record from data base
                CALL FUNCTION 'DEQUEUE_EMMARCS'
                  EXPORTING
                    mode_marc = 'S'
                    mandt     = sy-mandt
                    matnr     = wa_marc-matnr
                    werks     = wa_marc-werks.
              ENDIF.
    Here's the question - why did this person enqueue and dequeue explicit locks like this ?  They claimed it was to prevent issues - what issues ???  Is there something special about updating tables that we don't know about ?  We've actually seen it where the system runs out of these ENQUEUE locks.
    Before you all go off the deep end and ask why not just do the update, keep in mind that you don't want to update a million + rows and then do a commit either - that locks up the entire table!

    The ENQUEUE lock insure that another program called by another user will not update the data at the same time, so preventing database coherence to be lost. In fact, another user on a SAP correct transaction, has read the record and locked it, so when it will be updated your modifications will be lost, also you could override modifications made by another user in another luw.
    You cannot use a COMMIT WORK in a SELECT - ENDSELECT, because COMMIT WORK will close each and every opened database cursor, so your first idea would dump after the first update. (so the internal table is mandatory)
    Go through some documentation like [Updates in the R/3 System (BC-CST-UP)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCSTUP/BCCSTUP_PT.pdf]
    Regards

  • Issue regarding update rules--Table RSUPDKEY

    Hi Friends..
    Can anyone please tell me something about the table RSUPDKEY?
    I knw the use of this table.......but how the fields are getting updated.......how the value in the filed BOOLEAN getting populated?
    I am facing a strange problem...
    In Production system.....For one keyfigure....one characteristic is not mapped...initial value option is selected.But in the field Source Characteristic that charecteristic name is selected but that option is not selected.......it means the field is not blank......
    For Prod......in the table RSUPDKEY.........for this rule......in the Source Infoobject field that infoobject name is coming and Boolean field = X
    When I am trying to do the same thing in the development box............i.e. in the Source Characteristic field I have selected the infoobject and i have selected the Initial value option............after that when I am saving it.......the Source characteristic field remains blank......
    In Dev box in this table both the fields are blank.
    Thanks and Regards,
    Debjani.....

    Hi,
    You can check End Routine .
    An end routine is a routine with a table in the target structure format as input and output parameters. You can use an end routine to postprocess data after transformation on a package-by-package basis
    http://help.sap.com/saphelp_nw70/helpdata/EN/43/bcdc6001344defe10000000a422035/content.htm.
    Below is the lSAP help link for migration of 3.x update rules & transfer rules.
    http://help.sap.com/saphelp_nw70/helpdata/EN/43/f00e2696d24c5fe10000000a155369/frameset.htm
    Hope this helps!
    Edited by: Meera Murali on Mar 4, 2009 9:52 AM

  • AQ Auto update from Table

    Hi All
    When I insert records into my table it should update Queue also. What is the best way to implement this?
    Thanks in Advance
    Raghu.

    Hi
    thanks for your reply.
    This is what my scenario.
    I want to send Data from operating to Other operating system. So Whenever user inserts data into table it should update Queue also. Once data comes to queue then I have to propagate to Other operating system. So I would like to the following thing.
    If there is any way to use 'trigger' to Insert data into Queue?

  • Update from table ORA-00933 error

    I use Oracle 10g. The following throws an ORA-00933 SQL command not properly ended Error
    update fb_mst_complaint
    set sub_category = n.subcategory
    from fb_mst_complaint s,
    select a.docket_no, a.sub_category, c.subcategory
    from fb_mst_complaint a,
    +( select category, min(subcategory) subcategory+
    from fb_subcategory
    where activated > 0
    group by category
    +) c+
    where a.category =
    +( select distinct a.category from fb_subcategory b+
    where b.category = a.category
    and b.subcategory = c.subcategory
    and b.activated > 0
    +)+
    and a.category = c.category
    and a.sub_category <= 0
    ) n
    where s.docket_no = n.docket_no
    and s.sub_category = n.sub_category
    and s.docket_no = 8573;
    The error is shown in the FROM clause. However, The SELECT statement which makes up the alias name 'n' works accurately.
    Please help. Thanks for the help in advance.
    Edited by: user11195221 on May 24, 2009 6:35 AM

    user11195221 wrote:
    The issue is that the inner select returns multiple values and therefore cannot be set as mentioned.Well then you cannot do this in a single UPDATE statement (you could use the rownum = 1 construct but it would make no sense without knowing the business context).

  • Member Access Profile - update from table MemberAccess

    Hello,
    We need to do an update in all our member access profiles. As we have 710 profiles, it's very time consuming to update each of them seperately.
    I was looking into the table MemberAccess profile to update the profiles. I manage to update all profiles with one query but unfortunately it seems that we still need to go into SAP BPC Admin to process each profile. If I don't process in SAP BPC Admin, I get the error in Excel: 'There is a problem in dimension file: Entity' and the current view in Entity dimension just shows ...more... instead of the correct security!
    Is there another way of updating the MemberAccess profiles in 1 go, without needing to process it individually? This would save us a lot of time!
    Thanks,
    Sofie Luyten

    Sofie,
    Are you assuming it didn't work because of the "Return Value = 0" result? That stored procedure isn't designed to return anything so whether it ran properly or not you wouldn't get much back (except an error message is something went very wrong).
    The only way that you can know if it worked is to look at the acsEntity table and make sure it has all of the proper records. I guess you can also start up SQL Profiler before executing the stored procedure to see what the stored procedure runs and make sure that's what you want. I'm not sure how familiar you are with SQL though so that may not be helpful for you.
    Jimmy

  • Question regarding Update from an ODS

    Hi Experts,
    I have an issue of data mismatch between oa ODS 0FIGL_O02 and the InfocubeSFIGL_C02.
    the infocube is getting updated through the ODS(By means of generated Datasource).
    I have some Question:
    1) If i delete the data selectively from Infocube and ODS and then load full request for that selection:
    wather the change log data will be deeted autometically while deleting the data selectively from ODS?.
    2) I am not getting all generated  the generated datasource inspite of selecting "Display generated Objects" from Menu bar.
    Please Help me ASAP.
    Thanks ain advance
    Jitendra Joshi

    Hi experts
    Many thanks for your help.
    if i delete the data selectively from Cube and ODS both  and then load the data in to ODS for that selection (As repairfull request) now if I will try to update my Cube from the ODS, will the data in Change log cause any incostency (Because the data in change log will not be deleted from change log while selective deletion. )
    please Advice me ASAP as its an issue in Production.
    Thanks in Advance
    jiootendra Joshi

  • FAGLFLEXT table is not updating from FAGLFLEXA

    Hello Experts,
    In thru which program the summarisatin table of FAGLFLEXT getting updated from table FAGLFLEXA .
    We've updated some filed values like prctr , cost center to FAGLFLEXA but the same cumulative amount is not showing in the table period wise and there is a difference in balace sheet.
    Pls advise, how to generate the table FAGLFLEXT to get my overall balances or how to run this table to go and do their own std calculations and updation.
    Pls advise.
    thanks & regards
    sankar.

    Thanks

  • Select * from table not working with Oracle OBDC driver

    Hello,
    In our web development we have been using the MS ODBC for Oracle
    driver to connect to our Oracle db. We decided to try the
    Oracle ODBC driver because it supports the commandTimeout
    property in ASP which the MS driver does not. The problem I'm
    running into now is that all of our select * from table
    statements appear not to be working. The Oracle ODBC driver
    version we are using is ver 8.00.05.00. Is there something that
    I'm not doing properly? If I take the same select * from table
    statement and name the columns, I dont get any error. Otherwise
    I'm getting a Subscript out of range error. It seems strange to
    me that this driver would not support a select * from table
    statement (which I''m told is the case by another developer
    here).
    Is there something I'm missing?
    Thanks,
    Pete

    I'm positive I have a connection. Otherwise I wouldn't get a
    response when I name the columns instead of using *.
    There must be something else that I'm missing or doing wrong.
    I've actually been looking into alternative ODBC drivers to see
    if I have the same problems but none that I have found support
    commandTimeout.
    Any other ideas?

  • Best way to update indicators in state machine ?

    What is the best method to update indicators constantly in a SM ? ... 
    MY INDICATORS: I want to update the cluster of OUTPUT INDICATORS for ever new update that is happening inside the FOR LOOP (see next image). How could I achieve that ?
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]

    Since on my machine, the second screenshot is cropped, i cannot see the complete FOR loop. You do refer to the loop writing to VISA, correct?
    If so:
    - Is this loop timed? If so, what is the average iteration time? Note: if this is faster than about 50ms, you should not update the indicator in every iteration as the human simply cannot see changes that fast. An average user would only see some flickering and from time to time something "readable".
    - Do you update the indicators elsewhere as well?
    Possible solution:
    - As Yamaeda suggests: Put the indicator in the FOR loop. Works well if only this loop updates these indicators.
    - Local variable: As dataflow serializes access to the indicator (variable in loop, terminal outside the state case), you wont have race conditions. On the other hand bears risks if someone introduces concurrent loops using the same indicators (variables).
    - Property node "value": Same as local variable, but is bound to UI thread. Therefore, it takes more time which induces performance drawbacks. On the other hand, a property node has error in/out and is better suited to be placed in well designed dataflow programming.
    - Extract UI updates from the state machine and introduce a parallel running "UI Update" loop. Refer to the Producer/Consumer template for an initial start point.
    hope this helps,
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • HT4623 My computer is not taking the new update from itunes. It states that i do not have the requirements to finish the Install and that it was Installed incorrectly. I have never had any issue with any previous update regarding iTunes. What is the issue

    My computer is not taking the new update from itunes. It states that i do not have the requirements to finish the Install and that it was Installed incorrectly. I have never had any issue with any previous update regarding iTunes. What is the issue?

    Hi there Double2D,
    You may find the troubleshooting steps in the article below helpful.
    iTunes 11.1.4 for Windows: Unable to install or open
    http://support.apple.com/kb/TS5376
    -Griff W. 

  • UPDATE dbtable FROM TABLE itab .

    Hi All,
    UPDATE dbtable FROM TABLE itab.
    For the above statement, if there are entries in itab that do not have primary key in dbtable, then are they created in the dbtable or ignored.
    if they are ignored, how would i know which are ignored. or how to insert those ignored lines into the dbtable.
    Thanks in advance..!

    MODIFY will update current records and create ones that do not exists.   Not sure about UPDATE as I never use it.
    MODIFY dbtable FROM TABLE itab.
    Regards,
    Rich Heilman

Maybe you are looking for

  • Digital Signature on TDS certificate - Vendors

    Dear All, Their is possiblity to insert digital signature on TDS certificate given to employees(form 16), but is their any chance of inseting the digital signature on TDS certificate given to Vendors. Thanks & Regards Krishna Chaitanya

  • Can i make it using Java?

    I'm wondering if it is possible to translate a visual basic code to java. I use NetBeans platform. I want to clone [statusdetect.com|http://www.statusdetect.com] . I know i have to use a bot which is written already in visual basic , but i don't real

  • How do unzip a file?

    I have received a 'zip' file from FedEx and instructed to open and print the image, but I am unable to open it with what I have on my IMac.

  • Applying Patch for OC4J to update JDBC Driver

    I've downloaded a patch (3335848) for OC4J in order to update the JDBC drivers from metalink for windows. The Readme file says its generic for all OS but got to execute a shell script for unix OS. Im using Windows. How to update the patch in Windows.

  • Fatal error Acrobat failed to connect to DDE Server

    I just purchased the Adobe Acrobat xI Pro & installed. I get a Fatal Error message when I try to open the program. I am running Windows7. What is the problem?