BDC备忘
report ZDBC
no standard page heading line-size . data: begin of record,
* data element: MATNR
MATNR_001(), "RMMG1 物料主数据维护:初始参数-原材料 MATNR即物料编号
* data element: XFELD
KZSEL_01_002(), "MSICHTAUSW 视图选择的帮助结构:物料主记录 表 KZSEL复选框
* data element: MAKTX
MAKTX_003(), "物料描述-物料描述(短文本)
* data element: MEINS
MEINS_004(), "常规物料数据-基本计量单位
* data element: MATKL
MATKL_005(), "物料组
* data element: MTPOS_MARA
MTPOS_MARA_006(), "普通项目类别组
end of record. *** End generated data section *** DATA: itab_out LIKE TABLE OF record WITH HEADER LINE. TABLES SSCRFIELDS."用于按键 data: bdcdata like bdcdata occurs with header line."批输入:新表格字段结构 包含bdc的一些屏幕号等内容
data: messtab like bdcmsgcoll occurs with header line. " SAP 系统中的信息表 *** 绘屏 ***
SELECTION-SCREEN begin of block blk with frame title text-.
SKIP .
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON () but1 USER-COMMAND download. " 定义搜索按钮
SELECTION-SCREEN END OF LINE.
SKIP .
parameters:p_typ type ctu_mode obligatory default 'N', "批处理模式
p_file like rlgrap-filename.
SELECTION-SCREEN end of block blk. INITIALIZATION.
PERFORM frm_init_button. "初始化下载模板按钮 AT SELECTION-SCREEN .
IF SSCRFIELDS-UCOMM = 'DOWNLOAD'. " 下载模板按钮响应
PERFORM temp_excel_get USING 'ZBDC_YHY' ."从服务器下载模板
CLEAR SSCRFIELDS-UCOMM.
ENDIF. "为了能有选择文件对话框
at selection-screen on value-request for p_file.
perform frm_select_files. START-OF-SELECTION.
perform frm_get_data. END-OF-SELECTION. "START-OF-SELECTION.执行完 但输出屏幕未显示之前
perform frm_upload_data. *&---------------------------------------------------------------------*
*& Form FRM_SELECT_FILES
*&---------------------------------------------------------------------*
* 选择文件对话框
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SELECT_FILES .
data: l_filetab type filetable,
l_waftab like line of l_filetab,
l_rc type i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '打开文件'
initial_directory = 'C:/'
CHANGING
file_table = l_filetab
rc = l_rc
EXCEPTIONS
file_open_dialog_failed =
cntl_error =
error_no_gui =
not_supported_by_gui =
others = .
if sy-subrc <> .
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit.
else.
"l_filetab是个内表结构,我们现在只能单选,所以只有第一条数据。还可以多选的。
read table l_filetab into l_waftab index .
p_file = l_waftab-filename.
clear: l_filetab,
l_waftab.
endif. ENDFORM. " FRM_SELECT_FILES *&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* 读取excel数据到指定内表
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
data lt_excel type table of alsmex_tabline with header line.
data l_index like sy-tabix.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_row = '' "开始行
i_begin_col = '' "开始列 注意实际需求 改动
i_end_row = ''
i_end_col = ''
TABLES
intern = lt_excel "lt_excel 有3个字段: row col value.即它的一行只存储一个单元格的数据
EXCEPTIONS
inconsistent_parameters =
upload_ole =
others = .
*&& 将EXCEL格式中的数据重新整理导入到内表TAB_LOAD中
loop at lt_excel.
move lt_excel-col to l_index.
case l_index.
when''.
move lt_excel-value to itab_out-MATNR_001.
when''.
move lt_excel-value to itab_out-KZSEL_01_002.
when''.
move lt_excel-value to itab_out-MAKTX_003.
when''.
move lt_excel-value to itab_out-MEINS_004.
when''.
move lt_excel-value to itab_out-MATKL_005.
when''.
move lt_excel-value to itab_out-MTPOS_MARA_006.
endcase. at end of row."设置内表循环触发条件,AT END OF F1: 如果字段F及F的左则全部字段的数据,与下一行数据不一致时,则执行代码。
"这里的row是lt_excel里面的字段 即row=1,2,3,....取完之后才构成完整的一条itab_out数据
append itab_out.
clear: itab_out.
endat.
endloop. ENDFORM. " FRM_GET_DATA *&---------------------------------------------------------------------*
*& Form FRM_UPLOAD_DATA
*&---------------------------------------------------------------------*
* 将内表数据重复bdc录屏操作
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_UPLOAD_DATA .
* DATA: MESS(100) TYPE C. IF ITAB_OUT[] IS INITIAL.
MESSAGE '没有数据!' TYPE 'E'.
ENDIF. LOOP AT itab_out. perform bdc_dynpro using 'SAPLMGMM' ''.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform bdc_field using 'RMMG1-MATNR'
itab_out-MATNR_001.
perform bdc_dynpro using 'SAPLMGMM' ''.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
itab_out-KZSEL_01_002.
perform bdc_dynpro using 'SAPLMGMM' ''.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
itab_out-MAKTX_003.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
itab_out-MEINS_004.
perform bdc_field using 'MARA-MATKL'
itab_out-MATKL_005.
perform bdc_field using 'MARA-MTPOS_MARA'
itab_out-MTPOS_MARA_006.
perform bdc_dynpro using 'SAPLSPO1' ''.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM02' p_typ 'S'. ENDLOOP. ENDFORM. " FRM_UPLOAD_DATA *&---------------------------------------------------------------------*
*& Form BDC_TRANSACTION
*&---------------------------------------------------------------------*
* 执行事务代码 并返回处理结果
*----------------------------------------------------------------------*
* -->P_1128 text
* -->P_1129 text
* -->P_1130 text
*----------------------------------------------------------------------*
form bdc_transaction using tcode p_typ cupdate.
data: l_mstring().
data: l_subrc like sy-subrc..
refresh messtab.
call transaction tcode using bdcdata
mode p_typ
update cupdate "更新模式 f1可看
messages into messtab. if lines( messtab ) > . "如更新一条记录 可能改动多个位置 会有多个消息 我们只要最后一个消息即可
loop at messtab.
if messtab-msgtyp ne 'E' and messtab-msgtyp ne 'S'.
continue.
endif.
select single text from t100 into l_mstring
where sprsl = messtab-msgspra
and arbgb = messtab-msgid
and msgnr = messtab-msgnr.
if sy-subrc = .
if l_mstring cs '&1'. "Contains String: True, if the content of operand2 is contained in operand1.
replace '&1' with messtab-msgv1 into l_mstring.
replace '&2' with messtab-msgv2 into l_mstring.
replace '&3' with messtab-msgv3 into l_mstring.
replace '&4' with messtab-msgv4 into l_mstring.
else.
replace '&' with messtab-msgv1 into l_mstring.
replace '&' with messtab-msgv2 into l_mstring.
replace '&' with messtab-msgv3 into l_mstring.
replace '&' with messtab-msgv4 into l_mstring.
endif.
condense l_mstring.
write: / itab_out-MATNR_001,l_mstring.
CLEAR: itab_out.
endif.
endloop.
endif.
refresh bdcdata. endform. " BDC_TRANSACTION *&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata. endform. " BDC_DYNPRO *&----------------------------------------------------------------
form bdc_field using fnam fval.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endform. " BDC_FIELD *&---------------------------------------------------------------------*
*& Form FRM_INIT_BUTTON
*&---------------------------------------------------------------------*
* 初始化按钮 为按钮添加图标和文本
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_INIT_BUTTON .
CALL FUNCTION 'ICON_CREATE'
EXPORTING
NAME = 'ICON_DOCUMENT'
TEXT = '下载模板'
* INFO = ' '
* ADD_STDINF = 'X'
IMPORTING
RESULT = but1
* EXCEPTIONS
* ICON_NOT_FOUND = 1
* OUTPUTFIELD_TOO_SHORT = 2
* OTHERS = 3
.
IF SY-SUBRC <> .
* Implement suitable error handling here
ENDIF. ENDFORM. " FRM_INIT_BUTTON *下载EXCEL模板FORM
*----------------------------------------------------------------------*
* -->VALUE(templat) 上传的excel模板名
* <--VALUE(ls_destination) 返回excel文件模板对象
*
*----------------------------------------------------------------------*
FORM temp_excel_get USING template TYPE any.
DATA: lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
lc_filename TYPE string VALUE 'dbc',"默认名
lc_fullpath TYPE string , "C:\Users\yang\Desktop\文件名
lc_path TYPE string , "C:\Users\yang\Desktop\ 不包括文件名
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
DATA:p_objid TYPE wwwdatatab-objid,
p_dest LIKE sapb-sappfad.
p_objid = template.
CONCATENATE lc_filename '_' SY-DATUM '_' SY-UZEIT
INTO lc_filename. "给模板命名
CALL METHOD cl_gui_frontend_services=>file_save_dialog "调用保存对话框
EXPORTING
default_extension = 'XLS'
default_file_name = lc_filename
CHANGING
filename = lc_filename
path = lc_path
fullpath = lc_fullpath
EXCEPTIONS
cntl_error =
error_no_gui =
not_supported_by_gui =
OTHERS = .
IF lc_fullpath = ''.
MESSAGE '不能打开excel' TYPE 'E'.
ENDIF.
IF sy-subrc = .
p_dest = lc_fullpath.
* concatenate p_objid '.XLS' into ls_objnam.
CONDENSE ls_objnam NO-GAPS.
SELECT SINGLE relid objid FROM wwwdata INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = AND relid = 'MI' AND objid = p_objid. *检查表wwwdata中是否存在所指定的模板文件
IF sy-subrc NE OR lo_objdata-objid EQ space."如果不存在,则给出错误提示
CONCATENATE '模板文件' ls_objnam '不存在' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'I'.
ENDIF.
ls_destination = p_dest. "保存路径 *如果存在,调用DOWNLOAD_WEB_OBJECT 函数下载模板到路径下
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = li_rc.
IF li_rc NE .
CONCATENATE '模板文件:' ls_objnam '下载失败' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'E'.
ENDIF.
p_file = ls_destination. "fname 全局 注意
ENDIF.
ENDFORM. "fm_excel
BDC备忘的更多相关文章
- GIS部分理论知识备忘随笔
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.高斯克吕格投影带换算 某坐标的经度为112度,其投影的6度带和3度带 ...
- python序列,字典备忘
初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...
- Vi命令备忘
备忘 Ctrl+u:向文件首翻半屏: Ctrl+d:向文件尾翻半屏: Ctrl+f:向文件尾翻一屏: Ctrl+b:向文件首翻一屏: Esc:从编辑模式切换到命令模式: ZZ:命令模式下保存当前文件所 ...
- ExtJs4常用配置方法备忘
viewport布局常用属性 new Ext.Viewport({ layout: "border", renderTo: Ext.getBody(), defaults: { b ...
- [备忘] Automatically reset Windows Update components
这两天遇到Windows 10的更新问题,官方有一个小工具,可以用来修复Windows Update的问题,备忘如下 https://support.microsoft.com/en-us/kb/97 ...
- ECMAScript 5(ES5)中bind方法简介备忘
一直以来对和this有关的东西模糊不清,譬如call.apply等等.这次看到一个和bind有关的笔试题,故记此文以备忘. bind和call以及apply一样,都是可以改变上下文的this指向的.不 ...
- MFC通过txt查找文件并进行复制-备忘
MFC基于对话框的Demo txt中每行一个23位的卡号. 文件夹中包含以卡号命名的图像文件.(fpt或者bmp文件) 要求遍历文件夹,找到txt中卡号所对应的图像文件,并复制出来. VC6.0写的. ...
- php 相关模块备忘
在安装php的时候,不管是编译安装: ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc -- ...
- 『备忘』HttpWebRequest 在 POST 提交时, 标头(Headers)丢失原因
近来研究 HttpWebRequest —— 辅助类完成时,POST JSON数据 总会 丢失标头(Headers). HttpWebRequest POST JSON数据,分如下几步: > 将 ...
随机推荐
- 深入学习webpack(二)
深入学习webpack(二) 在深入学习webpack(一)中,我通过一个例子介绍了webpack的基本使用方法,下面将更为系统的学习webpack的基本概念,对于一门技术的掌握我认为系统化还是很重要 ...
- Spring Cloud学习笔记之微服务架构
目录 什么是微服务 架构优点 架构的挑战 设计原则 什么是微服务 微服务构架方法是以开发一种小型服务的方式,来开发一个独立的应用系统的. 其中每个小型服务都运行在自己的进程中,并经常采 ...
- 我使用的brackets插件
livereload atom dark theme autoprefixer auto save files on window blur beautify brackets file icons ...
- mysql操作命令梳理(3)-pager
在mysql日常操作中,妙用pager设置显示方式,可以大大提高工作效率.比如select出来的结果集超过几个屏幕,那么前面的结果一晃而过无法看到,这时候使用pager可以设置调用os的more或者l ...
- fillder script使用
打开fiddler script editor 在fiddler中Rules -> Customize Rules打开 在editor中点击open, 打开CustomRules.js文件, 对 ...
- ejs判断变量是否为空并输出
在ejs里输出变量如下: <%=errmsg%> 但如果errmsg变量不存在则会报错:errmsg is undefined 我们可以改为: <%=locals.errmsg || ...
- 关于web.xml的welcome-file-list 配置与tomcat的关系:
关于web.xml的welcome-file-list 配置与tomcat的关系: 2018年04月18日 10:17:13 守望dfdfdf 阅读数:377 标签: welcome-file-lis ...
- Mincost
The cost of taking a taxi in Hangzhou is not a constant for each kilometer you travel: the first 4 k ...
- tp3.2水印上传文件
<html> <html lang="en"><head> <meta charset="UTF-8"> ...
- 安装office提示Office 16 Click-to-Run Extensibility Component
今天安装office时,提示Office 16 Click-to-Run Extensibility Component或者Office 15 Click-to-Run Extensibility C ...