Help to improve the performance of a procedure.

Hello everybody,
First to introduce myself. My name is Ivan and I recently started learning SQL and PL/SQL. So don't go hard on me. :)
Now let's jump to the problem. What we have there is a table (big one, but we'll need only a few fields) with some information about calls. It is called table1. There is also another one, absolutely the same structure, which is empty and we have to transfer the records from the first one.
The shorter calls (less than 30 minutes) have segmentID = 'C1'.
The longer calls (more than 30 minutes) are recorded as more than one record (1 for every 30 minutes). The first record (first 30 minutes of the call) has segmentID = 'C21'. It is the first so we have only one of these for every different call. Then we have the next (middle) parts of the call, which have segmentID = 'C22'. We can have more than 1 middle part and again the maximum minutes in each is 30 minutes. Then we have the last part (again max 30 minutes) with segmentID = 'C23'. As with the first one we can have only one last part.
So far, so good. Now we need to insert these call records into the second table. The C1 are easy - one record = one call. But the partial ones we need to combine so they become one whole call. This means that we have to take one of the first parts (C21), find if there is a middle part (C22) with the same calling/called numbers and with 30 minutes difference in date/time, then search again if there is another C22 and so on. And last we have to search for the last part of the call (C23). In the course of these searches we sum the duration of each part so we can have the duration of the whole call at the end. Then we are ready to insert it in the new table as a single record, just with new duration.
But here comes the problem with my code... The table has A LOT of records and this solution, despite the fact that it works (at least in the tests I've made so far), it's REALLY slow.
As I said I'm new to PL/SQL and I know that this solution is really newbish, but I can't find another way of doing this.
So I decided to come here and ask you for some tips on how to improve the performance of this.
I think you are getting confused already, so I'm just going to put some comments in the code.
I know it's not a procedure as it stands now, but it will be once I create a better code. I don't think it matters for now.
DECLARE
CURSOR cur_c21 IS
    select * from table1
    where segmentID = 'C21'
    order by start_date_of_call;     // in start_date_of_call is located the beginning of a specific part of the call. It's date format.
CURSOR cur_c22 IS
    select * from table1
    where segmentID = 'C22'
    order by start_date_of_call;
CURSOR cur_c22_2 IS
    select * from table1
    where segmentID = 'C22'
    order by start_date_of_call;  
cursor cur_c23 is
    select * from table1
    where segmentID = 'C23'
    order by start_date_of_call;
v_temp_rec_c22 cur_c22%ROWTYPE;
v_dur table1.duration%TYPE;           // using this for storage of the duration of the call. It's number.
BEGIN
insert into table2
select * from table1 where segmentID = 'C1';     // inserting the calls which are less than 30 minutes long
-- and here starts the mess
FOR rec_c21 IN cur_c21 LOOP        // taking the first part of the call
   v_dur := rec_c21.duration;      // recording it's duration
   FOR rec_c22 IN cur_c22 LOOP     // starting to check if there is a middle part for the call
      IF rec_c22.callingnumber = rec_c21.callingnumber AND rec_c22.callednumber = rec_c21.callednumber AND 
        (rec_c22.start_date_of_call - rec_c21.start_date_of_call) = (1/48)                
/* if the numbers are the same and the date difference is 30 minutes then we have a middle part and we start searching for the next middle. */
      THEN
         v_dur := v_dur + rec_c22.duration;     // updating the new duration
         v_temp_rec_c22:=rec_c22;               // recording the current record in another variable because I use it for the next check
         FOR rec_c22_2 in cur_c22_2 LOOP
            IF rec_c22_2.callingnumber = v_temp_rec_c22.callingnumber AND rec_c22_2.callednumber = v_temp_rec_c22.callednumber AND 
              (rec_c22_2.start_date_of_call - v_temp_rec_c22.start_date_of_call) = (1/48)        
/* logic is the same as before but comparing with the last value in v_temp...
And because the data in the cursors is ordered by date in ascending order it's easy to search for another middle parts. */
            THEN
               v_dur:=v_dur + rec_c22_2.duration;
               v_temp_rec_c22:=rec_c22_2;
            END IF;
         END LOOP;                     
      END IF;
      EXIT WHEN rec_c22.callingnumber = rec_c21.callingnumber AND rec_c22.callednumber = rec_c21.callednumber AND 
               (rec_c22.start_date_of_call - rec_c21.start_date_of_call) = (1/48);       
/* exiting the loop if we have at least one middle part.
(I couldn't find if there is a way to write this more clean, like exit when (the above if is true) */
   END LOOP;
   FOR rec_c23 IN cur_c23 LOOP             
      IF (rec_c23.callingnumber = rec_c21.callingnumber AND rec_c23.callednumber = rec_c21.callednumber AND
         (rec_c23.start_date_of_call - rec_c21.start_date_of_call) = (1/48)) OR v_dur != rec_c21.duration          
/* we should always have one last part, so we need this check.
If we don't have the "v_dur != rec_c21.duration" part it will execute the code inside only if we don't have middle parts
(yes we can have these situations in calls longer than 30 and less than 60 minutes). */
      THEN
         v_dur:=v_dur + rec_c23.duration;
         rec_c21.duration:=v_dur;               // updating the duration
         rec_c21.segmentID :='C1';
         INSERT INTO table2 VALUES rec_c21;     // inserting the whole call in table2
      END IF;
      EXIT WHEN (rec_c23.callingnumber = rec_c21.callingnumber AND rec_c23.callednumber = rec_c21.callednumber AND
                (rec_c23.start_date_of_call - rec_c21.start_date_of_call) = (1/48)) OR v_dur != rec_c21.duration;                 
                // exit the loop when the last part has been found.
   END LOOP;
END LOOP;
END;I'm using Oracle 11g and version 1.5.5 of SQL Developer.
It's my first post here so hope this is the right sub-forum.
I tried to explain everything as deep as possible (sorry if it's too long) and I kinda think that the code got somehow hard to read with all these comments. If you want I can remove them.
I know I'm still missing a lot of knowledge so every help is really appreciated.
Thank you very much in advance!

Atiel wrote:
Thanks for the suggestion but the thing is that segmentID must stay the same for all. The data in this field is just to tell us if this is a record of complete call (C1) or a partial record of a call(C21, C22, C23). So in table2 as every record will be a complete call the segmentID must be C1 for all.Well that's not a problem. You just hard code 'C1' instead of applying the row number as I was doing:
SQL> ed
Wrote file afiedt.buf
  1  select 'C1' as segmentid
  2        ,start_date_of_call, duration, callingnumber, callednumber
  3  from (
  4        select distinct
  5               min(start_date_of_call) over (partition by callingnumber, callednumber) as start_date_of_call
  6              ,sum(duration) over (partition by callingnumber, callednumber) as duration
  7              ,callingnumber
  8              ,callednumber
  9        from table1
10*      )
SQL> /
SEGMENTID  START_DATE_OF_CALL     DURATION CALLINGNUMBER   CALLEDNUMBER
C1         11-MAY-2012 12:13:10 8020557824 1982032041      0631432831624
C1         15-MAR-2012 09:07:26  269352960 5581790386      0113496771567
C1         31-JUL-2012 23:20:23  134676480 4799842978      0813391427349
Another thing is that, as I said above, the actual table has 120 fields. Do I have to list them all manually if I use something similar?If that's what you need, then yes you would have to list them. You only get data if you tell it you want it. ;)
Of course if you are taking the start_date_of_call, callingnumber and callednumber as the 'key' to the record, then you could join the results of the above back to the original table1 and pull out the rest of the columns that way...
SQL> select * from table1;
SEGMENTID  START_DATE_OF_CALL     DURATION CALLINGNUMBER   CALLEDNUMBER          COL1       COL2       COL3
C1         31-JUL-2012 23:20:23  134676480 4799842978      0813391427349          556         40       5.32
C21        15-MAR-2012 09:07:26  134676480 5581790386      0113496771567          219        100      10.16
C23        11-MAY-2012 09:37:26  134676480 5581790386      0113496771567          321         73       2.71
C21        11-MAY-2012 12:13:10 3892379648 1982032041      0631432831624          959         80       2.87
C22        11-MAY-2012 12:43:10 3892379648 1982032041      0631432831624          375         57       8.91
C22        11-MAY-2012 13:13:10  117899264 1982032041      0631432831624          778         27       1.42
C23        11-MAY-2012 13:43:10  117899264 1982032041      0631432831624          308         97       3.26
7 rows selected.
SQL> ed
Wrote file afiedt.buf
  1  with t2 as (
  2  select 'C1' as segmentid
  3        ,start_date_of_call, duration, callingnumber, callednumber
  4  from (
  5        select distinct
  6               min(start_date_of_call) over (partition by callingnumber, callednumber) as start_date_of_call
  7              ,sum(duration) over (partition by callingnumber, callednumber) as duration
  8              ,callingnumber
  9              ,callednumber
10        from table1
11       )
12  )
13  --
14  select t2.segmentid, t2.start_date_of_call, t2.duration, t2.callingnumber, t2.callednumber
15        ,t1.col1, t1.col2, t1.col3
16  from   t2
17         join table1 t1 on (   t1.start_date_of_call = t2.start_date_of_call
18                           and t1.callingnumber = t2.callingnumber
19                           and t1.callednumber = t2.callednumber
20*                          )
SQL> /
SEGMENTID  START_DATE_OF_CALL     DURATION CALLINGNUMBER   CALLEDNUMBER          COL1       COL2       COL3
C1         11-MAY-2012 12:13:10 8020557824 1982032041      0631432831624          959         80       2.87
C1         15-MAR-2012 09:07:26  269352960 5581790386      0113496771567          219        100      10.16
C1         31-JUL-2012 23:20:23  134676480 4799842978      0813391427349          556         40       5.32
SQL>Of course this is pulling back the additional columns for the record that matches the start_date_of_call for that calling/called number pair, so if the values differed from row to row within the calling/called number pair you may need to aggregate those (take the minimum/maximum etc. as required) as part of the first query. If the values are known to be the same across all records in the group then you can just pick them up from the join to the original table as I coded in the above example (only in my example the data was different across all rows).

Similar Messages

  • Need help in improving the performance for the sql query

    Thanks in advance for helping me.
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. The data count which is updated in the target table is 2 million records and the target table has 15 million records.
    Any suggestions or solutions for improving performance are appreciated
    SQL query:
    update targettable tt
    set mnop = 'G',
    where ( x,y,z ) in
    select a.x, a.y,a.z
    from table1 a
    where (a.x, a.y,a.z) not in (
    select b.x,b.y,b.z
    from table2 b
    where 'O' = b.defg
    and mnop = 'P'
    and hijkl = 'UVW';

    987981 wrote:
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. And that meant what? Surely if you spend all that time and effort to try various approaches, it should mean something? Failures are as important teachers as successes. You need to learn from failures too. :-)
    The data count which is updated in the target table is 2 million records and the target table has 15 million records.Tables have rows btw, not records. Database people tend to get upset when rows are called records, as records exist in files and a database is not a mere collection of records and files.
    The failure to find a single faster method with the approaches you tried, points to that you do not know what the actual performance problem is. And without knowing the problem, you still went ahead, guns blazing.
    The very first step in dealing with any software engineering problem, is to identify the problem. Seeing the symptoms (slow performance) is still a long way from problem identification.
    Part of identifying the performance problem, is understanding the workload. Just what does the code task the database to do?
    From your comments, it needs to find 2 million rows from 15 million rows. Change these rows. And then write 2 million rows back to disk.
    That is not a small workload. Simple example. Let's say that the 2 million row find is 1ms/row and the 2 million row write is also 1ms/row. This means a 66 minute workload. Due to the number of rows, an increase in time/row either way, will potentially have 2 million fold impact.
    So where is the performance problem? Time spend finding the 2 million rows (where other tables need to be read, indexes used, etc)? Time spend writing the 2 million rows (where triggers and indexes need to be fired and maintained)? Both?

  • Improving the performance of Stored Procedure

    need to improve the performance of this SP that is hitting two tables that holds about 24000 rowsUSE [trouble_database]
    GO
    SET ANSI_NULLS OFF
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    ALTER PROCEDURE [dbo].[the_trouble_StoredProcedure]
    @troubleMedicatiotrouble_durationl int
    as
    declare @trouble_refil table
    ( troubleMedicatiotrouble_durationl int,
    trouble_durationl int
    declare @nRefillDispense int
    if exists (select ml.lid from trouble_MedicaticDirectmd
    inner join trouble_Medicatication ml on ml.troubleMedicatiotrouble_durationl=md.lID
    where isnull(md.trouble_bRefillDisp,0)=1
    and ml.lID <>(Select MIN(lID) from trouble_Medicatication where troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl)
    begin
    select @nRefillDispense = isnull(nRefillDispense,9) from trouble_MedicaticDirect where lID=@troubleMedicatiotrouble_durationl
    insert @trouble_refil (trouble_durationl)
    select
    Case szIncrement
    when 'Day(s)' then isnull(trouble_durationl,0)
    when 'Week(s)' then isnull(trouble_durationl,0) * 7
    when 'Month(s)' then isnull(trouble_durationl,0) * 30
    when 'Year(s)' then isnull(trouble_durationl,0) * 365
    else 0
    end as trouble_durationl
    from
    trouble_Medicatication where
    troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl
    and lID<>(Select min(lID) from trouble_Medicatication where troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl)
    select @nRefillDispense as nRefillDispense, sum(trouble_durationl)as trouble_durationl from @trouble_refil
    end
    else
    select 0 as nRefillDispense,0 as trouble_durationl
    k

    you can use Execution plain
    http://stackoverflow.com/questions/7359702/how-do-i-obtain-a-query-execution-plan
    and add index.
    Index according to the fields you ask queries can improve performance greatly larger!
    You can use the statistics for building indexes:
    http://www.mssqltips.com/sqlservertip/2979/querying-sql-server-index-statistics/
    Tzuri Ben Ezra | My Certifications:
    CompTIA A+ ,Microsoft MCP, MCTS, MCSA, MCITP |
    FaceBook: Tzuri FaceBook | vCard:
    Tzuri vCard | 
    Microsoft ID:
    Microsoft Transcript 
     |

  • Improve the performance in stored procedure using sql server 2008 - esp where clause in very big table - Urgent

    Hi,
    I am looking for inputs in tuning stored procedure using sql server 2008. l am new to performance tuning in sql,plsql and oracle. currently facing issue in stored procedure - need to increase the performance by code optmization/filtering the records using where clause in larger table., the requirement is Stored procedure generate Audit Report which is accessed by approx. 10 Admin Users typically 2-3 times a day by each Admin users.
    It has got CTE ( common table expression ) which is referred 2  time within SP. This CTE is very big and fetches records from several tables without where clause. This causes several records to be fetched from DB and then needed processing. This stored procedure is running in pre prod server which has 6gb of memory and built on virtual server and the same proc ran good in prod server which has 64gb of ram with physical server (40sec). and the execution time in pre prod is 1min 9seconds which needs to be reduced upto 10secs or so will be the solution. and also the exec time differs from time to time. sometimes it is 50sec and sometimes 1min 9seconds..
    Pl provide what is the best option/practise to use where clause to filter the records and tool to be used to tune the procedure like execution plan, sql profiler?? I am using toad for sqlserver 5.7. Here I see execution plan tab available while running the SP. but when i run it throws an error. Pl help and provide inputs.
    Thanks,
    Viji

    You've asked a SQL Server question in an Oracle forum.  I'm expecting that this will get locked momentarily when a moderator drops by.
    Microsoft has its own forums for SQL Server, you'll have more luck over there.  When you do go there, however, you'll almost certainly get more help if you can pare down the problem (or at least better explain what your code is doing).  Very few people want to read hundreds of lines of code, guess what's it's supposed to do, guess what is slow, and then guess at how to improve things.  Posting query plans, the results of profiling, cutting out any code that is unnecessary to the performance problem, etc. will get you much better answers.
    Justin

  • Required help in improving the performance

    Hi I am very new to java concept, I am working with an API, where the records are being processed in for loop, and taking time, to process 10k records it is taking almost 35 min, and as I have incorporated in my apex, if the multiple users using the same that stage the performance even being dropped, it is taking almost near to an hour, somehow with the help of online tutors, I was able to incorporate oracle.sql.array, not able to increase the performance,
    My first requirement is there is any way that I can process the records parallel in batches, or not how do I increase the performance, and I got know that by enabling setautoindex and setautobuffer on we can increase the performance, but I could not do that can anyone help me on this.

    Hi
    I apologize for not adding the process in the initial phase
    The task for me to pass the records from my table to api, and update the results given by the api, the steps involved are
    1) I have created type of strarray and have assigned the same to rec1,rec2 in my stored procedure
    2) rec1 is the input details which consist of batch_id unique identifier by batch,row_id unique identifier for the batch and the contact address information.
    3) rec2 is the output for rec1, where i will get the batch_id,row_id, and formatted address in output form
    4) I will capture the opt put in temp table and update these results to the input table
    5) With this stored procedure, i am not able to allow parallel transaction i..e multiple users
    6) As records are being processed row by row, consuming time
    Here is the code, Please let me know if you need more information on this.
    PROCESS_INT (REC_IN, REC_OUT); which will call the following process
         public static int process(oracle.sql.ARRAY rec_in, oracle.sql.ARRAY[] rec_out) {
              // If everything has been initialized then we want to write some data
              // to the socket we have opened a connection to
              if (m_clientSocket != null && m_out != null && m_in != null) {
                   try {
                        String[] record = (String[])rec_in.getArray();
                        for (int i = 0; i < 9; i++) {
                             if (record[i] != null)
                                  m_out.println(record);
                             else
                                  m_out.println("");
                        m_out.flush();
                        // Read the result
                        for (int i = 0; i < 14; i++) {
                             record[i] = m_in.readLine();
                        Connection conn = new OracleDriver().defaultConnection();
                        ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( rec_in.getSQLTypeName(), conn );
                        rec_out[0] = new ARRAY( descriptor, conn, record );
                   } catch (UnknownHostException e) {
                        System.err.println("Unable to connect to lqtListener: " + e);
                        return -1;
                   } catch (IOException e) {
                        System.err.println("IOException in process: " + e);
                        return -2;
                   } catch (SQLException e) {
                        System.err.println("SQLException in process: " + e);
                        return -4;
              else
                   return -3;
              return 0;

  • Needed help to improve the performance of a select query?

    Hi,
    I have been preparing a report which involves data to be fetched from 4 to 5 different tables and calculation has to performed on some columns also,
    i planned to write a single cursor to populate 1 temp table.i have used INLINE VIEW,EXISTS more frequently in the select query..please go through the query and suggest me a better way to restructure the query.
    cursor c_acc_pickup_incr(p_branch_code varchar2, p_applDate date, p_st_dt date, p_ed_dt date) is
    select sca.branch_code "BRANCH",
    sca.cust_ac_no "ACCOUNT",
    to_char(p_applDate, 'YYYYMM') "YEARMONTH",
    sca.ccy "CURRENCY",
    sca.account_class "PRODUCT",
    sca.cust_no "CUSTOMER",
    sca.ac_desc "DESCRIPTION",
    null "LOW_BAL",
    null "HIGH_BAL",
    null "AVG_CR_BAL",
    null "AVG_DR_BAL",
    null "CR_DAYS",
    null "DR_DAYS",
    --null                                 "CR_TURNOVER",       
    --null                                 "DR_TURNOVER",       
    null "DR_OD_DAYS",
    (select sum(gf.limit_amount * (scal.linkage_percentage / 100)) +
    (case when (p_applDate >= sca.tod_limit_start_date and
    p_applDate <= nvl(sca.tod_limit_end_date, p_applDate)) then
    sca.tod_limit else 0 end) dd
    from getm_facility gf, sttm_cust_account_linkages scal
    where gf.line_code || gf.line_serial = scal.linked_ref_no
    and cust_ac_no = sca.cust_ac_no) "OD_LIMIT",
    --sc.credit_rating                      "CR_GRADE",        
    null "AVG_NET_BAL",
    null "UNAUTH_OD_AMT",
    sca.acy_blocked_amount "AMT_BLOCKED",
    (select sum(amt)
    from ictb_entries_history ieh
    where ieh.acc = sca.cust_ac_no
    and ieh.brn = sca.branch_code
    and ieh.drcr = 'D'
    and ieh.liqn = 'Y'
    and ieh.entry_passed = 'Y'
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select * from ictm_pr_int ipi, ictm_rule_frm irf
    where ipi.product_code = ieh.prod
    and ipi.rule = irf.rule_id
    and irf.book_flag = 'B')) "DR_INTEREST",
    (select sum(amt)
    from ictb_entries_history ieh
    where ieh.acc = sca.cust_ac_no
    and ieh.brn = sca.branch_code
    and ieh.drcr = 'C'
    and ieh.liqn = 'Y'
    and ieh.entry_passed = 'Y'
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select * from ictm_pr_int ipi, ictm_rule_frm irf
    where ipi.product_code = ieh.prod
    and ipi.rule = irf.rule_id
    and irf.book_flag = 'B')) "CR_INTEREST",
    (select sum(amt) from ictb_entries_history ieh
    where ieh.brn = sca.branch_code
    and ieh.acc = sca.cust_ac_no
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select product_code
    from ictm_product_definition ipd
    where ipd.product_code = ieh.prod
    and ipd.product_type = 'C')) "FEE_INCOME",
    sca.record_stat "ACC_STATUS",
    case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
    and not exists (select 1
    from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null))
    then 1 else 0 end "NEW_ACC_FOR_THE_MONTH",
    case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
    and trunc(sc.cif_creation_date,'MM') = trunc(p_applDate,'MM')
    and not exists (select 1
    from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null))
    then 1 else 0 end "NEW_ACC_FOR_NEW_CUST",
    (select 1 from dual
    where exists (select 1 from ictm_td_closure_renew itcr
    where itcr.brn = sca.branch_code
    and itcr.acc = sca.cust_ac_no
    and itcr.renewal_date = sysdate)
    or exists (select 1 from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null)) "RENEWED_OR_ROLLOVER",
    (select maturity_date from ictm_acc ia
    where ia.brn = sca.branch_code
    and ia.acc = sca.cust_ac_no) "MATURITY_DATE",
    sca.ac_stat_no_dr "DR_DISALLOWED",
    sca.ac_stat_no_cr "CR_DISALLOWED",
    sca.ac_stat_block                     "BLOCKED_ACC",       Not Reqd
    sca.ac_stat_dormant "DORMANT_ACC",
    sca.ac_stat_stop_pay "STOP_PAY_ACC", --New
    sca.ac_stat_frozen "FROZEN_ACC",
    sca.ac_open_date "ACC_OPENING_DT",
    sca.address1 "ADD_LINE_1",
    sca.address2 "ADD_LINE_2",
    sca.address3 "ADD_LINE_3",
    sca.address4 "ADD_LINE_4",
    sca.joint_ac_indicator "JOINT_ACC",
    sca.acy_avl_bal "CR_BAL",
    0 "DR_BAL",
    0 "CR_BAL_LCY", t
    0 "DR_BAL_LCY",
    null "YTD_CR_MOVEMENT",
    null "YTD_DR_MOVEMENT",
    null "YTD_CR_MOVEMENT_LCY",
    null "YTD_DR_MOVEMENT_LCY",
    null "MTD_CR_MOVEMENT",
    null "MTD_DR_MOVEMENT",
    null "MTD_CR_MOVEMENT_LCY",
    null "MTD_DR_MOVEMENT_LCY",
    'N' "BRANCH_TRFR", --New
    sca.provision_amount "PROVISION_AMT",
    sca.account_type "ACCOUNT_TYPE",
    nvl(sca.tod_limit, 0) "TOD_LIMIT",
    nvl(sca.sublimit, 0) "SUB_LIMIT",
    nvl(sca.tod_limit_start_date, global.min_date) "TOD_START_DATE",
    nvl(sca.tod_limit_end_date, global.max_date) "TOD_END_DATE"
    from sttm_cust_account sca, sttm_customer sc
    where sca.branch_code = p_branch_code
    and sca.cust_no = sc.customer_no
    and ( exists (select 1 from actb_daily_log adl
    where adl.ac_no = sca.cust_ac_no
    and adl.ac_branch = sca.branch_code
    and adl.trn_dt = p_applDate
    and adl.auth_stat = 'A')
    or exists (select 1 from catm_amount_blocks cab
    where cab.account = sca.cust_ac_no
    and cab.branch = sca.branch_code
    and cab.effective_date = p_applDate
    and cab.auth_stat = 'A')
    or exists (select 1 from ictm_td_closure_renew itcr
    where itcr.acc = sca.cust_ac_no
    and itcr.brn = sca.branch_code
    and itcr.renewal_date = p_applDate)
    or exists (select 1 from sttm_ac_stat_change sasc
    where sasc.cust_ac_no = sca.cust_ac_no
    and sasc.branch_code = sca.branch_code
    and sasc.status_change_date = p_applDate
    and sasc.auth_stat = 'A')
    or exists (select 1 from cstb_acc_brn_trfr_log cabtl
    where cabtl.branch_code = sca.branch_code
    and cabtl.cust_ac_no = sca.cust_ac_no
    and cabtl.process_status = 'S'
    and cabtl.process_date = p_applDate)
    or exists (select 1 from sttbs_provision_history sph
    where sph.branch_code = sca.branch_code
    and sph.cust_ac_no = sca.cust_ac_no
    and sph.esn_date = p_applDate)
    or exists (select 1 from sttms_cust_account_dormancy scad
    where scad.branch_code = sca.branch_code
    and scad.cust_ac_no = sca.cust_ac_no
    and scad.dormancy_start_dt = p_applDate)
    or sca.maker_dt_stamp = p_applDate
    or sca.status_since = p_applDate
    l_tb_acc_det ty_tb_acc_det_int;
    l_brnrec cvpks_utils.rec_brnlcy;
    l_acbr_lcy sttms_branch.branch_lcy%type;
    l_lcy_amount actbs_daily_log.lcy_amount%type;
    l_xrate number;
    l_dt_rec sttm_dates%rowtype;
    l_acc_rec sttm_cust_account%rowtype;
    l_acc_stat_row ty_r_acc_stat;
    Edited by: user13710379 on Jan 7, 2012 12:18 AM

    I see it more like shown below (possibly with no inline selects
    Try to get rid of the remaining inline selects ( left as an exercise ;) )
    and rewrite traditional joins as ansi joins as problems might arise using mixed syntax as I have to leave so I don't have time to complete the query
    select sca.branch_code "BRANCH",
           sca.cust_ac_no "ACCOUNT",
           to_char(p_applDate, 'YYYYMM') "YEARMONTH",
           sca.ccy "CURRENCY",
           sca.account_class "PRODUCT",
           sca.cust_no "CUSTOMER",
           sca.ac_desc "DESCRIPTION",
           null "LOW_BAL",
           null "HIGH_BAL",
           null "AVG_CR_BAL",
           null "AVG_DR_BAL",
           null "CR_DAYS",
           null "DR_DAYS",
    --     null "CR_TURNOVER",
    --     null "DR_TURNOVER",
           null "DR_OD_DAYS",
           w.dd "OD_LIMIT",
    --     sc.credit_rating "CR_GRADE",
           null "AVG_NET_BAL",
           null "UNAUTH_OD_AMT",
           sca.acy_blocked_amount "AMT_BLOCKED",
           x.dr_int "DR_INTEREST",
           x.cr_int "CR_INTEREST",
           y.fee_amt "FEE_INCOME",
           sca.record_stat "ACC_STATUS",
           case when trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
                 and not exists(select 1
                                  from ictm_tdpayin_details itd
                                 where itd.multimode_payopt = 'Y'
                                   and itd.brn = sca.branch_code
                                   and itd.acc = sca.cust_ac_no
                                   and itd.multimode_offset_brn is not null
                                   and itd.multimode_tdoffset_acc is not null
                then 1
                else 0
           end "NEW_ACC_FOR_THE_MONTH",
           case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
                 and trunc(sc.cif_creation_date,'MM') = trunc(p_applDate,'MM')
                 and not exists(select 1
                                  from ictm_tdpayin_details itd
                                 where itd.multimode_payopt = 'Y'
                                   and itd.brn = sca.branch_code
                                   and itd.acc = sca.cust_ac_no
                                   and itd.multimode_offset_brn is not null
                                   and itd.multimode_tdoffset_acc is not null
                then 1
                else 0
           end "NEW_ACC_FOR_NEW_CUST",
           (select 1 from dual
             where exists(select 1
                            from ictm_td_closure_renew itcr
                           where itcr.brn = sca.branch_code
                             and itcr.acc = sca.cust_ac_no
                             and itcr.renewal_date = sysdate
                or exists(select 1
                            from ictm_tdpayin_details itd
                           where itd.multimode_payopt = 'Y'
                             and itd.brn = sca.branch_code
                             and itd.acc = sca.cust_ac_no
                             and itd.multimode_offset_brn is not null
                             and itd.multimode_tdoffset_acc is not null
           ) "RENEWED_OR_ROLLOVER",
           m.maturity_date "MATURITY_DATE",
           sca.ac_stat_no_dr "DR_DISALLOWED",
           sca.ac_stat_no_cr "CR_DISALLOWED",
    --     sca.ac_stat_block "BLOCKED_ACC", --Not Reqd
           sca.ac_stat_dormant "DORMANT_ACC",
           sca.ac_stat_stop_pay "STOP_PAY_ACC", --New
           sca.ac_stat_frozen "FROZEN_ACC",
           sca.ac_open_date "ACC_OPENING_DT",
           sca.address1 "ADD_LINE_1",
           sca.address2 "ADD_LINE_2",
           sca.address3 "ADD_LINE_3",
           sca.address4 "ADD_LINE_4",
           sca.joint_ac_indicator "JOINT_ACC",
           sca.acy_avl_bal "CR_BAL",
           0 "DR_BAL",
           0 "CR_BAL_LCY", t
           0 "DR_BAL_LCY",
           null "YTD_CR_MOVEMENT",
           null "YTD_DR_MOVEMENT",
           null "YTD_CR_MOVEMENT_LCY",
           null "YTD_DR_MOVEMENT_LCY",
           null "MTD_CR_MOVEMENT",
           null "MTD_DR_MOVEMENT",
           null "MTD_CR_MOVEMENT_LCY",
           null "MTD_DR_MOVEMENT_LCY",
           'N' "BRANCH_TRFR", --New
           sca.provision_amount "PROVISION_AMT",
           sca.account_type "ACCOUNT_TYPE",
           nvl(sca.tod_limit, 0) "TOD_LIMIT",
           nvl(sca.sublimit, 0) "SUB_LIMIT",
           nvl(sca.tod_limit_start_date, global.min_date) "TOD_START_DATE",
           nvl(sca.tod_limit_end_date, global.max_date) "TOD_END_DATE"
      from sttm_cust_account sca,
           sttm_customer sc,
           (select sca.cust_ac_no
                   sum(gf.limit_amount * (scal.linkage_percentage / 100)) +
                       case when p_applDate >= sca.tod_limit_start_date
                             and p_applDate <= nvl(sca.tod_limit_end_date, p_applDate)
                            then sca.tod_limit else 0
                       end
                      ) dd
              from sttm_cust_account sca
                   getm_facility gf,
                   sttm_cust_account_linkages scal
             where gf.line_code || gf.line_serial = scal.linked_ref_no
               and cust_ac_no = sca.cust_ac_no
             group by sca.cust_ac_no
           ) w,
           (select acc,
                   brn,
                   sum(decode(drcr,'D',amt)) dr_int,
                   sum(decode(drcr,'C',amt)) cr_int
              from ictb_entries_history ieh
             where ent_dt between p_st_dt and p_ed_dt
               and drcr in ('C','D')
               and liqn = 'Y'
               and entry_passed = 'Y'
               and exists(select null
                            from ictm_pr_int ipi,
                                 ictm_rule_frm irf
                           where ipi.rule = irf.rule_id
                             and ipi.product_code = ieh.prod 
                             and irf.book_flag = 'B'
             group by acc,brn
           ) x,
           (select acc,
                   brn,
                   sum(amt) fee_amt
              from ictb_entries_history ieh
             where ieh.ent_dt between p_st_dt and p_ed_dt
               and exists(select product_code
                            from ictm_product_definition ipd
                           where ipd.product_code = ieh.prod
                             and ipd.product_type = 'C'
             group by acc,brn
           ) y,
           ictm_acc m,
           (select sca.cust_ac_no,
                   sca.branch_code
                   coalesce(nvl2(coalesce(t1.ac_no,t1.ac_branch),'exists',null),
                            nvl2(coalesce(t2.account,t2.account),'exists',null),
                            nvl2(coalesce(t3.acc,t3.brn),'exists',null),
                            nvl2(coalesce(t4.cust_ac_no,t4.branch_code),'exists',null),
                            nvl2(coalesce(t5.cust_ac_no,t5.branch_code),'exists',null),
                            nvl2(coalesce(t6.cust_ac_no,t6.branch_code),'exists',null),
                            nvl2(coalesce(t7.cust_ac_no,t7.branch_code),'exists',null),
                            decode(sca.maker_dt_stamp,p_applDate,'exists'),
                            decode(sca.status_since,p_applDate,'exists')
                           ) existence
              from sttm_cust_account sca
                   left outer join
                   (select ac_no,ac_branch
                      from actb_daily_log
                     where trn_dt = p_applDate
                       and auth_stat = 'A'
                   ) t1
                on (sca.cust_ac_no = t1.ac_no
               and  sca.branch_code = t1.ac_branch
                   left outer join
                   (select account,account
                      from catm_amount_blocks
                     where effective_date = p_applDate
                       and auth_stat = 'A'
                   ) t2
                on (sca.cust_ac_no = t2.account
               and  sca.branch_code = t2.branch
                   left outer join
                   (select acc,brn
                      from ictm_td_closure_renew itcr
                     where renewal_date = p_applDate
                   ) t3
                on (sca.cust_ac_no = t3.acc
               and  sca.branch_code = t3.brn
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttm_ac_stat_change
                     where status_change_date = p_applDate
                       and auth_stat = 'A'
                   ) t4
                on (sca.cust_ac_no = t4.cust_ac_no
               and  sca.branch_code = t4.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from cstb_acc_brn_trfr_log
                     where process_date = p_applDate
                       and process_status = 'S'
                   ) t5
                on (sca.cust_ac_no = t5.cust_ac_no
               and  sca.branch_code = t5.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttbs_provision_history
                     where esn_date = p_applDate
                   ) t6
                on (sca.cust_ac_no = t6.cust_ac_no
               and  sca.branch_code = t6.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttms_cust_account_dormancy
                     where dormancy_start_dt = p_applDate
                   ) t7
                on (sca.cust_ac_no = t7.cust_ac_no
               and  sca.branch_code = t7.branch_code
           ) z
    where sca.branch_code = p_branch_code
       and sca.cust_no = sc.customer_no
       and sca.cust_ac_no = w.cust_ac_no
       and sca.cust_ac_no = x.acc
       and sca.branch_code = x.brn
       and sca.cust_ac_no = y.acc
       and sca.branch_code = y.brn
       and sca.cust_ac_no = m.acc
       and sca.branch_code = m.brn
       and sca.cust_ac_no = z.sca.cust_ac_no
       and sca.branch_code = z.branch_code
       and z.existence is not nullRegards
    Etbin

  • Options to improve the performance of the Job

    Hi Team,
    As part of the CRM Upgrade requirement, we are planning to use Account Life cycle functionality to reflect the status of an account.
    As per the SAP recommendations( Note 1113330) we are currently executing the program CRM_BUPA_USERSTATUS_CONV2ROLE to convert user status master data to BP roles. We have noticed that this program is taking more time even when we run this for single business partner. We are trying to explore the options on how to improve the performance of the job. Incase if anyone have done this kind of exercise in any of their previous assignments or have information on this, request to provide your feedback on the below points.
    1) Total Volume of Customer Master Data
    2) How many records did we consider for one execution of the conversion program
    3) How much time did it toke for one execution ?Did we do any performance tuning
    4) When we are running the program in back ground mode..we are not getting the spool
    showing the log information. Was there any custom report developed to view the log when
    we execute the program in background mode..if so can you share us the technical details
    6) Any information on how many work processors that were available for executing the jobs 
    Appreciate your help.
    Regards,
    Varun

    Hello Udaya ,
    Could you please tryy providing a range of BPs as per note 1121015? This can help in improving the performance .
    Thanks & regards,
    Krishnen

  • Please help me how to improve the performance of this query further.

    Hi All,
    Please help me how to improve the performance of this query further.
    Thanks.

    Hi,
    this is not your first SQL tuning request in this community -- you really should learn how to obtain performance diagnostics.
    The information you posted is not nearly enough to even start troubleshooting the query -- you haven't specified elapsed time, I/O, or the actual number of rows the query returns.
    The only piece of information we have is saying that your query executes within a second. If we believe this, then your query doesn't need tuning. If we don't, then we throw it away
    and we're left with nothing.
    Start by reading this blog post: Kyle Hailey &amp;raquo; Power of DISPLAY_CURSOR
    and applying this knowledge to your case.
    Best regards,
      Nikolay

  • Re: How to Improve the performance on Rollup of Aggregates for PCA Infocube

    Hi BW Guru's,
    I have unresolved issue and our team is still working on it.
    I have already posted several questions on this but not clear on how to reduce the time on Rollup of Aggregates process.
    I have requested for OSS note and searching myself but still could not found.
    Finally i have executed one of the cube in RSRV with the database selection
    "Database indexes of an InfoCube and its aggregates"  and got warning messages i was tried to correct the error and executed once again but still i found warning message. and the error message are as follows: (this is only for one info cube we got 6 info cubes i am executing one by one).
    ORACLE: Index /BI0/IACCOUNT~0 has possibly degenerated
    ORACLE: Index /BI0/IPROFIT_CTR~0 has possibly degenerated     
    ORACLE: Index /BI0/SREQUID~0 has possibly degenerated
    ORACLE: Index /BIC/D1001072~010 has possibly degenerated
    ORACLE: Index /BIC/D1001132~010 has possibly degenerated
    ORACLE: Index /BIC/D1001212~010 has possibly degenerated
    ORACLE: Index /BIC/DGPCOGC062~01 has possibly degenerated
    ORACLE: Index /BIC/IGGRA_CODE~0 has possibly degenerated
    ORACLE: Index /BIC/QGMAPGP1~0 has possibly degenerated
    ORACLE: Index /BIC/QGMAPPC2~0 has possibly degenerated
    ORACLE: Index /BIC/SGMAPGP1~0 has possibly degenerated
    i don't know how to move further on this can any one tell me how to tackle this problem to increase the performance on Rollup of Aggregates (PCA Info cubes).
    every time i use to create index and statistics regularly to improve the performance it will work for couple of days and again the performance of the rollup of aggregates come down gradually.
    Thanks and Regards,
    Venkat

    hi,
    check in a sql client the sql created by Bi and the query that you use directy from your physical layer...
    The time between these 2 must be 2-3 seconds,otherwise you have problems.(these seconds are for scripts that needed by Bi)
    If you use "like" in your sql then forget indexes....
    For more informations about indexes check google or your Dba .
    Last, i mentioned that materialize view is not perfect,it help a lot..so why not try to split it to smaller ones....
    ex...
    logiacal dimensions
    year-half-day
    company-department
    fact
    quantity
    instead of making one...make 3,
    year - department - quantity
    half - department - quantity
    day - department - quantity
    and add them as datasource and assign them the appropriate logical level at bussiness layer in administrator...
    Do you use partioning functionality???
    i hope i helped....
    http://greekoraclebi.blogspot.com/
    ///////////////////////////////////////

  • Hi sap gurus can u plz improve the performance of my code --sneha

    // for the below program i have performance issue can any sap gurus can modify my code to improve the performance ,its very urgent  plz help me -
    sneha
    REPORT  ZFIR_GRIR_IPV
            NO STANDARD PAGE HEADING
            LINE-SIZE 120
            MESSAGE-ID ZFI02.
    TABLES: BSEG,BKPF.
    TYPES: BEGIN OF A_FINAL,
            BUKRS   TYPE CHAR12,
            HKONT_P TYPE CHAR18,
            GJAHR   TYPE CHAR11,
            BELNR   TYPE CHAR19,
            BUDAT   TYPE CHAR12,
            WAERS   TYPE CHAR8,
            XBLNR   TYPE CHAR20,
            BLART   TYPE CHAR13,
            MONAT   TYPE CHAR13,
            DMBTR_P TYPE CHAR13,
            KOSTL   TYPE CHAR11,
            PRCTR_P TYPE CHAR13,
            HKONT_G TYPE CHAR18,
            DMBTR_G TYPE CHAR13,
            PRCTR_G TYPE CHAR13,
            BUZID_G TYPE CHAR15,
            END OF A_FINAL.
    changes on 30 th may by dileep
    TYPES: BEGIN OF IT_FINAL,
            BUKRS   TYPE BUKRS ,
            HKONT TYPE HKONT,
            BELNR   TYPE BELNR_D,
            DMBTR TYPE DMBTR ,
            KOSTL   TYPE KOSTL,
            PRCTR TYPE PRCTR,
            END OF IT_FINAL.
    TYPES: BEGIN OF IT_FINAL1,
            BUKRS   TYPE BUKRS,
            HKONT TYPE HKONT,
            GJAHR   TYPE GJAHR ,
            BELNR   TYPE  BELNR_D,
            BUDAT   TYPE BUDAT,
            WAERS   TYPE WAERS ,
            XBLNR   TYPE XBLNR1,
            BLART   TYPE BLART,
            MONAT   TYPE MONAT,
            DMBTR TYPE DMBTR,
            KOSTL   TYPE KOSTL,
            PRCTR TYPE PRCTR,
             END OF IT_FINAL1.
    end of changes on 30 th may by dileep
    TYPES: BEGIN OF P_FINAL,
            BUKRS   TYPE CHAR12,
            DELIMITER_1         TYPE CHAR1,
            HKONT_P TYPE CHAR18,
             DELIMITER_2         TYPE CHAR1,
            GJAHR   TYPE CHAR11,
            DELIMITER_3         TYPE CHAR1,
            BELNR   TYPE CHAR19,
            DELIMITER_4         TYPE CHAR1,
            BUDAT   TYPE CHAR12,
            DELIMITER_5        TYPE CHAR1,
            WAERS   TYPE CHAR8,
            DELIMITER_6         TYPE CHAR1,
            XBLNR   TYPE CHAR20,
            DELIMITER_7         TYPE CHAR1,
            BLART   TYPE CHAR13,
            DELIMITER_8         TYPE CHAR1,
            MONAT   TYPE CHAR13,
            DELIMITER_9         TYPE CHAR1,
            DMBTR_P TYPE CHAR13,
            DELIMITER_10         TYPE CHAR1,
            KOSTL   TYPE CHAR11,
            DELIMITER_11         TYPE CHAR1,
            PRCTR_P TYPE CHAR13,
            DELIMITER_12         TYPE CHAR1,
            HKONT_G TYPE CHAR18,
            DELIMITER_13         TYPE CHAR1,
            DMBTR_G TYPE CHAR13,
            DELIMITER_14         TYPE CHAR1,
            PRCTR_G TYPE CHAR13,
            DELIMITER_15        TYPE CHAR1,
            BUZID_G TYPE CHAR15,
            END OF P_FINAL.
    DATA: IT_BSEG TYPE STANDARD TABLE OF IT_FINAL INITIAL SIZE 0,
          I_BSEG TYPE STANDARD TABLE OF IT_FINAL1 INITIAL SIZE 0,
          I_FINAL TYPE STANDARD TABLE OF A_FINAL INITIAL SIZE 0 WITH HEADER LINE,
          I_FINAL_P TYPE STANDARD TABLE OF P_FINAL INITIAL SIZE 0 WITH HEADER LINE,
          W_FINAL_P TYPE P_FINAL,
          W_BSEG1 TYPE BSEG,
          WA_BSEG TYPE IT_FINAL OCCURS 0 WITH HEADER LINE,
          W_BSEG TYPE IT_FINAL1 OCCURS 0 WITH HEADER LINE,
          T_BSEG TYPE STANDARD TABLE OF BSEG INITIAL SIZE 0 WITH HEADER LINE,
          W_FINAL TYPE A_FINAL,
          F_YEAR  TYPE  BAPI0002_4-FISCAL_YEAR,
          F_PERIOD  TYPE  BAPI0002_4-FISCAL_PERIOD,
          RETURN1 TYPE BAPIRETURN1,
          V_DATE        TYPE  CHAR8,               " Date in YYYYMMDD format
          V_PRESPATH    TYPE  STRING,              " Path
          V_APPPATH     TYPE  STRING,               " Path
          V_FILENAME(25) TYPE C,                    " File Name
          V_PERIOD      TYPE  CHAR3,                " Date for Posting Period
          V_FSYEAR      TYPE  BDATJ,                " Fiscal Year
          L_TEXT        TYPE  CHAR1.                " Hypen
    CONSTANTS:   C_TXT       TYPE    CHAR4    VALUE  '.txt',          " File Extension
                 C_TXT1      TYPE    STRING   VALUE  'txt',           " File Type
                 C_FLAG_X    TYPE    CHAR1    VALUE  'X',             " Flag
                 C_ASC       TYPE    FILETYPE VALUE  'ASC',           " File type
                 C_DAT       TYPE    CHAR4    VALUE  '.dat',          " File Type
                 C_FLAG_1    TYPE    CHAR1    VALUE  '1',             " Constant value
                 C_ZERO      TYPE    CHAR1    VALUE  '0',             " Constant
                 C_GLD(10)    TYPE    C        VALUE  'GRIR021S',       " Constant in file Path
                 C_DIR       TYPE    CHAR3    VALUE  'C:\',           " Presentation Server path
                 C_FLAG_12   TYPE    CHAR2    VALUE  '12',            " Constant value
                 C_PCFILE    TYPE    STRING   VALUE  'PC File',
                 C_DELIMITER TYPE    C        VALUE  '|'.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
    *--- Selection Criteria
    SELECT-OPTIONS: S_BUKRS  FOR    BSEG-BUKRS   DEFAULT '012T',       " Company Code
                    S_HKONT  FOR    BSEG-HKONT OBLIGATORY DEFAULT '4505001',
                    S_GJAHR  FOR    BKPF-GJAHR   DEFAULT SY-DATUM+0(4),
                    S_MONAT  FOR    BKPF-MONAT   DEFAULT SY-DATUM+4(2),
                    S_BELNR  FOR    BSEG-BELNR ,
                    S_BUDAT  FOR    BKPF-BUDAT ,
                    S_PRCTR  FOR    BSEG-PRCTR OBLIGATORY DEFAULT '12TOTH00',
                    S_BLART  FOR    BKPF-BLART   OBLIGATORY DEFAULT 'RE'.
    SELECTION-SCREEN END OF BLOCK B1.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.
    *--- Radio Buttons for chose the PC Path or App.. Server Path
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS:
      RB_PFILE  RADIOBUTTON  GROUP RAD2 DEFAULT 'X' USER-COMMAND UCOMM1.
    SELECTION-SCREEN COMMENT 5(27) TEXT-002 FOR FIELD RB_PFILE.
    PARAMETERS:
      P_PFILE   LIKE     RLGRAP-FILENAME LOWER CASE.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS:
      RB_AFILE  RADIOBUTTON  GROUP RAD2.
    SELECTION-SCREEN COMMENT 5(27) TEXT-003 FOR FIELD RB_AFILE.
    PARAMETERS:
      P_AFILE   LIKE     RLGRAP-FILENAME LOWER CASE.  " Path for AS
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PFILE.
    *-- Select File name with Dialog Box
      PERFORM SUB_GET_FILENAME CHANGING P_PFILE.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_AFILE.
    *--- Attach F4 HELP CORRESPONDING TO THE FIELD
      PERFORM  SUB_AP_F4.
    AT SELECTION-SCREEN OUTPUT.
    *--Modify screen parameters
      PERFORM SUB_MODIFY_SCREEN.
    AT SELECTION-SCREEN.
    *--- Selection Screen validations for Company Code
      PERFORM SUB_VALIDATION_BUKRS.
    *--- Selection Screen validations for Chart of Accounts
      PERFORM SUB_VALIDATION_HKONT.
    *--- Selection Screen validations Fiscal Year
      PERFORM SUB_VALIDATION_GJAHR.
    *--- Selection Screen validations for Peiod
      PERFORM SUB_VALIDATION_MONAT.
    *--- Selection Screen validations for Company Code
      PERFORM SUB_VALIDATION_BELNR.
    *--- Selection Screen validations for Chart of Accounts
      PERFORM SUB_VALIDATION_BUDAT.
    *--- Selection Screen validations Fiscal Year
      PERFORM SUB_VALIDATION_PRCTR.
    *--- Selection Screen validations for Peiod
      PERFORM SUB_VALIDATION_BLART.
                            START-OF-SELECTION
    START-OF-SELECTION.
    *--- Check whether filepath/name have been entered in the sel screen
      PERFORM SUB_CHECK_FILEPATH.
    *--- Prepare Final Internal Table.
      PERFORM SUB_PREPARE_FINAL.
    *---  Download data.
      PERFORM SUB_DOWNLOAD_DATA .
    *&      Form  sub_get_filename
          text
         <--P_PFILE  Presentation server File name
    FORM SUB_GET_FILENAME  CHANGING P_FILE TYPE C.
      DATA :  L_FILENAME   TYPE STRING,                " For File Name
              L_PATH       TYPE STRING,                " For Directory
              L_FULLPATH   TYPE STRING.                " Full path
    *--- For File Open Dialog Box
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
        EXPORTING
          WINDOW_TITLE         = C_PCFILE              " Window Title
          DEFAULT_EXTENSION    = C_TXT1                " File Extn
          PROMPT_ON_OVERWRITE  = C_FLAG_X              " Over write
        CHANGING
          FILENAME             = L_FILENAME            " File Name
          PATH                 = L_PATH                " File Path
          FULLPATH             = L_FULLPATH            " Full Path
        EXCEPTIONS
          CNTL_ERROR           = 1
          ERROR_NO_GUI         = 2
          NOT_SUPPORTED_BY_GUI = 3
          OTHERS               = 4.
      IF SY-SUBRC NE 0.
    *--- Error in opening the file
        MESSAGE E000.
      ELSE.
        CONCATENATE L_PATH
                    L_FILENAME
               INTO P_FILE.
        V_PRESPATH  = L_PATH.
      ENDIF.
    ENDFORM.                    " sub_get_filename
    *&      Form  sub_ap_f4
          f4 help attched with application server
    FORM SUB_AP_F4 .
    *--- FM for to get the Application Server Path
      IF RB_AFILE = C_FLAG_X.
        CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
         EXPORTING
         DIRECTORY              =
           FILEMASK               = C_ASC                 " File Extn
        IMPORTING
           SERVERFILE             = P_AFILE               " File Path
        EXCEPTIONS
           CANCELED_BY_USER       = 1
           OTHERS                 = 2.
        IF SY-SUBRC NE 0.
    *--- Error in opening the file
          MESSAGE E000.
        ENDIF.
      ENDIF.
    ENDFORM.                                                    " sub_ap_f4
    *&      Form  sub_modify_screen
          text
    -->  p1        text
    <--  p2        text
    FORM SUB_MODIFY_SCREEN .
    *--- Selection screen Modifications
      IF RB_PFILE = C_FLAG_X.
        LOOP AT SCREEN.
          IF SCREEN-NAME = 'P_PFILE' OR
             SCREEN-NAME = '%_P_PFILE_%_APP_%-TEXT'.
            SCREEN-ACTIVE = C_FLAG_1.
            CONCATENATE C_DIR C_GLD V_DATE SY-UZEIT(4) C_TXT INTO P_PFILE.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ELSE.
        LOOP AT SCREEN.
          IF SCREEN-NAME = 'P_PFILE' OR
             SCREEN-NAME = '%_P_PFILE_%_APP_%-TEXT'.
            SCREEN-ACTIVE = C_ZERO.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
      IF RB_AFILE = C_FLAG_X.
        LOOP AT SCREEN.
          IF SCREEN-NAME = 'P_AFILE' OR
             SCREEN-NAME = '%_P_AFILE_%_APP_%-TEXT'.
            SCREEN-ACTIVE = C_FLAG_1.
            CONCATENATE '/Solectron/Data/' C_GLD V_DATE SY-UZEIT(4) C_DAT
                          INTO P_AFILE.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ELSE.
        LOOP AT SCREEN.
          IF SCREEN-NAME = 'P_AFILE' OR
             SCREEN-NAME = '%_P_AFILE_%_APP_%-TEXT'.
            SCREEN-ACTIVE = C_ZERO.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
      IF RB_PFILE = C_FLAG_X.
        LOOP AT SCREEN.
          IF SCREEN-NAME = 'P_PFILE'.
            SCREEN-ACTIVE = C_FLAG_1.
          ENDIF.
          IF SCREEN-NAME = 'P_AFILE'.
            SCREEN-ACTIVE = C_ZERO.
          ENDIF.
          MODIFY SCREEN.
        ENDLOOP.
      ELSEIF RB_AFILE = C_FLAG_X.
        LOOP AT SCREEN.
          IF SCREEN-NAME = 'P_PFILE'.
            SCREEN-ACTIVE = C_ZERO.
          ENDIF.
          IF SCREEN-NAME = 'P_AFILE'.
            SCREEN-ACTIVE = C_FLAG_1.
          ENDIF.
          MODIFY SCREEN.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " sub_modify_screen
    *&      Form  sub_validation_bukrs
          Validation For Company Code
    FORM SUB_VALIDATION_BUKRS .
      DATA: L_BUKRS  TYPE  BUKRS.                " Company Code
      IF S_BUKRS IS NOT INITIAL.
        IF S_BUKRS-HIGH IS NOT INITIAL AND S_BUKRS-LOW IS INITIAL.
          MESSAGE E006.
        ELSE.
    *--- Validation for chart of accounts
          SELECT BUKRS                              " Company Code
          FROM T001 UP TO 1 ROWS
          INTO L_BUKRS
          WHERE BUKRS IN S_BUKRS.
          ENDSELECT.
          IF SY-SUBRC  NE  0.
    *--- Invalid Company code
            MESSAGE E001.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_bukrs
    *&      Form  sub_validation_hkont
          Validation For General Ledger Account
    FORM SUB_VALIDATION_HKONT .
      DATA: L_HKONT  TYPE HKONT.                " General Ledger Account
      IF S_HKONT IS INITIAL.
        MESSAGE E002.
      ELSE.
        IF S_HKONT-HIGH IS NOT INITIAL AND S_HKONT-LOW IS INITIAL.
          MESSAGE E006.
        ELSE.
    *--- Validation for chart of accounts
          SELECT SAKNR                             " General Ledger Account
          FROM SKA1 UP TO 1 ROWS
          INTO L_HKONT
          WHERE SAKNR IN S_HKONT AND KTOPL = '1SLR'.
          ENDSELECT.
          IF SY-SUBRC  NE  0.
    *--- Invalid General Ledger Account
            MESSAGE E003.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_hkont
    *&      Form  sub_validation_gjahr
          Validation For Fiscal Year
    FORM SUB_VALIDATION_GJAHR .
      DATA: L_GJAHR  TYPE  GJAHR.                " Fiscal Year
      IF S_GJAHR IS NOT INITIAL.
        IF S_GJAHR-HIGH IS NOT INITIAL AND S_GJAHR-LOW IS INITIAL.
          MESSAGE E006.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_gjahr
    *&      Form  sub_validation_monat
          Validation For Fiscal period
    FORM SUB_VALIDATION_MONAT .
      DATA: L_MONAT  TYPE  MONAT.                " Fiscal period
      IF S_MONAT IS NOT INITIAL.
        IF S_MONAT-LOW LE C_ZERO.
    *--- Invalid Fiscal Period
          MESSAGE E006.
        ENDIF.
        IF S_MONAT-HIGH GT C_FLAG_12.
    *--- Invalid Fiscal Period
          MESSAGE E007.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_monat
    *&      Form  sub_validation_belnr
          Validation For Accounting Document Number
    FORM SUB_VALIDATION_BELNR .
      DATA: L_BELNR  TYPE BELNR_D.                " Accounting Document Number
      IF S_BELNR IS NOT INITIAL.
        IF S_BELNR-HIGH IS NOT INITIAL AND S_BELNR-LOW IS INITIAL.
          MESSAGE E006.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_belnr
    *&      Form  sub_validation_budat
          Validation For Posting Date
    FORM SUB_VALIDATION_BUDAT .
      DATA: L_BUDAT  TYPE  BUDAT.                " Posting Date
      IF S_BUDAT IS NOT INITIAL.
        IF S_BUDAT-HIGH IS NOT INITIAL AND S_BUDAT-LOW IS INITIAL.
          MESSAGE E006.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_budat
    *&      Form  sub_validation_prctr
          Validation For Profit Center
    FORM SUB_VALIDATION_PRCTR .
      DATA: L_PRCTR  TYPE  PRCTR.                " Profit Center
      IF S_PRCTR IS INITIAL.
        MESSAGE E010.
      ELSE.
        IF S_PRCTR-HIGH IS NOT INITIAL AND S_PRCTR-LOW IS INITIAL.
          MESSAGE E006.
        ELSE.
    *--- Validation for chart of accounts
          SELECT PRCTR                             " Profit Center
          FROM CEPC UP TO 1 ROWS
          INTO L_PRCTR
          WHERE PRCTR IN S_PRCTR.
          ENDSELECT.
          IF SY-SUBRC  NE  0.
    *--- Invalid Profit Center
            MESSAGE E011.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_prctr
    *&      Form  sub_validation_blart
          Validation For Document type
    FORM SUB_VALIDATION_BLART .
      DATA: L_BLART  TYPE  BLART.                " Document type
      IF S_BLART IS INITIAL.
        MESSAGE E012.
      ELSE.
        IF S_BLART-HIGH IS NOT INITIAL AND S_BLART-LOW IS INITIAL.
          MESSAGE E006.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_validation_blart
    *&      Form  sub_check_filepath
          Check user input for initial filename
    FORM SUB_CHECK_FILEPATH .
      IF RB_PFILE = C_FLAG_X.
        IF P_PFILE IS INITIAL.
    *--- The Local File Path can not be Empty
          MESSAGE I014.
          LEAVE LIST-PROCESSING.
        ENDIF.
      ELSEIF RB_AFILE = C_FLAG_X.
        IF P_AFILE IS INITIAL.
    *--- The App Server File Path can not be Empty
          MESSAGE I015.
          LEAVE LIST-PROCESSING.
        ENDIF.
      ENDIF.
    ENDFORM.                    " sub_check_filepath
    *&      Form  sub_prepare_final
          append the required output data in to the internal table.
    FORM SUB_PREPARE_FINAL.
    changes on 30 th may by dileep
    SELECT * FROM BSEG INTO TABLE I_BSEG WHERE HKONT IN S_HKONT AND  "G/L Account
                                                GJAHR IN S_GJAHR AND
                                                PRCTR IN S_PRCTR AND  "Profit Center
                                                BLART IN S_BLART .  "Document Type
      SELECT BUKRS
             HKONT
             BELNR
             DMBTR
             KOSTL
             PRCTR
             FROM BSEG INTO TABLE IT_BSEG WHERE HKONT IN S_HKONT AND  "G/L Account
                                                PRCTR IN S_PRCTR.  "Profit Center
      LOOP AT IT_BSEG INTO WA_BSEG.
        SELECT SINGLE GJAHR
               BUDAT
               WAERS
               XBLNR
               BLART
               MONAT
               INTO (W_BSEG-GJAHR,W_BSEG-BUDAT,W_BSEG-WAERS,W_BSEG-XBLNR,W_BSEG-BLART,W_BSEG-MONAT)
                 FROM BKPF WHERE BELNR = W_BSEG-BELNR AND
                       GJAHR IN S_GJAHR AND
                       BLART IN S_BLART .  "Document Type
        MOVE WA_BSEG-BUKRS TO W_BSEG-BUKRS.
        MOVE WA_BSEG-HKONT TO W_BSEG-HKONT.
        MOVE WA_BSEG-BELNR TO W_BSEG-BELNR.
        MOVE WA_BSEG-DMBTR TO W_BSEG-DMBTR.
        MOVE WA_BSEG-KOSTL TO W_BSEG-KOSTL.
        MOVE WA_BSEG-PRCTR TO W_BSEG-PRCTR.
        APPEND W_BSEG TO I_BSEG.
      ENDLOOP.
    changes on 30 th may by dileep
      IF S_BUKRS IS NOT INITIAL.
        SORT I_BSEG BY BUKRS ASCENDING.
        DELETE I_BSEG WHERE NOT BUKRS IN S_BUKRS.
      ENDIF.
      IF S_MONAT IS NOT INITIAL.
        SORT I_BSEG BY GJAHR MONAT ASCENDING.
        IF S_MONAT-HIGH IS NOT INITIAL AND S_MONAT-LOW IS NOT INITIAL.
          DELETE I_BSEG WHERE MONAT < S_MONAT-LOW OR MONAT > S_MONAT-HIGH.
        ENDIF.
        IF S_MONAT-HIGH IS INITIAL AND S_MONAT-LOW IS NOT INITIAL.
          DELETE I_BSEG WHERE MONAT NE S_MONAT-LOW.
        ENDIF.
      ENDIF.
      IF S_BELNR IS NOT INITIAL.
        SORT I_BSEG BY BELNR ASCENDING.
        DELETE I_BSEG WHERE NOT BELNR IN S_BELNR.
      ENDIF.
      IF S_BUDAT IS NOT INITIAL.
        SORT I_BSEG BY BUDAT ASCENDING.
        DELETE I_BSEG WHERE NOT BUDAT IN S_BUDAT.
      ENDIF.
      LOOP AT I_BSEG INTO W_BSEG.
        MOVE W_BSEG-BUKRS      TO W_FINAL-BUKRS.
        MOVE W_BSEG-HKONT      TO W_FINAL-HKONT_P.
        MOVE W_BSEG-GJAHR      TO W_FINAL-GJAHR.
        MOVE W_BSEG-BELNR      TO W_FINAL-BELNR.
        MOVE W_BSEG-BUDAT      TO W_FINAL-BUDAT.
        MOVE W_BSEG-WAERS      TO W_FINAL-WAERS.
        MOVE W_BSEG-XBLNR      TO W_FINAL-XBLNR.
        MOVE W_BSEG-BLART      TO W_FINAL-BLART.
        MOVE W_BSEG-MONAT      TO W_FINAL-MONAT.
        MOVE W_BSEG-DMBTR      TO W_FINAL-DMBTR_P.
        MOVE W_BSEG-KOSTL      TO W_FINAL-KOSTL.
        MOVE W_BSEG-PRCTR      TO W_FINAL-PRCTR_P.
        SELECT SINGLE * FROM BSEG INTO W_BSEG1 WHERE BELNR = W_BSEG-BELNR AND    "Document Type
                                              BUZID = 'W' .
        IF SY-SUBRC = 0.
          MOVE W_BSEG1-HKONT      TO W_FINAL-HKONT_G.
          MOVE W_BSEG1-DMBTR      TO W_FINAL-DMBTR_G.
          MOVE W_BSEG1-PRCTR      TO W_FINAL-PRCTR_G.
          MOVE W_BSEG1-BUZID      TO W_FINAL-BUZID_G.
        ELSE.
          EXIT.
        ENDIF.
        APPEND W_FINAL TO I_FINAL.
        SORT I_FINAL BY BELNR ASCENDING.
      ENDLOOP.
    ENDFORM.                  " sub_prepare_final
    *&      Form  sub_download_data
          Download data
    FORM SUB_DOWNLOAD_DATA .
      DATA : V_PRD(2) TYPE N.
      IF RB_PFILE = C_FLAG_X.
    *--- Downloading To presentation server
        V_PRESPATH = P_PFILE.
        PERFORM SUB_DOWNLOAD_PRESSERVER.
      ELSEIF RB_AFILE = C_FLAG_X.
    *--- Downloading To Application server in Auto Mode
        V_APPPATH = P_AFILE.
        PERFORM SUB_DOWNLOAD_APPSERVER.
      ENDIF.
    ENDFORM.                    " sub_download_data
    *&      Form  sub_download_presserver
          text
    FORM SUB_DOWNLOAD_PRESSERVER.
      DATA: MESSAGE TYPE STRING.
      IF I_FINAL[] IS INITIAL.
        MESSAGE I016.
        EXIT.
      ELSE.
        W_FINAL_P-BUKRS = 'Company Code'.
        W_FINAL_P-DELIMITER_1 = '|'.
        W_FINAL_P-HKONT_P = 'G/L Account Number'.
        W_FINAL_P-DELIMITER_2 = '|'.
        W_FINAL_P-GJAHR = 'Fiscal Year'.
        W_FINAL_P-DELIMITER_3 = '|'.
        W_FINAL_P-BELNR = 'A/c Document Number'.
        W_FINAL_P-DELIMITER_4 = '|'.
        W_FINAL_P-BUDAT  = 'Posting Date' .
        W_FINAL_P-DELIMITER_5 = '|'.
        W_FINAL_P-WAERS = 'Currency'.
        W_FINAL_P-DELIMITER_6 = '|'.
        W_FINAL_P-XBLNR = 'Ref. Document Number'.
        W_FINAL_P-DELIMITER_7 = '|'.
        W_FINAL_P-BLART = 'Document Type'.
        W_FINAL_P-DELIMITER_8 = '|'.
        W_FINAL_P-MONAT = 'Fiscal Period'.
        W_FINAL_P-DELIMITER_9 = '|'.
        W_FINAL_P-DMBTR_P = 'Amount'.
        W_FINAL_P-DELIMITER_10 = '|'.
        W_FINAL_P-KOSTL = 'Cost Center'.
        W_FINAL_P-DELIMITER_11 = '|'.
        W_FINAL_P-PRCTR_P = 'Profit Center'.
        W_FINAL_P-DELIMITER_12 = '|'.
        W_FINAL_P-HKONT_G = 'G/L Account Number'.
        W_FINAL_P-DELIMITER_13 = '|'.
        W_FINAL_P-DMBTR_G = 'Amount'.
        W_FINAL_P-DELIMITER_14 = '|'.
        W_FINAL_P-PRCTR_G = 'Profit Center'.
        W_FINAL_P-DELIMITER_15 = '|'.
        W_FINAL_P-BUZID_G = 'Line Item Id'.
        APPEND W_FINAL_P TO I_FINAL_P.
        LOOP AT I_FINAL INTO W_FINAL.
          W_FINAL_P-BUKRS = W_FINAL-BUKRS.
          W_FINAL_P-DELIMITER_1 = '|'.
          W_FINAL_P-HKONT_P = W_FINAL-HKONT_P.
          W_FINAL_P-DELIMITER_2 = '|'.
          W_FINAL_P-GJAHR = W_FINAL-GJAHR.
          W_FINAL_P-DELIMITER_3 = '|'.
          W_FINAL_P-BELNR = W_FINAL-BELNR.
          W_FINAL_P-DELIMITER_4 = '|'.
          W_FINAL_P-BUDAT  = W_FINAL-BUDAT .
          W_FINAL_P-DELIMITER_5 = '|'.
          W_FINAL_P-WAERS = W_FINAL-WAERS.
          W_FINAL_P-DELIMITER_6 = '|'.
          W_FINAL_P-XBLNR = W_FINAL-XBLNR.
          W_FINAL_P-DELIMITER_7 = '|'.
          W_FINAL_P-BLART = W_FINAL-BLART.
          W_FINAL_P-DELIMITER_8 = '|'.
          W_FINAL_P-MONAT = W_FINAL-MONAT.
          W_FINAL_P-DELIMITER_9 = '|'.
          W_FINAL_P-DMBTR_P = W_FINAL-DMBTR_P.
          W_FINAL_P-DELIMITER_10 = '|'.
          W_FINAL_P-KOSTL = W_FINAL-KOSTL.
          W_FINAL_P-DELIMITER_11 = '|'.
          W_FINAL_P-PRCTR_P = W_FINAL-PRCTR_P.
          W_FINAL_P-DELIMITER_12 = '|'.
          W_FINAL_P-HKONT_G = W_FINAL-HKONT_G.
          W_FINAL_P-DELIMITER_13 = '|'.
          W_FINAL_P-DMBTR_G = W_FINAL-DMBTR_G.
          W_FINAL_P-DELIMITER_14 = '|'.
          W_FINAL_P-PRCTR_G = W_FINAL-PRCTR_G.
          W_FINAL_P-DELIMITER_15 = '|'.
          W_FINAL_P-BUZID_G = W_FINAL-BUZID_G.
          APPEND W_FINAL_P TO I_FINAL_P.
          CLEAR : W_FINAL_P, W_FINAL.
        ENDLOOP.
      ENDIF.
    *---Downloading data to file on Presentation Server
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME                = V_PRESPATH
          FILETYPE                = 'ASC'
        TABLES
          DATA_TAB                = I_FINAL_P
        EXCEPTIONS
          FILE_WRITE_ERROR        = 1
          NO_BATCH                = 2
          GUI_REFUSE_FILETRANSFER = 3
          INVALID_TYPE            = 4
          NO_AUTHORITY            = 5
          UNKNOWN_ERROR           = 6
          HEADER_NOT_ALLOWED      = 7
          SEPARATOR_NOT_ALLOWED   = 8
          FILESIZE_NOT_ALLOWED    = 9
          HEADER_TOO_LONG         = 10
          DP_ERROR_CREATE         = 11
          DP_ERROR_SEND           = 12
          DP_ERROR_WRITE          = 13
          UNKNOWN_DP_ERROR        = 14
          ACCESS_DENIED           = 15
          DP_OUT_OF_MEMORY        = 16
          DISK_FULL               = 17
          DP_TIMEOUT              = 18
          FILE_NOT_FOUND          = 19
          DATAPROVIDER_EXCEPTION  = 20
          CONTROL_FLUSH_ERROR     = 21
          OTHERS                  = 22.
    *-- File can not be opened successfully
      IF SY-SUBRC NE 0.
        IF SY-BATCH EQ C_FLAG_X. " Stop Processing
          MESSAGE E017.        " File could not be opened
        ELSE.
          MESSAGE I017.        " File could not be opened
          LEAVE LIST-PROCESSING.
        ENDIF.
      ELSE.
        CONCATENATE 'Data Successfully downloaded to the Specified Location' V_PRESPATH INTO MESSAGE SEPARATED BY SPACE.
        MESSAGE MESSAGE TYPE 'S'.
      ENDIF.
      MODIFY SCREEN.
    ENDFORM.                    " sub_download_presserver
    *&      Form  sub_download_appserver
          text
    FORM SUB_DOWNLOAD_APPSERVER .
      DATA: V_FILE        TYPE  STRING,               " String
            P_DMBTR  TYPE  CHAR20,
            G_DMBTR  TYPE  CHAR20,
            MESSAGE1 TYPE STRING.
      IF I_FINAL[] IS INITIAL.
        IF SY-BATCH EQ C_FLAG_X.
    *--- File contains no data
          MESSAGE E016 .
        ELSE.
    *--- File contains no data
          MESSAGE I016 .
          LEAVE LIST-PROCESSING.
        ENDIF.
      ENDIF.
    *--- To Open The file in Application Server
      OPEN DATASET V_APPPATH FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
      IF SY-SUBRC NE 0.
    *--- Display error message: "Could not open file"
        IF SY-BATCH EQ C_FLAG_X.
    *--- File contains no data
          MESSAGE E016 .
        ELSE.
    *--- File contains no data
          MESSAGE I016 .
          LEAVE LIST-PROCESSING.
        ENDIF.
      ENDIF.
    *--- Perform for building the Report header
      CONCATENATE
                 'COMPANY_CODE'
                 'G/L_ACCOUNT_NUMBER'
                 'FISCAL_YEAR'
                 'A/C_DOCUMENT_NUMBER'
                 'POSTING_DATE'
                 'CURRENCY'
                 'REF_DOCUMENT_NUMBER'
                 'DOCUMENT_TYPE'
                 'FISCAL_PERIOD'
                 'AMOUNT'
                 'COSTCENTER'
                 'PROFIT_CENTER'
                 'G/L_ACCOUNT_NUMBER'
                 'AMOUNT'
                 'PROFIT_CENTER'
                 'LINE_ITEM_ID'
                INTO V_FILE SEPARATED BY C_DELIMITER.
      TRANSFER V_FILE TO V_APPPATH.
    *--- Transfer the data to application Server
      LOOP AT I_FINAL INTO W_FINAL.
        P_DMBTR =  W_FINAL-DMBTR_P.
        G_DMBTR =  W_FINAL-DMBTR_G.
        CONCATENATE
                 W_FINAL-BUKRS
                 W_FINAL-HKONT_P
                 W_FINAL-GJAHR
                 W_FINAL-BELNR
                 W_FINAL-BUDAT
                 W_FINAL-WAERS
                 W_FINAL-XBLNR
                 W_FINAL-BLART
                 W_FINAL-MONAT
                 P_DMBTR
                 W_FINAL-KOSTL
                 W_FINAL-PRCTR_P
                 W_FINAL-HKONT_G
                 G_DMBTR
                 W_FINAL-PRCTR_G
                 W_FINAL-BUZID_G
              INTO V_FILE SEPARATED BY C_DELIMITER.
        TRANSFER V_FILE TO V_APPPATH.
        IF SY-SUBRC NE 0.
    Display error message: "Data could not be written at the location"
          MESSAGE 'Data could not be written at the location' TYPE 'I'.
          EXIT.
        ENDIF.
        CLEAR V_FILE.
      ENDLOOP.
      CLOSE DATASET V_APPPATH.
      IF SY-SUBRC NE 0.
    Display error message: "File could not be closed"
        MESSAGE 'File could not be closed' TYPE 'I'.
        EXIT.
      ELSE.
        CONCATENATE 'Data Successfully downloaded to the Specified Location' V_APPPATH INTO MESSAGE1 SEPARATED BY SPACE.
        MESSAGE MESSAGE1 TYPE 'S'.
      ENDIF.
    ENDFORM.                    " sub_download_appserver

    hi,
    here is improved code.
    REPORT ZFIR_GRIR_IPV
    NO STANDARD PAGE HEADING
    LINE-SIZE 120
    MESSAGE-ID ZFI02.
    TABLES: BSEG,BKPF.
    TYPES: BEGIN OF A_FINAL,
    BUKRS TYPE CHAR12,
    HKONT_P TYPE CHAR18,
    GJAHR TYPE CHAR11,
    BELNR TYPE CHAR19,
    BUDAT TYPE CHAR12,
    WAERS TYPE CHAR8,
    XBLNR TYPE CHAR20,
    BLART TYPE CHAR13,
    MONAT TYPE CHAR13,
    DMBTR_P TYPE CHAR13,
    KOSTL TYPE CHAR11,
    PRCTR_P TYPE CHAR13,
    HKONT_G TYPE CHAR18,
    DMBTR_G TYPE CHAR13,
    PRCTR_G TYPE CHAR13,
    BUZID_G TYPE CHAR15,
    END OF A_FINAL.
    changes on 30 th may by dileep
    TYPES: BEGIN OF IT_FINAL,
    BUKRS TYPE BUKRS ,
    HKONT TYPE HKONT,
    BELNR TYPE BELNR_D,
    DMBTR TYPE DMBTR ,
    KOSTL TYPE KOSTL,
    PRCTR TYPE PRCTR,
    END OF IT_FINAL.
    TYPES: BEGIN OF IT_FINAL1,
    BUKRS TYPE BUKRS,
    HKONT TYPE HKONT,
    GJAHR TYPE GJAHR ,
    BELNR TYPE BELNR_D,
    BUDAT TYPE BUDAT,
    WAERS TYPE WAERS ,
    XBLNR TYPE XBLNR1,
    BLART TYPE BLART,
    MONAT TYPE MONAT,
    DMBTR TYPE DMBTR,
    KOSTL TYPE KOSTL,
    PRCTR TYPE PRCTR,
    END OF IT_FINAL1.
    end of changes on 30 th may by dileep
    TYPES: BEGIN OF P_FINAL,
    BUKRS TYPE CHAR12,
    DELIMITER_1 TYPE CHAR1,
    HKONT_P TYPE CHAR18,
    DELIMITER_2 TYPE CHAR1,
    GJAHR TYPE CHAR11,
    DELIMITER_3 TYPE CHAR1,
    BELNR TYPE CHAR19,
    DELIMITER_4 TYPE CHAR1,
    BUDAT TYPE CHAR12,
    DELIMITER_5 TYPE CHAR1,
    WAERS TYPE CHAR8,
    DELIMITER_6 TYPE CHAR1,
    XBLNR TYPE CHAR20,
    DELIMITER_7 TYPE CHAR1,
    BLART TYPE CHAR13,
    DELIMITER_8 TYPE CHAR1,
    MONAT TYPE CHAR13,
    DELIMITER_9 TYPE CHAR1,
    DMBTR_P TYPE CHAR13,
    DELIMITER_10 TYPE CHAR1,
    KOSTL TYPE CHAR11,
    DELIMITER_11 TYPE CHAR1,
    PRCTR_P TYPE CHAR13,
    DELIMITER_12 TYPE CHAR1,
    HKONT_G TYPE CHAR18,
    DELIMITER_13 TYPE CHAR1,
    DMBTR_G TYPE CHAR13,
    DELIMITER_14 TYPE CHAR1,
    PRCTR_G TYPE CHAR13,
    DELIMITER_15 TYPE CHAR1,
    BUZID_G TYPE CHAR15,
    END OF P_FINAL.
    DATA: IT_BSEG TYPE STANDARD TABLE OF IT_FINAL INITIAL SIZE 0,
    I_BSEG TYPE STANDARD TABLE OF IT_FINAL1 INITIAL SIZE 0,
    I_FINAL TYPE STANDARD TABLE OF A_FINAL INITIAL SIZE 0 WITH HEADER LINE,
    I_FINAL_P TYPE STANDARD TABLE OF P_FINAL INITIAL SIZE 0 WITH HEADER LINE,
    W_FINAL_P TYPE P_FINAL,
    W_BSEG1 TYPE BSEG,
    WA_BSEG TYPE IT_FINAL OCCURS 0 WITH HEADER LINE,
    W_BSEG TYPE IT_FINAL1 OCCURS 0 WITH HEADER LINE,
    T_BSEG TYPE STANDARD TABLE OF BSEG INITIAL SIZE 0 WITH HEADER LINE,
    W_FINAL TYPE A_FINAL,
    F_YEAR TYPE BAPI0002_4-FISCAL_YEAR,
    F_PERIOD TYPE BAPI0002_4-FISCAL_PERIOD,
    RETURN1 TYPE BAPIRETURN1,
    V_DATE TYPE CHAR8, " Date in YYYYMMDD format
    V_PRESPATH TYPE STRING, " Path
    V_APPPATH TYPE STRING, " Path
    V_FILENAME(25) TYPE C, " File Name
    V_PERIOD TYPE CHAR3, " Date for Posting Period
    V_FSYEAR TYPE BDATJ, " Fiscal Year
    L_TEXT TYPE CHAR1. " Hypen
    CONSTANTS: C_TXT TYPE CHAR4 VALUE '.txt', " File Extension
    C_TXT1 TYPE STRING VALUE 'txt', " File Type
    C_FLAG_X TYPE CHAR1 VALUE 'X', " Flag
    C_ASC TYPE FILETYPE VALUE 'ASC', " File type
    C_DAT TYPE CHAR4 VALUE '.dat', " File Type
    C_FLAG_1 TYPE CHAR1 VALUE '1', " Constant value
    C_ZERO TYPE CHAR1 VALUE '0', " Constant
    C_GLD(10) TYPE C VALUE 'GRIR021S', " Constant in file Path
    C_DIR TYPE CHAR3 VALUE 'C:\', " Presentation Server path
    C_FLAG_12 TYPE CHAR2 VALUE '12', " Constant value
    C_PCFILE TYPE STRING VALUE 'PC File',
    C_DELIMITER TYPE C VALUE '|'.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
              o
                    +
    Selection Criteria
    SELECT-OPTIONS: S_BUKRS FOR BSEG-BUKRS DEFAULT '012T', " Company Code
    S_HKONT FOR BSEG-HKONT OBLIGATORY DEFAULT '4505001',
    S_GJAHR FOR BKPF-GJAHR DEFAULT SY-DATUM+0(4),
    S_MONAT FOR BKPF-MONAT DEFAULT SY-DATUM+4(2),
    S_BELNR FOR BSEG-BELNR ,
    S_BUDAT FOR BKPF-BUDAT ,
    S_PRCTR FOR BSEG-PRCTR OBLIGATORY DEFAULT '12TOTH00',
    S_BLART FOR BKPF-BLART OBLIGATORY DEFAULT 'RE'.
    SELECTION-SCREEN END OF BLOCK B1.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.
              o
                    +
    Radio Buttons for chose the PC Path or App.. Server Path
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS:
    RB_PFILE RADIOBUTTON GROUP RAD2 DEFAULT 'X' USER-COMMAND UCOMM1.
    SELECTION-SCREEN COMMENT 5(27) TEXT-002 FOR FIELD RB_PFILE.
    PARAMETERS:
    P_PFILE LIKE RLGRAP-FILENAME LOWER CASE.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS:
    RB_AFILE RADIOBUTTON GROUP RAD2.
    SELECTION-SCREEN COMMENT 5(27) TEXT-003 FOR FIELD RB_AFILE.
    PARAMETERS:
    P_AFILE LIKE RLGRAP-FILENAME LOWER CASE. " Path for AS
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PFILE.
              o
                    + Select File name with Dialog Box
    PERFORM SUB_GET_FILENAME CHANGING P_PFILE.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_AFILE.
              o
                    +
    Attach F4 HELP CORRESPONDING TO THE FIELD
    PERFORM SUB_AP_F4.
    AT SELECTION-SCREEN OUTPUT.
    *--Modify screen parameters
    PERFORM SUB_MODIFY_SCREEN.
    AT SELECTION-SCREEN.
              o
                    +
    Selection Screen validations for Company Code
    PERFORM SUB_VALIDATION_BUKRS.
              o
                    +
    Selection Screen validations for Chart of Accounts
    PERFORM SUB_VALIDATION_HKONT.
              o
                    +
    Selection Screen validations Fiscal Year
    PERFORM SUB_VALIDATION_GJAHR.
              o
                    +
    Selection Screen validations for Peiod
    PERFORM SUB_VALIDATION_MONAT.
              o
                    +
    Selection Screen validations for Company Code
    PERFORM SUB_VALIDATION_BELNR.
              o
                    +
    Selection Screen validations for Chart of Accounts
    PERFORM SUB_VALIDATION_BUDAT.
              o
                    +
    Selection Screen validations Fiscal Year
    PERFORM SUB_VALIDATION_PRCTR.
              o
                    +
    Selection Screen validations for Peiod
    PERFORM SUB_VALIDATION_BLART.
    START-OF-SELECTION
    START-OF-SELECTION.
              o
                    +
    Check whether filepath/name have been entered in the sel screen
    PERFORM SUB_CHECK_FILEPATH.
              o
                    +
    Prepare Final Internal Table.
    PERFORM SUB_PREPARE_FINAL.
              o
                    +
    Download data.
    PERFORM SUB_DOWNLOAD_DATA .
    *& Form sub_get_filename
    text
    <--P_PFILE Presentation server File name
    FORM SUB_GET_FILENAME CHANGING P_FILE TYPE C.
    DATA : L_FILENAME TYPE STRING, " For File Name
    L_PATH TYPE STRING, " For Directory
    L_FULLPATH TYPE STRING. " Full path
              o
                    +
    For File Open Dialog Box
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    EXPORTING
    WINDOW_TITLE = C_PCFILE " Window Title
    DEFAULT_EXTENSION = C_TXT1 " File Extn
    PROMPT_ON_OVERWRITE = C_FLAG_X " Over write
    CHANGING
    FILENAME = L_FILENAME " File Name
    PATH = L_PATH " File Path
    FULLPATH = L_FULLPATH " Full Path
    EXCEPTIONS
    CNTL_ERROR = 1
    ERROR_NO_GUI = 2
    NOT_SUPPORTED_BY_GUI = 3
    OTHERS = 4.
    IF SY-SUBRC NE 0.
              o
                    +
    Error in opening the file
    MESSAGE E000.
    ELSE.
    CONCATENATE L_PATH
    L_FILENAME
    INTO P_FILE.
    V_PRESPATH = L_PATH.
    ENDIF.
    ENDFORM. " sub_get_filename
    *& Form sub_ap_f4
    f4 help attched with application server
    FORM SUB_AP_F4 .
              o
                    +
    FM for to get the Application Server Path
    IF RB_AFILE = C_FLAG_X.
    CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
    DIRECTORY =
    FILEMASK = C_ASC " File Extn
    IMPORTING
    SERVERFILE = P_AFILE " File Path
    EXCEPTIONS
    CANCELED_BY_USER = 1
    OTHERS = 2.
    IF SY-SUBRC NE 0.
              o
                    +
    Error in opening the file
    MESSAGE E000.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_ap_f4
    *& Form sub_modify_screen
    text
    --> p1 text
    <-- p2 text
    FORM SUB_MODIFY_SCREEN .
              o
                    +
    Selection screen Modifications
    IF RB_PFILE = C_FLAG_X.
    LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_PFILE' OR
    SCREEN-NAME = '%_P_PFILE_%_APP_%-TEXT'.
    SCREEN-ACTIVE = C_FLAG_1.
    CONCATENATE C_DIR C_GLD V_DATE SY-UZEIT(4) C_TXT INTO P_PFILE.
    MODIFY SCREEN.
    ENDIF.
    ENDLOOP.
    ELSE.
    LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_PFILE' OR
    SCREEN-NAME = '%_P_PFILE_%_APP_%-TEXT'.
    SCREEN-ACTIVE = C_ZERO.
    MODIFY SCREEN.
    ENDIF.
    ENDLOOP.
    ENDIF.
    IF RB_AFILE = C_FLAG_X.
    LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_AFILE' OR
    SCREEN-NAME = '%_P_AFILE_%_APP_%-TEXT'.
    SCREEN-ACTIVE = C_FLAG_1.
    CONCATENATE '/Solectron/Data/' C_GLD V_DATE SY-UZEIT(4) C_DAT
    INTO P_AFILE.
    MODIFY SCREEN.
    ENDIF.
    ENDLOOP.
    ELSE.
    LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_AFILE' OR
    SCREEN-NAME = '%_P_AFILE_%_APP_%-TEXT'.
    SCREEN-ACTIVE = C_ZERO.
    MODIFY SCREEN.
    ENDIF.
    ENDLOOP.
    ENDIF.
    IF RB_PFILE = C_FLAG_X.
    LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_PFILE'.
    SCREEN-ACTIVE = C_FLAG_1.
    ENDIF.
    IF SCREEN-NAME = 'P_AFILE'.
    SCREEN-ACTIVE = C_ZERO.
    ENDIF.
    MODIFY SCREEN.
    ENDLOOP.
    ELSEIF RB_AFILE = C_FLAG_X.
    LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_PFILE'.
    SCREEN-ACTIVE = C_ZERO.
    ENDIF.
    IF SCREEN-NAME = 'P_AFILE'.
    SCREEN-ACTIVE = C_FLAG_1.
    ENDIF.
    MODIFY SCREEN.
    ENDLOOP.
    ENDIF.
    ENDFORM. " sub_modify_screen
    *& Form sub_validation_bukrs
    Validation For Company Code
    FORM SUB_VALIDATION_BUKRS .
    DATA: L_BUKRS TYPE BUKRS. " Company Code
    IF S_BUKRS IS NOT INITIAL.
    IF S_BUKRS-HIGH IS NOT INITIAL AND S_BUKRS-LOW IS INITIAL.
    MESSAGE E006.
    ELSE.
              o
                    +
    Validation for chart of accounts
    SELECT BUKRS " Company Code
    FROM T001 UP TO 1 ROWS
    INTO L_BUKRS
    WHERE BUKRS IN S_BUKRS.
    ENDSELECT.
    IF SY-SUBRC NE 0.
              o
                    +
    Invalid Company code
    MESSAGE E001.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_bukrs
    *& Form sub_validation_hkont
    Validation For General Ledger Account
    FORM SUB_VALIDATION_HKONT .
    DATA: L_HKONT TYPE HKONT. " General Ledger Account
    IF S_HKONT IS INITIAL.
    MESSAGE E002.
    ELSE.
    IF S_HKONT-HIGH IS NOT INITIAL AND S_HKONT-LOW IS INITIAL.
    MESSAGE E006.
    ELSE.
              o
                    +
    Validation for chart of accounts
    SELECT SAKNR " General Ledger Account
    FROM SKA1 UP TO 1 ROWS
    INTO L_HKONT
    WHERE SAKNR IN S_HKONT AND KTOPL = '1SLR'.
    ENDSELECT.
    IF SY-SUBRC NE 0.
              o
                    +
    Invalid General Ledger Account
    MESSAGE E003.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_hkont
    *& Form sub_validation_gjahr
    Validation For Fiscal Year
    FORM SUB_VALIDATION_GJAHR .
    DATA: L_GJAHR TYPE GJAHR. " Fiscal Year
    IF S_GJAHR IS NOT INITIAL.
    IF S_GJAHR-HIGH IS NOT INITIAL AND S_GJAHR-LOW IS INITIAL.
    MESSAGE E006.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_gjahr
    *& Form sub_validation_monat
    Validation For Fiscal period
    FORM SUB_VALIDATION_MONAT .
    DATA: L_MONAT TYPE MONAT. " Fiscal period
    IF S_MONAT IS NOT INITIAL.
    IF S_MONAT-LOW LE C_ZERO.
              o
                    +
    Invalid Fiscal Period
    MESSAGE E006.
    ENDIF.
    IF S_MONAT-HIGH GT C_FLAG_12.
              o
                    +
    Invalid Fiscal Period
    MESSAGE E007.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_monat
    *& Form sub_validation_belnr
    Validation For Accounting Document Number
    FORM SUB_VALIDATION_BELNR .
    DATA: L_BELNR TYPE BELNR_D. " Accounting Document Number
    IF S_BELNR IS NOT INITIAL.
    IF S_BELNR-HIGH IS NOT INITIAL AND S_BELNR-LOW IS INITIAL.
    MESSAGE E006.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_belnr
    *& Form sub_validation_budat
    Validation For Posting Date
    FORM SUB_VALIDATION_BUDAT .
    DATA: L_BUDAT TYPE BUDAT. " Posting Date
    IF S_BUDAT IS NOT INITIAL.
    IF S_BUDAT-HIGH IS NOT INITIAL AND S_BUDAT-LOW IS INITIAL.
    MESSAGE E006.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_budat
    *& Form sub_validation_prctr
    Validation For Profit Center
    FORM SUB_VALIDATION_PRCTR .
    DATA: L_PRCTR TYPE PRCTR. " Profit Center
    IF S_PRCTR IS INITIAL.
    MESSAGE E010.
    ELSE.
    IF S_PRCTR-HIGH IS NOT INITIAL AND S_PRCTR-LOW IS INITIAL.
    MESSAGE E006.
    ELSE.
              o
                    +
    Validation for chart of accounts
    SELECT PRCTR " Profit Center
    FROM CEPC UP TO 1 ROWS
    INTO L_PRCTR
    WHERE PRCTR IN S_PRCTR.
    ENDSELECT.
    IF SY-SUBRC NE 0.
              o
                    +
    Invalid Profit Center
    MESSAGE E011.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_prctr
    *& Form sub_validation_blart
    Validation For Document type
    FORM SUB_VALIDATION_BLART .
    DATA: L_BLART TYPE BLART. " Document type
    IF S_BLART IS INITIAL.
    MESSAGE E012.
    ELSE.
    IF S_BLART-HIGH IS NOT INITIAL AND S_BLART-LOW IS INITIAL.
    MESSAGE E006.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_validation_blart
    *& Form sub_check_filepath
    Check user input for initial filename
    FORM SUB_CHECK_FILEPATH .
    IF RB_PFILE = C_FLAG_X.
    IF P_PFILE IS INITIAL.
              o
                    +
    The Local File Path can not be Empty
    MESSAGE I014.
    LEAVE LIST-PROCESSING.
    ENDIF.
    ELSEIF RB_AFILE = C_FLAG_X.
    IF P_AFILE IS INITIAL.
              o
                    +
    The App Server File Path can not be Empty
    MESSAGE I015.
    LEAVE LIST-PROCESSING.
    ENDIF.
    ENDIF.
    ENDFORM. " sub_check_filepath
    *& Form sub_prepare_final
    append the required output data in to the internal table.
    FORM SUB_PREPARE_FINAL.
    changes on 30 th may by dileep
    SELECT * FROM BSEG INTO TABLE I_BSEG WHERE HKONT IN S_HKONT AND "G/L Account
    GJAHR IN S_GJAHR AND
    PRCTR IN S_PRCTR AND "Profit Center
    BLART IN S_BLART . "Document Type
    SELECT BUKRS
    HKONT
    BELNR
    DMBTR
    KOSTL
    PRCTR
    FROM BSEG INTO TABLE IT_BSEG WHERE HKONT IN S_HKONT AND "G/L Account
    PRCTR IN S_PRCTR. "Profit Center
    LOOP AT IT_BSEG INTO WA_BSEG.
    SELECT SINGLE GJAHR
    BUDAT
    WAERS
    XBLNR
    BLART
    MONAT
    INTO (W_BSEG-GJAHR,W_BSEG-BUDAT,W_BSEG-WAERS,W_BSEG-XBLNR,W_BSEG-BLART,W_BSEG-MONAT)
    FROM BKPF WHERE BELNR = W_BSEG-BELNR AND
    GJAHR IN S_GJAHR AND
    BLART IN S_BLART . "Document Type
    MOVE WA_BSEG-BUKRS TO W_BSEG-BUKRS.
    MOVE WA_BSEG-HKONT TO W_BSEG-HKONT.
    MOVE WA_BSEG-BELNR TO W_BSEG-BELNR.
    MOVE WA_BSEG-DMBTR TO W_BSEG-DMBTR.
    MOVE WA_BSEG-KOSTL TO W_BSEG-KOSTL.
    MOVE WA_BSEG-PRCTR TO W_BSEG-PRCTR.
    APPEND W_BSEG TO I_BSEG.
    ENDLOOP.
    changes on 30 th may by dileep
    IF S_BUKRS IS NOT INITIAL.
    SORT I_BSEG BY BUKRS ASCENDING.
    DELETE I_BSEG WHERE NOT BUKRS IN S_BUKRS.
    ENDIF.
    IF S_MONAT IS NOT INITIAL.
    SORT I_BSEG BY GJAHR MONAT ASCENDING.
    IF S_MONAT-HIGH IS NOT INITIAL AND S_MONAT-LOW IS NOT INITIAL.
    DELETE I_BSEG WHERE MONAT < S_MONAT-LOW OR MONAT > S_MONAT-HIGH.
    ENDIF.
    IF S_MONAT-HIGH IS INITIAL AND S_MONAT-LOW IS NOT INITIAL.
    DELETE I_BSEG WHERE MONAT NE S_MONAT-LOW.
    ENDIF.
    ENDIF.
    IF S_BELNR IS NOT INITIAL.
    SORT I_BSEG BY BELNR ASCENDING.
    DELETE I_BSEG WHERE NOT BELNR IN S_BELNR.
    ENDIF.
    IF S_BUDAT IS NOT INITIAL.
    SORT I_BSEG BY BUDAT ASCENDING.
    DELETE I_BSEG WHERE NOT BUDAT IN S_BUDAT.
    ENDIF.
    LOOP AT I_BSEG INTO W_BSEG.
    MOVE W_BSEG-BUKRS TO W_FINAL-BUKRS.
    MOVE W_BSEG-HKONT TO W_FINAL-HKONT_P.
    MOVE W_BSEG-GJAHR TO W_FINAL-GJAHR.
    MOVE W_BSEG-BELNR TO W_FINAL-BELNR.
    MOVE W_BSEG-BUDAT TO W_FINAL-BUDAT.
    MOVE W_BSEG-WAERS TO W_FINAL-WAERS.
    MOVE W_BSEG-XBLNR TO W_FINAL-XBLNR.
    MOVE W_BSEG-BLART TO W_FINAL-BLART.
    MOVE W_BSEG-MONAT TO W_FINAL-MONAT.
    MOVE W_BSEG-DMBTR TO W_FINAL-DMBTR_P.
    MOVE W_BSEG-KOSTL TO W_FINAL-KOSTL.
    MOVE W_BSEG-PRCTR TO W_FINAL-PRCTR_P.
    SELECT SINGLE * FROM BSEG INTO W_BSEG1 WHERE BELNR = W_BSEG-BELNR AND "Document Type
    BUZID = 'W' .
    IF SY-SUBRC = 0.
    MOVE W_BSEG1-HKONT TO W_FINAL-HKONT_G.
    MOVE W_BSEG1-DMBTR TO W_FINAL-DMBTR_G.
    MOVE W_BSEG1-PRCTR TO W_FINAL-PRCTR_G.
    MOVE W_BSEG1-BUZID TO W_FINAL-BUZID_G.
    ELSE.
    EXIT.
    ENDIF.
    APPEND W_FINAL TO I_FINAL.
    SORT I_FINAL BY BELNR ASCENDING.
    ENDLOOP.
    ENDFORM. " sub_prepare_final
    *& Form sub_download_data
    Download data
    FORM SUB_DOWNLOAD_DATA .
    DATA : V_PRD(2) TYPE N.
    IF RB_PFILE = C_FLAG_X.
              o
                    +
    Downloading To presentation server
    V_PRESPATH = P_PFILE.
    PERFORM SUB_DOWNLOAD_PRESSERVER.
    ELSEIF RB_AFILE = C_FLAG_X.
              o
                    +
    Downloading To Application server in Auto Mode
    V_APPPATH = P_AFILE.
    PERFORM SUB_DOWNLOAD_APPSERVER.
    ENDIF.
    ENDFORM. " sub_download_data
    *& Form sub_download_presserver
    text
    FORM SUB_DOWNLOAD_PRESSERVER.
    DATA: MESSAGE TYPE STRING.
    IF I_FINAL[] IS INITIAL.
    MESSAGE I016.
    EXIT.
    ELSE.
    W_FINAL_P-BUKRS = 'Company Code'.
    W_FINAL_P-DELIMITER_1 = '|'.
    W_FINAL_P-HKONT_P = 'G/L Account Number'.
    W_FINAL_P-DELIMITER_2 = '|'.
    W_FINAL_P-GJAHR = 'Fiscal Year'.
    W_FINAL_P-DELIMITER_3 = '|'.
    W_FINAL_P-BELNR = 'A/c Document Number'.
    W_FINAL_P-DELIMITER_4 = '|'.
    W_FINAL_P-BUDAT = 'Posting Date' .
    W_FINAL_P-DELIMITER_5 = '|'.
    W_FINAL_P-WAERS = 'Currency'.
    W_FINAL_P-DELIMITER_6 = '|'.
    W_FINAL_P-XBLNR = 'Ref. Document Number'.
    W_FINAL_P-DELIMITER_7 = '|'.
    W_FINAL_P-BLART = 'Document Type'.
    W_FINAL_P-DELIMITER_8 = '|'.
    W_FINAL_P-MONAT = 'Fiscal Period'.
    W_FINAL_P-DELIMITER_9 = '|'.
    W_FINAL_P-DMBTR_P = 'Amount'.
    W_FINAL_P-DELIMITER_10 = '|'.
    W_FINAL_P-KOSTL = 'Cost Center'.
    W_FINAL_P-DELIMITER_11 = '|'.
    W_FINAL_P-PRCTR_P = 'Profit Center'.
    W_FINAL_P-DELIMITER_12 = '|'.
    W_FINAL_P-HKONT_G = 'G/L Account Number'.
    W_FINAL_P-DELIMITER_13 = '|'.
    W_FINAL_P-DMBTR_G = 'Amount'.
    W_FINAL_P-DELIMITER_14 = '|'.
    W_FINAL_P-PRCTR_G = 'Profit Center'.
    W_FINAL_P-DELIMITER_15 = '|'.
    W_FINAL_P-BUZID_G = 'Line Item Id'.
    APPEND W_FINAL_P TO I_FINAL_P.
    LOOP AT I_FINAL INTO W_FINAL.
    W_FINAL_P-BUKRS = W_FINAL-BUKRS.
    W_FINAL_P-DELIMITER_1 = '|'.
    W_FINAL_P-HKONT_P = W_FINAL-HKONT_P.
    W_FINAL_P-DELIMITER_2 = '|'.
    W_FINAL_P-GJAHR = W_FINAL-GJAHR.
    W_FINAL_P-DELIMITER_3 = '|'.
    W_FINAL_P-BELNR = W_FINAL-BELNR.
    W_FINAL_P-DELIMITER_4 = '|'.
    W_FINAL_P-BUDAT = W_FINAL-BUDAT .
    W_FINAL_P-DELIMITER_5 = '|'.
    W_FINAL_P-WAERS = W_FINAL-WAERS.
    W_FINAL_P-DELIMITER_6 = '|'.
    W_FINAL_P-XBLNR = W_FINAL-XBLNR.
    W_FINAL_P-DELIMITER_7 = '|'.
    W_FINAL_P-BLART = W_FINAL-BLART.
    W_FINAL_P-DELIMITER_8 = '|'.
    W_FINAL_P-MONAT = W_FINAL-MONAT.
    W_FINAL_P-DELIMITER_9 = '|'.
    W_FINAL_P-DMBTR_P = W_FINAL-DMBTR_P.
    W_FINAL_P-DELIMITER_10 = '|'.
    W_FINAL_P-KOSTL = W_FINAL-KOSTL.
    W_FINAL_P-DELIMITER_11 = '|'.
    W_FINAL_P-PRCTR_P = W_FINAL-PRCTR_P.
    W_FINAL_P-DELIMITER_12 = '|'.
    W_FINAL_P-HKONT_G = W_FINAL-HKONT_G.
    W_FINAL_P-DELIMITER_13 = '|'.
    W_FINAL_P-DMBTR_G = W_FINAL-DMBTR_G.
    W_FINAL_P-DELIMITER_14 = '|'.
    W_FINAL_P-PRCTR_G = W_FINAL-PRCTR_G.
    W_FINAL_P-DELIMITER_15 = '|'.
    W_FINAL_P-BUZID_G = W_FINAL-BUZID_G.
    APPEND W_FINAL_P TO I_FINAL_P.
    CLEAR : W_FINAL_P, W_FINAL.
    ENDLOOP.
    ENDIF.
    *---Downloading data to file on Presentation Server
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    FILENAME = V_PRESPATH
    FILETYPE = 'ASC'
    TABLES
    DATA_TAB = I_FINAL_P
    EXCEPTIONS
    FILE_WRITE_ERROR = 1
    NO_BATCH = 2
    GUI_REFUSE_FILETRANSFER = 3
    INVALID_TYPE = 4
    NO_AUTHORITY = 5
    UNKNOWN_ERROR = 6
    HEADER_NOT_ALLOWED = 7
    SEPARATOR_NOT_ALLOWED = 8
    FILESIZE_NOT_ALLOWED = 9
    HEADER_TOO_LONG = 10
    DP_ERROR_CREATE = 11
    DP_ERROR_SEND = 12
    DP_ERROR_WRITE = 13
    UNKNOWN_DP_ERROR = 14
    ACCESS_DENIED = 15
    DP_OUT_OF_MEMORY = 16
    DISK_FULL = 17
    DP_TIMEOUT = 18
    FILE_NOT_FOUND = 19
    DATAPROVIDER_EXCEPTION = 20
    CONTROL_FLUSH_ERROR = 21
    OTHERS = 22.
              o
                    + File can not be opened successfully
    IF SY-SUBRC NE 0.
    IF SY-BATCH EQ C_FLAG_X. " Stop Processing
    MESSAGE E017. " File could not be opened
    ELSE.
    MESSAGE I017. " File could not be opened
    LEAVE LIST-PROCESSING.
    ENDIF.
    ELSE.
    CONCATENATE 'Data Successfully downloaded to the Specified Location' V_PRESPATH INTO MESSAGE SEPARATED BY SPACE.
    MESSAGE MESSAGE TYPE 'S'.
    ENDIF.
    MODIFY SCREEN.
    ENDFORM. " sub_download_presserver
    *& Form sub_download_appserver
    text
    FORM SUB_DOWNLOAD_APPSERVER .
    DATA: V_FILE TYPE STRING, " String
    P_DMBTR TYPE CHAR20,
    G_DMBTR TYPE CHAR20,
    MESSAGE1 TYPE STRING.
    IF I_FINAL[] IS INITIAL.
    IF SY-BATCH EQ C_FLAG_X.
              o
                    +
    File contains no data
    MESSAGE E016 .
    ELSE.
              o
                    +
    File contains no data
    MESSAGE I016 .
    LEAVE LIST-PROCESSING.
    ENDIF.
    ENDIF.
              o
                    +
    To Open The file in Application Server
    OPEN DATASET V_APPPATH FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF SY-SUBRC NE 0.
              o
                    +
    Display error message: "Could not open file"
    IF SY-BATCH EQ C_FLAG_X.
              o
                    +
    File contains no data
    MESSAGE E016 .
    ELSE.
              o
                    +
    File contains no data
    MESSAGE I016 .
    LEAVE LIST-PROCESSING.
    ENDIF.
    ENDIF.
              o
                    +
    Perform for building the Report header
    CONCATENATE
    'COMPANY_CODE'
    'G/L_ACCOUNT_NUMBER'
    'FISCAL_YEAR'
    'A/C_DOCUMENT_NUMBER'
    'POSTING_DATE'
    'CURRENCY'
    'REF_DOCUMENT_NUMBER'
    'DOCUMENT_TYPE'
    'FISCAL_PERIOD'
    'AMOUNT'
    'COSTCENTER'
    'PROFIT_CENTER'
    'G/L_ACCOUNT_NUMBER'
    'AMOUNT'
    'PROFIT_CENTER'
    'LINE_ITEM_ID'
    INTO V_FILE SEPARATED BY C_DELIMITER.
    TRANSFER V_FILE TO V_APPPATH.
              o
                    +
    Transfer the data to application Server
    LOOP AT I_FINAL INTO W_FINAL.
    P_DMBTR = W_FINAL-DMBTR_P.
    G_DMBTR = W_FINAL-DMBTR_G.
    CONCATENATE
    W_FINAL-BUKRS
    W_FINAL-HKONT_P
    W_FINAL-GJAHR
    W_FINAL-BELNR
    W_FINAL-BUDAT
    W_FINAL-WAERS
    W_FINAL-XBLNR
    W_FINAL-BLART
    W_FINAL-MONAT
    P_DMBTR
    W_FINAL-KOSTL
    W_FINAL-PRCTR_P
    W_FINAL-HKONT_G
    G_DMBTR
    W_FINAL-PRCTR_G
    W_FINAL-BUZID_G
    INTO V_FILE SEPARATED BY C_DELIMITER.
    TRANSFER V_FILE TO V_APPPATH.
    IF SY-SUBRC NE 0.
    Display error message: "Data could not be written at the location"
    MESSAGE 'Data could not be written at the location' TYPE 'I'.
    EXIT.
    ENDIF.
    CLEAR V_FILE.
    ENDLOOP.
    CLOSE DATASET V_APPPATH.
    IF SY-SUBRC NE 0.
    Display error message: "File could not be closed"
    MESSAGE 'File could not be closed' TYPE 'I'.
    EXIT.
    ELSE.
    CONCATENATE 'Data Successfully downloaded to the Specified Location' V_APPPATH INTO MESSAGE1 SEPARATED BY SPACE.
    MESSAGE MESSAGE1 TYPE 'S'.
    ENDIF.
    ENDFORM. " sub_download_appserver
    regards,
    Vipul

  • Do you have an idea how to improve the performance ?

    Hi All,
    Greeting,
    I'm doing SEM IP. Regarding the performance, do you have some thought about this ?
    So I have planning report for project report . As we know, if we forecast against project, means the date itself is the life of the project itself.
    It means it could be more than 10 years (forecast period) and 10 years (actual period). Currently I segregate between actual and forecast into different info cube .
    But the performance of the planning report is slow now. Do you have an idea about this how to increase the performance. The performance I mentioned here is when we're going to the report (after putting in the value in the selection screen).
    The other question, at this moment, I have a multiprovider than this multi provider consist 2 info cubes ( actual and forecast ). Than my aggregation is sitting on top of that multi-provider .
    My question whether that's approach correct or not ? Or do we have to create 1 aggregate (only for forecast), than I have multi-provider consisting forecasting aggregation and actual cube .
    than my query will sit on top of that multi-provider ?
    Which one is better ??
    Thanks a lot all,
    really need your help,

    Hi,
       For the performance tuning, you can consider any of the following three methods,
    1. Indices
    With an increasing number of data records in the InfoCube, not only the load but also the query performance can be reduced. This is attributed to the increasing demands on the system for maintaining indexes. The indexes that are created in the fact table for each dimension allow you to easily find and select the data.
    2. Partitioning
    By using partitioning you can split up the whole dataset for an InfoCube into several, smaller, physically independent and redundancy-free units. Thanks to this separation, performance is increased when reporting, or also when deleting data from the InfoCube.
    3. Aggregates 
    Aggregates make it possible to access InfoCube data quickly in Reporting. Aggregates serve, in a similar way to database indexes, to improve performance.
    4. Compressing the Infocube
    Infocube compression means aggregation of the data ignoring the request idu2019s. After compression, the system need not perform aggregation using the request ID every time you execute a query.
    And I feel that as per your scenario, you need to do first compress the data based on user requirements and have only the required data in the infocube.
    And for the approach regarding the Aggregation level design, choosing between the two approaches depends on the user requirements. For example,
    If you have aggregation level created on top of multiprovider containing actual and forecast cube, in your report (created on top of aggregation level) you can view the key figure values present in both the cubes, which is not possible in the other approach.
    So this approach is suited if your requirement is to view the records from both the cubes in your report (Comparing planning and actual values).
    The second approach is used if your requirement is only to report on planning forecast cube.
    Hopes this solves your issue.
    Regards,
    Balajee

  • Improve the performance of the 'BAPI_GOODSMVT_CREATE' Bapi

    Hi All,
    We have a requirement in which we create a material document number for each goods receipt note.
    This is done with the help of 'BAPI_GOODSMVT_CREATE' . This BAPI is working perfectly fine and is correctly posting the material document number for each of the goods receipt.
    The problem lies in the fact that this BAPI is geting called for each line item of the Purchase order ie it gets called in a loop , due to which this program is taking much longer time to run.
    Is there any way or any sap notes which we can use to improve the performance of this BAPI .
    Thanks ,
    Sumit

    Hi,
    Why do you call the bapi for each line item. All the line items per document should be processed together.
    The standard code is mostly fine. The performance of these standard transactions generally deteriorates if good programming practices are not used in the user exits/badis available in the standard transaction. Check where is the pain point to figure out where the transaction takes more time.
    Regards,
    Abdullah.

  • Is There any way to improve the performance on this code

    Hi all can any one tell me how to improve the performance of this below code.
    Actually i need to calculate opening balance of gl account so instead of using bseg am using bsis
    So is there any way to improve this code performance.
    Any help would be appreciated.
    REPORT  ZTEMP5 NO STANDARD PAGE HEADING LINE-SIZE 190.
    data: begin of collect occurs 0,
           MONAT TYPE MONAT,
           HKONT TYPE HKONT,
           BELNR TYPE BELNR_D,
           BUDAT TYPE BUDAT,
           WRBTR TYPE WRBTR,
           SHKZG TYPE SHKZG,
           SGTXT TYPE SGTXT,
           AUFNR TYPE AUFNR_NEU,
           TOT   LIKE BSIS-WRBTR,
    end of collect.
    TYPES: BEGIN OF TY_BSIS,
           MONAT TYPE MONAT,
           HKONT TYPE HKONT,
           BELNR TYPE BELNR_D,
           BUDAT TYPE BUDAT,
           WRBTR TYPE WRBTR,
           SHKZG TYPE SHKZG,
           SGTXT TYPE SGTXT,
           AUFNR TYPE AUFNR_NEU,
    END OF TY_BSIS.
    DATA: IT_BSIS TYPE TABLE OF TY_BSIS,
          WA_BSIS TYPE TY_BSIS.
    DATA: TOT TYPE WRBTR,
          SUMA TYPE WRBTR,
          VALUE TYPE WRBTR,
          VALUE1 TYPE WRBTR.
    SELECTION-SCREEN: BEGIN OF BLOCK B1.
    PARAMETERS:  S_HKONT LIKE WA_BSIS-HKONT DEFAULT '0001460002' .
    SELECT-OPTIONS: S_BUDAT FOR WA_BSIS-BUDAT,
                    S_AUFNR FOR WA_BSIS-AUFNR DEFAULT '200020',
                    S_BELNR FOR WA_BSIS-BELNR.
    SELECTION-SCREEN: END OF BLOCK B1.
    AT SELECTION-SCREEN OUTPUT.
      LOOP AT SCREEN.
        IF SCREEN-NAME = 'S_HKONT'.
          SCREEN-INPUT = 0.
          MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
    START-OF-SELECTION.
      SELECT MONAT
             HKONT
             BELNR
             BUDAT
             WRBTR
             SHKZG
             SGTXT
             AUFNR
             FROM BSIS
             INTO TABLE IT_BSIS
             WHERE HKONT EQ S_HKONT
             AND   BELNR IN S_BELNR
             AND   BUDAT IN S_BUDAT
             AND   AUFNR IN S_AUFNR.
    *  if sy-subrc <> 0.
    *    message 'No Data' type 'I'.
    *  endif.
      SELECT SUM( WRBTR )
             FROM BSIS
             INTO COLLECT-TOT
             WHERE HKONT EQ S_HKONT
             AND BUDAT < S_BUDAT-LOW
             AND AUFNR IN S_AUFNR.
    END-OF-SELECTION.
      CLEAR: S_BUDAT, S_AUFNR, S_BELNR, S_HKONT.
      LOOP AT IT_BSIS INTO WA_BSIS.
    IF wa_bsis-SHKZG = 'H'.
       wa_bsis-WRBTR = 0 - wa_bsis-WRBTR.
    ENDIF.
        collect-MONAT  = wa_bsis-monat.
        collect-HKONT  = wa_bsis-hkont.
        collect-BELNR  = wa_bsis-belnr.
        collect-BUDAT  = wa_bsis-budat.
        collect-WRBTR  = wa_bsis-wrbtr.
        collect-SHKZG  = wa_bsis-shkzg.
        collect-SGTXT  = wa_bsis-sgtxt.
        collect-AUFNR  = wa_bsis-aufnr.
        collect collect into  collect.
        CLEAR: COLLECT, WA_BSIS.
      ENDLOOP.
      LOOP AT COLLECT.
        AT end of HKONT.
          WRITE:/65 'OpeningBalance',
                 85  collect-tot.
          skip 1.
        ENDAT.
        WRITE:/06 COLLECT-BELNR,
               22 COLLECT-BUDAT,
               32 COLLECT-WRBTR,
               54 COLLECT-SGTXT.
        AT end of MONAT.
          SUM.
          WRITE:/ COLLECT-MONAT COLOR 1.
          WRITE:32 COLLECT-WRBTR COLOR 1.
          VALUE = COLLECT-WRBTR.
          SKIP 1.
        ENDAT.
        VALUE1 = COLLECT-TOT +  VALUE.
        AT end of MONAT.
          WRITE:85 VALUE1.
        ENDAT.
      endloop.
      CLEAR: COLLECT, SUMA, VALUE, VALUE1.
    TOP-OF-PAGE.
      WRITE:/06 'Doc No',
             22 'Post Date',
             39 'Amount',
             54 'Text'.
    Moderator message : See the Sticky threads (related for performance tuning) in this forum. Thread locked.
    Edited by: Vinod Kumar on Oct 13, 2011 11:12 AM

    Hi Ben,
    both BSIS selects would become faster if you can add Company Code BUKRS as 1st field of WHERE clause, because it's the 1st field of primary key and HKONT is the 2nd field of primary key.
    If you have no table index with HKONT as 1st field it's a full database access.
    If possible, try to add BUKRS as 1st field of WHERE clause, otherwise ask for an additional BSIS index at your basis team.
    Regards,
    Klaus

  • How to improve the performance of insert statement.

    Hi All,
    I have one procedure and it inserts 40 million records into one table. As my current method taking long time to accomplish the task, Is there any mechanism to improve the performance
    Thanks in Advance.

    > Thanks for pointing out my mistake Billy :)
    It is a common misconception it seems - that Oracle PQ is only useful for multi CPU platforms. I have seen it mentioned numerous times since the Oracle 7 OPS days in the mid 90's.
    > Edit: Could you please highlight which operations
    benefit from a multi-cpu machine?
    More CPUs increase the CPU capacity of the platform (and not speed). Allows it to run more processes.
    So very simplistically - on a single CPU box you find only sufficient CPU capacity (free CPU time) to run a parallel degree of 2 (i.e. 2 PQs). On a 4 CPU box, you may sufficient capacity for a degree of 10.
    But there are some catches here.
    Oracle PQ is specifically used for I/O sharing. Instead of a single process doing all the I/O, the I/O is shared amongst a bunch of PQ processes.
    The real bottle neck here is actually the size of the pipe to the disk.
    Simple example: You may have sufficient CPU capacity to run 20 PQs. But the I/O pipe will be seriously hammered as the pipe can only do a 1000 IOs/sec, and these 20 PQs are trying to push 10,000 IOs/sec.
    Another catch is that there are overheads when using SMP (symetrical multi processing). Again, very basically: as only a single CPU can for example access a specific piece of memory, two processes running on two different CPUs can cause "contention" when trying to access this memory (e.g. a typical piece of shared memory).
    So having two related processes running on two different CPUs can be in fact slower than having both related processes running on the same CPU.
    This is quite noticeable on Windows NT/2000/XP kernel for example. Windows will load the 1st CPU close to capacity, before spilling across to the 2nd CPU. It is the norm to see the 1st CPU with high usage and the 2nd CPU running almost idle. (something that seems to have PC gamers confused in recent times when using "high-end" dual core machines and not understanding why the 2nd CPU does not seem to be used)
    Bottom line. Multi-CPU platforms provide more processing capacity for running PQ than a single CPU platform. But a single CPU is capable of running PQ if there is capacity (which is often the case).

  • How to improve the performance of the abap program

    hi all,
    I have created an abap program. And it taking long time since the number of records are more. And can anyone let me know how to improve the performance of my abap program.
    Using se30 and st05 transaction.
    can anyone help me out step by step
    regds
    haritha

    Hi Haritha,
    ->Run Any program using SE30 (performance analysis)
    Note: Click on the Tips & Tricks button from SE30 to get performance improving tips.
    Using this you can improve the performance by analyzing your code part by part.
    ->To turn runtim analysis on within ABAP code insert the following code
    SET RUN TIME ANALYZER ON.
    ->To turn runtim analysis off within ABAP code insert the following code
    SET RUN TIME ANALYZER OFF.
    ->Always check the driver internal tables is not empty, while using FOR ALL ENTRIES
    ->Avoid for all entries in JOINS
    ->Try to avoid joins and use FOR ALL ENTRIES.
    ->Try to restrict the joins to 1 level only ie only for tables
    ->Avoid using Select *.
    ->Avoid having multiple Selects from the same table in the same object.
    ->Try to minimize the number of variables to save memory.
    ->The sequence of fields in 'where clause' must be as per primary/secondary index ( if any)
    ->Avoid creation of index as far as possible
    ->Avoid operators like <>, > , < & like % in where clause conditions
    ->Avoid select/select single statements in loops.
    ->Try to use 'binary search' in READ internal table. -->Ensure table is sorted before using BINARY SEARCH.
    ->Avoid using aggregate functions (SUM, MAX etc) in selects ( GROUP BY , HAVING,)
    ->Avoid using ORDER BY in selects
    ->Avoid Nested Selects
    ->Avoid Nested Loops of Internal Tables
    ->Try to use FIELD SYMBOLS.
    ->Try to avoid into Corresponding Fields of
    ->Avoid using Select Distinct, Use DELETE ADJACENT
    Check the following Links
    Re: performance tuning
    Re: Performance tuning of program
    http://www.sapgenie.com/abap/performance.htm
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
    check the below link
    http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
    See the following link if it's any help:
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
    Check also http://service.sap.com/performance
    and
    books like
    http://www.sap-press.com/product.cfm?account=&product=H951
    http://www.sap-press.com/product.cfm?account=&product=H973
    http://www.sap-img.com/abap/more-than-100-abap-interview-faqs.htm
    http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp
    Performance tuning for Data Selection Statement
    http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
    Debugger
    http://help.sap.com/saphelp_47x200/helpdata/en/c6/617ca9e68c11d2b2ab080009b43351/content.htm
    http://www.cba.nau.edu/haney-j/CIS497/Assignments/Debugging.doc
    http://help.sap.com/saphelp_erp2005/helpdata/en/b3/d322540c3beb4ba53795784eebb680/frameset.htm
    Run Time Analyser
    http://help.sap.com/saphelp_47x200/helpdata/en/c6/617cafe68c11d2b2ab080009b43351/content.htm
    SQL trace
    http://help.sap.com/saphelp_47x200/helpdata/en/d1/801f7c454211d189710000e8322d00/content.htm
    CATT - Computer Aided Testing Too
    http://help.sap.com/saphelp_47x200/helpdata/en/b3/410b37233f7c6fe10000009b38f936/frameset.htm
    Test Workbench
    http://help.sap.com/saphelp_47x200/helpdata/en/a8/157235d0fa8742e10000009b38f889/frameset.htm
    Coverage Analyser
    http://help.sap.com/saphelp_47x200/helpdata/en/c7/af9a79061a11d4b3d4080009b43351/content.htm
    Runtime Monitor
    http://help.sap.com/saphelp_47x200/helpdata/en/b5/fa121cc15911d5993d00508b6b8b11/content.htm
    Memory Inspector
    http://help.sap.com/saphelp_47x200/helpdata/en/a2/e5fc84cc87964cb2c29f584152d74e/content.htm
    ECATT - Extended Computer Aided testing tool.
    http://help.sap.com/saphelp_47x200/helpdata/en/20/e81c3b84e65e7be10000000a11402f/frameset.htm
    Just refer to these links...
    performance
    Performance
    Performance Guide
    performance issues...
    Performance Tuning
    Performance issues
    performance tuning
    performance tuning
    You can go to the transaction SE30 to have the runtime analysis of your program.Also try the transaction SCI , which is SAP Code Inspector.
    edited by,
    Naveenan

Maybe you are looking for

  • RFC Receiver Adapter Issue

    Hi all,       I'm sending a sales order from my ftp server to my R/3 system through RFC. I want this sales order to be created in the R/3 system, For this i'm using BAPI_SALESORDER_CREATEFROMDAT2. Now when i'm configuring my RFC Receiver adapter usin

  • Can't get OneStep to work

    I have my sony DVD cam hooked up, DVD-R in SuperDrive. Camera works with this machine but when I click on Onestep icon, it just gives me a message to hookup camera and load dvd. I'm in a loop. Everytime I click onestep icon, I get the message to load

  • Satellite Pro P300-1AY - Where can I get new keyboard parts?

    Hey guys, I was wondering if you knew of any places where I could get a set of keys for the keyboard (as opposed to buying a new keyboard) and if possible; where I can get sets of keys for different keyboard layouts, such as AZERTY for example. Many

  • Get Client Host Name

    Dear Experts, I am using String ipAddress = WDProtocolAdapter.getProtocolAdapter().getRequestObject().getClientHostAddress(); retrieve client ip address. When I use getClientHostName(), it still present client ip address. Regarding the client hostnam

  • Keyboard shortcut blend mode in gradient tool

    I switch between screen and mulitply all the time when working on adjustment layer masks. Cant find shortcut to change the mode within the gradient tool (ony for changing the layer mode)