‎2008 Jul 16 8:10 AM
Hi...Friends,
>loop at itab1.
>
>/////
>
> loop at itab2 where f1 = itab1-f1.
>
>///////
>
> endloop.
>
>endloop.
Here Iam having more than one entreis in table itab2 for each itab-f1 entry.
I want the same functionality with out using where condition for second loop.
( Get back to you... If you want to know my orginal problem..at closing of this thread... )
Thanks,
Naveen.I
‎2008 Jul 16 8:11 AM
Hi,
You better use
Read table statement and get the no of lines of the internal table (Say it is N).
and DO N times ..ENDDO loop
Regards,
Anirban
‎2008 Jul 16 8:11 AM
Hi,
You better use
Read table statement and get the no of lines of the internal table (Say it is N).
and DO N times ..ENDDO loop
Regards,
Anirban
‎2008 Jul 16 8:13 AM
Hi Experts....
here read statement with "with key statement" is not working.........
Any other replies...
(Hi freinds... I deffenately get back with my problem in this thread...give me some time.. plz try logic.. )
Thanks,
Naveen.I
Edited by: Naveen Inuganti on Jul 16, 2008 12:44 PM
‎2008 Jul 16 8:15 AM
hi,
you can use
DESCRIBE <ITAB>statement.
CHECK THE SYNTAX
DESCRIBE TABLE <itab> [LINES <l>]
[OCCURS <n>]
[KIND <k>].Here LINES will give you total line no.
REGARDS,
ANIRBAN
‎2008 Jul 16 8:19 AM
Hi Naveen.
Use parallel cursor technique which is much faster than loop at where clause.
SORT itab1 BY f1,
itab2 BY f1.
MOVE 1 TO w_index.
LOOP AT itab1 INTO wa1.
LOOP AT itab2 INTO wa2 FROM w_index.
IFwa1-f1 NE wa-f2.
w_index = sy-tabix.
EXIT.
ENDIF.
Do your processing
ENDLOOP.
ENDLOOP.
Check below sample code for usage of parallel cursor tech.(Comparision also.)
TABLES: vbak.
SELECT-OPTIONS: so_vbeln FOR vbak-vbeln,
so_erdat FOR vbak-erdat.
PARAMETERS: po_rows TYPE i.
TYPES: BEGIN OF t_vbak,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF t_vbak,
BEGIN OF t_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
END OF t_vbap.
DATA: i_vbak TYPE STANDARD TABLE OF t_vbak,
i_vbap TYPE STANDARD TABLE OF t_vbap,
wa_vbak TYPE t_vbak,
wa_vbap TYPE t_vbap,
w_time1 TYPE i,
w_time2 TYPE i,
w_time3 TYPE i,
w_count TYPE i,
w_index TYPE sy-index.
SELECT vbeln erdat UP TO po_rows ROWS
INTO TABLE i_vbak
FROM vbak
WHERE vbeln IN so_vbeln
AND erdat IN so_erdat.
WRITE:/1 'Total number of header records', sy-dbcnt.
CHECK NOT i_vbak[] IS INITIAL.
SELECT vbeln posnr
INTO TABLE i_vbap
FROM vbap
FOR ALL ENTRIES IN i_vbak
WHERE vbeln EQ i_vbak-vbeln.
WRITE:/1 'Total number of item records', sy-dbcnt.
SORT: i_vbak BY vbeln,
i_vbap BY vbeln.
DO 5 TIMES.
CLEAR: w_time1, w_time2, w_time3, w_count.
GET RUN TIME FIELD w_time1.
*Loop at where clause
LOOP AT i_vbak INTO wa_vbak.
LOOP AT i_vbap INTO wa_vbap WHERE vbeln EQ wa_vbak-vbeln.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD w_time2.
w_time3 = w_time2 - w_time1.
WRITE: /1 'Time taken for where clause', w_time3,
/1 'Number matching records', w_count.
CLEAR: w_time1, w_time2, w_time3, w_count.
GET RUN TIME FIELD w_time1.
*Parallel cursor technique
MOVE 1 TO w_index.
LOOP AT i_vbak INTO wa_vbak.
LOOP AT i_vbap INTO wa_vbap FROM w_index.
IF wa_vbak-vbeln NE wa_vbap-vbeln.
w_index = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD w_time2.
w_time3 = w_time2 - w_time1.
WRITE: /1 'Time taken for parallel processing' , w_time3,
/1 'Number matching records', w_count.
ENDDO.
Thanks,
Vinod.
‎2008 Jul 16 8:12 AM
HI,
You can store sy-tabix in a variable and then loop at itab2 from <variable>.
This is more eficient in such cases.
‎2008 Jul 16 8:13 AM
‎2008 Jul 16 8:15 AM
HI ,
You can remove where condition , use from .. to and put if condition inside that second loop.if successfull capture sy-tabix into a variable use this variable in loop from..to.Hope it helps.
Regards,
Kalyan.
‎2008 Jul 16 8:15 AM
hi,
i think we can use the concept of parallel cursors i.e., using sy-tabix we can ctrl the loop iteration.
Rgds.,
subash
‎2008 Jul 16 8:16 AM
Hi,
Loop at itab1.
Loop at itab2.
if itab1-f1 = itab2-f1.
write: 'Match found'.(What you want ot Display)
endif.
Endloop.
Endloop.
Regards,
Sujit
‎2008 Jul 16 8:19 AM
Hi Naveen,
Solution:
sort itab2 by f1.
loop at itab1.
..............
read table itab2 with key f1 = itab1-f1 binary search.
if sy-subrc = 0.
w_index = sy-tabix.
loop at itab2 from w_index.
if itab2-f1 = itab1-f1.
..........
else.
exit.
endif.
endloop.
...............
endloop.
if it useful, reward points.
Thank you,
Prasad G.V.K
‎2008 Jul 16 8:24 AM
hiiii
here you can use READ statement but before that what ever field you are using in where condition ..sort second table by that field.then instead of using second loop condition use READ statement & in that use IF condition...then write whatever you want to display...i think it will work..
loop at itab1..
sort itab2 by ....
read table i tab2...
if condition...
display()
endif.
endloop.
regards
twinkal
‎2008 Jul 16 8:26 AM
Hi,
Try to avoid loop inside a loop.
Instead of loop inside a loop use parallel cursor to enhance the performance.
Please try in this way.
loop at i_tab1 into wa_work1.
read table I-tab2 transporting no field with key f1 = wa_work1-f1.
if sy-subrc = 0.
l_tabix = sy-tabix.
loop at i_tab2 into wa_work2 from l_tabix.
if wa_work2-f1 = wa_work1-f1.
-
do ur work
else
exit.
endloop.
endif.
endloop.
‎2008 Jul 16 8:28 AM
Hai Naveen,
loop at itab1.
/////
read table itab2 with key f1 = itab1-f1.
if sy-subrc eq 0.
///////
endif.
endloop.
Regards,
Harish
‎2008 Jul 16 8:38 AM
HI..... Friends....
That was really very great responce from ur side....
Actually where condition is not working for loop..,
And also read statement also not working with "with key" statement...for the internal table in changing parameter of subroutine which is in the include program of function module..
there is one more thread with folloing subject.. with complete code...
Subroutine showing error in include program with changing parameter
Here so many solutions are there...I will try..
Get back to you with result....
Thanks a lot SDN friends,
Naveen Inuganti
Edited by: Naveen Inuganti on Jul 16, 2008 1:12 PM
‎2008 Jul 16 8:43 AM
Hi,
Why don't you try doing like
loop at itab1.
*steps to be done for itab1 data
/////
endloop.
above loop for processing of itab1 data and
for common data do it as below:
loop at itab2.
read itab1 where f1 = itab2-f1.
*steps for common data in itab1 and itab2
///////
endloop.
As I suppose there is a unique f1 in itab1 for multiple f1 in itab2.
I hope this solves the problem.
‎2008 Jul 16 8:45 AM
Hi.... Hitish...,
No there is number of f1s in itab1...
and..,
Now may i know what is the entry for itab2-f1 in read statement.. in ur code...
Thnaks for ur reply,
Naveen.I
‎2008 Jul 16 9:07 AM
Hi Naveen,
The itab2-f1 in the prev code is the f1 in itab2 for which we find data in itab1 (which i thought was a single record).
If there are a number of f1s in itab1 and itab2 both u can try this
sort itab2 by f1.
loop at itab1.
*steps for itab1 data
/////
read itab2 with key f1 = itab1-f1 binary search transporting no fields.
*this will give index of first f1 in table itab2
lv_index = sy-tabix
loop at itab2 from lv_index.
if itab2-f1 ne itab1-f1.
exit.
endif.
*steps for common data in itab1 and itab2
///////
endloop.
*above loop will run same as loop with where condition
endloop.
Hope this will help.
Reward points if it works for u.
Thanks,
Hitesh