‎2007 Aug 09 9:52 PM
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
‎2007 Aug 09 10:00 PM
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
‎2007 Aug 09 10:03 PM
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.
‎2007 Aug 09 10:12 PM
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
‎2007 Aug 09 10:14 PM
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..."
‎2007 Aug 09 10:05 PM
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.