Search code examples
sqlamazon-redshiftsap-erp

Link EKPO-EBELP and G/L accounts


I want to know which order position (EBELP from EKPO in SAP MM) appear in which G/L account (HKONT in BSEG in SAP FI with koart = 'S').

I'm working with SQL queries on a redshift database which has the tables copied from SAP.


Solution

  • Okay, so I found an answer after a couple of days looking through forums and SAP tables column by column... since I am mainly interested in connecting order positions to G/L accounts, I was able to find them in EKKN which is directly linkable to EKPO. For some ebelp there are multiple sakto which is why we need "vproz" to be able to divide the EKPO-NETWR into the different sakto.

    Going through all of it also made me shift my question from linking EKPO and BSEG to linking EKPO-EBELP and the G/L accounts. The BSEG-HKONT (with filter to BSEG-KOART = 'S') are also in EKKN-SAKTO.

    SELECT ebeln, ebelp, netwr, sakto, vproz, vproz * netwr / 100 AS sakto_netwr
    FROM ekpo
    LEFT JOIN (
              SELECT
              mandt
              ,ebeln
              ,ebelp
              ,sakto
              ,SUM(vproz) as vproz
              FROM ekkn
              GROUP BY mandt, ebeln, ebelp, sakto
              )
              ekkn ON ekkn.mandt = ekpo.mandt AND ekkn.ebeln = ekpo.ebeln AND ekkn.ebelp = ekpo.ebelp