TABLES:MSEG,MAKT.
"定义结构
TYPES:BEGIN OF TY_DATA,
MJAHR LIKE MSEG-MJAHR, "物料凭证的年份
MBLNR LIKE MSEG-MBLNR, "物料凭证
BWART LIKE MSEG-BWART, "移动类型
XAUTO LIKE MSEG-XAUTO, "是否自动创建
MATNR LIKE MSEG-MATNR, "物料编码
MAKTX LIKE MAKT-MAKTX, "物料描述
WERKS LIKE MSEG-WERKS, "工厂
LGORT LIKE MSEG-LGORT, "库位
CHARG LIKE MSEG-CHARG, "批次
MENGE LIKE MSEG-MENGE, "基本单位数量
MEINS LIKE MSEG-MEINS, "基本单位
ERFMG LIKE MSEG-ERFMG, "录入数量
ERFME LIKE MSEG-ERFME, "录入单位
BUDAT_MKPF LIKE MSEG-BUDAT_MKPF, "过账日期
CPUDT_MKPF LIKE MSEG-CPUDT_MKPF, "输入日期
CPUTM_MKPF LIKE MSEG-CPUTM_MKPF, "输入时间
USNAM_MKPF LIKE MSEG-USNAM_MKPF, "用户名
END OF TY_DATA.
TYPES:BEGIN OF TY_DATA1,
* MJAHR LIKE MSEG-MJAHR, "物料凭证的年份
* MBLNR LIKE MSEG-MBLNR, "物料凭证
WERKS LIKE MSEG-WERKS, "工厂
LGORT LIKE MSEG-LGORT, "库位
MATNR LIKE MSEG-MATNR, "物料编码
MAKTX LIKE MAKT-MAKTX, "物料描述
BWART LIKE MSEG-BWART, "移动类型
* XAUTO LIKE MSEG-XAUTO, "是否自动创建
* CHARG LIKE MSEG-CHARG, "批次
MENGE LIKE MSEG-MENGE, "基本单位数量
MEINS LIKE MSEG-MEINS, "基本单位
* ERFMG LIKE MSEG-ERFMG, "录入数量
* ERFME LIKE MSEG-ERFME, "录入单位
* BUDAT_MKPF LIKE MSEG-BUDAT_MKPF, "过账日期
* CPUDT_MKPF LIKE MSEG-CPUDT_MKPF, "输入日期
* CPUTM_MKPF LIKE MSEG-CPUTM_MKPF, "输入时间
* USNAM_MKPF LIKE MSEG-USNAM_MKPF, "用户名
END OF TY_DATA1.
TYPES:BEGIN OF TY_DATA2,
* MJAHR LIKE MSEG-MJAHR, "物料凭证的年份
* MBLNR LIKE MSEG-MBLNR, "物料凭证
* WERKS LIKE MSEG-WERKS, "工厂
* LGORT LIKE MSEG-LGORT, "库位
* MATNR LIKE MSEG-MATNR, "物料编码
* MAKTX LIKE MAKT-MAKTX, "物料描述
BWART LIKE MSEG-BWART, "移动类型
* XAUTO LIKE MSEG-XAUTO, "是否自动创建
* CHARG LIKE MSEG-CHARG, "批次
* MENGE LIKE MSEG-MENGE, "基本单位数量
* MEINS LIKE MSEG-MEINS, "基本单位
* ERFMG LIKE MSEG-ERFMG, "录入数量
* ERFME LIKE MSEG-ERFME, "录入单位
* BUDAT_MKPF LIKE MSEG-BUDAT_MKPF, "过账日期
* CPUDT_MKPF LIKE MSEG-CPUDT_MKPF, "输入日期
* CPUTM_MKPF LIKE MSEG-CPUTM_MKPF, "输入时间
* USNAM_MKPF LIKE MSEG-USNAM_MKPF, "用户名
END OF TY_DATA2.
DATA:IT_DATA TYPE STANDARD TABLE OF TY_DATA,
WA_DATA TYPE TY_DATA.
DATA:IT_DATA1 TYPE STANDARD TABLE OF TY_DATA1,
WA_DATA1 TYPE TY_DATA1.
DATA:IT_DATA2 TYPE STANDARD TABLE OF TY_DATA2,
WA_DATA2 TYPE TY_DATA2.
DATA:N TYPE I.
DATA: IT_TABLE TYPE REF TO DATA,
IT_STRUCTURE TYPE LVC_T_FCAT,
WA_STRUCTURE TYPE LVC_S_FCAT.
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_LAYOUT TYPE LVC_S_LAYO.
DATA: G_TITLE TYPE LVC_TITLE.
"FIELD SYMBOLS
FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
<DYN_WA>,
<DYN_FIELD>.
"定义屏幕
SELECTION-SCREEN BEGIN OF BLOCK BLK01.
SELECT-OPTIONS:S_WERKS FOR MSEG-WERKS,"工厂
S_LGORT FOR MSEG-LGORT,"库位
S_MATNR FOR MSEG-MATNR,"物料
S_BUDAT FOR MSEG-BUDAT_MKPF,"过账日期
S_CPUDT FOR MSEG-CPUDT_MKPF,"输入日期
S_BWART FOR MSEG-BWART,"移动类型
S_USNAM FOR MSEG-USNAM_MKPF."username
SELECTION-SCREEN END OF BLOCK BLK01.
"主程序 START-OF-SELECTION.
PERFORM GET_DATA."取数
PERFORM CREAT_STRUCTURE."创建内表结构
PERFORM CREAT_TABLE."按照结构定义内表
PERFORM DATA_TO_TABLE."写数据进内表
PERFORM FRM_INIT_LAYOUT.
PERFORM FRM_SHOW_ALV."内表数据展示
FORM GET_DATA.
SELECT
MSEG~MJAHR,
MSEG~MBLNR,
MSEG~BWART,
MSEG~XAUTO,
MSEG~MATNR,
MAKT~MAKTX,
MSEG~WERKS,
MSEG~LGORT,
MSEG~CHARG,
CASE MSEG~SHKZG
WHEN 'H' THEN ( - MSEG~MENGE )
ELSE MSEG~MENGE
END AS MENGE,
MSEG~MEINS,
CASE MSEG~SHKZG
WHEN 'H' THEN ( - MSEG~ERFMG )
ELSE MSEG~ERFMG
END AS ERFMG,
MSEG~ERFME,
MSEG~BUDAT_MKPF,
MSEG~CPUDT_MKPF,
MSEG~CPUTM_MKPF,
MSEG~USNAM_MKPF
FROM MSEG
LEFT JOIN MAKT ON MAKT~MATNR = MSEG~MATNR
INTO CORRESPONDING FIELDS OF TABLE @IT_DATA
WHERE MSEG~WERKS IN @S_WERKS
AND MSEG~LGORT IN @S_LGORT
AND MSEG~MATNR IN @S_MATNR
AND MSEG~BUDAT_MKPF IN @S_BUDAT
AND MSEG~BWART IN @S_BWART
AND MSEG~USNAM_MKPF IN @S_USNAM
AND MSEG~CPUDT_MKPF IN @S_CPUDT.
LOOP AT IT_DATA INTO WA_DATA.
MOVE-CORRESPONDING WA_DATA TO WA_DATA1.
COLLECT WA_DATA1 INTO IT_DATA1.
CLEAR:WA_DATA,WA_DATA1.
ENDLOOP. ENDFORM.
FORM CREAT_STRUCTURE.
DATA: L_LINES TYPE I.
LOOP AT IT_DATA1 INTO WA_DATA1.
MOVE-CORRESPONDING WA_DATA1 TO WA_DATA2.
APPEND WA_DATA2 TO IT_DATA2.
ENDLOOP. SORT IT_DATA2 BY BWART.
DELETE ADJACENT DUPLICATES FROM IT_DATA2 COMPARING BWART.
DESCRIBE TABLE IT_DATA2 LINES N.
L_LINES = . * 创建静态结构部分
PERFORM FRM_ALV_FCAT_SET USING:
'WERKS' TEXT- 'WERKS' 'MSEG' SPACE SPACE,
'LGORT' TEXT- 'LGORT' 'MSEG' SPACE SPACE,
'MATNR' TEXT- 'MATNR' 'MAKT' SPACE SPACE,
'MAKTX' TEXT- 'MAKTX' 'MAKT' SPACE SPACE.
* 5 'BUDAT_MKPF' TEXT-008 'BUDAT_MKPF' 'MSEG' SPACE SPACE,
* 6 'CPUDT_MKPF' TEXT-008 'CPUDT_MKPF' 'MSEG' SPACE SPACE. LOOP AT IT_DATA2 INTO WA_DATA2.
* DO N TIMES.
CLEAR WA_STRUCTURE.
*字段名称
WA_STRUCTURE-FIELDNAME = WA_DATA2-BWART.
*列名称
* CONCATENATE '移动类型' WA_DATA2-BWART INTO WA_STRUCTURE-SCRTEXT_L.
WA_STRUCTURE-SCRTEXT_L = WA_DATA2-BWART.
WA_STRUCTURE-SCRTEXT_M = WA_STRUCTURE-SCRTEXT_L.
WA_STRUCTURE-SCRTEXT_S = WA_STRUCTURE-SCRTEXT_L.
WA_STRUCTURE-COLTEXT = WA_STRUCTURE-SCRTEXT_L.
WA_STRUCTURE-NO_ZERO = 'X'.
WA_STRUCTURE-DO_SUM = 'X'. WA_STRUCTURE-REF_FIELD = 'MENGE'.
WA_STRUCTURE-REF_TABLE = 'EKPO'. WA_STRUCTURE-COL_POS = L_LINES.
APPEND WA_STRUCTURE TO IT_STRUCTURE. L_LINES = L_LINES + .
ENDLOOP.
WA_STRUCTURE-FIELDNAME = 'SUM'.
WA_STRUCTURE-SCRTEXT_L = '行总计'.
WA_STRUCTURE-SCRTEXT_M = WA_STRUCTURE-SCRTEXT_L.
WA_STRUCTURE-SCRTEXT_S = WA_STRUCTURE-SCRTEXT_L.
WA_STRUCTURE-COLTEXT = WA_STRUCTURE-SCRTEXT_L.
WA_STRUCTURE-NO_ZERO = 'X'.
WA_STRUCTURE-DO_SUM = 'X'.
* WA_STRUCTURE-REF_FIELD = 'MENGE'.
* WA_STRUCTURE-REF_TABLE = 'EKPO'.
WA_STRUCTURE-COL_POS = L_LINES.
APPEND WA_STRUCTURE TO IT_STRUCTURE. ENDFORM.
FORM CREAT_TABLE.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_STRUCTURE
IMPORTING
EP_TABLE = IT_TABLE. ASSIGN IT_TABLE->* TO <DYN_TABLE>.
ENDFORM.
FORM DATA_TO_TABLE.
DATA:WA_NEW_LINE TYPE REF TO DATA.
CREATE DATA WA_NEW_LINE LIKE LINE OF <DYN_TABLE>.
ASSIGN WA_NEW_LINE->* TO <DYN_WA>. DATA: L_SUM() TYPE P DECIMALS . DATA:L_FIELDNAME TYPE LVC_S_FCAT-FIELDNAME.
DATA:LW_ERFMG TYPE TY_DATA1.
SORT IT_DATA1 BY WERKS LGORT MATNR.
LOOP AT IT_DATA1 INTO WA_DATA1.
CLEAR:L_FIELDNAME.
L_FIELDNAME = WA_DATA1-BWART.
ASSIGN COMPONENT L_FIELDNAME OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
IF WA_DATA1-MENGE IS NOT INITIAL.
<DYN_FIELD> = WA_DATA1-MENGE.
L_SUM = L_SUM + WA_DATA1-MENGE.
ENDIF.
LW_ERFMG = WA_DATA1.
AT END OF MATNR.
ASSIGN COMPONENT 'WERKS' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
<DYN_FIELD> = LW_ERFMG-WERKS.
ASSIGN COMPONENT 'LGORT' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
<DYN_FIELD> = LW_ERFMG-LGORT.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
<DYN_FIELD> = LW_ERFMG-MATNR.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
<DYN_FIELD> = LW_ERFMG-MAKTX.
* ASSIGN COMPONENT 'BUDAT_MKPF' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
* <DYN_FIELD> = LW_ERFMG-BUDAT_MKPF.
* ASSIGN COMPONENT 'CPUDT_MKPF' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
* <DYN_FIELD> = LW_ERFMG-CPUDT_MKPF.
ASSIGN COMPONENT 'SUM' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
<DYN_FIELD> = L_SUM.
APPEND <DYN_WA> TO <DYN_TABLE>.
CLEAR: L_SUM, <DYN_WA>.
ENDAT. CLEAR: LW_ERFMG, WA_DATA1. ENDLOOP. * DELETE <DYN_TABLE> WHERE MATNR IS INITIAL. ENDFORM.
*设置layout属性
FORM FRM_INIT_LAYOUT .
G_TITLE = TEXT-. CLEAR WA_LAYOUT.
WA_LAYOUT-CWIDTH_OPT = 'X'.
ENDFORM. " FRM_INIT_LAYOUT
FORM FRM_SHOW_ALV.
* * ALV显示函数
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = WA_LAYOUT
IT_FIELDCAT_LVC = IT_STRUCTURE
I_GRID_TITLE = G_TITLE
* i_callback_pf_status_set = 'PF_STATUS_SET'
* IT_EXCLUDING = "系统自带STATUS图标控制内表
I_SAVE = 'A'
* i_callback_pf_status_set = 'PF_STATUS_SET'
* i_callback_user_command = 'FRM_USER_COMMAND'
TABLES
T_OUTTAB = <DYN_TABLE>
EXCEPTIONS
PROGRAM_ERROR =
OTHERS = .
IF SY-SUBRC <> .
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. ENDFORM.
FORM FRM_ALV_FCAT_SET USING PU_POS TYPE I
PU_FNAME TYPE C
PU_FTEXT TYPE C
PU_RFIELD TYPE C
PU_RTABLE TYPE C
PU_QNAME TYPE C
PU_EDIT TYPE C.
CLEAR WA_STRUCTURE.
WA_STRUCTURE-COL_POS = PU_POS.
WA_STRUCTURE-FIELDNAME = PU_FNAME.
WA_STRUCTURE-SCRTEXT_L = PU_FTEXT.
WA_STRUCTURE-SCRTEXT_M = PU_FTEXT.
WA_STRUCTURE-SCRTEXT_S = PU_FTEXT.
WA_STRUCTURE-REF_FIELD = PU_RFIELD.
WA_STRUCTURE-REF_TABLE = PU_RTABLE.
WA_STRUCTURE-QFIELDNAME = PU_QNAME.
WA_STRUCTURE-EDIT = PU_EDIT.
WA_STRUCTURE-KEY = 'X'.
APPEND WA_STRUCTURE TO IT_STRUCTURE.
ENDFORM. " FRM_ALV_FCAT_S

动态ALV表实例-移动类型汇总的更多相关文章

  1. 转ABAP将内表行列转换实例(动态内表) .

    把内表的行列转换,网上的例子很多,但是新人想看懂,几乎很难,所以总结下我是怎么完成的. 比如:你的内表如图: 你想让内表最后展示成这样:如图: 那么完成之后会是这样: 完成这个过程,得用到动态内表.看 ...

  2. ABAP 动态内表 动态ALV

    DATA: DY_TABLE TYPE REF TO DATA, DY_WA TYPE REF TO DATA. FIELD-SYMBOLS: <DYN_TABLE> TYPE TABLE ...

  3. 第三天:字典表dict、元组tuple、文件与类型汇总

    1.字典表dict 声明 {键: 值,...} dict(键=值) d = {'isbn':'13123','title':'python入门'} #字典表中的键不能使用诸如列表这种可以改变的,只能使 ...

  4. sql的存储过程实例--动态根据表数据复制一个表的数据到另一个表

    动态根据表数据复制一个表的数据到另一个表 把track表的记录 根据mac_id后两位数字,复制到对应track_? 的表中 如:mac_id=12345678910,则后两位10 对应表为track ...

  5. ALV TREE 实例

    ALV TREE 实例 REPORT ZRPT_PS_PS021TREE . TABLES: PROJ, "项目定义数据 PRPS, "WBS元素数据 ZCJ30, "A ...

  6. JavaScript正則表達式知识汇总

    Js 正則表達式知识汇总 正則表達式: 1.什么是RegExp?RegExp是正則表達式的缩写.RegExp 对象用于规定在文本中检索的内容. 2.定义RegExp:var +变量名=new RegE ...

  7. ABAP 动态内表添加单元格颜色字段

    *动态内表alv显示时要求某些单元格显示颜色 *wa_fldcat-datatype不能添加LVC_T_SCOL类型,在创建好内表之后,再添加颜色列. DATA: wa_fldcat TYPE lvc ...

  8. 菜鸟学SSH(十八)——Hibernate动态模型+JRebel实现动态创建表

    项目用的是SSH基础框架,当中有一些信息非常相似,但又不尽同样.假设每个建一个实体的话,那样实体会太多.假设分组抽象,然后继承,又不是特别有规律.鉴于这样的情况.就打算让用户自己配置要加入的字段,然后 ...

  9. 学习动态性能表(2)--v$sesstat

    学习动态性能表 第二篇--v$sesstat  2007.5.25 按照OracleOnlineBook中的描述,v$sesstat存储session从login到logout的详细资源使用统计. 类 ...

随机推荐

  1. asp.net core 新建area使用asp-action,asp-controller不管用

    解决方法: 在新建的Area目录下,这里使用Admin,Admin/Views下新建_ViewImports.cshtml和_ViewStart.cshtml两个视图文件,复制项目自动生成的到对应的新 ...

  2. Python安装PyOpenGL

    1.目前PyOpenGL是用python2写的,如果你使用的是python3需要自己修改PyOpenGL,我这里使用的是python2.7 2.下载PyOpenGLhttps://pypi.org/p ...

  3. Java基础—面向对象的三大特性

    面向对象有三大特性分别是继承.封装和多态. (1)继承:继承是一种联结类的层次模型,并且允许和鼓励类的重用,它提供了一种明确表述共性的方法.对象的一个新类可以从现有的类中派生,这个过程称为类继承.新类 ...

  4. CodeForces - 1250B The Feast and the Bus (贪心+暴力)

    题意 https://vjudge.net/problem/CodeForces-1250B 每个人属于队伍ai,汽车一次至多载两只队伍(全员),费用为车的容量*载人次数,问最少花费. 思路 k(队伍 ...

  5. axios+vue实现动态渲染员工数据+数据是对象

    <style> table{ width: 600px; margin: 0 auto; text-align: center; border-collapse: collapse; /* ...

  6. 【cf600】E. Lomsat gelral(dsu on tree)

    传送门 题意: 求子树众数. 思路: \(dsu\ on\ tree\)模板题,用一个桶记录即可. 感觉\(dsu\ on\ tree\)这个算法的涉及真是巧妙呀,保留重链的信息,不断暴力轻边,并且不 ...

  7. Html学习之十五(盒模型)

    Web页面中的每一个元素都是一个盒模型,CSS中使用盒模型来描述一个元素.CSS盒子模型又称框模型,它包含四个边界,分别是外边距边界(Margin).边框边界(border).内边距边界(paddin ...

  8. scrapy 爬取图片

    scrapy 爬取图片 1.scrapy 有下载图片的自带接口,不用我们在去实现 setting.py设置 # 保存log信息的文件名 LOG_LEVEL = "INFO" # L ...

  9. ioctl操作

    在本书中有两个地方都对这个函数进行了介绍,其实还有很多地方需要这个函数.ioclt函数传统上一直作为纳西而不适合归入其他精细定义类别的特性的系统接口.网络程序(特别是服务器程序)经常在程序启动执行后使 ...

  10. 设计模式-抽象工厂模式(AbstractFactory)(创建型模式)

    //以下代码来源: 设计模式精解-GoF 23种设计模式解析附C++实现源码 //Product.h #pragma once class AbstractProductA { public: vir ...