Skip to Content

According to SAP Note 493900 Q3 reset of the release strategy for purchase order only takes place if CEKKO-GNETW is higher than the old one or CEKKO-GNETW fall off a lower interval if there is no tolerance limit maintained.

Here is how it is done besides of the standard; copy Badi “ME_PURCHDOC_POSTED” and in the method code as follows;

DATA: LINE_EKPO TYPE I ,
LINE_EKPO_OLD TYPE I ,
EKPO_CHANGED TYPE C LENGTH 1,
LS_EKPO_OLD TYPE UEKPO,
LS_EKPO TYPE UEKPO.

CLEAR EKPO_CHANGED.
LOOP AT IM_EKPO INTO LS_EKPO.
LOOP AT IM_EKPO_OLD INTO LS_EKPO_OLD WHERE EBELP = LS_EKPO-EBELP.
IF LS_EKPO-NETWR NE LS_EKPO_OLD-NETWR OR
LS_EKPO-MENGE NE LS_EKPO_OLD-MENGE .
EKPO_CHANGED = ‘X’.
ENDIF.
ENDLOOP.
ENDLOOP.

DESCRIBE TABLE IM_EKPO     LINES LINE_EKPO .
DESCRIBE TABLE IM_EKPO_OLD LINES LINE_EKPO_OLD .

FIELD-SYMBOLS: <LF_REL_CODE> TYPE BAPIMMPARA-REL_CODE.
DATA :
REL_STATUS_NEW TYPE BAPIMMPARA-REL_STATUS,
REL_INDICATOR_NEW TYPE BAPIMMPARA-PO_REL_IND,
RETURN TYPE TABLE OF BAPIRETURN .

DATA: LS_RETURN          TYPE BAPIRETURN,
LT_BAPIRETURN      TYPE TABLE OF BAPIRETURN,
LS_RELEASE_INFO    TYPE BAPIRLGNPO,
LS_RELEASE_POSTED  TYPE BAPIRLCOPO,
LF_COMP_NUM        TYPE I,
LF_STRING          TYPE STRING,
LF_ERROR           TYPE FLAG,
LV_UNAME           TYPE SY-UNAME.

*if quantity or net price is changed

( IM_EKKO_OLD-FRGSX EQ IM_EKKO-FRGSX AND
EKPO_CHANGED      EQ  ‘X’ AND
IM_EKKO_OLD-EBELN IS NOT INITIAL ) .

IF IM_EKKO-FRGZU     = IM_EKKO_OLD-FRGZU .

CALL FUNCTION ‘ZMM_PO_RESET_RELEASE’
EXPORTING
IM_EKKO       = IM_EKKO
.
ENDIF.
ENDIF.

ENDIF.

Function ZMM_PO_RESET_RELEASE contains;

FIELD-SYMBOLS: <LF_REL_CODE> TYPE BAPIMMPARA-REL_CODE.
DATA :
REL_STATUS_NEW TYPE BAPIMMPARA-REL_STATUS,
REL_INDICATOR_NEW TYPE BAPIMMPARA-PO_REL_IND,
RETURN TYPE TABLE OF BAPIRETURN .

DATA: LS_RETURN          TYPE BAPIRETURN,
LT_BAPIRETURN      TYPE TABLE OF BAPIRETURN,
LS_RELEASE_INFO    TYPE BAPIRLGNPO,
LS_RELEASE_POSTED  TYPE BAPIRLCOPO,
LF_COMP_NUM        TYPE I,
LF_STRING          TYPE STRING,
LF_ERROR           TYPE FLAG,

CALL FUNCTION ‘BAPI_PO_GETRELINFO’
EXPORTING
PURCHASEORDER          = IM_EKKO-EBELN
IMPORTING
GENERAL_RELEASE_INFO   = LS_RELEASE_INFO
RELEASE_ALREADY_POSTED = LS_RELEASE_POSTED
TABLES
RETURN                 = LT_BAPIRETURN.

LF_COMP_NUM = 2.

DO 8 TIMES.
ASSIGN COMPONENT LF_COMP_NUM OF STRUCTURE LS_RELEASE_POSTED
TO <LF_REL_CODE>.

IF <LF_REL_CODE> IS NOT INITIAL.

CALL FUNCTION ‘BAPI_PO_RESET_RELEASE’
EXPORTING
PURCHASEORDER     = IM_EKKO-EBELN
PO_REL_CODE       = <LF_REL_CODE>
USE_EXCEPTIONS    = SPACE
IMPORTING
REL_STATUS_NEW    = REL_STATUS_NEW
REL_INDICATOR_NEW = REL_INDICATOR_NEW
TABLES
RETURN            = RETURN.
LOOP AT RETURN INTO ls_return WHERE TYPE = ‘E’ OR TYPE = ‘A’ .
EXIT.
ENDLOOP.
IF SY-SUBRC NE 0 .
WAIT UP TO 3 SECONDS.
ENDIF.
ENDIF.

LF_COMP_NUM = LF_COMP_NUM – 1.

ENDDO.
ENDFUNCTION.

Regards

Melih

P.S. You may need to copy and change BAPI_PO_RESET_RELEASE if you do not want to stuck with standard authority checks.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. yarden jacobson

    Hi , Great article.

    From my experience – customers tend to ask for updates and more fields for this solution.

    i.e. – after deploying this solution the customer suddenly remember that new request is critical – make field “EKPO-TXZ01” sensitive to changes ( reset release strategy ).

    In current solution – you should update this hard coded.

     

    My suggestion is to transfer all fields to customizing table , this could make solution scalable and customizable .

    The solution include two parts :

     

    Customizing table which include two fields :

      1. Table name ( DE TABNAME).
      2. Field name (DE FIELDNAME).

         This table holds all fields to be checked for change.

      Changes check with dynamic data :

       

      This code will get field list from DB and compare two structures field by field ( from DB field list ).

       

      So, for our example let’s call DB TABLE ZMM_CHANGE_SF ( change sensitive field ).

       

      And there are 4 records :

       

      EKPO TXZ01

      EKPO NETWR

      EKPO MENGE

      EKKO EKGRP

      This code will check changes in EKPO :



      data: lt_fields type table of ZMM_CHANGE_SF.
      clear ekpo_change.

      fieldsymbols:     <fs_fields>   like line of lt_fields,
                                  <fs_ekpo_new>
      like line of UEKPO

                                  <fs_ekpo_old>      like line of UEKPO,
                                  <fs_new>     
      type any,
                                  <fs_old>     
      type any.
       
      select *
         
      from ZMM_CHANGE_SF
         
      into table lt_fields
         
      where tabname = ‘EKPO’.
       
      check sysubrc = 0.
       
      loop at lt_fields assigning <fs_fields>.
         
      check ekpo_change is initial.
         
      loop at  IM_EKPO assigning <fs_ekpo_new> .

      read table IM_EKPO_OLD assigning <fs_ekpo_old>
                 
      with key ebelp = <fs_ekpo_new>ebelp.
           
      if sysubrc <> 0.
              ekpo_change
      = ‘X’.
           
      else.
             
      if ekpo_change is initial.
               
      assign component <fs_fields>fieldname of structure <fs_ekpo_old> to <fs_old>.
               
      check <fs_old> is assigned.
               
      assign component <fs_fields>fieldname of structure <fs_ekpo_new> to <fs_new>.
               
      check <fs_new> is assigned.
               
      if <fs_old> <> <fs_new>.
                  ekpo_change
      = ‘X’.
               
      endif.
                unassign
      : <fs_old><fs_new>.
              endif.
           
      endif.
         
      endloop.
       
      endloop.

        

      and EKKO changes should be easy …

       

        data: lt_fields type table of zmm_change_sf
        clear ekko_change.

        fieldsymbols: <fs_fields> like line of lt_fields,
                               <fs_new>    type any,
                               <fs_old>    type any.

        select *
          from zmm_change_sf
          into table lt_fields
          where tabname = ‘EKKO’.
        check sysubrc = 0.

        loop at lt_fields assigning <fs_fields>.
          if ekko_change is initial.
            assign component <fs_fields>fieldname of structure im_ekko_old to <fs_old>.
            check <fs_old> is assigned.
            assign component <fs_fields>fieldname of structure im_ekko to <fs_new>.
            check <fs_new> is assigned.
            if <fs_old> <> <fs_new>.
              ekko_change= ‘X’.
            endif.
            unassign: <fs_old><fs_new>.
         endif.
        endloop.

      (0) 
      1. Grzegorz Skorus

        Calling BAPI_PO_RESET_RELEASE from ME_PURCHDOC_POSTED BAdI will of course cancel release but I am pretty sure that all changes made to the document eg. in the ME33K (if one wants to cancel contract release) transaction will be lost which makes this solution just partially useful.

        (0) 

    Leave a Reply