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

Validation

Former Member
0 Likes
638

Hi guys,

I am new to ABAP.

I need to validate one of my statement, according to it if customer type is 'PY then check Customer id against Knvp-kunn2 where knvp-parvw= AB.

and for this I have written this code:

if it_tab-custty = 'PY'.

it_tabcustid = knvp-kunn2

where knvp-parvw = 'AB'.

endif.

But its giving me some error. Can you help me out.

Thanks

Rajeev Gupta

5 REPLIES 5
Read only

uwe_schieferstein
Active Contributor
0 Likes
607

Hello Rajeev

Based on your description I assume that you have to do a select on table KNVP. Then you could use the following coding:

  IF ( it_tab-custty = 'PY' ).
    SELECT * FROM knvp INTO ls_knvp
      WHERE ( kunn2 = it_tab-custid    AND
              parvw = 'AB' ).
      EXIT.
    ENDSELECT.

    IF ( syst-subrc = 0 ).
"    at least single entry found in DB table that matches condition
"    ...do something

    ELSE.
"    no entry found
    ENDIF.

  ELSE.
...
  ENDIF.

Regards

Uwe

Read only

Former Member
0 Likes
607

The Where clause is only used in SQL statements, like a select, update, or delete. You will have to first select the data from KNVP.

IF it_tab-custty = 'PY'.

SELECT * FROM knvp WHERE kunn2 = it_tabcustid AND parvw = 'AB'.

ENDIF.

Read only

0 Likes
607

Kevin,

Just a correction for freshers in abap.

where clause is not only used in SQL.

you can also use in other places like 'read' , 'loop at itab'... etc.

Thanks,

Pankaj

Read only

0 Likes
607

Yes, "where" can be used in some other places like a loop statement. However, if you are doing a read statement you have to use "with key..."

Read only

Former Member
0 Likes
607

If you already selected from KNVP and those values are available to you.

if it_tab-custty = 'PY' and

it_tabcustid = knvp-kunn2 and

knvp-parvw = 'AB'.

endif.

If don't have KNVP record already then do this

if it_tab-custty = 'PY'.

select * from knvp up to 1 rows where kunn2 = it_tabcustid and knvp-parvw = 'AB'.

endselect.

check sy-subrc = 0.

endif.