PO Service Line Item Quantity Exceed Validation Against PR Quantity - SAP Blogs
PO Service Line Item Quantity Exceed Validation Against PR Quantity - SAP Blogs
Community
Follow
Ask a Question
Write
Like a Blog Post Login
RSS Feed
Suresh Kutam
May 21, 2017 | 9 minute read
Scenario
Service PO creation / change scenario – Service Quantity increasing more than
requested in PR.
If we are creating PO with respective to RFQ, we can increase the any service line
item quantity whatever we wanted. There is no proper SAP validation exist in PO
for the POs which are created with reference to RFQ. This scenario is related to
only service POs.
Example,
1. Service line item keep the quantity as “100” for any line item (in this case
consider I have 2nd service line item quantity as “100”.
2. Release the PR.
3. Create RFQ with reference to PR and release RFQ.
4. Now create PO with reference to RFQ created in Step 3, where PR number
will be auto populated from RFQ. Now save the PO.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 1/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
Reason is actually quantity field is not updated in the PRs for the POs created
using RFQ. And its more complex as it deals with pack no and sub pack numbers.
For some of the business this is key validation as PR quantity must validate
during the PO creation.
Solution::-
Declarations -
TYPES:
lty_t_esll TYPE STANDARD TABLE OF esll WITH DEFAULT KEY.
TYPES:
*// To read PR details and its package number
BEGIN OF ty_eban,
banfn TYPE banfn,
bnfpo TYPE bnfpo,
bsart TYPE bbsrt,
loekz TYPE eloek,
packno TYPE packno,
END OF ty_eban,
BEGIN OF ty_esll,
packno TYPE packno,
introw TYPE numzeile,
srvpos TYPE asnum,
sub_packno TYPE sub_packno,
menge TYPE mengev,
END OF ty_esll,
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 2/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
*// To get all POs which are used this PR and line item
BEGIN OF ty_ekpo_val,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
loekz TYPE eloek,
banfn TYPE banfn,
bnfpo TYPE bnfpo,
packno TYPE packno,
END OF ty_ekpo_val.
FIELD-SYMBOLS:
<lfs_lw_esll_sub> TYPE esll.
DATA:
lv_err_flg TYPE char1,
lv_srv_nt_pr TYPE char1,
lv_curr_po_qty TYPE mengev,
lv_pr_qty TYPE mengev,
lv_bal_qty TYPE mengev,
lv_pr_qty_by TYPE mengev,
lv_bal_qtyc TYPE char20,
lv_pr_qty_byc TYPE char20,
lv_cur_ser_qtyc TYPE char20,
lv_exis_po_qty TYPE mengev,
lv_cur_ser_qty TYPE mengev,
lv_new_po_qty TYPE mengev,
lv_extrow TYPE extrow,
lv_ebelps TYPE ebelp,
lv_service TYPE asnum,
lt_ekpo_val TYPE STANDARD TABLE OF ty_ekpo_val INITIAL S
lw_ekpo_val TYPE ty_ekpo_val,
lt_items_tmp TYPE TABLE OF mepoitem,
lt_items_ser TYPE TABLE OF mepoitem,
lt_items_ser_tmp TYPE TABLE OF mepoitem,
lw_items_ser_tmp TYPE mepoitem,
lw_items_ser TYPE mepoitem,
ls_item TYPE meout_item,
lr_esll TYPE REF TO esll,
ls_srv TYPE if_mmbsi_gui_factory=>type_s_srv_key,
lt_esll_sub TYPE lty_t_esll,
lt_esll_loop TYPE lty_t_esll,
lw_esll_loop TYPE esll,
lt_esll TYPE lty_t_esll,
lw_eban TYPE ty_eban,
lt_eban TYPE STANDARD TABLE OF ty_eban INITIAL SIZE
lt_esll_pr TYPE STANDARD TABLE OF ty_esll INITIAL SIZE
lw_esll_pr TYPE ty_esll,
lw_esll_subpack TYPE ty_esll,
lt_esll_subpack TYPE STANDARD TABLE OF ty_esll INITIAL SIZE
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 3/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
IF re_mgr IS BOUND.
CALL METHOD re_mgr->get_current_item
RECEIVING
re_item = re_item.
ENDIF.
IF re_item IS BOUND.
CALL METHOD re_item->get_data
RECEIVING
re_data = re_data.
ENDIF.
ENDLOOP.
REFRESH:
lt_esll_curpac,
lt_esll_cursubp,
lt_eban,
lt_esll_pr,
lt_esll_subpack,
lt_ekpo_val,
lt_items_ser,
lt_items_tmp.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 4/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
*// Get unique PR and PR line item number to get all the POs,
*// which are already used these PR&PR line items
APPEND LINES OF lt_items_ser TO lt_items_tmp.
SORT lt_items_tmp BY banfn bnfpo.
DELETE ADJACENT DUPLICATES FROM lt_items_tmp
COMPARING banfn bnfpo.
*// Get the selected PRs and its line item details -> GET PACK num
*// under that PR line items
IF lt_items_tmp IS NOT INITIAL.
SELECT
banfn
bnfpo
bsart
loekz
packno
FROM eban
INTO TABLE lt_eban
FOR ALL ENTRIES IN lt_items_tmp
WHERE banfn = lt_items_tmp-banfn
AND bnfpo = lt_items_tmp-bnfpo.
IF sy-subrc IS INITIAL.
SORT lt_eban BY banfn bnfpo.
ENDIF.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 5/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
menge
FROM esll
INTO TABLE lt_esll_pr
FOR ALL ENTRIES IN lt_eban
WHERE packno EQ lt_eban-packno.
IF sy-subrc IS INITIAL.
SORT lt_esll_pr BY packno.
*// Get PR sub package number, where you will have activity/service
SELECT
packno
introw
srvpos
sub_packno
menge
FROM esll
INTO TABLE lt_esll_subpack
FOR ALL ENTRIES IN lt_esll_pr
WHERE packno EQ lt_esll_pr-sub_packno.
IF sy-subrc IS INITIAL.
SORT lt_esll_subpack BY sub_packno.
ENDIF.
ENDIF.
ENDIF.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 6/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
SELECT
packno
introw
srvpos
sub_packno
menge
FROM esll
INTO TABLE lt_esll_popack
FOR ALL ENTRIES IN lt_ekpo_val
WHERE packno EQ lt_ekpo_val-packno.
IF sy-subrc IS INITIAL.
*// Get PO line item sub pack number
SELECT
packno
introw
srvpos
sub_packno
menge
FROM esll
INTO TABLE lt_esll_posubp
FOR ALL ENTRIES IN lt_esll_popack
WHERE packno EQ lt_esll_popack-sub_packno.
IF sy-subrc IS INITIAL.
SORT lt_esll_posubp BY sub_packno.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
******************************************************
*// Read current PO line item services details
******************************************************
*// Take unique PR and line items to process the validation
REFRESH:
lt_items_ser_tmp.
CLEAR:
lv_err_flg,
lw_items_ser_tmp,
wa_items_final.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 7/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
CLEAR:
wa_items_final.
REFRESH:
lt_esll_cursubp.
REFRESH:
lt_esll_loop,
lt_esll.
REFRESH:
lt_esll_sub.
APPEND LINES OF lt_esll_cursubp TO lt_esll_sub.
***********************/******************************
*// PO loaded data..
*// Check each service line qty - in case if the service line is re
*// take the consolidated qty to compare PR qty
***********************/******************************
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 8/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
CLEAR:
lw_esll_loop.
*// loop only current line item services to compare the values
LOOP AT lt_esll_loop INTO lw_esll_loop
WHERE srvpos IS NOT INITIAL.
UNASSIGN:
<lfs_lw_esll_sub>.
CLEAR:
lv_curr_po_qty,
lv_pr_qty,
lv_cur_ser_qty,
lv_exis_po_qty,
lv_ebelps,
lv_extrow,
lv_service.
lv_cur_ser_qty = lw_esll_loop-menge.
*// Service line item total qty in current PO
LOOP AT lt_esll_cursubp INTO lw_esll_cursubp
WHERE srvpos = <lfs_lw_esll_sub>-srvpos.
*// Get Service qty till the current line for accurate results on e
IF lw_esll_cursubp-introw > lw_esll_loop-introw.
EXIT.
ENDIF.
lv_curr_po_qty = lw_esll_cursubp-menge + lv_curr_
ENDLOOP.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 9/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
IF lv_srv_nt_pr IS INITIAL.
CLEAR:
lv_message,
lv_message1.
lv_err_flg = abap_true.
CONCATENATE
'For line item' lv_ebelps
'service line' lv_extrow
'/' lv_service '-'
INTO
lv_message SEPARATED BY space.
ELSE.
*// service line item qty in existing/already created POs
CLEAR:
lw_ekpo_val.
LOOP AT lt_ekpo_val INTO lw_ekpo_val
WHERE banfn = wa_items_final-banfn
AND bnfpo = wa_items_final-bnfpo.
CLEAR:
lw_esll_popack.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 10/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
INTO lw_esll_popack
WITH KEY packno = lw_ekpo_val-packno.
IF sy-subrc IS INITIAL.
LOOP AT lt_esll_posubp INTO lw_esll_posubp
WHERE packno = lw_esll_popack-sub_packno
AND srvpos = <lfs_lw_esll_sub>-srvpos.
lv_exis_po_qty = lv_exis_po_qty + lw_esll_
ENDLOOP.
ENDIF.
ENDLOOP. "service line item qty in existing/al
CLEAR:
lv_new_po_qty.
CLEAR:
lv_message,
lv_message1,
lv_bal_qty,
lv_pr_qty_by,
lv_bal_qtyc,
lv_cur_ser_qtyc,
lv_pr_qty_byc,
lv_message2,
lv_message3.
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 11/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
CONCATENATE
'For line item' lv_ebelps
'service line' lv_extrow
'/' lv_service '-'
INTO
lv_message SEPARATED BY space.
CONCATENATE
'Quantity exceeds by' lv_pr_qty_byc
INTO
lv_message1 SEPARATED BY space.
CONCATENATE
'for entered quantity'
lv_cur_ser_qtyc
INTO
lv_message2 SEPARATED BY space.
CONCATENATE
'as balance PR Qty is'
lv_bal_qtyc
INTO
lv_message3 SEPARATED BY space.
Thanks,
Suresh Kutam
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 12/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
ABAP Development
ABAP Connectivity
ABAP Extensibility
MM (Materials Management)
View more...
Developer Extensibility - Embedded Steampunk: Extend PR App using released BADI in S/4 HANA Cloud
By Mohammed Aymen Sep 20, 2022
Related Questions
Updating New QTY at saving of PR in ME51n and saving PO in ME21n
By Former Member Aug 19, 2013
validation on PO save.
By Former Member Oct 05, 2015
2 Comments
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 13/14
3/6/23, 12:36 PM PO Service line item quantity exceed validation against PR quantity… | SAP Blogs
Former Member
May 22, 2017 at 7:20 am
Was looking for this solution for quite some time. Thanks
Like 0 | Share
Avik Mazumder
August 28, 2017 at 5:59 am
Nice document steps. Since you have adopted for customized ABAP solution, can you please also look into
the possibility of alternate approach -
setting the complete status of your PR to "2" from the PO conversion during ME21n - doc category = 'A'.
This way, the same PR item cannot be reference more than once if the full qty had been received.
Regards
Avik
Like 0 | Share
Find us on
Newsletter Support
https://blogs.sap.com/2017/05/21/po-service-line-item-quantity-exceed-validation-against-pr-quantity.../ 14/14