Users feel that it is too troublesome to transfer planned orders to purchase requisitions one by one through MD14. Although MD15 can be batched, it also needs to be confirmed one by one.
When business consultants can’t convince users to check out standard features, the pressure is on technology.
After research, the function MD_PLANNED_ORDER_2_REQUISITION can fully simulate MD14, but I don’t know about the personalization.
After a series of verifications, the function is finally fine-tuned to solve the problem perfectly. (Note, since the source code is directly changed, please operate with caution and make a backup to prevent data abnormalities after the upgrade)
1. Comment out the original enhancement: FSH_PP_SFC_SFWS_PLO_2PR_2
2. Retain the standard enhanced logic, and then add your own logic
Below is the code to call the function, for reference only.
* &------------------------------------------- --------------------------* * & Form FRM_CONVERT_TO_PR * &---------------------------------------------- -----------------------* * & text * &---------------------------------------------- -----------------------* * & amp; --> p1 text * & amp; <-- p2 text * &---------------------------------------------- -----------------------* FORM frm_convert_to_pr. DATA lv_tabix TYPE i. DATA: ls_plaf1 TYPE plaf, ls_mdba1 TYPE mdba, ls_cm61o TYPE cm61o, ls_plaf2 TYPE plaf, ls_mdba2 TYPE mdba. "Check Select lines or not READ TABLE gt_alv INTO gs_alv WITH KEY sel = 'X'. IF sy-subrc <> 0. MESSAGE 'At least one line selected' TYPE 'S' DISPLAY LIKE 'E'. RETURN. ENDIF. LOOP AT gt_alv ASSIGNING <fs_alv> WHERE sel = 'X'. CLEAR:<fs_alv>-message,<fs_alv>-status. "If processed, do not convert IF <fs_alv>-ebeln IS NOT INITIAL. CONTINUE. ENDIF. IF <fs_alv>-ekgrp IS INITIAL. <fs_alv>-status = icon_red_light. <fs_alv>-message = 'Purchase group is required'. ENDIF. IF <fs_alv>-gsmng IS INITIAL. <fs_alv>-status = icon_red_light. IF <fs_alv>-message IS INITIAL. <fs_alv>-message = 'Required quantity is required'. ELSE. <fs_alv>-message = |{ <fs_alv>-message };Required quantity is required|. ENDIF. ENDIF. IF <fs_alv>-zpsttr IS INITIAL. <fs_alv>-status = icon_red_light. IF <fs_alv>-message IS INITIAL. <fs_alv>-message = 'Required date is required'. ELSE. <fs_alv>-message = |{ <fs_alv>-message }; required date required|. ENDIF. ENDIF. IF <fs_alv>-status = icon_red_light. CONTINUE. ENDIF. "Get planned order information CLEAR: ls_plaf1. SELECT SINGLE * INTO ls_plaf1 FROM plaf WHERE plnum = <fs_alv>-plnum. ls_plaf1-flief = <fs_alv>-flief." Provider ls_plaf1-konnr = <fs_alv>-konnr." Purchase agreement number ls_plaf1-ktpnr = <fs_alv>-ktpnr." Purchase agreement number line item ls_plaf1-ekorg = p_ekorg." Purchasing Organization "Set the PR field CLEAR: ls_mdba1. ls_mdba1-fixkz = 'X' . ls_mdba1-bsart = 'NB'. * ls_mdba1-pstyp = <fs_item>-pstyp. ls_mdba1-knttp = ls_plaf1-knttp. ls_mdba1-ekorg = p_ekorg." Purchasing Organization * ls_mdba1-ekorg = ls_plaf1-ekorg." Purchasing Organization ls_mdba1-flief = ls_plaf1-flief." fixed provider ls_mdba1-ekgrp = <fs_alv>-ekgrp. ls_mdba1-werks = <fs_alv>-pwwrk. ls_mdba1-lgort = <fs_alv>-lgort. ls_mdba1-lfdat = <fs_alv>-zpsttr. ls_mdba1-dispo = ls_plaf1-dispo. ls_mdba1-menge = <fs_alv>-gsmng. ls_mdba1-meins = <fs_alv>-meins. ls_mdba1-repos = 'X'." Receipt ID ls_mdba1-wepos = 'X'."Invoice receipt identification "Common workspace for planned order functions CLEAR: ls_cm61o. ls_cm61o-trtyp = 'V'."Change ls_cm61o-lockx = 'X'."Lock planned order ls_cm61o-autho = 'X'."Authority check durchfuehren ls_cm61o-stpre = 'V'."VC = change but no save ls_cm61o-wtpst = 'X'."Wait for time stamp TL: P4DK111222 ls_cm61o-darkx = 'I'." Warning skipped ls_cm61o-nodia = 'X'."No Dialog screen(BkGrnd) ls_cm61o-xcode = 'PCONV'." function code CLEAR: ls_plaf2, ls_mdba2. CALL FUNCTION 'MD_PLANNED_ORDER_2_REQUISITION' EXPORTING plaf1 = ls_plaf1 mdba1 = ls_mdba1 cm61o = ls_cm61o * MANYORDERS = ' ' * FINDSOURCE = XFLAG IMPORTING plaf2 = ls_plaf2 mdba2 = ls_mdba2 * NO_NEXT_ORDER = EXCEPTIONS error = 1 OTHERS = 2. IF ls_mdba2-bannr IS NOT INITIAL. <fs_alv>-sel = ''. <fs_alv>-ebeln = ls_mdba2-bannr. <fs_alv>-status = icon_green_light. <fs_alv>-message = 'Conversion successful'. "Update Request Tracking Number PERFORM frm_update_pr USING ls_mdba2-bannr <fs_alv>-lgort. ELSE. <fs_alv>-status = icon_red_light. <fs_alv>-message = 'Conversion failed'. ENDIF. ENDLOOP. ENDFORM.
In addition, there is no requirement tracking number information in the new PR, if necessary, update the PR separately.
* &------------------------------------------- --------------------------* * & Form FRM_UPDATE_PR * &---------------------------------------------- -----------------------* * & text * &---------------------------------------------- -----------------------* * & --> LS_MDBA2_BANNR * & amp; --> <FS_ALV>_LGORT * &---------------------------------------------- -----------------------* FORM frm_update_pr USING pv_bannr TYPE eban-banfn pv_lgort. DATA: lt_eban TYPE TABLE OF eban, ls_eban TYPE eban. DATA: wa_return TYPE bapiret2, wa_pritem TYPE bapimereqitemimp, wa_pritemx TYPE bapimereqitemx, lt_return TYPE TABLE OF bapiret2, lt_pritem TYPE TABLE OF bapimereqitemimp, lt_pritemx TYPE TABLE OF bapimereqitemx. DATA : lv_mess TYPE string. "Check PR exist or not CLEAR: lt_eban. DO 10 TIMES. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_eban FROM eban WHERE banfn = pv_bannr. IF lt_eban IS NOT INITIAL. EXIT. ELSE. WAIT UP TO 1 SECONDS. ENDIF. ENDDO. IF lt_eban IS NOT INITIAL. LOOP AT lt_eban INTO ls_eban. CLEAR: wa_pritem. wa_pritem-preq_item = ls_eban-bnfpo. wa_pritem-trackingno = pv_lgort. APPEND wa_pritem TO lt_pritem. CLEAR: wa_pritemx. wa_pritemx-preq_item = ls_eban-bnfpo. wa_pritemx-trackingno = 'X'. APPEND wa_pritemx TO lt_pritemx. ENDLOOP. CLEAR: lt_return. CALL FUNCTION 'BAPI_PR_CHANGE' EXPORTING number = pv_bannr TABLES return = lt_return primem = lt_pritem primemx = lt_pritemx. READ TABLE lt_return INTO wa_return WITH KEY type = 'E'. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. ENDIF. ENDFORM.