*&---------------------------------------------------------------------*
*& Report Z_EXCEL_FORM3 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT z_excel_form3 .
TABLES: kna1, brfckna1.
PARAMETERS: kunnr LIKE kna1-kunnr DEFAULT '1'.
*
* Internal table customer_data with structure of BRFCKNA1
*
DATA: BEGIN OF customer_data OCCURS 0.
INCLUDE STRUCTURE brfckna1.
DATA: END OF customer_data.
*
* OLE-specific include file
*
INCLUDE ole2incl. " OLE-specific include file
*
* Define OLE objects of type OLE_OBJEKT
*
DATA: excel TYPE ole2_object. " EXCEL object
DATA: books TYPE ole2_object. " collection of books
DATA: book TYPE ole2_object. " book
DATA: cell TYPE ole2_object. " cell
*
* Loop counter: Start value ---> 1st output line in EXCEL table
*
DATA: i TYPE i VALUE '4'.
CREATE OBJECT excel 'EXCEL.APPLICATION'.
CALL METHOD OF excel 'WORKBOOKS' = books.
CALL METHOD OF books 'ADD' = book.
CALL FUNCTION 'RFC_CUSTOMER_GET'
EXPORTING
kunnr = kunnr
TABLES
customer_t = customer_data
EXCEPTIONS
nothing_specified = 1
no_record_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / text-001. "Call error !
EXIT.
ENDIF.
* Fill the second line on EXCEL worksheet with header line info
*
PERFORM fill_cell USING 2 1 'Number'.
PERFORM fill_cell USING 2 2 'Form'.
PERFORM fill_cell USING 2 3 'Name'.
PERFORM fill_cell USING 2 4 'POBox'.
PERFORM fill_cell USING 2 5 'Street'.
PERFORM fill_cell USING 2 6 'ZIP'.
PERFORM fill_cell USING 2 7 'City'.
PERFORM fill_cell USING 2 8 'Tel.No'.
PERFORM fill_cell USING 2 9 'Tel.Fax'.
LOOP AT customer_data.
PERFORM fill_cell USING i 1 customer_data-kunnr.
PERFORM fill_cell USING i 2 customer_data-anred.
PERFORM fill_cell USING i 3 customer_data-name1.
PERFORM fill_cell USING i 4 customer_data-pfach.
PERFORM fill_cell USING i 5 customer_data-stras.
PERFORM fill_cell USING i 6 customer_data-pstlz.
PERFORM fill_cell USING i 7 customer_data-ort01.
PERFORM fill_cell USING i 8 customer_data-telf1.
PERFORM fill_cell USING i 9 customer_data-telfx.
i = i + 1.
ENDLOOP.
SET PROPERTY OF excel 'VISIBLE' = 1.
*&--------------------------------------------------------------------*
*& Form fill_cell
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->I text
* -->J text
* -->WERTE text
*---------------------------------------------------------------------*
FORM fill_cell USING i j werte.
CALL METHOD OF excel 'CELLS' = cell
EXPORTING
#1 = i
#2 = j.
SET PROPERTY OF cell 'VALUE' = werte.
ENDFORM. "fill_cell
*
*& Report Z_EXCEL_FORM3 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT z_excel_form3 .
TABLES: kna1, brfckna1.
PARAMETERS: kunnr LIKE kna1-kunnr DEFAULT '1'.
*
* Internal table customer_data with structure of BRFCKNA1
*
DATA: BEGIN OF customer_data OCCURS 0.
INCLUDE STRUCTURE brfckna1.
DATA: END OF customer_data.
*
* OLE-specific include file
*
INCLUDE ole2incl. " OLE-specific include file
*
* Define OLE objects of type OLE_OBJEKT
*
DATA: excel TYPE ole2_object. " EXCEL object
DATA: books TYPE ole2_object. " collection of books
DATA: book TYPE ole2_object. " book
DATA: cell TYPE ole2_object. " cell
*
* Loop counter: Start value ---> 1st output line in EXCEL table
*
DATA: i TYPE i VALUE '4'.
CREATE OBJECT excel 'EXCEL.APPLICATION'.
CALL METHOD OF excel 'WORKBOOKS' = books.
CALL METHOD OF books 'ADD' = book.
CALL FUNCTION 'RFC_CUSTOMER_GET'
EXPORTING
kunnr = kunnr
TABLES
customer_t = customer_data
EXCEPTIONS
nothing_specified = 1
no_record_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / text-001. "Call error !
EXIT.
ENDIF.
* Fill the second line on EXCEL worksheet with header line info
*
PERFORM fill_cell USING 2 1 'Number'.
PERFORM fill_cell USING 2 2 'Form'.
PERFORM fill_cell USING 2 3 'Name'.
PERFORM fill_cell USING 2 4 'POBox'.
PERFORM fill_cell USING 2 5 'Street'.
PERFORM fill_cell USING 2 6 'ZIP'.
PERFORM fill_cell USING 2 7 'City'.
PERFORM fill_cell USING 2 8 'Tel.No'.
PERFORM fill_cell USING 2 9 'Tel.Fax'.
LOOP AT customer_data.
PERFORM fill_cell USING i 1 customer_data-kunnr.
PERFORM fill_cell USING i 2 customer_data-anred.
PERFORM fill_cell USING i 3 customer_data-name1.
PERFORM fill_cell USING i 4 customer_data-pfach.
PERFORM fill_cell USING i 5 customer_data-stras.
PERFORM fill_cell USING i 6 customer_data-pstlz.
PERFORM fill_cell USING i 7 customer_data-ort01.
PERFORM fill_cell USING i 8 customer_data-telf1.
PERFORM fill_cell USING i 9 customer_data-telfx.
i = i + 1.
ENDLOOP.
SET PROPERTY OF excel 'VISIBLE' = 1.
*&--------------------------------------------------------------------*
*& Form fill_cell
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->I text
* -->J text
* -->WERTE text
*---------------------------------------------------------------------*
FORM fill_cell USING i j werte.
CALL METHOD OF excel 'CELLS' = cell
EXPORTING
#1 = i
#2 = j.
SET PROPERTY OF cell 'VALUE' = werte.
ENDFORM. "fill_cell
*
댓글 7
-
체인지
2007.11.20 20:45
좋은 자료 감사합니다^^ -
ABAP짱!
2007.12.06 19:09
감사합니다~
-
st
2008.01.09 19:46
감사합니다
-
수갬
2008.04.10 19:59
정보 감사합니다. 'RFC_CUSTOMER_GET 펑션 대신 쓸수 있는 평선은 없나요? 제 버전에선 안나오던데...
-
알렉스
2008.06.22 06:26
감사합니다.
-
보물찾기
2008.09.10 23:12
감사해요~ -
indianhead
2009.12.23 22:28
저도 'RFC_CUSTOMER_GET function 은 안되네요~