Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to update EKPO-LOEKZ for multiple level release in PO

Hi friends,

After running my code i found that those PO's which are released at 2nd and 3rd level are not getting updated . SELECT ebeln

frgzu      
                         frgke                
             bedat                     
        FROM ekko
        INTO TABLE i_ekko
        WHERE  ebeln IN  so_po
        AND   bedat IN  so_date
        and   frgzu EQ 'X'
        AND   frgke EQ 'R'.
  LOOP AT i_ekko.

    IF i_ekko-frgzu = ' '.
      DELETE i_ekko.
    ENDIF.
  ENDLOOP.



  IF sy-subrc EQ 0.

    IF NOT i_ekko[] IS INITIAL.
      SELECT ebeln                      
             ebelp     
             lewed        
                
             elikz                        
             loekz                       
             FROM ekpo
             INTO TABLE i_ekpo
             FOR ALL ENTRIES IN i_ekko
             WHERE ebeln EQ i_ekko-ebeln.

      IF sy-subrc NE 0.
        WRITE : ' Item not found'.
      ENDIF.


      DELETE i_ekpo WHERE lewed GT sy-datum OR lewed EQ 0 OR elikz EQ
      'X'
      OR loekz EQ 'L' OR loekz EQ 'S'.

      SORT i_ekpo BY ebeln ebelp.

      LOOP AT i_ekpo  .
        AT NEW ebeln.
          CLEAR : i_item,
                  i_itemx,
                  i_ekpo.
          REFRESH : i_itemx,i_item.
        ENDAT.

        i_item-po_item = i_ekpo-ebelp.
        i_item-no_more_gr = 'X'.
        APPEND i_item.

        i_itemx-po_item = i_ekpo-ebelp.
        i_itemx-po_itemx = 'X'.
        i_itemx-no_more_gr = 'X'. 
        l_ebeln = i_ekpo-ebeln.
        APPEND i_itemx.


        AT END OF ebeln.
          CALL FUNCTION 'BAPI_PO_CHANGE'
            EXPORTING
              purchaseorder = l_ebeln
            TABLES
              return        = i_return
              poitem        = i_item[]
              poitemx       = i_itemx[].

          LOOP AT i_return WHERE type = 'A' OR type = 'E'.
            EXIT.
          ENDLOOP.

          IF sy-subrc NE 0.
            WRITE: l_ebeln.
            COMMIT WORK.
          ENDIF.
        ENDAT.
      ENDLOOP.

    ENDIF.
  ELSE.
    WRITE : / ' PO is not found'.
  ENDIF.

Regards,

SAURAV LAHIRY

Former Member
Not what you were looking for? View more on this topic or Ask a question