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: 

Is it possible to get sum of BSIS-dmbtr and add it to sum of BSAS-dmbtr?

bsarcia19
Discoverer
0 Kudos
1,050



Tables: BSIS, BSAS
Required fields - DBMBTR

9 REPLIES 9

AlexGourdet
Product and Topic Expert
Product and Topic Expert
0 Kudos
785

Thank you for visiting SAP Community to get answers to your questions.

Since you're asking a question here for the first time, I'd like to recommend you with the following steps so you can get the most out of your community membership:

I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

All the best,
-Alex

lenapadeken
Product and Topic Expert
Product and Topic Expert
785

Hi bsarcia19,

One solution might be:

SUM( bsis~dmbtr ) + SUM( bsas~dmbtr ) AS total_amount

Best regards,

Lena

0 Kudos
785

Thank you

former_member9115
Participant
0 Kudos
785

Hi,

Refer if this simple example may help you.

Data :  LV_AMT1 type DMBTR.<br>
SELECT  A~belnr as a_belnr , 
        B~belnr as b_belnr ,
        A~gjahr as a_yr    , 
        B~gjahr as b_yr    , 
        A~dmbtr as a_amt   , 
        B~dmbtr as b_amt
INTO TABLE @DATA(IT_BS)
FROM BSIS AS A
INNER JOIN BSAS  AS B ON A~BELNR = B~BELNR AND A~GJAHR = B~GJAHR.  


LOOP AT IT_BS ASSIGNING FIELD-SYMBOL(<LFS_BS>).
  IF <LFS_BS>-A_BELNR = <LFS_BS>-B_BELNR AND <LFS_BS>-A_YR = <LFS_BS>-B_YR .
    LV_AMT1 =  LV_AMT1 + <LFS_BS>-A_AMT +  <LFS_BS>-B_AMT.
  ENDIF.
ENDLOOP.

Write : LV_AMT1.

0 Kudos
785

Thank you

anujawani2426
Active Participant
0 Kudos
785

Hi,

types:
begin of ty_bsis,
bukrs type bukrs,
dmbtr type dmbtr,
END OF ty_bsis.
data:
it_bsis type table of ty_bsis,
wa_bsis type ty_bsis.
select
a~bukrs,
sum( a~dmbtr ) + sum( b~dmbtr ) as total
from bsis_view as a
INNER JOIN bsas_view as b
on a~bukrs = b~bukrs
group by a~bukrs
into table @it_bsis.
if sy-subrc eq 0.
loop at it_bsis into wa_bsis.
write:/ wa_bsis-bukrs,
wa_bsis-dmbtr.
ENDLOOP.
ENDIF.

Regards,

Anuja Kawadiwale

0 Kudos
785

Thank you ❤

former_member808116
Participant
0 Kudos
785

Hope this helps you.

DATA : LV_TOTAL TYPE DMBTR,
LV_A LIKE LV_TOTAL,
LV_B LIKE LV_TOTAL.
SELECT A~BUKRS AS BUKRS,
A~DMBTR AS A_AMT,
B~DMBTR AS B_AMT
FROM BSIS AS A
INNER JOIN BSAS AS B ON A~BUKRS = B~BUKRS AND
A~HKONT = B~HKONT AND
A~AUGDT = B~AUGDT AND
A~ZUONR = B~ZUONR AND
A~BELNR = B~BELNR AND
A~GJAHR = B~GJAHR AND
A~BUZEI = B~BUZEI
INTO TABLE @DATA(IT_AB).

SORT IT_AB BY BUKRS ASCENDING.

LOOP AT IT_AB INTO DATA(WA_AB).

LV_A = LV_A + WA_AB-A_AMT.
LV_B = LV_B + WA_AB-B_AMT.

AT END OF BUKRS.
LV_TOTAL = LV_A + LV_B.
WRITE / LV_TOTAL.
CLEAR: LV_A, LV_B, LV_TOTAL.
ENDAT.

CLEAR: WA_AB.
ENDLOOP.

raymond_giuseppi
Active Contributor
0 Kudos
785

You could look at the UNION option of the SELECT statement in the latest versions.

Otherwise, be careful with the cardinality of a JOIN between BSIS and BSAS, if several items are cleared or not in the same document, or if there are only cleared, resp. non cleared, items...