Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

modify stmt in read and select query?

Former Member
0 Likes
1,193

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  .

1 ACCEPTED SOLUTION
Read only

guilherme_frisoni
Contributor
0 Likes
1,169

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

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  .

9 REPLIES 9
Read only

hendrik_brandes
Contributor
0 Likes
1,169

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

Read only

0 Likes
1,169

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.

.

Read only

Former Member
0 Likes
1,169

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

Read only

0 Likes
1,169

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.?

Read only

0 Likes
1,169

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

Read only

guilherme_frisoni
Contributor
0 Likes
1,170

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

Read only

0 Likes
1,169

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.

Read only

Former Member
0 Likes
1,169

Hi Krishna sree,

                           Check what are the key fields of your table. I think this problem is because of your key fields.

Read only

0 Likes
1,169

Hi,

    Thank,Issuse resolved.thanks for sharing.