Entering content frameProcedure documentation Appending Attachments at the Sender Locate the document in its SAP Library structure

Use

An attachment comprises any data (for example, text or graphics) that can be appended to a message. In principle, you can append an unlimited number of attachments to an output message of an outbound or inbound interface (in the synchronous case) using the controller object.

Procedure

  1. Declare a variable for the attachment object, a table for the transfer of one or more attachments to the controller object, and variables that specify the name, contents, and the type of attachment. To create the attachment object you require the factory class CL_AI_FACTORY:
  2. data: l_attachment type ref to if_ai_attachment,
          lt_attach    type prx_attach,
          l_name       type string,
          l_xstring    type xstring,
          l_type       type string.

    class cl_ai_factory definition load.
    data: l_controller type ref to if_ai_posting_controller.

  3. Assign 1_name to the name, 1_xstring to the contents of the attachments in binary format, and 1_type to the type (for example, ‘text/html’). The interface IF_AI_ATTACHMENT provides a selection of constants for this purpose. If the type in question is not yet available as a constant in the interface, you can also assign l_type to any other string.
  4. Using the factory class CL_AI_FACTORY, you can now generate an attachment instance and append it to the attachment table lt_attach:
  5. l_attachment =
         cl_ai_factory=>create_attachment_from_binary(
                  p_data = l_xstring
                  p_type = l_type
                  p_name = l_name ).

    append l_attachment to lt_attach.

    Note

    The factory class also provides the method create_attachment_from_text () for pure text attachments; you can append the attachment to this method as STRING.

  6. To generate additional attachments, repeat the procedure described in the last two steps.
  7. Transfer your attachments using the method set_attachments() of the controller object:
  8. l_controller = cl_ai_factory=>create_controller( ).
    l_controller->set_attachments( lt_attach ).

  9. Transfer the controller object when you call your proxy.

Note

In the synchronous case, you can also set attachments at the receiver. Once you have fetched input message attachments, you can set attachments for the output message, using set_attachments (). Since only one controller object exists for the inbound interface, you overwrite the attachments of the input message, however.

 

 

 

 

Leaving content frame