ZMMR107-批量更改PO经价值

***********************************************************************
* Title : ZMMR107 *
* Application : MM   *
* Subject : 批量更新po净价值 *
* Requested by : 采购部 *
* Execution : any time *
* Ref no: : B231 *
* Author : rainy *
* Req Date : 20150804 *
***********************************************************************
* 批量更新po净价值 *
***********************************************************************
***********************************************************************
*1.取数:
*2.输出: *
***********************************************************************
* MODIFICATIONS (latest entry at the top) *
* ------------------------------------------------------------------- *
* REL DATE NAME (COMPANY) DESCRIPTION TASK-NO *
* --- ---- ---- --------- ----------- ------- *
* *
***********************************************************************
REPORT zmmr107 MESSAGE-ID zmm_001.

TABLES:ekpo,
sscrfields.

DATA:BEGIN OF it_text,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
lgort LIKE ekpo-lgort,
netpr LIKE ekpo-netpr,
zicon TYPE char4,
ztext TYPE string,
zline TYPE string.
DATA: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.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t1.

PARAMETERS: so_file(300).

SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN FUNCTION KEY 1.

*----------------------------------------------------------------------
* INITIALIZATION
*----------------------------------------------------------------------
INITIALIZATION.
t1 = ‘导入数据‘.
sscrfields-functxt_01 = ‘下载导入模板‘.

*----------------------------------------------------------------------
* AT SELECTION-SCREEN.
*----------------------------------------------------------------------
AT SELECTION-SCREEN.
*&下载模板
PERFORM frm_download_template.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR so_file.
PERFORM getdata USING so_file.

*----------------------------------------------------------------------
* START-OF-SELECTION.
*----------------------------------------------------------------------
START-OF-SELECTION.

*&S1.upload data.
PERFORM frm_upload.
* CHECK gt_text[] IS NOT INITIAL.
*&write text
PERFORM frm_exeupdate.

PERFORM frm_alv_output.
* PRINT-CONTROL INDEX-LINE.

*&---------------------------------------------------------------------*
*& Form getdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->SO_FILE text
*----------------------------------------------------------------------*
FORM getdata USING so_file.
* 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 so_file.

ENDFORM. "getdata
*&---------------------------------------------------------------------*
*& Form FRM_UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_upload .
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 so_file 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
.
* CALL FUNCTION ‘TEXT_CONVERT_XLS_TO_SAP‘
* EXPORTING
** I_FIELD_SEPERATOR =
** I_LINE_HEADER =
* i_tab_raw_data =
* i_filename =
* TABLES
* i_tab_converted_data =
** 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.

*&删除标题行
* DELETE gt_text FROM 1 TO 1.
* i_line_header = ‘X‘

ENDFORM. " FRM_UPLOAD
*&---------------------------------------------------------------------*
*& 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 ‘\ZM107.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.

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 = ‘ZM107‘. "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_EXEUPDATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_exeupdate .
FIELD-SYMBOLS:<fs_text> LIKE LINE OF gt_text.
DATA: lv_upd(1).
DATA:lv_date LIKE sy-datum,
lv_day(2) TYPE n,
lv_month(2) TYPE n,
lv_year(4) TYPE n,
lv_calc_date TYPE d.
DATA:l_line TYPE string.

SORT gt_text BY ebeln ebelp.

*&S1.处理数据
LOOP AT gt_text ASSIGNING <fs_text>.

CLEAR:lv_day,
lv_month,
lv_year.
<fs_text>-zline = sy-tabix.

*&S1.1PO#加前导0
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
input = <fs_text>-ebeln
IMPORTING
output = <fs_text>-ebeln.
*&判断PO 是否存在
SELECT SINGLE *
FROM ekpo
WHERE ebeln EQ <fs_text>-ebeln
AND ebelp EQ <fs_text>-ebelp.
IF sy-subrc EQ 0.

UPDATE ekpo SET netpr = <fs_text>-netpr
WHERE ebeln = <fs_text>-ebeln
AND ebelp = <fs_text>-ebelp.
IF sy-subrc EQ 0.
<fs_text>-zicon = ‘@[email protected]‘.
<fs_text>-ztext = ‘更新成功!‘.
COMMIT WORK.
ELSE.
<fs_text>-zicon = ‘@[email protected]‘.
<fs_text>-ztext = ‘更新失败!‘.
ROLLBACK WORK.
ENDIF.

ELSE.
<fs_text>-ztext = ‘数据不存在!‘.
ENDIF.

ENDLOOP.

DATA:l_lines TYPE string.
l_lines = lines( gt_text[] ).
IF l_lines EQ 0.
MESSAGE s000(oo) WITH ‘没有找到符合条件的数据!‘ DISPLAY LIKE ‘E‘.
LEAVE TO LIST-PROCESSING.
ELSE.
MESSAGE s000(oo) WITH ‘找到数据‘ l_lines ‘条!‘.
ENDIF.

ENDFORM. " FRM_EXEUPDATE
*&---------------------------------------------------------------------*
*& Form FRM_ALV_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_alv_output .
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 ‘ZLINE‘ ‘行号‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.
add_fieldcat ‘EBELN‘ ‘采购凭证‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.
add_fieldcat ‘EBELP‘ ‘项目‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.
add_fieldcat ‘MATNR‘ ‘物料号‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.
add_fieldcat ‘WERKS‘ ‘工厂‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.
add_fieldcat ‘LGORT‘ ‘库位‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘X‘ ‘‘.
add_fieldcat ‘NETPR‘ ‘需要改成的净价‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.
add_fieldcat ‘ZTEXT‘ ‘消息‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.

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_OUTPUT

时间: 2024-12-10 22:27:17

ZMMR107-批量更改PO经价值的相关文章

ubuntu下,批量更改文件后缀

ubuntu下,批量更改文件后缀: eg:把当前目录下以tpl为后缀的文件全部rename为html a.tpl  b.tpl  c.tpl 执行命令:   rename 's/\.tpl/.html/' *.tpl a.html  b.html  c.html

用Objective-C写了一个简单的批量更改文件名的程序

前言:因为本人要高仿一个app,从app中解压asserts得到的所有图片文件,文件名都带有~iPhone这个干扰的名字,为了去除这个~iPhone这个字符串,所以本人写了个简答的批量更改所有文件名的程序. 程序员就是应该会利用程序来帮自己偷懒,因为用到的很多方法不是很熟悉,也是花了点时间去熟悉NSFileManager的一些方法,所以写下这个笔记做个笔记,省的下次又需要就忘记了方法. 我的基本需求,在啰嗦一下下哈: 一个文件目录下有上百个图片文件,文件名都带有~iPhone.写一个程序,删除所

Windows2008server R2 组策略批量更改本地管理员密码

Windows2008域组策略批量更改本地管理员密码 1,打开域策略管理器. 2,在组策略对象下面新建一个组策略对象:如:Local_Root 3,接着在Local_Root右键点击编辑这个组策略. 4,在Local_Root编辑器下"用户配置"下面的"本地用户和组"点击新建"用户"或者"用户组",我在此处选的是本地用户,内置Administrator并且重命名为Admin. 5,剩下就是在组策略里面生效,你如果想快点生效需要

Python脚本--批量更改本地md文件的图片链接

#-*- coding:utf-8 -*- import re import os def patch_md(filename): if filename.endswith('.md'): return True return False def _patch_replace(text): pattern=re.compile(r'(?<=!)\[.*\]\((.*)(?=\))') result = re.findall(pattern,text)for filedir in result:

批量更改数据库COLLATION

企业内部有很多系统是繁体的,由于各方面的原因,公司目前正在实行简体化,但各系统中又有数据间的交换,所以系统只能一个一个的更改,以防同时出现过多的问题.由于原先数据库只能存储繁体,而原先已存在的数据则可以不必转换为简体,照用就可以了.我们新的数据库均采用Chinese_PRC_BIN collation, 所以我们直接把旧系统备份一份,然后恢复到新的服务器上,同时更改数据库的collation. 但是只更改了数据库的COLLATION还是不够的.要把数据库里面的表都同时更改了才可以.但我们的数据库

MP3文件信息批量更改器

以前(估计是2002年)编写一个MP3文件信息批量更改器MP3TagChanger,现放上来参考. 使用方法很简单,会Winamp或者千千静听的就懂使用. 点击MP3文件信息批量更改器MP3TagChanger下载使用.

AIX 批量更改密码

使用 chpasswd 可以使用 chpasswd 方便地更改单个或多个账户密码.这意味着不需要像平时一样在命令行上重复输入密码.尽管可以以交互方式使用 chpasswd,但是我建议以非交互方式使用它.使用 chpasswd 是一种快速更改密码的方法. 使用 chpasswd 的格式是: chpasswd -f <pwdadm flags> -c 其中:-f 可以解析 pwdadm 标志 -c 清除密码标志 从标准输入读取以下格式的用户名和密码: user_name:user_password

shell 批量更改文件或目录名

批量更改文件名: 1.在多个文件后面添加.bak或者其他有规律的字符 ls  |xargs -n1 -i{} mv {} {}.bak 或者 find ./*.txt -exec mv {} {}_bak \; 2.通用的批量更改脚本 #!/bin/bash read -p "old extension:" oldext read -p "new extension:" newext read -p "The directory:" dir cd

批量更改数据库表架构(生成sql后直接执行!)

批量更改数据库表架构(生成sql后直接执行!) use my_test; --当前数据库 declare @alltable varchar(1000), @SchemaOld varchar(1000), @SchemaNew varchar(1000), @NewSql VARCHAR(max), @Index INT; SET @SchemaOld='';--原架构名称 SET @SchemaNew='';--新架构名称 SET @NewSql=''; SET @Index=1; SELE