SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L1S31 { font-style. italic; color: #808080; } .L1S32 { color: #3399FF; } .L1S33 { color: #4DA619; } .L1S52 { color: #0000FF; }
***********************************************************************
*author: xiao p hai.
*date : 2010/03/29
************************************************************************
REPORT z_cost_analysis_01 MESSAGE- ID zreportmsg.
*ALV类型定义
TYPE-POOLS: slis.
************************************************************************
* DATA *
************************************************************************
DATA: rec_ekpo LIKE ekpo, "采购文件项目
rec_ekko LIKE ekko, "采购文件头
rec_eket LIKE eket, "调度协议计划线
rec_qals LIKE qals. "抽检记录表
*存储查询数据库记录的结构体
DATA: BEGIN OF str_tab1,
ebeln LIKE ekko-ebeln, "采购订单号
ebelp LIKE ekpo-ebelp, "项目
banfn LIKE ekpo-banfn, "采购申请号
BNFPO like ekpo-BNFPO, "采购申请项目号
lifnr LIKE ekko-lifnr, "供应商
werks LIKE ekpo-werks, "工厂代码
ekorg LIKE ekko-ekorg, "采购组织
ekgrp LIKE ekko-ekgrp, "采购组
matkl LIKE ekpo-matkl, "物料组
bsart LIKE ekko-bsart, "凭证类型
loekz LIKE ekpo-loekz, "删除标识
knttp LIKE ekpo-knttp, "A
pstyp LIKE ekpo-pstyp, "I
matnr LIKE ekpo-matnr, "物料编码
txz01 LIKE ekpo-txz01, "物料描述
peinh LIKE ekpo-peinh, "价格单位
meins LIKE ekpo-meins, "单位
netpr LIKE ekpo-netpr, "价格
waers LIKE ekko-waers, "货币
menge LIKE ekpo-menge, "采购数量
wemng LIKE eket-wemng, "已交货数量
lgort LIKE ekpo-lgort, "交货地点
eindt LIKE eket-eindt, "交货日期
ernam LIKE ekko-ernam, "采购订单创建人
bedat LIKE ekko-bedat, "采购订单日期
elikz LIKE ekpo-elikz, "已完成交货标识
losmenge LIKE qals-losmenge, "检验批数量
lmenge01 LIKE qals-lmenge01, "合格数量
lmenge07 LIKE qals-lmenge07, "退货数量
obmng LIKE eket-wemng, "未交货数量
zmenge LIKE qals-losmenge, "质检库存数量
menge_I like ekbe-menge , "开票数量
menge_n like ekbe-menge , "未开票数量
BADAT type BADAT , "采购申请日期
NAME1 type NAME1_GP , "供应商描述
END OF str_tab1.
*存储查询数据库记录的内表
DATA tbl_tab1 LIKE TABLE OF str_tab1 with header line .
*存储ALV输出记录的结构体
DATA str_tab2 LIKE str_tab1.
*存储ALV输出记录的内表
DATA tbl_tab2 LIKE TABLE OF str_tab2.
**采购订单物料历史
data : begin of t_ekbe occurs 0 ,
ebeln type ebeln ,
ebelp type ebelp ,
menge like ekbe-menge ,
shkzg type shkzg ,
end of t_ekbe .
data : begin of t_eban occurs 0 ,
BANFN type BANFN ,
BNFPO TYPE BNFPO ,
BADAT TYPE BADAT ,
END OF T_EBAN .
DATA w_obmng LIKE eket-wemng. "临时变量(未交货数量)
DATA cnt_obmng LIKE eket-wemng. "合计变量(未交货数量)
DATA cnt_menge LIKE ekpo-menge. "合计变量(采购数量)
DATA cnt_wemng LIKE eket-wemng. "合计变量(已交货数量)
DATA w_zmenge LIKE qals-losmenge. "临时变量(质检库存量)
DATA cnt_zmenge LIKE qals-losmenge. "合计变量(质检库存量)
DATA flg_ebelp. "*
DATA: w_repid LIKE sy-repid, "程序名称变量
w_layout TYPE slis_layout_alv, "程序外观变量
w_fieldcat1 TYPE slis_t_fieldcat_alv,
w_fieldcat2 TYPE slis_t_fieldcat_alv,
w_fieldcat3 LIKE LINE OF w_fieldcat1,
w_events TYPE slis_t_event,
w_header TYPE slis_t_listheader, "ALV标题变量
w_event TYPE slis_alv_event.
************************************************************************
* PARAMETERS *
************************************************************************
PARAMETERS rb_sel1 RADIOBUTTON GROUP rad1 "按物料查询按钮
USER-COMMAND radio
DEFAULT 'X'.
SELECTION- SCREEN BEGIN OF BLOCK block1 WITH FRAME.
SELECT-OPTIONS: s_matnr1 FOR rec_ekpo-matnr, "屏幕参数(物料编码)
* MATCHCODE OBJECT mat1,
s_matkl1 FOR rec_ekpo-matkl, "屏幕参数(物料组)
s_bsart1 FOR rec_ekko-bsart, "屏幕参数(凭证类型)
s_werks1 FOR rec_ekpo-werks, "屏幕参数(工厂代码)
s_bedat1 FOR rec_ekko-bedat, "屏幕参数(采购订单日期)
s_aedat1 FOR rec_ekpo-aedat. "屏幕参数(交货日期)
PARAMETERS cb_chk1 AS CHECKBOX. "未清PO查询复选框
SELECTION- SCREEN END OF BLOCK block1.
PARAMETERS rb_sel2 RADIOBUTTON GROUP rad1. "按供应商查询按钮
SELECTION- SCREEN BEGIN OF BLOCK block2 WITH FRAME.
SELECT-OPTIONS: s_lifnr2 FOR rec_ekko-lifnr, "屏幕参数(供应商)
s_werks2 FOR rec_ekpo-werks, "屏幕参数(工厂代码)
s_ekgrp2 FOR rec_ekko-ekgrp, "屏幕参数(采购组)
s_bsart2 FOR rec_ekko-bsart, "屏幕参数(凭证类型)
s_bedat2 FOR rec_ekko-bedat. "屏幕参数(采购订单日期)
PARAMETERS cb_chk2 AS CHECKBOX. "未清PO查询复选框
SELECTION- SCREEN END OF BLOCK block2.
PARAMETERS rb_sel3 RADIOBUTTON GROUP rad1. "按采购订单查询按钮
SELECTION- SCREEN BEGIN OF BLOCK block3 WITH FRAME.
SELECT-OPTIONS: s_ebeln3 FOR rec_ekko-ebeln, "屏幕参数(采购订单号)
s_werks3 FOR rec_ekpo-werks, "屏幕参数(工厂代码)
s_bsart3 FOR rec_ekko-bsart, "屏幕参数(凭证类型)
s_bedat3 FOR rec_ekko-bedat. "屏幕参数(采购订单日期)
PARAMETERS cb_chk3 AS CHECKBOX. "未清PO查询复选框
SELECTION- SCREEN END OF BLOCK block3.
************************************************************************
* INITIALIZATION *
************************************************************************
INITIALIZATION.
************************************************************************
* AT SELECTION-SCREEN *
************************************************************************
AT SELECTION- SCREEN OUTPUT.
PERFORM set_screen_input. "设定屏幕输入状态
************************************************************************
* START-OF-SELECTION *
************************************************************************
START- OF-SELECTION.
PERFORM chose_select_options. "选择查询方式
PERFORM prepare_alv_data. "准备ALV输出数据
PERFORM alv_control_output. "ALV相关控制
PERFORM call_alv_function. "调用ALV函数
*&---------------------------------------------------------------------*
*& Form set_screen_input
*&---------------------------------------------------------------------*
* 设定屏幕输入状态
*----------------------------------------------------------------------*
FORM set_screen_input .
LOOP AT SCREEN.
* 循环屏幕BLOCK1中元素
IF screen-name = 'S_MATNR1-LOW'
OR screen-name = 'S_MATNR1-HIGH'
OR screen-name = 'S_MATKL1-LOW'
OR screen-name = 'S_MATKL1-HIGH'
OR screen-name = 'S_BSART1-LOW'
OR screen-name = 'S_BSART1-HIGH'
OR screen-name = 'S_WERKS1-LOW'
OR screen-name = 'S_WERKS1-HIGH'
OR screen-name = 'S_BEDAT1-LOW'
OR screen-name = 'S_BEDAT1-HIGH'
OR screen-name = 'S_AEDAT1-LOW'
OR screen-name = 'S_AEDAT1-HIGH'
OR screen-name = 'CB_CHK1'.
* 判断查询方式
CASE 'X'.
WHEN rb_sel1. "按物料查询
screen- input = 1. "可输入
WHEN rb_sel2. "按供应商查询
screen- input = 0. "不可输入
WHEN rb_sel3. "按采购订单查询
screen- input = 0. "不可输入
ENDCASE.
MODIFY SCREEN.
ENDIF.
* 循环屏幕BLOCK2中元素
IF screen-name = 'S_LIFNR2-LOW'
OR screen-name = 'S_LIFNR2-HIGH'
OR screen-name = 'S_WERKS2-LOW'
OR screen-name = 'S_WERKS2-HIGH'
OR screen-name = 'S_EKGRP2-LOW'
OR screen-name = 'S_EKGRP2-HIGH'
OR screen-name = 'S_BSART2-LOW'
OR screen-name = 'S_BSART2-HIGH'
OR screen-name = 'S_BEDAT2-LOW'
OR screen-name = 'S_BEDAT2-HIGH'
OR screen-name = 'CB_CHK2'.
* 判断查询方式
CASE 'X'.
WHEN rb_sel1. "按物料查询
screen- input = 0. "不可输入
WHEN rb_sel2. "按供应商查询
screen- input = 1. "可输入
WHEN rb_sel3. "按采购订单查询
screen- input = 0. "不可输入
ENDCASE.
MODIFY SCREEN.
ENDIF.
* 循环屏幕BLOCK3中元素
IF screen-name = 'S_EBELN3-LOW'
OR screen-name = 'S_EBELN3-HIGH'
OR screen-name = 'S_WERKS3-LOW'
OR screen-name = 'S_WERKS3-HIGH'
OR screen-name = 'S_BSART3-LOW'
OR screen-name = 'S_BSART3-HIGH'
OR screen-name = 'S_BEDAT3-LOW'
OR screen-name = 'S_BEDAT3-HIGH'
OR screen-name = 'CB_CHK3'.
* 判断查询方式
CASE 'X'.
WHEN rb_sel1. "按物料查询
screen- input = 0. "不可输入
WHEN rb_sel2. "按供应商查询
screen- input = 0. "不可输入
WHEN rb_sel3. "按采购订单查询
screen- input = 1. "可输入
ENDCASE.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDFORM. " set_screen_input
*&---------------------------------------------------------------------*
*& Form chose_select_options
*&---------------------------------------------------------------------*
* 选择查询方式
*----------------------------------------------------------------------*
FORM chose_select_options .
CASE 'X'. "判断查询方式
WHEN rb_sel1. "按物料查询
PERFORM get_data_ekpo1. "按物料查查询数据
WHEN rb_sel2. "按供应商查询
PERFORM get_data_ekpo2. "按供应商查询数据
WHEN rb_sel3. "按采购订单查询
PERFORM get_data_ekpo3. "按采购订单查询数据
ENDCASE.
DELETE tbl_tab1 WHERE loekz = 'L'.
perform get_invoice_data .
SORT tbl_tab1 BY ebeln ebelp. "按采购订单号、项目
"排序
ENDFORM. " select_options
*&---------------------------------------------------------------------*
*& Form get_data_ekpo1
*&---------------------------------------------------------------------*
* 按物料查查询数据
*----------------------------------------------------------------------*
FORM get_data_ekpo1 .
SELECT ekko~ebeln "采购订单号
ekpo~ebelp "项目
ekpo~banfn "采购申请号
ekpo~BNFPO "采购申请项次
ekko~lifnr "供应商
ekpo~werks "工厂代码
ekko~ekorg "采购组织
ekko~ekgrp "采购组
ekpo~matkl "物料组
ekko~bsart "凭证类型
ekpo~loekz "删除标识
ekpo~knttp "A
ekpo~pstyp "I
ekpo~matnr "物料编码
ekpo~txz01 "物料描述
ekpo~peinh "价格单位
ekpo~meins "单位
ekpo~netpr "价格
ekko~waers "货币
ekpo~menge "采购数量
eket~wemng "已交货数量
ekpo~lgort "交货地点
eket~eindt "交货日期
ekko~ernam "采购订单创建人
ekko~bedat "采购订单日期
ekpo~elikz "已完成交货标识
* qals~losmenge "检验批数量
* qals~lmenge01 "合格数量
* qals~lmenge07 "退货数量
FROM ( ( ekpo
JOIN ekko ON ekko~ebeln = ekpo~ebeln "采购订单号
JOIN eket ON eket~ebeln = ekpo~ebeln "采购订单号
AND eket~ebelp = ekpo~ebelp ) ) "项目
* LEFT JOIN qals ON qals~ebeln = ekpo~ebeln "采购订单号
* AND qals~ebelp = ekpo~ebelp ) "项目
INTO TABLE tbl_tab1
WHERE ekpo~matnr IN s_matnr1 "物料编码
AND ekpo~matkl IN s_matkl1 "物料组
AND ekko~bsart IN s_bsart1 "凭证类型
AND ekpo~werks IN s_werks1 "工厂代码
AND ekko~bedat IN s_bedat1 "采购订单日期
AND ekpo~aedat IN s_aedat1. "交货日期
IF sy-subrc <> 0. "查询失败
MESSAGE s000.
ENDIF.
IF cb_chk1 = 'X'. "选择未清PO查询
DELETE tbl_tab1 WHERE elikz = 'X'. "删除已完成订单
ENDIF.
ENDFORM. " get_data_1
*&---------------------------------------------------------------------*
*& Form get_data_ekpo2
*&---------------------------------------------------------------------*
* 按供应商查询数据
*----------------------------------------------------------------------*
FORM get_data_ekpo2 .
select ekko~ebeln "采购订单号
ekpo~ebelp "项目
ekpo~banfn "采购申请号
ekpo~bnfpo "采购申请项次
ekko~lifnr "供应商
ekpo~werks "工厂代码
ekko~ekorg "采购组织
ekko~ekgrp "采购组
ekpo~matkl "物料组
ekko~bsart "凭证类型
ekpo~loekz "删除标识
ekpo~knttp "A
ekpo~pstyp "I
ekpo~matnr "物料编码
ekpo~txz01 "物料描述
ekpo~peinh "价格单位
ekpo~meins "单位
ekpo~netpr "价格
ekko~waers "货币
ekpo~menge "采购数量
eket~wemng "已交货数量
ekpo~lgort "交货地点
eket~eindt "交货日期
ekko~ernam "采购订单创建人
ekko~bedat "采购订单日期
ekpo~elikz "已完成交货标识
* qals~losmenge "检验批数量
* qals~lmenge01 "合格数量
* qals~lmenge07 "退货数量
FROM ( ( ekpo
JOIN ekko ON ekko~ebeln = ekpo~ebeln "采购订单号
JOIN eket ON eket~ebeln = ekpo~ebeln "采购订单号
AND eket~ebelp = ekpo~ebelp ) ) "项目
* LEFT JOIN qals ON qals~ebeln = ekpo~ebeln "采购订单号
* AND qals~ebelp = ekpo~ebelp ) "项目
INTO TABLE tbl_tab1
WHERE ekko~lifnr IN s_lifnr2 "供应商
AND ekpo~werks IN s_werks2 "工厂代码
AND ekko~ekgrp IN s_ekgrp2 "采购组
AND ekko~bsart IN s_bsart2 "凭证类型
AND ekko~bedat IN s_bedat2. "采购订单日期
IF sy-subrc <> 0. "查询失败
MESSAGE s000.
ENDIF.
IF cb_chk2 = 'X'. "选择未清PO查询
DELETE tbl_tab1 WHERE elikz = 'X'. "删除已完成订单
ENDIF.
ENDFORM. " get_data_2
*&---------------------------------------------------------------------*
*& Form get_data_ekpo3
*&---------------------------------------------------------------------*
* 按采购订单查询数据
*----------------------------------------------------------------------*
FORM get_data_ekpo3 .
select ekko~ebeln "采购订单号
ekpo~ebelp "项目
ekpo~banfn "采购申请号
ekpo~bnfpo "采购申请项次
ekko~lifnr "供应商
ekpo~werks "工厂代码
ekko~ekorg "采购组织
ekko~ekgrp "采购组
ekpo~matkl "物料组
ekko~bsart "凭证类型
ekpo~loekz "删除标识
ekpo~knttp "A
ekpo~pstyp "I
ekpo~matnr "物料编码
ekpo~txz01 "物料描述
ekpo~peinh "价格单位
ekpo~meins "单位
ekpo~netpr "价格
ekko~waers "货币
ekpo~menge "采购数量
eket~wemng "已交货数量
ekpo~lgort "交货地点
eket~eindt "交货日期
ekko~ernam "采购订单创建人
ekko~bedat "采购订单日期
ekpo~elikz "已完成交货标识
* qals~losmenge "检验批数量
* qals~lmenge01 "合格数量
* qals~lmenge07 "退货数量
FROM ( ( ekpo
JOIN ekko ON ekko~ebeln = ekpo~ebeln "采购订单号
JOIN eket ON eket~ebeln = ekpo~ebeln "采购订单号
AND eket~ebelp = ekpo~ebelp ) ) "项目
* LEFT JOIN qals ON qals~ebeln = ekpo~ebeln "采购订单号
* AND qals~ebelp = ekpo~ebelp ) "项目
INTO TABLE tbl_tab1
WHERE ekko~ebeln IN s_ebeln3 "采购订单号
AND ekpo~werks IN s_werks3 "工厂代码
AND ekko~bsart IN s_bsart3 "凭证类型
AND ekko~bedat IN s_bedat3. "采购订单日期
IF sy-subrc <> 0. "查询失败
MESSAGE s000.
ENDIF.
IF cb_chk3 = 'X'. "选择未清PO查询
DELETE tbl_tab1 WHERE elikz = 'X'. "删除已完成订单
ENDIF.
ENDFORM. " get_data_3
*&---------------------------------------------------------------------*
*& Form prepare_alv_data
*&---------------------------------------------------------------------*
* 准备ALV输出数据
*----------------------------------------------------------------------*
FORM prepare_alv_data .
* 删除有删除标记的纪录
LOOP AT tbl_tab1 INTO str_tab1 .
AT END OF ebelp.
MOVE 'X' TO flg_ebelp.
ENDAT.
IF flg_ebelp = 'X'.
w_obmng = str_tab1-menge - str_tab1-wemng. "计算临时变量(未交货数量)
cnt_obmng = cnt_obmng + w_obmng. "计算合计变量(未交货数量)
cnt_menge = cnt_menge + str_tab1-menge. "计算合计变量(采购数量)
cnt_wemng = cnt_wemng + str_tab1-wemng. "计算合计变量(已交货数量)
CLEAR flg_ebelp.
ENDIF.
w_zmenge = str_tab1-losmenge "计算临时变量(质检库存量)
- str_tab1-lmenge01
- str_tab1-lmenge07.
cnt_zmenge = cnt_zmenge + w_zmenge. "计算合计变量(质检库存量)
MOVE str_tab1 TO str_tab2. "结构体赋值
AT END OF ebeln. "按相同采购订单号合计
str_tab2-obmng = cnt_obmng. "合计变量赋值
str_tab2-menge = cnt_menge. "合计变量赋值
str_tab2-wemng = cnt_wemng. "合计变量赋值
str_tab2-zmenge = cnt_zmenge. "合计变量赋值
APPEND str_tab2 TO tbl_tab2. "追加至内表
CLEAR w_obmng.
CLEAR w_zmenge.
CLEAR cnt_zmenge.
CLEAR cnt_obmng.
CLEAR cnt_menge.
CLEAR cnt_wemng.
ENDAT.
CLEAR str_tab1.
ENDLOOP.
IF tbl_tab2 IS INITIAL. "处理后无数据
MESSAGE s000.
ENDIF.
ENDFORM. " prepare_alv_data
*&---------------------------------------------------------------------*
*& Form alv_control_output
*&---------------------------------------------------------------------*
* ALV相关控制
*----------------------------------------------------------------------*
FORM alv_control_output .
w_repid = sy-repid. "程序名称
PERFORM build_alv_catalog. "设定ALV显示顺序及标签
w_event-name = 'TOP_OF_PAGE'.
w_event- form = 'TOP_OF_PAGE'.
APPEND w_event TO w_events.
PERFORM prepare_standard_header. "设定ALV标准标题
ENDFORM. " alv_control_output
*&---------------------------------------------------------------------*
*& Form build_alv_catalog
*&---------------------------------------------------------------------*
* 设定ALV显示顺序及标签
*----------------------------------------------------------------------*
FORM build_alv_catalog .
* 输出采购申请号
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BANFN'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3- key = 'X'.
w_fieldcat3-seltext_l = '采购申请号'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购申请日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BADAT'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '采购申请日期'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购申请日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BNFPO'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '项次'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购订单号
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'EBELN'.
w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '采购订单号'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购订单日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BEDAT'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '采购订单日期'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出交货日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'EINDT'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '交货日期'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出供应商 改为供应商名称
* CLEAR w_fieldcat3.
* w_fieldcat3-fieldname = 'LIFNR'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
** w_fieldcat3-key = 'X'.
* w_fieldcat3-seltext_l = '供应商'.
* w_fieldcat3-outputlen = 10.
* APPEND w_fieldcat3 TO w_fieldcat1.
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'NAME1'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '供应商名称'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出物料编码
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MATNR'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '物料编码'.
w_fieldcat3-outputlen = 18.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出物料描述
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'TXZ01'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '物料描述'.
w_fieldcat3-outputlen = 40.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购组
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'EKGRP'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '采购组'.
w_fieldcat3-outputlen = 3.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出单位
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MEINS'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '单位'.
w_fieldcat3-outputlen = 3.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MENGE'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '采购数量'.
w_fieldcat3-outputlen = 13.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出已交货数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'WEMNG'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '已交货数量'.
w_fieldcat3-outputlen = 13.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出未交货数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'OBMNG'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '未交货数量'.
w_fieldcat3-outputlen = 13.
APPEND w_fieldcat3 TO w_fieldcat1.
* 已开票数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MENGE_I' .
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '已开票数量'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
* 未开票数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MENGE_N' .
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '未开票数量'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
ENDFORM. " build_alv_catalog
*&---------------------------------------------------------------------*
*& Form prepare_standard_header
*&---------------------------------------------------------------------*
* 设定ALV标准标题
*----------------------------------------------------------------------*
FORM prepare_standard_header .
DATA line TYPE slis_listheader.
line-typ = 'H'.
line-info = 'PO未交货明细查询报表'.
APPEND line TO w_header.
ENDFORM. " prepare_standard_header
*&---------------------------------------------------------------------*
*& Form call_alv_function
*&---------------------------------------------------------------------*
* 调用ALV函数
*----------------------------------------------------------------------*
FORM call_alv_function .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
i_callback_pf_status_set = 'SET_STATUS'
i_structure_name = 'STR_TAB'
i_callback_user_command = 'USER_COMMAND'
is_layout = w_layout
it_fieldcat = w_fieldcat1[]
it_events = w_events[]
TABLES
t_outtab = tbl_tab2.
ENDFORM. " call_alv_function
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* 设定ALV外观
*----------------------------------------------------------------------*
FORM build_layout .
w_layout-colwidth_optimize = 'X'.
w_layout-zebra = 'X'.
w_layout-cell_merge = 'X'.
ENDFORM. " BUILD_LAYOUT
*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* 设定页头
*---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = w_header.
ENDFORM. "top_of_page
*&--------------------------------------------------------------------*
*& Form SET_STATUS
*&--------------------------------------------------------------------*
* 设定工具栏
*---------------------------------------------------------------------*
* -->W_EXTAB
*---------------------------------------------------------------------*
FORM set_status USING w_extab TYPE slis_t_extab.
SET PF-STATUS 'RMM006'.
ENDFORM. "set_status
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
* 双击响应
*---------------------------------------------------------------------*
* --> UCOMM
* --> SELFIELD
*----------------------------------------------------------------------*
FORM user_command USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.
READ TABLE tbl_tab2 INTO str_tab2 INDEX selfield-tabindex.
CHECK sy-subrc = 0.
CASE ucomm.
WHEN '&IC1'.
* CASE SELFIELD-SEL_TAB_FIELD.
* WHEN 'TBL_TAB2-EBELN'.
SET PARAMETER ID 'BES' FIELD str_tab2-ebeln.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
* ENDCASE.
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form GET_INVOICE_DATA
*&---------------------------------------------------------------------*
* 根据查询的结果,计算开票信息
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
form GET_INVOICE_DATA .
data : ES_LFA1 type lfa1 .
**获取采购申请日期
select BADAT BANFN BNFPO
from eban
into corresponding fields of table t_eban
for all entries in tbl_tab1
where banfn = tbl_tab1-BANFN
and BNFPO = tbl_tab1-BNFPO .
select ebeln ebelp menge shkzg
from ekbe
into corresponding fields of t_ekbe
for all entries in tbl_tab1
where ebeln = tbl_tab1-ebeln
and ebelp = tbl_tab1-ebelp
and vgabe = '2' ."发票
if t_ekbe-shkzg = 'H' .
t_ekbe-menge = -1 * t_ekbe-menge .
else .
endif .
t_ekbe-shkzg = '' .
collect t_ekbe .
endselect .
loop at tbl_tab1 .
read table t_ekbe with key ebeln = tbl_tab1-ebeln
ebelp = tbl_tab1-ebelp .
if sy-subrc eq 0 .
tbl_tab1-menge_i = t_ekbe-menge .
tbl_tab1-menge_n = tbl_tab1-menge - tbl_tab1-menge_i .
endif .
read table t_eban with key banfn = tbl_tab1-BANFN
BNFPO = tbl_tab1-BNFPO .
if sy-subrc eq 0 .
tbl_tab1-BADAT = t_eban-BADAT .
endif .
call function 'LFA1_READ_SINGLE'
exporting
ID_LIFNR = tbl_tab1-lifnr
importing
ES_LFA1 = ES_LFA1
exceptions
NOT_FOUND = 1
INPUT_NOT_SPECIFIED = 2 .
if sy-subrc eq 0 .
tbl_tab1-name1 = es_lfa1-name1 .
endif .
modify tbl_tab1 .
endloop .
endform. " GET_INVOICE_DATA
***********************************************************************
*author: xiao p hai.
*date : 2010/03/29
************************************************************************
REPORT z_cost_analysis_01 MESSAGE- ID zreportmsg.
*ALV类型定义
TYPE-POOLS: slis.
************************************************************************
* DATA *
************************************************************************
DATA: rec_ekpo LIKE ekpo, "采购文件项目
rec_ekko LIKE ekko, "采购文件头
rec_eket LIKE eket, "调度协议计划线
rec_qals LIKE qals. "抽检记录表
*存储查询数据库记录的结构体
DATA: BEGIN OF str_tab1,
ebeln LIKE ekko-ebeln, "采购订单号
ebelp LIKE ekpo-ebelp, "项目
banfn LIKE ekpo-banfn, "采购申请号
BNFPO like ekpo-BNFPO, "采购申请项目号
lifnr LIKE ekko-lifnr, "供应商
werks LIKE ekpo-werks, "工厂代码
ekorg LIKE ekko-ekorg, "采购组织
ekgrp LIKE ekko-ekgrp, "采购组
matkl LIKE ekpo-matkl, "物料组
bsart LIKE ekko-bsart, "凭证类型
loekz LIKE ekpo-loekz, "删除标识
knttp LIKE ekpo-knttp, "A
pstyp LIKE ekpo-pstyp, "I
matnr LIKE ekpo-matnr, "物料编码
txz01 LIKE ekpo-txz01, "物料描述
peinh LIKE ekpo-peinh, "价格单位
meins LIKE ekpo-meins, "单位
netpr LIKE ekpo-netpr, "价格
waers LIKE ekko-waers, "货币
menge LIKE ekpo-menge, "采购数量
wemng LIKE eket-wemng, "已交货数量
lgort LIKE ekpo-lgort, "交货地点
eindt LIKE eket-eindt, "交货日期
ernam LIKE ekko-ernam, "采购订单创建人
bedat LIKE ekko-bedat, "采购订单日期
elikz LIKE ekpo-elikz, "已完成交货标识
losmenge LIKE qals-losmenge, "检验批数量
lmenge01 LIKE qals-lmenge01, "合格数量
lmenge07 LIKE qals-lmenge07, "退货数量
obmng LIKE eket-wemng, "未交货数量
zmenge LIKE qals-losmenge, "质检库存数量
menge_I like ekbe-menge , "开票数量
menge_n like ekbe-menge , "未开票数量
BADAT type BADAT , "采购申请日期
NAME1 type NAME1_GP , "供应商描述
END OF str_tab1.
*存储查询数据库记录的内表
DATA tbl_tab1 LIKE TABLE OF str_tab1 with header line .
*存储ALV输出记录的结构体
DATA str_tab2 LIKE str_tab1.
*存储ALV输出记录的内表
DATA tbl_tab2 LIKE TABLE OF str_tab2.
**采购订单物料历史
data : begin of t_ekbe occurs 0 ,
ebeln type ebeln ,
ebelp type ebelp ,
menge like ekbe-menge ,
shkzg type shkzg ,
end of t_ekbe .
data : begin of t_eban occurs 0 ,
BANFN type BANFN ,
BNFPO TYPE BNFPO ,
BADAT TYPE BADAT ,
END OF T_EBAN .
DATA w_obmng LIKE eket-wemng. "临时变量(未交货数量)
DATA cnt_obmng LIKE eket-wemng. "合计变量(未交货数量)
DATA cnt_menge LIKE ekpo-menge. "合计变量(采购数量)
DATA cnt_wemng LIKE eket-wemng. "合计变量(已交货数量)
DATA w_zmenge LIKE qals-losmenge. "临时变量(质检库存量)
DATA cnt_zmenge LIKE qals-losmenge. "合计变量(质检库存量)
DATA flg_ebelp. "*
DATA: w_repid LIKE sy-repid, "程序名称变量
w_layout TYPE slis_layout_alv, "程序外观变量
w_fieldcat1 TYPE slis_t_fieldcat_alv,
w_fieldcat2 TYPE slis_t_fieldcat_alv,
w_fieldcat3 LIKE LINE OF w_fieldcat1,
w_events TYPE slis_t_event,
w_header TYPE slis_t_listheader, "ALV标题变量
w_event TYPE slis_alv_event.
************************************************************************
* PARAMETERS *
************************************************************************
PARAMETERS rb_sel1 RADIOBUTTON GROUP rad1 "按物料查询按钮
USER-COMMAND radio
DEFAULT 'X'.
SELECTION- SCREEN BEGIN OF BLOCK block1 WITH FRAME.
SELECT-OPTIONS: s_matnr1 FOR rec_ekpo-matnr, "屏幕参数(物料编码)
* MATCHCODE OBJECT mat1,
s_matkl1 FOR rec_ekpo-matkl, "屏幕参数(物料组)
s_bsart1 FOR rec_ekko-bsart, "屏幕参数(凭证类型)
s_werks1 FOR rec_ekpo-werks, "屏幕参数(工厂代码)
s_bedat1 FOR rec_ekko-bedat, "屏幕参数(采购订单日期)
s_aedat1 FOR rec_ekpo-aedat. "屏幕参数(交货日期)
PARAMETERS cb_chk1 AS CHECKBOX. "未清PO查询复选框
SELECTION- SCREEN END OF BLOCK block1.
PARAMETERS rb_sel2 RADIOBUTTON GROUP rad1. "按供应商查询按钮
SELECTION- SCREEN BEGIN OF BLOCK block2 WITH FRAME.
SELECT-OPTIONS: s_lifnr2 FOR rec_ekko-lifnr, "屏幕参数(供应商)
s_werks2 FOR rec_ekpo-werks, "屏幕参数(工厂代码)
s_ekgrp2 FOR rec_ekko-ekgrp, "屏幕参数(采购组)
s_bsart2 FOR rec_ekko-bsart, "屏幕参数(凭证类型)
s_bedat2 FOR rec_ekko-bedat. "屏幕参数(采购订单日期)
PARAMETERS cb_chk2 AS CHECKBOX. "未清PO查询复选框
SELECTION- SCREEN END OF BLOCK block2.
PARAMETERS rb_sel3 RADIOBUTTON GROUP rad1. "按采购订单查询按钮
SELECTION- SCREEN BEGIN OF BLOCK block3 WITH FRAME.
SELECT-OPTIONS: s_ebeln3 FOR rec_ekko-ebeln, "屏幕参数(采购订单号)
s_werks3 FOR rec_ekpo-werks, "屏幕参数(工厂代码)
s_bsart3 FOR rec_ekko-bsart, "屏幕参数(凭证类型)
s_bedat3 FOR rec_ekko-bedat. "屏幕参数(采购订单日期)
PARAMETERS cb_chk3 AS CHECKBOX. "未清PO查询复选框
SELECTION- SCREEN END OF BLOCK block3.
************************************************************************
* INITIALIZATION *
************************************************************************
INITIALIZATION.
************************************************************************
* AT SELECTION-SCREEN *
************************************************************************
AT SELECTION- SCREEN OUTPUT.
PERFORM set_screen_input. "设定屏幕输入状态
************************************************************************
* START-OF-SELECTION *
************************************************************************
START- OF-SELECTION.
PERFORM chose_select_options. "选择查询方式
PERFORM prepare_alv_data. "准备ALV输出数据
PERFORM alv_control_output. "ALV相关控制
PERFORM call_alv_function. "调用ALV函数
*&---------------------------------------------------------------------*
*& Form set_screen_input
*&---------------------------------------------------------------------*
* 设定屏幕输入状态
*----------------------------------------------------------------------*
FORM set_screen_input .
LOOP AT SCREEN.
* 循环屏幕BLOCK1中元素
IF screen-name = 'S_MATNR1-LOW'
OR screen-name = 'S_MATNR1-HIGH'
OR screen-name = 'S_MATKL1-LOW'
OR screen-name = 'S_MATKL1-HIGH'
OR screen-name = 'S_BSART1-LOW'
OR screen-name = 'S_BSART1-HIGH'
OR screen-name = 'S_WERKS1-LOW'
OR screen-name = 'S_WERKS1-HIGH'
OR screen-name = 'S_BEDAT1-LOW'
OR screen-name = 'S_BEDAT1-HIGH'
OR screen-name = 'S_AEDAT1-LOW'
OR screen-name = 'S_AEDAT1-HIGH'
OR screen-name = 'CB_CHK1'.
* 判断查询方式
CASE 'X'.
WHEN rb_sel1. "按物料查询
screen- input = 1. "可输入
WHEN rb_sel2. "按供应商查询
screen- input = 0. "不可输入
WHEN rb_sel3. "按采购订单查询
screen- input = 0. "不可输入
ENDCASE.
MODIFY SCREEN.
ENDIF.
* 循环屏幕BLOCK2中元素
IF screen-name = 'S_LIFNR2-LOW'
OR screen-name = 'S_LIFNR2-HIGH'
OR screen-name = 'S_WERKS2-LOW'
OR screen-name = 'S_WERKS2-HIGH'
OR screen-name = 'S_EKGRP2-LOW'
OR screen-name = 'S_EKGRP2-HIGH'
OR screen-name = 'S_BSART2-LOW'
OR screen-name = 'S_BSART2-HIGH'
OR screen-name = 'S_BEDAT2-LOW'
OR screen-name = 'S_BEDAT2-HIGH'
OR screen-name = 'CB_CHK2'.
* 判断查询方式
CASE 'X'.
WHEN rb_sel1. "按物料查询
screen- input = 0. "不可输入
WHEN rb_sel2. "按供应商查询
screen- input = 1. "可输入
WHEN rb_sel3. "按采购订单查询
screen- input = 0. "不可输入
ENDCASE.
MODIFY SCREEN.
ENDIF.
* 循环屏幕BLOCK3中元素
IF screen-name = 'S_EBELN3-LOW'
OR screen-name = 'S_EBELN3-HIGH'
OR screen-name = 'S_WERKS3-LOW'
OR screen-name = 'S_WERKS3-HIGH'
OR screen-name = 'S_BSART3-LOW'
OR screen-name = 'S_BSART3-HIGH'
OR screen-name = 'S_BEDAT3-LOW'
OR screen-name = 'S_BEDAT3-HIGH'
OR screen-name = 'CB_CHK3'.
* 判断查询方式
CASE 'X'.
WHEN rb_sel1. "按物料查询
screen- input = 0. "不可输入
WHEN rb_sel2. "按供应商查询
screen- input = 0. "不可输入
WHEN rb_sel3. "按采购订单查询
screen- input = 1. "可输入
ENDCASE.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDFORM. " set_screen_input
*&---------------------------------------------------------------------*
*& Form chose_select_options
*&---------------------------------------------------------------------*
* 选择查询方式
*----------------------------------------------------------------------*
FORM chose_select_options .
CASE 'X'. "判断查询方式
WHEN rb_sel1. "按物料查询
PERFORM get_data_ekpo1. "按物料查查询数据
WHEN rb_sel2. "按供应商查询
PERFORM get_data_ekpo2. "按供应商查询数据
WHEN rb_sel3. "按采购订单查询
PERFORM get_data_ekpo3. "按采购订单查询数据
ENDCASE.
DELETE tbl_tab1 WHERE loekz = 'L'.
perform get_invoice_data .
SORT tbl_tab1 BY ebeln ebelp. "按采购订单号、项目
"排序
ENDFORM. " select_options
*&---------------------------------------------------------------------*
*& Form get_data_ekpo1
*&---------------------------------------------------------------------*
* 按物料查查询数据
*----------------------------------------------------------------------*
FORM get_data_ekpo1 .
SELECT ekko~ebeln "采购订单号
ekpo~ebelp "项目
ekpo~banfn "采购申请号
ekpo~BNFPO "采购申请项次
ekko~lifnr "供应商
ekpo~werks "工厂代码
ekko~ekorg "采购组织
ekko~ekgrp "采购组
ekpo~matkl "物料组
ekko~bsart "凭证类型
ekpo~loekz "删除标识
ekpo~knttp "A
ekpo~pstyp "I
ekpo~matnr "物料编码
ekpo~txz01 "物料描述
ekpo~peinh "价格单位
ekpo~meins "单位
ekpo~netpr "价格
ekko~waers "货币
ekpo~menge "采购数量
eket~wemng "已交货数量
ekpo~lgort "交货地点
eket~eindt "交货日期
ekko~ernam "采购订单创建人
ekko~bedat "采购订单日期
ekpo~elikz "已完成交货标识
* qals~losmenge "检验批数量
* qals~lmenge01 "合格数量
* qals~lmenge07 "退货数量
FROM ( ( ekpo
JOIN ekko ON ekko~ebeln = ekpo~ebeln "采购订单号
JOIN eket ON eket~ebeln = ekpo~ebeln "采购订单号
AND eket~ebelp = ekpo~ebelp ) ) "项目
* LEFT JOIN qals ON qals~ebeln = ekpo~ebeln "采购订单号
* AND qals~ebelp = ekpo~ebelp ) "项目
INTO TABLE tbl_tab1
WHERE ekpo~matnr IN s_matnr1 "物料编码
AND ekpo~matkl IN s_matkl1 "物料组
AND ekko~bsart IN s_bsart1 "凭证类型
AND ekpo~werks IN s_werks1 "工厂代码
AND ekko~bedat IN s_bedat1 "采购订单日期
AND ekpo~aedat IN s_aedat1. "交货日期
IF sy-subrc <> 0. "查询失败
MESSAGE s000.
ENDIF.
IF cb_chk1 = 'X'. "选择未清PO查询
DELETE tbl_tab1 WHERE elikz = 'X'. "删除已完成订单
ENDIF.
ENDFORM. " get_data_1
*&---------------------------------------------------------------------*
*& Form get_data_ekpo2
*&---------------------------------------------------------------------*
* 按供应商查询数据
*----------------------------------------------------------------------*
FORM get_data_ekpo2 .
select ekko~ebeln "采购订单号
ekpo~ebelp "项目
ekpo~banfn "采购申请号
ekpo~bnfpo "采购申请项次
ekko~lifnr "供应商
ekpo~werks "工厂代码
ekko~ekorg "采购组织
ekko~ekgrp "采购组
ekpo~matkl "物料组
ekko~bsart "凭证类型
ekpo~loekz "删除标识
ekpo~knttp "A
ekpo~pstyp "I
ekpo~matnr "物料编码
ekpo~txz01 "物料描述
ekpo~peinh "价格单位
ekpo~meins "单位
ekpo~netpr "价格
ekko~waers "货币
ekpo~menge "采购数量
eket~wemng "已交货数量
ekpo~lgort "交货地点
eket~eindt "交货日期
ekko~ernam "采购订单创建人
ekko~bedat "采购订单日期
ekpo~elikz "已完成交货标识
* qals~losmenge "检验批数量
* qals~lmenge01 "合格数量
* qals~lmenge07 "退货数量
FROM ( ( ekpo
JOIN ekko ON ekko~ebeln = ekpo~ebeln "采购订单号
JOIN eket ON eket~ebeln = ekpo~ebeln "采购订单号
AND eket~ebelp = ekpo~ebelp ) ) "项目
* LEFT JOIN qals ON qals~ebeln = ekpo~ebeln "采购订单号
* AND qals~ebelp = ekpo~ebelp ) "项目
INTO TABLE tbl_tab1
WHERE ekko~lifnr IN s_lifnr2 "供应商
AND ekpo~werks IN s_werks2 "工厂代码
AND ekko~ekgrp IN s_ekgrp2 "采购组
AND ekko~bsart IN s_bsart2 "凭证类型
AND ekko~bedat IN s_bedat2. "采购订单日期
IF sy-subrc <> 0. "查询失败
MESSAGE s000.
ENDIF.
IF cb_chk2 = 'X'. "选择未清PO查询
DELETE tbl_tab1 WHERE elikz = 'X'. "删除已完成订单
ENDIF.
ENDFORM. " get_data_2
*&---------------------------------------------------------------------*
*& Form get_data_ekpo3
*&---------------------------------------------------------------------*
* 按采购订单查询数据
*----------------------------------------------------------------------*
FORM get_data_ekpo3 .
select ekko~ebeln "采购订单号
ekpo~ebelp "项目
ekpo~banfn "采购申请号
ekpo~bnfpo "采购申请项次
ekko~lifnr "供应商
ekpo~werks "工厂代码
ekko~ekorg "采购组织
ekko~ekgrp "采购组
ekpo~matkl "物料组
ekko~bsart "凭证类型
ekpo~loekz "删除标识
ekpo~knttp "A
ekpo~pstyp "I
ekpo~matnr "物料编码
ekpo~txz01 "物料描述
ekpo~peinh "价格单位
ekpo~meins "单位
ekpo~netpr "价格
ekko~waers "货币
ekpo~menge "采购数量
eket~wemng "已交货数量
ekpo~lgort "交货地点
eket~eindt "交货日期
ekko~ernam "采购订单创建人
ekko~bedat "采购订单日期
ekpo~elikz "已完成交货标识
* qals~losmenge "检验批数量
* qals~lmenge01 "合格数量
* qals~lmenge07 "退货数量
FROM ( ( ekpo
JOIN ekko ON ekko~ebeln = ekpo~ebeln "采购订单号
JOIN eket ON eket~ebeln = ekpo~ebeln "采购订单号
AND eket~ebelp = ekpo~ebelp ) ) "项目
* LEFT JOIN qals ON qals~ebeln = ekpo~ebeln "采购订单号
* AND qals~ebelp = ekpo~ebelp ) "项目
INTO TABLE tbl_tab1
WHERE ekko~ebeln IN s_ebeln3 "采购订单号
AND ekpo~werks IN s_werks3 "工厂代码
AND ekko~bsart IN s_bsart3 "凭证类型
AND ekko~bedat IN s_bedat3. "采购订单日期
IF sy-subrc <> 0. "查询失败
MESSAGE s000.
ENDIF.
IF cb_chk3 = 'X'. "选择未清PO查询
DELETE tbl_tab1 WHERE elikz = 'X'. "删除已完成订单
ENDIF.
ENDFORM. " get_data_3
*&---------------------------------------------------------------------*
*& Form prepare_alv_data
*&---------------------------------------------------------------------*
* 准备ALV输出数据
*----------------------------------------------------------------------*
FORM prepare_alv_data .
* 删除有删除标记的纪录
LOOP AT tbl_tab1 INTO str_tab1 .
AT END OF ebelp.
MOVE 'X' TO flg_ebelp.
ENDAT.
IF flg_ebelp = 'X'.
w_obmng = str_tab1-menge - str_tab1-wemng. "计算临时变量(未交货数量)
cnt_obmng = cnt_obmng + w_obmng. "计算合计变量(未交货数量)
cnt_menge = cnt_menge + str_tab1-menge. "计算合计变量(采购数量)
cnt_wemng = cnt_wemng + str_tab1-wemng. "计算合计变量(已交货数量)
CLEAR flg_ebelp.
ENDIF.
w_zmenge = str_tab1-losmenge "计算临时变量(质检库存量)
- str_tab1-lmenge01
- str_tab1-lmenge07.
cnt_zmenge = cnt_zmenge + w_zmenge. "计算合计变量(质检库存量)
MOVE str_tab1 TO str_tab2. "结构体赋值
AT END OF ebeln. "按相同采购订单号合计
str_tab2-obmng = cnt_obmng. "合计变量赋值
str_tab2-menge = cnt_menge. "合计变量赋值
str_tab2-wemng = cnt_wemng. "合计变量赋值
str_tab2-zmenge = cnt_zmenge. "合计变量赋值
APPEND str_tab2 TO tbl_tab2. "追加至内表
CLEAR w_obmng.
CLEAR w_zmenge.
CLEAR cnt_zmenge.
CLEAR cnt_obmng.
CLEAR cnt_menge.
CLEAR cnt_wemng.
ENDAT.
CLEAR str_tab1.
ENDLOOP.
IF tbl_tab2 IS INITIAL. "处理后无数据
MESSAGE s000.
ENDIF.
ENDFORM. " prepare_alv_data
*&---------------------------------------------------------------------*
*& Form alv_control_output
*&---------------------------------------------------------------------*
* ALV相关控制
*----------------------------------------------------------------------*
FORM alv_control_output .
w_repid = sy-repid. "程序名称
PERFORM build_alv_catalog. "设定ALV显示顺序及标签
w_event-name = 'TOP_OF_PAGE'.
w_event- form = 'TOP_OF_PAGE'.
APPEND w_event TO w_events.
PERFORM prepare_standard_header. "设定ALV标准标题
ENDFORM. " alv_control_output
*&---------------------------------------------------------------------*
*& Form build_alv_catalog
*&---------------------------------------------------------------------*
* 设定ALV显示顺序及标签
*----------------------------------------------------------------------*
FORM build_alv_catalog .
* 输出采购申请号
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BANFN'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3- key = 'X'.
w_fieldcat3-seltext_l = '采购申请号'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购申请日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BADAT'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '采购申请日期'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购申请日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BNFPO'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '项次'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购订单号
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'EBELN'.
w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '采购订单号'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购订单日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'BEDAT'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '采购订单日期'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出交货日期
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'EINDT'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '交货日期'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出供应商 改为供应商名称
* CLEAR w_fieldcat3.
* w_fieldcat3-fieldname = 'LIFNR'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
** w_fieldcat3-key = 'X'.
* w_fieldcat3-seltext_l = '供应商'.
* w_fieldcat3-outputlen = 10.
* APPEND w_fieldcat3 TO w_fieldcat1.
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'NAME1'.
* w_fieldcat3-tabname = 'TBL_TAB2'.
* w_fieldcat3-key = 'X'.
w_fieldcat3-seltext_l = '供应商名称'.
w_fieldcat3-outputlen = 10.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出物料编码
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MATNR'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '物料编码'.
w_fieldcat3-outputlen = 18.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出物料描述
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'TXZ01'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '物料描述'.
w_fieldcat3-outputlen = 40.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购组
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'EKGRP'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '采购组'.
w_fieldcat3-outputlen = 3.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出单位
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MEINS'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '单位'.
w_fieldcat3-outputlen = 3.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出采购数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MENGE'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '采购数量'.
w_fieldcat3-outputlen = 13.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出已交货数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'WEMNG'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '已交货数量'.
w_fieldcat3-outputlen = 13.
APPEND w_fieldcat3 TO w_fieldcat1.
* 输出未交货数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'OBMNG'.
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '未交货数量'.
w_fieldcat3-outputlen = 13.
APPEND w_fieldcat3 TO w_fieldcat1.
* 已开票数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MENGE_I' .
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '已开票数量'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
* 未开票数量
CLEAR w_fieldcat3.
w_fieldcat3-fieldname = 'MENGE_N' .
w_fieldcat3-tabname = 'TBL_TAB2'.
w_fieldcat3-seltext_l = '未开票数量'.
w_fieldcat3-outputlen = 8.
APPEND w_fieldcat3 TO w_fieldcat1.
ENDFORM. " build_alv_catalog
*&---------------------------------------------------------------------*
*& Form prepare_standard_header
*&---------------------------------------------------------------------*
* 设定ALV标准标题
*----------------------------------------------------------------------*
FORM prepare_standard_header .
DATA line TYPE slis_listheader.
line-typ = 'H'.
line-info = 'PO未交货明细查询报表'.
APPEND line TO w_header.
ENDFORM. " prepare_standard_header
*&---------------------------------------------------------------------*
*& Form call_alv_function
*&---------------------------------------------------------------------*
* 调用ALV函数
*----------------------------------------------------------------------*
FORM call_alv_function .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
i_callback_pf_status_set = 'SET_STATUS'
i_structure_name = 'STR_TAB'
i_callback_user_command = 'USER_COMMAND'
is_layout = w_layout
it_fieldcat = w_fieldcat1[]
it_events = w_events[]
TABLES
t_outtab = tbl_tab2.
ENDFORM. " call_alv_function
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* 设定ALV外观
*----------------------------------------------------------------------*
FORM build_layout .
w_layout-colwidth_optimize = 'X'.
w_layout-zebra = 'X'.
w_layout-cell_merge = 'X'.
ENDFORM. " BUILD_LAYOUT
*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* 设定页头
*---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = w_header.
ENDFORM. "top_of_page
*&--------------------------------------------------------------------*
*& Form SET_STATUS
*&--------------------------------------------------------------------*
* 设定工具栏
*---------------------------------------------------------------------*
* -->W_EXTAB
*---------------------------------------------------------------------*
FORM set_status USING w_extab TYPE slis_t_extab.
SET PF-STATUS 'RMM006'.
ENDFORM. "set_status
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
* 双击响应
*---------------------------------------------------------------------*
* --> UCOMM
* --> SELFIELD
*----------------------------------------------------------------------*
FORM user_command USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.
READ TABLE tbl_tab2 INTO str_tab2 INDEX selfield-tabindex.
CHECK sy-subrc = 0.
CASE ucomm.
WHEN '&IC1'.
* CASE SELFIELD-SEL_TAB_FIELD.
* WHEN 'TBL_TAB2-EBELN'.
SET PARAMETER ID 'BES' FIELD str_tab2-ebeln.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
* ENDCASE.
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form GET_INVOICE_DATA
*&---------------------------------------------------------------------*
* 根据查询的结果,计算开票信息
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
form GET_INVOICE_DATA .
data : ES_LFA1 type lfa1 .
**获取采购申请日期
select BADAT BANFN BNFPO
from eban
into corresponding fields of table t_eban
for all entries in tbl_tab1
where banfn = tbl_tab1-BANFN
and BNFPO = tbl_tab1-BNFPO .
select ebeln ebelp menge shkzg
from ekbe
into corresponding fields of t_ekbe
for all entries in tbl_tab1
where ebeln = tbl_tab1-ebeln
and ebelp = tbl_tab1-ebelp
and vgabe = '2' ."发票
if t_ekbe-shkzg = 'H' .
t_ekbe-menge = -1 * t_ekbe-menge .
else .
endif .
t_ekbe-shkzg = '' .
collect t_ekbe .
endselect .
loop at tbl_tab1 .
read table t_ekbe with key ebeln = tbl_tab1-ebeln
ebelp = tbl_tab1-ebelp .
if sy-subrc eq 0 .
tbl_tab1-menge_i = t_ekbe-menge .
tbl_tab1-menge_n = tbl_tab1-menge - tbl_tab1-menge_i .
endif .
read table t_eban with key banfn = tbl_tab1-BANFN
BNFPO = tbl_tab1-BNFPO .
if sy-subrc eq 0 .
tbl_tab1-BADAT = t_eban-BADAT .
endif .
call function 'LFA1_READ_SINGLE'
exporting
ID_LIFNR = tbl_tab1-lifnr
importing
ES_LFA1 = ES_LFA1
exceptions
NOT_FOUND = 1
INPUT_NOT_SPECIFIED = 2 .
if sy-subrc eq 0 .
tbl_tab1-name1 = es_lfa1-name1 .
endif .
modify tbl_tab1 .
endloop .
endform. " GET_INVOICE_DATA
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13973563/viewspace-691277/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/13973563/viewspace-691277/