***********************************************************************
* 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 = '@5B@'.
<fs_text>-ztext = '更新成功!'.
COMMIT WORK.
ELSE.
<fs_text>-zicon = '@5C@'.
<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

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

  1. MP3文件信息批量更改器

    以前(估计是2003年)编写一个MP3文件信息批量更改器MP3TagChanger,现放上来参考.(VB6编码) 使用方法很简单,会Winamp或者千千静听的就懂使用. http://pan.baid ...

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

    前言:因为本人要高仿一个app,从app中解压asserts得到的所有图片文件,文件名都带有~iPhone这个干扰的名字,为了去除这个~iPhone这个字符串,所以本人写了个简答的批量更改所有文件名的 ...

  3. 批量更改int类型的timestamp字段to datetime

    批量更改int类型的timestamp字段to datetime 1.创建datetime字段created_at 2.update 字段 UPDATE table set created_at = ...

  4. 批量更改数据库COLLATION

    企业内部有很多系统是繁体的,由于各方面的原因,公司目前正在实行简体化,但各系统中又有数据间的交换,所以系统只能一个一个的更改,以防同时出现过多的问题.由于原先数据库只能存储繁体,而原先已存在的数据则可 ...

  5. word文档标题级别批量更改——批量降级与升级实例

    word文档标题级别批量更改——批量降级与升级实例   word文档标题级别批量更改——批量降级实例 2012年12月21日16:30:44 现有一个3级文档结构的word文档,如下图所示 先需要将上 ...

  6. ubuntu批量更改文件权限

    重装系统之后,把文件从windows分区拷到linux分区发现所有文件的权限全是777,在终端下看到所有文件的颜色都很刺眼,文件有很多,一个一个改不现实,所以写了一段python脚本批量更改文件权限. ...

  7. linux下怎样批量更改文件后缀名

    今天又有同学问linux下怎样批量更改文件后缀名,这个问题被别人问到三次了,所以这里给出几个解决方法 一.rename解决 1.  Ubuntu系统下 rename 's//.c//.h/'  ./* ...

  8. Python3 批量更改文件后缀名

    Python3 批量更改文件后缀名 示例: # coding:utf8 import os import sys def Rename(): #Path = "F:\\test\\" ...

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

    批量更改数据库表架构(生成sql后直接执行!) use my_test; --当前数据库 ), ), ), @NewSql VARCHAR(max), @Index INT; SET @SchemaO ...

随机推荐

  1. Iterator之ListIterator简介

    ListIterator是什么? (参考自百度百科) java中的ListIterator在Iterator基础上提供了add.set.previous等对列表的操作.但是ListIterator跟I ...

  2. 用PHP做服务器接口客户端用http协议POST访问安全性一般怎么做

    我的问题是,如果不做安全相关处理的话,一些可能改变数据库的操作可能会遭遇垃圾数据提交什么的,毕竟要找到这些信息只要找个http包就可以了 系统无用户登录 新手问题(从来没做过服务端开发),如果可以,给 ...

  3. .NET C#使用微信公众号登录网站

    适用于:本文适用于有一定微信开发基础的用户 引言:花了300大洋申请了微信公众平台后,发现不能使用微信公众号登录网站(非微信打开)获得微信帐号.仔细研究后才发现还要再花300大洋申请微信开放平台才能接 ...

  4. 使用ASP.Net WebAPI构建REST服务(五)——客户端

    WebAPI是标准的Http协议,支持Http协议的客户端(如浏览器)都可以访问.但是,有的时候我们如果想在自己的程序中使用WebAPI时,此时就要实现自己的客户端了.我之前介绍过在.Net 4.5中 ...

  5. Spring学习笔记之Bean的实例化

    一.bean的实例化方法有3种, 1.构造器实例化 2.静态工厂方法实例化 3.实例工厂方法实例化 二.用构造器来实例化 <bean id="ShunDao" class=& ...

  6. linux内核编译

    1,进入内核源码树,如果是第一次编译,建议清理以下内核功能选择文件: make mrproper 2,删除前一次编译的残留文件: make clean 3,配置内核功能 make menuconfig ...

  7. Matlab与C/C++联合编程之Matlab以MEX方式调用C/C++代码(一)

    MEX文件是一种可在matlab环境中调用的C语言(或fortran)衍生程序,mex的编译结果实际上就是一个带输出函数mexFunction 的dll文件. 中文名 mex文件 外文名 MATLAB ...

  8. 2014年2月份第4周51Aspx源码发布详情

    AM自定义报表管理系统源码  2014-2-28 [VS2010]源码描述: 本系统有以下特色之处: 1.一套软件,多点登陆,根据权限不同共同管理报表,适应于前期获取客户需求报表字段使用. 2.客户自 ...

  9. 2013年7月底至8月初51Aspx源码发布详情

    兼职人员信息管理系统源码  2013-8-2 [VS2008]2013.8.2更新内容:修改了一级菜单不能修改的bug.功能介绍:兼职人员信息管理:添加,修改,删除,查询,支持数据导出Excel,按多 ...

  10. iOS NSDictionary、NSData、JSON数据类型相互转换

    iOS经常需要用到数据类型的转换,下面列举一下常用类型的转换. 1.NSDictionary类型转换为NSData类型: //NSDictionary -> NSData: NSDictiona ...