Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Raising an error message for ME52N transaction using user Exit

Former Member
0 Kudos

Dear Experts,

I have a requirement, I need to validate the total valuated amount entered in PR, If the amount is exceeded, it should not allow to create a purchase requisition.

It should raise an exception, saying the budget is exceeded, then user should be there in the current transaction to edit the amount and then finally create the PR.

I got the exit, EXIT_SAPLMEREQ_010, I have written a piece of code

 DATA: l_msg TYPE symsgv,
      wa_eban TYPE eban,
      w_preis TYPE eban-preis,
      w_amt TYPE eban-preis.
BREAK-POINT.

LOOP AT im_t_eban INTO wa_eban.
  IF wa_eban-werks = '1106'.
    w_amt = wa_eban-menge *  wa_eban-preis.
    w_preis = w_amt + w_preis.
  ENDIF.
ENDLOOP.

IF w_preis > '10000'.
  CONCATENATE : 'Plant: ' wa_eban-werks 'max PR value 10000.00 sar'
    INTO l_msg SEPARATED BY space.
  CALL METHOD cl_message_mm=>create
    EXPORTING
      im_msgid         = 'ZMSGS'
      im_msgty         = 'E'
      im_msgno         = '899'
      im_msgv1         = l_msg
      im_force_collect = mmpur_yes. "collect message

ENDIF.

when the enduser, checks the PR, it raises an exception as written above.

But when the enduser, saves the PR, initially it throws an error but still it gives us an option to save the PR, which should not happen in my case... It should not allow the user to save until the amount is corrected.

Kindly assist me on this.

Thanks and Regards,

Abdur Rafique

1 REPLY 1

Former Member
0 Kudos

Dear Experts,

Done.

I have added the below code for my requirement.

   
"EXIT_SAPLMEREQ_010

DATA: l_msg TYPE symsgv,
      wa_eban TYPE eban,
      w_preis TYPE eban-preis,
      w_amt TYPE eban-preis,
      wa_messages TYPE  bapiret2.

" The budget is checked for the plant 1106 only

LOOP AT im_t_eban INTO wa_eban.
  IF wa_eban-werks = '1106'.
    w_amt = wa_eban-menge *  wa_eban-preis.
    w_preis = w_amt + w_preis.
  ENDIF.
ENDLOOP.

IF w_preis > '10000'.
  CONCATENATE : 'Plant: ' wa_eban-werks
                'max PR value 10000.00 sar only'
                INTO l_msg SEPARATED BY space.
  wa_messages-type = 'E'.
  wa_messages-id = 'ZMSGS'.
  wa_messages-number = '003'.
  wa_messages-message_v1 = l_msg.

  APPEND wa_messages TO ex_messages .

ENDIF.