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

where clause

Former Member
0 Likes
674

i have an itab ITAB1 , with a field NAME which is supposed to have many A's, but

i have to report error if all entries are A's.

LOOP AT ITAB1 WHERE NAME .....................

WRITE: / 'ERROR'.

EXIT.

ENDLOOP.

what do i put in the where clause.

plz help

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
652

Try this.

data: counter type i.
data: total_lines type i.

LOOP AT ITAB1 WHERE name = 'A'.
  counter = counter + 1.
ENDLOOP.

describe table itab1 lines total_lines.

if total_lines = counter.
  write:/ 'Error'.
endif.

Regards,.

RIch Heilman

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
653

Try this.

data: counter type i.
data: total_lines type i.

LOOP AT ITAB1 WHERE name = 'A'.
  counter = counter + 1.
ENDLOOP.

describe table itab1 lines total_lines.

if total_lines = counter.
  write:/ 'Error'.
endif.

Regards,.

RIch Heilman

Read only

Former Member
0 Likes
652

I did not quite get it.

Do you have to report an error if all the entries in internal table are 'A' or do you have to report an error if all the character in field NAME are 'A'?

Can you please give more details?

If you need to check whether all the entries in table are 'A' or not then you can use:

CLEAR FLAG.

LOOP AT ITAB1 WHERE NAME <b><> 'A'</b>.

FLAG = 'X'.

ENDLOOP.

IF FLAG = ' '.

WRITE 'ERROR'.

ENDIF.

Message was edited by:

Darshil Shah

Read only

Former Member
0 Likes
652

Saritha,

This statement will work if you still need the EXIT.

READ TABLE itab1 INTO wa_itab1 WITH KEY name = 'A'.

if sy-subrc = 0.

WRITE: /'ERROR'.

endif.

Read only

Former Member
0 Likes
652

thanks rich and darshil.

Read only

Former Member
0 Likes
652

felip , i think you did not get my point.

your code returns sy-subrc as soon as it gets first A entry and reports error at very first entry.

but my situation was if all the entries were A's it should give error.

but anyways i got solution.

good try, thank you.