|
Purpose The SAP standard OData service API_CV_ATTACHMENT_SRV allows us to manage attachments for business objects. You can perform operations such as upload and download attachments, delete attachments, list attachments. Business objects types and keys To reference a specific business object, you need the SAP standard name for its type and information about the key; in particular, the key length, since the key often must be specified with leading zeros. The following table lists the common SAP business object types and provides information about the corresponding key field:
For master data, the object type is often the table name rather than a BUSxxxx code (e.g. EQUI, IFLOT, LFA1, KNA1). See transaction SWO1 (F4 on the object type field).
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example: Upload an attachment for a maintenance notification
The details of the uploaded attachment are set as follows:
In our example, we specified the 12-digit message number with leading zeros, as expected by the attachment service, e.g., "000010000073". If you have the number in an external format without leading zeros, for example, "10000073", the simplest solution is to have the GuiXT OData API perform the conversion:
Example: Upload an attachment for a maintenance notification
If you forget to perform this conversion, the OData service will not return an error message but will respond with "201 Created." You can then download the attachment, again with the incorrect message number, but you will not find it in SAP transaction IW22/IW23.
The situation is different if you make a typo in the object type and enter, for example, "BUSS2038." SAP then returns HTTP code "400 Bad Request" with an error message that GuiXT displays in the Script Editor: ![]() The SAP error message is a bit misleading in this case, but it's probably still a good idea to check for any error messages whenever you call the GuiXT OData API. You can do this using the "message" parameter as follows:
Displaying an error message
In the following examples, we'll generally omit error handling so we can focus on the OData API. With SAP HDM (Harmonized Document Management), you can specify which archive document types are permitted for each business object type and which type is set as the default. Here is an example (equipments): ![]() If we upload an attachment without explicitely specifying the archive document type, it will be saved as "YP2" (Manuals). To have it saved as "GOS", add the DocType to the key fields:
Specifying the DocType
![]() Read an attachment list
Example: Read and display the customer attachments
![]() Download and display an attachment We extend the previous example, allowing the user to select an attachment and to display it in a separate window. For the download we need the full attachment key.
GuiXT Script: Download and display a customer attachment
InputScript display_attachment.txt
Components InputAssistant + GuiXT Controls |