Skip to Content

check whether the attachment exist or not when save a document

Oct 12, 2017 at 02:55 PM


avatar image


I'm going to add an enhancement based on the Transaction ME51N/ME52N.

The needs has told it's going to check whether the attachment is exist when the save command is excute.

Can anyone help me!

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Quickly Wang Oct 13, 2017 at 09:06 AM


I've got the answer,when i change the attachmens i'll export the information list to a memory id,during command execution i'll got the list from the memory id and check whether the data exist or not.

10 |10000 characters needed characters left characters exceeded
Aldrin Butcon Oct 13, 2017 at 06:44 AM


I think you can't add an attachment in ME51N for this functionality requires a reference number, in this case, a purchase requisition number, which does not exist yet.

As for ME52N, you need to find a user-exit (that will be triggered on the save command) wherein the purchase requisition number is accessible.

Next, inside the user-exit, select data from table SRGBTBREL with the following conditions:

  • RELTYPE = 'ATTA' (attachment)
  • INSTID_A = (purchase requisition number)
  • TYPEID_A = 'BUS2105' (purchase requisition object id)
  • CATID_A = 'BO' (instances of BOR object types)

The code should look something like this:

data: lt_srgbtbrel type standard table of srgbtbrel.

    select *
      from srgbtbrel
into table lt_srgbtbrel
     where reltype  eq 'ATTA'
       and instid_a eq us_banfn  " (suppose that variable us_banfn holds the purchase requisition number)
       and typeid_a eq 'BUS2105'
       and catid_a eq 'BO'.

if sy-subrc ne 0.
  " (means no attachment is found, display relevant error message)
Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi, Aldrin

In that case,it's wrong when i change the attachments.

For example,when i'm trying to empty the attachments,and data still exist in table srgbtbrel untill the save command ends.



I don't get it. If you delete the attachment, the data will be definitely removed from table SRGBTBREL. As per your requirement, it should display an error if you save the document without an attachment.



During command execution,the data of table SRGBTBREL is not the latest.For tha case, in the user-exit i cannot get the latest data.

On the other hand, If the purchase requisition had attached a attachment already,now I delete it.The attachment's information still exists in table SRGBTBREL.So it won't display any error.