Selecting better query from performance point of view.

Hi friends,
I have one situation which following example represents exactly.
we have a table marks.
Table Marks ( Student_No number,exam_code number, Mark_subject1 number, Mark_subject2 number, Mark_subject3 number).
What I want is to prepare a table Results in following way.
I need to insert one record for each student's each total Marks of each subject.
Like
Marks:
Student_No...........Exam_code........Mark_subject1........Mark_subject2........Mark_subject3
.........1.......................1.....................10.........................15..........................12
.........1.......................2.....................15.........................15..........................10
.........2.......................1.....................10.........................10..........................10
.........2.......................2.....................17.........................17..........................10
Then I want to populate results table with following data.
Student...................Subject..............TotalMarks
.....1.......................Subject1..................25
.....1.......................Subject2..................30
.....1.......................Subject3..................22
.....2.......................Subject1..................27
.....2.......................Subject2..................27
.....2.......................Subject3..................20
This needs to be done within one procedure.
I can do it by two ways.
1)
insert into Results select student_no, 'Subject1',sum(Mark_Subject1) from marks group by student_no;
insert into Results select student_no,'Subject2',sum(Mark_Subject2) from Marks group by student_no;
insert into Results select student_no,'Subject2',sum(Mark_Subject3) from Marks group by student_no;
2)
For i in (select student_no,sum(mark_subject1) sub1, sum(mark_subject2) sub2, sum(mark_subject3) sub3 from marks)
loop
insert into Results values(i.student_no,'Subject1',i.sub1);
insert into Results values(i.student_no,'Subject2',i.sub2);
insert into Results values(i.student_no,'Subject3',i.sub3);
end loop;
If we use first way, 3 times the table will be accessed and will be processed (sorted) for "grouped by" and all the resultant data will be inserted.
If we use second way, the marks table will be accessed and processed for group by for only once. But for each record of result set, 3 inserts will be done.
I am confused about which would be better way provided the number of records in marks table is around 1,00,000.
Please help me deciding the better way.
Regards,
Dipali..

I would avoid cursor for loops if at all possible.

Similar Messages

  • Which is better from performance point of view : Enum or String?

    Hello All
    While working to re-factor code so as to improve performance,I saw that repeatedly some Strings are used to be put as keys in a HashMap.
    Will there be an improvement in performance if I assign use enums in place of using double quoted strings everytime.
    Also,Is it a better idea to use string constants rather than enums.
    Can anyone help me over this?
    Thanks in advance
    Mansi

    Found an article in Java performance tuning book.But they nowhere mentioned the perfect reason for doing this.Here's the artice :
    Enumerating constants
    Another canonicalization technique often used is replacing constant objects with integers. For example, rather than use the strings "female" and "male", you should use a constant defined in an interface:
    public interface GENDER
    public static final int FEMALE=1;
    public static final int MALE=2;
    Used consistently, this enumeration can provide both speed and memory advantages. The enumeration requires less memory than the equivalent strings and makes network transfers faster. Comparisons are faster too, as the identity comparison can be used instead of the equality comparison. For example, you can use:
    this.gender == FEMALE;
    instead of:
    this.gender.equals("female");

  • Which design is best from a performance point of view?

    Hello
    I'm writing a small system that needs to track changes to certain columns on 4 different tables. I'm using triggers on those columns to write the changes to a single "change register" table, which has 12 columns. Beacuse the majority of tracked data is not shared between the tables, most of the columns will have null values. From a design point of view it is apparent that having 4 separate change register tables (one for each main table that is being tracked), would be better in terms of avoiding lots of null columns for each row, but I was trying to trade this off against having a single table to see all changes that have been made across the tracked tables.
    From a performance point of view though, will there be any real difference whether there are 4 separate tables or 1 single register table? I'm only ever going to be inserting into the register table, and then reading back from it at a later date and there won't be any indexes on it. Someone I work with suggested that there would be more overhead on the redo logs if a single table was used rather than 4 separate tables.
    Any help would be appreciated.
    David

    The volumes of data are going to be pretty small,
    maybe a couple of thousand records each day, it's an
    OLTP environment with 150 concurrent users max.Consider also the growing of data and if you'll put data constantly to an historical db or if the same tables will contain the increasing number of record.
    The point that my colleague raised was that multiple
    inserts into a single table across multiple
    transactions could cause a lot of redo contention,
    but I can't see how inserting into one table from
    multiple triggers would result in more redo
    contention that inserting into multiple tables. The
    updates that will fire the triggers are only ever
    going to be single row updates, and won't normally
    cause more than one trigger to fire within a single
    transaction. Is this a fair assumption to make?
    David
    I agree with you, the only thing I will consider, instead of redo problem, is the locking on the table that could be generated when logs of different tables will have to be put in a single table, i mean if after insert of a log record you could need to update it....
    In this case if 2 or more users have to update the same log you could have problems.

  • Performance tuning from Basis point of View ?

    Hi,
    Can anybody help me in doing the performance tuning from Basis point of view.
    What all parameters are involved in it and what are the values need to be initially assigned and what all factors need to be kept in mind.?
    Thanks in advance.

    wrong forum??
    not a security related question??

  • Please validate my logic performance point of view:

    Please validate my logic performance point of view:
    logic I wrote :
       LOOP AT i_mara INTO wa_mara.
    *-----For material description, go to makt table.
          SELECT SINGLE maktx
            FROM makt
            INTO l_maktx
           WHERE matnr = lwa_mara-matnr
             AND SPRAS = 'E'.
          IF sy-subrc = 0.
            wa_mara-MAKTX = l_maktx.
          ENDIF.        " IF sy-subrc = 0.
    *-----For Recurring Inspection, go to marc table.
          SELECT prfrq
            FROM marc
            INTO l_prfrq
            UP TO 1 ROWS
           WHERE matnr = lwa_mara-matnr.
          ENDSELECT.
          IF sy-subrc = 0.
            wa_mara-prfrq = l_prfrq.
          ENDIF.          " IF sy-subrc = 0.
          MODIFY TABLE i_mara FROM wa_mara
                 TRANSPORTING maktx.
          CLEAR : wa_mara.
       ENDLOOP.   " LOOP AT i_mara INTO wa_mara.
    Or is it better below : ?
    To SELECT all the maktx values from makt and all prfrq values from marc
    in two internal tables and
    Loop at i_mara.
      LOOP at all maktx itab
    and pass corresponding maktx values into i_mara table
    and pass corresponding prfrq values into i_mara table
    ENDLOOP.
    OR
    is there any better performance logic you suggest ?
    THANKS IN ADVANCE.

    ok this is very funny so if someone gets a good way to code he should wait till he gets 1198 points till he write a performance wiki
    so that means ppl who has high SDN points only can write wiki
    for your information wiki definition is
    [http://en.wikipedia.org/wiki/Wiki |http://en.wikipedia.org/wiki/Wiki]
    its all about contribution and sharing.
    did you try that code on a production or a Quality server. If you did you wont say that coz the results i have shown in that blog is what i my self tested on a Quality system of our client.
    and for your information i did my internship at a SAP AFS consultancy firm and i created the account at that time. I have joined that company and now working as a developer over there.
    if you have worked on a client system development on SD and MM you will know that most of the time
    we use header and item tables like
    likp,lips
    vbak,vbap
    vbrk,vbrp
    most of the time we come across nested loops with smiler kind of condition.
    in this Q he has MATNR as reference.
    if you see it properly you can see both tables are sorted.
    and the select statement is for all entries.
    for your information there can be a delivery document item with out a header if you are aware of DB concepts in that case there will be a foreign key error.
    ok lets think about a situation like that even in that case if there ant any header data then simply the client wont request for that record.( you would know if you have worked with clients )
    last but not least i dont care about my points rate at SDN i just wanted to share what i know coz anyway i have a very good job here. dont try to put down ppl just because they are new.
    Thomas Zloch  : i never told its my code i saw it some where then i checked and i bogged it so that i can get it when i want and i saw it in se30 ( its not se38 ) but i know most of ABAP developers dont check it much so i just wanted to help.
    Rui Pedro Dantas   : ya your correct we dont need to use it most of the time since sorted table is easy but there are programs which works with bulky data load we can use it in places like that. Thanks for talking the truth
    Nafran
    sorry if i said anything to hurt anyone.

  • Client Merge! precautions to be taken from BW point of view

    Hi,
    We are in a process of merging two clients in R/3 which are typical source systems for BW!
    What are the steps that we should take care of while the client merge is on from R/3 side.
    these two clients are ofcourse very important for BW system as almost all for everydata load the extraction logic in FM to the ABAP routine in selection of infopacakge is different!
    in a scenario such as this, what are the things that should i make a note from BW point of view?
    Raj

    Hi,
    1.Internal table with header line will not support in ECC 6.0 for that u need to create internal table and work area using TYPES.
    2.Mostly u need to do some PATCH WORK for the STANDARD programmes.
    Patch work in the sense for SPAU objects in Mysap is there any code written by client(INSERT {....END INSERT....}) this type of code u need to add in ECC 6.0 code....
    3.Mostly u have to resolve EPC(Extended program check) errors.
    In that u will find so many type of errors...Field attribute errors,Perform interface errors,Obsolete stetement errors,....etc.
    4.First thing u need to what r the SCOPE and OUT OF SCOPE in your upgradation.
    5.If u find any Fmodules obsolete...U just press F1 on that Fmodule it will show which function module can useful instead of that obsolete one...
    6.If they want UNI CODE compatiable .....
    EX Report...
    Go to the attributes of the report...
    There u can c a check box to check UNI CODE Errors...
    U have to resolve these errors also...
    After doing all these things u have to show 0 errors on CODE INSPECTOR fro each n every object...
    Thats t as per my knowledge...
    Regards,
    Kishore Reddy.

  • Batch managment from MM point of view

    Dear Friends,
    I want to learn the Batch management from MM  point of view.
    Can you please provide me the material which will explain me how to configure the SAP system for batch managment from MM point of view.
    Thanks a lot
    Nilesh

    Please check these answered links:
    Batch management
    batch management
    Batch Management
    Edited by: Afshad Irani on Jun 14, 2010 3:15 PM

  • Performance point of view

    Hi every one,
    I am new to XI . I have a small doubt in Mappings.
    In XI we have 4 types of mappings:
    1.Graphical mapping
    2.XSLT mapping,
    3.Java Mapping
    4.ABAP mapping
    In case of performance point of view which one is best .
    Plz explain me in details .
    I will give full points for correct answers.
    Thanks and Regards,
    P.Naganjana Reddy

    Hi,
    refer to these links:
    Re: Why xslt  mapping?
    http://searchsap.techtarget.com/tip/0,289483,sid21_gci1217018,00.html
    /people/r.eijpe/blog/2006/02/20/xml-dom-processing-in-abap-part-iiib150-xml-dom-within-sap-xi-abap-mapping
    /people/sravya.talanki2/blog/2006/12/27/aspirant-to-learn-sap-xiyou-won-the-jackpot-if-you-read-this-part-iii
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8a57d190-0201-0010-9e87-d8f327e1dba7
    Regards,
    Nithiyanandam

  • Need information on MDX queries from beginners point of view

    Hi Gurus,
    I am working in BI 7. Till now I am untouched with the basics of MDX and its syntaxes except with the T-Code MDXTEST
    Can anyone forward me the docs or links to learn MDX from beginners point of view.
    Regards,
    Srinivas

    Hi Srini,
    /people/prakash.singh4/blog/2005/03/12/get-bw-data-in-portal-via-jca-using-mdx-statement
    Tables in R/3 what in BW?
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/ed8c3c59021315e10000000a114084/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/64/9b8f3c855f0454e10000000a11405a/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/45/f33574fee1487f9b8487d2986a2658/frameset.htm
    /message/4683448#4683448 [original link is broken]
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/60f35908-ecd4-2910-6c89-e75e1054d9d1
    /people/prakash.darji/blog/2006/09/04/work-with-xmla-web-service-for-bi-data-in-external-applications
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/60f4cabe-0401-0010-fbba-fae6c7a8d29e
    Regards,
    Vijay

  • Movement   types  from  sd  point of view

    does somebody have a list of movement  types   and   some  document   explaining  what  movement types  are  meant for   what?  from  sd  point of  view
    thank
    s.r.c
    [email protected]

    Movement types
    Any movement of stock in SAP has a movement type , u can see the movement types in  T:code: OMJJ
    As such a movement type is not directly related to any order type. But the combination of
    order type + item category group ==> item category
    now
    item category + MRP type ( from mat master) --- > Schedule line category.
    The movement type is linked with schedule line category. As a thumb rule all Movement types from 601 to 699 belong purely to SD.
    If u want to c the movement type related to that particular order go with the following path.
    Hit the icon 'schedule line for the item' , in the following screen hit 'procurement push button' there u will find the movement type.
    For each material movement, the system uses the movement type to determine the rules for updating the stock quantities and the stock values in the relevant G/L accounts.
    http://help.sap.com/saphelp_40b/helpdata/ru/fc/6cec6eb435d1118b3f0060b03ca329/content.htm
    601 Goods issue for delivery (Shipping)
    In Shipping, this movement type is created automatically with the Goods issue for delivery function.
    The quantity is taken from unrestricted-use stock.
    Possible special stock indicators:
    E, K, Q
    603 Goods issue for stock transport order (Shipping) with additional
    item
    If you issue goods for a stock transport order in Shipping using movement type 641, you can use this movement type to assign an extra item to the order.
    The ordered material is transferred to the stock in transit of the receiving plant. The material for the additional item is transferred from unrestricted-use stock in the issuing plant to stock in transfer in the receiving plant.
    You can also use this movement type without referencing a purchase order.
    Possible special stock indicators:
    None
    See also: 303, 641
    605 Goods receipt for a stock transport order (Shipping) with
    additional item
    You can use this movement type to transfer into unrestricted-use stock the material you posted into stock in transfer in the receiving plant using movement type 603. You post the goods movement with reference to the purchase order (if available) or the delivery.
    Possible special stock indicators:
    None
    See also: 305 and 641
    621 Transfer posting unrestricted-use - returnable packaging (Shipping)
    The quantity is transferred from unrestricted-use stock to the returnable packaging stock at customer.
    Possible special stock indicators:
    none
    623 Goods issue from returnable packaging stock at customer (Shipping)
    This quantity is withdrawn from unrestricted-use returnable packaging stock at the customer.
    Possible special stock indicators:
    V
    631 Transfer posting unrestricted use - customer consignment stock (Shipping)
    The quantity is transferred from unrestricted-use stock to consignment stock at customer.
    Possible special stock indicators:
    E, Q
    633 Goods issue from customer consignment (Shipping)
    The quantity is withdrawn from unrestricted-use consignment stock at the customer.
    Possible special stock indicators:
    W
    641 Goods issue for a stock transport order (Shipping)
    The quantity is transferred using a delivery in Shipping from unrestricted-use stock of the issuing plant to stock in transit of the receiving plant.
    The goods receipt for the stock transport order takes place using movement type 101 and can, if required, refer to the purchase order or to the delivery. If a purchase order item is flagged as a returns item in the stock transport order, you can post the goods receipt of the returns in the issuing plant with movment type 671.
    Possible special stock indicators:
    E, Q
    For the special stock indicators E and Q and for purchase orders assigned to an account, you must ensure that the quantity is not posted to the stock in transit of the receiving plant.
    See also: 351, 643, 671
    643 Goods issue for a cross-company stock transport order (Shipping)
    It is used only for cross-company stock transport orders with SD billing and invoice. The quantity is withdrawn from the unrestricted-use stock of the issuing plant. No stock in transit is created here. In the second step, the goods receipt must be entered in the receiving plant. If a purchase order item is flagged as a returns item in the stock transport order, you can post the goods receipt of the returns in the issuing plant with movment type 673.
    Possible special stock indicators:
    E
    See also: 351, 641, 673
    645 Goods issue for a cross-company
    stock transport order in one step (Shipping)
    Unlike movement type 643 when a goods issue is posted using movement type 645, a goods receipt line is generated automatically 101). If a purchase order item is flagged as a returns item in the stock transport order, you can post the goods receipt of the returns in the issuing plant with movment type 675.
    Possible special stock indicators:
    E
    See also: 675
    647 Goods issue for a stock transport order in one step
    (Shipping)
    Unlike movement type 641 when a goods issue is posted using movement type 647, a goods receipt line (movement type 101) is generated automatically in the receiving plant. If a purchase order item is flagged as a returns item in the stock transport order, you can post the goods receipt of the returns in the issuing plant with movement type 677.
    Possible special stock indicators:
    E, Q
    See also: 677
    651 Returns from customer (Shipping)
    Using movement type 651, you post returns from a customer with a return delivery in Shipping to blocked stock returns.
    Possible special stock indicators:
    None
    See also: 451, 453, 653
    653 Returns from customer (Shipping) to unrestricted-use stock
    With this movement type you post returns from the customer with returns delivery via Shipping directly to the valuated stock.
    Possible special stock indicators:
    E
    See also: 451, 453, 651
    655 Returns from customer (Shipping) to stock in quality inspection
    With this movement type you post returns from the customer with returns delivery via Shipping directly to the valuated stock.
    Possible special stock indicators:
    E
    See also: 451, 453, 651
    657 Returns from customer (Shipping) to blocked stock
    With this movement type you post returns from the customer with returns delivery via Shipping directly to the valuated stock.
    Possible special stock indicators:
    E
    See also: 451, 453, 651
    661 Returns to vendor via Shipping
    As with movement type 502, a return delivery to the vendor is entered without reference to the purchase order, but the goods issue is posted via a delivery in Shipping.
    Possible special stock indicators:
    E
    671 Returns for stock transport order via Shipping
    If a purchase order item is marked as a returns item in a stock transport order using movement type 641 when a goods receipt for a stock transport order ( 101) is posted, the return is posted to stock in transit using movement type 161. When the return arrives, the issuing plant posts the goods receipt for the return using movement type 671. Movement type 671 (like movement types 352 and 642) reduces the receiving plant's stock in transit and increases the issuing plant's unrestricted-use stock.
    Possible special stock indicators:
    E, Q
    673 Returns for cross-company stock transport order
    (Shipping)
    673.
    Possible special stock indicators:
    675 Returns for cross-company stock transport order
    (Shipping) in one step
    677 Returns for stock transport order in one step (Shipping)

  • Interview Questions for MTO from SD point of view

    Dear SAP Experts,
    I would like to know in detail the Interview Questions for MTO from SD point of view.
    Thanks
    Bhushan

    Hi,
    Since MTO is more a conceptually driven scenario first you need to understand what exactly happens in a business.
    1) Be clear on the strategy groups.
    2) Be clear on the cost center assignments since sales order is cost object in case of MTO
    3) So you need FI interface idea to execute MTO process.
    4) Understand how the SD is informed after the production is completed for an MTO order.
    5) Understand the movement types involved, since sometimes it may be required that this special stock may be needed to sent to unrestricted or perhaps assign it to some other sales order.
    6) Know clearly about requirement type since thats the key which identifies an MTO order.
    Make sure you als read the library. Hope it helps.
    regards
    sadhu kishore

  • Plant from FICO Point of View?

    Dear Members,
    can somebody tell me the purpose and importance of the plant from FICO point of view.
    what parameters will decide about how many plants an organisation can have.
    what implecations can a plant has from taxes view point.
    regards,
    sashi.

    You already posted this yesterday. > Plant from FICO Point of View?
    Do not repost. Respect Forum rules.

  • Can any body  tell me about  sap-plm  from  technical point of view

    In sap-plm from the development point of view what abapers task

    Hi Prasoon,
    PLM very wide area but from ABAP point of view it depends which area you are working on, like it includes Bill of Materials, Document Management System, Classifications, Product Structure Browser, Engineering Change Mangement, etc within R/3 and apart from this it even includes Project System
    on Web application Systems it includes Collaboration Projects & Collaboration Folders.
    ABAP work comes for enhancements, Functional Modules, User Exists, Feild Exists, Interfaces(RFC) for CAD Integrations etc, & Reports like ALV etc.
    It Depends which part of PLM you are working on & what is the requirement where in ABAP development is required so in general it is difficult to answer this question but for any particular/specific requirements anybody will answer.
    Hope you might have got the fair idea of PLM
    Regards
    Rehman
    Mark Useful Answers

  • Integration points among various SAP Modules from BP point of view

    Hi Everyone,
    Can anyone tell me the various integration points among various SAP Modules from BP point of view.
    I did see one thread long back but now I am not able to locate one.
    Would really appreciate your responses.
    Thanks

    FOund something on SDN

  • Specific GL accounts from consolidation point of view.

    What are the mandatory GL accounts added to operating COA from consolidation point of view.
    Please share your inputs and points will be awarded.

    All those GL accounts which your client is looking presently need to be th eGL accounts in consolidation COA.

Maybe you are looking for

  • How do I set up separate user accounts on the same computer

    I would like to set up a separate user account on the same computer with different bookmarks and favorites. Can it be done? How do you do it? Thanks, Bobby

  • Report of expiry dates for framework purchase orders

    Hi, In Standard SAP is there any report of expiry dates for framework purchase orders? Thanks & Br, Sandeep

  • Arial font not showing up

    For some reason, the font Arial is not showing up in my documents, most notably Office documents. The folder is there in my Fonts Library and the standard system fonts check out ( I ran the restore standard font function), but still it does not show

  • Application to oracle application software development competition 2009

    dear sir, i am good in sql/plsql. After seeing the message of software development competition 2009, i downloaded oracle XE , apex and now I have successsfully created an application which can handle hotel administration. I have to prepare two/ three

  • M-Audio FW1814 drivers

    Hi. Is anyone out there using this audio interface?. I have one at home with Macbook Pro 10.4.8 and 13 at a college with Intel iMacs currently on 10.4.7. Sound quality excellent, records well etc, but at work odd problems like continually having to r