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

Most optimized select query

Former Member
0 Likes
403

Hi friends ,

Please suggest most optimized code for the following scenerio , which fetches Billing Document , Company Code , and Address based on plant

There are two tables

1 . T001 (only 13 rows present in this) containing

a. Company Code - BUKRS

b. Address - ADRNR

2. BSEG (60000 rows present in this and 3000 rows per plant on avg. ) containing

a. Billing document - VBELN

b. Planning Date - FDTAG

c. Company Code - BUKRS

d. Plant - WERKS

3 REPLIES 3
Read only

Former Member
0 Likes
381

Hi Yogesh,

TRy this code:

Select bukrs, adrnr into table i_tab1 from t001.

if sy-subrc = 0.

Select vbeln bukrs werks into table i_tab2 from bseg

for all entries in i_tab1 where bukrs = i_tab1-bukrs.

endif.

Use these two internal tables after proper sorting to get your required output.

Regards,

Raj

Read only

Former Member
0 Likes
381

hi

secify the selection criteria

select bukrs werks adrnr from t001 into table itab_company

if sy-subrc is initial.

select bukrs belnr gjahr

into table itab

from bseg

for all entries in itab_company

where bukrs = itab_company-bukrs

and werks = itab_Company-werks

and.......anymore conditions

select name1 name2 from adrc into table itab_address

for all entries in itab_company

where adrnr = itab_company-adrnr

endif

Read only

Former Member
0 Likes
381

Hi,

As far as possible avoid retrieving data from BSEG as this is a cluster table, instead you can use the following according to your requirement,

1. To get Vendor account details,

Use: BSAK(Cleared)

BSIK(Open) you may have to append both the table entries in one internal table, using appending statement

2.To get G/L account details,

Use: BSAS(Cleared)

BSIS(Open)

3.To get Customer account details

Use: BSAD(Cleared)

BSIS(Open)

Hope this helps,

Rgds,