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: 

reg table relation BSIK and BSAK to EKKO and EKPO tables

Former Member
0 Kudos

hi all,

can u plz let me know how to relate BSIK and BSAK with the corresponding POs??

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Try this:


  SELECT belnr gjahr
    FROM ekbe
    INTO TABLE ekbe_int
    UP TO 100 ROWS
    WHERE ebeln = ebeln
    AND vgabe IN ('1', '2').                      "1 - GR, 2 - IR

  CHECK sy-subrc = 0.

  SORT ekbe_int.
  DELETE ADJACENT DUPLICATES FROM ekbe_int.

  LOOP AT ekbe_int INTO ekbe_wa.
    v_objectkey+00(10) = ekbe_wa-belnr.
    v_objectkey+10(10) = ekbe_wa-gjahr.           "BELNR+YEAR

    IF ekbe_wa-vgabe = '1'.
      v_reference = 'MKPF'.
    ELSE.
      v_reference = 'RMRP'.
    ENDIF.

* Uses index BKPF~4 (4.7)
    SELECT SINGLE bukrs belnr gjahr               "Accounting Doc Header
      FROM bkpf
      INTO doc_int
      WHERE awtyp =  v_reference
        AND awkey =  v_objectkey.
    IF sy-subrc = 0.
      APPEND doc_int.
    ENDIF.
  ENDLOOP.

This will give you the document header. You can easily get anything else you need from BSEG.

Rob

2 REPLIES 2

raymond_giuseppi
Active Contributor
0 Kudos

There was an OSS note on this subject, since purchase invoice allow multiple purchase order in a single invoice this data is no longer written in vendor item (BSEG) of the financial document. So you need to read the other items of the document (general ledger) to get the purchase order(s) linked. Another way could be via table EKBE order history which has the BELNR field too.

(<a href="https://service.sap.com/sap/support/notes/152335">Note 152335 - Field EBELN in line layout variant for cust./vendor</a>)

Regards

Former Member
0 Kudos

Try this:


  SELECT belnr gjahr
    FROM ekbe
    INTO TABLE ekbe_int
    UP TO 100 ROWS
    WHERE ebeln = ebeln
    AND vgabe IN ('1', '2').                      "1 - GR, 2 - IR

  CHECK sy-subrc = 0.

  SORT ekbe_int.
  DELETE ADJACENT DUPLICATES FROM ekbe_int.

  LOOP AT ekbe_int INTO ekbe_wa.
    v_objectkey+00(10) = ekbe_wa-belnr.
    v_objectkey+10(10) = ekbe_wa-gjahr.           "BELNR+YEAR

    IF ekbe_wa-vgabe = '1'.
      v_reference = 'MKPF'.
    ELSE.
      v_reference = 'RMRP'.
    ENDIF.

* Uses index BKPF~4 (4.7)
    SELECT SINGLE bukrs belnr gjahr               "Accounting Doc Header
      FROM bkpf
      INTO doc_int
      WHERE awtyp =  v_reference
        AND awkey =  v_objectkey.
    IF sy-subrc = 0.
      APPEND doc_int.
    ENDIF.
  ENDLOOP.

This will give you the document header. You can easily get anything else you need from BSEG.

Rob