10 Replies Latest reply: May 22, 2014 9:45 AM by Piotr Kirylczuk RSS

How to Read BSEG Efficiently

senthil bala
Currently Being Moderated

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

  • Re: How to Read BSEG Efficiently
    ERWAN LE BRUN
    Currently Being Moderated

    The more efficient is to fill the key.

     

    In fact, I think one of the better way to access BSEG is :

     

    - First try to do a selection in BKPF  ( into table t_bkpf eg : with GJAHR, )

    - And then to "select" from BSEG ( using the 'for all entries' statement ) for all entries in t_bkpf where ....

     

    Hope this helps.

     

    Erwan.

    • Re: How to Read BSEG Efficiently
      Shehryar Khan
      Currently Being Moderated

      Usually, index usage makes access faster. This means that rather than querying cluster table BSEG, select data from tables like BSAS, BSIS, BSAK, BSIK, BSAD, and BSID, etc by issuing a join on the required tables and making sure that an index is used. Otherwise, you could also use logical databases like SDF, KDF, BRM, etc. The LDB programs are optimized for accessing data, though that is subjective to the level of data your require.

       

      Regards

       

      Shehryar

  • Re: How to Read BSEG Efficiently
    Shravan Kodam
    Currently Being Moderated

    Hi

    better approach is to use the index loop on the header table

    and the item internal table which contains bseg data

    like below

     

    loop at itab1

     

    loop at itab-bseg from index

    if the key fields = itab1-keyfields

    then do the process

    if the key fields ne itab1-keyfields

    index = sy-tabix

    exit

    endloop

     

    i feel this is the better approach and better performance

     

    regards

    shravan

  • Re: How to Read BSEG Efficiently
    Homiar Kalwachwala
    Currently Being Moderated

    Hello Senthil,

     

    The most efficient process would depend upon your application & requirement. However there are some FMs such as :

    READ_BSEG

    GET_ALL_BSEG

     

    Regards,

    Homiar.

  • Re: How to Read BSEG Efficiently
    Jason DeLuca
    Currently Being Moderated

    I use inner joins and select from bsik and bsak.

    • Re: How to Read BSEG Efficiently
      Rishi Joseph
      Currently Being Moderated

      Careful with the BS<b>I</b>K and BS<b>A</b>K. These are for Vendor (Accounts Payable) documents only, as BS<b>I</b>D and BS<b>A</b>D is for Customer (Accounts Recievable) lines.

       

      Use BS<b>I</b>S and BS<b>A</b>S for all GL lines.

       

      <b>I</b> Stands for Open Items

      <b>A</b> Stands for Cleared Items

       

      Rishi

      • Re: How to Read BSEG Efficiently
        Jason DeLuca
        Currently Being Moderated

        Rishi,

         

        Thank you for clarifying.  I failed to mention that using BSIK and BSAK are appropriate in my individual case, but may not be appropriate for others' requirements.  I really meant to say that accessing the individual tables seems to work best for me. The inner joins are to other tables, not between BSIK/BSAK.

         

        Regards,

        Jason

  • Re: How to Read BSEG Efficiently
    Kshitij Devre
    Currently Being Moderated

    Hi, because you referred to something in HR ABap, there is similarity between BSEG and payroll clusters. As you know, BSEG is a cluster table and should have a table cluster with it. It is RFBLG. As you would do reading a RT cluster from PCL1 table cluster -- fill up the key and pass that key to the "import" statement to read from PCL1 table cluster which inturn would read (using the index it creates) RT(RU) cluster for say USA. Same way fill up the key and use the 'Import" statement on RFBLG(BSEG).

     

    Just another take on reading BSEG!!!

  • Re: How to Read BSEG Efficiently
    Srikanth Inja
    Currently Being Moderated

    AS BSEG is cluster table, BSEG Table consists of data from BSIS, BSAS, BSID, BSAD, BSIK, and BSAK tables.

    BSIS: G/L Open Items

    BSAS: G/L Closed Items

    BSID: Customer Open Items(Account Receivables)

    BSAD: Customer Closed Items)(Account Receivables)

    BSIK: Vendor Open Items(Account Payables)

    BSAK: Vendor Closed Items(Account Payables)

     

    It is better to retrieve data from above tables based up on the data(vendor,customer,G/L account).Otherwise it will give performance issue if u use BSEG in production and may give run time error. So please use above tables to avoid run time error in Production.

  • Re: How to Read BSEG Efficiently
    KALLA TOUFIK
    Currently Being Moderated

    Hi

    Use the function ABAP: READ_BSEG

    Regards,

  • Re: How to Read BSEG Efficiently
    Piotr Kirylczuk
    Currently Being Moderated

    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.

Actions