‎2006 Aug 31 2:34 PM
Hi,
I have one query regarding different condition. Suppose i have to one internal table itab.
Now i read the data from vbak & vbap table. My parameters r p_vbeln, p_posnr.
parameters: p_vbeln LIKE vbak-vbeln,
p_posnr LIKE vbak-posnr.
I have to select all records from table vbak for parameter p_vbeln.
after it for each entry on table vbak select single on table vbap for the material. & store
it into internal table itab.
if only one entry exists on table itab check the entry matches the input parameters p_vbeln,
p_posnr. If no match then generate error. If match then proceed.
anybody will tell me how to write the logic for the above condition.
thanks in advance.
‎2006 Aug 31 2:38 PM
Why do you want to add a condition again. because
select * into corresponding fields of table itab
from vbap
where vbeln in (
select vbeln from vbak where vbeln eq p_vbeln )
and matnr eq p_matnr
and posnr eq p_posnr.
if not sy-subrc is initial.
"not match.
endif.
itab already has conditioned value.
ibrahim
ok i have changed the code.
Message was edited by: Ibrahim UGUR
‎2006 Aug 31 2:41 PM
HI Ibrahim,
I think ur not fully read my query. I have to use first select statement & after that select statement i have to use select single * for vbak table. after it lot of conditions are there.
‎2006 Aug 31 3:00 PM
Hi Salil,
I agree with Anurag regarding one key field from VBAK and you will get one record only. But here is what i understood from your requirement.
tables: vbak, vbap.
select * from vbak where vbeln = p_vbeln.
if sy-subrc eq 0.
select single * from vbap where vbeln = vbak-vbeln.
if sy-subrc eq 0.
move-corresponding vbap to itab.
endif.
endif.
endselect.
describe table itab lines index.
check index eq 1.
loop at itab.
if itab-vbeln eq p_vbeln and itab-posnr eq p_posnr.
do other stuff.
else.
message e000 with 'record not matches'.
endif.
endloop.
hope this will help you.
Regards,
Vivek
‎2006 Aug 31 2:54 PM
I am bit confused about your requirement as vbeln is the key for table VBAK..so if you have a parameter for vbeln it would fetch only a single record from VBAK and not many records.
Secondly, you want to read the material information and store it in itab for all lines for the particular order. Also, to check if itab has only one line than compare the posnr paramter with itab.
The complete check can be done using the below.
SELECT avbeln bposnr b~matnr
into table itab
from vbak as a inner join vbap as b on avbeln = bvbap
where a~vbeln = p_vbeln.
describe table itab lines lrec.
If lrec = 1.
read table itab index 1.
if p_posnr <> itab-posnr.
Error Message.
endif.
endif.