Application Development 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: 

BSAK link to BSIS and BSAS...

aris_hidalgo
Contributor
0 Kudos

Hello Experts,

I am doing 2 FOR ALL ENTRIES to get records from BSIS and BSAS based on the records

that I got in BSAK. Currently, I only know of 3 fields to link which is BUKRS, BELNR, AND GJAHR

but I is still any more fields that I can link to BSAK from BSIS and BSAS? Because we are

experiencing performance issues in my program. I am using index for the 3 tables but still it gives us

performance issues. Below is my code:


*   Get previous year
    lv_year = p_gjahr - 1.

*   Get records from PAYR
    SELECT zbukr vblnr gjahr lifnr zaldt
      FROM payr
      INTO TABLE gt_payr
     WHERE zbukr = p_bukrs
       AND gjahr IN (lv_year, p_gjahr).

    DELETE gt_payr WHERE zaldt+4(2) > p_monat.
    SORT gt_payr BY zbukr vblnr gjahr lifnr zaldt.
    DELETE ADJACENT DUPLICATES FROM gt_payr COMPARING zbukr vblnr gjahr lifnr zaldt.

    IF NOT gt_payr[] IS INITIAL.
*     Get records from BSAK
      SELECT bukrs blart gjahr monat belnr lifnr dmbtr shkzg
        FROM bsak
        INTO TABLE gt_bsak
         FOR ALL ENTRIES IN gt_payr
        WHERE lifnr = gt_payr-lifnr
          AND bukrs = gt_payr-zbukr
          AND augdt = gt_payr-zaldt
          AND augbl = gt_payr-vblnr
          AND gjahr = gt_payr-gjahr.
    ENDIF.

    DELETE gt_bsak WHERE monat > p_monat.
    DELETE gt_bsak WHERE shkzg <> 'H'.
    gt_payments[] = gt_bsak[].

    IF NOT gt_payments[] IS INITIAL.
*   Get records from BSIS(Open items)
    SELECT bukrs blart gjahr monat dmbtr hkont
      FROM bsis
      INTO TABLE gt_bsis
       FOR ALL ENTRIES IN gt_payments
     WHERE bukrs = gt_payments-bukrs
       AND belnr = gt_payments-belnr
       AND gjahr = gt_payments-gjahr
       AND blart IN (lc_su, lc_px).

*   Get records from BSAS(Cleared items)
    SELECT bukrs blart gjahr monat dmbtr hkont
      FROM bsas
      INTO TABLE gt_bsas
       FOR ALL ENTRIES IN gt_payments
     WHERE bukrs = gt_payments-bukrs
       AND belnr = gt_payments-belnr
       AND gjahr = gt_payments-gjahr
       AND blart IN (lc_su, lc_px).
    ENDIF.


Hope you can help me guys. Thank you and take care!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY

bsis

select MANDT

BUKRS

HKONT

AUGDT

AUGBL

ZUONR

GJAHR

BELNR

BUZEI

bsak

select MANDT

BUKRS

LIFNR

UMSKS

UMSKZ

AUGDT

AUGBL

ZUONR

GJAHR

BELNR

BUZEI

bsas

select MANDT

BUKRS

HKONT

AUGDT

AUGBL

ZUONR

GJAHR

BELNR

BUZEI

Message was edited by:

Karthikeyan Pandurangan

2 REPLIES 2

Former Member
0 Kudos

In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY

bsis

select MANDT

BUKRS

HKONT

AUGDT

AUGBL

ZUONR

GJAHR

BELNR

BUZEI

bsak

select MANDT

BUKRS

LIFNR

UMSKS

UMSKZ

AUGDT

AUGBL

ZUONR

GJAHR

BELNR

BUZEI

bsas

select MANDT

BUKRS

HKONT

AUGDT

AUGBL

ZUONR

GJAHR

BELNR

BUZEI

Message was edited by:

Karthikeyan Pandurangan

Former Member
0 Kudos

The relationship is via BSEG... BSAK, BSIK, BSAS, BSIS, BSAD, and BSID are really just operating as indexes to BSEG... so if you get a record from BSAK, use the company code, document number, and year to select the line items from BSEG (into an internal table is good)... then you will have all the data you need without needing to visit BSK, BSD, and BS*S again.

cheers

Jonathan