‎2008 Mar 26 9:56 AM
Hi,
I have copied some code from a book, and modified it, in order to learn ABAP. The program keeps hanging, and I do not know why.
I have less than 2 weeks of experience with ABAP, so clearly explain everything.
Regards,
Al Lal
data: w_key(10) type c.
data: begin of ikey,
city(10) type c,
state(2) type c,
zip(5) type c,
end of ikey.
data: begin of itab2 occurs 10000,
city(10) type c,
state(2) type c,
zip(5) type c,
name(15) type c,
address(20) type c,
phone(10) type c,
end of itab2.
move 'Miami' to itab2-city.
move 'FL' to itab2-state.
move '99999' to itab2-state.
append itab2.
clear itab2.
move 'New York' to itab2-city.
move 'NY' to itab2-state.
move '99999' to itab2-zip.
append itab2.
clear itab2.
move 'New York' to w_key.
while sy-subrc = 0.
read table itab2 with key w_key.
if sy-subrc = 0.
write itab2.
endif.
endwhile.
move 'New York' to ikey-city.
move 'NY' to ikey-state.
move '99999' to ikey-zip.
while sy-subrc = 0.
read table itab2 with key ikey.
if sy-subrc = 0.
write itab2.
endif.
endwhile.
‎2008 Mar 26 9:59 AM
The best way to resolve issues is to run the program in debug mode. Anyway, its prob this.
move 'New York' to w_key.
while sy-subrc = 0.
read table itab2 with key w_key.
if sy-subrc = 0.
write itab2.
endif.
endwhile.
The return code will always be zero. Change it to this.
move 'New York' to w_key.
read table itab2 with key w_key.
if sy-subrc = 0.
write itab2.
endif.
‎2008 Mar 26 10:05 AM
Hi,
Remove while-endwhile...
while reading a table you always check sy-subrc.
If the entry is available it will show sy-subrc = 0.