ABAP DOI详解(3)
这一篇解决上一篇的几个遗留问题:
- 如何根据屏幕大小让Excel自适应
- Excel单个单元格写入
- 设置Excel属性
- 错误处理
如何根据屏幕大小让Excel自适应
Dialog screen中的custom control大小是固定的,比较难看。如果想让Excel自适应变更大小,要用cl_gui_container
类。
增加一个新的子例程:
data: gr_container type ref to cl_gui_container,gr_splitter type ref to cl_gui_splitter_container,...form get_dynamic_container.create object gr_splitterexportingparent = cl_gui_container=>screen0rows = 1columns = 1 .call method gr_splitter->set_borderexportingborder = cl_gui_cfw=>false.gr_container = gr_splitter->get_container( row = 1 column = 1 ).
endform.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
同样地,Container control初始化的时候,设定parent为gr_container :
form create_container_control.
* create container controlcall method c_oi_container_control_creator=>get_container_controlimportingcontrol = gr_control.* initialize controlcall method gr_control->init_controlexportinginplace_enabled = 'X 'inplace_scroll_documents = 'X'register_on_close_event = 'X'register_on_custom_event = 'X'r3_application_name = 'DOI demo by Stone Wang'parent = gr_container.
endform.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
这样,Excel就能根据屏幕变更大小,是不是漂亮多了呢?
Excel单个单元格写入
单个单元格写入的方法,同批量写入一样,使用i_oi_spreadsheet
接口的set_range_dim
方法和set_range_data
方法。区别在于range只包含一行一列:
form write_single_cell using p_row p_col p_value.
* define internal table for ranges and contents parametersdata: lt_ranges type soi_range_list,ls_rangeitem type soi_range_item,lt_contents type soi_generic_table,ls_content type soi_generic_item.* populate rangesclear ls_rangeitem.clear lt_ranges[].ls_rangeitem-name = 'cell' .ls_rangeitem-columns = 1.ls_rangeitem-rows = 1.ls_rangeitem-code = 4.append ls_rangeitem to lt_ranges.* populate contentsclear ls_content.clear lt_contents[].ls_content-column = 1.ls_content-row = 1.ls_content-value = p_value.append ls_content to lt_contents.* 每次只写一行一列call method gr_spreadsheet->insert_range_dimexportingname = 'cell'no_flush = 'X'top = p_rowleft = p_colrows = 1columns = 1.call method gr_spreadsheet->set_ranges_dataexportingranges = lt_rangescontents = lt_contentsno_flush = 'X'.
endform.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
假如我们要把gt_spfli的数据写入Excel,可以这样:
form write_itab_to_excel_singlecell.data: row_index type i.check not gt_spfli is initial.clear gs_spfli.loop at gt_spfli into gs_spfli.row_index = sy-tabix + 1.perform write_single_cell using row_index 1 gs_spfli-carrid.perform write_single_cell using row_index 2 gs_spfli-connid.perform write_single_cell using row_index 3 gs_spfli-cityfrom.perform write_single_cell using row_index 4 gs_spfli-cityto.clear gs_spfli.endloop.row_index = row_index + 1.perform write_single_cell using row_index 1 sy-uname.perform write_single_cell using row_index 2 sy-datum.endform.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
设置Excel属性
我们刚刚把spfli的数据写入到Excel,假设我们想把工作表的名称改为spfli,并且将数据(注意我们写入的时候定义了range name为cell)区设置边框,列大小根据数据自适应我们可以这样:
form set_excel_attributes.
* change name of Sheet1 to 'spfli'call method gr_spreadsheet->set_sheet_nameexportingnewname = 'spfli'oldname = 'Sheet1'.* set border line for rangecall method gr_spreadsheet->set_frameexportingrangename = 'cell'typ = '127'color = '1'no_flush = 'X'.* auto fitcall method gr_spreadsheet->fit_widestexportingname = spaceno_flush = 'X'.
endform.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
i_oi_spreadsheet接口的方法和如何使用这些方法,请参考帮助:Using the spreadsheet interface。
错误处理
与Office集成的错误是非常复杂的,因为涉及外部资源的通讯和处理。调用i_oi_spreadsheet
接口的方法后,必须弄清楚调用是否成功。前面几篇的演示代码故意没有涉及错误的处理,是为了让代码更容易理解。每一个方法都有一个ret_code
参数,如果有错误,返回错误码,没有错误则返回OK
。在程序中,开发人员可以用c_oi_errors
类中定义的常量来代表这些错误码或者没有错误的OK。请移步至SAP help了解这些常量:Error Messages and Their Meanings。
在程序中,通常有两种方法来处理错误,第一种方法:使用c_oi_errors
的静态方法raise_message
简单地显示相关的错误:
CALL METHOD C_OI_ERRORS=>RAISE_MESSAGE
EXPORTING TYPE = type
- 1
- 2
- 1
- 2
type可以是A/E/W/I/S。
第二种方法是区分不同的错误,给用户一个更明确的提示:
IF ret_code EQ c_oi_errors=>ret_ok." Document opened successfully
ELSEIF ret_code EQ c_oi_errors=> ret_document_already_open." Special error handling, e.g. dialog box.
ELSE.
CALL METHOD c_oi_errors=>raise_message
EXPORTING type = 'E'.
ENDIF.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
因为Excel操作多个步骤,为了在过程中间减少对用户的干扰,也可以把ret_code返回的错误码先储存在内表中,集中处理:
DATA: errors TYPE REF TO i_oi_error OCCURS 0 WITH HEADER LINE.# DOI processing
CALL METHOD control->get_link_serverEXPORTING server_type = server_typeno_flush = 'X'IMPORTING link_server = link_serverretcode = retcodeerror = errors.
APPEND errors.LOOP AT errors. CALL METHOD errors->raise_messageEXPORTING type = 'E'EXCEPTIONS message_raised = 1flush_failed = 2. ENDLOOP.
FREE errors.
ABAP DOI详解(3)相关推荐
- ABAP DOI详解(2)
我们之所以用Excel输出,主要是想用Excel在显示中的优势,所以最常见的做法,往往调用Excel模板文件来实现.这一篇,我们就来操作Excel模板文件,另外,excel文档放在dialog scr ...
- 详解ABAP Selection Screens
转载自大神 jevinxu:详解ABAP Selection Screens: http://www.sapjx.com/abap-selection-screen.html ABAP Sele ...
- 【SAP Abap】BOM多级展开函数 CS_BOM_EXPL_MAT_V2 使用详解
SAP ABAP BOM多级展开函数 CS_BOM_EXPL_MAT_V2 使用详解 1.函数入参说明 2.函数出参说明 1.函数入参说明 CALL FUNCTION 'CS_BOM_EXPL_MAT ...
- 一文弄懂元学习 (Meta Learing)(附代码实战)《繁凡的深度学习笔记》第 15 章 元学习详解 (上)万字中文综述
<繁凡的深度学习笔记>第 15 章 元学习详解 (上)万字中文综述(DL笔记整理系列) 3043331995@qq.com https://fanfansann.blog.csdn.net ...
- endnotex7怎么导入中文文献_EndNote X7自动导入PDF功能详解 | 科研动力
在Endnote X7 新功能简介一文中对于EndNote X7的自动导入PDF功能作了一简要介绍,但是有些人对于EndNote自动导入PDF的功能还是有疑问,本文就EndNote如何自动导入PDF功 ...
- SAP UI5 初学者教程之二十六 - OData 服务配合 Mock 服务器的使用步骤详解试读版
一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 初学者教程之一:Hello World SAP UI5 初学者教程之二:SAP UI5 ...
- 一文详解宏基因组组装工具Megahit安装及应用
要点 Megahit简介 Megahit的基本组装原理 Megahit的安装和使用 Megahit实战 hello,大家好,今天为大家带来关于宏基因组组装工具Megahit的超详细安装及应用教程. 我 ...
- NEXT社区小课堂 | 第四课:dBFT 2.0详解 | 委托拜占庭容错:技术细节、挑战和前景...
NEXT社区 | 小课堂 由于近期NEXT社区加入很多新的小伙伴,有在校大学生,有对区块链感兴趣的传统企业从业者.为了更方便.更系统的让NEXT社区的伙伴们了解NEO的技术知识,因此我们开设了小课堂, ...
- R统计绘图-PCA详解1(princomp/principal/prcomp/rda等)
此文为<精通机器学习:基于R>的学习笔记,书中第九章详细介绍了无监督学习-主成分分析(PCA)的分析过程和结果解读. PCA可以对相关变量进行归类,从而降低数据维度,提高对数据的理解.分析 ...
最新文章
- javascript功能_功能性JavaScript简介
- 【转】每天一个linux命令(34):du 命令
- 记录去大搜车的一道笔试题
- 【ArcGIS Pro微课1000例】0007:ArcGIS Pro 2.5质量检查:拓扑创建与编辑案例教程
- shell编程之进阶篇二常见运算符号
- python--修改默认递归层级
- IntelliJ IDEA打jar时,MANIFEST.MF内容出错
- 【转载】linux环境下大数据网站搬家
- R语言本地安装包教程
- 单片机矩阵键盘扫描程序c语言,51单片机矩阵键盘扫描程序详解
- python实现3d建模工具_Python实现3D建模工具
- 201903股票投资与实践入门三:资金流向与K线入门
- win10计算机加域步骤,Windows域是什么|win10系统加入域的详细步骤
- 并发调度的可串行性:可串行化调度、冲突可串行化调度、两段锁协议
- 一款app 开发在线工具:app inventor
- 考研日语线上笔记(八):完型易混易考知识点梳理篇
- 2019年1月1日起,国家推出新的个人所得税政策,起征点上调值5000元。也就是说税前工资扣除五险一金(五险一金数额假设是税前工资的10%) * 后如果不足5000元,则不交税。
- C#实战项目~智能图书管理系统
- 电子阅览室使用云终端解决方案的重要性
- GoEXP规则变更通知 l 信创额外奖励活动