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. C# rename files

    static void RenameFiles() { string sourceDir = @"D:\ll"; string[] allFiles = Directory.Get ...

  2. \" 转义字符, \a系统警报,逐字字符串(verbatim string)

    string str="The key factors are \"focus\" and \"perseverance\""; strin ...

  3. SRDC - ORA-30013: Checklist of Evidence to Supply (Doc ID 1682701.1)

    Action Plan 1. Execute srdc_db_undo_ora-30013.sql as sysdba and provide the spool output --srdc_db_u ...

  4. k8s资产清单(二)

    什么是清单 说白了清单是k8s当中用来定义pod的文件,语法格式遵循yaml语法,在yaml当中可以定义控制器类型,元数据,容器端口号等等等....,也可以针对于清单对pod进行删除等操作 为什么太学 ...

  5. [视频教程] 灵活配置多版本PHP并存运行

    经常有一些项目需要使用不同版本的PHP运行环境,比如有的老项目需要使用5.3版本,有的新项目比如laravel需要使用7.2以上版本,那么在一台机器上如何多版本PHP并存运行呢 有一种很灵活高效的方式 ...

  6. logistic 回归(线性和非线性)

    一:线性logistic 回归 代码如下: import numpy as np import pandas as pd import matplotlib.pyplot as plt import ...

  7. Centos 7 LAMP+wordpress

    一.简介        LAMP--->Linux(OS).Apache(http服务器),MySQL(有时也指MariaDB,数据库) 和PHP的第一个字母,一般用来建立web应用平台. 它是 ...

  8. 批量文件B中选出部分文件(与A文件夹数量相同),放到C中

    import glob import os,sys import shutil fileDir = 'F:/project/Breast/InBreast/INBreast/outimgpatch/n ...

  9. SpringMVC环境搭建(二)

    一.基于XML 1. 创建Maven Project,选择war,修改pom.xml SpringMVC是依赖于Spring的,需要导入核心包. <properties> <!-- ...

  10. 01_javaSE面试题:自增变量

    开启刷面试题,都是根据视频进行刷面试题的 自增变量,只要记住两点 i++ 是先赋值后计算 ++i 是先计算后赋值 看下面的代码 int i = 1; i = i++; int j = i++; int ...