SAP ABAP에서 웹저장소(SMW0)를 이용한 문서 연결

SAP ABAP에서 웹저장소(SMW0)를 이용한 문서 연결

Published
2009년 03월 16일
생성자
카테고리
SAP
태그
abap
SAP
SMW0
sap smw0
하위 카테고리
ABAP
ABAP 프로그램에 파일을 연결하는 방식은 여러가지가 있겠지만, 저같은 경우엔 SMW0에 파일을 업로드 하여 사용을 합니다.
이 파일을 BDC나 Excel Upload할때 문서양식을 PC에서 찾지 않고 프로그램에 직접 연결해서 쓰면 편하기 때문이지요.
아래와 같이 버튼을 추가해서 프로그램에 연결합니다.
그럼, SMW0에 문서를 저장하는 방법을 소개합니다.

1. SMW0 초기화면

  • 티코드 SMW0를 실행하면 초기 화면이 나옵니다. 여기서 2번째 선택

2. 패키지 생성 or 대상 패키지 조회

3. 신규 오브젝트 생성

4. 신규파일 타입일 경우 MIME Type 추가

  • 등록된 확장자가 없다면 신규등록 추가 (파일 등록전에 mime type 추가해준 화면(ms-word, ms-excel) )

5. 신규문서 등록

6. SMW0 파일 링크 위한 ABAP 코드

*&———————————————————————* *& Report ZMMB3000 *& *&———————————————————————* *&이크래더블 거래실적 Excel Upload *&———————————————————————* REPORT zmmb3000. TYPE-POOLS: kcde, icon. TABLES: sscrfields. “선택화면의 필드 DATA : g_xls_t TYPE STANDARD TABLE OF kcde_intern_struc WITH HEADER LINE. DATA: BEGIN OF gt_dat OCCURS 0, venid(10), “협력회사ID seqid(2), “Seq. bunam(35), “사업및솔루션. reqcm(35), “사업분야. smonth(6), “수행기간시작일. emonth(6), “수행기간종료일. putyp(1), “수행성격(‘1’:제품, ‘2’:용역). oramt(20), “계약금액. ordcm(35), “발주처. suptp(20), “수급형태. pertp(20), “이행구분. END OF gt_dat. DATA: gt_2060 TYPE TABLE OF zmmt2060 WITH HEADER LINE. *–> SMW0 ROUTING 생성/변경 양식 INCLUDE: officeintegrationinclude. DATA: functxt TYPE smp_dyntxt. DATA: doc_table LIKE w3mime OCCURS 0. DATA: doc_size TYPE i. DATA: doc_type(80) VALUE soi_doctype_excel97_sheet.“엑셀 DATA: doc_format(80) TYPE c. DATA: link_server TYPE REF TO i_oi_link_server. DATA: factory TYPE REF TO i_oi_document_factory. DATA: document TYPE REF TO i_oi_document_proxy. DATA: retcode TYPE t_oi_ret_string. *<– *———————————————————————-* * INITIALIZATION *———————————————————————-* INITIALIZATION. PERFORM scrfields_functxt. *———————————————————————-* * SELECTION-SCREEN *———————————————————————-* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text–001. PARAMETERS: p_header TYPE c DEFAULT 1. “헤더라인. PARAMETERS p_fname LIKE rlgrap-filename. “파일. SELECTION-SCREEN: FUNCTION KEY 1. SELECTION-SCREEN END OF BLOCK b1. *&———————————————————————* *& AT SELECTION-SCREEN * *&———————————————————————* AT SELECTION-SCREEN. PERFORM scr_user_command. *———————————————————————-* * AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname. *———————————————————————-* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname. CALL FUNCTION ‘F4_FILENAME’ “File Upload를 위한 Window IMPORTING file_name = p_fname. *———————————————————————-* * START-OF-SELECTION. *———————————————————————-* START-OF-SELECTION. PERFORM close_document. PERFORM excel_upload. PERFORM change_data. PERFORM save_data. *&———————————————————————* *& Form EXCEL_UPLOAD *&———————————————————————* * text *———————————————————————-* FORM excel_upload . FIELD-SYMBOLS: <fs>. DATA: lv_index TYPE i. * 엑셀 파일 upload 함수 호출 CALL FUNCTION ‘KCD_EXCEL_OLE_TO_INT_CONVERT’ “파일 convert EXPORTING filename = p_fname i_begin_col = 1 i_begin_row = 1 i_end_col = 100 i_end_row = 5000 TABLES intern = g_xls_t EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. STOP. ENDIF. CHECK NOT g_xls_t[] IS INITIAL. SORT g_xls_t BY row col. LOOP AT g_xls_t WHERE row > p_header. MOVE : g_xls_t-col TO lv_index. ASSIGN COMPONENT lv_index OF STRUCTURE gt_dat TO <fs>. MOVE : g_xls_t-value TO <fs>. AT END OF row. APPEND gt_dat. CLEAR gt_dat. ENDAT. ENDLOOP. ENDFORM. ” EXCEL_UPLOAD *&———————————————————————* *& Form CHANGE_DATA *&———————————————————————* * text *———————————————————————-* FORM change_data . CLEAR: gt_2060, gt_2060[]. LOOP AT gt_dat. MOVE-CORRESPONDING gt_dat TO gt_2060. gt_2060-erdat = sy-datum. gt_2060-erzet = sy-uzeit. gt_2060-ernam = sy-uname. gt_2060-aedat = sy-datum. gt_2060-aezet = sy-uzeit. gt_2060-aenam = sy-uname. gt_2060-act_yn = ‘Y’. gt_2060-lvorm = space. APPEND gt_2060. CLEAR: gt_2060. ENDLOOP. ENDFORM. ” CHANGE_DATA *&———————————————————————* *& Form SAVE_DATA *&———————————————————————* * text *———————————————————————-* FORM save_data . DATA: lv_lines(5). lv_lines = LINES( gt_2060 ). * DELETE FROM zmmt2060. MODIFY zmmt2060 FROM TABLE gt_2060. IF sy-subrc = 0. WRITE:/ ‘거래실적 Upload완료!’. WRITE:/ ‘건수:’, lv_lines. ELSE. WRITE:/ ‘거래실적 Upload실패!’. ENDIF. ENDFORM. ” SAVE_DATA *&———————————————————————* *& Form SCRFIELDS_FUNCTXT *&———————————————————————* * text *———————————————————————-* FORM scrfields_functxt . functxt-icon_id = icon_import. functxt-quickinfo = ‘Excel Format Download’. functxt-icon_text = ‘Excel Format Download’. sscrfields-functxt_01 = functxt. ENDFORM. “scrfields_functxt *&———————————————————————* *& Form SCR_USER_COMMAND *&———————————————————————* * text *———————————————————————-* FORM scr_user_command . CASE sscrfields-ucomm. WHEN ‘FC01’. PERFORM sap_oi_load_mime_data. WHEN OTHERS. ENDCASE. ENDFORM. ” SCR_USER_COMMAND *&———————————————————————* *& Form SAP_OI_LOAD_MIME_DATA *&———————————————————————* * text *———————————————————————-* FORM sap_oi_load_mime_data . IF factory IS INITIAL. CALL METHOD c_oi_factory_creator=>get_document_factory IMPORTING factory = factory retcode = retcode. IF retcode NE c_oi_errors=>ret_ok. EXIT. ENDIF. CALL METHOD factory->start_factory EXPORTING r3_application_name = ‘document_name’ IMPORTING retcode = retcode. CALL METHOD c_oi_errors=>show_message EXPORTING type = ‘E’. CALL METHOD factory->get_link_server IMPORTING link_server = link_server retcode = retcode. CALL METHOD c_oi_errors=>show_message EXPORTING type = ‘E’. CALL METHOD link_server->start_link_server EXPORTING link_server_mode = 3 * DEFAULT 1(STANDARD NAME), 0 (INACTIVE), 2(CUSTOMER NAME), * 3(UNIQUE NAME) -> 0, 2(동일사용자 X), 3 일때 다중실행 ## * SERVER_NAME_SUFFIX = ‘HR’ IMPORTING retcode = retcode. CALL METHOD c_oi_errors=>show_message EXPORTING type = ‘E’. ENDIF. “factory IS INITIAL.. * CLEAR: doc_table[]. CALL FUNCTION ‘SAP_OI_LOAD_MIME_DATA’ EXPORTING object_id = ‘ZMMB3000’ ” SMW0 정의된 문서 IMPORTING data_size = doc_size document_format = doc_format document_type = doc_type TABLES data_table = doc_table EXCEPTIONS object_not_found = 1 internal_error = 2 OTHERS = 3. IF sy-subrc NE 0. RAISE fail_document_load. MESSAGE ID sy-msgid TYPE ‘E’ NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. IF doc_size NE 0. * FACTORY 와 DOCUMENT 연결 CALL METHOD factory->get_document_proxy EXPORTING document_type = doc_type IMPORTING document_proxy = document retcode = retcode. CALL METHOD c_oi_errors=>show_message EXPORTING type = ‘E’. * Document를 Protected Mode로 Open하고 매크로를 실행함. CALL METHOD document->open_document_from_table EXPORTING document_table = doc_table[] document_size = doc_size IMPORTING retcode = retcode. CALL METHOD c_oi_errors=>show_message EXPORTING type = ‘E’. ELSE. * MESSAGE E005 RAISING FAIL_DOCUMENT_OPEN. * RAISE FAIL_DOCUMENT_OPEN. * MESSAGE S000 WITH ‘선택한 문서가 없습니다’. ENDIF. ENDFORM. ” SAP_OI_LOAD_MIME_DATA *&———————————————————————* *& Form close_document *&———————————————————————* * text *———————————————————————-* FORM close_document . IF NOT document IS INITIAL. CALL METHOD document->close_document. FREE document. ENDIF. ENDFORM. ” close_document

댓글

guest