Skip to Content

bapi_pr_change set delivery date as current date

Hi all. When I update document with bapi_pr_change it sets delivery date for updated item for today but I need to save date that was set when document created.

pritemx-preq_item = pritem-preq_item = '10'.

pritem-material = '123'.

pritemx-material = 'X'.

pritem-deliv_date is empty or any date. pritemx-deliv_date also set.

    CALL FUNCTION 'BAPI_PR_CHANGE'
      EXPORTING
        number                       = number
     TABLES
       RETURN                       = RETURN
       PRITEM                       = PRITEM
       PRITEMX                      = PRITEMX
       EXTENSIONIN                  = EXTENSIONIN
       .

I checked badi and user-exits but didnt found anything. Any hints?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 20, 2016 at 09:15 AM

    I found it...

    LMEREQF15, CLASS lcl_r_lfdat:


    IF l_context->item_before_checks->item-matnr IS NOT INITIAL AND l_context->req_item->my_persistent_eban-matnr NE l_context->item_new->item-matnr AND l_context->item_before_checks->item-matnr NE l_context->item_new->item-matnr. l_lfdat = calculate_delivery_date( im_context = l_context ). ENDIF.

    So, if we changed material, delivery date will be recalculated.

    https://launchpad.support.sap.com/#/notes/1871265

    Will call bapi twice (for material and for date).

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 12, 2016 at 08:02 PM

    You say that 'pritemx-deliv_date also set'. Which indicates that you have set it as 'X'.

    Please make sure that it is empty/not set.

    Marking it as X indicates you want to update that field, and as you are not providing a value i assume it is taking the system data (sy-datum).

    If that was just a typo, and instead 'pritemx-deliv_date is not set, then what you should do is get the purchase requisition item details that you are updating (use bapi_pr_getdetail), and read the item data into a variable that you then populate before you call bapi_pr_change.

    pritem-deliv_date = lv_date_variable. "delivery date we get from item from original requisition
    pritemx-deliv_date = 'X'.
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Evgeniy Astafev

      There are multiple enhancement spots within BAPI_PR_CHANGE so i would go take a look at those first. Then check the rest of the function module.

      * set item data
        lr_bapi->set_items( im_items     = pritem[]    im_itemsx   = pritemx[] ).

      This method is in Include L2105I01. Can you debug in there and check the 'my_bapi_items' structure to see the deliv_date in there ?

      After that the 'process' method also calls the 'badi_in' method during some inbound checks.

      * start processing
        CALL METHOD lr_bapi->process( ).
      METHOD badi_in.
      *  define local field
          DATA: lr_badi_ibs  TYPE REF TO me_bapi_pr_ibs,
                no_customer_badi TYPE mmpur_bool VALUE cl_mmpur_constants=>no.
      *  contine only for asynchronous API
          CHECK me->my_actyp NE if_bapi_mereq~anz.
      *  do not continue in case of IF_PURCHASE_REQ_BAPI is used
          CHECK me->my_ext_ref IS INITIAL.
      *  INBOUND mapping BAdI for BAPI_PR_CREATE and BAPI_PR_CHANGE
          GET BADI lr_badi_ibs.
          CALL BADI lr_badi_ibs->inbound
            EXPORTING
              im_aktyp              = me->my_actyp
            CHANGING
              ch_testrun            = me->my_testrun
              ch_itemtext           = me->my_bapi_itemtext
              ch_return             = me->my_bapi_return
              ch_extensionin        = me->my_bapi_ext_in
              ch_headertext         = me->my_bapi_headtext
              <strong>ch_item               = me->my_bapi_items</strong>
              ch_itemx              = me->my_bapi_itemsx
              ch_addrdelivery       = me->my_bapi_delivery
              ch_account            = me->my_bapi_account
              ch_accountx           = me->my_bapi_accountx
              ch_profitsegment      = me->my_bapi_profit
              ch_header             = me->my_bapi_header
              ch_headerx            = me->my_bapi_headerx
              ch_version            = me->my_bapi_version
              ch_versionx           = me->my_bapi_versionx
              ch_components         = me->my_bapi_component
              ch_componentsx        = me->my_bapi_componentx
              ch_serialnumber       = me->my_bapi_serialno
              ch_serialnumberx      = me->my_bapi_serialnox
              cust_badi_not_allowed = no_customer_badi.
      *  inbound mapping customer BAdI
          CHECK no_customer_badi EQ cl_mmpur_constants=>no.
          CALL FUNCTION 'MEREQBADI_BAPI'
            EXPORTING
              im_vorga         = 'IN'
              im_aktyp         = me->my_actyp
            CHANGING
              ch_testrun       = me->my_testrun
              ch_itemtext      = me->my_bapi_itemtext
              ch_return        = me->my_bapi_return
              ch_extensionin   = me->my_bapi_ext_in
              ch_headertext    = me->my_bapi_headtext
              <strong>ch_item          = me->my_bapi_items</strong>
              ch_itemx         = me->my_bapi_itemsx
              ch_addrdelivery  = me->my_bapi_delivery
              ch_account       = me->my_bapi_account
              ch_accountx      = me->my_bapi_accountx
              ch_profitsegment = me->my_bapi_profit
              ch_header        = me->my_bapi_header
              ch_headerx       = me->my_bapi_headerx
              ch_version       = me->my_bapi_version
              ch_versionx      = me->my_bapi_versionx
              ch_components    = me->my_bapi_component
              ch_componentsx   = me->my_bapi_componentx
              ch_serialnumber  = me->my_bapi_serialno
              ch_serialnumberx = me->my_bapi_serialnox
            EXCEPTIONS
              OTHERS           = 1.
          CHECK sy-subrc EQ 1. "customer message
          mmpur_message_forced sy-msgty sy-msgid sy-msgno sy-msgv1
                               sy-msgv2 sy-msgv3 sy-msgv4.
        ENDMETHOD.                    "badi_in
      

      Check the deliv_date after both of these calls as well.

      Then do the same in the outbound methods

      * get item data
       <strong> pritemexp[]</strong>      = lr_bapi->get_items_exp( ).