How to Query and Update/Insert Large Tables ...

I have the following 2 tables:
Table 1: Pricing
This table holds pricing details of all Items (roughly 150,000 items). One Item has three types of prices Standard, Promotion, and Discounted. Therefore the table contains roughly 150,000 * 3 records. Also the prices may get updated frequently every day.
Item#---Type------------FromDate---ToDate-----Price
===================================
AAA-----Standard------01/01/05---31/12/05---1.50
AAA-----Promotion----16/12/05---20/12/05---1.40     
AAA-----Discounted---10/12/05---15/12/05---1.20
BBB-----Standard------01/01/05---31/12/05---1.60
BBB-----Promotion----17/12/05---18/12/05---1.30
BBB-----Discounted---10/12/05---15/12/05---1.50
Table 2: BestPrice
At a given date, this table contains the best price (lowest price) of each item for the following 21 days (including the current date). The POS system is accessing this table to get the daily best price for billing customers.
Item#----Date--------BestPrice
=====================
AAA------17/12/05----1.40
AAA------18/12/05----1.40     
AAA------19/12/05----1.40
AAA------20/12/05----1.40
AAA------21/12/05----1.50
BBB------17/12/05----1.30
BBB------18/12/05----1.30
BBB------19/12/05----1.60
BBB------20/12/05----1.60
BBB------21/12/05----1.60
Problem Statement:
Table 2 (BestPrice) needs to get updated from Table 1 (Pricing) at least once every day with the best price for each item for the next 21 days (including the current day). What’s the most efficient method to perform this job?

I don't know really why your application needs to use BestPrice table!
It is not clear what it does for it because querying will not be better than querying the pricing table. This will be very fast with an index on intem#
On the other hand, why do you use three rows per item in Pricing table? it could be one row per item.
Any way, to populate the table for the first time :
insert into bestprice
select item#
     , dte
     , min(price) bestprice
from pricing, (select trunc(sysdate) + rownum - 1 dte from dual connect by rownum <= 21) t
where  dte  between fromdate and todate
group by dte, item#Now, you can have a row trigger (update) on Pricing table which can change BestPrice table according to a change in Pricing tabe.
Then you have to use a daily job that can be based on the following statement:
update BestPrice B
set dte = trunc(sysdate) + 20
  , BestPrice =
         select min(price)
         from Pricing P
         where P.item# = B.item#
            and B.dte between P.FromDate and P.ToDate
where dte = trunc (sysdate) - 1Message was edited by:
Michel SALAIS
I forgot to say that that if your periods in the pricing table don't covere a desired date in the BestPrice table then my insert statement will not treat it and my update will put it to NULL

Similar Messages

  • Insert,  Delete and Update options in Table control

    Experts,
    I have writen code for Insert,  Delete and Update options in Table control. They are not working properly...
    can any one send the code for the above please...
    Thanks in advance..

    Hi,
    Following steps will help you.
    1.TOP-INCLUDE
    DATA: ITAB1 LIKE KNA1 OCCURS 0 WITH HEADER LINE.
    DATA: ITAB2 LIKE KNA1 OCCURS 0 WITH HEADER LINE.
    DATA: WA LIKE KNA1.
    DATA: ANT TYPE I,CUR TYPE I.
    DATA: OK_CODE TYPE SY-UCOMM.
    CONTROLS: TABCTRL TYPE TABLEVIEW USING SCREEN 100.
    IN FLOWLOGIC
    PROCESS BEFORE OUTPUT.
    LOOP AT ITAB1 CURSOR CUR WITH CONTROL TABCTRL.
    ENDLOOP.
    PROCESS AFTER INPUT.
    MODULE CLEAR_DATA.
    LOOP AT ITAB1.
    MODULE MOVE_DATA.
    ENDLOOP.
    ADD “OK_CODE” IN ELEMENT LIST. CLICK ON LAYOUT AND  ADD TABLE CONTROL(name it as TABCTRL) AND PUSHBUTTONS AS FOLLOWS.
    SELECT THE FIELDS FROM PROGRAM. SAVE CHECK AND ACTIVATE.
    CLICK ON FLOWLOGIC EDITOR FROM APPLICATION TOOL BAR.
    DOUBLE CLICK ON MODULE “CLEAR_DATA”.
    write the in this module as below.
    CLEAR ITAB2. REFRESH ITAB2.
    DOUBLE CLICK ON MODULE “MOVE_DATA”.
    write the code in this module as below.
    APPEND ITAB1 TO ITAB2.
    ACTIVATE PAI AND WRITE THE CODE AS BELOW.
    CASE OK_CODE.
    WHEN 'FETCH'.
    SELECT * FROM KNA1 INTO TABLE ITAB1 UP TO 20 ROWS.
    TABCTRL-LINES = SY-DBCNT.
    WHEN 'ADD'.
    GET CURSOR LINE CNT.
    CNT = TABCTRL-TOP_LINE + CNT - 1.
    CLEAR WA.
    INSERT WA INTO ITAB1 INDEX CNT.
    WHEN 'MODIFY'.
    GET CURSOR LINE CNT.
    READ TABLE ITAB2 INDEX CNT.
    LOOP AT ITAB2.
    MODIFY KNA1 FROM ITAB2.
    ENDLOOP.
    SELECT * FROM KNA1 INTO TABLE ITAB1.
    WHEN 'EXIT'.
    LEAVE PROGRAM.
    ENDCASE.
    SAVE,CHECK AND ACTIVATE ALL.
    CREATE TCODE AND EXECUTE.
    contact if u hv any issues regarding this code.
    reward points,if it is useful.
    Thanks,
    Chandu.

  • ORA-20001: Unable to create query and update page.

    I am using the wizard: Form on a table with report 2 pages. I do not change any of the values when using the wizard (just taking all default values)
    I created over 10 pages successfully already.
    When creating the one page, I received this error on clicking the 'Finish' button
    Error creating query and update.
    Return to Application
    ORA-20001: Unable to create query and update page. ORA-12899: value too large for column "FLOWS_010500"."WWV_FLOW_PAGE_PLUGS"."PLUG_QUERY_COL_ALLIGNMENTS" (actual: 269, maximum: 255)
    Seems like it might be table related since I can continue and create more forms/reports on other tables.
    Any help would be appreciated.

    336554,
    Looks like there is a 127-column limit on the number of report columns supported when using that wizard. Do you have more than that?
    57434

  • Which one is faster loading type between Insert/Update and Update/Insert?

    Hi Gurus,
    Could anyone tell me which loading type faster between Insert/Update and Update/Insert?Any resolution and document reference would be grateful.
    Regards,
    Joni

    910575 wrote:
    Thanks Purvesh for your quick response..
    Yes you are right, we have to prefer sql rather than plsql. But if i have 1 lakh records to be inserted then my insert into select will do insert one by one that mean context switching is more to server i.e 1 lakh.
    If i use BULK COLLECT+ FORALL then in a single switch the lakh records will be inserted right?
    I agree that when we have less number of records to insert we can prefer insert into select, if we have huge data then why not FORALL ?
    You have just tested for 107 records, but in huge data it is different right?
    Thanks,
    VinodYou've misunderstood how it works, I think. When you do the "insert into ... select", Oracle works out what rows need to be inserted and does them in one fell swoop. That's 2 context switches only, with the bulk of the work being done by the SQL engine.
    When you do the BULK COLLECT + FORALL, you're telling Oracle to first identify the rows (that's two context switches straight off; one from PL/SQL to SQL and then back to PL/SQL again), load them into a collection, then loop through the collection and insert the records X rows at a time (which could be all records or whatever you set as the LIMIT on the FORALL) (again, with the context switching between PL/SQL and SQL and back again through each loop).
    Which one sounds like it does the least amount of work? Not the BULK COLLECT, right?

  • Difference between MERGE and Update/Insert

    Can anybody pls tell me what is the difference between MERGE and Update/Insert statements.

    hi vivek,
    merge is totally different than normal update and insert.Merge is a combination of update+inserrt.
    Merge statment first checks the data in your table, if data is already exists then it will try to update the data otherwise it will go for insertion.In case of normal update/insert it will not check the data directly it does the specified operation.
    So based on your requirement you have to select the best option.
    Thanks.

  • How to read and update the value of property file

    Hi,
    I am not able read the values from property file.
    Please tell me how to read and update the values from property file using Properties class
    This is my property file : - Config.properties its located in D:\newfolder
    Values
    SMTP = localhost
    Now i need to change the value of the SMTP
    New value :
    SMTP =10.60.1.9
    Pls Help me
    Thanks
    Merlin Rosina,

    Post a small (<1 page) example program that forum members can copy and run that demonstrates your problem.

  • How are attribute and text master data tables linked in SAP R/3?

    Hello,
    how are attribute and text master data tables linked in SAP R/3?
    Most tables with attribute master data like T001 for company codes,
    have a text master data table T001T (add "T" to table name).
    When looking at the content of table T001 via transaction se11,
    the text are automatically joined.
    But for some tables there is no "T"-table (e.g. table TVBUR for sales offices
    has no text table TVBURT), but in se11 you get texts. There is an address
    link in TVBUR, but the Name1, etc. are empty.
    a) Where are the text stored?
    b) How does the system know of the link?
    Hope someone can help!
    Best regards
    Thomas

    Hi Thomas
    The master and text table are not linked by name, of course, if you see the text table, it has the same key fields of master table, only it has the field key spras and the field for description.
    The link beetween the tables is done by foreign key: if you check the text table TVKBT u need to see how the foreign key for field VKBUR is done:
    -> Foreing key with table TVBUR
    -> Foreing key field type -> KEY FIELD FOR A TEXT TABLE
    ->Cardinality-> 1-:CN
    It's very important the attribute sets for Foreing key field type, if it's KEY FIELD FOR A TEXT TABLE, it'll mean the table is a text table: i.e. that mean the master table is a check table for the text table, where the foreign key type is for text table.
    U can find out the text table of master table by SE11: GoTo->Text Table
    U can fined some information in table DD08L.
    Max

  • In jdbc adapter what is the difference between insert and update insert

    in jdbc adapter what is the difference between insert and update insert
    Edited by: katru vijay on Mar 22, 2010 7:43 AM

    Please refer to this Link [Document Formats for the Receiver JDBC Adapter|http://help.sap.com/saphelp_nw04/Helpdata/EN/22/b4d13b633f7748b4d34f3191529946/frameset.htm]
    Hope this helps.
    Regards,
    Chandravadan

  • HT3281 How to download and update iso 6

    I would like to learn how to download and update iso 6 in my iPad

    If you have an iPad 1, the max iOS is 5.1.1. For newer iPads, the current iOS is 6.1.3. The Settings>General>Software Update only appears if you have iOS 5.0 or higher currently installed.
    iOS 5: Updating your device to iOS 5 or Later
    http://support.apple.com/kb/HT4972
    How to install iOS 6
    http://www.macworld.com/article/2010061/hands-on-with-ios-6-installation.html
    iOS: How to update your iPhone, iPad, or iPod touch
    http://support.apple.com/kb/HT4623
    If you are currently running an iOS lower than 5.0, connect the iPad to the computer, open iTunes. Then select the iPad under the Devices heading on the left, click on the Summary tab and then click on Check for Update.
    Tip - If connected to your computer, you may need to disable your firewall and anitvirus software temporarily.  Then download and install the iOS update. Be sure and backup your iPad before the iOS update. After you update an iPad (except iPad 1) to iOS 6.x, the next update can be installed via wifi (i.e., not connected to your computer).
    Tip 2 - If you're updating via wifi, place your iPad close to your router to preclude getting a corrupted download.
     Cheers, Tom

  • How to medium and small subclasses Taxonomy table are shown on the Portal it? Currently only display subcategories

    How to medium and small subclasses Taxonomy table are shown on the Portal it? Currently only display subcategories

    From within OEM it doesnt look possible. User defined metrics (UDM) can only return number or a string. The alertlog fetch is done via alertlogViewer.pl while being passed a couple of parameters.
    OEM does have a preliminary/rough api available at http://www.oracle.com/technology/products/oem/emx/index.html but I havent seen anyone make use of it yet.
    If you use just a web connection then you will probably run into security issues as a web server can usually only view/access stuff under their htmldoc dir.
    Seems like some non-OEM very custom code is what you seek..

  • Memory leak/overload when looping by index over a large query and updating each DB record

    I am importing a CSV file into a temporary table and then running a select query that joins my actual database table with the temporary table, looking for any changes in the data. If changes exist, the select query is looped from 1 to #recordCount# and an update is applied to each record via cfquery. It runs very quickly (much more quickly than looping the query itself), but my memory spikes and overloads after about 1500 updates are completed. I need to be able to do upwards of 20000 at a time, without killing my system. I have tried manually setting the runtime garbage collection to trigger after X number of loops, but that doesn't seem to help. I am running CF8. See below for loop example:
    <cfloop from="1" to="#updatedRecordsQuery.recordCount#" index="a">
    <cftry>
                    <cfquery datasource="#db#" name="doUpdate">
                        UPDATE
                            CI
                        SET
                            firstname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#updatedRecordsQuery.firstname[a]#" />,
                            lastname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#updatedRecordsQuery.lastname[a]#" />,
                            etc, for about 15 various fields
                        FROM
                            client_info CI
                        WHERE
                            CI.client_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#updatedRecordsQuery.client_id[a]#" />
                    </cfquery>
                    <cfcatch type="database">
                        <cfset local.updateErrorList = listappend(local.updateErrorList,updatedRecordsQuery.client_id[a]) />
                        <cfset local.error = true />
                    </cfcatch>
               </cftry>
    </cfloop>

    I would suggest to use select update instead of looping over query object and update each row one-by-one.
    Procedure:
    - Insert your CSV data into temp table.
    - Use a select update SQL query to update the changed data instead of looping over a select query.
    Example:
    UPDATE
       Table
    SET
       Table.col1 = other_table.col1,
       Table.col2 = other_table.col2
    FROM
       Table
    INNER JOIN
      other_table
    ON
       Table.id = other_table.id
    NOTE: You can put all your scripts in a Procedure.

  • HOW CAN I ADD/UPDATE/INSERT IN A USER TABLE WITH MATRIX

    Hi All,
    I have one User table (Defined as No Object) and what i need to do is a form with a matrix to Add/Update/Delete data in my user table.
    I already create the form and the matrix that already give me the user table data. But now i have several problems to solve.
    First I try to add a new row but this new row get the data of the last row in the matrix. What i needed is a blank row to add new data in the user table.
    Second, when i change data in matrix and do update in the form, sap show me the message that the operation is successfully done but the data in the user table in not updated.
    I am trying to do one forma like whe can find in Setup-> General -> Freight.
    Can anyone help me?
    Best Regards,
    Luis Duarte

    Hi,
    If ur dealing with a simple form like that U can as well use the direct table form, and just provide a FMS to auto matically fill the code and name. U can directly use the form by.. Tools-->UserDefined Windows
    Or
    Comming to ur problem.... when ur adding a new row clear the data sources so that u'll get a blank row.
    And for update the best thing to do is delete all the records in the table and again insert all the records directly from the matrix.
    Hope it helps,
    Vasu Natari.

  • How to edit and update table control into database?

    I am doing table control. Here are my codes:
    *& Report  ZHERA_TABLE2
    REPORT  ZHERA_TABLE2.
    ***&SPWIZARD: DATA DECLARATION FOR TABLECONTROL 'ZTABLE_CONTROL'
    *&SPWIZARD: DEFINITION OF DDIC-TABLE
    TABLES:   ZHERA.
    *&SPWIZARD: TYPE FOR THE DATA OF TABLECONTROL 'ZTABLE_CONTROL'
    TYPES: BEGIN OF T_ZTABLE_CONTROL,
             NAME LIKE ZHERA-NAME,
             AGE LIKE ZHERA-AGE,
           END OF T_ZTABLE_CONTROL.
    *&SPWIZARD: INTERNAL TABLE FOR TABLECONTROL 'ZTABLE_CONTROL'
    DATA:     G_ZTABLE_CONTROL_ITAB   TYPE T_ZTABLE_CONTROL OCCURS 0,
              G_ZTABLE_CONTROL_WA     TYPE T_ZTABLE_CONTROL. "work area
    DATA:     G_ZTABLE_CONTROL_COPIED.           "copy flag
    *&SPWIZARD: DECLARATION OF TABLECONTROL 'ZTABLE_CONTROL' ITSELF
    CONTROLS: ZTABLE_CONTROL TYPE TABLEVIEW USING SCREEN 1000.
    START-OF-SELECTION.
    CALL SCREEN 1000.
    *&SPWIZARD: OUTPUT MODULE FOR TC 'ZTABLE_CONTROL'. DO NOT CHANGE THIS LI
    *&SPWIZARD: COPY DDIC-TABLE TO ITAB
    MODULE ZTABLE_CONTROL_INIT OUTPUT.
      IF G_ZTABLE_CONTROL_COPIED IS INITIAL.
    *&SPWIZARD: COPY DDIC-TABLE 'ZHERA'
    *&SPWIZARD: INTO INTERNAL TABLE 'g_ZTABLE_CONTROL_itab'
        SELECT * FROM ZHERA
           INTO CORRESPONDING FIELDS
           OF TABLE G_ZTABLE_CONTROL_ITAB.
        G_ZTABLE_CONTROL_COPIED = 'X'.
        REFRESH CONTROL 'ZTABLE_CONTROL' FROM SCREEN '1000'.
      ENDIF.
    ENDMODULE.
    *&SPWIZARD: OUTPUT MODULE FOR TC 'ZTABLE_CONTROL'. DO NOT CHANGE THIS LI
    *&SPWIZARD: MOVE ITAB TO DYNPRO
    MODULE ZTABLE_CONTROL_MOVE OUTPUT.
      MOVE-CORRESPONDING G_ZTABLE_CONTROL_WA TO ZHERA.
    ENDMODULE.
    Screen 1000 codes:
    PROCESS BEFORE OUTPUT.
    *&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'ZTABLE_CONTROL'
      MODULE ZTABLE_CONTROL_INIT.
    *&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_TC_ATTR.
    *&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_COL_ATTR.
      LOOP AT   G_ZTABLE_CONTROL_ITAB
           INTO G_ZTABLE_CONTROL_WA
           WITH CONTROL ZTABLE_CONTROL
           CURSOR ZTABLE_CONTROL-CURRENT_LINE.
    *&SPWIZARD:   MODULE ZTABLE_CONTROL_CHANGE_FIELD_ATTR
        MODULE ZTABLE_CONTROL_MOVE.
      ENDLOOP.
    MODULE STATUS_1000.
    PROCESS AFTER INPUT.
    *&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'ZTABLE_CONTROL'
      LOOP AT G_ZTABLE_CONTROL_ITAB.
        CHAIN.
          FIELD ZHERA-NAME.
          FIELD ZHERA-AGE.
        ENDCHAIN.
      ENDLOOP.
    *&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_TC_ATTR.
    *&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_COL_ATTR.
    MODULE USER_COMMAND_1000.
    Please show me where to put my codes to edit(edit directly on table control fields) and update my table control(using the 'save' button)?

    Hi,
    You have to put the following code in the PBO of screen 1000.This code would make the fields editable to make changes in the table control fields directly.
    Here there are 3 transactions.For create and change transactions, the fields will be in editable mode and for display transaction,they will be non editable mode.
    DESCRIBE TABLE tb_line LINES lin.    " tb_line is the name of the internal table for the table control
      tcl_item-lines = lin.                             '' lin hold the number of lines of the internal table
    CASE sy-tcode.
        WHEN 'ZCREATE09' OR 'ZCHANGE09'.
    ***Checking if the table control is empty or not***
          IF lin NE 0.       
            LOOP AT SCREEN.
    ***To make the screen editable****
              screen-input = 1.
            ENDLOOP.
          ELSE.
            LOOP AT SCREEN.
              IF screen-name CS 'TB_LINE'.
    ****To make the screen non-editable if no values are present in the
    ***table control****
                screen-input = 0.
                MODIFY SCREEN.
              ENDIF.
            ENDLOOP.
          ENDIF.
    Once the fields are edited and the save button is pressed,the entered values have to be populated into the Z tables.The code has to written in the PAI of the screen 1000.Here the values from the work area of the internal table are moved into the Z Table. The code will be.
    LOOP AT tb_line.
        ztm09_ekpo-ebeln = ztm09_ekko-ebeln.  "ztm09_ekko and ztm09_ekpo are the names of the Z Tables.
        ztm09_ekpo-ebelp = tb_line-ebelp.   
        ztm09_ekpo-matnr = tb_line-matnr.
        ztm09_ekpo-menge = tb_line-menge.
        ztm09_ekpo-meins = tb_line-meins.
        ztm09_ekpo-netpr = tb_line-netpr.
        ztm09_ekpo-waers = tb_line-waers.
    *****Update the entries into item table*****
        MODIFY ztm09_ekpo.
      ENDLOOP.
    Reward if helpfull
    Thanks,
    Kashyap

  • How do I open and use a large table from Word in Pages?

    I upgraded my MBP from Snow Leopard to Mountain Lion a couple days ago.  I knew that my old Word application wouldn't work, but several Apple people assured me that Pages could handle my old docs, including tables.
    So, I purchased and installed Pages '09 this morning.  I opened the table I use all the time - - and most of it is missing!  Apparently, Pages doesn't handle large tables.
    I need help - desperately!  This table contains all my medical expenses for the year, so I have to have it.
    Thanks

    J,
    Besides needing to have your Table Object Floating, you should know that the maximum number of rows in Pages Tables is 999.
    If you continue to have problems opening your Word document and its table in Pages, try one of the free Office Clones, LibreOffice, OpenOffice, IBM Lotus Symphony, etc.
    I'd bet that at least one of those free apps will work if Pages doesn't. By the way, have you tried viewing your Word document in Quick Look? To do that, click on the filename in Finder and hit the Spacebar key. You won't be able to do anything but view the document in Quick Look, but it would give you confidence that your file is OK.
    Jerry

  • Updating/Inserting multiple tables

    Hi,
    I've been trying to figure out how to update/insert multiple fields in 2 different tables with one RowSet. im new to java and have been using Creator for about 2 weeks
    basically there are 3 tables: one containing user info(USER), one containing department info (DEPT), and one table relating the two (USER_DEPT). my form lets uers update, among others, their NAME in table USER, and DEPT_NAME in table DEPT.
    These are all VARCHAR types.
    I used the Clips provided by Creator to initialize and do the updating. i am using updateRow() to do the updating. the fields are bound to specific database fields. the RowSet is updatable.
    in my app i chose some specific fields, but for the sake of avoiding pasting very long SQL queries lets just say i chose everything. some of the queries i tried:
    SELECT *
    FROM USER WHERE USER.USERNAME = ?This one works.
    SELECT *
    FROM USER, DEPT, USER_DEPT
    where USER.ID = USER_DEPT.USER_ID
    and DEPT.ID = USER_DEPT.DEPT_ID AND USER.USERNAME = ?this one gives me a Conversion Error message. i have no conversion going on whatsoever. i havent even learned how to use conversion yet.
    another query i tried:
    SELECT * FROM USER
    INNER JOIN USER_DEPT ON USER.ID = USER_DEPT.USER_ID
    INNER JOIN DEPT ON DEPT.ID = USER_DEPT.DEPT_ID
    WHERE USER.USERNAME=?this one gives me no error. the app works except the database doesnt get updated. i have determined that when using this query updateRow() is skipped. i dont know why. the app keeps running in that it goes to the next page as defined by the XML, but updateRow() is never called.
    so can anyone please tell me how to update/insert multiple fields in multiple tables using one RowSet PLEASE?
    THANKS!

    The only way this can be done with a single rowset is if you do your query against a view (instead of a join), and if your JDBC driver supports updates to multiple tables through a view. Otherwise, you're going to need to update the underlying tables individually.
    Craig

Maybe you are looking for