Timing the Execution of Labview code

Hey Guys,
I am looking for suggestions to limit the execution time for my code, or even to time it, Idont want it to exceed say 30 seconds as the next device is carried in to be tested.  I am initialising the code,aquiring parameters from a database , running through the test sequence and writing the results back to a database. Thanks guys.
Damien

Damien,
You might get more replies by posting on the LabVIEW Board.  It gets much more traffic than this one, which is primarily for issues related to hardware counter/timer cards.
Several methods are in common use for timing code. One is to use the Tools >> Profile >> Performance and Memory menu item. This opens a window which allows you to get information about the time each VI and subVI takes to execute along with quite a bit of other useful information.  It is quite helpful for idenitfying those portions of the code which are taking the largest amount of time.  Then you can focus your efforts to improve the code where they will do the most good.  If your code does not use subVIs, (well, it should), then this will not help much.
A way to test the time of small segments of code, subVIs or not, is to include the code in a 3-frame sequence structure. The first and last frames have Tick Count functions. In the middle frame is the code under test, often inside a For loop so that it can be repeated many times to capture the time of code which may execute in nanoseconds or microseconds. After the sequence structure completes the two tick counts are subtracted to get the elapsed time for the code in the middle.  There are many posts in the LV Board about pitfalls and how to optimize this technique.
As for limiting the time, this can be more problematic.  Assuming that you are not running on a Real Time operating system, it is hard to guarantee a maximum time.  I think timed loops will report that they finished late.  The key is to break up the code so that no section takes very long.  Then a supervisory module can stop a process after any section if the total time approaches or exceeds your limit.  For example if your database is offline, you need to make sure that the code which acquires the parameters has a timeout mechanism so the program does not wait forever for data it may never get.
Lynn

Similar Messages

  • How to turn off Currency Conversion within the execution of Fox code

    Hi All:
    We have a number of custom key figures defined in a Planning Layout.
    We had wanted to define those fields as type CURR with 4 Decimals, however it appeared that 2 Decimals was the maximum we could specify.  We therefore wound up using Type FLOATING POINT with 16 Decimals.
    In some Fox code that calculates these custom key figures we then use a ROUND statement to produce values such as 3.2735000000000000.
    When this Fox code executes in debug mode, I see a generated ABAP program running which includes Include programs RUPFGENTOP and RUPFGEN00.   This program executes a Form F_00001, which is essentially the Fox code. Here I can see the ROUND statement producing the desired result.  Right after though a Form TCURX_CONVERSION executes, which often reintroduces all 16 decimals, and I might get values, such as 3.2735000000000001 or 3.2734999999999998.   These small fractions cause other issues later on in the process.
    In our case we are not trying to convert an amount from one currency to another, so we don't understand why it even would try to do a currency conversion.
    My question:  is there any way to "turn off" this currency conversion routine?
    Please advise - any suggestions would be most welcome.
    Many thanks in advance,
    Robert van der Kam

    Hi Robert,
    the solution suggested by Anass only works for key figures of type number. For key figures of type amout or quantity it is not allowed to change the number of decimals. Especially for amounts the number on the DB can only be intepreted correctly knowing the currency. Depending on the currency the value 1 on DB may be 100. This is why the FOX does the TCURX_CONVERSION, a better word would be currency shift since currency values have to be scaled depending on the values maintained in table TCURX. Since FOX needs one common number type for calculations the shift is neccessary.
    This is the reason why amounts have only 2 decimals on DB, the real number of decimals comes from TCURX; no entry there means 2 decimals, i.e. not scaling is neccessary. This is why changing the number of decimals via domains might corrupt all data.
    It seems that you are using release 7.0x, in releases 7.3x internally uses DECFLOAT data type, thus the 'problems' coming from binary arithmetic in ABAP FLOAT will not occur any more.
    Regards,
    Gregor

  • I am looking to replace the hypertermi​nal with labview code

    I am trying to replace the hyperterminal with labview code. I am getting visa read error. Please provide me the sample code or let me know where I can find the sample code?
    Thanks
    Jey
    Attachments:
    SERIAL_READ.vi ‏50 KB

    Jey,
    here is my hyperterm replacement, I use it for first serial tests on new devices.
    It's maybe more than you need and not even documented.
    It's in LabVIEW 7.1 now (was 6.1), and this new serial assistant looks even more powerful than this, however I haven't used the assistant (started with LV3.1 ;-)
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'
    Attachments:
    Serial tester.llb ‏196 KB

  • A question about the execution order of java code

    I have a question about the order of the execution of java code.
    class myclass
    String str1 = new String("str1");
    static String str2 = new String("str2");
    static
    String str3 = new String("str3");
    myclass( )
    String str4 = new String("str4");
    static myfuntion()
    String str5 = new String("str5");
    When I new a myclass object, what is the order of execution about str1,str2.str3 ,str4?
    When I run myclass::myfunction( ) instead of new a myclass object what is the execution order about str1, str2, str3, str4, str5?
    Thanks

    hello,
    I think there may be one thing can't use println to make sure.
    class myclass
    static {  System.out.println("str1");   };
    myclass() { System.out.println("str2"); }
    then str1 appear before str2
    class myclass
    static {  String str1 = new String("str1"); };
    myclass() { String str2 = new String("str2"); }
    then
    str1 initilized before str2,
    str1 get the value str1----->after<----- str2.
    Am I right or wrong?

  • How to optimize the performance of this code ?

    I've two Movie clips on a flash project. One of them is fixed and the other can be moved by arrow buttons on the keyboard. The two Movie clips have irregular shapes, so HitTestObject and HitTestPoint doesn't work very well. I've a function that detects collision of two movie clips using bitmap. I wanted to update the position of the movable Movie clip so I put the collision detection function under the code of ENTER_FRAME event listener. It works very well, but when I add many fixed movie clips  ( about 10 fixed movie clips in one frame ), the game (.swf file) becomes slower and the performance of the PC becomes slower. I thought that my collision detection function has a negative effect on PC performance so I used the class on this page : https://forums.adobe.com/thread/873737
    but the same thing happens.
    Would you tell me how to speed up the execution of my codes ?
    Here is part of my code :
    stage.addEventListener(Event.ENTER_FRAME, myOnEnterFrame);
    function myOnEnterFrame(event:Event):void
      if (doThisFn) // doThisFn is a variable to allow or prevent the movable movie clip form being moved with keyboard arrows
      if ( left && !right ) {
      player.x -= speed;
      player.rotation = player.rotation - speed ;
      if( right && !left ) {
      player.x += speed;
      player.rotation = player.rotation + speed ;
    if( up && !down ) {
      player.y -= speed;
    if( down && !up ) {
      player.y += speed;
    // The fixed movie clips are wall1 ,wall2 , wall3 , wall4 , ... and so on
    // the following code checks how many walls exists on each frame and pushes them into the wallA  array
      for(var i:int=0;i<1000;i++) // We can put up to 1000 wall object into the wallA array
      if(this['wall'+i]) // If the object wall exists, push it into the wallA array
      wallA.push(this['wall'+i]);
      for(i=0;i<wallA.length;i++)
      if( h.hitF (player , wallA[i] ) || gameOverTest ) // This code checks if the player ( the movable movie clip ) hits the walls or not
      trace ( "second try" ) ;
      gameOver.visible = true ;
      doThisFn = false ;
    //I think the following codes are easy to excite and run. I think the performance issue is due to previous codes.
      if (player.hitTestObject(door))
      win.visible = true ;
      doThisFn = false ;
      if (key) // if there is a key on frame
      if (player.hitTestObject(key))
      key.visible = false ;
      switch( currentFrame )
      case 4:
      wallA[0].visible = false ;
      wallA[0].x = 50000;
      break;
      case 5:
      wall14.play();
      wall8.x = 430 ;
      break;

    it's a simple question that usually has no simple answer.
    here's an excerpt from a book (Flash Game Development: In a Social, Mobile and 3D World)  i wrote.
    Optimization Techniques
    Unfortunately, I know of no completely satisfactory way to organize this information. In what follows, I discuss memory management first with sub-topics listed in alphabetical order. Then I discuss CPU/GPU management with sub-topics listed in alphabetical order.
    That may seem logical but there are, at least, two problems with that organization.
    1. I do not believe it is the most helpful way to organize this information.
    2. Memory management affects CPU/GPU usage, so everything in the Memory Management section could also be listed in the CPU/GPU section.
    Anyway, I am going to also list the information two other ways, from easiest to hardest to implement and from greatest to least benefit.
    Both of those later listings are subjective and are dependent on developer experience and capabilities, as well as, the test situation and test environment. I very much doubt there would be a consensus on ordering of these lists.  Nevertheless, I think they still are worthwhile.
    Easiest to Hardest to Implement
    1.  Do not use Filters.
    2.  Always use reverse for-loops and avoid do-loops and avoid while-loops.
    3.  Explicitly stop Timers to ready them for gc (garbage collection).
    4.  Use weak event listeners and remove listeners.
    5.  Strictly type variables whenever possible.
    6.  Explicitly disable mouse interactivity when mouse interactivity not needed.
    7.  Replace dispatchEvents with callback functions whenever possible.
    8.  Stop Sounds to enable Sounds and SoundChannels to be gc'd.
    9.  Use the most basic DisplayObject needed.
    10. Always use cacheAsBitmap and cacheAsBitmapMatrix with air apps (i.e., mobile devices).
    11. Reuse Objects whenever possible.
    12. Event.ENTER_FRAME loops: Use different listeners and different listener functions applied to as few DisplayObjects as possible.
    13. Pool Objects instead of creating and gc'ing Objects.
    14. Use partial blitting.
    15. Use stage blitting.
    16. Use Stage3D
    Greatest to Least Benefit
    Use stage blitting (if there is enough system memory).
    Use Stage3D.
    Use partial blitting.
    Use cacheAsBitmap and cacheAsBitmapMatrix with mobile devices.
    Explicitly disable mouse interactivity when mouse interactivity not needed.
    Do not use Filters.
    Use the most basic DisplayObject needed.
    Reuse Objects whenever possible.
    Event.ENTER_FRAME loops: Use different listeners and different listener functions applied to as few DisplayObjects as possible.
    Use reverse for-loops and avoid do-loops and while-loops.
    Pool Objects instead of creating and gc'ing Objects.
    Strictly type variables whenever possible.
    Use weak event listeners and remove listeners.
    Replace dispatchEvents with callback functions whenever possible.
    Explicitly stop Timers to ready for gc.
      16. Stop Sounds to enable Sounds and SoundChannels to be gc'd.

  • How to optimize execution time for code

    Please suggest the way as i m new to performance tuning for reducing the execution time of code . Related document to performance tuning is appreciable .also tell how to work with Tcode ST05 .
    Thanks in advance

    Please Read before Posting in the Performance and Tuning Forum
    Thread locked.
    Thomas

  • How can i execute in the same block diagram two separate labview codes each one with diferent execution timings?

    Hello guys. I have been trying to solve this by a long time now...but i cant solve it....
    I have my main code in labview beying executed in one timed loop of 1second.....but now i need to pulse a lazer very fast than one second...
    my ideia was like executing the lazer pulse code in paralel with the main code but with a mutch faster timed loop....but when i put the second timed loop outside of the main one....it hapens that the aplication keeps runing only the faster loop and the main loop doesnt run....
    I really dont know how to solve this....
    many thanks
    JOSE

    JOSE,
    your code is really difficult to read. Please do some cleanup work, your diagram should be only little larger than an average computer screen. What I have glanced so far is that your code has a lot of beginner mistakes (overuse of local variables).
    For multi-loop applications, you shoul have a look at the tutorials concerning Producer-Consumer design pattern. The quick and dirty approach is to use locals (a bit contradictonary to suggest using locals here after I stated an overuse of them). The drawback will be, that you lose the latch mechanism of the button and must code it on your own (and make a big set of mistakes, using locals always attracts race conditions). Most important is that you write to your button only once, after all loops have finished spinning.
    Felix
    www.aescusoft.de
    My latest community nugget on producer/consumer design
    My current blog: A journey through uml

  • Execution time optimizing labview code

    Hi,
    I would like to optimize my labview program. Is there a way I can plot
    the execution time of my program as a function of some parameter I am
    changing in my program. I was thinking of placing the entire program in
    a while loop and then changing the parameter during each loop iteration
    and then outputting the time that the program takes to execute as a
    function of the parameter. The problem is how would I obtain the
    execution time.
    Thank you,
    -Tim

    Here a re a few more tips:
    Running on a typical multipurpose OS will will make things a bit unpredictable because you never know what else is running so you should always repeat each run many times (then take the fastest, not the average, of all corresponding times).
    Make sure that each run takes a few hundred milliseconds to get accurate values.
    For timing purposes, it might be worth to temporarily raise the execution priority. The results will be much more reproducible (at the expense of useablility).
    LabVIEW Champion . Do more with less code and in less time .

  • Labview code for closing the command window

    Hi,
    This is naveen.Actually we are using 3rd paty test software for our mobile hardware testing which creates an DOS or Command window after execution.We have automated to execute this software using labview.the problem we facing is that we couldn't run the test software unless we close or kill the dos window opened in the previous run.So i like to know whether you have any labview code for closing or killing the DOS window ,i request you help me in this regard.
    regards,
    Naveen 

    Use the System Exec VI Owning Palette: Libraries & Executables VIs and Functions.
    And take a look here http://www.tech-recipes.com/rx/446/xp_kill_windows_process_command_line_taskkill/
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • How to find the Execution Time for Java Code?

    * Hi everyone , i want to calculate the execution time for my process in java
    * The following was the ouput for my coding,
    O/P:-
    This run took 0 Hours ;1.31 Minutes ;78.36 Seconds
    *** In the above output , the output should come exactly what hours , minutes and seconds for my process,
    but in my code the minutes are converted into seconds(It should not)...
    * Here is my coding,
        static long start_time;
        public static void startTime()
            start_time = System.currentTimeMillis();
        public static void endTime()
            DecimalFormat df = new DecimalFormat("##.##");
            long end_time = System.currentTimeMillis();
            float t = end_time - start_time;
            float sec = t / 1000;
            float min = 0, hr = 0;
            if (sec > 60) {
                min = sec / 60;
            if (min > 60) {
                hr = min / 60;
            System.out.println("This run took " + df.format(hr) + " Hours ;"+ df.format(min) + " Minutes ;" + df.format(sec) + " Seconds");
        }* How to Calcualte exact timing for my process....
    * Thanks

    * Hi flounder, Is following code will wotk perfectly?
         public static void endTime()
              DecimalFormat df = new DecimalFormat("##.##");
              long end_time = System.currentTimeMillis();
              float t = end_time - start_time;
              float sec = t / 1000;
              float min = 0, hr = 0;
              while(sec >= 60){
         min++;
         sec = sec -60;
         if (min >= 60){
         min = 0; //or min = min -60;
         hr++;
              System.out.println("This run took " + df.format(hr) + " Hours ;"+ df.format(min) + " Minutes ;" + df.format(sec) + " Seconds");
         }

  • I am trying to have some LabVIEW code called in a New thread exit when the testStand sequence terminates

    I have a Sequence that launches a sequence in a New Thread that happens to launch some LabVIEW code.  The problem is when the LabVIEW code finishes, it will not close even when the TestStand sequence terminates. Is there a way to tell this LabVIEW code to Exit, I've tried the Quit LabVIEW function, but that causes a C++ RunTime Error.  The LabVIEW code does end though, and it is set in the VI properties to:
    Checked - Show Front Panel When Called
    Checked - Close Afterwardds if originally closed
    The sequence call that the LabVIEW code is launched from has the following options:
    - New Thread
    Unchecked - Automatically wait for the thread to complete at the end of the current sequence
    Unchecked - Initially Suspended
    Unchecked - Use single threaded apartment
    Any clues on this would be appreciated.

    Hi ADL,
    Everything should close correctly if you check the checkbox "Automatically wait for the thread to complete at the end of the current sequence" in the thread settings.
    With it unchecked, I am seeing the behavior you are. 
    Gavin Fox
    Systems Software
    National Instruments

  • Is there a way to determine the equivalent ANSI C code from a Labview project?

    I'm a complete beginner to Labview.  I have this fairly complex Labview project that was used to create a DLL which matlab could call to control my PCI-6534 card without having to know the NIDAQmx calls.
    I'm in the process of figuring out how to make those NIDAQmx calls directly from Matlab but I'm not getting the same results as when I call this DLL mentioned above so I thought I'd try to make sense of the Labview project VIs.  I'm starting to make sense of the overall scheme of the VIs, but I'd like to be able to run the project, step through it, and perhaps see the NIDAQmx commands (or something equivalent so I can determine how to call the NIDAQmx commands within Matlab).
    Is this possible to do?
    Thanks,
    Jason
    Solved!
    Go to Solution.

    Yes. The toolbar allows you to turn on highlighting so you can run the VI and see the contents of wires. You can put probes on wires. You can single-step through code. All of this is explained in the LabVIEW Help under Fundamantals -> Running and DEbugging VIs -> Concepts -> Debugging Techniques.
    In regards to the implied question in the title of your post, no you cannot directly convert LabVIEW code to C in the development environment. Yes, there are tools to convert LabVIEW to C, but that's intended for microprocessors.

  • N unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    some one can help me please
    i have no idea what i must to do.
    an unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    The Exception Handler gave all the info that you need. No need to print the whole stack trace.
    The exception handler says
    Exception Details: java.lang.IllegalArgumentException
    TABLE1.NAME
    Look in the session bean (assuming that is where your underlying rowset is). Look in the _init() method for statements similar to the following:
    personRowSet.setCommand("SELECT * FROM TRAVEL.PERSON");
    personRowSet.setTableName("PERSON");
    What do you have?

  • How to send data to labview code at run time while using with (or executing the sequence)the teststand

    Hello
    I am new to the Teststand.
    I am using labview8.0 with teststand 3.1
    I have developed some labview codemodules as vi's without using the teststand utility library pallete
    Now i have to run them in teststand.
    While executing them(as a sequence) in teststand,i need to enter the data to the labview code at run time.For this labview front panel should appear as GUI or popup (while executing).Is it possible to do this without using teststand pallete.
    or i need to change the code with teststand pallete(i think it is difficult now to change the code)
    Plz provide a solution to this problem
    Also one more,how and where to use the 'pass by reference' option
    Thanks and Regards
      Mudigondla

    Hi,
    see your other post http://forums.ni.com/ni/board/message?board.id=330&message.id=13914
    Also, you can, specify to display the front panel of your VI when you specify your VI in your sequence file.
    There are examples, for dialog panel using LabVIEW, in the examples folder of TestStand and on the NI Web Site.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Improve the execution of code

    hi,
    i given my program. can any one tell me how to improve the execution speed of this program. it is working very slow in quality system.
    *& Report  ZQMRSMNMWIPRPT                                              *
    REPORT  zqmrsmnmwiprpt   LINE-SIZE 328.
    TABLES : mbew, mver, mseg, mara, mkpf, makt, zqmtsmnm,keko,ckis,marc.
    DATA: PLANT TYPE mard-werks.
    DATA : BEGIN OF it_mbew OCCURS 0,
             bwkey TYPE bwkey,
             bklas LIKE mbew-bklas,
             matnr LIKE mbew-matnr,
             salk3 LIKE mbew-salk3,
             lbkum TYPE p DECIMALS 2,
             stprs LIKE mbew-stprs,
             maktx LIKE makt-maktx,
             werks LIKE mver-werks,
             gjahr LIKE mver-gjahr,
             perkz LIKE mver-perkz,
             meins LIKE mara-meins,
             EKGRP LIKE MARC-EKGRP,
             LABST TYPE p DECIMALS 2,
             EINME LIKE MARD-EINME,
             LABST1 type p DECIMALS 2,
             EINME1 LIKE MARD-EINME,
             TOTUR type p DECIMALS 2,
             SALK1 LIKE MBEW-SALK3,
             SALK2 LIKE MBEW-SALK3,
             letztzug TYPE s032-letztzug,
             letztabg TYPE s032-letztabg,
             letztver TYPE s032-letztver,
             letztbew TYPE s032-letztbew,
             tot_1  TYPE p DECIMALS 2,
             tot_11  TYPE p DECIMALS 2,
             tot_12 TYPE p DECIMALS 2,
             menge LIKE mseg-menge,
             w_lbkum TYPE p DECIMALS 2,
             tot_2  TYPE p DECIMALS 2,
              tot_21  TYPE p DECIMALS 2,
             TOT_3  TYPE P DECIMALS 2,
              TOT_31  TYPE P DECIMALS 2,
            w_consm type p decimals 2,
             w_days  TYPE p,
             erfmg TYPE p DECIMALS 2,
             erfme LIKE mseg-erfme,
             cur_rate LIKE mbew-stprs,
             w_value TYPE i,
              w_value01 TYPE i,
             w_value1 TYPE i,
             w_value11 TYPE i,
    added by mohan on 20/08/2007
             w_value2 type i,
             w_value21 type i,
    --end of addition----
          END OF it_mbew.
    DATA: BEGIN OF it_mard OCCURS 0,
            matnr TYPE mard-matnr,
            werks TYPE mard-werks,
            labst TYPE p DECIMALS 2,
            einme TYPE mard-einme,
            labst1 TYPE p DECIMALS 2,
            einme1 TYPE mard-einme,
           END OF it_mard.
    DATA : BEGIN OF it_mver OCCURS 0,
             werks LIKE mver-werks,
             gjahr LIKE mver-gjahr,
             matnr LIKE mver-matnr,
             perkz LIKE mver-perkz,
             gsv01 LIKE mver-gsv01,
             gsv02 LIKE mver-gsv02,
             gsv03 LIKE mver-gsv03,
             gsv04 LIKE mver-gsv04,
             gsv05 LIKE mver-gsv05,
             gsv06 LIKE mver-gsv06,
             gsv07 LIKE mver-gsv07,
             gsv08 LIKE mver-gsv08,
             gsv09 LIKE mver-gsv09,
             gsv10 LIKE mver-gsv10,
             gsv11 LIKE mver-gsv11,
             gsv12 LIKE mver-gsv12,
             curr_dt(08) TYPE c,
             currdt(2) TYPE n,
             tot_1 LIKE mver-gsv01,
             tot_2 LIKE mver-gsv01,
           END OF it_mver.
    DATA: BEGIN OF it_s032 OCCURS 0,
            matnr TYPE s032-matnr,
            letztzug TYPE s032-letztzug,
            letztabg TYPE s032-letztabg,
            letztver TYPE s032-letztver,
            letztbew TYPE s032-letztbew,
            werks TYPE s032-werks,
          END OF it_s032.
    DATA: it_mbew1 LIKE it_mbew OCCURS 0 WITH HEADER LINE.
    DATA : BEGIN OF dt OCCURS 0,
             currdt(2) TYPE n,
             curryr(4) TYPE N,
             curryr1(4) TYPE N,
           END OF dt.
    DATA : currdate LIKE sy-datum,
           newdate  LIKE sy-datum.
    DATA : tot_12 LIKE mver-gsv01,
           tot_1  LIKE mver-gsv01,
           tot_2  LIKE mver-gsv01,
         TOT_3  LIKE MVER-GSV01.
    DATA :    abc TYPE p,
    w_mjahr LIKE mseg-mjahr,
           w_bwart LIKE mseg-bwart.
    DATA : w_lbkum TYPE p,
               w_101menge  TYPE P DECIMALS 2,
              w_102menge TYPE P DECIMALS 2.
    DATA : BEGIN OF it_mkpf OCCURS 0,
             budat LIKE mkpf-budat,
             mblnr LIKE mkpf-mblnr,
             MJAHR like mkpf-MJAHR,
           END OF it_mkpf.
    DATA : BEGIN OF it_mseg OCCURS 0,
             bwart LIKE mseg-bwart,
             menge TYPE P DECIMALS 2,
             mjahr LIKE mseg-mjahr,
             mblnr LIKE mseg-mblnr,
             erfmg TYPE p DECIMALS 2,
             erfme LIKE mseg-erfme,
             werks LIKE mseg-werks,
             matnr LIKE mseg-matnr,
            END OF it_mseg.
    *data: it_mseg like table of mseg with header line.
    DATA : BEGIN OF it_mseg1 OCCURS 0,
             w_diffmenge TYPE P DECIMALS 2,
           END OF it_mseg1.
    DATA : w_srno TYPE i,                  " Serial number.
           w_pagectr TYPE i,               " Page counter.
           w_linectr TYPE i.               " Line counter
    DATA: w_pos LIKE ckis-wrtfw_pos,
          w_pfx LIKE ckis-wrtfw_pfx,
          w_pos1 LIKE ckis-wrtfw_pos,
          w_pfx1 LIKE ckis-wrtfw_pfx,
          w_cost LIKE ckis-wrtfw_pos.
    data : curryr2(4) type n,
    curryr3(4) type n.
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS : BWKEY1 FOR  PLANT .
    *NO DATABASE SELECTION.
    PARAMETERS : p_kadky LIKE keko-kadky OBLIGATORY.
    *----ADDED BY MOHAN ON 20/08/2007--
    SELECT-OPTIONS : BKLAS FOR MBEW-BKLAS.
    SELECT-OPTIONS : EKGRP FOR MARC-EKGRP.
    SELECT-OPTIONS : MATNR FOR MBEW-MATNR.
    --END OF MODIFICATION--
    SELECTION-SCREEN END OF BLOCK blk1.
    SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-001.
    PARAMETERS: p_summ AS CHECKBOX.
    PARAMETERS : SUMMARY RADIOBUTTON GROUP G1,
                 DETAILS RADIOBUTTON GROUP G1.
    SELECTION-SCREEN END OF BLOCK blk2.
    SELECT F~bwkey
           F~bklas
           F~matnr
           F~salk3
           F~lbkum
           F~STPRS
           E~EKGRP
           INTO CORRESPONDING FIELDS OF TABLE it_mbew
                  FROM mbew AS F INNER JOIN MARC AS E
                  ON FBWKEY = EWERKS AND FMATNR = EMATNR
                  WHERE F~BKLAS IN BKLAS AND
                        F~BWKEY in BWKEY1 AND
                        F~MATNR IN MATNR AND
                        E~EKGRP IN EKGRP .
    *REFRESH it_mbew.
    *IF it_mbew IS INITIAL.
    *FREE it_mbew.
    *ENDIF.
    SELECT matnr
           werks
           labst
           einme  INTO CORRESPONDING FIELDS OF TABLE IT_MARD
                   FROM MARD
                   FOR ALL ENTRIES IN IT_MBEW
                  WHERE WERKS IN BWKEY1 AND
                        MATNR IN MATNR.
                   WHERE WERKS = IT_MBEW-BWKEY AND
                         MATNR = IT_MBEW-MATNR .
    SELECT werks
           matnr
           letztzug
           letztabg
           letztver
           letztbew
           INTO CORRESPONDING FIELDS OF TABLE IT_S032
           FROM S032
           FOR ALL ENTRIES IN IT_MBEW
           WHERE MATNR = IT_MBEW-MATNR and
                 WERKS = IT_MBEW-BWKEY.
    LOOP AT it_mbew.
      IF it_mbew-lbkum = 0 .
        DELETE it_mbew INDEX sy-tabix.
      ELSE.
      ENDIF.
    ENDLOOP.
    loop at it_mard.
      move it_mard-labst to it_mard-labst1.
      move it_mard-einme to it_mard-einme1.
      collect it_mard.
    endloop.
    CLEAR IT_MARD.
    LOOP AT IT_MARD.
    DELETE ADJACENT DUPLICATES FROM IT_MARD.
    MODIFY IT_MARD.
    ENDLOOP.
    CLEAR IT_MARD.
    *------MODIFIED BY MOHAN ON 21/10/2007
    LOOP AT IT_MBEW.
    READ TABLE IT_MARD  WITH KEY MATNR = IT_MBEW-MATNR
                                 WERKS = IT_MBEW-BWKEY.
      IT_MBEW-LABST = IT_MARD-LABST.
      IT_MBEW-EINME = IT_MARD-EINME.
    MODIFY IT_MBEW.
    ENDLOOP.
    --added by mohan 29/10/2007--
    SORT IT_S032 BY MATNR letztzug descending.
    read table it_s032 index 1.
    LOOP AT IT_MBEW.
      READ TABLE IT_S032 WITH KEY MATNR = IT_MBEW-MATNR
                                 WERKS = IT_MBEW-BWKEY.
      IT_MBEW-LETZTZUG = IT_S032-LETZTZUG.
      MODIFY IT_MBEW.
      clear it_s032.
    ENDLOOP.
    SORT IT_S032 BY MATNR letztabg descending.
    read table it_s032 index 1.
    LOOP AT IT_MBEW.
      READ TABLE IT_S032 WITH KEY MATNR = IT_MBEW-MATNR
                                 WERKS = IT_MBEW-BWKEY.
      IT_MBEW-letztabg = IT_S032-letztabg.
      MODIFY IT_MBEW.
      clear it_s032.
    ENDLOOP.
    SORT IT_S032 BY matnr letztver descending.
    read table it_s032 index 1.
    LOOP AT IT_MBEW.
      READ TABLE IT_S032 WITH KEY MATNR = IT_MBEW-MATNR
                                  WERKS = IT_MBEW-BWKEY.
      IT_MBEW-letztver = IT_S032-letztver.
      MODIFY IT_MBEW.
      clear it_s032.
    ENDLOOP.
    SORT IT_S032 BY letztbew descending.
    read table it_s032 index 1.
    LOOP AT IT_MBEW.
      READ TABLE IT_S032 WITH KEY MATNR = IT_MBEW-MATNR
                                  WERKS = IT_MBEW-BWKEY.
      IT_MBEW-letztbew = IT_S032-letztbew.
      MODIFY IT_MBEW.
      clear it_s032.
    ENDLOOP.
    SORT it_mbew BY matnr.
    LOOP AT it_mbew.
      SELECT SINGLE werks gjahr perkz INTO (mver-werks, mver-gjahr,
                                            mver-perkz)
                                            FROM mver
                                            WHERE matnr = it_mbew-matnr AND
                                            werks IN bwkey1.
      SELECT SINGLE meins INTO mara-meins
                          FROM mara
                          WHERE matnr = it_mbew-matnr.
      SELECT SINGLE maktx INTO makt-maktx
                          FROM makt
                          WHERE matnr = it_mbew-matnr.
      it_mbew-werks = mver-werks.
      it_mbew-gjahr = mver-gjahr.
      it_mbew-perkz = mver-perkz.
      it_mbew-meins = mara-meins.
      it_mbew-maktx = makt-maktx.
      MODIFY it_mbew.
    ENDLOOP.
    **DATA INTO INTERNAL TABLE OF IT_MVER.
    **LOGIC FOR GETTING PREVIOUS 6 MONTHS DATA.
    *ADDED BY MOHAN ON 20/08/2007
    SORT it_mbew BY matnr werks gjahr.
    LOOP AT it_mbew.
      dt-curryr = p_kadky+0(4).
      APPEND dt.
      SELECT  * INTO  CORRESPONDING FIELDS OF TABLE it_mver FROM mver
                        WHERE matnr = it_mbew-matnr AND
                              werks = it_mbew-werks
                              AND
                              perkz = 'P'.
    **LOGIC FOR GETTING PREVIOUS 6 MONTHS DATA.
      LOOP AT it_mver.
        if p_kadky+4(2) = '01'.
          dt-currdt = '10'.
          APPEND dt.
        elseif p_kadky+4(2) = '02'.
          dt-currdt = '11'.
          APPEND dt.
        elseif p_kadky+4(2) = '03'.
          dt-currdt = 12.
          APPEND dt.
        elseif p_kadky+4(2) = '04'.
          dt-currdt = '01'.
          APPEND dt.
        elseif p_kadky+4(2) = '05'.
          dt-currdt = '02'.
          APPEND dt.
        elseif p_kadky+4(2) = '06'.
          dt-currdt = '03'.
          APPEND dt.
        elseif p_kadky+4(2) = '07'.
          dt-currdt = '04'.
          APPEND dt.
        elseif p_kadky+4(2) = '08'.
          dt-currdt = '05'.
          APPEND dt.
        elseif p_kadky+4(2) = '09'.
          dt-currdt = '06'.
          APPEND dt.
        elseif p_kadky+4(2) = '10'.
          dt-currdt = '07'.
          APPEND dt.
        elseif p_kadky+4(2) = '11'.
          dt-currdt = '08'.
          APPEND dt.
        elseif p_kadky+4(2) = '12'.
          dt-currdt = '09'.
          APPEND dt.
        endif.
        IF dt-currdt EQ '01'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_3 = it_mver-gsv10 + it_mver-gsv11 + it_mver-gsv12 +
    it_mver-gsv07  +  it_mver-gsv08  + it_mver-gsv09.
          endif.
        ELSEIF dt-currdt EQ '02'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_3 = it_mver-gsv10
                 +  it_mver-gsv11 + it_mver-gsv12 + it_mver-gsv08  +
               it_mver-gsv09 .
          endif.
           if it_mver-gjahr = dt-curryr .
            tot_3 =   tot_3 + it_mver-gsv01.
          endif.
        ELSEIF dt-currdt EQ '03'.
          dt-curryr1 = dt-curryr - 1.
                if it_mver-gjahr = dt-curryr1.
            tot_3 =  it_mver-gsv10 + it_mver-gsv11 +
    it_mver-gsv12 + it_mver-gsv09.
          endif.
          if it_mver-gjahr = dt-curryr .
            tot_3 = tot_3 + it_mver-gsv01 + it_mver-gsv02.
          endif.
        ELSEIF dt-currdt EQ '04'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_3 = it_mver-gsv10 + it_mver-gsv11 + it_mver-gsv12.
          endif.
          if it_mver-gjahr = dt-curryr .
            tot_3 =  tot_3 + it_mver-gsv01 + it_mver-gsv02 + it_mver-gsv03.
          endif.
        ELSEIF dt-currdt EQ '05'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_3 =  it_mver-gsv11 + it_mver-gsv12.
          endif.
          if it_mver-gjahr = dt-curryr .
            tot_3 =  tot_3 + it_mver-gsv01 +
                it_mver-gsv02 + it_mver-gsv03 + it_mver-gsv04.
          endif.
        ELSEIF dt-currdt EQ '06'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_3 = it_mver-gsv12 .
          endif.
           if it_mver-gjahr = dt-curryr .
            tot_3 = tot_3 +  it_mver-gsv01 + it_mver-gsv02
                    + it_mver-gsv03 + it_mver-gsv04 + it_mver-gsv05.
          endif.
        ELSEIF dt-currdt EQ '07'.
         if it_mver-gjahr = dt-curryr .
          tot_3 = it_mver-gsv01 + it_mver-gsv02 + it_mver-gsv03
                  + it_mver-gsv04 + it_mver-gsv05 + it_mver-gsv06.
            endif.
        ELSEIF dt-currdt EQ '08'.
         if it_mver-gjahr = dt-curryr .
          tot_3 = it_mver-gsv02 + it_mver-gsv03 + it_mver-gsv04
                  + it_mver-gsv05 + it_mver-gsv06 + it_mver-gsv07.
           endif.
        ELSEIF dt-currdt EQ '09'.
         if it_mver-gjahr = dt-curryr .
          tot_3 = it_mver-gsv03 + it_mver-gsv04 + it_mver-gsv05
                  + it_mver-gsv06 + it_mver-gsv07 + it_mver-gsv08.
                 endif.
        ELSEIF dt-currdt EQ '10'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1 .
            tot_3 = it_mver-gsv04 + it_mver-gsv05 + it_mver-gsv06
                    + it_mver-gsv07 + it_mver-gsv08 + it_mver-gsv09.
          endif.
        ELSEIF dt-currdt EQ '11'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1 .
            tot_3 = it_mver-gsv05 + it_mver-gsv06 + it_mver-gsv07
                    + it_mver-gsv08 + it_mver-gsv09 + + it_mver-gsv10.
          endif.
        ELSEIF dt-currdt EQ '12'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1 .
            tot_3 =   it_mver-gsv06 + it_mver-gsv07 + it_mver-gsv08
                      + it_mver-gsv09 + it_mver-gsv10 + it_mver-gsv11 .
          endif.
        ENDIF.
    **MODIFYING THE VARIABLE TOT_1.
        it_mbew-tot_3 = tot_3.
        MODIFY it_mbew TRANSPORTING tot_3.
         IF dt-currdt EQ '01'.
    dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_1 = it_mver-gsv10 + it_mver-gsv11 + it_mver-gsv12.
          endif.
        ELSEIF dt-currdt EQ '02'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_1 = it_mver-gsv11 + it_mver-gsv12 .
          endif.
           if it_mver-gjahr = dt-curryr .
            tot_1 = tot_1 + it_mver-gsv01.
          endif.
        ELSEIF dt-currdt EQ '03'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_1 =  it_mver-gsv12.
          endif.
           if it_mver-gjahr = dt-curryr .
            tot_1 = tot_1 + it_mver-gsv01 + it_mver-gsv02.
          endif.
        ELSEIF dt-currdt EQ '04'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_1 = it_mver-gsv01 + it_mver-gsv02 + it_mver-gsv03.
          endif.
        ELSEIF dt-currdt EQ '05'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_1 =  it_mver-gsv01 +
                it_mver-gsv02 + it_mver-gsv03 + it_mver-gsv04.
          endif.
        ELSEIF dt-currdt EQ '06'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_1 = it_mver-gsv03 + it_mver-gsv04 + it_mver-gsv05.
          endif.
        ELSEIF dt-currdt EQ '07'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1 .
            tot_1 =  it_mver-gsv04 + it_mver-gsv05 + it_mver-gsv06.
          endif.
        ELSEIF dt-currdt EQ '08'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_1 = it_mver-gsv05 + it_mver-gsv06 + it_mver-gsv07.
          endif.
        ELSEIF dt-currdt EQ '09'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_1 = it_mver-gsv06 + it_mver-gsv07 + it_mver-gsv08.
          endif.
        ELSEIF dt-currdt EQ '10'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_1 = it_mver-gsv07 + it_mver-gsv08 + it_mver-gsv09.
          endif.
        ELSEIF dt-currdt EQ '11'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
                    tot_1 = it_mver-gsv08 + it_mver-gsv09 +  it_mver-gsv10.
          endif.
        ELSEIF dt-currdt EQ '12'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_1 = it_mver-gsv09 + it_mver-gsv10 + it_mver-gsv11.
          endif.
        ENDIF.
        it_mbew-tot_1 = tot_1.
        MODIFY it_mbew TRANSPORTING tot_1.
         if p_kadky+4(2) = '01'.
          dt-currdt = '10'.
          APPEND dt.
        elseif p_kadky+4(2) = '02'.
          dt-currdt = '11'.
          APPEND dt.
        elseif p_kadky+4(2) = '03'.
          dt-currdt = 12.
          APPEND dt.
        elseif p_kadky+4(2) = '04'.
          dt-currdt = '01'.
          APPEND dt.
        elseif p_kadky+4(2) = '05'.
          dt-currdt = '02'.
          APPEND dt.
        elseif p_kadky+4(2) = '06'.
          dt-currdt = '03'.
          APPEND dt.
        elseif p_kadky+4(2) = '07'.
          dt-currdt = '04'.
          APPEND dt.
        elseif p_kadky+4(2) = '08'.
          dt-currdt = '05'.
          APPEND dt.
        elseif p_kadky+4(2) = '09'.
          dt-currdt = '06'.
          APPEND dt.
        elseif p_kadky+4(2) = '10'.
          dt-currdt = '07'.
          APPEND dt.
        elseif p_kadky+4(2) = '11'.
          dt-currdt = '08'.
          APPEND dt.
        elseif p_kadky+4(2) = '12'.
          dt-currdt = '09'.
          APPEND dt.
        endif.
        IF dt-currdt EQ '01'.
    dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_2 = it_mver-gsv12 .
          endif.
        ELSEIF dt-currdt EQ '02'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_2 = it_mver-gsv01.
          endif.
        ELSEIF dt-currdt EQ '03'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_2 =  it_mver-gsv02.
          endif.
        ELSEIF dt-currdt EQ '04'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_2 = it_mver-gsv03.
          endif.
        ELSEIF dt-currdt EQ '05'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_2 =  it_mver-gsv04.
          endif.
        ELSEIF dt-currdt EQ '06'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_2 = it_mver-gsv05.
          endif.
        ELSEIF dt-currdt EQ '07'.
          dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
            tot_2 =  it_mver-gsv06.
          endif.
        ELSEIF dt-currdt EQ '08'.
         dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr.
          tot_2 = it_mver-gsv07.
          endif.
        ELSEIF dt-currdt EQ '09'.
         dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr .
          tot_2 = it_mver-gsv08.
          endif.
        ELSEIF dt-currdt EQ '10'.
          if it_mver-gjahr = dt-curryr1.
            tot_2 = it_mver-gsv09.
          endif.
        ELSEIF dt-currdt EQ '11'.
          dt-curryr1 = dt-curryr - 1.
         if it_mver-gjahr = dt-curryr1.
            tot_2 = it_mver-gsv10.
          endif.
        ELSEIF dt-currdt EQ '12'.
              dt-curryr1 = dt-curryr - 1.
          if it_mver-gjahr = dt-curryr1.
            tot_2 = it_mver-gsv11.
          endif.
        ENDIF.
    *****MODIFYING THE VARIABLE TOT_2.
        it_mbew-tot_2 = tot_2.
        MODIFY it_mbew TRANSPORTING tot_2.
    ENDLOOP.
    SELECT SINGLE RATE FROM ZPPTMB5L INTO W_COST
      WHERE BWKEY = IT_MBEW-BWKEY AND
            MATNR = IT_MBEW-MATNR.
        it_mbew-cur_rate = w_cost.
        MODIFY it_mbew.
        CLEAR: w_cost,marc-losgr,w_pos1,w_pfx1.
    ENDIF.
    it_mbew-w_value = it_mbew-cur_rate * it_mbew-tot_1.
      MODIFY it_mbew .
      it_mbew-w_value1 = it_mbew-cur_rate * it_mbew-tot_2.
      MODIFY it_mbew .
    --added by mohan on 20/08/2007--
      it_mbew-w_value2 = it_mbew-cur_rate * it_mbew-tot_3.
      MODIFY it_mbew .
      IT_MBEW-SALK1  = IT_MBEW-LBKUM * IT_MBEW-cur_rate.
      IT_MBEW-TOTUR  = IT_MBEW-LABST + IT_MBEW-EINME.
      IT_MBEW-SALK2  = IT_MBEW-TOTUR * IT_MBEW-cur_rate.
      MODIFY IT_MBEW.
       currdate = sy-datum.
      CALL FUNCTION 'CCM_GO_BACK_MONTHS'
        EXPORTING
          currdate   = currdate
          backmonths = '3'
        IMPORTING
          newdate    = newdate.
    curryr2 = currdate+0(4).
    curryr3 = newdate+0(4).
      SELECT matnr menge mblnr mjahr bwart werks erfmg erfme
                   INTO  CORRESPONDING FIELDS OF table it_mseg FROM mseg
                                        WHERE
                                            matnr in matnr
                                             matnr = it_mbew-matnr
                                             AND
                                             mjahr le curryr2 and
                                             mjahr ge curryr3
                                              AND
                                            bwart IN ('101','102') and
                                           mblnr = it_mkpf-mblnr.
    *change by 5-10-2007
                                            werks = it_mbew-BWKEY.
        SELECT mblnr budat mjahr INTO CORRESPONDING FIELDS OF TABLE
                     it_mkpf FROM mkpf  WHERE budat GE newdate
                                 AND
                              budat LE currdate
                              AND
                                             mjahr le curryr2 and
                                             mjahr ge curryr3.
      loop at it_mseg.
      loop at it_mkpf.
      IF it_mseg-bwart = '101' and it_mseg-mblnr = it_mkpf-mblnr.
          w_101menge = w_101menge + it_mseg-menge.
        ELSEIF it_mseg-bwart = '102' and  it_mseg-mblnr = it_mkpf-mblnr.
          w_102menge = w_102menge + it_mseg-menge.
    endif.
          it_mseg1-w_diffmenge = w_101menge - w_102menge.
      ENDLOOP.
    endloop.
      clear : w_102menge,w_101menge.
      it_mbew-erfmg = it_mseg1-w_diffmenge.
      it_mbew-erfme = it_mseg-erfme.
      MODIFY it_mbew TRANSPORTING erfmg erfme.
      IF it_mbew-tot_1 = 0.
      ELSE.
        it_mbew-w_days = it_mbew-lbkum / ( it_mbew-tot_1 / 90 ).
      ENDIF.
    it_mbew-w_days = w_days.
      MODIFY it_mbew TRANSPORTING w_days.
    ENDLOOP.
    clear  IT_MARD[].
    clear  IT_S032[].
    clear  IT_S032[].
    clear it_mard[].
    clear: it_mver,it_mver[].
    CLEAR : it_mseg1[], it_mseg1.
    clear : it_mkpf[], it_mkpf.
    clear  IT_MARD[].
    clear  IT_S032[].
    clear  IT_S032[].
    clear it_mard.
    clear : it_mseg[],it_mseg, it_mkpf[], it_mkpf.
    free : it_mseg[],it_mseg, it_mkpf[], it_mkpf.
      SORT it_mbew BY bwkey.
      LOOP AT it_mbew.
      IF p_summ = 'X'.
        MOVE it_mbew-bwkey TO it_mbew1-bwkey.
        it_mbew1-tot_1 = it_mbew-tot_1.
        it_mbew1-tot_2 = it_mbew-tot_2.
        it_mbew1-tot_3 = it_mbew-tot_3.
        it_mbew1-w_value  = it_mbew-w_value.
        it_mbew1-w_value1 = it_mbew-w_value1.
        it_mbew1-w_value2 = it_MBEW-W_VALUE2.
        COLLECT it_mbew1.
    elseif summary = 'X'.
        AT FIRST.
          w_pagectr = 1.
          PERFORM header.
        ENDAT.
        FORMAT COLOR 2 ON INTENSIFIED.
        WRITE : /01 sy-vline,
                     02 it_mbew-bwkey,                      10 sy-vline,
                     11 it_mbew-bklas,                      20 sy-vline,
                     21 IT_MBEW-EKGRP,                      27 SY-VLINE,
                     28 it_mbew-matnr+11(7),                39 sy-vline,
                     40 it_mbew-maktx,                      80 sy-vline,
                     81 it_mbew-cur_rate  CENTERED,         91 sy-vline,
                     92(13) it_mbew-lbkum right-justified,  105 sy-vline,
                    106 it_mbew-meins,                     111 sy-vline,
                    112 IT_MBEW-SALK1 left-justified,      126 SY-VLINE,
                    127(13) IT_MBEW-TOTUR right-justified,  141 SY-VLINE,
                    142 IT_MBEW-SALK2 left-justified,      156 SY-VLINE,
                   157(10) IT_MBEW-TOT_3 right-justified,  170 SY-VLINE,
                    171 IT_MBEW-W_VALUE2 left-justified,   184 SY-VLINE,
                   185(10) it_mbew-tot_1 right-justified,   198 sy-vline,
                    199 it_mbew-w_value left-justified,    212 sy-vline,
                    213 it_mbew-w_days CENTERED,           223 sy-vline,
                   224(10) it_mbew-tot_2 right-justified,      237 sy-vline,
                   238 it_mbew-w_value1 left-justified,        251 sy-vline.
        FORMAT COLOR 2 OFF INTENSIFIED.
    ENDLOOP.
      ULINE (251).
    elseif details = 'X'.
    LOOP AT it_mbew.
        AT FIRST.
          w_pagectr = 1.
          PERFORM header1.
        ENDAT.
        FORMAT COLOR 2 ON INTENSIFIED.
        WRITE : /01 sy-vline,
                     02 it_mbew-bwkey,                        10 sy-vline,
                     11 it_mbew-bklas,                        20 sy-vline,
                     21 IT_MBEW-EKGRP,                        27 SY-VLINE,
                     28 it_mbew-matnr+11(7),                  39 sy-vline,
                     40 it_mbew-maktx,                        80 sy-vline,
                  81(10) it_mbew-erfmg   right-justified,   93 sy-vline
                  94(10) it_mbew-erfme  right-justified,    104 sy-vline,
                    105 it_mbew-letztzug,                     117 sy-vline,
                    118 it_mbew-letztabg ,                     129 sy-vline,
                    130 it_mbew-letztver,                     141 sy-vline,
                    142 it_mbew-letztbew,                     153 sy-vline.
        FORMAT COLOR 2 OFF INTENSIFIED.
      ULINE /(153).
    ENDIF.
      ENDLOOP.
    LOOP AT it_mbew1.
        AT FIRST.
          w_pagectr = 1.
          PERFORM summary.
        ENDAT.
    ************************by ganesh
        it_mbew1-tot_31 = it_mbew1-tot_31 + it_mbew1-tot_3.
        it_mbew1-tot_21 = it_mbew1-tot_21 + it_mbew1-tot_2.
        it_mbew1-tot_11 = it_mbew1-tot_11 + it_mbew1-tot_1.
        it_mbew1-w_value01 = it_mbew1-w_value01 + it_mbew1-w_value.
        it_mbew1-w_value11 = it_mbew1-w_value11 + it_mbew1-w_value1.
        it_mbew1-w_value21 = it_mbew1-w_value21 + it_mbew1-w_value2.
        WRITE: /01 sy-vline,
                10 sy-vline,
                26 sy-vline,
                44 sy-vline,
                63 sy-vline,
                82 sy-vline,
                101 sy-vline,
                119 sy-vline.
        WRITE: 02 it_mbew1-bwkey  COLOR 4    , 10 sy-vline.
        WRITE: 01 sy-vline,
              11   it_mbew-tot_3    centered  color 7, 26 sy-vline,
                11   it_mbew1-tot_31    centered  color 7, 26 sy-vline,
              27 it_mbew1-tot_1    CENTERED COLOR 7,  44 sy-vline,
                27   it_mbew1-tot_11    CENTERED COLOR 7,  44 sy-vline,
              45 it_mbew1-tot_2    CENTERED COLOR 7, 63 sy-vline,
                45   it_mbew1-tot_21      CENTERED COLOR 7, 63 sy-vline,
               64 it_mbew1-w_value21  centered color 7, 82 sy-vline,
               83 it_mbew1-w_value01  CENTERED COLOR 7, 101 sy-vline ,
              102 it_mbew1-w_value11 CENTERED COLOR 7, 119 sy-vline.
      ENDLOOP.
      CLEAR : it_mbew1[] , it_mbew1.
      free : it_mbew1[] , it_mbew1.
    ULINE /(119).
    clear : it_mseg[],it_mseg, it_mkpf[], it_mkpf, IT_MBEW, IT_MBEW[].
    free: it_mseg[],it_mseg, it_mkpf[], it_mkpf, IT_MBEW, IT_MBEW[].
    *&      Form  header
          text
    -->  p1        text
    <--  p2        text
    FORM header .
      WRITE :  AT 110 'Page : ', w_pagectr COLOR 7.
      WRITE : /50 ' KANSAI NEROLAC PAINTS LIMITED' COLOR 7.
      WRITE : /50 '----
      WRITE : /50 'INTERMEDIATE INVENTORY REPORT' COLOR 7. " ADDED BY
      WRITE : /2  'DATE', sy-datum COLOR 6 INVERSE ON.   "AMRITANSHU
      FORMAT COLOR 7.
      ULINE /(251).
      FORMAT COLOR 4  ON INTENSIFIED.
      WRITE : /01 sy-vline,
               02 'FACTORY',                   10 sy-vline,
               11 'VALUATION',                 20 sy-vline,
               21 'PURCH',                     27 SY-VLINE,
               28 'MATERIAL',                  39 sy-vline,
               40 'MATERIAL DESCRIPTION',      80 sy-vline,
               81 'RATE',                      91 sy-vline,
               92 'TOTAL STOCK',              105 sy-vline,
              106  'UOM' ,                    111 SY-VLINE,
              112 'TOTAL VALUE',              126 sy-vline,
              127 'TOT UNRES & RES',          141 SY-VLINE,
              142 'TOT UNRES & RES' ,         156 SY-VLINE,
              157 'QUANTITY',                 170 sy-vline,
              171 'VALUE CONSUMP',            184 sy-vline,
              185 'QUANTITY',                 198 sy-vline,
              199 'VALUE CONSUMP',            212 sy-vline,
              213 'NO.OF DAYS',               223 sy-vline,
              224 'QUANTITY',                 237 sy-vline,
              238 'VALUE CONSUMP',            251 sy-vline.
      FORMAT COLOR 4 OFF INTENSIFIED.
      WRITE:  /01 sy-vline,
              10 sy-vline ,
              11 'CLASS'       COLOR 4,
              20 sy-vline,
              21 'GROUP' COLOR 4,
              27 sy-vline,
              39 sy-vline,
              80 sy-vline,
              91 SY-VLINE,
              105 SY-VLINE,
              111 SY-VLINE,
              112 '(INR)' COLOR 4,
              126 SY-VLINE,
              127 '  STOCK  ' COLOR 4,
              141 SY-VLINE,
              142 '(INR)' COLOR 4,
              156 SY-VLINE,
              157 'IN 6 MNTHS' COLOR 4,
              170 SY-VLINE,
              171 'IN 6 MNTHS' COLOR 4,
              184 SY-VLINE,
              185 'IN 3 MNTHS' COLOR 4,
              198 SY-VLINE,
              199 'IN 3 MNTHS' COLOR 4,
              212 SY-VLINE,
              213 '(INVENTORY)' COLOR 4,
              223 sy-vline,
              224 'IN 1 MNTHS' COLOR 4,
              237 SY-VLINE,
              238 'IN 1 MNTHS' COLOR 4,
              251 SY-VLINE.
      ULINE (251).
    ENDFORM.                    " header
    *&      Form  summary
          text
    FORM summary.
      WRITE :  AT 110 'Page : ', w_pagectr COLOR 7.
      WRITE : /50 ' KANSAI NEROLAC PAINTS LIMITED' COLOR 7.
      WRITE : /50 '----
      WRITE : /50 'INTERMEDIATE INVENTORY SUM REPORT' COLOR 7. " ADDED BY
      WRITE : /2  'DATE' , sy-datum COLOR 6 INVERSE ON.    "AMRITANSHU
      FORMAT COLOR 7.
      ULINE /(119).
      FORMAT COLOR 4  ON INTENSIFIED.
      WRITE : /01 sy-vline,
               02 'FACTORY' ,                   10 sy-vline,
               11 '  QUANTITY',                 26 sy-vline,
               27 '   QUANTITY'    ,            44 sy-vline,
               45 '   QUANTITY   ' ,             63 SY-VLINE,
               64 '  Value CONSUMP',             82 sy-vline,
               83 '  Value CONSUMP' ,            101 sy-vline,
               102 '  Value CONSUMP ',           119 sy-vline.
      FORMAT COLOR 4 OFF INTENSIFIED.
      WRITE:  /01 sy-vline,
               10 sy-vline,
               11 ' IN 6 MNTHS    ' COLOR 4,
               26 sy-vline,
               27 ' IN 3 MNTHS    ' COLOR 4,
               44 sy-vline,
               45 '  IN 1 MNTHS   ' COLOR 4,
               63 sy-vline,
               64 '   IN 6 MNTHS  ' COLOR 4,
               82 sy-vline,
               83 '   IN 3 MNTHS  ' COLOR 4,
               101 sy-vline,
               102 '   IN 1 MNTHS ' COLOR 4,
               119 sy-vline.
      ULINE /(119).
    ENDFORM.                    "summary
    *&      Form  header1
          text
    -->  p1        text
    <--  p2        text
    form header1 .
      WRITE :  AT 110 'Page : ', w_pagectr COLOR 7.
      WRITE : /50 ' KANSAI NEROLAC PAINTS LIMITED' COLOR 7.
      WRITE : /50 '----
      WRITE : /50 'INTERMEDIATE INVENTORY REPORT' COLOR 7. " ADDED BY
      WRITE : /2  'DATE', sy-datum COLOR 6 INVERSE ON.   "AMRITANSHU
      FORMAT COLOR 7.
      ULINE /(153).
      FORMAT COLOR 4  ON INTENSIFIED.
      WRITE : /01 sy-vline,

    HI
    and see these points which are very usefull for improve performance of a program
    Ways of Performance Tuning
    1.     Selection Criteria
    2.     Select Statements
    •     Select Queries
    •     SQL Interface
    •     Aggregate Functions
    •     For all Entries
    Select Over more than one Internal table
    Selection Criteria
    1.     Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement. 
    2.     Select with selection list.
    Points # 1/2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Select Statements   Select Queries
    1.     Avoid nested selects
    2.     Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
    3.     When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
    4.     For testing existence , use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. 
    5.     Use Select Single if all primary key fields are supplied in the Where condition .
    Point # 1
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops  only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
    Point # 2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Point # 3
    To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields . In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
    Point # 4
    SELECT * FROM SBOOK INTO SBOOK_WA
      UP TO 1 ROWS
      WHERE CARRID = 'LH'.
    ENDSELECT.
    The above code is more optimized as compared to the code mentioned below for testing existence of a record.
    SELECT * FROM SBOOK INTO SBOOK_WA
        WHERE CARRID = 'LH'.
      EXIT.
    ENDSELECT.
    Point # 5
    If all primary key fields are supplied in the Where condition you can even use Select Single.
    Select Single requires one communication with the database system, whereas Select-Endselect needs two.
    Select Statements           contd..  SQL Interface
    1.     Use column updates instead of single-row updates
    to update your database tables.
    2.     For all frequently used Select statements, try to use an index.
    3.     Using buffered tables improves the performance considerably.
    Point # 1
    SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
      SFLIGHT_WA-SEATSOCC =
        SFLIGHT_WA-SEATSOCC - 1.
      UPDATE SFLIGHT FROM SFLIGHT_WA.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    UPDATE SFLIGHT
           SET SEATSOCC = SEATSOCC - 1.
    Point # 2
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE MANDT IN ( SELECT MANDT FROM T000 )
        AND CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    Point # 3
    Bypassing the buffer increases the network considerably
    SELECT SINGLE * FROM T100 INTO T100_WA
      BYPASSING BUFFER
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    The above mentioned code can be more optimized by using the following code
    SELECT SINGLE * FROM T100  INTO T100_WA
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    Select Statements       contd…           Aggregate Functions
    •     If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
    Some of the Aggregate functions allowed in SAP are  MAX, MIN, AVG, SUM, COUNT, COUNT( * )
    Consider the following extract.
                Maxno = 0.
                Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
                 Check zflight-fligh > maxno.
                 Maxno = zflight-fligh.
                Endselect.
    The  above mentioned code can be much more optimized by using the following code.
    Select max( fligh ) from zflight into maxno where airln = ‘LF’ and cntry = ‘IN’.
    Select Statements    contd…For All Entries
    •     The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
         The plus
    •     Large amount of data
    •     Mixing processing and reading of data
    •     Fast internal reprocessing of data
    •     Fast
         The Minus
    •     Difficult to program/understand
    •     Memory could be critical (use FREE or PACKAGE size)
    Points to be must considered FOR ALL ENTRIES
    •     Check that data is present in the driver table
    •     Sorting the driver table
    •     Removing duplicates from the driver table
    Consider the following piece of extract
    Loop at int_cntry.
           Select single * from zfligh into int_fligh
    where cntry = int_cntry-cntry.
    Append int_fligh.
    Endloop.
    The above mentioned can be more optimized by using the following code.
    Sort int_cntry by cntry.
    Delete adjacent duplicates from int_cntry.
    If NOT int_cntry[] is INITIAL.
                Select * from zfligh appending table int_fligh
                For all entries in int_cntry
                Where cntry = int_cntry-cntry.
    Endif.
    Select Statements    contd…  Select Over more than one Internal table
    1.     Its better to use a views instead of nested Select statements.
    2.     To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
    3.     Instead of using nested Select loops it is often better to use subqueries.
    Point # 1
    SELECT * FROM DD01L INTO DD01L_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND AS4LOCAL = 'A'.
      SELECT SINGLE * FROM DD01T INTO DD01T_WA
        WHERE   DOMNAME    = DD01L_WA-DOMNAME
            AND AS4LOCAL   = 'A'
            AND AS4VERS    = DD01L_WA-AS4VERS
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT.
    The above code can be more optimized by extracting all the data from view DD01V_WA
    SELECT * FROM DD01V INTO  DD01V_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT
    Point # 2
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Point # 3
    SELECT * FROM SPFLI
      INTO TABLE T_SPFLI
      WHERE CITYFROM = 'FRANKFURT'
        AND CITYTO = 'NEW YORK'.
    SELECT * FROM SFLIGHT AS F
        INTO SFLIGHT_WA
        FOR ALL ENTRIES IN T_SPFLI
        WHERE SEATSOCC < F~SEATSMAX
          AND CARRID = T_SPFLI-CARRID
          AND CONNID = T_SPFLI-CONNID
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    The above mentioned code can be even more optimized by using subqueries instead of for all entries.
    SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                         WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    1.     Table operations should be done using explicit work areas rather than via header lines.
    2.     Always try to use binary search instead of linear search. But don’t forget to sort your internal table before that.
    3.     A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
    4.     A binary search using secondary index takes considerably less time.
    5.     LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
    6.     Modifying selected components using “ MODIFY itab …TRANSPORTING f1 f2.. “ accelerates the task of updating  a line of an internal table.
    Point # 2
    READ TABLE ITAB INTO WA WITH KEY K = 'X‘ BINARY SEARCH.
    IS MUCH FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY K = 'X'.
    If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
    Point # 3
    READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
    Point # 5
    LOOP AT ITAB INTO WA WHERE K = 'X'.
    ENDLOOP.
    The above code is much faster than using
    LOOP AT ITAB INTO WA.
      CHECK WA-K = 'X'.
    ENDLOOP.
    Point # 6
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
    The above code is more optimized as compared to
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1.
    7.     Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
    8.    If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
    9.    "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to “ LOOP-APPEND-ENDLOOP.”
    10.   “DELETE ADJACENT DUPLICATES“ accelerates the task of deleting duplicate entries considerably as compared to “ READ-LOOP-DELETE-ENDLOOP”.
    11.   "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to “  DO -DELETE-ENDDO”.
    Point # 7
    Modifying selected components only makes the program faster as compared to Modifying all lines completely.
    e.g,
    LOOP AT ITAB ASSIGNING <WA>.
      I = SY-TABIX MOD 2.
      IF I = 0.
        <WA>-FLAG = 'X'.
      ENDIF.
    ENDLOOP.
    The above code works faster as compared to
    LOOP AT ITAB INTO WA.
      I = SY-TABIX MOD 2.
      IF I = 0.
        WA-FLAG = 'X'.
        MODIFY ITAB FROM WA.
      ENDIF.
    ENDLOOP.
    Point # 8
    LOOP AT ITAB1 INTO WA1.
      READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
      IF SY-SUBRC = 0.
        ADD: WA1-VAL1 TO WA2-VAL1,
             WA1-VAL2 TO WA2-VAL2.
        MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
      ELSE.
        INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
      ENDIF.
    ENDLOOP.
    The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
    LOOP AT ITAB1 INTO WA.
      COLLECT WA INTO ITAB2.
    ENDLOOP.
    SORT ITAB2 BY K.
    COLLECT, however, uses a hash algorithm and is therefore independent
    of the number of entries (i.e. O(1)) .
    Point # 9
    APPEND LINES OF ITAB1 TO ITAB2.
    This is more optimized as compared to
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 10
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
    This is much more optimized as compared to
    READ TABLE ITAB INDEX 1 INTO PREV_LINE.
    LOOP AT ITAB FROM 2 INTO WA.
      IF WA = PREV_LINE.
        DELETE ITAB.
      ELSE.
        PREV_LINE = WA.
      ENDIF.
    ENDLOOP.
    Point # 11
    DELETE ITAB FROM 450 TO 550.
    This is much more optimized as compared to
    DO 101 TIMES.
      DELETE ITAB INDEX 450.
    ENDDO.
    12.   Copying internal tables by using “ITAB2[ ] = ITAB1[ ]” as compared to “LOOP-APPEND-ENDLOOP”.
    13.   Specify the sort key as restrictively as possible to run the program faster.
    Point # 12
    ITAB2[] = ITAB1[].
    This is much more optimized as compared to
    REFRESH ITAB2.
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 13
    “SORT ITAB BY K.” makes the program runs faster as compared to “SORT ITAB.”
    Internal Tables         contd…
    Hashed and Sorted tables
    1.     For single read access hashed tables are more optimized as compared to sorted tables.
    2.      For partial sequential access sorted tables are more optimized as compared to hashed tables
    Hashed And Sorted Tables
    Point # 1
    Consider the following example where HTAB is a hashed table and STAB is a sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    This runs faster for single read access as compared to the following same code for sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE STAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    Point # 2
    Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
    LOOP AT STAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.
    This runs faster as compared to
    LOOP AT HTAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.
    <b>Reward if usefull</b>

Maybe you are looking for

  • How do you get iTunes music from one computer to the other?

    I activated iCloud, home sharing on multiple computers and i still don't know how to share my music and movie files from itunes.

  • When I run a web browser immediately loaded two blank tabs. How to make the browser load the only one?

    when I run a web browser immediately loaded two blank tabs. How to make the browser load the only one?

  • ADF af:column width attribute

    Hello, I'm trying to expand the width of columns inside an af:table component so they stretch automatically according to the parent's size. I have tried all ways but columns always get set the default 100px width. The only way to make it stretch is u

  • Aperture- shopping cart option?

    Hi I am currently in the process of creating a website...and I may be purchasing Aperture soon...I guess what I want to do is allow client proofing (password protected) and ordering (and preferably payment) online. *I want to maintain control of the

  • Select Max Rno Records

    I have following data select  * from retreport   CODE VDATE        STAT  ICODE INAME   FCODE FNAME        IAMOUNT        UNITS          AVG       UBAL           ABAL        Rno    108 28/06/2010    I     1    ABC      1    MCMOF   67107445.99      65