Skip to Content
0

How to Read GOS attachment having word,excel,ppt to binary format

Feb 02, 2017 at 05:17 PM

204

avatar image
Former Member

I have written the below code but thats allowing only pdf attachments to be downloaded. Kindly suggest.

CODE:

P_BO_ID = WA_EKPO-EBELN.

LO_IS_OBJECT_A-INSTID = P_BO_ID.
LO_IS_OBJECT_A-TYPEID = P_BOTYPE.
LO_IS_OBJECT_A-CATID = 'BO'.

WA_REL-SIGN = 'I'.
WA_REL-OPTION = 'EQ'.
WA_REL-LOW = P_RELTYP.
APPEND WA_REL TO LT_REL.


CALL METHOD CL_BINARY_RELATION=>READ_LINKS
EXPORTING
IS_OBJECT = LO_IS_OBJECT_A
* IP_LOGSYS =
* IT_ROLE_OPTIONS =
IT_RELATION_OPTIONS = LT_REL
* IP_NO_BUFFER = SPACE
IMPORTING
ET_LINKS = LT_LINKS
* ET_ROLES =
.

Loop at LT_LINKS INTO WA_LINKS.
clear: document_id, DOCUMENT_DATA,OBJECT_CONTENT,OBJECT_CONTENT[].
DOCUMENT_ID = WA_LINKS-instid_b.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
DOCUMENT_ID = DOCUMENT_ID
* FILTER = 'X '
IMPORTING
DOCUMENT_DATA = DOCUMENT_DATA
TABLES
* OBJECT_HEADER =
OBJECT_CONTENT = OBJECT_CONTENT
* OBJECT_PARA =
* OBJECT_PARB =
* ATTACHMENT_LIST =
* RECEIVER_LIST =
CONTENTS_HEX = CONTENTS_HEX
* EXCEPTIONS
* DOCUMENT_ID_NOT_EXIST = 1
* OPERATION_NO_AUTHORIZATION = 2
* X_ERROR = 3
* OTHERS = 4
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

clear GV_TAB_LINES.
DESCRIBE TABLE GT_OBJBIN LINES GV_TAB_LINES.
CLEAR: GS_OBJBIN, ATT1.
ATT1 = GV_TAB_LINES + 1.
READ TABLE GT_OBJBIN INTO GS_OBJBIN INDEX GV_TAB_LINES.
IF SY-SUBRC = 0.
GS_OBJPACK-DOC_SIZE = ( GV_TAB_LINES - 1 ) * 255 + STRLEN( GS_OBJBIN ).
GS_OBJPACK-TRANSF_BIN = 'X'.
GS_OBJPACK-HEAD_START = 1.
GS_OBJPACK-HEAD_NUM = 0.
GS_OBJPACK-BODY_START = ATT1.
GS_OBJPACK-BODY_NUM = GV_TAB_LINES.
GS_OBJPACK-DOC_TYPE = DOCUMENT_DATA-OBJ_TYPE."'PDF'.
GS_OBJPACK-OBJ_NAME = DOCUMENT_DATA-OBJ_DESCR."'ATTACHMENT'.
GS_OBJPACK-OBJ_DESCR = DOCUMENT_DATA-OBJ_DESCR. " l_doc-xekko-ebeln.
APPEND GS_OBJPACK TO GT_OBJPACK.
ENDIF.

LOOP AT OBJECT_CONTENT.
GS_OBJBIN = OBJECT_CONTENT.
APPEND GS_OBJBIN TO GT_OBJBIN.
CLEAR GS_OBJBIN.
ENDLOOP.

endloop.
ENDIF.
************* Adding Attachments for Facilities end ****************

* Sending the Form Output in the PDF format to email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = GS_DOCDATA
PUT_IN_OUTBOX = 'X'
* commit_work = 'X'
TABLES
PACKING_LIST = GT_OBJPACK
CONTENTS_BIN = GT_OBJBIN
CONTENTS_TXT = CONTENTS_TXT
RECEIVERS = GT_RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers