How to improve the execution time of my VI?

My vi does data processing for hundreds of files and takes more than 20 minutes to commplete. The setup is firstly i use the directory LIST function to list all the files in a dir. to a string array. Then I index this string array into a for loop, in which each file is opened one at a time inside the loop, and some other sub VIs are called to do data analysis. Is there a way to improve my execution time? Maybe loading all files into memory at once? It will be nice to be able to know which section of my vi takes the longest time too. Thanks for any help.

Bryan,
If "read from spreadsheet file" is the main time hog, consider dropping it! It is a high-level, very multipurpose VI and thus carries a lot of baggage around with it. (you can double-click it and look at the "guts" )
If the files come from a just executed "list files", you can assume the files all exist and you want to read them in one single swoop. All that extra detailed error checking for valid filenames is not needed and you never e.g. want it to popup a file dialog if a file goes missing, but simply skip it silently. If open generates an error, just skip to the next in line. Case closed.
I would do a streamlined low level "open->read->close" for each and do the "spreadsheet string to array" in your own code, optimized to the exact format of your files. For example, notice that "read from spreadheet file" converts everything to SGL, a waste of CPU if you later need to convert it to DBL for some signal processing anyway.
Anything involving formatted text is not very efficient. Consider a direct binary file format for your data files, it will read MUCH faster and take up less disk space.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • How to get the execution time of a Discoverer Report from qpp_stats table

    Hello
    by reading some threads on this forum I became aware of the information stored in eul5_qpp_stats table. I would like to know if I can use this table to determine the execution time of a worksheet. In particular it looks like the field qs_act_elap_time stores the actual elapsed time of each execution of specific worksheet: am I correct? If so, how is this value computed? What's the unit of measure? I assume it's seconds, but then I've seen that sometimes I get numbers with decimals.
    For example I ran a worksheet and it took more than an hour to run, and the value I get in the qs_act_elap_time column is 2218.313.
    Assuming the unit of measure was seconds than it would mean approx 37 mins. Is that the actual execution time of the query on the database? I guess the actual execution time on my Discoverer client was longer since some calculations were performed at the client level and not on the database.
    I would really appreciate if you could shed some light on this topic.
    Thanks and regards
    Giovanni

    Thanks a lot Rod for your prompt reply.
    I agree with you about the accuracy of the data. Are you aware of any other way to track the execution times of Discoverer reports?
    Thanks
    Giovanni

  • 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");
         }

  • How to get the execution time of a query

    Hi,
    Environment: 10.2.0.4.0
    Just wondering how I can get the query execution time? I am not interested in the query output nor do I want the statistics, just the execution time?
    Any suggestions will be appreciated
    Thanks in advance
    rogers42

    If you're using SQL*Plus
    SQL> set autotrace traceonly
    SQL> set timing on
    SQL> <<your query here>>SQL*Plus will fetch all the data and then report the query plan, execution statistics, and elapsed time. It will not display the actual data.
    SET TIMING ON alone tells SQL*Plus to display the execution time of each SQL statement-- the problem is that it also displays all the data which can skew the results because you're including the time required by SQL*Plus to pipe a bunch of data to the screen.
    Justin

  • How to know the execution time of rule in Calculation Manager

    Hi All,
    How do we come to know the time of execution of rule in calculation manager ?
    Regards
    Vikram

    At this point there is no way to know the execution time of a rule in calculation Manager . If you are working on Planning rules, I believe planning displays the execution time in its job console.
    -SR

  • How to extend the execution time of an ABAP Program using the Process chain

    Hello Sapians,
    Our Environment has got 600seconds = 10 mintues as the execution time.
    My ABAP Program is taking more than this 600 seconds, to show the result, I found this when I tried to execute in debug mode, it shows the result.
    If I execute in background also it shows the results succesfully.
    Only issue is when I execute this report in foreground it has been taking ages and goes on Time OUT Error.
    It has been decided that we can extend the execution time only for this report, and it will reset the time back to 10mintues once the report has been executed successfully or failed in between for any other reasons.
    And we can achieve this by using the process chains.
    Can any body help me please in this regard
    Thanks,

    Hi,,,,,,,,,,
    Besides Process Chain There is another way out for this........
    Resetting time counter of dialog process so that time-out does not
    happen. Use this fm within your program at appropriate locations to
    reset time counter.
    "CALL FUNCTION 'TH_REDISPATCH'."
    Thanks
    Saurabh

  • How to find the execution time of a query?

    hi guys,
    i need to find the execution time of a query.
    i tried finding it in rsrt but couldn find the execution time.
    pleasse let me know the way to do it..
    regards
    sagar

    Hi sagar,
    If you want to know the frontend time, first of all you need to maitain the BW Statistics. To maintain you have to go the respective target and click on it. Go to the tools, select BW Statistics of infoprovider. It pop ups a window there you find two check boxes 1) WHM and 2) Front end time. Check both.
    Now Exe query and close the analyzer. Then go to SE11 table RSDDSTAT. There is one field which displays Frentend time.
    OR
    Go to STO3 here also you can analys the frontend time.
    If you feel useful Assign Pts.
    Regards,
    Vishal

  • How to find the execution time

    Hi
    I don't know whether it is possible in Oracle or not?
    Say i have got around 20 odd Views in my DB and couple of them based on Materialized View which is again created by joining more than 5 based tables.
    Even most of the Views are also created by joining base tables and MV's.
    When i execute Select count(*) from <viewname>;
    I do get the count of rows and on avg each view returns more that 30lacs row.
    And when i excute select * from <View_name> by setting the Time on.
    It takes more than 2 hours to return the rows.I know the elapsed time of a query do depend of external factors as well such as number of users using the DB Object used in thoe views,Number of process involved and all.
    And therefore in order to gather the elapsed time of each and every view will take more than a week .
    I would appreciate if anyone can provide me a better approach or even a shell script or something like that which will give me the elapsed time of all the views if i query (Select * from <view_name>);
    Thanks in advance.
    Vineet

    But to SomeoneElse's point, if you are running
    SELECT * FROM view_namefrom SQL*Plus, what you are primarily measuring is how fast your network is (because you're spending a great deal of time sending data from the database to the client) and the speed of the SQL*Plus client on your machine (which has to fetch that data, which may have to format and display that data, etc.) It is not a particularly meaningful metric. If you tuned the client machine so that SQL*Plus wasn't displaying the data, if you increased the fetch size, etc. you could drastically decrease the time it would take to send all the data to your client machine, but that is probably not going to constitute tuning for anyone other than you (i.e. you might see a halving of run time while everyone else saw no change).
    Beyond that, doing a SELECT * with no criteria is likely to involve execution plans that no one else will see, data access patterns no one else will see, etc. which just makes the benchmark you are proposing irrelevent.
    If you really, really want to measure how quickly your client can pull the data from all the views, you could of course let that run for a week. But the number wouldn't mean anything.
    Justin

  • What to do if data grows heavily.How to decrease the execution time

    Procedure execution time increases from 1 minute to 40 minutes in the past three years. I think this is due to increase in size of tables. We are maintaining the database from last 6years. Nearly 25,000 records are adding per month in a table. Now each contains above 12Lakh records. I already used Query Optimization techniques. So please suggest me what to do.

    So, does this process need to access the whole table or is it just interested in the last months records?
    I already used Query Optimization techniques.meaning what precisely???
    So please suggest me what to do.Without knowing a whole bunch more about your situation we cannot give you a solution. You have one slow process. So what? For instance, let's presume this is a batch process that runs once a month. Does a forty minute elapsed time matter compare to processes that are used by all your users many times every day? Are you prepared to risk the performance of those OLTP functions to improve the runtime of that batch process?
    Cheers, APC

  • How to improve the activation time for a standard DSO

    Hi all,
    I'm facing an issue related to the activation of a DSO. The SM37 log is as follows....
    12:03:16 Job started
    12:03:16 Step 001 started (program RSPROCESS, variant &0000000006946, user ID BWREMOTE)
    12:03:20 Attivazione is running: Data target ZFIZIASA, from 93,627 to 93,627
    12:18:00 Overlapping check with archived data areas for InfoProvider ZFIZIASA
    12:18:00 Data to be activated successfully checked against archiving objects
    12:18:02 Status transition 2 / 2 to 7 / 7 completed successfully
    12:18:13 Program RSBATCH_EXECUTE_PROZESS successfully scheduled as job BIBCTL_4IC45QJA588GKZ0M7JEJ3HCAR with ID 1218130
    12:18:19 Program RSBATCH_EXECUTE_PROZESS successfully scheduled as job BIBCTL_4IC45QJA588GKZ0M7JEJ3HCAR with ID 1218190
    12:18:20 Parallel processes (for Attivazione); 000003
    12:18:20 Timeout for parallel process (for Attivazione): 000300
    12:18:20 Package size (for Attivazione): 020000
    12:18:20 Task handling (for Attivazione): Processi batch
    12:18:20 Server group (for Attivazione): Nessun gruppo di server config
    12:18:20 Activation started (process is running under user BWREMOTE)
    12:18:20 Not all data fields were updated in mode "overwrite"
    12:18:20 Process started
    12:18:20 Process completed
    12:18:20 Activation ended
    Please have a look into the bold 3rd & 4th line. I couldnt able to analyse where the issue is and what to do to minimize the time for activation.
    It is very challenging, please reply!
    Please help.
    Thanks in adv.
    Ajay

    Hi Kundan,
    Thanks for the response!
    Actually, I have two identical DSO, having all the char & KF same and feeding the data from same DS at the same time but the issue is...
    1) For 1st DSO, Activation log....
    01.07.2010 02:02:41 Job started
    01.07.2010 02:02:41 Step 001 started (program RSPROCESS, variant &0000000006946, user ID BWREMOTE)
    01.07.2010 02:02:46 Attivazione is running: Data target ZFIZIASA, from 93,751 to 93,751
    01.07.2010 02:19:27 Overlapping check with archived data areas for InfoProvider ZFIZIASA
    01.07.2010 02:19:27 Data to be activated successfully checked against archiving objects
    01.07.2010 02:19:27 Status transition 2 / 2 to 7 / 7 completed successfully
    01.07.2010 02:19:28 Program RSBATCH_EXECUTE_PROZESS successfully scheduled as job BIBCTL_4ICC6UMXYT00Z2DYOQV8QL8CJ with ID 021
    01.07.2010 02:19:30 Parallel processes (for Attivazione); 000003
    01.07.2010 02:19:30 Timeout for parallel process (for Attivazione): 000600
    01.07.2010 02:19:30 Package size (for Attivazione): 020000
    01.07.2010 02:19:30 Task handling (for Attivazione): Processi batch
    01.07.2010 02:19:30 Server group (for Attivazione): Nessun gruppo di server config
    01.07.2010 02:19:30 Activation started (process is running under user BWREMOTE)
    01.07.2010 02:19:30 Not all data fields were updated in mode "overwrite"
    01.07.2010 02:19:30 Activation ended
    2) For 2nd DSO, the activation log is..
    01.07.2010 02:01:13 Job started
    01.07.2010 02:01:13 Step 001 started (program RSPROCESS, variant &0000000006947, user ID BWREMOTE)
    01.07.2010 02:01:35 Attivazione is running: Data target ZFIGL_02, from 93,749 to 93,749
    01.07.2010 02:01:43 Overlapping check with archived data areas for InfoProvider ZFIGL_02
    01.07.2010 02:01:43 Data to be activated successfully checked against archiving objects
    01.07.2010 02:01:53 Program RSBATCH_EXECUTE_PROZESS successfully scheduled as job BIBCTL_4ICCAR91ALHE1VHSB6GV9PAPV with ID 02015300
    01.07.2010 02:01:54 Program RSBATCH_EXECUTE_PROZESS successfully scheduled as job BIBCTL_4ICCAR91ALHE1VHSB6GV9PAPV with ID 02015400
    01.07.2010 02:01:56 Program RSBATCH_EXECUTE_PROZESS successfully scheduled as job BIBCTL_4ICCAR91ALHE1VHSB6GV9PAPV with ID 02015600
    Now my client is asking to lower the activation time for 1st one as it is taking for 2nd one.
    I'm toatally blank now that what & how to do it!
    The volume of data ...
    ZFIZIASA
    Active table - Number of entries: 13.960.508
    Change Log Table - Number of entries: 13.976.530
    ZFIGL_02
    Active Table - Number of entries: 21.923.947
    Change Log table - Number of entries: 21.938.657
    Thanks,
    ajay
    Edited by: sap.ajaykumar on Jul 6, 2010 1:47 PM

  • How to improve the load time of my swf group

    Hi,
    I need help to have some tricks to improve my load time on my swf captivate online traning. My training has 6 sections and it takes 3 minutes to download each time I open the window of the training. It takes too much time and if there are 50 users at the same time, it will take lots of my website bandwidth. Do you have any tips on captivate settings or other tips to help reduce my training download time? I do not understand why the 6 modules loading simultaneously and not every time I click to start a new part of training.
    Can you help me with my problem?
    Thank you

    Bryan,
    If "read from spreadsheet file" is the main time hog, consider dropping it! It is a high-level, very multipurpose VI and thus carries a lot of baggage around with it. (you can double-click it and look at the "guts" )
    If the files come from a just executed "list files", you can assume the files all exist and you want to read them in one single swoop. All that extra detailed error checking for valid filenames is not needed and you never e.g. want it to popup a file dialog if a file goes missing, but simply skip it silently. If open generates an error, just skip to the next in line. Case closed.
    I would do a streamlined low level "open->read->close" for each and do the "spreadsheet string to array" in your own code, optimized to the exact format of your files. For example, notice that "read from spreadheet file" converts everything to SGL, a waste of CPU if you later need to convert it to DBL for some signal processing anyway.
    Anything involving formatted text is not very efficient. Consider a direct binary file format for your data files, it will read MUCH faster and take up less disk space.
    LabVIEW Champion . Do more with less code and in less time .

  • How to improve the run time of this query

    Is there any way to improve this query,
    I have a table which SR_WId with atleast one subtype as 'Break Fix', 'Break/Fix','Break Fix/Corrective Maint','Break Fix-Corrective Maint'. then i can have other subtype as 'Break Fix', 'Break/Fix', 'Follow Up', 'Follw-Up','T&'||'M Break Fix','Break Fix/Corrective Maint','Break Fix-Corrective Maint'.
    Let me know if this is okay or to modify it.
    SELECT DISTINCT A.SR_WID AS SR_WID
    FROM WC_SR_ACT_SMRY_FS A
    WHERE EXISTS
    (SELECT NULL FROM WC_SR_ACT_SMRY_FS B
    WHERE B.ACT_TYPE = 'Maintenance'
    AND B.ACT_SUBTYPE in ('Break Fix', 'Break/Fix','Break Fix/Corrective Maint','Break Fix-Corrective Maint') AND B.NBR_OF_ACTIVITIES = 1 AND B.SR_WID = A.SR_WID
    GROUP BY B.SR_WID
    HAVING COUNT(B.SR_WID) >= 1)
    AND A.ACT_TYPE = 'Maintenance'
    AND A.ACT_SUBTYPE IN ('Break Fix', 'Break/Fix', 'Follow Up', 'Follw-Up','T&'||'M Break Fix','Break Fix/Corrective Maint','Break Fix-Corrective Maint')

    SELECT DISTINCT A.SR_WID AS SR_WID
               FROM WC_SR_ACT_SMRY_FS A
              WHERE EXISTS(
                       SELECT   NULL
                           FROM WC_SR_ACT_SMRY_FS B
                          WHERE B.ACT_TYPE = 'Maintenance'
                            AND B.ACT_SUBTYPE IN
                                  ('Break Fix',
                                   'Break/Fix',
                                   'Break Fix/Corrective Maint',
                                   'Break Fix-Corrective Maint')
                            AND B.NBR_OF_ACTIVITIES = 1
                            AND B.SR_WID = A.SR_WID
                       GROUP BY B.SR_WID
                         HAVING COUNT(B.SR_WID) >= 1 )
                AND A.ACT_TYPE = 'Maintenance'
                AND A.ACT_SUBTYPE IN
                      ('Break Fix',
                       'Break/Fix',
                       'Follow Up',
                       'Follw-Up',
                       'T&' || 'M Break Fix',
                       'Break Fix/Corrective Maint',
                       'Break Fix-Corrective Maint');First of all, you can omit the GROUP BY and HAVING part in the sub-select -
    we already know thath the only value for B.SR_WID can be A.SR_WID and
    COUNT(B.SR_WID) will always be at least 1, otherwise the sub-select will
    return nothing.
    As a second step, you could transform EXISTS() into IN():
    SELECT DISTINCT SR_WID
               FROM WC_SR_ACT_SMRY_FS A
              WHERE SR_WID IN(
                       SELECT B.SR_WID
                         FROM WC_SR_ACT_SMRY_FS B
                        WHERE B.ACT_TYPE = 'Maintenance'
                          AND B.ACT_SUBTYPE IN
                                ('Break Fix',
                                 'Break/Fix',
                                 'Break Fix/Corrective Maint',
                                 'Break Fix-Corrective Maint')
                          AND B.NBR_OF_ACTIVITIES = 1)
                AND ACT_TYPE = 'Maintenance'
                AND ACT_SUBTYPE IN
                      ('Break Fix',
                       'Break/Fix',
                       'Follow Up',
                       'Follw-Up',
                       'T&' || 'M Break Fix',
                       'Break Fix/Corrective Maint',
                       'Break Fix-Corrective Maint');

  • How can I improve the response time of the user interface?

    I'm after some tips on how to improve the response time to mouse clicks on a VI front panel.
    I have  data acquistion application which used to run fine, but after spending a couple of weeks making a whole bunch of changes to it I find that the user interface has become a bit sluggish.
    My main GUI VI has a while loop running 16 times a second, updating some waveform charts and polling about a dozen buttons on the front panel.
    There is sometimes a delay (variable, but up to 2 seconds sometimes) from when I click on a button to when it becomes depressed. I have wired the iteration terminal of the while loop to an indicator on the front panel and can see that the while loop is ticking over during the delayed response to the mouse click, so I know that the problem is not that the whole program is running slow, just the response to mouse clicks.
    Also, just for debugging purposes, I have indicators of the iterations of all the main while loops in my program on the front panel, so I can see that there are no loops running abnormally fast either.
    One thing I've tried is to turn off multi-threading, and this does seem to work - the response to mouse clicks is much faster. However, it has the side effect of making the main GUI while loop run less evenly. I was trying to get a fairly smooth waveform scrolling across the screen, and when multi-threading is off it gets a bit jerky.
    Any other suggestion welcome..
    (I am using LabVIEW 7.1, Windows 2000).
    Regards,
    Mark.

    Hi Altenbach,
    Thanks for your reply. In answer to your questions:
    I am doing both DAQ board and serial data acquisition. I am using NIDAQ traditional for the DAQ board, and VISA for the serial. I have other similar versions of this program that do only DAQ board, or only serial, and these work fine. It was only when I combined them both into the same program that I ran into problems.
    The multiple while loops are actually in separate VIs. I have one VI that acquires data from the DAQ card, another VI that acquires data from the serial port, another VI that processes the data and saves to file, and another VI, the GUI VI, that displays the data in graphs and charts.  The data is transferred betwen the VIs via LV2 globals.
    The GUI VI is a bit more complicated than I first mentioned. It has tab control, with 4 waveform charts on one page, 4 waveform graphs on another page, and 3 waveform graphs on another page. The charts have a history length of 2560, and 16 data points are added 16 times a second. The wavefom graphs are only updated once per minute.
    I don't use the value property at all, but I do use lots of property nodes for changing the properties of the graphs and charts e.g. changing plot colours, Y scale range etc. There is only one local variable (for the Tab control). All the graphs and charts have data wired directly to their terminals.
    I haven't done any profiling yet.
    I am building arrays in uninitialised shift registers, but this is all well under control. As the experiement goes on, more data is collected and stored, and so the memory usage does gradually increase, but only to the extent that I would expect.
    The CPU usage is 100%, but I thought this was always the case when using NIDAQ  with DAQ cards. Or am I wrong about this? (As a side note, I am using NIDAQ traditional, but would NIDAQmx be better?)
    Execution priority of the GUI vi (and all the other VIs for that matter) is set to normal.
    The program is a bit large to post here, and I'm not sure if my company would be happy for me to publicise it anyway, so I suspect that this is turning into one of those questions that are going to be impossible to answer.
    Just as a more general question, why would turning off multi-threading improve the user interface response?
    Thanks,
    Mark.

  • OSB: how to figure out the execution time of OSB proxy

    Trying to figure out how to determine the execution time taken for any given OSB proxy. Seems like the OSB built-in alerting facilities can display the average response time of all calls to a proxy but not individually. Is there a way to dig this out from the monitoring data being collected?

    Service monitoring which comes OOTB is supposed to be aggregated because in usual scenarios you dont need to see the processing time of a specific request. From a performance monitoring perspective the useful data usually is average processing time and minimum or maximum processing time for any request within the aggregation interval which is provided by OSB OOTB.
    Now, in some cases the business might want to track each request individually. So, for example they can track how long did it take to process a specific order. OSB does not provide this feature OOTB. There are multiple ways to get this implemented. Two of the most common ways are:
    1. Add a start and end time capturing in Proxy Services. You can use logging/reporting/publish to a DB etc to achieve this. But this is indeed intrusive and you will need to do this for every Proxy which needs to be monitored at every instance level. This is also a slight overhead in processing in itself.
    2. Use monitoring products which can monitor the WS invocations externally. This will mean more investment but definitely a much better solution. You can consider using different products from Oracle and other vendors based on your requirements, features of products and costs. A few examples are OWSM, Oracle EM, CA Wily etc.

  • 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