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

select from bseg

Former Member
0 Likes
4,623

Hi

In my report I have as follow:

 
select * from bsid 
into corresponding fields of table tt_bsid 
where kunnr eq i_kunnr. 

select * from bseg 
into corresponding fields of table tt_bseg 
for all entries in tt_bsid 
where bukrs = tt_bsid-bukrs and 
gjahr = tt_bsid-gjahr and 
rebzg = tt_bsid-rebzg. 

but the second select (select from bseg....) run some minutes.

Do you have any idea, in which way prepare correctly the select?

thx in advance and best regards

JS

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,983

hi,

hi Basically u should not use BSEG tables for selection utill u know the primary keys values .....

As bseg table stores all the information it takes several minitues to execute...

there are some views for bseg table

bsis,bsas,bsid,bsad,bsik,bask

find out which will be useful for u and use it.

ur program berformance will increase..

regards,

priya

13 REPLIES 13
Read only

Former Member
0 Likes
2,983

Hi John,

There is no proble with the select statement ( from bseg ).

Normally for selecting data from tables like BSEG , MSEG etc will take so much time.

Regards,

Raja.K

Read only

Former Member
0 Likes
2,983

hi,

Sort tt_bsid with primary keys before second select statement and select only required fields instead of "*'.

If you are selecting only few fields thn use select into table instead of into corresponding fields of table, but order of fields should be proper.

Hope it helps.

Regards,

Siddhesh S.Tawate

Read only

Former Member
0 Likes
2,983

Try this way..

DATA: tt_bsid like bsid occurs 0 with header line,

tt_bseg like bseg occurs 0 with header line.

select * from bsid

into table tt_bsid

where kunnr eq i_kunnr.

SORT tt_bsid

by bukrs

gjahr

rebzg

buzei.

select * from bseg

into table tt_bseg

for all entries in tt_bsid

where bukrs = tt_bsid-bukrs and

gjahr = tt_bsid-gjahr and

rebzg = tt_bsid-rebzg AND

buzei = tt_bsid-buzei.

OR make a INNER JOIN... with the 2 tables

Edited by: heber rodarte on Apr 14, 2008 9:02 AM

Read only

former_member194669
Active Contributor
0 Likes
2,983

While selecting from BSEG (Cluster tables) you need to use proper key for the select. If you check the BSEG primary keys BUKRS

BELNR GJAHR BUZEI. Here you not using full key for the selection,

There are several index tables - bsis,bsas,bsad,bsik,bsak. Each contains a different subset of columns from table bseg.

a®

Read only

Former Member
0 Likes
2,983

Hi

Specify the field names from bseg table

and use below select

select BUKRS BELNR GJAHR BUZEI from BSEG

into table it_bseg

for all entries in tt_bsid

where BUKRS eq tt_bsid-bukrs

and BELNR eq tt_bsid-belnr

and GJAHR eq tt_bsid-gjahr

and BUZEI eq tt_bsid-BUZEI.

Use delete statement on it_bseg for unwanted records

Read only

ThomasZloch
Active Contributor
0 Likes
2,983

Hi John,

please include BSID-BELNR in the BSEG Select. Check also that tt_bsid is not empty beforehand.

Cheers

Thomas

Read only

Former Member
0 Likes
2,984

hi,

hi Basically u should not use BSEG tables for selection utill u know the primary keys values .....

As bseg table stores all the information it takes several minitues to execute...

there are some views for bseg table

bsis,bsas,bsid,bsad,bsik,bask

find out which will be useful for u and use it.

ur program berformance will increase..

regards,

priya

Read only

Former Member
0 Likes
2,983

Hi,

BSEG is a cluster table, it will have huge data. You need to use all the key fields of BSEG table. Instead of selecting all the fields like * you have choose required fields only for both BSID and BSEG.

You change code as below for retrieving the data from BSEG table.


select <required fields> from bseg 
into table tt_bseg 
for all entries in tt_bsid 
where bukrs = tt_bsid-bukrs and 
belnr =  tt_bsid-belnr and
gjahr = tt_bsid-gjahr and 
buzei = tt_bsid-buzei and
rebzg = tt_bsid-rebzg. 

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
2,983

thanx for your help

but kindly please note, I can't use belnr in the select because I need for one record form bsid some records from bseg with diferenses value in belnr. I can't use gjahr in the select too because one doc from bseg can be in 2007 and second document from bseg can be in 2008 year.

thx in advance

JS

Read only

0 Likes
2,983

strange, because one record from BSID points to exactly one record from BSEG. Sorry, I don't understand the underlying logic and thus cannot help further.

Read only

0 Likes
2,983

H Thomas

you are right

bsid-belnr = bseg-belnr results only one record from bseg

but bsid-rebzg = bseg-rebzg results some records from bseg.

thx

JS

Read only

Former Member
0 Likes
2,983

So long as you are looking at customer and/or vendor invoices only, there is a secondary index on REBZG in BSID, BSAD, BSIK and BSAK. You should go against those tables instead. You should also add the company code to all of your SELECTs.

Rob

Read only

Former Member
0 Likes
2,983

Take a look at this weblog...

[Quickly Retrieving FI document Data from BSEG|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/7692] [original link is broken] [original link is broken] [original link is broken];

Greetings,

Blag.