Chinaunix首页 | 论坛 | 博客
  • 博客访问: 233541
  • 博文数量: 17
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 329
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-31 20:05
个人简介

linux kernal research

文章分类

全部博文(17)

文章存档

2023年(7)

2013年(10)

分类: 项目管理

2013-09-01 10:03:46

开发程序,在屏幕上输入时间范围(多选),工厂(单选),物料编号(多选),然后显示物料的库存数量和在这段时间内(VBAK-ERDAT)的销售数量。
要求:要对工厂输入的值进行有效性检查;用WRITE列表输出;库存数量只统计非限制使用库存(MARD-LABST);销售数量只统计销售订单类型(VBAK-AUART)为TA的销售数量。
输出字段:工厂(MARD-WERKS),物料编号(MARD-MATNR),物料描述(MAKT-MAKTX),销售数量(VBAP-KWMENG),单位(MARA-MEINS),库存数量(MARD-LABST),单位(VBAP-MEINS)
参考表:T001W    MARD   MAKT   MARA   VBAK    VBAP

本题老师的解法及其ALV输出:SAP 内表的ALV输出


  1. *&---------------------------------------------------------------------*
  2. *& Report ZY20130830_ITAB
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*

  8. REPORT ZY20130830_ITAB.
  9. TABLES: vbak, mard.

  10. "定义物料工作区、物料内表
  11. DATA: BEGIN OF wa_material,
  12.   werks TYPE mard-werks, "工厂
  13.   matnr TYPE mard-matnr, "物料编号
  14.   maktx TYPE makt-maktx, "物料描述
  15.   kwmeng TYPE vbap-kwmeng, "销售数量
  16.   meins TYPE mara-meins, "单位
  17.   labst TYPE mard-labst, "库存数量
  18.   mein2 TYPE vbap-meins, "单位
  19. END OF wa_material.
  20. DATA: itab_material LIKE STANDARD TABLE OF wa_material.

  21. "定义销售工作区、销售内表
  22. DATA: BEGIN OF wa_sale,
  23.   vbeln TYPE vbak-vbeln, "销售凭证
  24.   erdat TYPE vbak-erdat, "销售日期
  25.   matnr TYPE vbap-matnr, "物料号
  26.   kwmeng TYPE vbap-kwmeng, "累计销售数量
  27.   meins TYPE vbap-meins, "单位
  28. END OF wa_sale.
  29. DATA: itab_sale LIKE STANDARD TABLE OF wa_sale.

  30. "定义屏幕
  31. SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE t01.
  32.   PARAMETERS: p_werks TYPE mard-werks.
  33.   SELECT-OPTIONS: s_erdat FOR vbak-erdat,
  34.                   s_matnr FOR mard-matnr.
  35. SELECTION-SCREEN: END OF BLOCK b1.

  36. "初始化参数
  37. INITIALIZATION.
  38. p_werks = '1000'. "工厂编码
  39. s_erdat-sign = 'I'. "日期类型
  40. s_erdat-option = 'BT'. "日期选项
  41. s_erdat-low = '20130830'. "开始日期
  42. s_erdat-high = '20130930'. "结束日期
  43. APPEND s_erdat.

  44. "屏幕选择
  45. AT SELECTION-SCREEN.

  46. "屏幕有效性检查
  47. DATA: w_werks TYPE mard-werks.
  48. SELECT SINGLE werks
  49.   INTO w_werks
  50.   FROM t001w
  51.   WHERE werks = p_werks.
  52. IF sy-subrc <> 0.
  53.   MESSAGE '没有您输入的工厂' TYPE 'E'.
  54. ENDIF.

  55. "开始取数
  56. START-OF-SELECTION.
  57. **取库存数量
  58. PERFORM get_mard.
  59. **取销售订单数量
  60. PERFORM get_sale.
  61. **加工数据
  62. PERFORM tidy_data.
  63. **数据输出
  64. PERFORM write_data.

  65. "取库存数量
  66. FORM get_mard.
  67.   SELECT mard~werks mard~matnr mard~labst makt~maktx mara~meins
  68.     INTO CORRESPONDING FIELDS OF TABLE itab_material
  69.     FROM mard
  70.     INNER JOIN makt ON mard~matnr = makt~matnr
  71.     INNER JOIN mara ON mard~matnr = mara~matnr
  72.     WHERE mard~matnr IN s_matnr
  73.     AND mard~werks = p_werks
  74.     AND makt~spras = 'E'.
  75. ENDFORM.

  76. "取销售订单数量
  77. FORM get_sale.
  78.   CHECK itab_material IS NOT INITIAL.
  79.   SELECT vbak~vbeln vbak~erdat vbap~matnr vbap~kwmeng vbap~meins
  80.     INTO CORRESPONDING FIELDS OF TABLE itab_sale
  81.     FROM vbak
  82.     INNER JOIN vbap ON vbak~vbeln = vbap~vbeln
  83.     FOR ALL ENTRIES IN itab_material
  84.     WHERE vbap~matnr = itab_material-matnr
  85.     AND vbak~erdat IN s_erdat
  86.     AND vbak~auart = 'ZSBC'.
  87. ENDFORM.

  88. "加工数据
  89. FORM tidy_data.
  90.   LOOP AT itab_material INTO wa_material.
  91.     DATA: d_kwmeng TYPE vbap-kwmeng.
  92.     d_kwmeng = 0.
  93. ****销量汇总
  94.     LOOP AT itab_sale INTO wa_sale WHERE matnr = wa_material-matnr.
  95.       d_kwmeng = d_kwmeng + wa_sale-kwmeng.
  96.       wa_material-mein2 = wa_sale-meins.
  97.       CLEAR wa_sale.
  98.     ENDLOOP.
  99.     wa_material-kwmeng = d_kwmeng. "汇总得到物料的销量
  100.     MODIFY itab_material FROM wa_material.
  101.     CLEAR wa_material.
  102.   ENDLOOP.
  103. ENDFORM.

  104. "数据输出
  105. FORM write_data.
  106.   LOOP AT itab_material INTO wa_material.
  107.     WRITE: /4(12) wa_material-werks, "工厂
  108.             16(10) wa_material-matnr, "物料编号
  109.             28(20) wa_material-maktx, "物料描述
  110.             48(10) wa_material-kwmeng, "销售数量
  111.             61(4) wa_material-meins, "单位
  112.             68(10) wa_material-labst, "库存数量
  113.             80(10) wa_material-mein2. "单位
  114.   ENDLOOP.
  115. ENDFORM.


阅读(4421) | 评论(0) | 转发(0) |
0

上一篇:SAP 概念区别

下一篇:SAP 内表的ALV输出

给主人留下些什么吧!~~