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

Bseg Table Issue

Former Member
0 Likes
965

Hi,

Below is my code, it taking much time to get the data from BSEG table and even after executing for long time it not populating the data into internal table. If i pass single account in selection screen, it is displaying the data.

Please help me out.

SELECT hkont lkorr FROM t030hb INTO CORRESPONDING FIELDS OF

TABLE gt_tr_t030hb

WHERE ktopl = 'ZCOA'

AND bwber = 'TR'

and hkont in so_hkont.

IF gp_pprct IS INITIAL.

loop at gt_tr_t030hb.

SELECT hkont prctr bewar dmbe2 FROM bseg INTO CORRESPONDING

FIELDS OF table gt_hkont for all entries

in gt_tr_t030hb

WHERE bukrs IN so_bukrs

AND prctr IN so_prctr

AND saknr = gt_tr_t030hb-hkont

AND vbund IN so_vbund

and gjahr in so_gjahr

and xauto = 'X'.

Thanks,

Pavan.

Message was edited by: Pavan Panduru

7 REPLIES 7
Read only

Former Member
0 Likes
807

Hi Pavan.

SELECT hkont lkorr FROM t030hb <b>INTO CORRESPONDING FIELDS</b> OF TABLE gt_tr_t030hb reduces the performance

WHERE ktopl = 'KCOA'

AND bwber = 'TR'

and hkont in so_hkont.

<b>IF gp_pprct IS NOT INITIAL.</b>

loop at gt_tr_t030hb.

SELECT hkont prctr bewar dmbe2 FROM bseg <b>INTO CORRESPONDING

FIELDS</b> OF table gt_hkont for all entries

in gt_tr_t030hb

WHERE bukrs IN so_bukrs

AND prctr IN so_prctr

AND saknr = gt_tr_t030hb-hkont

AND vbund IN so_vbund

and gjahr in so_gjahr

and xauto = 'X'.

Instead of the above code u check the below code:

FORM F_MOVE_RECORDS.

LOOP AT <SELECTED INTERNAL TABLE NAME> INTO <SELECTED WORK AREA>.

READ <SELECTED INTERNAL TABLE NAME> INTO <SELECTED WORK AREA> WITH KEY ...

IF SY-SUBRC EQ 0.

MOVE <SELECTED WORK AREA FIELDS> TO <OUTPUT WORK AREA FIELDS>.

APPEND <OUTPUT WORK AREA> TO <OUTPUT INTERNAL TABLE NAME>.

ENDIF.

CLEAR: <SELECTED WORK AREA>, <OUTPUT WORK AREA>.

ENDLOOP.

ENDFORM. " F_MOVE_RECORDS

Read only

0 Likes
807

HI,

I didnot get where should I use the your given code?

Thanks,

Pavan.

Read only

Former Member
0 Likes
807

Hi

SELECT hkont lkorr FROM t030hb INTO CORRESPONDING FIELDS OF

TABLE gt_tr_t030hb

WHERE ktopl = 'ZCOA'

AND bwber = 'TR'

and hkont in so_hkont.

IF gp_pprct IS INITIAL.

You don't need to do a LOOP in you use FOR ALL ENTRIES option:

<b>*loop at gt_tr_t030hb.</b>

BUKRS and GJAHR are field key of BSEG do you should place at the top of WHERE condition

SELECT hkont prctr bewar dmbe2 FROM bseg INTO CORRESPONDING

FIELDS OF table gt_hkont for all entries

in gt_tr_t030hb

<b>WHERE bukrs IN so_bukrs

and gjahr in so_gjahr</b>

AND prctr IN so_prctr

AND saknr = gt_tr_t030hb-hkont

AND vbund IN so_vbund.

If you define gt_hkont in this way:

DATA: BEGIN OF GT_HKONT,

hkont

prctr

bewar

dmbe2

.............

END OF GT_HKONT.

You can use INTO TABLE instead of INTO CORRESPONDING

<b>SELECT hkont prctr bewar dmbe2 FROM bseg INTO table</b> gt_hkont for all entries

in gt_tr_t030hb

<b>WHERE bukrs IN so_bukrs

and gjahr in so_gjahr</b>

AND prctr IN so_prctr

AND saknr = gt_tr_t030hb-hkont

AND vbund IN so_vbund

and xauto = 'X'.

If you need to read G/L accounting item it's better to read BSIS/BSAS table instead of BSEG.

Max

Read only

0 Likes
807

Hi,

If I have to read the gl accounts, dmbe2 and prctr from bseg instead of bseg how to refer to BSIS/BSAS.

Can u give me the code,

Thanks,

Pavan.

Read only

0 Likes
807

Hi,

I chnaged the code as you mentioned still it is taking time.

Please let me know how to resolve this?

Thanks,

Pavan.

Read only

0 Likes
807

Hi,

- never access BSEG records directly without fully specified key GJAHR BUKRS BELNR.

First get the key values from secondary index tables as there are:

BSAD Accounting- Secondary Index for Customers (Cleared Items)

BSAK Accounting- Secondary Index for Vendors (Cleared Items)

BSAS Accounting- Secondary Index for G/L Accounts (Cleared Items)

BSEC One-Time Account Data Document Segment

BSID Accounting- Secondary Index for Customers

BSIK Accounting- Secondary Index for Vendors

BSIM Secondary Index, Documents for Material

BSIS Accounting- Secondary Index for G/L Accounts

The statement about performance reduction using INTO CORRESPONDING FIELDS is a widely-believed but never prooved urban legend. INTO CORRESPONDING FIELDS is evaluated once per database access and translated into ligtning-fast moves. It will ensure that the result is always correct.

You may significantly gain performance selecting only the field you really need.

Regards,

Clemens

Read only

0 Likes
807

Hi

Try to select the items from BSIS/BSAS:

- One solution can be:

TABLES: BSIS.

DATA: GT_TR_T030HB LIKE STANDARD TABLE OF T030HB.

SELECT-OPTIONS: SO_BUKRS FOR BSIS-BUKRS,

SO_HKONT FOR BSIS-HKONT,

SO_GJAHR FOR BSIS-GJAHR,

SO_PRCTR FOR BSIS-PRCTR,

SO_VBUND FOR BSIS-VBUND.

DATA: BEGIN OF GT_HKONT OCCURS 0,

BUKRS LIKE BSIS-BUKRS,

HKONT LIKE BSIS-HKONT,

GJAHR LIKE BSIS-GJAHR,

BELNR LIKE BSIS-BELNR,

BUZEI LIKE BSIS-BUZEI,

PRCTR LIKE BSIS-PRCTR,

BEWAR LIKE BSIS-BEWAR,

DMBE2 LIKE BSIS-DMBE2,

END OF GT_HKONT.

DATA: XAUTO.

SELECT * FROM T030HB INTO TABLE GT_TR_T030HB

WHERE HKONT IN SO_HKONT

.......................................

  • Open Items (BSIS)

SELECT BUKRS HKONT GJAHR BELNR BUZEI

PRCTR BEWAR DMBE2

FROM BSIS INTO TABLE GT_HKONT

FOR ALL ENTRIES IN GT_TR_T030HB

WHERE BUKRS IN SO_BUKRS

AND HKONT = GT_TR_T030HB-HKONT

AND GJAHR IN SO_GJAHR

AND PRCTR IN SO_PRCTR

AND VBUND IN SO_VBUND.

  • Cleared items

SELECT BUKRS HKONT GJAHR BELNR BUZEI

PRCTR BEWAR DMBE2

FROM BSAS APPENDING TABLE GT_HKONT

FOR ALL ENTRIES IN GT_TR_T030HB

WHERE BUKRS IN SO_BUKRS

AND HKONT = GT_TR_T030HB-HKONT

AND GJAHR IN SO_GJAHR

AND PRCTR IN SO_PRCTR

AND VBUND IN SO_VBUND.

  • If you need to check if the item is automatically loaded:

LOOP AT GT_HKONT.

SELECT SINGLE XAUTO FROM BSEG INTO XAUTO

WHERE BUKRS = GT_HKONT-BUKRS

AND BELNR = GT_HKONT-BELNR

AND GJAHR = GT_HKONT-GJAHR

AND BUZEI = GT_HKONT-BUZEI.

IF XAUTO = SPACE.

DELETE GT_HKONT.

ENDIF.

ENDLOOP.

Other solution can be

TABLES: BSIS.

DATA: GT_TR_T030HB LIKE STANDARD TABLE OF T030HB.

SELECT-OPTIONS: SO_BUKRS FOR BSIS-BUKRS,

SO_HKONT FOR BSIS-HKONT,

SO_GJAHR FOR BSIS-GJAHR,

SO_PRCTR FOR BSIS-PRCTR,

SO_VBUND FOR BSIS-VBUND.

DATA: BEGIN OF T_DOCUMENT OCCURS 0,

BUKRS LIKE BSIS-BUKRS,

GJAHR LIKE BSIS-GJAHR,

BELNR LIKE BSIS-BELNR,

BUZEI LIKE BSIS-BUZEI,

END OF T_DOCUMENT.

DATA: BEGIN OF GT_HKONT OCCURS 0,

HKONT LIKE BSIS-HKONT,

PRCTR LIKE BSIS-PRCTR,

BEWAR LIKE BSIS-BEWAR,

DMBE2 LIKE BSIS-DMBE2,

END OF GT_HKONT.

DATA: XAUTO.

  • Open Items (BSIS)

SELECT BUKRS GJAHR BELNR BUZEI

FROM BSIS INTO TABLE T_DOCUMENT

FOR ALL ENTRIES IN GT_TR_T030HB

WHERE BUKRS IN SO_BUKRS

AND HKONT = GT_TR_T030HB-HKONT

AND GJAHR IN SO_GJAHR

AND PRCTR IN SO_PRCTR

AND VBUND IN SO_VBUND.

  • Cleared items

SELECT BUKRS GJAHR BELNR BUZEI

FROM BSAS INTO TABLE T_DOCUMENT

FOR ALL ENTRIES IN GT_TR_T030HB

WHERE BUKRS IN SO_BUKRS

AND HKONT = GT_TR_T030HB-HKONT

AND GJAHR IN SO_GJAHR

AND PRCTR IN SO_PRCTR

AND VBUND IN SO_VBUND.

  • Auto items

SELECT HKONT PRCTR BEWAR DMBE2

FROM BSEG INTO TABLE GT_HKONT

FOR ALL ENTRIES IN T_DOCUMENT

WHERE BUKRS = T_DOCUMENT-BUKRS

AND BELNR = T_DOCUMENT-BELNR

AND GJAHR = T_DOCUMENT-GJAHR

AND BUZEI = T_DOCUMENT-BUZEI

AND XAUTO = 'X'.

Try

Max