Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Requirement:

Purchase Requisition to be blocked by checking the ABGRU(Reason for rejection of quotations and sales
orders) in VBAP and AUGRU(Order reason (reason for the business transaction)) in VBAK tables and then
block the document to be posted .

BADI - ME_REQ_POSTED
Method POSTED

Code:
IF sy-tcode EQ 'ME51N'.
DATA: im_wa_ebkn LIKE LINE OF im_ebkn.

** Structure declaration for VBAP table


TYPES: BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln, " Sales Document
posnr TYPE vbap-posnr, " Sales Document Item
abgru TYPE vbap-abgru, " Reason for rejection of quotations and sales
orders
END OF ty_vbap,
** Structure declaration for VBAK table
BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln, " Sales Document
augru TYPE vbak-augru, " Order reason (reason for the business transaction)
END OF ty_vbak.

DATA:
** Work area declaration for VBAP table
wa_vbap TYPE ty_vbap,
** Work area declaration for VBAK table
wa_vbak TYPE ty_vbak.

DATA: g_string TYPE string. " String declaration to display error message

** Read table data from EBKN table


loop at im_ebkn into im_wa_ebkn.
** Condition to get the values of vbeln and vbelp
IF im_wa_ebkn-vbeln IS NOT INITIAL AND im_wa_ebkn-vbelp IS NOT INITIAL.

** Fetching the data from VBAK table


SELECT SINGLE
vbeln
augru
FROM vbak
INTO wa_vbak
WHERE vbeln = im_wa_ebkn-vbeln.

IF wa_vbak-augru = 'CL' OR wa_vbak-augru = 'HL'.


MESSAGE 'Sales order is blocked' TYPE 'I' display like 'E'.
leave to current transaction.
ELSE.
** Fetching the data from VBAP table
SELECT SINGLE
vbeln
posnr
abgru
FROM vbap
INTO wa_vbap
WHERE vbeln = im_wa_ebkn-vbeln
AND posnr = im_wa_ebkn-vbelp.
IF wa_vbap-abgru eq 'CL' or wa_vbap-abgru eq 'HL'.
** Concatenation in a string to display Sales document and Sales document item details
CONCATENATE 'Sales order line item is blocked for' im_wa_ebkn-vbeln im_wa_ebkn-vbelp
INTO g_string separated by space.
MESSAGE g_string TYPE 'I' display like 'E'.
leave to current transaction.
ENDIF.
ENDIF.
ENDIF.
endloop.
ENDIF.
ENDMETHOD.

You might also like