SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF }
.L0S31 { font-style: italic; color: #808080 }
.L0S32 { color: #3399FF }
.L0S33 { color: #4DA619 }
.L0S52 { color: #0000FF }
.L0S55 { color: #800080 }
.L0S70 { color: #808080 }
*&---------------------------------------------------------------------*
*& Report ZMMR023
*&
*&---------------------------------------------------------------------*
*&by xiaochangye 20161010
*&xiugai by dev02 20161226
*&---------------------------------------------------------------------*
report ztestxiao001.
tables:vbkd,vbak,vbrp,vbrk,ekpo,vbap,lips.
*定义ALV变量
type-pools: slis.
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv,
gt_sort type slis_t_sortinfo_alv,
gs_sort type slis_sortinfo_alv,
g_title type lvc_title.
data:begin of gt_out occurs 0,
ernam like ekko-ernam,"负责人
bstkd_e like vbkd-bstkd_e,"采购订单号
menge like ekpo-menge,"订单数量
bpmng like ekbe-bpmng,"收货数量
werks like ekpo-werks,"工厂
matnr like ekpo-matnr,"物料号
txz01 like ekpo-txz01,"物料描述
vbelnxs like vbkd-vbeln,"销售订单号
posnrxs like vbkd-posnr,"销售订单行项目号
kwmeng like vbep-wmeng,"销售订单数量
lfimg like lips-lfimg,"交货数量
vkorg like vbak-vkorg,"销售组织
matwa like vbap-matwa,"物料号
arktx like vbap-arktx,"物料描述
vbelnjh like vbkd-vbeln,"交互单号
posnrjh like vbkd-posnr,"交货单行项目号
vbelnfp like vbkd-vbeln,"发票号
posnrfp like vbkd-posnr,"发票行项目号
fkdat like vbrk-fkdat,"发票创建日期
end of gt_out.
data:begin of gt_huizong occurs 0,
ernam like ekko-ernam,"负责人
bstkd_e like vbkd-bstkd_e,"采购订单号
werks like ekpo-werks,"工厂
matnr like ekpo-matnr,"物料号
txz01 like ekpo-txz01,"物料描述
vbelnxs like vbkd-vbeln,"销售订单号
posnrxs like vbkd-posnr,"销售订单行项目号
lfimg like lips-lfimg,"交货数量
end of gt_huizong.
data:begin of gt_vbkd occurs 0,
bstkd_e like vbkd-bstkd_e,"采购订单号
ebeln like vbkd-vbeln,"采购订单号
vbelnxs like vbkd-vbeln,"销售订单号
posnrxs like vbkd-posnr,"销售订单行项目号
vbeln like vbkd-vbeln,"销售订单号
posnr like vbkd-posnr,"销售订单行项目号
vbelnjh like vbkd-vbeln,"交互单号
posnrjh like vbkd-posnr,"交货单行项目号
ERNAM like ekko-ERNAM,
end of gt_vbkd.
data:begin of gt_ekpo occurs 0,
ebeln like vbkd-vbeln,"采购订单号
werks like ekpo-werks,"采购工厂
matnr like ekpo-matnr,"采购物料号
txz01 like ekpo-txz01,"采购物料描述
MENGE LIKE EKPO-MENGE,"订单数量
end of gt_ekpo.
data gt_ekpo1 like gt_ekpo occurs 0 with header line.
data:begin of gt_ekbe occurs 0,
ebeln like vbkd-vbeln,"采购订单号
MENGE like ekbe-MENGE,"收货数量
BWART like ekbe-BWART,"移动类型
end of gt_ekbe.
data gt_ekbe1 like gt_ekbe occurs 0 with header line.
data:begin of gt_vbrk occurs 0,
vbelnxs like vbak-vbeln,"销售订单号
vkorg like vbak-vkorg,"销售组织
matwa like vbap-matwa,"销售物料号
arktx like vbap-arktx,"销售物料描述
end of gt_vbrk.
data:begin of gt_vbap occurs 0,
vbeln like vbap-vbeln,"销售订单号
KWMENG like vbap-KWMENG,"
end of gt_vbap.
data gt_vbap1 like gt_vbap occurs 0 with header line.
data:begin of gt_vbak occurs 0,
bstkd_e like vbkd-bstkd_e,"交货单号
posex_e like vbkd-posex_e,"交货单行项目号
vbelnjh like vbkd-vbeln,"交互单号
vbeln like vbkd-vbeln,"销售订单号
posnr like vbkd-posnr,"销售订单行项目号
end of gt_vbak.
data:begin of gt_lips occurs 0,
vbeln like lips-vbeln,"交货单号
vgbel like lips-vgbel,
vgpos like lips-vgpos,
LFIMG like lips-LFIMG,"
end of gt_lips.
data gt_lips1 like gt_lips occurs 0 with header line.
data:begin of gt_fp occurs 0,
aubel like vbrp-aubel,"销售订单号
aupos like vbrp-aupos,"销售订单行项目号
vbeln like vbrp-vbeln,"发票号
posnr like vbrp-posnr,"发票行项目号
end of gt_fp.
data:begin of gt_fpdata occurs 0,
vbeln like vbrp-vbeln,"发票号
fkdat like vbrk-fkdat,"发票日期
end of gt_fpdata.
"定义选择屏幕(输入条件)
selection-screen begin of block block1 with frame title text-001.
select-options: s_bstkd for vbkd-bstkd_e. "采购订单号
select-options: s_aubel for vbrp-aubel. "销售订单号
selection-screen end of block block1.
start-of-selection.
"取数
perform get_data.
"处理数据
perform deal_data.
"alv显示
perform alv_dis.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
select
a~bstkd_e
a~vbeln as vbelnxs
a~posnr as posnrxs
b~vbeln as vbelnjh
b~posnr as posnrjh
c~ERNAM
into corresponding fields of table gt_vbkd
from vbkd as a
inner join lips as b on b~vgbel = a~vbeln and b~vgpos = a~posnr
inner join ekko as c on c~EBELN = a~bstkd_e
where a~bstkd_e in s_bstkd
and a~vbeln in s_aubel.
if gt_vbkd[] is not initial. "判断查出的数据是否为空,如果为空不再执行以下的程序(initial=空)
select "从表VBKD查出销售订单类型为ZWK1,售达方为公司间的全部数据放到临时表GT_VBAK里
a~vbeln as vbeln
a~posnr
a~bstkd_e
a~posex_e
into corresponding fields of table gt_vbak
from vbkd as a
inner join vbak as b on a~vbeln = b~vbeln
where b~auart = 'ZKE1'
and ( b~kunnr = '0000002300' or b~kunnr = '0000002100'
or b~kunnr = '0000002200' or b~kunnr = '0000003100'
or b~kunnr = '0000001000' )
and a~posex_e <> ''.
loop at gt_vbak. "更改自字符串长度格式
gt_vbak-vbelnjh = gt_vbak-bstkd_e+0(10).
modify gt_vbak.
clear gt_vbak.
endloop.
loop at gt_vbkd. "更改自字符串长度格式
gt_vbkd-ebeln = gt_vbkd-bstkd_e+0(10).
modify gt_vbkd.
clear gt_vbkd.
endloop.
"删除gt_vbkd中交货单号及航项目在gt_vbak中找不到的行
* loop at gt_vbkd.
* read table gt_vbak with key vbelnjh = gt_vbkd-vbelnjh
* posex_e = gt_vbkd-posnrjh.
* if sy-subrc <> 0.
* delete gt_vbkd.
* endif.
* endloop.
*对gt_vbkd中交货单号机航项目在gt_vbak中找到的行,
*修改销售订单号及航项目=gt_vbak中的销售订单号及航项目
loop at gt_vbkd.
read table gt_vbak with key vbelnjh = gt_vbkd-vbelnjh
posex_e = gt_vbkd-posnrjh.
if sy-subrc = 0.
gt_vbkd-vbeln = gt_vbak-vbeln.
gt_vbkd-posnr = gt_vbak-posnr.
endif.
modify gt_vbkd.
clear gt_vbkd.
endloop.
"查出销售订单号,销售订单行项目,发票号,发票行项目,发票日期放到临时表 get_FP里
select
aubel
aupos
vbeln
posnr
into corresponding fields of table gt_fp
from vbrp
for all entries in gt_vbkd
where aubel = gt_vbkd-vbeln and aupos = gt_vbkd-posnr.
"查出发票的下达日期放到GT_FPDATA这个临时表里
select
vbeln
fkdat
into corresponding fields of table gt_fpdata
from vbrk
for all entries in gt_fp
where vbeln = gt_fp-vbeln.
"查出采购订单的工厂、物料号、采购数量、和物料描述放在临时表GT_EKPO里。
select
ebeln
werks
matnr
txz01
MENGE
into corresponding fields of table gt_ekpo
from ekpo
for all entries in gt_vbkd
where ebeln = gt_vbkd-ebeln
and LOEKZ = ''.
* 收货数量
select
ebeln
MENGE
BWART
into corresponding fields of table gt_ekbe
from ekbe
for all entries in gt_vbkd
where ebeln = gt_vbkd-ebeln
and BWART <> ''.
"查出销售订单的销售组织、物料号和物料描述在临时表GT_VBRK
select
a~vbeln as vbelnxs
a~vkorg
b~matwa
b~arktx
into corresponding fields of table gt_vbrk
from vbak as a
inner join vbap as b on b~vbeln = a~vbeln
for all entries in gt_vbkd
where a~vbeln = gt_vbkd-vbelnxs.
* 销售订单数量
select
vbeln
KWMENG
into corresponding fields of table gt_vbap
from vbap
for all entries in gt_vbkd
where vbeln = gt_vbkd-vbelnxs.
* 交货数量
select
vbeln
LFIMG
into corresponding fields of table gt_lips
from lips
for all entries in gt_vbkd
where vbeln = gt_vbkd-vbelnjh and LGORT <> ''.
endif.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DEAL_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form deal_data . "给需要输出的字段赋值
loop at gt_ekbe.
if gt_ekbe-BWART = '102'.
gt_ekbe-MENGE = 0 - gt_ekbe-MENGE.
endif.
gt_ekbe-BWART = ''.
modify gt_ekbe.
clear gt_ekbe.
endloop.
sort gt_ekbe by ebeln.
loop at gt_ekbe.
collect gt_ekbe into gt_ekbe1.
endloop.
sort gt_vbap by VBELN.
loop at gt_vbap.
collect gt_vbap into gt_vbap1.
endloop.
sort gt_lips by VBELN.
loop at gt_lips.
collect gt_lips into gt_lips1.
endloop.
loop at gt_vbkd.
gt_out-ernam = gt_vbkd-ernam .
gt_out-bstkd_e = gt_vbkd-bstkd_e.
gt_out-vbelnxs = gt_vbkd-vbelnxs.
gt_out-posnrxs = gt_vbkd-posnrxs.
gt_out-vbelnjh = gt_vbkd-vbelnjh.
gt_out-posnrjh = gt_vbkd-posnrjh.
read table gt_fp with key aubel = gt_vbkd-vbeln
aupos = gt_vbkd-posnr.
if sy-subrc = 0.
gt_out-vbelnfp = gt_fp-vbeln.
gt_out-posnrfp = gt_fp-posnr.
endif.
read table gt_fpdata with key vbeln = gt_out-vbelnfp.
if sy-subrc = 0.
gt_out-fkdat = gt_fpdata-fkdat.
endif.
read table gt_ekpo with key ebeln = gt_vbkd-ebeln.
if sy-subrc = 0.
gt_out-werks = gt_ekpo-werks."工厂
gt_out-matnr = gt_ekpo-matnr."物料号
gt_out-txz01 = gt_ekpo-txz01."物料描述
gt_out-menge = gt_ekpo-menge."
endif.
read table gt_ekbe1 with key ebeln = gt_vbkd-ebeln.
if sy-subrc = 0.
gt_out-bpmng = gt_ekbe1-MENGE."
endif.
read table gt_vbrk with key vbelnxs = gt_vbkd-vbelnxs.
if sy-subrc = 0.
gt_out-vkorg = gt_vbrk-vkorg."销售组织
gt_out-matwa = gt_vbrk-matwa."物料号
gt_out-arktx = gt_vbrk-arktx."物料描述
endif.
read table gt_vbap1 with key vbeln = gt_vbkd-vbelnxs.
if sy-subrc = 0.
gt_out-kwmeng = gt_vbap1-kwmeng ."销售组织
endif.
read table gt_lips1 with key vbeln = gt_vbkd-vbelnjh.
if sy-subrc = 0.
gt_out-lfimg = gt_lips1-lfimg ."销售组织
endif.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = gt_out-matnr
importing
output = gt_out-matnr.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = gt_out-matwa
importing
output = gt_out-matwa.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = gt_out-vbelnxs
importing
output = gt_out-vbelnxs.
append gt_out.
clear gt_out.
endloop.
loop at gt_out.
MOVE-CORRESPONDING gt_out TO GT_HUIZONG.
collect gt_huizong.
endloop.
loop at gt_out.
read table gt_huizong with key bstkd_e = gt_out-bstkd_e
vbelnxs = gt_out-vbelnxs
posnrxs = gt_out-posnrxs.
if sy-subrc = 0.
gt_out-lfimg = gt_huizong-lfimg ."销售组织
endif.
modify gt_out.
clear gt_out.
endloop.
sort gt_out by BSTKD_E VBELNXS POSNRXS.
DELETE ADJACENT DUPLICATES FROM gt_out COMPARING BSTKD_E VBELNXS POSNRXS.
endform. " DEAL_DATA
*&---------------------------------------------------------------------*
*& Form ALV_DIS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form alv_dis .
*创建字段宏定义和输出字段赋值
perform frm_build_fieldcatalog.
*定义输出模式
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-f2code = '&IC1'. "Sets fcode for when double click(press f2)
"gd_layout-box_fieldname = 'BOX'.
gd_layout-cell_merge = 'X'.
gd_layout-zebra = 'X'.
*使用ALV输出函数
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
**用户操作的参数
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND_4000' "自定义指向代码
*ALV输出状态的参数
i_callback_pf_status_set = 'SET_PF_STATUS_3200' "菜单
*输出模式参数
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
is_print = gd_prntparams
i_grid_title = g_title
i_save = 'X'
"it_sort = gt_sort[]
tables
*用于输出ALV的内表
t_outtab = gt_out
exceptions
*定义输出异常时的信息,配合MESSAGE语句使用
program_error = 1
others = 2.
endform. " ALV_DIS
*&---------------------------------------------------------------------*
*& Form FRM_BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form frm_build_fieldcatalog .
"创建字段宏定义
define add_field.
fieldcatalog-fieldname = &1. "内表字段名称
fieldcatalog-seltext_m = &2. "字段输出名称
fieldcatalog-no_zero = &3. "是否显示零
fieldcatalog-just = &4. "对齐方式
fieldcatalog-emphasize = &5. "是否高亮
fieldcatalog-checkbox = &6. "是否带单选框
fieldcatalog-edit = &7. "可编辑
append fieldcatalog.
clear fieldcatalog.
end-of-definition.
*输出字段赋值
add_field 'ERNAM' '负责人' '' 'L' '' '' ''.
add_field 'BSTKD_E' '采购订单号' '' 'L' '' '' ''.
add_field 'MENGE' '订单数量' '' 'L' '' '' ''.
add_field 'BPMNG' '收货数量' '' 'L' '' '' ''.
add_field 'WERKS' '工厂' '' 'L' '' '' ''.
add_field 'MATNR' '物料号' '' 'L' '' '' ''.
add_field 'TXZ01' '物料描述' '' 'L' '' '' ''.
add_field 'VBELNXS' '销售订单号' '' 'L' '' '' ''.
add_field 'POSNRXS' '销售订单行项目号' '' 'L' '' '' ''.
add_field 'VKORG' '销售组织' '' 'L' '' '' ''.
add_field 'KWMENG' '订单数量' '' 'L' '' '' ''.
add_field 'LFIMG' '交货数量' '' 'L' '' '' ''.
add_field 'MATWA' '物料号' '' 'L' '' '' ''.
add_field 'ARKTX' '物料描述' '' 'L' '' '' ''.
add_field 'VBELNJH' '交货单号' '' 'L' '' '' ''.
add_field 'POSNRJH' '交货单行项目号' '' 'L' '' '' ''.
add_field 'VBELNFP' '发票号' '' 'L' '' '' ''.
add_field 'POSNRFP' '发票行项目号' '' 'L' '' '' ''.
add_field 'FKDAT' '发票下达日期' '' 'L' '' '' ''.
endform. " FRM_BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form set_pf_status_3200
*&---------------------------------------------------------------------*
* GUI定义
*----------------------------------------------------------------------*
* -->EXTAB text
*----------------------------------------------------------------------*
form set_pf_status_3200 using extab type slis_t_extab.
data: r_ucomm like sy-ucomm.
set pf-status 'MYSTATUS'.
endform.