‎2010 Mar 15 4:04 AM
Hi all,
The following is my codes.
LOOP AT t_pa INTO w_pa.
SELECT pernr
begda
endda
INTO TABLE t_infty_data
FROM (w_pa-pa)
WHERE begda <= me->a_payperiod-begda
AND endda >= me->a_payperiod-endda.
Anyone have any idea how can perform the Select statement outside the loop? I used the loop because at program run tme, I do not know yet which database tables to select from. Thanks.
Edited by: Siong Chao on Mar 15, 2010 5:05 AM
‎2010 Mar 15 5:04 AM
Select is required ?
data wa_infty_data like LINE OF t_infty_data.
LOOP AT t_pa INTO w_pa WHERE begda <= me->a_payperiod-begda AND endda >= me->a_payperiod-endda.
MOVE w_pa-..pernr to wa_infty_data-pernr
.... .... ....
APPEND wa_infty_data TO t_infty_data.
ENDLOOP.
‎2010 Mar 15 5:50 AM
Hello Siong Chao,
In the above scenario, you just have to move records from one internal table to another, for that a simple MOVE statement is needed. Select statements are meant to traverse database tables, internal tables have commands, such as READ, MOVE, MODIFY, WRITE, etc.
Regards,
Manish
‎2010 Mar 15 5:59 AM
Hi
Put the select retrieval in outside of the loop. Use the below code.
SELECT pernr
begda
endda
INTO TABLE t_infty_data
FOR ALL ENTRIES IN t_pa
WHERE PA = t_pa-pa AND
begda <= me->a_payperiod-begda AND
AND endda >= me->a_payperiod-endda.
Then
LOOP AT t_pa INTO w_pa.
READ TABLE t_infty_data with key = w_pa-KEY
IF SY-SUVRC EQ 0.
MOVE or USE ur logic
ENDIF
ENDLOOP
‎2010 Mar 15 6:48 AM
make sure you clear the header each time you enter the loop before reading the value from internal table through READ statement.....
‎2010 Mar 15 11:33 AM
Hi,
You can try as shown below,
data temp_pa type table of XXX (same as t_pa)
temp_pa = t_pa.
SORT temp_pa by pa.
delete adjacent duplicates temp_pa comapring pa.
loop at temp_pa into w_pa.
SELECT pernr
begda
endda
appending t_infty_data
FROM (w_pa-pa)
WHERE begda <= me->a_payperiod-begda
AND endda >= me->a_payperiod-endda.
endloop.
loop at t_pa into w_pa.
read table t_infty_data into wa with key....
endloop.
Note: There is a possibility of memory overflow while appending the entries into t_infty_data with data for all the different tables.
regards,
Chen
‎2010 Mar 15 2:27 PM