ZPPR101-批量更改BOM组件
***********************************************************************
* Title : ZPPR101 *
* Application : PP *
* Subject : 批量更改BOM组件 *
* Requested by : PP *
* Execution : any time *
* Ref no: : B221 *
* Author : rainy *
* Req Date : 20150701 *
***********************************************************************
* Production Order Variance Report *
***********************************************************************
***********************************************************************
*1.取数: Excel 上传数据并对数据bom 批量更改BOM组件
*2.输出: *
***********************************************************************
* MODIFICATIONS (latest entry at the top) *
* ------------------------------------------------------------------- *
* REL DATE NAME (COMPANY) DESCRIPTION TASK-NO *
* --- ---- ---- --------- ----------- ------- *
* *
***********************************************************************
REPORT zppr101 MESSAGE-ID zmm_001.
TABLES:marc,
stpo,
sscrfields..
DATA:BEGIN OF it_text,
matnr LIKE marc-matnr,
werks LIKE marc-werks,
idnrk LIKE stpo-idnrk,"原始组件
idnrk_n LIKE stpo-idnrk,"更改值
meins LIKE stpo-meins,"更改单位
text TYPE string,
zicon TYPE char4,
END OF it_text.
DATA:gt_text LIKE TABLE OF it_text WITH HEADER LINE,
wa_text LIKE gt_text.
*----------------------------------------------------------------------
* Data parameters for alv report use
*----------------------------------------------------------------------
DATA: g_program TYPE sy-repid,
gw_layout TYPE slis_layout_alv,
gt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
gt_event TYPE slis_t_event,
wa_event TYPE slis_alv_event.
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
DATA l_len TYPE i.
************************************************************************
* Select Screen *
************************************************************************
*SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001 . "'请指定选择条件'.
*"BOM 选择条件
*PARAMETERS p_plant LIKE csap_mbom-werks.
*PARAMETERS p_usage LIKE csap_mbom-stlan.
*PARAMETERS p_alt LIKE csap_mbom-stlal.
*PARAMETERS p_datuv LIKE csap_mbom-datuv .
*SELECTION-SCREEN END OF BLOCK block1.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE t1. " '请指定本地EXCEL文件'
PARAMETERS: p_name LIKE rlgrap-filename." OBLIGATORY.
SELECTION-SCREEN END OF BLOCK block2.
SELECTION-SCREEN FUNCTION KEY 1.
INITIALIZATION. " 初始化选择屏上的变量
t1 = '导入数据'.
sscrfields-functxt_01 = '下载导入模板'.
AT SELECTION-SCREEN.
*&下载模板
PERFORM frm_download_template.
*&读取文件
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.
PERFORM getdata USING p_name.
* CALL FUNCTION 'WS_FILENAME_GET'
* EXPORTING
* def_path = 'C:\'
* mask = ',DAT(*.DATA),*.DAT.'
*
"MASK = ',Excel文件(*.XLS),*.XLS.'
** MODE = 'O'
** TITLE = ' '
* IMPORTING
* filename = p_name
** RC =
* EXCEPTIONS
* inv_winsys = 1
* no_batch = 2
* selection_cancel = 3
* selection_error = 4
* OTHERS = 5.
*&---------------------------------------------------------------------*
*& 主程序
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&对工厂操作权限检查
* PERFORM plant_authority_check USING p_plant.
*&S1.读取EXCEL 数据
PERFORM frm_get_excel.
*&S2.更改BOM
PERFORM frm_maintain_bom.
*&S3.list
PERFORM frm_alv_grid.
*&---------------------------------------------------------------------*
*& Form PLANT_AUTHORITY_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PLANT text
*----------------------------------------------------------------------*
FORM plant_authority_check USING p_werks.
* AUTHORITY-CHECK OBJECT 'C_STUE_WRK'
* ID 'ACTVT' FIELD '03'
* ID 'CSWRK' FIELD p_werks.
*
* IF sy-subrc <> 0.
* MESSAGE e001(00) WITH '你没有工厂 ' p_werks ' 的权限.'.
* ENDIF.
ENDFORM. "PLANT_AUTHORITY_CHECK
*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_download_template .
DATA: ls_key TYPE wwwdatatab,
lv_temp TYPE c,
lv_file TYPE string VALUE '\ZP101.xlsx',
lv_filepath TYPE rlgrap-filename,
lv_result TYPE abap_bool,
lv_path TYPE string,
lv_msg TYPE string.
DATA:l_rc TYPE sy-subrc.
TRANSLATE lv_msg TO UPPER CASE.
*REPLACE
* REPLACE [{first occurrence}|{all occurrences} OF] PATTERN
* IN [section_of] dobj WITH NEW
* [IN {character|BYTE} MODE]
* [replace_options].
CASE sscrfields-ucomm.
WHEN 'FC01'.
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = '选择文件目录'
* initial_folder = 'C:\TEMP'
CHANGING
selected_folder = lv_path
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
CONCATENATE lv_path lv_file INTO lv_file.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = lv_file
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lv_result = 'X'.
CONCATENATE '模板' lv_file '已存在!' INTO lv_msg.
MESSAGE lv_msg TYPE 'S'.
STOP.
ELSE.
ls_key-relid = 'MI'.
ls_key-objid = 'ZP101'. "SMW0定义的对象名称
lv_filepath = lv_file.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = ls_key
destination = lv_filepath
IMPORTING
rc = l_rc.
IF l_rc <> 0.
MESSAGE '下载模板失败!' TYPE 'E'.
ELSE.
MESSAGE s000 WITH '成功下载模板至目录:' lv_filepath.
ENDIF.
ENDIF.
ENDIF.
ENDCASE.
ENDFORM. " FRM_DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*& Form FRM_GET_EXCEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_excel .
DATA:BEGIN OF i_excel OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA:END OF i_excel.
DATA:l_answer(1) TYPE c,
l_culumn TYPE i,
l_pathname LIKE rlgrap-filename.
FIELD-SYMBOLS:<fs>.
DATA:it_raw TYPE truxs_t_text_data.
*&文件名赋值l_pathname.
MOVE p_name TO l_pathname.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw
i_filename = l_pathname
TABLES
i_tab_converted_data = gt_text.
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF gt_text[] IS INITIAL.
CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
EXPORTING
* DEFAULTOPTION = 'Y'
diagnosetext1 = 'No data in excel'
* DIAGNOSETEXT2 = ' '
* DIAGNOSETEXT3 = ' '
textline1 = 'No data in excel'
* TEXTLINE2 = ' '
titel = 'Confirm'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
IMPORTING
answer = l_answer.
*&OUT
EXIT.
ENDIF.
ENDIF.
ENDFORM. " FRM_GET_EXCEL
*&---------------------------------------------------------------------*
*& Form FRM_MAINTAIN_BOM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_maintain_bom .
DATA:lv_line TYPE string,
lv_false TYPE c.
DATA:lt_stpo TYPE STANDARD TABLE OF stpo_api02 WITH HEADER LINE.
DATA:
it_stpo TYPE TABLE OF stpo_api03,
is_stpo TYPE stpo_api03,
is_stko TYPE stko_api01,
lt_stko TYPE TABLE OF stko_api02,
ls_stpo TYPE stpo_api02,
ls_stko TYPE stko_api02,
l_prio TYPE alprf_bi,
l_datuv TYPE csap_mbom-datuv.
DATA:is_stko_add TYPE stko_api01,
is_stpo_add TYPE stpo_api02,
it_stpo_add TYPE TABLE OF stpo_api03.
LOOP AT gt_text.
*&L1.为物料号补0
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = gt_text-matnr
IMPORTING
output = gt_text-matnr.
*&L2.组件号补0
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = gt_text-idnrk
IMPORTING
output = gt_text-idnrk.
*&条目
lv_line = lv_line + 1.
CLEAR:lv_false.
*&L3.read BOM
CLEAR:lt_stpo,lt_stpo[],
lt_stko,
it_stpo,it_stpo[],
is_stko,
it_stpo_add,it_stpo_add[],
is_stko_add.
CLEAR:l_datuv.
*&读取bom原始数据
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
material = gt_text-matnr
plant = gt_text-werks
bom_usage = '1'
alternative = ' '
TABLES
t_stpo = lt_stpo
t_stko = lt_stko
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc = 0.
READ TABLE lt_stko INTO ls_stko INDEX 1.
MOVE-CORRESPONDING ls_stko TO is_stko.
MOVE-CORRESPONDING ls_stko TO is_stko_add.
l_datuv = ls_stko-created_on.
LOOP AT lt_stpo INTO ls_stpo.
READ TABLE gt_text WITH KEY idnrk = ls_stpo-component. "werks = ls_stpo-plant.
IF sy-subrc <> 0.
DELETE lt_stpo.
CONTINUE.
ELSE.
* IF ls_stpo-ai_group IS INITIAL.
* DELETE lt_stpo.
* CONTINUE.
* ENDIF.
*&修改组件物料号+单位
* ls_stpo-component = gt_text-idnrk_n.
* ls_stpo-comp_unit = gt_text-meins.
ls_stpo-fldelete = 'X'.
is_stpo_add-component = gt_text-idnrk_n.
is_stpo_add-comp_unit = gt_text-meins.
ENDIF.
* IF sy-tabix = 1.
* l_prio = sy-tabix.
* ls_stpo-ai_prio = l_prio.
* ls_stpo-usage_prob = '100'.
* ls_stpo-ai_strateg = '2'.
* ELSE.
* l_prio = sy-tabix.
* ls_stpo-ai_prio = l_prio.
* ls_stpo-usage_prob = '0'.
* ls_stpo-ai_strateg = '1'.
* ENDIF.
MOVE-CORRESPONDING ls_stpo TO is_stpo.
APPEND is_stpo TO it_stpo.
MOVE-CORRESPONDING ls_stpo TO is_stpo_add.
APPEND is_stpo_add TO it_stpo_add.
ENDLOOP.
ENDIF.
*&1.删除
*& 先将组件项目 打上删除标记
CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
EXPORTING
material = gt_text-matnr
plant = gt_text-werks
bom_usage = '1'
alternative = ' '
valid_from = l_datuv
i_stko = is_stko
fl_commit_and_wait = 'X'
* fl_new_item = 'X'
TABLES
t_stpo = it_stpo
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO gt_text-text.
* CONCATENATE gt_text-werks '-' gt_text-matnr 'bom组件更改失败!' INTO gt_text-text.
gt_text-zicon = '@5C@'.
ELSE.
gt_text-text = '更改成功!'.
gt_text-zicon = '@5B@'.
*&2.新增
CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
EXPORTING
material = gt_text-matnr
plant = gt_text-werks
bom_usage = '1'
alternative = ' '
valid_from = l_datuv
i_stko = is_stko_add
fl_commit_and_wait = 'X'
* fl_new_item = 'X'
TABLES
t_stpo = it_stpo_add
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO gt_text-text.
* CONCATENATE gt_text-werks '-' gt_text-matnr 'bom组件更改失败!' INTO gt_text-text.
gt_text-zicon = '@5C@'.
ELSE.
gt_text-text = '更改成功!'.
gt_text-zicon = '@5B@'.
ENDIF.
ENDIF.
MODIFY gt_text.
ENDLOOP.
ENDFORM. " FRM_MAINTAIN_BOM
*&---------------------------------------------------------------------*
*& Form FRM_ALV_GRID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_alv_grid .
DATA: l_nn TYPE i.
DEFINE add_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = &1.
wa_fieldcat-seltext_l = &2.
wa_fieldcat-key = &3.
wa_fieldcat-col_pos = l_nn + 1.
wa_fieldcat-just = &4.
wa_fieldcat-outputlen = &5.
wa_fieldcat-fix_column = &6.
wa_fieldcat-no_zero = &7.
wa_fieldcat-edit = &8.
append wa_fieldcat to gt_fieldcat.
END-OF-DEFINITION.
CLEAR gt_fieldcat.
REFRESH gt_fieldcat.
add_fieldcat 'ZICON' '指示灯' '' '' '' '' '' ''.
add_fieldcat 'MATNR' '物料' '' '' '' '' '' ''.
add_fieldcat 'WERKS' '工厂' '' '' '' '' '' ''.
add_fieldcat 'IDNRK' '原始组件' '' '' '' '' '' ''.
add_fieldcat 'IDNRK_N' '更改值' '' '' '' '' '' ''.
add_fieldcat 'MEINS' '单位' '' '' '' '' '' ''.
add_fieldcat 'TEXT' '消息' '' '' '' '' '' ''.
gw_layout-colwidth_optimize = 'X'.
* gw_layout-box_fieldname = 'SEL'.
*& 调用函数显示ALV列表
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_program
i_save = 'A'
is_layout = gw_layout
it_fieldcat = gt_fieldcat
it_events = gt_event
TABLES
t_outtab = gt_text
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " FRM_ALV_GRID
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_p_name text
*----------------------------------------------------------------------*
FORM getdata USING p_name.
* Data for open dialog
DATA: l_filetab TYPE filetable,
l_rc TYPE i.
CLEAR l_filetab.
REFRESH l_filetab.
* Open dialog
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
* WINDOW_TITLE = 'SAP Custom - Open File'
* DEFAULT_EXTENSION =
default_filename = '*.xls'
* FILE_FILTER = '*.xls'
initial_directory = 'd:\'
multiselection = ''
CHANGING
file_table = l_filetab
rc = l_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
* Get file path
CHECK l_rc EQ 1.
READ TABLE l_filetab INDEX 1 INTO p_name.
ENDFORM. " GETDATA
ZPPR101-批量更改BOM组件的更多相关文章
- MP3文件信息批量更改器
以前(估计是2003年)编写一个MP3文件信息批量更改器MP3TagChanger,现放上来参考.(VB6编码) 使用方法很简单,会Winamp或者千千静听的就懂使用. http://pan.baid ...
- 用Objective-C写了一个简单的批量更改文件名的程序
前言:因为本人要高仿一个app,从app中解压asserts得到的所有图片文件,文件名都带有~iPhone这个干扰的名字,为了去除这个~iPhone这个字符串,所以本人写了个简答的批量更改所有文件名的 ...
- 批量清除BOM头
批量清除BOM头 (2012-03-05 13:28:30) 转载▼ 标签: 杂谈 有些php文件由于不小心保存成了含bom头的格式而导致出现一系列的问题.以下是批量清除bom头的代码,复制代码, ...
- 批量更改int类型的timestamp字段to datetime
批量更改int类型的timestamp字段to datetime 1.创建datetime字段created_at 2.update 字段 UPDATE table set created_at = ...
- BOM组件物料重复检查
好吧,今天同事让做个BOM组件物料重复检查 网上有很多例子都是在保存的时候检查的,用的是BADI :BOM_UPDATE 自己也试了一下,麻烦....很麻烦...尤其是在重复检查的时候: METHOD ...
- 批量更改数据库COLLATION
企业内部有很多系统是繁体的,由于各方面的原因,公司目前正在实行简体化,但各系统中又有数据间的交换,所以系统只能一个一个的更改,以防同时出现过多的问题.由于原先数据库只能存储繁体,而原先已存在的数据则可 ...
- word文档标题级别批量更改——批量降级与升级实例
word文档标题级别批量更改——批量降级与升级实例 word文档标题级别批量更改——批量降级实例 2012年12月21日16:30:44 现有一个3级文档结构的word文档,如下图所示 先需要将上 ...
- ubuntu批量更改文件权限
重装系统之后,把文件从windows分区拷到linux分区发现所有文件的权限全是777,在终端下看到所有文件的颜色都很刺眼,文件有很多,一个一个改不现实,所以写了一段python脚本批量更改文件权限. ...
- linux下怎样批量更改文件后缀名
今天又有同学问linux下怎样批量更改文件后缀名,这个问题被别人问到三次了,所以这里给出几个解决方法 一.rename解决 1. Ubuntu系统下 rename 's//.c//.h/' ./* ...
随机推荐
- redis sort
redis sort命令用法 1.命令描述返回或保存给定列表.集合.有序集合key中经过排序的元素.排序默认以数字作为对象,值被解释为双精度浮点数,然后进行比较. 2.一般sort用法最简单的sort ...
- 从python中copy与deepcopy的区别看python引用
讨论copy与deepcopy的区别这个问题要先搞清楚python中的引用.python的内存管理. python中的一切事物皆为对象,并且规定参数的传递都是对象的引用.可能这样说听起来比较难懂,对比 ...
- IT公司100题-1-二叉树转换为双链表
问题描述: 输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表.要求不能创建任何新的结点,只调整指针的指向. 10 / \ 6 14/ \ / \4 8 1 ...
- Section 1.4 Packing Rectangles
本来是USACO Training的1.4.1的,但是介于今早过了食物链想起了这道题实在是太怨念了,翻出自己写的AC程序居然有5KB!! 思路很简单,枚举,而且就图中的六种情况.但是第六种变化状况太多 ...
- hdu 1031 (partial sort problem, nth_element, stable_partition, lambda expression) 分类: hdoj 2015-06-15 17:47 26人阅读 评论(0) 收藏
partial sort. first use std::nth_element to find pivot, then use std::stable_partition with the pivo ...
- Linux摄像头驱动学习之:(一)V4L2_框架分析
这段时间开始搞安卓camera底层驱动了,把以前的的Linux视频驱动回顾一下,本篇主要概述一下vfl2(video for linux 2). 一. V4L2框架: video for linux ...
- hadoop shell 操作命令
shell操作命令: hdfs的路径,在core-site.xml中定义 <property> <name>fs.default.name</name> <v ...
- C# 3.0 扩展方法[转载]
实践 扩展方法是C# 3.0中新加入的特性.MSDN中对扩展方法的定义是:扩展方法使您能够向现有类型"添加"方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 以下以 ...
- Tomcat 网站部署(三)
一.Tomcat的部署方式有以下两种 1.自动部署 2.虚拟目录 二.自动部署 文件必须放在放在webapps就可以了,可以用这样访问 http://localhost:8080/放在webapps目 ...
- 2013年8月份第2周51Aspx源码发布详情
上班族网站(毕设)源码 2013-8-16 [VS2010]源码描述:自己做的毕业设计,上班族网站项目是专门针对上班族群体设计和开发的网站项目.该网站主要涵盖了论坛平台,笑话模块,名言模块,资讯模块 ...