*&---------------------------------------------------------------------*
*& Report YPMRP010_ALV01
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT YPMRP010_ALV01.
*-----设定变量-------*
TYPE-POOLS:SLIS.
TABLES:VBAP.
*定义ALV结构
DATA:LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV."FIELDCAT内表
DATA:LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV."FIELDCAT工作区
DATA:LS_LAYOUT TYPE SLIS_LAYOUT_ALV."ALV控制结构体:layout
DATA:LT_EVENT TYPE SLIS_T_EVENT."事件内表
DATA:LS_EVENT TYPE SLIS_ALV_EVENT."事件工作区
DATA:LT_SORT TYPE SLIS_T_SORTINFO_ALV. "用于排序的内表
DATA:LS_SORT TYPE SLIS_SORTINFO_ALV."用于排序的工作区
DATA:LS_SETTING TYPE LVC_S_GLAY."ALV 控制: 退出可编辑单元格时回调
*定义内表结构
TYPES:BEGIN OF TY_ALVSHOW,
VBELN LIKE VBAK-VBELN,
ERDAT LIKE VBAK-ERDAT,
ERNAM LIKE VBAK-ERNAM,
KUNNR LIKE VBAK-KUNNR,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
MATKL LIKE VBAP-MATKL,
ZMENG LIKE VBAP-ZMENG,
ZIEME LIKE VBAP-ZIEME,
WERKS LIKE VBAP-WERKS,
LGORT LIKE VBAP-LGORT,
END OF TY_ALVSHOW.
*定义内表及工作区
DATA:IT_ALVSHOW TYPE STANDARD TABLE OF TY_ALVSHOW.
DATA:WA_ALVSHOW TYPE TY_ALVSHOW.
DATA:IT_ALVSHOW1 TYPE STANDARD TABLE OF TY_ALVSHOW.
DATA:WA_ALVSHOW1 TYPE TY_ALVSHOW.
DATA:COL_POS TYPE I.
SELECT-OPTIONS:S_VBELN FOR VBAP-VBELN.
*取数据
SELECT
VBAK~VBELN VBAK~ERDAT VBAK~ERNAM VBAK~KUNNR VBAP~POSNR VBAP~MATNR VBAP~MATKL
VBAP~ZMENG VBAP~ZIEME VBAP~WERKS VBAP~LGORT FROM VBAK
INNER JOIN VBAP ON VBAK~VBELN = VBAP~VBELN
* INTO CORRESPONDING FIELDS OF TABLE IT_ALVSHOW WHERE VBAK~VBELN IN S_VBELN.
INTO CORRESPONDING FIELDS OF TABLE IT_ALVSHOW UP TO ROWS.
IT_ALVSHOW1 = IT_ALVSHOW.
*ALV格式控制layout
LS_LAYOUT-ZEBRA = 'X'.
LS_LAYOUT-DETAIL_POPUP = 'X'.
LS_LAYOUT-DETAIL_TITLEBAR = '详细信息'.
LS_LAYOUT-F2CODE = '&ETA'.
LS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
* fieldcat
COL_POS = .
*销售凭证列
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'VBELN'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-KEY = 'X'.
LS_FIELDCAT-SELTEXT_M = '销售凭证'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*创建日期
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'ERDAT'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-REF_TABNAME = 'VBAK'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*创建者
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'ERNAM'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-SELTEXT_M = '创建人'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*售达方 自己起字段描述
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'KUNNR'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-SELTEXT_M = '客户'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*售达方1 参考数据字典表名
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'KUNNR'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-REF_TABNAME = 'VBAK'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*行号
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'POSNR'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-REF_TABNAME = 'VBAP'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*物料
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'MATNR'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-SELTEXT_M = '物料编码'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*物料组
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'MATKL'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-SELTEXT_M = '物料组'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*数量
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'ZMENG'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-SELTEXT_M = '数量'.
LS_FIELDCAT-DO_SUM = 'X'. "总计
LS_FIELDCAT-EDIT = 'X'. "总计
LS_FIELDCAT-DECIMALS_OUT = . "因为当编辑数量的时候,如果是小数,要指定小数位,否则输入数据之后回车会自动缩小,如果使用ref则不需要设置 APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*单位
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'ZIEME'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-SELTEXT_M = '单位'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*工厂
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'WERKS'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-REF_TABNAME = 'VBAP'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*库位
COL_POS = COL_POS + .
LS_FIELDCAT-FIELDNAME = 'LGORT'.
LS_FIELDCAT-COL_POS = COL_POS.
LS_FIELDCAT-SELTEXT_M = '库位'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
CLEAR:LS_FIELDCAT.
*定义事件
LS_EVENT-NAME = 'USER_COMMAND'."用户响应事件
LS_EVENT-FORM = 'FORM_USER_COMMAND'."子例程
APPEND LS_EVENT TO LT_EVENT."加入到事件内表
CLEAR:LS_EVENT.
LS_EVENT-NAME = 'TOP_OF_PAGE'."显示标题
LS_EVENT-FORM = 'FORM_TOP_OF_PAGE'."子例程
APPEND LS_EVENT TO LT_EVENT.
CLEAR:LS_EVENT.
LS_EVENT-NAME = 'PF_STATUS_SET'."设置gui状态栏
LS_EVENT-FORM = 'FORM_PF_STATUS_SET'."子例程
APPEND LS_EVENT TO LT_EVENT.
CLEAR:LS_EVENT.
*排序
LS_SORT-FIELDNAME = 'ERDAT'.
LS_SORT-DOWN = 'X'.
APPEND LS_SORT TO LT_SORT.
LS_SORT-FIELDNAME = 'KUNNR'.
LS_SORT-UP = 'X'.
APPEND LS_SORT TO LT_SORT.
CLEAR:LS_SORT.
*ALV 控制: 退出可编辑单元格时回调
LS_SETTING-EDT_CLL_CB = 'X'. *显示
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'SET PF-STATUS '
I_CALLBACK_USER_COMMAND = ' USER_COMMAND'
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
I_GRID_SETTINGS = LS_SETTING "退出可编辑单元格时回调保存修改的值,修改了值必须要按回车健激活
IS_LAYOUT = LS_LAYOUT
IT_FIELDCAT = LT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = LT_SORT
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
IT_EVENTS = LT_EVENT
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_ALVSHOW
EXCEPTIONS
PROGRAM_ERROR =
OTHERS = .
IF SY-SUBRC <> .
* Implement suitable error handling here
ENDIF.
"FORM define
FORM FORM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
* DATA:IT_VBAP TYPE TABLE OF VBAP."更新源内表,要和数据库表结构一致 7.5以前可以定义内表
* DATA:WA_VBAP TYPE VBAP. * CASE .
* WHEN .
* WHEN .
* WHEN OTHERS.
* ENDCASE. 也可以用case IF R_UCOMM = '&ADD'.
MESSAGE '您触发了按钮TEST' TYPE 'I'.
ENDIF.
IF R_UCOMM = 'ZSAVE'.
* SELECT * FROM VBAP INTO TABLE @DATA(LT_VBAP) FOR ALL ENTRIES IN @IT_ALVSHOW"7.5以后可以直接@data内表名
* WHERE VBELN = @IT_ALVSHOW-VBELN AND POSNR = @IT_ALVSHOW-POSNR.
* LOOP AT LT_VBAP INTO DATA(WA_VBAP).
* READ TABLE IT_ALVSHOW INTO WA_ALVSHOW WITH KEY VBELN = WA_VBAP-VBELN POSNR = WA_VBAP-POSNR.
* IF SY-SUBRC = 0.
* WA_VBAP-ZMENG = WA_ALVSHOW-ZMENG.
* MODIFY LT_VBAP FROM WA_VBAP.
* CLEAR:WA_VBAP,WA_ALVSHOW.
* UPDATE VBAP FROM TABLE LT_VBAP.
* ENDIF.
* ENDLOOP.
DATA:TABLE_DEL TYPE TABLE OF TY_ALVSHOW.
DATA:TABLE_ADD TYPE TABLE OF TY_ALVSHOW.
DATA:TABLE_MOD TYPE TABLE OF TY_ALVSHOW.
DATA:WA_TABLE_MOD TYPE TY_ALVSHOW.
DATA:NO_CHANGES() TYPE C.
CALL FUNCTION 'CTVB_COMPARE_TABLES' "用于比较更改前后内表的变化,比上面的全部循环更新更有效率
EXPORTING
TABLE_OLD = IT_ALVSHOW1
TABLE_NEW = IT_ALVSHOW
KEY_LENGTH = ''
* IF_SORTED =
IMPORTING
TABLE_DEL = TABLE_DEL
TABLE_ADD = TABLE_ADD
TABLE_MOD = TABLE_MOD
NO_CHANGES = NO_CHANGES.
SELECT * FROM VBAP INTO TABLE @DATA(LT_VBAP) FOR ALL ENTRIES IN @TABLE_MOD"7.5以后可以直接@data内表名
WHERE VBELN = @TABLE_MOD-VBELN AND POSNR = @TABLE_MOD-POSNR.
LOOP AT LT_VBAP INTO DATA(WA_VBAP).
READ TABLE TABLE_MOD INTO WA_TABLE_MOD WITH KEY VBELN = WA_VBAP-VBELN POSNR = WA_VBAP-POSNR.
IF SY-SUBRC = .
WA_VBAP-ZMENG = WA_TABLE_MOD-ZMENG.
MODIFY LT_VBAP FROM WA_VBAP.
CLEAR:WA_VBAP,WA_TABLE_MOD.
UPDATE VBAP FROM TABLE LT_VBAP.
ENDIF.
ENDLOOP. IF SY-SUBRC = .
COMMIT WORK. "用于提交数据
MESSAGE '更新成功' TYPE 'I'.
ELSE.
ROLLBACK WORK.
MESSAGE '更新失败' TYPE 'I'.
ENDIF.
ENDIF.
ENDFORM.
FORM FORM_TOP_OF_PAGE. DATA:LT_COMMENTARY TYPE SLIS_T_LISTHEADER,
WA_COMMENTARY TYPE SLIS_LISTHEADER.
WA_COMMENTARY-TYP = 'H'.
WA_COMMENTARY-INFO = '销售凭证'.
APPEND WA_COMMENTARY TO LT_COMMENTARY.
CLEAR:WA_COMMENTARY.
WA_COMMENTARY-TYP = 'S'.
WA_COMMENTARY-INFO = '销售凭证'.
APPEND WA_COMMENTARY TO LT_COMMENTARY.
CLEAR:WA_COMMENTARY.
WA_COMMENTARY-TYP = 'A'.
WA_COMMENTARY-INFO = '销售凭证'.
APPEND WA_COMMENTARY TO LT_COMMENTARY.
CLEAR:WA_COMMENTARY.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' "用于ALV标题的显示
EXPORTING
IT_LIST_COMMENTARY = LT_COMMENTARY
I_LOGO = 'ZTEST1'.
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
ENDFORM.
FORM FORM_PF_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS'STANDARD'.
ENDFORM.

简单ALV得演示(用到了ALV可编辑及保存后修改数据库)的更多相关文章

  1. JS事件 编程练习-自制计算器 使用JS完成一个简单的计算器功能。实现2个输入框中输入整数后,点击第三个输入框能给出2个整数的加减乘除。

    编程练习 使用JS完成一个简单的计算器功能.实现2个输入框中输入整数后,点击第三个输入框能给出2个整数的加减乘除. 提示:获取元素的值设置和获取方法为:例:赋值:document.getElement ...

  2. SAP ABAP ALV 颜色设置(两个ALV函数例子) 列 行 单元格

    @[TOC](设置ALV颜色)# 前言淦! 要求花花绿绿的ALV ,那就淦他! 需要的参数和对应颜色放在最后.稍微改改就能用. 介绍两个常用的ALV函数实现1.REUSE_ALV_GRID_DISPL ...

  3. 支持Ajax跨域访问ASP.NET Web Api 2(Cors)的简单示例教程演示

    随着深入使用ASP.NET Web Api,我们可能会在项目中考虑将前端的业务分得更细.比如前端项目使用Angularjs的框架来做UI,而数据则由另一个Web Api 的网站项目来支撑.注意,这里是 ...

  4. 基于gulp编写的一个简单实用的前端开发环境好了,安装完Gulp后,接下来是你大展身手的时候了,在你自己的电脑上面随便哪个地方建一个目录,打开命令行,然后进入创建好的目录里面,开始撸代码,关于生成的json文件请点击这里https://docs.npmjs.com/files/package.json,打开的速度看你的网速了注意:以下是为了演示 ,我建的一个目录结构,你自己可以根据项目需求自己建目

    自从Node.js出现以来,基于其的前端开发的工具框架也越来越多了,从Grunt到Gulp再到现在很火的WebPack,所有的这些新的东西的出现都极大的解放了我们在前端领域的开发,作为一个在前端领域里 ...

  5. Mockito的简单使用方法演示样例

    Mockito是一个流行的Mocking框架.它使用起来简单,学习成本非常低.并且具有非常简洁的API,測试代码的可读性非常高.因此它十分受欢迎,用 户群越来越多.非常多的开源的软件也选择了Mocki ...

  6. 一百零五、SAP中ALV事件之十七,让ALV表格修改后保存到数据库

    一.我们来到代码界面设置保存按钮的代码 二.i_grid_settings这个属性用来编辑单元格之后,返回给程序编辑后的值 三.我们双击点  'REUSE_ALV_GRID_DISPLAY',来到定义 ...

  7. Html5 简单选择排序演示

    简单选择排序,是选择排序算法的一种.基本思想:每趟从待排序的记录中选出关键字最小的记录,顺序放在已排序的记录序列末尾,直到全部排序结束为止.由于在每次循环中,会对数值相等的元素改变位置,所以属于非稳定 ...

  8. beego框架的最简单登入演示

    一.controllers逻辑代码 func (c *UserController) Get() { c.TplName="login.html" } func (c *UserC ...

  9. 一个简单的实例演示vuex模块化和命名空间

    因为Vuex Store是全局注册的,不利于较大的项目,引入模块分离业务状态和方法,引入命名空间解决不同模块内(getters,mutaions,actions)名称冲突的问题 ----------- ...

随机推荐

  1. SQL 带有output、inserted、deleted

    因需求的关系需要将修改的值返回,故查了些资料发现了OUTPUT这个好东西,现记录下来以防以后忘记 使用例子: 1.对于INSERT,可以引用inserted表以查询新行的属性.    insert i ...

  2. 何为http?何为RPC?

    RPC(即Remote Procedure Call,远程过程调用)和HTTP(HyperText Transfer Protocol,超文本传输协议)他们最本质的区别,就是RPC主要工作在TCP协议 ...

  3. vscode 设置代码格式化缩进为2个空格

    打开文件——>首选——>设置 输入搜索 tabsize 按照下图设置即可,然后打开 注意:如果不将Detect Indentation 勾选取消 以前用tab创建的忘记依然为4个空格

  4. es6 最新函数封装(简易版)

    map封装: Array.prototype.map=function(fn){ var arr=this; var newArr=[] for(var i=0;i<arr.length;i++ ...

  5. 安卓开发笔记(三十二):banner轮播图的实现

    一.activity.xml 我这里主要爬取的爱奇艺首页的图片进行轮播,应用了两个github上的开源库,一个banner的库,一个加载网络图片的库,用开源库能够极大地节省我们编写代码的时间. < ...

  6. Kotlin介绍(非原创)

    文章大纲 一.Kotlin简介二.Kotlin相比Java优势三.Kotlin与Java混合使用四.参考文章   一.Kotlin简介 1. 什么是Kotlin 安卓和Java,前者是最受欢迎的移动开 ...

  7. c++ 模板特化与局部特化

    c++ 模板特化与局部特化 模板的由来是要处理泛化,也就是任何类型都可以处理.但是泛化的同时,如果针对某种特殊的类型,又更加效率的处理方法.c++提供针对特殊的类型,可以定义不同的处理方法.针对某种特 ...

  8. Nginx 配置实例-动静分离

    1.什么是动静分离  通过 location 指定不同的后缀名实现不同的请求转发.通过 expires 参数设置,可以使浏 览器缓存过期时间,减少与服务器之前的请求和流量.具体 Expires 定义: ...

  9. Html学习之五(嵌套之简单购物界面设计)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. 攻防世界web-NaNNaNNaNNaN-Batman

    先把附件下载下来,然后打开,一堆js乱码 把最后的eval修改成alert,再将文件后缀修改成html,用浏览器打开,乱码变正常了 之后把js代码对齐一下,这里用这个网站进行对齐 https://be ...