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

Comparing Operation

former_member202474
Contributor
0 Likes
805

Hi all,

I have written a code in the following manner.

data : wa type zaett, (zaett is my table)

itab2 type zaett occurs 0 with header line.

write / :sy-uname. (Initial output)

select * from zaett into table itab2.

loop at itab2 into wa.

if wa-username eq sy-uname.

write / wa-username.

else.

write : 'wrong'.

endif.

endloop.

My initial ouput is inf64624 (which is my sy-uname).The table also has inf64624 value in its username field , but in the "if statement "some problem is there it is always giving me output as wrong .wa-username is having the value inf64624 but I think some logical error is there.Please Help.

Regards,

Ruby.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
764

Hi Ruby ,

Why dont you use READ TABLE instead of loop endloop.

READ TABLE itab2 WITH KEY <USERNAME_FEILD> = SY-UNAME.

Regards

Arun

  • Assign points if reply is useful

5 REPLIES 5
Read only

Former Member
0 Likes
764

Hi,

The code is correct.

Try a Clear wa. before endloop.

But your code executes fine for me, when i replaced the tablename and the username.

Regards

Subramanian

Read only

Former Member
0 Likes
765

Hi Ruby ,

Why dont you use READ TABLE instead of loop endloop.

READ TABLE itab2 WITH KEY <USERNAME_FEILD> = SY-UNAME.

Regards

Arun

  • Assign points if reply is useful

Read only

former_member202474
Contributor
0 Likes
764

Hi all,

The mistake what I found is sy-uname is always in upper case.What i entered in my table was in lower case so it was not comparing .Any way .Thanks

Regards,

Ruby.

Read only

Former Member
0 Likes
764

In the select query itself u can specify the condition.

select * from zaett into table itab2 where username = sy-uname.

or use read statement next to ur select query.

READ TABLE itab2 INTO WA WITH KEY USERNAME = sy-uname .

Read only

Former Member
0 Likes
764

Hi

try this

data : wa type zaett, (zaett is my table)

itab2 type zaett occurs 0 with header line.

write / :sy-uname. (Initial output)

select * from zaett into table itab2

where username = sy-uname.

if sy-subrc = 0.

write : / wa-username.

else.

write : 'wrong'.

endif.

thanks

shiva