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

problem while Fetching BSAD

Former Member
0 Likes
1,272

Hi to all ,

I' ve problem while fetching bsad for a report , in t-code se30 i've seen that it takes %89,1 performance of overall.

SELECT belnr buzei dmbtr blart budat augdt augbl sgtxt

into table odemelerg

FROM bsad

WHERE bukrs EQ bukrs

AND kunnr EQ kunnr

AND ( umsks EQ space OR umsks IS NULL )

AND ( umskz EQ space OR umskz IS NULL )

AND augbl EQ i_augbl

AND augdt GE i_budat

AND gjahr EQ gjahr

AND belnr NE i_belnr

AND bsadbelnr NE bsadaugbl

AND ( blart EQ blart_bt OR blart EQ blart_hf

OR blart EQ blart_mi ).

here : blart_bt is declared as a constant type and its value is 'BT'. such as blart_hf, blart_mi

How can I make this Select query working in a better performance

Kind regards,

Caglar

11 REPLIES 11
Read only

Former Member
0 Likes
1,217

SELECT belnr buzei dmbtr blart budat augdt augbl sgtxt

into table odemelerg

FROM bsad

<b>WHERE bukrs EQ bukrs</b>

AND <b>kunnr EQ kunnr</b>

AND ( umsks EQ space OR umsks IS NULL )

AND ( umskz EQ space OR umskz IS NULL )

AND augbl EQ i_augbl

AND augdt GE i_budat

<b>AND gjahr EQ gjahr</b>

AND belnr NE i_belnr

<b>AND bsadbelnr NE bsadaugbl</b>

AND ( blart EQ blart_bt OR blart EQ blart_hf

OR blart EQ blart_mi ).

1)WHERE bukrs EQ <b>bukrs</b> -


>what is this..

2)bsadbelnr NE bsadaugbl )it is not a join query....

Read only

0 Likes
1,217

Yes you are right Kishan, i forgot to explain them.

this is a class-based report and the biggest was written in se24 .

bukrs is coming from selection screen parameter and i am passing it to the method as 'Bukrs' contains only one value. same as field Kunnr ,

But from 2nd one i couldn' t understand what you meant

thanks

Caglar

Read only

Demirbilek
Explorer
0 Likes
1,217

Hi Caglar;

You have a condition (belnr NE i_belnr) in your SELECT statement which forces query optimizer to scan the whole table sequentially. You should change your logic in your program. If you can give more information, I'd be more helpful.

Regards;

Read only

0 Likes
1,217

Hi Hakan ,

I had to wrote this report with classes and had to search " (belnr NE i_belnr) " because the flow scenario of this report could only be solved as this , i mean while you are searching for a billing document if it is parked or not, and it is BSAD doc. number must not equal to its clearing number .

  • here there is a loop and it includes this method searching for BSAD as the criterions.

CALL METHOD odeme_oku

EXPORTING

i_augbl = lv_augbl

i_belnr = augbl

i_budat = lv_budat.

  • and in method odeme_oku there is the select statement

kind regards,

Caglar

Read only

0 Likes
1,217

Hi

Have you the billing document number?

Max

Read only

0 Likes
1,217

If you want to check whether the document has been cleared or not, you can check table BSID with same criteria and using "belnr EQ i_belnr". BSAD table is for cleared customer accounting documents while BSID is for open customer accounting documents. If you still want to use BSAD table, you already state that you don't want to get clearing document by stating "bsadbelnr NE bsadaugbl". So using "belnr EQ i_belnr" will boost performance as query optimizer will use the primary key of BSAD.

Hope this helps;

Read only

0 Likes
1,217

Thanks to all,

Because large amount of data , i think this problem can not be solved easily

Thanks again

Kind regards,

Caglar

Read only

0 Likes
1,217

Hi

It depends on what you really need to do?

Which documents you need to search?

The bills? Why don't you start from them?

If you don't need the payments, you only need to exclude the type document of payments, so you shouldn't check IF BELNR <> AUGBL.

Max

Read only

0 Likes
1,217

Hi Max,

I need the search the bills and the payments both and there is partial clearing of bills too. I need to check all of the bills if it is cleared or not, if cleared ; are there any items still remained and uncleared. this is a little part of scenario(this is where i stuck)

Kind regards,

Caglar

Read only

0 Likes
1,217

Hi

If you know the bill number:

-1) Search FI document:

  • Get header data

select * from bkpf where AWTYP = 'VBRK'

and AWKEY = BILL NUMBER.

EXIT.

ENDSELECT.

  • Get items data

SELECT * FROM BSEG INTO TABLE T_BSEG

WHERE BUKRS = BKPF-BUKRS

AND BELNR = BKPF-BELNR

AND GJAHR = BKPF-GJAHR

AND KOART = 'D'.

  • Payment:

LOOP AT T_BSEG WHERE AUGDT <> '00000000'.

IF T_BSEG-AUGBL <> _BKPF-BELNR

T_BSEG-AUGDT <> _BKPF-BUDAT.

SELECT * FROM BKPF INTO _BKPF

WHERE BUKRS = T_BSEG-BUKRS

AND BELNR = T_BSEG-AUGBL

AND BUDAT = T_BSEG-AUGDT.

EXIT.

ENDSELECT.

SELECT * FROM BSEG APPENDING TABLE T_PAYMENT

WHERE BUKRS = _BKPF-BUKRS

AND BELNR = _BKPF-BELNR

AND GJAHR = _BKPF-GJAHR

AND KOART = 'D'.

ENDIF.

ENDLOOP.

  • Partial payment

SELECT * FROM BSAD INTO TABLE WHERE BUKRS = BKPF-BUKRS

AND KUNNR = T_BSEG-KUNNR

AND REBZG = BKPF-BELNR

AND REBZJ = BKPF-GJAHR.

Max

Read only

0 Likes
1,217

Hi Max,

Sorry for misunderstood and thanks a lot for your attention , i tried to mean FI invoices as bills sorry,

This code is ok but fetching bseg is too risky for this case.

Thanks a lot again