BDC나 Excel Upload할때 문서양식을 찾지않고 프로그램에 바로 연결해서 쓰면 편하죠.
1. SMW0에 문서저장하기.
요건 문서등록전에 해mime type 추가해준 화면(ms-word, ms-excel).
그리고 이렇게 문서를 등록.
2. 이젠 프로그램에 버튼추가해서 연결해야지요.
*&———————————————————————*
*& 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
'IT > SAP' 카테고리의 다른 글
[BC] SAP Tunning(2) (0) | 2020.05.19 |
---|---|
[SAP/ABAP] Possible Entry, Search Help (0) | 2020.04.23 |
[SAP/BC]SAP Pool, Cluster table Copy (0) | 2019.11.12 |
[SAP/BC] ST02 - Analyzing Buffer and Swaps (0) | 2019.10.30 |
[SAP/SAP] 자주사용하는 tcode (0) | 2019.03.18 |