开发程序,在屏幕上输入时间范围(多选),工厂(单选),物料编号(多选),然后显示物料的库存数量和在这段时间内(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输出
-
*&---------------------------------------------------------------------*
-
*& Report ZY20130830_ITAB
-
*&
-
*&---------------------------------------------------------------------*
-
*&
-
*&
-
*&---------------------------------------------------------------------*
-
-
REPORT ZY20130830_ITAB.
-
TABLES: vbak, mard.
-
-
"定义物料工作区、物料内表
-
DATA: BEGIN OF wa_material,
-
werks TYPE mard-werks, "工厂
-
matnr TYPE mard-matnr, "物料编号
-
maktx TYPE makt-maktx, "物料描述
-
kwmeng TYPE vbap-kwmeng, "销售数量
-
meins TYPE mara-meins, "单位
-
labst TYPE mard-labst, "库存数量
-
mein2 TYPE vbap-meins, "单位
-
END OF wa_material.
-
DATA: itab_material LIKE STANDARD TABLE OF wa_material.
-
-
"定义销售工作区、销售内表
-
DATA: BEGIN OF wa_sale,
-
vbeln TYPE vbak-vbeln, "销售凭证
-
erdat TYPE vbak-erdat, "销售日期
-
matnr TYPE vbap-matnr, "物料号
-
kwmeng TYPE vbap-kwmeng, "累计销售数量
-
meins TYPE vbap-meins, "单位
-
END OF wa_sale.
-
DATA: itab_sale LIKE STANDARD TABLE OF wa_sale.
-
-
"定义屏幕
-
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE t01.
-
PARAMETERS: p_werks TYPE mard-werks.
-
SELECT-OPTIONS: s_erdat FOR vbak-erdat,
-
s_matnr FOR mard-matnr.
-
SELECTION-SCREEN: END OF BLOCK b1.
-
-
"初始化参数
-
INITIALIZATION.
-
p_werks = '1000'. "工厂编码
-
s_erdat-sign = 'I'. "日期类型
-
s_erdat-option = 'BT'. "日期选项
-
s_erdat-low = '20130830'. "开始日期
-
s_erdat-high = '20130930'. "结束日期
-
APPEND s_erdat.
-
-
"屏幕选择
-
AT SELECTION-SCREEN.
-
-
"屏幕有效性检查
-
DATA: w_werks TYPE mard-werks.
-
SELECT SINGLE werks
-
INTO w_werks
-
FROM t001w
-
WHERE werks = p_werks.
-
IF sy-subrc <> 0.
-
MESSAGE '没有您输入的工厂' TYPE 'E'.
-
ENDIF.
-
-
"开始取数
-
START-OF-SELECTION.
-
**取库存数量
-
PERFORM get_mard.
-
**取销售订单数量
-
PERFORM get_sale.
-
**加工数据
-
PERFORM tidy_data.
-
**数据输出
-
PERFORM write_data.
-
-
"取库存数量
-
FORM get_mard.
-
SELECT mard~werks mard~matnr mard~labst makt~maktx mara~meins
-
INTO CORRESPONDING FIELDS OF TABLE itab_material
-
FROM mard
-
INNER JOIN makt ON mard~matnr = makt~matnr
-
INNER JOIN mara ON mard~matnr = mara~matnr
-
WHERE mard~matnr IN s_matnr
-
AND mard~werks = p_werks
-
AND makt~spras = 'E'.
-
ENDFORM.
-
-
"取销售订单数量
-
FORM get_sale.
-
CHECK itab_material IS NOT INITIAL.
-
SELECT vbak~vbeln vbak~erdat vbap~matnr vbap~kwmeng vbap~meins
-
INTO CORRESPONDING FIELDS OF TABLE itab_sale
-
FROM vbak
-
INNER JOIN vbap ON vbak~vbeln = vbap~vbeln
-
FOR ALL ENTRIES IN itab_material
-
WHERE vbap~matnr = itab_material-matnr
-
AND vbak~erdat IN s_erdat
-
AND vbak~auart = 'ZSBC'.
-
ENDFORM.
-
-
"加工数据
-
FORM tidy_data.
-
LOOP AT itab_material INTO wa_material.
-
DATA: d_kwmeng TYPE vbap-kwmeng.
-
d_kwmeng = 0.
-
****销量汇总
-
LOOP AT itab_sale INTO wa_sale WHERE matnr = wa_material-matnr.
-
d_kwmeng = d_kwmeng + wa_sale-kwmeng.
-
wa_material-mein2 = wa_sale-meins.
-
CLEAR wa_sale.
-
ENDLOOP.
-
wa_material-kwmeng = d_kwmeng. "汇总得到物料的销量
-
MODIFY itab_material FROM wa_material.
-
CLEAR wa_material.
-
ENDLOOP.
-
ENDFORM.
-
-
"数据输出
-
FORM write_data.
-
LOOP AT itab_material INTO wa_material.
-
WRITE: /4(12) wa_material-werks, "工厂
-
16(10) wa_material-matnr, "物料编号
-
28(20) wa_material-maktx, "物料描述
-
48(10) wa_material-kwmeng, "销售数量
-
61(4) wa_material-meins, "单位
-
68(10) wa_material-labst, "库存数量
-
80(10) wa_material-mein2. "单位
-
ENDLOOP.
-
ENDFORM.
阅读(4421) | 评论(0) | 转发(0) |