abap ole问题。大家帮忙啊,江湖救急!!!
DATA: L_LINES TYPE I.FIELD-SYMBOLS <FS> TYPE ANY.
DATA:CNT_ROW TYPE I,
CNT_COLUM TYPE I,
OLE_SELCELL TYPE OLE2_OBJECT,
OLE_EXCEL TYPE OLE2_OBJECT,
OLE_RANGE TYPE OLE2_OBJECT,
OLE_WORKBOOKS1 TYPE OLE2_OBJECT,
OLE_WORKBOOK1 TYPE OLE2_OBJECT,
OLE_WORKSHEETS1 TYPE OLE2_OBJECT,
OLE_WORKSHEET1 TYPE OLE2_OBJECT,
OLE_WK TYPE OLE2_OBJECT.
DATA: CNT_SHEETS TYPE I.
DATA: WK_NAME(50) TYPE C.
DATA: WK_INDEX TYPE I.
CREATE OBJECT OLE_EXCEL 'Excel.Application'.
* EXCEL属性を設定する
SET PROPERTY OF OLE_EXCEL 'Visible' = 1.
* SET PROPERTY OF OLE_EXCEL 'ScreenUpdating' = 0.
* SET PROPERTY OF OLE_EXCEL 'Interactive' = 0.
* EXCELファイルをオープンする
*------BOOKS
CALL METHOD OF OLE_EXCEL 'Workbooks' = OLE_WORKBOOKS1.
CALL METHOD OF OLE_WORKBOOKS1 'OPEN' = OLE_WORKBOOK1
EXPORTING
#1 = 'C:\5.XLS'.
CALL METHOD OF OLE_WORKBOOK1 'Sheets' = OLE_WORKSHEETS1.
GET PROPERTY OF OLE_WORKSHEETS1 'COUNT' = CNT_SHEETS.
DO CNT_SHEETS TIMES.
CALL METHOD OF OLE_WORKSHEETS1 'Item' = OLE_WK
EXPORTING
#1 = SY-INDEX.
GET PROPERTY OF OLE_WK 'Name' = WK_NAME.
IF WK_NAME = '指示.
MOVE SY-INDEX TO WK_INDEX.
EXIT.
ENDIF.
ENDDO.
IF WK_INDEX IS INITIAL.
CALL METHOD OF OLE_WORKBOOK1 'SAVE'.
CALL METHOD OF OLE_WORKBOOK1 'close'.
SET PROPERTY OF OLE_EXCEL 'DisplayAlerts' = 0.
CALL METHOD OF OLE_EXCEL 'QUIT'.
FREE OBJECT OLE_WORKSHEET1.
FREE OBJECT OLE_WORKSHEETS1.
FREE OBJECT OLE_WORKBOOK1.
FREE OBJECT OLE_WORKBOOKS1.
FREE OBJECT OLE_EXCEL.
MESSAGE E001(ZMSG_TEST).
EXIT.
ENDIF.
CALL METHOD OF OLE_WORKSHEETS1 'Item' = OLE_WORKSHEET1
EXPORTING
#1 = WK_INDEX.
CALL METHOD OF OLE_WORKSHEET1 'Activate'.
LOOP AT TBL_9200 .
CNT_ROW = CNT_ROW + 1 .
CLEAR:CNT_COLUM.
DO 16 TIMES.
CNT_COLUM = CNT_COLUM + 1.
ASSIGN COMPONENT CNT_COLUM OF STRUCTURE TBL_9200 TO <FS>.
CALL METHOD OF OLE_EXCEL 'Cells' = OLE_SELCELL
EXPORTING
#1 = CNT_ROW
#2 = CNT_COLUM.
SET PROPERTY OF OLE_SELCELL 'FormulaR1C1' = <FS>.
FREE OBJECT OLE_SELCELL.
ENDDO.
ENDLOOP.
CALL METHOD OF OLE_WORKBOOK1 'SAVE'.
CALL METHOD OF OLE_WORKBOOK1 'close'.
SET PROPERTY OF OLE_EXCEL 'DisplayAlerts' = 0.
CALL METHOD OF OLE_EXCEL 'QUIT'.
FREE OBJECT OLE_WORKSHEET1.
FREE OBJECT OLE_WORKSHEETS1.
FREE OBJECT OLE_WORKBOOK1.
FREE OBJECT OLE_WORKBOOKS1.
FREE OBJECT OLE_EXCEL.
上面是我程序的一个片断,红色的部分如果加上的话,OLE进程不能杀死,如果去掉,进程可以杀掉,但是那是程序的赋值部分,
现在我调试的时候发现,就是给CELL赋值的时候出现问题,请问各位如何解决,小弟很郁闷。
--------------------编程问答-------------------- 顶一下,刚开始了解 --------------------编程问答-------------------- 我还没有写过code呢,帮你顶一下!!!! --------------------编程问答-------------------- 你代码写得很乱,没心思看你写些什么,“进程可以杀死”是什么东东,术语太强了不懂
红色字体下那句不用每次循环都释放对象的,把它放到循环外吧 --------------------编程问答-------------------- 你把Free改成refresh试试看? --------------------编程问答-------------------- 接分先! --------------------编程问答-------------------- --------------------编程问答--------------------
*&---------------------------------------------------------------------*
*& Form read_serverfile_to_local
*&---------------------------------------------------------------------*
* text 读读服务器上文件并下载到本地
*----------------------------------------------------------------------*
* -->F_NAME text 服务器路径+文件名
* -->F_DIR text 本地文件名 利用CHARGING 回写 f_local_file
*----------------------------------------------------------------------*
FORM read_serverfile_to_local USING f_server_file TYPE c CHANGING f_local_file TYPE string .
DATA: f_itab TYPE TABLE OF x WITH HEADER LINE.
DATA: f_length TYPE i.
DATA:f_name LIKE epsf-epsfilnam, "类型参考 函数 EPS_GET_FILE_ATTRIBUTES
f_dir LIKE epsf-epsdirnam.
DATA:o_dir TYPE string,
o_name TYPE string.
DATA: f_11 TYPE sy-fdpos.
DATA: f_itabnew TYPE TABLE OF string.
SPLIT f_server_file AT '\' INTO TABLE f_itabnew."分离字符串到内表
LOOP AT f_itabnew INTO o_name."读到最后一个 \
* WRITE / o_name.
ENDLOOP.
SEARCH f_server_file FOR o_name.
IF sy-subrc = 0.
f_11 = sy-fdpos.
o_dir = f_server_file+0(f_11).
ENDIF.
f_dir = o_dir."请注意本步转换
f_name = o_name.
****读服务器上文件到内表********************
OPEN DATASET f_server_file FOR INPUT IN BINARY MODE.
DO.
READ DATASET f_server_file INTO f_itab.
IF sy-subrc <> 0 .
EXIT.
ENDIF.
APPEND f_itab.
ENDDO.
****计算下载文件大小********************
CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'
EXPORTING
file_name = f_name "str_name_new " '出口统计.xls' "类型:epsf-epsfilnam
dir_name = f_dir "str_dir_new " "'\usr\sap\ids\dvebmgs00\log\' "类型:epsf-epsdirnam
IMPORTING
file_size = f_length
* FILE_OWNER =
* FILE_MODE =
* FILE_TYPE =
* FILE_MTIME =
* FILE_SIZE_LONG =
EXCEPTIONS
read_directory_failed = 1
read_attributes_failed = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*连接字符串组成文件路径 用户本地TEMP路径+文件名
CONCATENATE g_user_file_path '\' o_name INTO o_name.
f_local_file = o_name.
g_sql = f_local_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = f_length "56018
filename = f_local_file "'d:\9_new.xls' "str_name "
filetype = 'BIN'
TABLES
data_tab = f_itab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
***************************************************************************
ENDFORM. "read_serverfile_to_local
*& Form write_to_local_excel
*&---------------------------------------------------------------------*
* text 打开EXCEL,并将将数据写回EXCEL
* f_table 存放需要替换的内容组成的内表 f_local_file 本地指定的EXCEL文件
*----------------------------------------------------------------------*
FORM write_to_local_excel TABLES f_table STRUCTURE alsmex_tabline USING f_local_file LIKE rcgfiletr-ftfront.
Create OBJECT excel 'EXCEL.APPLICATION'. "Create EXCEL OBJECT
IF sy-subrc NE 0.
EXIT.
ENDIF.
SET PROPERTY OF excel 'Visible' = 1. "是否显示EXCEL
CALL METHOD OF excel 'Workbooks' = workbook.
DATA h TYPE i.
CALL METHOD OF workbook 'Open'
EXPORTING
#1 = f_local_file.
CALL METHOD OF excel 'Sheets' = sheet
EXPORTING
#1 = 1.
CALL METHOD OF sheet 'Select' .
WRITE:/,'写入固定数据'.
*填充
* PERFORM fill_range USING 8 1 g_sql ."'100'. "第8行第1列
* PERFORM fill_range USING 2 1 '20' ."'100'. "第2行第1列
* PERFORM fill_range USING 2 2 '-4' ."'100'. "第2行第2列
LOOP AT f_table.
PERFORM fill_range USING f_table-row f_table-col f_table-value ." "在这框的下面10列显示结果
WRITE:/,'写入数据:','行:',f_table-row ,'列:',f_table-col,'值',f_table-value.
ENDLOOP.
GET PROPERTY OF excel 'ActiveWorkbook' = sheet.
* CALL METHOD OF sheet 'printout'. "打印
* CALL METHOD OF excel 'SAVE'. "保存
* CALL METHOD OF excel 'Quit'. "退出
FREE OBJECT cell.
FREE OBJECT range.
FREE OBJECT sheet.
FREE OBJECT workbook.
FREE OBJECT excel.
ENDFORM. "write_to_local_excel
*&---------------------------------------------------------------------*
*& Form fill_range
*&---------------------------------------------------------------------*
* text 填充EXCEL 单元格
*----------------------------------------------------------------------*
* -->VALUE(F_ROW) text
* -->VALUE(F_COL) text
* -->VALUE(F_VALUE) text
*----------------------------------------------------------------------*
FORM fill_range USING value(f_row)
value(f_col)
value(f_value).
DATA:
row TYPE i,
col TYPE i.
row = f_row.
col = f_col.
CALL METHOD OF excel 'CELLS' = cell
EXPORTING
#1 = row
#2 = col.
SET PROPERTY OF cell 'VALUE' = f_value.
ENDFORM. "fill_range
*&---------------------------------------------------------------------*
*& Form Get_data_to_innerTable
*&---------------------------------------------------------------------*
* text 打开本地EXCEL文件 并传递到内表
*----------------------------------------------------------------------*
FORM get_data_to_innertable TABLES f_tab STRUCTURE alsmex_tabline USING f_file_name LIKE rlgrap-filename.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = f_file_name
i_begin_col = 1
i_begin_row = 1
i_end_col = 100
i_end_row = 30000
TABLES
intern = f_tab"gt_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
SORT gt_data BY row col value."按行,列排序
ENDFORM. "Get_data_to_innerTable
--------------------编程问答--------------------
你红色代码下的
FREE OBJECT OLE_SELCELL.
这个要注释掉吧,不然应该有错。。。
--------------------编程问答-------------------- 诚聘IT兼职教师
北京思源培训中心诚聘既有教学经验又开发经验的兼职教师,
待遇优厚
兼职高级讲师若干
1. MS.NET讲师(主讲.NET 系列课程asp.net, C#)
2. JAVA讲师 (主讲JAVA,JSP,J2EE等)
3. MS SQL Server讲师(主讲MS SQL Server课程)
4. Oracle 讲师(主讲 Oracle 系列课程)
5.软件测试讲师(主讲软件测试课程)
5. VC++讲师 (主讲VC++,C++等)
6. LINUX/UNIX讲师(主讲LINUX / UNIX 系列课程)
7.IBM Aix /SUN Solaris讲师(主讲系统管理和维护)
8. Office讲师(精通办公软件)
9.Ajax讲师(主讲程序设计和WEB高级开发)
10.3DMax讲师(主讲 3DMax 基础和建模)
11.应用服务器weblogic/jboss/websphere
12.网络信息安全技术讲师
联系方式:abc@ciitc.com QQ:174629429 MSN:bjcosun@hotmail.com
网址:http://www.ciitc.com
--------------------编程问答-------------------- 博彦SAP顾问学院,是SAP公司正式授权的培训机构,现已在北京、上海、天津同步开课,正在招生中,当地授课。
FICO SD HR ABAP MM 等多个模块均开始了周末班及全日制班,课程灵活多选。
培训采用全球统一的教材和教学方式,通过正式的考试,合格者可获得德国SAP颁发的认证证书
公司将为缺少项目经验的学员提供实习的机会,并择优录用或推荐到大型IT企业
提前报名或三人以上报名均有优惠
详情请咨询 010-82826580
Email:sap@beyondsoft.com
http://sap.beyondsoft.com
补充:企业软件 , ERP/CRM