08-14-2006 5:50 AM
Hi friends,
I have one query regarding one logic.
First of all i m checking one field from database table.
say f1-c1. f1 is table name & c1 field name.
Now If the non of records are found for the above mentioned condition then it will check for another f2-c2.
Will u write one sample code for this??
should i directly check the condition using table & field name??
i.e. If KNA1-KUNNR = '001'
????
08-14-2006 6:19 AM
Hi,
You can achieve this with number of ways.
1.After the first select statement you check the sy-subrc value returned by abap,if it is not equal to zero then you need to write another select statement.
2.If you want to check whether that particular field has value or not then you need to check like this,
if f1-cl = space then write your select statement.
cheers,
Bujji
08-14-2006 6:28 AM
Hi,
Let`s say you`re trying to get the company code to which a customer is configured.
<u>Fact:</u>
1.Customer Number is found in table KNA1 and Company code is found in KNB1.
Your code should be as follows:
data : l_cust like kna1-kunnr,
l_bukrs like knb1-bukrs.
parameters : p_kunnr like kna1-kunnr obligatory.
start-of-selection.
select single kunnr from kna1 into l_cust
where kunnr = p_kunnr.
if sy-subrc = 0.
select single bukrs from knb1 into l_bukrs
where kunnr = p_kunnr.
else.
message 'customer number invalid' type 'S'...
endif.
This should help you, reward if helpful.
Regards
08-14-2006 6:34 AM
hi salil,
try this code..
<b>SELECT SINGLE C1 FROM F1.
IF SY-SUBRC EQ 0."Atleast one record found
SELECT SINGLE C2 FROM F2.
ELSE.
MESSAGE 'NO RECORDS FOUND IN PRIMARY TABLE' TYPE 'S'.
ENDIF.</b>
<u><b>NOTE: Without select query you cannot validate the table fields</b></u>
Regards:-
<b>Santosh</b>
<i>Award Points if the above thing is usefull</i>
Message was edited by: santosh D
08-14-2006 6:55 AM
hi,
u can check sy-subrc for first query.
if not zero , write next query.
this will solve ur purpose.