Wednesday, February 25, 2009

Read and convert a MIME object xstring to SOLI table data

If you are working in WebDynpro with PDF forms or Office Documents, you may want to store templates in the Mime repository and then manipulate them before sending them by email, or attaching them to objects using object services.

You need to read the Mime object, and convert it from xstring into a SOLI table. The following code makes that easy and quick.


REPORT zzzzzzz.

DATA:
mime_repository TYPE REF TO if_mr_api,
mime_xstring TYPE xstring,
mime_length TYPE i,
mime_soli TYPE soli_tab,
url TYPE string VALUE '/SAP/PUBLIC/BC/mymime.doc'.

mime_repository ?= cl_mime_repository_api=>get_api( ).

CALL METHOD mime_repository->get
EXPORTING
i_url = url
IMPORTING
e_content = mime_xstring.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = mime_xstring
IMPORTING
output_length = mime_length
TABLES
binary_tab = mime_soli.

* The MIME object is now in mime_soli ready for SAP Office processing.

Tuesday, February 24, 2009

Upload an attachment using object services

Object services are accessed from the drop down control in the top left of many SAP transactions such as XD02 Maintain Customer. One feature is the ability to attach documents uploaded from your PC.

It is surprisingly difficult to get under the covers of the object classes driving object services. I am developing an application that collects signatures scrawled on a tablet PC using a Flex control embedded in a web dynpro. Once collected, a signed document will be attached to the underlying SAP object and accessible through object services.

As a first step, I wanted to upload a document and attach it using a custom program. Here is the source code of my solution.


REPORT zzzzzzzz.

PARAMETERS:
p_kunnr TYPE kunnr.

DATA:
ls_object_identity TYPE borident,
lo_gos TYPE REF TO cl_gos_document_service.

ls_object_identity-objkey = p_kunnr. "e.g. '0000954410'.
ls_object_identity-objtype = 'KNA1'.

CREATE OBJECT lo_gos.

CALL METHOD lo_gos->create_attachment
EXPORTING
is_object = ls_object_identity
IMPORTING
ep_attachment = ls_object_identity-objkey.

COMMIT WORK.


In the next post, I will show how to load binary data from a table as an attached file object.