Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Travel Expense Form attachment in decision workitem

Hi all,

I have converted travel expense report to pdf file format. I used the following logic to attach the pdf file to attachment object container in the workflow

When i run the workflow attachment is there in decision workitem when i open that it is giving error that 'There was an error opening this document. The file is damaged and colud not be repaired'. Please help me

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = mi_rqident

no_dialog = space

dst_device = mstr_print_parms-pdest

importing

pdf_bytecount = mi_bytecount

tables

pdf = mtab_pdf

exceptions

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

others = 12.

DATA: office_object TYPE swc_object.

DATA: BEGIN OF SOFM_KEY,

FolderType LIKE SOFM-FOLTP,

FolderYear LIKE SOFM-FOLYR,

FolderNumber LIKE SOFM-FOLNO,

Type LIKE SOFM-DOCTP,

Year LIKE SOFM-DOCYR,

Number LIKE SOFM-DOCNO,

ForwarderName LIKE SOUB-USRNAM,

END OF SOFM_KEY.

DATA: REGION LIKE SOFD-FOLRG.

DATA: FOLDER_ID LIKE SOODK.

DATA: L_FOLDER_ID LIKE SOOBJINFI1-OBJECT_ID.

DATA: DOCUMENT_DATA LIKE SODOCCHGI1.

DATA: DOCUMENT_INFO LIKE SOFOLENTI1.

DATA: OBJECT_CONTENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

DATA: OBJECT_CONTENT_HEX LIKE SOLIX OCCURS 0 WITH HEADER LINE.

DATA: LINES LIKE SY-TABIX, DOCUMENT_TYPE LIKE SOODK-OBJTP.

*- set default

IF DOCUMENT_TYPE IS INITIAL.

DOCUMENT_TYPE = 'PDF'.

ENDIF.

*- create office object

*-- get dark folder

REGION = 'B'.

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

REGION = REGION

IMPORTING

FOLDER_ID = FOLDER_ID

EXCEPTIONS

COMMUNICATION_FAILURE = 1

OWNER_NOT_EXIST = 2

SYSTEM_FAILURE = 3

X_ERROR = 4

OTHERS = 5.

IF SY-SUBRC NE 0.

  • MESSAGE E696

  • RAISING ERROR_SOFM_CREATION.

ENDIF.

*-- create office document

DOCUMENT_DATA-OBJ_NAME = 'ATTACHMENT'.

DOCUMENT_DATA-OBJ_DESCR = 'Travel Expense Form'

DOCUMENT_DATA-OBJ_LANGU = SY-LANGU.

OBJECT_CONTENT[] = mtab_pdf[]. "NOTE_TEXT[].

  • object_content_hex[] = IT_SIMULATION_DATA[].

DESCRIBE TABLE OBJECT_CONTENT LINES LINES.

DOCUMENT_DATA-DOC_SIZE = ( LINES - 1 ) * 255 + STRLEN( OBJECT_CONTENT ).

L_FOLDER_ID = FOLDER_ID.

if object_content[] is initial.

describe table object_content_hex lines lines.

document_data-doc_size = lines * 255.

endif.

call function 'SO_DOCUMENT_INSERT_API1'

exporting

folder_id = l_folder_id

document_data = document_data

document_type = document_type

importing

document_info = document_info

tables

object_content = object_content

contents_hex = object_content_hex

exceptions

folder_not_exist = 1

document_type_not_exist = 2

operation_no_authorization = 3

parameter_error = 4

x_error = 5

enqueue_error = 6

others = 7.

if sy-subrc ne 0.

  • message e696(wl)

  • raising error_sofm_creation.

endif.

*- set export parameter

SOFM_KEY = DOCUMENT_INFO-DOC_ID.

swc_set_element CONTAINER 'ATTACH' office_object.

Former Member
Not what you were looking for? View more on this topic or Ask a question