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

ABAP table reading code keeps hanging

Former Member
0 Likes
347

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.

2 REPLIES 2
Read only

Former Member
0 Likes
309

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.

Read only

Former Member
0 Likes
309

Hi,

Remove while-endwhile...

while reading a table you always check sy-subrc.

If the entry is available it will show sy-subrc = 0.