Code listing for: GET_BASE64_CONTENT

Description: Get text content of text type attachment

**************************************************************************
*   Method attributes.                                                   *
**************************************************************************
Instantiation: Public
**************************************************************************

METHOD get_base64_content.

  DATA: li_length       TYPE i,
        ltp_doc_content TYPE string,
        ltp_content_x   TYPE xstring.

* Get the ascii content of this attachment
  TRY.
      ltp_doc_content = get_ascii_content( ).
    CATCH zcx_gos_attachment_exception .
      RAISE EXCEPTION TYPE zcx_gos_attachment_exception.
  ENDTRY.

* Convert to base-64
  li_length = strlen( ltp_doc_content ).

  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text     = ltp_doc_content
*     MIMETYPE = ' '
*     ENCODING =
    IMPORTING
      buffer   = ltp_content_x
    EXCEPTIONS
      failed   = 1
      OTHERS   = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

*** Encode content to BASE64
  CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
    EXPORTING
      input  = ltp_content_x
    IMPORTING
      output = content.

ENDMETHOD.