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

Issues fetchng data from VBFA table...

Former Member
0 Likes
1,846

Hello,

I am having an issue realted to a SQL query in a report. I am having three select options viz: sales order number, Delivery document number and Billing document numbr as select options.

Now when I enter either Delivery document number or Billing document number, data gets fetched but when I enter both Delivery document number and Billing ocument number on screen, nothing gets fetched...

DATA: begin of i_vbfa,

vbelv like vbfa-vbelv,

vbtyp_v like vbfa-vbtyp_v,

vbeln like vbfa-vbeln,

vbtyp_n like vbfa-vbtyp_n,

end of i_vbfa.

data: it_vbfa like table of i_vbfa with header line.

select-options:

S_VBELN for VBAK-VBELN,

S_DELNOT for VBFA-VBELN,

S_BILDOC for VBFA-VBELN.

select vbelv vbtyp_v vbeln vbtyp_n

from VBFA into table it_vbfa

where VBELV in S_VBELN

and ( ( VBELN in S_DELNOT ) and ( VBELN in S_BILDOC ) )

and VBTYP_V = 'C'

and ( ( VBTYP_N = 'J' ) OR ( VBTYP_N = 'M' ) ).

Please help.

Regards,

Rajesh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,122

>

> select vbelv vbtyp_v vbeln vbtyp_n

> from VBFA into table it_vbfa

> where VBELV in S_VBELN

> and ( ( VBELN in S_DELNOT ) and ( VBELN in S_BILDOC ) )

> and VBTYP_V = 'C'

> and ( ( VBTYP_N = 'J' ) OR ( VBTYP_N = 'M' ) ).

Hi u cant have an and condition like that.

because vbeln at a time can have only ether delivery number or billing number.

what ur condition suggests is that the number in the table should be both delivery number and billing doc at the same time which is not possible, so use two queries, in first give vbelv as sales order number and vbeln as delivery number then in next query use vbelv as delivery and vbeln is billing doc of ur select option.


select vbelv vbtyp_v vbeln vbtyp_n
       from VBFA into table it_vbfa
        where VBELV in S_VBELN
        and  ( VBELN in S_DELNOT )
        and  VBTYP_V = 'C'
        and  (( VBTYP_N = 'J' ) .

select vbelv vbtyp_v vbeln vbtyp_n
        from VBFA into table it_vbfa   " not sure if its overwrtes or appends so just check it
        where VBELV in S_delnot
        and   VBELN in S_BILDOC 
        and  VBTYP_V = 'J'
        and  ( VBTYP_N = 'M' ) .

Edited by: kartik tarla on Jan 14, 2009 7:52 AM

Edited by: kartik tarla on Jan 14, 2009 7:56 AM

5 REPLIES 5
Read only

Former Member
0 Likes
1,122

You should use an OR in the select where condition. VBELN cannot be s_delnot and s_bildoc. It will hold either of the values.

select vbelv vbtyp_v vbeln vbtyp_n

from VBFA into table it_vbfa

where VBELV in S_VBELN

and ( ( VBELN in S_DELNOT ) and ( VBELN in S_BILDOC ) )

and VBTYP_V = 'C'

and ( ( VBTYP_N = 'J' ) OR ( VBTYP_N = 'M' ) ).

change to

select vbelv vbtyp_v vbeln vbtyp_n

from VBFA into table it_vbfa

where VBELV in S_VBELN

and ( ( VBELN in S_DELNOT )OR ( VBELN in S_BILDOC ) )

and VBTYP_V = 'C'

and ( ( VBTYP_N = 'J' ) OR ( VBTYP_N = 'M' ) ).

regards,

Advait

Read only

0 Likes
1,122

Hi,

Using 'OR' would not work because if we feed the value for S_BILDOC field and leave the S_DELNOT field then, the query will fetch value for S_BILDOC and also all the data records for S_DELNOT if kept blank.

Any other idea..

Regards,

Rajesh.

Read only

0 Likes
1,122

populate the same table with two different selects... check if the select option is filled... based on that use different select statement.

Read only

Former Member
0 Likes
1,123

>

> select vbelv vbtyp_v vbeln vbtyp_n

> from VBFA into table it_vbfa

> where VBELV in S_VBELN

> and ( ( VBELN in S_DELNOT ) and ( VBELN in S_BILDOC ) )

> and VBTYP_V = 'C'

> and ( ( VBTYP_N = 'J' ) OR ( VBTYP_N = 'M' ) ).

Hi u cant have an and condition like that.

because vbeln at a time can have only ether delivery number or billing number.

what ur condition suggests is that the number in the table should be both delivery number and billing doc at the same time which is not possible, so use two queries, in first give vbelv as sales order number and vbeln as delivery number then in next query use vbelv as delivery and vbeln is billing doc of ur select option.


select vbelv vbtyp_v vbeln vbtyp_n
       from VBFA into table it_vbfa
        where VBELV in S_VBELN
        and  ( VBELN in S_DELNOT )
        and  VBTYP_V = 'C'
        and  (( VBTYP_N = 'J' ) .

select vbelv vbtyp_v vbeln vbtyp_n
        from VBFA into table it_vbfa   " not sure if its overwrtes or appends so just check it
        where VBELV in S_delnot
        and   VBELN in S_BILDOC 
        and  VBTYP_V = 'J'
        and  ( VBTYP_N = 'M' ) .

Edited by: kartik tarla on Jan 14, 2009 7:52 AM

Edited by: kartik tarla on Jan 14, 2009 7:56 AM

Read only

0 Likes
1,122

Hi Rajesh... in VBFA table u can have record for sales doc and delivery doc combination and for sales doc and billing doc number but not for delivery doc and billing doc ...

so as Kartik has suggested u can use two queries.. one to get data for sales doc and delivery doc... and nother for sales doc and billing doc combination...

just one correction for second query use appending clause

select vbelv vbtyp_v vbeln vbtyp_n

from VBFA into table it_vbfa

where VBELV in S_VBELN

and ( VBELN in S_DELNOT )

and VBTYP_V = 'C'

and (( VBTYP_N = 'J' ) .

select vbelv vbtyp_v vbeln vbtyp_n

from VBFA appending into table it_vbfa

where VBELV in S_delnot

and VBELN in S_BILDOC

and VBTYP_V = 'J'

and ( VBTYP_N = 'M' ) .

hope this solves your problem