Skip to Content
0

bapi_pr_change set delivery date as current date

Dec 12, 2016 at 10:15 AM

204

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Evgeniy Astafev Dec 20, 2016 at 09:15 AM
1

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).

Share
10 |10000 characters needed characters left characters exceeded
Dan Kennedy Dec 12, 2016 at 08:02 PM
0

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'.
Show 6 Share
10 |10000 characters needed characters left characters exceeded

I meant if I fill pritem-deliv_date I also set pritemx-deliv_date = 'X'. And if I dont fill pritem-deliv_date, pritemx-deliv_date = ' '.

At first try I changed only material by bapi. Then I found that delivery date was changed. I read date from position and fill the variable. But date was set for today again.

So I just cant change delivery date with that bapi.

0

Can you copy the rest of your code for me so i can see how exactly you populate your tables. Thanks

0

I dont think it will help but here it is:

* i_table - table with documents from EBAN for update
* transfer_to_extensionin just fill structure for Z fields.
* fill_x_table  fill fields for update (i.e. if pritem-matnr is not initial then pritemx-matnr will be set to 'X' )

LOOP AT i_table INTO DATA(ls_table) GROUP BY ( banfn = ls_table-banfn ) ASSIGNING FIELD-SYMBOL(<group>).
  LOOP AT GROUP <group> ASSIGNING FIELD-SYMBOL(<ls_group>).
    APPEND VALUE #( preq_item = <ls_group>-bnfpo MATERIAL = new_matnr SHORT_TEXT = l_maktx )
      TO pritem.
    CLEAR ls_extensionin.
    me->transfer_to_extensionin( EXPORTING is_bapi_extensionin = VALUE bapi_te_mereqitem( preq_item = <ls_group>-bnfpo zzmatnr = <ls_group>-matnr )
                                 CHANGING cs_bapiparex = ls_extensionin ).
    APPEND ls_extensionin TO EXTENSIONIN.
    CLEAR ls_extensionin.
    me->transfer_to_extensionin( EXPORTING is_bapi_extensionin = VALUE bapi_te_mereqitemx( preq_item = <ls_group>-bnfpo zzmatnr = 'X' )
                                 CHANGING cs_bapiparex = ls_extensionin ).
    APPEND ls_extensionin TO EXTENSIONIN.
  ENDLOOP.

  me->fill_x_table( EXPORTING table = pritem CHANGING tablex = pritemx ).
  CALL FUNCTION 'BAPI_PR_CHANGE'
    EXPORTING
      number                       = <group>-banfn
   TABLES
     RETURN                       = RETURN
     PRITEM                       = PRITEM
     PRITEMX                      = PRITEMX
     EXTENSIONIN                  = EXTENSIONIN
     .
  READ TABLE return with key type = 'E' TRANSPORTING NO FIELDS.
  IF sy-subrc = 0.
    CALL FUNCTION 'RSCRMBW_DISPLAY_BAPIRET2'
      TABLES
        it_return       = return
              .
    RETURN.
  ENDIF.
  ENDLOOP.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.



0

This is a stab in the dark as we dont have any PR's in our implementation.

  • Can you please debug and check the values of PRITEMX after "me->fill_x_table( EXPORTING table = pritem CHANGING tablex = pritemx )." just before your BAPI call - to confirm that APPEND VALUE # isn't doing anything weird like adding blanks for the undefined columns. A blank will default to system date during processing. (If that is the case try explicitly clearing the deliv_date and deliv_datex fields, or explicitly setting them where appropriate)
  • If that is ok then if you could check your return table directly in the debugger but do not just check for type 'E', there could be information type in there that could prove useful for your troubleshooting.

You might also have to do some reading on how Purchase Requisitions interact with their subsequent purchase orders, and the material master which may be configured for delivery date. Good luck

0

> try explicitly clearing the deliv_date and deliv_datex fields, or explicitly setting them where appropriate

Already tried.

I recently got access to a different system and tested bapi - I had no problems with delivery date. So it can be some customer code that I cant find :(

0

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( ).
0