Parallel Cursor method
Dear Experts,
I am using parallel cursor method for a nested loop by using this method the report got very fast
but the data from the loop where I used Parallel cursor method is not coimng after 7000 records.
Say when I am running the report from 1st jan to 30 jan total records are 48,000 but data from parallel cursor method 's loop is cumin till 7th of jan (7000 records) after that all values are coming zero.
When I am running it from 7th of jan to 30 th Jan data from that loop is cumin till 15th of jan(7000 records) after that values are cumin zero.
Below I am writing the code I used for parallel cursor method loop
paralele cursor method
data : v_index type sy-tabix.
read TABLE i_konv into wa_konv with key knumv = wa_vbrk-knumv
kposn = wa_vbrp-posnr binary search.
if sy-subrc = 0.
v_index = sy-tabix.
loop at i_konv into wa_konv FROM v_index. "FROM v_index.
if wa_konv-knumv = wa_vbrk-knumv.
if wa_konv-kposn <> wa_vbrp-posnr.
exit.
endif.
else.
exit.
endif.
Thanks and Regards,
Vikas Patel
Hi Vikas,
First check there are records available completely in you Internal table...
and Here is a very simple example for parallel cusor..
REPORT zparallel_cursor.
TABLES:
likp,
lips.
DATA:
t_likp TYPE TABLE OF likp,
t_lips TYPE TABLE OF lips.
DATA:
w_runtime1 TYPE i,
w_runtime2 TYPE i,
w_index LIKE sy-index.
START-OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp.
SELECT *
FROM lips
INTO TABLE t_lips.
GET RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln.
SORT t_lips BY vbeln.
LOOP AT t_likp INTO likp.
LOOP AT t_lips INTO lips FROM w_index.
IF likp-vbeln NE lips-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
compare the difference.
Thanks & regards,
Dileep .C
Similar Messages
-
Hello,
Can some one give me a description in detail as to what exactly Parallel cursor method is and how it works.
Also, what are the Performance Tuning Techniques that we can follow during ABAP Development?
Thanks and Regards,
Venkatactually, I would not recommend the parallel cursor technique! First name is actually incorrect internal tables have no cursor only indexes, only parallel
index would make sense.
Performance improvement:
If costs for sort are taken into account, then parallel index is not faster than loop with loop on sorted table.
or with standard table
loop
read ... binary search
index = sy-tabix
loop ... from index
if ( condition is not fulfilled )
exit
endif.
endloop
endloop
The full parallel index technique should find all deviations between 2 tables, additional lines in Tab1, additional lines in tab2, changes.
Feel free to find a complete solution. We can compare results, it is not worth the effort!
Siegfried -
What is parallel cursor technique.
what is parallel cursor technique. Please give an example
thanx in advanceSuppose u got data in two internal table itab1 and itab2 from header and from item table
u have to take cobine the values into one table
so normally what we do is that we write loop .(item table -itab2 ) inside antother loop (header table-itab1) . but it will affect the performance
So go for Parallel cursor method
Regards,
Nikhil -
Hi,
Im using cursor method in my sql query. For two tables, im putting the cursor. Im populating data from two tables into third internal table.
Now, the data from third internal table is inserted into a ztable.
During this entire process, my first cursor will be opened and second cursor will be open and closed till it gets the complete records based on first cursor. data insertion happens into a ztable and finally closing the cursor for the first one.
open cursor dbcur1
open cursor dbcur2
close cursor dbcur2
inserting into ztable
close cursor dbcur1. }
My problem is that a huge time is consumed while inserting the rows into dbtable. Here, im trying to do a batch processing. So for each batch process, my ztable will be inserted with new records.
So, what the best case of reducing the time for processing this activity.
thanks
rohithHi,
The best method i can think of is update the data outside the SQL. Collect data into an internal table. Once all the data is collected, close all the cursors, then INSERT the data into ZTABLE at single shot.
Logic behind this is, it reduces the number of database hits. As we know database operations works on queing principles. So instead of waiting in Q for each INSERT statement, update the data at once and COMMIT.
Hope you got the logic.
Thanks,
Vinod. -
hi experts,
can i use more than one parallel cursor , when i looping thru different internal tables,
i used once it in my current prog as i need multiple Grn no(ekbe-belnr) , with respect to single po(ekpo-ebeln).
but in my current prog. i also need multiple (konv-kposn) vaue with respect to sigle po no,
to display multiple tax calculation!
plz help , i badly needed this answer in no timeHi,
Have a look at the code below. The select the entries from KONV based on the requirement. Better not to use the select *, instead select the required fields from the tables.
TABLES : ekko, ekpo, ekbe, konv.
DATA: it_ekpo TYPE TABLE OF ekpo WITH HEADER LINE,
it_ekbe TYPE TABLE OF ekbe WITH HEADER LINE,
it_konv TYPE TABLE OF konv WITH HEADER LINE.
DATA: l_index1 TYPE sytabix,
l_index2 TYPE sytabix.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.
SELECT-OPTIONS s_knumv FOR konv-knumv.
SELECT * FROM ekpo INTO TABLE it_ekpo WHERE ebeln IN s_ebeln.
IF NOT it_ekpo[] IS INITIAL.
SELECT * FROM ekbe INTO TABLE it_ekbe
FOR ALL ENTRIES IN it_ekpo
WHERE ebeln = it_ekpo-ebeln
AND ebelp = it_ekpo-ebelp.
ENDIF.
SELECT * FROM konv INTO TABLE it_konv
WHERE knumv = s_knumv.
SORT it_ekpo BY ebeln ebelp.
SORT it_ekbe BY ebeln ebelp.
SORT it_konv BY knumv.
LOOP AT it_ekpo.
LOOP AT it_ekbe FROM l_index1.
if ( it_ekbe-ebeln ne it_ekpo-ebeln )
and ( it_ekbe-ebelp ne it_ekpo-ebelp ).
exit.
else.
l_index1 = sy-tabix.
*do the necessary calculations
endif.
LOOP AT it_konv FROM l_index2.
write the necessary if condition so that it would exit from the loop
if (.......)
else.
fill the required fields and do the necessary calculations
l_index2 = sy-tabix.
ENDLOOP.
ENDLOOP.
ENDLOOP.
The loop of the konv table has to be placed as required based on whether it has to be in the loop of EKBE or out of EKBE. -
Need help getting DataProvider cursor methods to work in JSC
Hi, I'm a newbie to Creator as well as JSF. I'm using JSC Update 1. I've
worked through a couple of the beginning tutorials including "Performing
Inserts, Updates, and Deletes" without a problem. I'm now trying to
craft a simple jsf database form application on my own using the sample
travel database and I'm stuck!
I put text fields on the form corresponding to each of the 4 fields in
the PERSON table and bound them to the fields in the table which, on
examination, resulted in a CachedRowSetDataProvider (personDataProvider)
in Page1 and a CachedRowSetXImpl (personRowSet) in SessionBean1. I then put 4 buttons on the form (First, Previous, Next, Last) for record
navigation. Here is the code I put in the first two actions (the others are
the same except for the cursor methods):
public String btn_firstrec_action() {
try {
personDataProvider.cursorFirst();
} catch (Exception e){
error("cursorFirst failed: " + e.getMessage());
log("cursorFirst failed " , e);
return null;
public String btn_next_action() {
try {
personDataProvider.cursorNext();
} catch (Exception e){
error("cursorNext failed: "+ e.getMessage() );
log("cursorNext failed " , e);
return null;
etc.
When I run the application using the bundled app server I get strange
behavior when I click the navigation buttons. There are 6 records in the
table. The application opens up displaying the data for the first
record. Clicking "Next" takes me to record 2--so far so good. However,
with repeated clicks on "Next", "Previous", "First" the data displayed in
the form remains the same. If I click "Last" (personDataProvider.cursorLast(); ), the data from record 6 is rendered OK!
I worked a little in the debugger. I added a cursorChanging method and
put a break point in there. Then I watched the index attributes for rk1
an rk2 as I continued the execution. I had to hit Alt+F5 (Continue)
2 to 4 times on each button click depending on the action--4X
with "Next" and "Previous". For each button click the index values would
change at first to what logically seemed the correct values but
then snap back to 0 or 1 as I kept continuing depending on the sequence--
wierd to me.
I also tried configuring all the form fields in a virtual form with
"Participate" on for the text fields and "Submit" on for the buttons
with the same result (I was really "shooting in the dark" here!).
I'm obviously missing something here--this shouldn't be this difficult!
I have scanned through a lot of the excellent tutorials, articles and forum posts as well as some of the sample apps but haven't as yet found a similar example of using the DataProvider cursor methods which seems pretty basic to me but, I could have easily missed seeing what I needed.
Any help would be greatly appreciated--I'm really counting on this tool
to get an overdue project going so I'm somewhat desperate.
Thanks, Len SissonThis happened to me as well the first time I used the JSC (and I was a newbie in web). I believe it is because everytime you hit the button, actually the sequence of program will back to init(), button_action(), prerender(), destroy(). So, try to remember the last state of the cursor position using session variable. And then you put a code in the init() to move back to the last cursor position.
Check the sample program provided by JSC (SinglePageCrudForm). This sample demonstrate how to put a code in init(), destroy() in order to 'remember' the last position.
hope that helps
Message was edited by:
discusfish -
Parallel Accounting Method for IFRS
Hello all,
My company would like to explore the parallel accounting method for IFRS. Currently we are on ECC 6.0 with classic GL.
Currently we have both US GAAP and local GAAP reporting running in the same ledger. We use a similar method (setting up additional H accounts which are used in local GAAP reporting only) to segregate local GAAP from US GAAP as recommended by SAP.
We set up 2 different depreciation areas: 01 (post to US GAAP accounts) and 02 (post to local GAAP accounts). The problem we ran into at year-end is pertaining to Retained Earnings. Because this a complete replacement method (US GAAP reporting will ignore all the H accounts which are set up for local GAAP and visa versa), we can't simply roll all the P/L accounts into one Retained Earnings account. We have to set up 3 Retained Earnings account (one for US GAAP only accounts, one for common accounts and another one for local GAAP accounts).
If we add IFRS into the mix, we will need to set up even more Retained Earnings accounts which is not ideal. Also, we plan on including more countries into our SAP environment which requires us to generate additional local GAAP reporting. So my thinking is that this will become very hard to manage.
Also, this method will fall apart if the common accounts are not the same for any of the reporting requirement (e.g. common accounts for US GAAP and local GAAP are different than IFRS).
My understanding is there are 2 ways to handle parallel accounting: replacement (which is what we are current using) or adjustment methods. Instead of completely replacing the US GAAP accounts, the adjustment method is to post the delta to the additional accounts.
My question is:
1. Giving current situation of my company, what is the best method to handle IFRS and also implement additional local GAAP reporting in the same environment?
2. What is the best practice to handle parallel accounting method? Replacement or adjustment method?
3. Since I'm already in the replacement method, can I easily switch to the adjustment method?
Any guidance will be greatly appreciated.
Regards,
Cassandra WongCassandra,
Check out this blog which has info and process map for parallel accounting. Theer's also a link for a recent SAP webinar about how we implemented parallel reporting for our own use.
http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417400)ID2115139750DB10714505287783485243End?blog=/pub/wlg/15679
siva
Edited by: Siva Darivemula on Sep 25, 2009 7:37 PM -
what is parallel cursor
Hi,
Here is the sample program which use the parallel cursor,
* Performance Tuning using parallel cursor
* Extracts from program ZFAL2002
* START-OF-SELECTION
SELECT *
INTO TABLE I_KEPH FROM KEPH
WHERE KADKY <= SY-DATUM
AND TVERS = '01'
AND KALKA IN ('01','Z1','Z2')
AND BWVAR IN ('Z01','Z02','Z03','Z04','Z07')
AND KKZST = ' '
AND KKZMA = ' '
AND KKZMM = ' '
AND KEART = 'H'
AND PATNR = 0.
* Table must be sorted to ensure all required records are together
SORT I_KEPH BY KALNR KALKA BWVAR KADKY.
* Perform actual processing
Perform get_cost_values.
FORM GET_COST_VALUES.
* Determine start position and then process all records for given key
* from that starting point
* i_keph is sorted on kalnr kalka bwvar kadky.
READ TABLE I_KEPH WITH KEY KALNR = W_KEKO-KALNR
KALKA = W_KEKO-KALKA
BWVAR = W_KEKO-BWVAR
KADKY = W_KEKO-KADKY BINARY SEARCH.
IF SY-SUBRC = 0.
* Loop at itab from first record found (sy-tabix) until record
* no-longer matches your criteria.
LOOP AT I_KEPH FROM SY-TABIX.
IF I_KEPH-KALNR = W_KEKO-KALNR AND I_KEPH-KALKA = W_KEKO-KALKA
AND I_KEPH-BWVAR = W_KEKO-BWVAR AND I_KEPH-KADKY = W_KEKO-KADKY.
* Key match
D_MAT_COST = D_MAT_COST + I_KEPH-KST001.
D_LAB_COST = D_LAB_COST + I_KEPH-KST004.
D_OVER_HEAD = D_OVER_HEAD + I_KEPH-KST010.
D_EXT_PURCH = D_EXT_PURCH + I_KEPH-KST014.
D_MISC_COST = D_MISC_COST + I_KEPH-KST002 + I_KEPH-KST003
+ I_KEPH-KST005 + I_KEPH-KST006 + I_KEPH-KST007
+ I_KEPH-KST008 + I_KEPH-KST009 + I_KEPH-KST011
+ I_KEPH-KST012 + I_KEPH-KST013 + I_KEPH-KST015
+ I_KEPH-KST016 + I_KEPH-KST017 + I_KEPH-KST018
+ I_KEPH-KST019 + I_KEPH-KST020 + I_KEPH-KST021
+ I_KEPH-KST022 + I_KEPH-KST023 + I_KEPH-KST024
+ I_KEPH-KST025 + I_KEPH-KST026 + I_KEPH-KST027
+ I_KEPH-KST028 + I_KEPH-KST029 + I_KEPH-KST030
+ I_KEPH-KST031 + I_KEPH-KST032 + I_KEPH-KST033
+ I_KEPH-KST034 + I_KEPH-KST035 + I_KEPH-KST036
+ I_KEPH-KST037 + I_KEPH-KST038 + I_KEPH-KST039
+ I_KEPH-KST040.
ELSE.
* Key greater - can't be less
EXIT. " Exit loop
ENDIF.
ENDLOOP.
ENDIF.
D_MAT_COST = D_MAT_COST / W_KEKO-LOSGR.
D_LAB_COST = D_LAB_COST / W_KEKO-LOSGR.
D_OVER_HEAD = D_OVER_HEAD / W_KEKO-LOSGR.
D_EXT_PURCH = D_EXT_PURCH / W_KEKO-LOSGR.
D_MISC_COST = D_MISC_COST / W_KEKO-LOSGR.
ENDFORM. " GET_COST_VALUES -
What is meant by parallel cursor
hi
what is meant by parallel cursorHi,
Parallel cursor is the technique to increase the perforamance of the program. For example if we use nested select in our program instead of For all entries addition, then definetly performance going down. In the same way the if we use nested loops in the program it will also leads to down the performance.
I will give you one example like take billing document header details in one table and item details in other table let say the header table have 1000 records and the item table have 1 lakh records. If you want to make an output then you need to put nested loops first loop at header table then next loop at item table. For each entry of header record the item table loops 1 lakh times. calculate the total. so instead of we develop parallel cursor technique,, see the belwo code..
Loop at header.
read table item with key number = header-number.
if sy-subrc = 0.
loop at item from sy-tabix.
if item-number <> header-number.
exit.
else.
do some process here.
endif.
endloop.
endif.
endloop.
First the item table is read using the read table statement for getting the exact index number where the document number reside. if found then loop through the item table from that index upto item- number <> header-number.
Rgds,
Bujji
Edited by: Bujji on Jun 26, 2008 12:48 PM -
Hi Experts,
In my program using nested loop. I want avoid that using parallel cursor. But In two nested loops, using
I done, but where has three nested loops how ? plz tell me or send code?
Ex: my Requirment is like this
Loop at i_tab1 into wa_tab1.
loop at s_tab into wa_tab2.
end loop.
loop at k_tab into wa_tab3
end loop.
end loop.
plz send code using parallel cursor, if u get more points.
thanx
srinuHI,
Check this Code .....
REPORT zparallel_cursor.
TABLES:
likp,
lips.
DATA:
t_likp TYPE TABLE OF likp,
t_lips TYPE TABLE OF lips.
DATA:
w_runtime1 TYPE i,
w_runtime2 TYPE i,
w_index LIKE sy-index.
START-OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp.
SELECT *
FROM lips
INTO TABLE t_lips.
GET RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln.
SORT t_lips BY vbeln.
LOOP AT t_likp INTO likp.
LOOP AT t_lips INTO lips FROM w_index.
IF likp-vbeln NE lips-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
WRITE w_runtime2.
Either you can use the above code ..or ucan replace the inside loops with read statement of lopp with where clause depending on requirement
Edited by: avinash kodarapu on Nov 30, 2008 4:04 PM -
How can we increse this coding Part
Hi there
I came across some coding to improve .while looking the progam it is unique .some say it is correct as per the Sap point of view .but some dosent.
Please verify is this the correct way for coding .
IF NOT skont IS INITIAL.
IF NOT aksaldo IS INITIAL.
IF NOT summen IS INITIAL.
LOOP AT organ.
CLEAR: f_bwkey, f_bklas, f_bwtty, f_bwtar, sum.
SELECT bwkey bklas bwtty bwtar SUM( salk3 ) FROM mbew
INTO (f_bwkey, f_bklas, f_bwtty, f_bwtar, sum)
WHERE bwkey EQ organ-bwkey
AND matnr IN matnr
AND bklas IN ibklas
AND bwtar IN bwtar
GROUP BY bwkey bklas bwtty bwtar.
CHECK NOT sum IS INITIAL.
MOVE f_bwkey TO xmbew-bwkey.
MOVE f_bklas TO xmbew-bklas.
MOVE f_bwtty TO xmbew-bwtty.
MOVE f_bwtar TO xmbew-bwtar.
MOVE sum TO xmbew-salk3.
COLLECT xmbew.
ENDSELECT.
CLEAR: f_bwkey, f_bklas, f_bwtty, f_bwtar, sum.
SELECT bwkey bklas bwtty bwtar SUM( salk3 ) FROM ebew
INTO (f_bwkey, f_bklas, f_bwtty, f_bwtar, sum)
WHERE bwkey EQ organ-bwkey
AND matnr IN matnr
AND bklas IN ibklas
AND bwtar IN bwtar
GROUP BY bwkey bklas bwtty bwtar.
CHECK NOT sum IS INITIAL.
MOVE f_bwkey TO xmbew-bwkey.
MOVE f_bklas TO xmbew-bklas.
MOVE f_bwtty TO xmbew-bwtty.
MOVE f_bwtar TO xmbew-bwtar.
MOVE sum TO xmbew-salk3.
COLLECT xmbew.
ENDSELECT.
CLEAR: f_bwkey, f_bklas, f_bwtty, f_bwtar, sum.
SELECT bwkey bklas bwtty bwtar SUM( salk3 ) FROM qbew
INTO (f_bwkey, f_bklas, f_bwtty, f_bwtar, sum)
WHERE bwkey EQ organ-bwkey
AND matnr IN matnr
AND bklas IN ibklas
AND bwtar IN bwtar
GROUP BY bwkey bklas bwtty bwtar.
CHECK NOT sum IS INITIAL.
MOVE f_bwkey TO xmbew-bwkey.
MOVE f_bklas TO xmbew-bklas.
MOVE f_bwtty TO xmbew-bwtty.
MOVE f_bwtar TO xmbew-bwtar.
MOVE sum TO xmbew-salk3.
COLLECT xmbew.
ENDSELECT.
consider valuated subcontractor stocks from OBEW "n497391
CLEAR: f_bwkey, f_bklas, f_bwtty, f_bwtar, sum. "n497391
SELECT bwkey bklas bwtty bwtar SUM( salk3 ) "n497391
FROM obew "n497391
INTO (f_bwkey, f_bklas, f_bwtty, f_bwtar, sum) "n497391
WHERE bwkey EQ organ-bwkey "n497391
AND matnr IN matnr "n497391
AND bklas IN ibklas "n497391
AND bwtar IN bwtar "n497391
GROUP BY bwkey bklas bwtty bwtar. "n497391
CHECK NOT sum IS INITIAL. "n497391
MOVE f_bwkey TO xmbew-bwkey. "n497391
MOVE f_bklas TO xmbew-bklas. "n497391
MOVE f_bwtty TO xmbew-bwtty. "n497391
MOVE f_bwtar TO xmbew-bwtar. "n497391
MOVE sum TO xmbew-salk3. "n497391
COLLECT xmbew. "n497391
ENDSELECT. "n497391
ENDLOOP.
ELSEIF summen IS INITIAL.
CLEAR xmbew. "388498
SELECT mandt matnr bwkey bwtar lvorm lbkum salk3
vprsv verpr stprs peinh bklas salkv lfgja lfmon
bwtty pstat vksal eklas qklas
FROM mbew INTO CORRESPONDING FIELDS OF xmbew
FOR ALL ENTRIES IN organ WHERE bwkey EQ organ-bwkey
AND matnr IN matnr
AND bklas IN ibklas
AND bwtar IN bwtar.
APPEND xmbew.
ENDSELECT.
Begin of Optima APP 037
IF NOT xmbew IS INITIAL.
Start of Insert E_FIR.018 PRADHSA1
SELECT matnr werks prctr
FROM marc
INTO TABLE i_marc
FOR ALL ENTRIES IN xmbew
WHERE matnr = xmbew-matnr
AND werks = xmbew-bwkey.
End of Insert E_FIR.018 PRADHSA1
ENDIF.
Begin of Optima APP 037
CLEAR xmbew. "388498
SELECT mandt matnr bwkey bwtar lbkum salk3
vprsv verpr stprs peinh bklas salkv lfgja lfmon
bwtty vksal sobkz vbeln posnr
FROM ebew INTO CORRESPONDING FIELDS OF xmbew
FOR ALL ENTRIES IN organ WHERE bwkey EQ organ-bwkey
AND matnr IN matnr
AND bklas IN ibklas
AND bwtar IN bwtar.
xmbew-no_sum = 'X'.
APPEND xmbew.
ENDSELECT.
CLEAR xmbew. "388498
SELECT mandt matnr bwkey bwtar lbkum salk3
vprsv verpr stprs peinh bklas salkv lfgja lfmon
bwtty vksal sobkz pspnr
FROM qbew INTO CORRESPONDING FIELDS OF xmbew
FOR ALL ENTRIES IN organ WHERE bwkey EQ organ-bwkey
AND matnr IN matnr
AND bklas IN ibklas
AND bwtar IN bwtar.
xmbew-no_sum = 'X'.
APPEND xmbew.
ENDSELECT.
consider valuated subcontractor stocks from OBEW "n497391
CLEAR xmbew. "n497391
SELECT mandt matnr bwkey bwtar lbkum salk3 "n497391
vprsv verpr stprs peinh bklas salkv "n497391
lfgja lfmon bwtty vksal sobkz lifnr "n497391
FROM obew INTO CORRESPONDING FIELDS OF xmbew "n497391
FOR ALL ENTRIES IN organ "n497391
WHERE bwkey EQ organ-bwkey "n497391
AND matnr IN matnr "n497391
AND bklas IN ibklas "n497391
AND bwtar IN bwtar. "n497391
xmbew-no_sum = 'X'. "n497391
APPEND xmbew. "n497391
ENDSELECT. "n497391
ENDIF.
Thanks in advance
RajaHi Raj,
1) Avoid select statements inside a loop which will effect the performance of your program
2) First get all the required data from tables mbew, ebew, qbew, obew, qbew, obew in to separate internal tables using for all entries from internal table organ instead of using select----endselect in a loop
3) use nested loops instead of select------endselect but use parallel cursor method in nested loop to improve performance.
The below example shows how to improve performance if we use nested loop using parallel cursor method
Nested Loop using Parallel Cursor:
REPORT zparallel_cursor2.
TABLES:
likp,
lips.
DATA:
t_likp TYPE TABLE OF likp,
t_lips TYPE TABLE OF lips.
DATA:
w_runtime1 TYPE i,
w_runtime2 TYPE i,
w_index LIKE sy-index.
START-OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp.
SELECT *
FROM lips
INTO TABLE t_lips.
GET RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln.
SORT t_lips BY vbeln.
LOOP AT t_likp INTO likp.
LOOP AT t_lips INTO lips FROM w_index.
IF likp-vbeln NE lips-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
WRITE w_runtime2.
Thanks,
Naveen Kumar. -
Hi All,
I am having one record in it_vbrk table and in it_vbrp table i am having three records with same vbeln with three items.
Loop at it_vbrk into wa_vbrk.
Move: XXXX to XXXX
Read table it_vbrp into wa_vbrp with key vbeln = wa_vbrk-vbeln.
if sy-subrc = 0.
move: XXXX to XXX.
endif.
endloop.
here in the above code i am getting only one record output. but i need three records as output with all the three item details of it_vbrp.
i am not suppose to use loop inside a loop.
Please suggest with code example.
Regards,
KumarSome optimizations guidance :
- Try Parallel Cursor method : look at wiki sample at [Copy of ABAP Code for Parallel Cursor - Loop Processing |http://wiki.sdn.sap.com/wiki/display/Snippets/CopyofABAPCodeforParallelCursor-Loop+Processing]
- Reverse the order of table processing, using the item table in the external LOOP and READ to get the header table, but only if each and every header has a least one item, else you will miss some header records.
- Use a LOOP in another LOOP if the internal table is a SORTED or HASH (as of Release 7.0) one and the WHERE criteria are the key of the table (check LOOP [WHERE log_exp |http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB_COND.htm#&ABAP_ADDITION_3@3@] online documentation)
Regards,
Raymond -
I have an ITAB which contains PO header details and another ITAB which has PO Item details. Now I need to to take this info. in a single ITAB and send it to some FM. Which will be the best way to do this ?
When I do,
Loop at it_header into wa_header.
wa_new-BUKRS = wa_heaeder-bukrs.
wa_new-LIFNR = wa_heaeder-LIFNR.
wa_new-BSTYP = wa_heaeder-BSTYP.
wa_new-BSAKZ = wa_heaeder-BSAKZ.
Loop at it_item into wa_item where ebeln = wa_header-ebeln.
wa_new-werks = wa_item-werks.
wa_new-MATNR = wa_item-MATNR.
wa_new-AEDAT = wa_item-AEDAT.
wa_new-MENGE = wa_item-MENGE.
wa_new-MEINS = wa_item-MEINS.
wa_new-IDNLF = wa_item-IDNLF.
append wa_new to it_new.
appended = 'X'.
endloop.
if appended ne 'X'.
append wa_new to it_new.
endif.
clear wa_new.
Endloop.
This code consumes a lot of time since I have a huge amount of data.Could you please suggest some other method?Hi,
You haven't explained how you are getting the data in the tables.If you only are selecting it , may be you can select the data at a time by using a join into the itab it_new directly.
If you are getting this data from somewhere else , we cant do anything on the select. In that case you can try using the parallel cursor method.
Before using this technique , you have to make sure that it_item is a sub table of it_header. That means, all the EBELN's in it_item should be there in it_header also. Since this is a PO info., I assume that the condition is satisfied.
Then try this code instead of your Loop.
Sort it_header by ebeln.
sort it_item by ebeln.
LOOP AT IT_HEADER INTO WA_HEADER.
wa_new-BUKRS = wa_heaeder-bukrs.
wa_new-LIFNR = wa_heaeder-LIFNR.
wa_new-BSTYP = wa_heaeder-BSTYP.
wa_new-BSAKZ = wa_heaeder-BSAKZ.
LOOP AT IT_ITEM INTO WA_ITEM FROM INDEX.
IF WA_ITEM-EBELN NE WA_HEADER-EBELN.
INDEX = SY_TABIX.
EXIT.
ENDIF.
wa_new-werks = wa_item-werks.
wa_new-MATNR = wa_item-MATNR.
wa_new-AEDAT = wa_item-AEDAT.
wa_new-MENGE = wa_item-MENGE.
wa_new-MEINS = wa_item-MEINS.
wa_new-IDNLF = wa_item-IDNLF.
append wa_new to it_new.
appended = 'X'.
ENDLOOP.
if appended ne 'X'.
append wa_new to it_new.
endif.
ENDLOOP.
Try this code instead..
If you get any improvement, pls reward with points.... -
Performanc issue...help..
Hi all
i want to increase performance in one Existing program..this program is working fine but performance is very poor. we r indexing the required filed.
but i find some nested select loop inside this program...
pls ,,suggest me how can i avoid this kind of nested select loop. instead of loop statement can i user read statement for avoiding the nested loop???
pls check the below code.
if any problem within this logice then change the code.
thanks in advance.
Indu
SORT it_but000 BY partner.
LOOP AT it_ever INTO wa_ever.
LOOP AT it_fkkvkp INTO wa_fkkvkp WHERE vkont = wa_ever-vkonto.
READ TABLE it_but000 INTO wa_but000 WITH KEY partner = wa_fkkvkp-gpart
BINARY SEARCH.
IF sy-subrc = 0.
IF wa_but000-name_org1 IS INITIAL.
CONCATENATE wa_but000-name_first
wa_but000-name_last
INTO wa_final-cust_name SEPARATED BY space.
CONDENSE wa_final-cust_name.
ELSE.
wa_final-cust_name = wa_but000-name_org1.
ENDIF.
wa_final-gpart = wa_fkkvkp-gpart.
MODIFY it_final FROM wa_final TRANSPORTING cust_name gpart WHERE vertrag = wa_ever-vertrag.
ENDIF.
ENDLOOP.
ENDLOOP.
LOOP AT it_isu_data.
LOOP AT it_iflot WHERE tplnr = it_isu_data-tplnr.
wa_final-s_o_code = it_iflot-zwst_wtr.
MODIFY it_final FROM wa_final TRANSPORTING s_o_code
WHERE vertrag = it_isu_data-vertrag.
CLEAR wa_final-s_o_code.
ENDLOOP.
LOOP AT it_final INTO wa_final.
LOOP AT it_erch WHERE vertrag = wa_final-vertrag.
IF it_erch-vertrag = wa_final-vertrag.
SELECT SINGLE tariftyp
branche
FROM eanlh
INTO (l_tariftyp, l_branche)
WHERE ab <= it_erch-erdat AND bis > it_erch-erdat
AND anlage = wa_final-anlage.
IF sy-subrc = 0.
wa_final-t_type = l_tariftyp.
IF l_tariftyp IS NOT INITIAL.
SELECT SINGLE ttypbez
FROM ettat
INTO l_ttypbez
WHERE spras = sy-langu
AND tariftyp = l_tariftyp.
wa_final-c_description = l_ttypbez.
ENDIF.
MODIFY it_final FROM wa_final TRANSPORTING c_description t_type. "sic_code
ENDIF.
CLEAR it_erch.
ENDLOOP.
CLEAR: wa_final, l_tariftyp, l_ttypbez, l_branche.
ENDLOOP.
DATA : it_egerh TYPE STANDARD TABLE OF ty_egerh,
wa_egerh TYPE ty_egerh.
LOOP AT it_final INTO wa_final.
LOOP AT it_erch WHERE vertrag = wa_final-vertrag.
wa_comb-equnr = wa_final-equnr.
wa_comb-erdat = it_erch-erdat.
APPEND wa_comb TO it_comb.
CLEAR wa_comb.
CLEAR it_erch.
ENDLOOP.
CLEAR wa_final.
ENDLOOP.
IF it_final[] IS NOT INITIAL.
SELECT anlage
logikzw
bis
preiskla
FROM easts
INTO TABLE it_easts
FOR ALL ENTRIES IN it_final
WHERE anlage = it_final-anlage.
IF sy-subrc = 0.
LOOP AT it_final INTO wa_final.
LOOP AT it_easts INTO wa_easts WHERE anlage = wa_final-anlage.
wa_final-m_size = wa_easts-preiskla.
MODIFY it_final FROM wa_final TRANSPORTING m_size WHERE anlage = wa_final-anlage.
ENDLOOP.
ENDLOOP.Hi Indu,
if u got Nested Loops then use PARALLEL CURSOR METHOD .
The performance will be very good.
Nested Loops This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.
Program using Normal Nested Loop:
REPORT ZNORMAL_NESTEDLOOP.
TABLES:
likp,
lips.
Data:
t_likp type table of likp,
t_lips type TABLE OF lips.
data:
W_RUNTIME1 TYPE I,
W_RUNTIME2 TYPE I.
START-OF-SELECTION.
select *
from likp
into table t_likp.
select *
from lips
into table t_lips.
get RUN TIME FIELD w_runtime1.
loop at t_likp into likp.
loop at t_lips into lips where vbeln eq likp-vbeln.
endloop.
endloop.
get RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
write w_runtime2.
Nested Loop using Parallel Cursor:
REPORT zparallel_cursor2.
TABLES:
likp,
lips.
DATA:
t_likp TYPE TABLE OF likp,
t_lips TYPE TABLE OF lips.
DATA:
w_runtime1 TYPE i,
w_runtime2 TYPE i,
w_index LIKE sy-index.
START-OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp.
SELECT *
FROM lips
INTO TABLE t_lips.
GET RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln.
SORT t_lips BY vbeln.
LOOP AT t_likp INTO likp.
LOOP AT t_lips INTO lips FROM w_index.
IF likp-vbeln NE lips-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
WRITE w_runtime2.
Analysis report: Runtime in microseconds:
Iteration No ...... Normal Nested Loop ..... Using Parallel Cursor
1...................... 34,796,147 .........................63,829
2 ..................... 38,534,583 ......................... 56,894
3 ..................... 34,103,426 ......................... 50,510
Please check this link
http://www.****************/Tutorials/ABAP/ParallelCursor.htm
reward if helpful
raam. -
Removing loop from loop.
Can any one help me on this issue,
i have to remove the loop on bseg ans so that i can add .
CLEAR : w_debit ,
w_credit .
LOOP AT wtl_temp ASSIGNING <fs>.
READ TABLE wtl_prctr WITH KEY bukrs = <fs>-bukrs
belnr = <lfs>-belnr
gjahr = <lfs>-gjahr
prctr = <lfs>-prctr
hkont = <lfs>-hkont
TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
MOVE : <lfs1>-bukrs TO wsl_prctr-bukrs,
<fs>-belnr TO wsl_prctr-belnr,
<fs>-gjahr TO wsl_prctr-gjahr,
<fs>-prctr TO wsl_prctr-prctr,
<fs>-hkont TO wsl_prctr-hkont.
LOOP AT wt_bseg ASSIGNING <fs2> WHERE bukrs EQ <fs>-bukrs
AND belnr EQ <fs>-belnr
AND gjahr EQ <fs>-gjahr
AND prctr EQ <fs>-prctr
AND hkont EQ <fs>-hkont.
CASE <fs2>-shkzg.
WHEN c_debit .
w_debit = w_debit + <fs2>-dmbtr.
WHEN c_credit.
w_credit = w_credit + <fs2>-dmbtr.
ENDCASE.
ENDLOOP.
wsl_prctr-dmbtr = w_credit - w_debit.
APPEND wsl_prctr TO wtl_prctr.
CLEAR : wsl_prctr ,
w_debit ,
w_credit .
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.Hi,
u can use parallel Cursor method here.
if it is compulsory to use nested loops, then we need to go for PARALLEL CURSOR METHOD
this is very efficient method. This decreases the execution time and increases the performance.
here is a sample code for PARALLEL CURSOR METHOD
Nested Loops This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.
Program using Normal Nested Loop:
REPORT ZNORMAL_NESTEDLOOP.
TABLES:
likp,
lips.
Data:
t_likp type table of likp,
t_lips type TABLE OF lips.
data:
W_RUNTIME1 TYPE I,
W_RUNTIME2 TYPE I.
START-OF-SELECTION.
select *
from likp
into table t_likp.
select *
from lips
into table t_lips.
get RUN TIME FIELD w_runtime1.
loop at t_likp into likp.
loop at t_lips into lips where vbeln eq likp-vbeln.
endloop.
endloop.
get RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
write w_runtime2.
Nested Loop using Parallel Cursor:
REPORT zparallel_cursor2.
TABLES:
likp,
lips.
DATA:
t_likp TYPE TABLE OF likp,
t_lips TYPE TABLE OF lips.
DATA:
w_runtime1 TYPE i,
w_runtime2 TYPE i,
w_index LIKE sy-index.
START-OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp.
SELECT *
FROM lips
INTO TABLE t_lips.
GET RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln.
SORT t_lips BY vbeln.
LOOP AT t_likp INTO likp.
LOOP AT t_lips INTO lips FROM w_index.
IF likp-vbeln NE lips-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
WRITE w_runtime2.
Analysis report: Runtime in microseconds:
Iteration No ....._Normal Nest Loop_ ..... Using Parallel Cursor
1 ....................... 34,796,147 ................... 63,829
2 .........................38,534,583 ................... 56,894
3 .........................34,103,426 ................... 50,510
u can check this site for more details
http://www.****************/Tutorials/ABAP/ParallelCursor.htm
reward if helpful
raam
Maybe you are looking for
-
When I first open a project in PrPro it asks a strange request to relink media. No files have been moved and all my media is on one hard drive. I understand how to relink media but this is strange. It asks "Where is the File "V1-etc, etc, etc? I'
-
Cant load mod_authz_default.so to start httpd service
Hi people.. im having an error just after i updated my laptop 2 days ago and i cant start my httpd service... when i try to start the httpd service i got this error: Syntax error on line 59 of /etc/httpd/conf/httpd.conf: Cannot load modules/mod_authn
-
PDF newbie: image in PDF
I am trying to learn the PDF language and make some PDF files from scratch. I have made some text files which work and now I want to insert some images, but I can't get it to work! I have made a testfile consisting of just an image inserted as an XOb
-
How to get contents from field of a pdf form?
Hi Experts, I am creating an application in which I have a table in pdf form and the table is bound to a node of the context of the view. Now I want to change value of one column of the table and the updated value is needed in a BAPI, which will be c
-
Dynamic Graphics - Image not clear in HTML page
Hi, i tried to generate the image from Dynamic Graphics( 3D Dial gauge). It creates successfully but when i show this image in HTML page it is not clear i.e values and arc are showing like points and words in description also shows as splited. How to