안녕하세요.
GOS를 사용하여 최종적으로는 3rd party에서 I/F받는 파일을
구매처 마스터에 백그라운드로 첨부시키려고 하는데요.
아래와 같이 두 가지 소스를 테스트해보았는데 잘 되지 않네요.
오류 해결과 함께, PDF 뿐 아니라 XLS, TXT 등 어떤 파일을 첨부하더라도
기능이 정상적으로 실행되려면 어떤 처리가 필요한지 아시는 분은 답변 부탁드립니다.~~
1. GUI_UPLAOD 함수를 사용
: 업로드 후에, 마스터의 attach된 파일을 열어보면, 확장자명이 잘못되었다는 오류가 남
2. OPEN DATASET 사용
: 파일 내용을 읽어들이지 못함.
<source1>
REPORT ZTEST003.
INCLUDE: <CNTN01>.
CLASS CL_BINARY_RELATION DEFINITION LOAD.
CLASS CL_OBL_OBJECT DEFINITION LOAD.
DATA: LV_FILE TYPE STRING,
LV_FILELENGTH TYPE I,
LV_XFNAME(255),
LV_XDOCTYPE TYPE C LENGTH 3 VALUE 'PDF'.
DATA: LV_FULLNAME LIKE RLGRAP-FILENAME,
LV_FILEPATH LIKE RLGRAP-FILENAME.
DATA : LV_DOC_SIZE TYPE I.
DATA : L_FILE_LINES TYPE I.
DATA: P_BOTYPE LIKE OBL_S_PBOR-TYPEID VALUE 'LFA1',
P_DOCTY LIKE OBL_S_PBOR-TYPEID VALUE 'MESSAGE',
P_MSGTYP LIKE SOFM-DOCTP VALUE 'ATTA', "첨부파일
P_RELTYP LIKE MDOBLREL-RELTYPE VALUE 'ATTA',
P_DOKNR(20) VALUE '_ACNTR0101',
P_LIFNR TYPE LIFNR VALUE '0000100063'.
TYPES: BEGIN OF TY_MESSAGE_KEY,
FOLTP TYPE SO_FOL_TP,
FOLYR TYPE SO_FOL_YR,
FOLNO TYPE SO_FOL_NO,
DOCTP TYPE SO_DOC_TP,
DOCYT TYPE SO_DOC_YR,
DOCNO TYPE SO_DOC_NO,
FORTP TYPE SO_FOR_TP,
FORYR TYPE SO_FOR_YR,
FORNO TYPE SO_FOR_NO,
END OF TY_MESSAGE_KEY.
DATA: LV_MESSAGE_KEY TYPE TY_MESSAGE_KEY.
DATA: LO_MESSAGE TYPE SWC_OBJECT.
DATA: LT_DOC_CONTENT TYPE STANDARD TABLE OF SOLIX
WITH HEADER LINE.
DATA: RESULT TYPE ABAP_BOOL.
P_DOCTY = 'MESSAGE'.
*CASE P_RELTYP.
* WHEN 'URL'.
* P_MSGTYP = 'URL'.
* WHEN 'NOTE' OR 'PNOT'.
* P_MSGTYP = 'RAW'.
* WHEN 'ATTA'.
P_MSGTYP = 'EXT'.
* WHEN OTHERS.
*ENDCASE.
SWC_CREATE_OBJECT LO_MESSAGE 'MESSAGE' LV_MESSAGE_KEY.
CONCATENATE 'C:TEMP' P_DOKNR '.' LV_XDOCTYPE INTO LV_FILE.
CONDENSE LV_FILE NO-GAPS.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST
EXPORTING
FILE = LV_FILE
RECEIVING
RESULT = RESULT.
IF RESULT <> 'X'.
EXIT.
ENDIF.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILE
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = LV_FILELENGTH
TABLES
DATA_TAB = LT_DOC_CONTENT.
SWC_CONTAINER LT_MESSAGE_CONTAINER.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' P_DOKNR.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTLANGU' SY-LANGU.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'NO_DIALOG' 'X'.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTNAME' '메시지'.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTYPE' LV_XDOCTYPE.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'CONTENT_HEX' LT_DOC_CONTENT.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_FILELENGTH.
SWC_CALL_METHOD LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER.
SWC_REFRESH_OBJECT LO_MESSAGE.
SWC_GET_OBJECT_KEY LO_MESSAGE LV_MESSAGE_KEY.
DATA: LO_IS_OBJECT_A TYPE SIBFLPORB.
LO_IS_OBJECT_A-INSTID = P_LIFNR.
LO_IS_OBJECT_A-TYPEID = P_BOTYPE.
LO_IS_OBJECT_A-CATID = 'BO'.
DATA: LO_IS_OBJECT_B TYPE SIBFLPORB.
LO_IS_OBJECT_B-INSTID = LV_MESSAGE_KEY.
LO_IS_OBJECT_B-TYPEID = P_DOCTY.
LO_IS_OBJECT_B-CATID = 'BO'.
CALL METHOD CL_BINARY_RELATION=>CREATE_LINK
EXPORTING
IS_OBJECT_A = LO_IS_OBJECT_A
IS_OBJECT_B = LO_IS_OBJECT_B
IP_RELTYPE = P_RELTYP.
COMMIT WORK.
<source2>
*&---------------------------------------------------------------------*
*& Report ZTEST005
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST005.
*---------------------------------------------------------------------*
* Function : We need to maintain links between Business Object and
* the attachment.Attachment document is basiclally a
* business object of type 'MESSAGE'.In order to maintain
* links, first the attachment will be crated as Business
* Object of type 'MESSAGE' using Message.Create method.
*
* This program can be used to attach PC documents eg. PDF
* ,DOC,TXT,GIF etc. to a SAP Business Object e.g Purchase
* Order etc. You should pass the correct message type
* [ P_MSGTYP ] as per the file extension[e.g. PDF,DOC etc].
*
* The code below is suitable for 4.6C+, though you might
* like to use the commented code, instead, for 4.7+
*---------------------------------------------------------------------*
* Include for BO macros
INCLUDE : <cntn01>.
* Load class.
* CLASS CL_BINARY_RELATION definition load.
PARAMETERS:
* Object_a
* P_BOTYPE LIKE obl_s_pbor-typeid DEFAULT 'BUS2031', " e.g. 'BUS2012'
* P_BO_ID LIKE OBL_S_PBOR-INSTID DEFAULT '0002029816',
P_BOTYPE LIKE borident-OBJTYPE DEFAULT 'LFA1', " e.g. 'BUS2012'
P_BO_ID LIKE borident-OBJKEY DEFAULT '0000100063',
" Key e.g. PO No.
* Object_b
P_MSGTYP LIKE SOFM-DOCTP DEFAULT 'PDF',
P_DOCTY LIKE borident-OBJTYPE DEFAULT 'MESSAGE',
* Relationship
P_RELTYP LIKE BRELTYP-RELTYPE DEFAULT 'ATTA',
* File Name
P_FNAME like rlgrap-filename Default 'C:TEMP_ACNTR0101.pdf'.
types: BEGIN OF TY_MESSAGE_KEY,
FOLTP TYPE SO_FOL_TP,
FOLYR TYPE SO_FOL_YR,
FOLNO TYPE SO_FOL_NO,
DOCTP TYPE SO_DOC_TP,
DOCYR TYPE SO_DOC_YR,
DOCNO TYPE SO_DOC_NO,
FORTP TYPE SO_FOR_TP,
FORYR TYPE SO_FOR_YR,
FORNO TYPE SO_FOR_NO,
END OF TY_MESSAGE_KEY.
DATA : LV_MESSAGE_KEY type TY_MESSAGE_KEY.
DATA : LO_MESSAGE type SWC_OBJECT.
DATA : LT_DOC_CONTENT type standard table of SOLI-LINE
with header line.
*----------------------------------------------------------------------*
* First derive the Attachment's ( MESSAGE )document type.
P_DOCTY = 'MESSAGE'.
CASE P_RELTYP.
* In case of URls
WHEN 'URL'.
P_MSGTYP = 'URL'.
* In case of Notes / Private Notes
WHEN 'NOTE' OR 'PNOT'.
P_MSGTYP = 'RAW'.
WHEN 'ATTA'.
* Take given parameter e.g. 'DOC', 'PDF' etc.
* P_MSGTYP = 'EXT'.
WHEN OTHERS.
* ....exit
EXIT.
ENDCASE.
*----------------------------------------------------------------*
* Create an initial instance of BO 'MESSAGE' - to call the
* instance-independent method 'Create'.
swc_create_object LO_MESSAGE 'MESSAGE' LV_MESSAGE_KEY.
* define container to pass the parameter values to the method call
* in next step.
swc_container LT_MESSAGE_CONTAINER.
* Populate container with parameters for method
swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' 'TestDocument'.
swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTLANGU' 'E'.
swc_set_element LT_MESSAGE_CONTAINER 'NO_DIALOG' 'X'.
swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTNAME' P_DOCTY.
swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTTYPE' P_MSGTYP.
* In case of URLs..it should be concatenated with &KEY& in the begining.
CASE P_MSGTYP.
WHEN 'URL'.
LT_DOC_CONTENT = '&KEY&http://www.rmtiwari.com' .
append LT_DOC_CONTENT.
* In case of Notes or Private Notes, get the data from files on appl
* server or from wherever(? - remember background).
WHEN 'RAW'.
LT_DOC_CONTENT = 'Hi How r u?' .
append LT_DOC_CONTENT.
* In case of PC File attachments
WHEN OTHERS.
OPEN DATASET P_FNAME FOR INPUT in binary mode.
IF SY-subrc EQ 0.
DO.
READ DATASET P_FNAME INTO LT_DOC_CONTENT.
IF SY-subrc EQ 0.
append LT_DOC_CONTENT.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET P_FNAME.
ENDIF.
ENDCASE.
* 'DocumentContent' is a multi-line element ( itab ).
swc_set_table LT_MESSAGE_CONTAINER 'DocumentContent' LT_DOC_CONTENT.
* Size is required in case of File attachments
data : LV_DOC_SIZE type i.
data : L_FILE_LINES type i.
DESCRIBE TABLE LT_DOC_CONTENT LINES L_FILE_LINES.
READ TABLE LT_DOC_CONTENT INDEX L_FILE_LINES.
LV_DOC_SIZE = ( 255 * ( L_FILE_LINES - 1 ) ) +
STRLEN( LT_DOC_CONTENT ).
swc_set_element LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_DOC_SIZE .
* Refresh to get the reference of create 'MESSAGE' object for attachment
swc_refresh_object LO_MESSAGE.
swc_call_method LO_MESSAGE 'CREATE' LT_MESSAGE_CONTAINER.
* Get Key of new object
swc_get_object_key LO_MESSAGE LV_MESSAGE_KEY.
* Now we have attachment as a business object instance. We can now
* attach it to our main business object instance.
* Create main BO object_a
* data: LO_IS_OBJECT_A type SIBFLPORB. "type SIBFLPORB is unknown, so I
data: LO_IS_OBJECT_A type BORIDENT.
LO_IS_OBJECT_A-OBJKEY = P_BO_ID.
LO_IS_OBJECT_A-OBJTYPE = P_BOTYPE.
* LO_IS_OBJECT_A-CATID = 'BO'.
* Create attachment BO object_b
* data: LO_IS_OBJECT_B type SIBFLPORB. "type SIBFLPORB is unknown
data: LO_IS_OBJECT_B type BORIDENT.
LO_IS_OBJECT_B-OBJKEY = LV_MESSAGE_KEY.
LO_IS_OBJECT_B-OBJTYPE = P_DOCTY.
* LO_IS_OBJECT_B-CATID = 'BO'.
*TRY.
*CALL METHOD CL_BINARY_RELATION=>CREATE_LINK
* EXPORTING
* IS_OBJECT_A = LO_IS_OBJECT_A
* IS_OBJECT_B = LO_IS_OBJECT_B
* IP_RELTYPE = P_RELTYP.
call function 'BINARY_RELATION_CREATE'
EXPORTING
obj_rolea = LO_IS_OBJECT_A
obj_roleb = LO_IS_OBJECT_B
relationtype = P_RELTYP
EXCEPTIONS
others = 1.
* Check if everything OK...who cares!!
commit work.
댓글 4
-
열공아밥
2010.07.27 08:28
-
ripencarrot
2010.07.27 19:14
참고 자료 감사합니다. 리플들이 엄청 많고 저랑 같은 경우의 질문들도 많은데,, 정작 해답을 찾지 못하고 있습니다...;;
잉글리쉬의 탓일까요..ㅡ.ㅡa.. 열심히 SAP질 중"
-
activeman
2010.07.28 20:11
One Paper에 있는 자료를 참고 하십시요.
예전에 One Paper에 소개한 내용입니다. 소스를 보시고 조금만 수정하시면 다른 확장자로 된 파일도 쉽게 올릴수 있습니다.
제가 소개한 내용에는 pdf 파일만 올리게 되어 있습니다만 소스를 수정하시면 다른 확장자명을 가진것도 첨부할 수 있습니다.
즐밥하세요.
-
방청객
2016.03.07 19:58
아래 LT_DOC_CONTENT 은 첨부화일 내용입니다.따라서, 이것은 TABLE과 연결 시켜줘야 합니다.아래 보시는 바와 같이 바꾸시면 됩니다.즐밥하세요 ^^SWC_CONTAINER LT_MESSAGE_CONTAINER.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTITLE' P_DOKNR.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTLANGU' SY-LANGU.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'NO_DIALOG' 'X'.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTNAME' '메시지'.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTTYPE' LV_XDOCTYPE.
===> SWC_SET_TABLE LT_MESSAGE_CONTAINER 'CONTENT_HEX' LT_DOC_CONTENT.
*** SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'CONTENT_HEX' LT_DOC_CONTENT.
SWC_SET_ELEMENT LT_MESSAGE_CONTAINER 'DOCUMENTSIZE' LV_FILELENGTH.
다음 블로그들을 참고해보세요~
https://weblogs.sdn.sap.com/pub/wlg/2519
http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3399