cancel
Showing results for 
Search instead for 
Did you mean: 

ME52N closed document going in editable mode BAPI_REQUISITION_DELETE

11-26-2024 2:23 PM
vieet Explorer
887 views 1 comments
0 Likes
SAP Managed Tags
Labels
"Best Practice"ABAP 7.4BAPISAP ABAP
Subscribe

Hi gurus, The query is why the user is able to make changes once the PR is in closed status ?
User is expecting to get the delete indicator and closed indicator to be checked for the PR
created 45 days.

There is custom program and BAPI_REQUISITION_DELETE is used to delete and close the items.
The following is the code ::

 data lv_date1 type datum.
  data lv_date2 type datum.

  call function 'RP_CALC_DATE_IN_INTERVAL'
    exporting
      date      = sy-datum
      days      = '46'
      months    = '00'
      signum    = '-'
      years     = '00'
    importing
      calc_date = lv_date1.

  call function 'RP_CALC_DATE_IN_INTERVAL'
    exporting
      date      = sy-datum
      days      = '00'
      months    = '06'
      signum    = '-'
      years     = '00'
    importing
      calc_date = lv_date2.


  if lv_date1 is not initial.
    select banfn, bnfpo from eban
      into table @DATA(lt_eban)
      where badat le @LV_date1
      and   frgkz IN ('C', 'D')
      and loekz NE 'X'.
  endif.

*  if lv_date2 is not initial.
*    select banfn, bnfpo from eban
*      appending table @LT_eban
*      where badat le @LV_date2
*      and   frgkz = 'A'
*      and   statu = 'N'.
*  endif.


  if lt_eban is not initial.

    data lt_items type table of bapieband.
    data ls_items type bapieband.
    data(lt_head) = lt_eban[].
    data lt_ret type table of bapireturn.
    data ls_log type zmm_pr_del_log.

    sort lt_head by banfn.
    delete adjacent duplicates from lt_head comparing all fields.

    loop at lt_head into data(ls_head).
      refresh lt_items[].
      refresh lt_ret[].

      loop at lt_eban into data(ls_eban) where banfn = ls_head-banfn.
        ls_items-preq_item = ls_eban-bnfpo.
        ls_items-delete_ind = 'X'.
        ls_items-closed     = 'X'.    "PASHA 17/10/2024
        append ls_items to lt_items.
        clear ls_items.
      endloop.

      call function 'BAPI_REQUISITION_DELETE'
        exporting
          number                      = ls_head-banfn
        tables
          requisition_items_to_delete = lt_items
          return                      = lt_ret.

      read table lt_ret into data(ls_ret) with key type = 'E'.
      if sy-subrc = 0.
        ls_log-banfn = ls_head-banfn.
        loop at lt_items into ls_items.
          ls_log-bnfpo = ls_items-preq_item.
          ls_log-message = ls_ret-message.
          ls_log-zdate = sy-datum.
          ls_log-uzeit = sy-uzeit.
          ls_log-uname = sy-uname.
          ls_log-status = 'E'.
          modify zmm_pr_del_log from ls_log.
        endloop.
        clear ls_log.
      else.
        ls_log-banfn = ls_head-banfn.
        loop at lt_items into ls_items.
          ls_log-bnfpo = ls_items-preq_item.
          ls_log-message = ls_ret-message.
          ls_log-zdate = sy-datum.
          ls_log-uzeit = sy-uzeit.
          ls_log-uname = sy-uname.
          ls_log-status = 'S'.
          modify zmm_pr_del_log from ls_log.
        endloop.
        clear ls_log.
      endif.


    endloop.

  endif.

I have observed two scenarios at me52n once this code gets executed.

for EBAN-ESTKG (PRODUCTION ORDER(F)) it is giving me the expected result which is not editable after
running the above code.

vieet_0-1732625603457.png

However ,

For all other scenarios other than production order it is going in editable mode after running through the same above code like below

vieet_1-1732622342348.png

Strange thing is that in the first scenario closed is not ticked but it was non editable , in the second one closed is ticked but i can able to undelete and make changes.


My question is why it is working fine in PRODUCTION ORDER case but not in other cases though
the code is same.

The requirement is once the code is executed it should be non editable for all documents based on the select query in the code.

Is it that needs to be fixed from functional end or is it SAP's glitch as it is making
item number editable after the PR is closed.

Thank in advance for your replies

 

0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

HenrikeGroetecke
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello,

Thank you very much for your question and sorry for the late reply.

Can you please check whether the following information (GenAI was used to help generate this content) solves your issue?

The behavior you are experiencing with the Purchase Requisition (PR) being editable even after being marked as closed can be attributed to the standard system design and the specific conditions under which the PRs are processed.

Production Order Scenario Purchase Order change output is generated even if the PURCHASINGDOCUMENTDELETIONCODE is disable.

In the case of PRs related to production orders, the system might have additional checks or settings that prevent editing once the PR is marked as closed. This could be due to specific configurations or business rules that apply to production-related documents.

Other Scenarios Issues and recommendation related to Workflow for …

For other types of PRs, even if the ‘closed’ indicator is set, the system might allow editing due to different configurations or lack of specific restrictions that apply to production orders. This behavior is consistent with the standard SAP system design where certain fields or indicators might not prevent editing unless explicitly configured.

Possible Solutions

  1. Functional Configuration: Check if there are specific configurations or business rules that need to be applied to non-production order PRs to prevent editing once closed.
  2. SAP System Design: It might be necessary to review SAP’s standard behavior and see if any custom logic or additional settings can be implemented to achieve the desired non-editable state for all PRs.

Recommendations

  • Consult with your SAP functional consultant to review the configurations related to PRs and ensure that the necessary settings are applied to prevent editing.
  • Consider implementing additional checks or custom logic in the BAPI or related processes to enforce non-editability for closed PRs across all scenarios.

Images

 
HenrikeGrtecke_2-1757076778555.png
 

Kind regards,

Henrike