cancel
Showing results for 
Search instead for 
Did you mean: 

How to Read BSEG Efficiently

Former Member
0 Kudos

Hi all,

As BSEG is a cluster table . how to read this table Efficiently . Is there any FM as such in ABAP HR.

Thanks

Senthil

View Entire Topic
pkirylcz
Explorer
0 Kudos

Hi,

this method: READ_BSEG has nothing more than select * from BSEG with WHERE (primary key) statement therefore I do not recomend to use that method.

Much better is to receive the data from another table, for example BSIS - if you need only G/L Accounts.

Then you can ask once again BSEG with primary keys if some fields are missing.

I just tested few sql-statements on the Quality System and I would like to share results:

1. Select in first flow the BSIS table to find the actuals accounts (I used the selection screen to fill in the input data):

TYPES: BEGIN OF doc,

          bukrs TYPE bsis-bukrs,

          belnr TYPE bsis-belnr,

          gjahr TYPE bsis-gjahr,

          buzei TYPE bsis-buzei,

        END   OF doc.

DATA: doc_int  TYPE TABLE OF doc.

  SELECT bukrs belnr gjahr buzei

    FROM bsis

    INTO TABLE doc_int

    WHERE bukrs in s_bukrs

      AND hkont in s_hkont

      AND gjahr in s_gjahr.

2. Select additionally BSEG if you need some other fields like MATNR which is not in BSIS.

You have 2 possibilities:

*****&1 - select with for all entries

form get_bseg.

  check doc_int is not INITIAL.

  SELECT bukrs belnr gjahr buzei

      FROM bseg

      INTO TABLE gt_bseg_sel

    FOR ALL ENTRIES IN doc_int

      WHERE bukrs = doc_int-bukrs

        AND belnr = doc_int-belnr

        AND gjahr = doc_int-gjahr

        and buzei = doc_int-buzei.

endform. 

*******&2 - Select in LOOP!!!! - Why? .... I'll explain you soon.

form get_bseg_loop.

  DATA: ls_bseg_sel like line of doc_int.

  FIELD-SYMBOLS: <fs_doc_int> like line of doc_int.

  CHECK doc_int is not INITIAL.

  LOOP AT doc_int ASSIGNING <fs_doc_int>.

    SELECT single bukrs belnr gjahr buzei

      FROM bseg

      INTO ls_bseg_sel

      WHERE bukrs = <fs_doc_int>-bukrs

        AND belnr = <fs_doc_int>-belnr

        AND gjahr = <fs_doc_int>-gjahr

        and buzei = <fs_doc_int>-buzei.

    append ls_bseg_sel to gt_bseg_sel.

  ENDLOOP.

endform.                    "get_bseg

And now the results:

Program check routine

Bsis time:                                 18.358.456

BSEG Time for all entries      387.986.642

BSEG Time with loop              34.930.089

No of lines:                                   210.438

As you can see, Select statement in LOOP is much much much more efficient than for all entries.