壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 696|回复: 0

sap开发笔记3

[复制链接]
发表于 2010/1/8 14:07:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x

a example -- export to excel  


REPORT RSDEMO01 NO STANDARD PAGE HEADING.

* this report demonstrates how to send some ABAP data to an

* EXCEL sheet using OLE automation.

INCLUDE OLE2INCL.

* handles for OLE objects

DATA: H_EXCEL TYPE OLE2_OBJECT,
" Excel object


H_MAPL TYPE OLE2_OBJECT,
" list of workbooks


H_MAP TYPE OLE2_OBJECT,
" workbook


H_ZL TYPE OLE2_OBJECT,
" cell

H_F TYPE OLE2_OBJECT.
" font

TABLES: SPFLI.

DATA
H TYPE I.

* table of flights

DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.

*&---------------------------------------------------------------------*

*&
Event START-OF-SELECTION

*&---------------------------------------------------------------------*

START-OF-SELECTION.

* read flights


SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.

* display header


ULINE (61).


WRITE: /
SY-VLINE NO-GAP,


(3)
'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,


(4)
'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,


(20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,


(20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,


(8)
'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.


ULINE (61).

* display flights


LOOP AT IT_SPFLI.


WRITE: / SY-VLINE NO-GAP,


IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,


IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,


IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,


IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,


IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.


ENDLOOP.


ULINE (61).

* tell user what is going on


CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'


EXPORTING

*
PERCENTAGE = 0


TEXT
= TEXT-007


EXCEPTIONS

OTHERS
= 1.

* start Excel


CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.


PERFORM ERR_HDL.


SET PROPERTY OF H_EXCEL
'Visible' = 1.


PERFORM ERR_HDL.

* tell user what is going on


CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'


EXPORTING

*
PERCENTAGE = 0


TEXT
= TEXT-008


EXCEPTIONS


OTHERS
= 1.

* get list of workbooks, initially empty


CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.


PERFORM ERR_HDL.

* add a new workbook


CALL METHOD OF H_MAPL 'Add' = H_MAP.


PERFORM ERR_HDL.

* tell user what is going on


CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'


EXPORTING

*
PERCENTAGE = 0


TEXT
= TEXT-009


EXCEPTIONS



OTHERS
= 1.

* output column headings to active Excel sheet


PERFORM FILL_CELL USING 1 1 1 'Flug'(001).


PERFORM FILL_CELL USING 1 2 1 'Nr'(002).


PERFORM FILL_CELL USING 1 3 1 'Von'(003).


PERFORM FILL_CELL USING 1 4 1 'Nach'(004).


PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).


LOOP AT IT_SPFLI.

* copy flights to active EXCEL sheet


H = SY-TABIX + 1.


PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.


PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.


PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.


PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.


PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.


ENDLOOP.

* disconnect from Excel


FREE OBJECT H_EXCEL.
“释放对象


PERFORM ERR_HDL.

*---------------------------------------------------------------------*

*
FORM FILL_CELL
*

*---------------------------------------------------------------------*

*
sets cell at coordinates i,j to value val boldtype bold
*

*---------------------------------------------------------------------*

FORM FILL_CELL USING I J BOLD VAL.


CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.


PERFORM ERR_HDL.


SET PROPERTY OF H_ZL 'Value' = VAL .


PERFORM ERR_HDL.


GET PROPERTY OF H_ZL 'Font' = H_F.


PERFORM ERR_HDL.


SET PROPERTY OF H_F 'Bold' = BOLD .


PERFORM ERR_HDL.

ENDFORM.

*&---------------------------------------------------------------------*

*&
Form
ERR_HDL

*&---------------------------------------------------------------------*

*
outputs OLE error if any
*

*----------------------------------------------------------------------*

FORM ERR_HDL.

IF SY-SUBRC <> 0.


WRITE: / 'Fehler bei OLE-Automation010), SY-SUBRC.


STOP.

ENDIF.

ENDFORM.
" ERR_HDL
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/30 03:24 , Processed in 0.015009 second(s), 14 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表