2013 Mar 18 12:19 PM
Hi Experts,
Below is the select query,and i tried to replace it with read table(the internal table is also having the same records as ekko table),when i execute the itab1 which i am modifying from select query is modifying the correct records ,whereas the itab2(itab1 = itab2) which i am modifying form read stmt is not modifying the correct values
LOOP AT ITAB1.
SELECT SINGLE
aedat lifnr bukrs
INTO (itab1-aedat,
itab1-lifnr,
itab1-bukrs)
FROM ekko
WHERE ebeln EQ itab1-ebeln.
IF sy-subrc EQ 0.
MODIFY itab1 TRANSPORTING aedat lifnr bukrs.
ENDIF.
endloop. here i am getting the o/p correctly.
*************************************************
loop at itab2.
READ TABLE
it_ekko_arch INTO wa_ekko_arch WITH KEY ebeln = itab2-ebeln .
itab2-aedat = wa_ekko_arch-aedat .
itab2-lifnr = wa_ekko_arch-lifnr .
itab2-bukrs = wa_ekko_arch-bukrs .
* APPEND itab1 .
IF sy-subrc EQ 0.
MODIFY itab2 TRANSPORTING aedat lifnr bukrs .
CLEAR wa_ekko_arch .
ENDIF.
endloop.
in itab2 all the 14 rows are populated with same values like 22.03.2016 00111 1000
22.03.2016 00111 1000 .
2013 Mar 18 1:18 PM
Hi Krishna,
the problem is that you are verifying SY-SUBRC after a move command, which will always be correct.
So, if you find a record in you read table in the firsta line, this line will be updated.
The next lina of itab2, if you didn't find any line in you read table statement, you will still move old values os wa_ekko_arch and do the modify in this line with wrong values.
All you need to to is move you line IF SY-SUBRC EQ 0 to right after your read table statement.
Regards,
Guilherme Frisoni
2013 Mar 18 12:59 PM
Hello Krishna,
I would suggest to use field-symbols:
LOOP AT i_tab1 ASSIGNING <line_itab1>.
SELECT SINGLE
aedat lifnr bukrs
INTO (<line_itab1>-aedat,
<line_itab1>-lifnr,
<line_itab1>-bukrs)
FROM ekko
WHERE ebeln EQ <itab1>-ebeln.
ENDLOOP.
But: Try to think about another solution: SELECT single within LOOP is not the best way to deal with a lot of data.
Kind regards,
Hendrik
2013 Mar 18 1:06 PM
HI,
Thanks for u r reply,i agree with wat u said.,but,here my situtation is different,i am editing the clients code,so i can'nt change their code,i told to add the extra code to read the data form the archivied records(here i am getting the archived records to the itab2 internal table)so,i need to do exactly wat they did with select query but i have to use the internal tables.
.
2013 Mar 18 1:01 PM
Hello.
I think that it will be helpful and better to use a Working Area while doing the loops.
loop at itab2 into wa_itab2.
...do ur thing
modify itab2 from wa_itab2. " modify the table, no mistakes with index
endloop.
same logic to the first table.
Regards
2013 Mar 18 1:08 PM
HI,
As explained above ,client decelared itab2 with header line.so i can't use the work area.
will it work,if i use where condition in modify stmt.?
2013 Mar 18 1:24 PM
so change ur code to this
loop at itab2.
READ TABLE
it_ekko_arch INTO wa_ekko_arch WITH KEY ebeln = itab2-ebeln .
IF sy-subrc = '0'.
itab2-aedat = wa_ekko_arch-aedat .
itab2-lifnr = wa_ekko_arch-lifnr .
itab2-bukrs = wa_ekko_arch-bukrs .
MODIFY itab2 TRANSPORTING aedat lifnr bukrs .
CLEAR wa_ekko_arch .
ENDIF.
endloop.
Regards
2013 Mar 18 1:18 PM
Hi Krishna,
the problem is that you are verifying SY-SUBRC after a move command, which will always be correct.
So, if you find a record in you read table in the firsta line, this line will be updated.
The next lina of itab2, if you didn't find any line in you read table statement, you will still move old values os wa_ekko_arch and do the modify in this line with wrong values.
All you need to to is move you line IF SY-SUBRC EQ 0 to right after your read table statement.
Regards,
Guilherme Frisoni
2013 Mar 19 9:05 AM
HI Frisoni.
Did exactly ,wat u said above,but still the same value is populating in all rows .checked the data in database ,it has different values.
2013 Mar 19 9:35 AM
Hi Krishna sree,
Check what are the key fields of your table. I think this problem is because of your key fields.
2013 Mar 19 9:50 AM