메뉴 건너뛰기

SAP 한국 커뮤니티

<img src=2.gif>GOS사용한 파일 attach (백그라운드)

ripencarrot 2010.07.27 03:10 조회 수 : 6671

안녕하세요.


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.


 


 

번호 제목 글쓴이 날짜 조회 수
5092 <img src=2.gif>메세지 관련 내용 볼수 있는곳이 어디인가요?(급해욤 ㅍㅍ) [6] abap왕초보 2010.07.29 1978
5091 <img src=3.gif>SO_NEW_DOCUMENT_ATT_SEND_API1 Function에 대한 질문입니다. [4] Chaconne 2010.07.28 2165
5090 <img src=2.gif>Online 스크린 Search help 질문입니다. [2] 초보생 2010.07.28 1759
5089 <img src=3.gif><img src=1.gif>ftp 연결로 첨부파일을 다른쪽으러 넣어줄때 파일명이 한글인것을 올리는법??? beginer 2010.07.28 1823
» <img src=2.gif>GOS사용한 파일 attach (백그라운드) [4] file ripencarrot 2010.07.27 6671
5087 <img src=3.gif>CL_GUI_ALV_TREE 에서 데이타에 따라 라인별로 ICON을 다르게 출력하려면.. [2] kms 2010.07.28 1622
5086 <img src=3.gif>:INTO *T001-BUTXT 의 문자 의미 [6] 막가레라 2010.07.28 1397
5085 <img src=2.gif>string 타입에 관한 질문 입니다. [5] 댕댕 2010.07.28 1120
5084 <img src=3.gif>RFC Function을 사용하여 BDC 실행을 하는 도중 에러 문제.. [7] 파초선 2010.07.27 3984
5083 <img src=2.gif>ALV 샘플에 대해서 질문있습니다.^^;; [3] genlux 2010.07.27 2104
5082 <img src=1.gif>set pf-status 'test' 에서 print 기능 상실했어요 [6] 아밥돌이 2010.07.27 3698
5081 <img src=3.gif>스크린상에 엑셀 창 띄울시 엑셀 프로그램이 빈페이지로 또 실행되는 문제.. [2] file 하얀콩 2010.07.27 2594
5080 <img src=1.gif>매크로를 이용한 MS워드와의 연동에서 HEAD가 하나이상일 경우 MACRO코드를 어떻게 쓰나요? file sora 2010.07.27 1426
5079 <img src=2.gif>alv 화면에서 금액필드 sum 해서 보여줄때 마지막 sum값 보여줄때. [3] 태사성 2010.07.26 3063
5078 <img src=3.gif>ALV 에서 셀 간의 계산시 자릿수 한계가 있는지요 [4] 남산밑 2010.07.24 1303
5077 <img src=3.gif>매크로 연동 워드 파일 PDF 파일로 변환하여 저장하기 [4] 고담 2010.07.24 3747
5076 <img src=2.gif>ALV Grid 칼럼 텍스트에 대한 질문입니다. [2] kms 2010.07.23 1817
5075 <img src=3.gif>- ~ => -> 기호 의미가 뭔지............ [9] 모포 2010.07.23 3149
5074 <img src=3.gif>스마트폼 내에서 alpha 컨버전 가능한가요?... [1] 돌맹이 2010.07.23 1538
5073 <img src=3.gif>webdynpro abap에서 table의 celldesign [2] file 모포 2010.07.23 1319