*& Report ZSDR025
*&
*&---------------------------------------------------------------------*
*&程序名称:销售订单转交货单
*&事物代码:
*&导入模板:无
*&作
*&时间:
*&更新时间:
REPORT zsdr025.
TYPE-POOLS: slis.
TABLES : vbak,vbap,vbep,ztsd024,t171t.
SELECTION-SCREEN BEGIN OF BLOCK sc3 WITH FRAME TITLE text-003.
SELECT-OPTIONS : vkorg FOR vbak-vkorg MEMORY ID vko,
werks FOR vbap-werks,
*PARAMETERS : "vkorg LIKE vbak-vkorg OBLIGATORY MEMORY ID vko,
vtweg FOR vbak-vtweg MEMORY ID vtw,
"spart FOR vbak-spart MEMORY ID spa,
"spart2 FOR vbap-spart MEMORY ID spa1,
bzrik FOR t171t-bzirk,
vkbur FOR vbak-vkbur ,
vkgrp FOR vbak-vkgrp
.
SELECTION-SCREEN END OF BLOCK sc3.
SELECTION-SCREEN BEGIN OF BLOCK sc1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : auart FOR vbak-auart.
*kunnr_y LIKE vbpa-kunnr,
SELECT-OPTIONS :
kunnr FOR vbak-kunnr,
*werks FOR vbap-werks,
lgort FOR vbap-lgort,
vstel FOR vbap-vstel,
ernam FOR vbak-ernam,
vbeln FOR vbak-vbeln,
erdat FOR vbak-erdat.
SELECT-OPTIONS :
edatu FOR vbep-edatu,
ezeit FOR vbep-ezeit.
*PARAMETERS : ck_audit AS CHECKBOX. "已审核
SELECTION-SCREEN END OF BLOCK sc1.
SELECTION-SCREEN BEGIN OF BLOCK sc2 WITH FRAME TITLE text-002.
*SKIP 2.
PARAMETERS : ck_audit AS CHECKBOX. "已审核
*SKIP 2.
SELECT-OPTIONS:
p_vl_s FOR ztsd024-vbeln_vl,
p_vbn_s FOR ztsd024-vbeln,
p_erdat FOR ztsd024-erdat,
p_ernam FOR ztsd024-ernam .
SELECTION-SCREEN END OF BLOCK sc2.
DATA : gs_layout TYPE slis_layout_alv.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE. "抬头
DATA: gt_fieldcat_d TYPE slis_t_fieldcat_alv WITH HEADER LINE. "明细
DATA: gt_fieldcat_s TYPE slis_t_fieldcat_alv WITH HEADER LINE. "审核取消
DATA : is_keyinfo TYPE slis_keyinfo_alv.
TYPES: BEGIN OF ty_vbap ,
ck,
auart LIKE vbak-auart,
vbeln LIKE vbak-vbeln,
vstel LIKE vbap-vstel,
spart1 LIKE vbak-spart,
spart2 LIKE vbap-spart,
bezei LIKE v_tvak-bezei,
kunnr LIKE vbak-kunnr,
name4 TYPE ad_name1,
kunnr_s LIKE vbpa-kunnr,
name5 TYPE ad_name1,
kunnr_j LIKE vbpa-kunnr,
name6 TYPE ad_name1,
bzirk LIKE t171t-bzirk,
adrnr LIKE vbpa-adrnr,
vkbur LIKE vbak-vkbur,
vkgrp LIKE vbak-vkgrp, "办事处
name7 TYPE ad_name1,
bzirk_txt LIKE t171t-bztxt,
telf1 LIKE kna1-telf1,
erdat LIKE vbak-erdat,
erzet LIKE vbak-erzet,
* 配送方式
stype(10),
street LIKE adrc-street,
edatu LIKE vbep-edatu,
ezeit LIKE vbep-ezeit,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
arktx LIKE vbap-arktx,
werks LIKE vbap-werks,
lgort LIKE vbap-lgort,
kwmeng_j LIKE vbap-kwmeng, "计价数量
meins LIKE vbep-meins,
kwmeng LIKE vbap-kwmeng,
vrkme LIKE vbap-vrkme,
kpein LIKE vbap-kpein,
kmein LIKE vbap-kmein,
netwr_d LIKE vbap-netwr, "单价
mwsbp LIKE vbap-mwsbp,
umvkz LIKE vbap-umvkz,
netwr_s LIKE vbap-netwr, "销售单价
kdmat LIKE vbap-kdmat , "头数 ++++++++++
umvkn LIKE vbap-umvkn,
netwr LIKE vbap-netwr, "金额
name1 LIKE t001w-name1, "工厂描述'
name2 LIKE t001l-lgobe, "仓库描述' 8 'GT_VBAP'.
name3 LIKE tvstt-vtext, "装运点描述' 8 'GT_VBAP'.
datbi LIKE lv50c-datbi, "KETDAT
kzwi1 LIKE vbap-kzwi1, "单价(合计)
taxk1 LIKE vbak-taxk1,
taxm1 LIKE vbap-taxm1,
netpr LIKE vbap-netpr,
prsdt TYPE prsdt, "定价日期
bstkd LIKE vbkd-bstkd,
txt_posnr(100) TYPE c, "行文本(工艺描述)
knumv LIKE konv-knumv,
zh_kwert LIKE konv-kwert,
END OF ty_vbap.
DATA : wa_vbap TYPE ty_vbap,
gt_vbap TYPE TABLE OF ty_vbap WITH HEADER LINE.
DATA : wa_vbap_vl TYPE ty_vbap,
gt_vbap_vl TYPE TABLE OF ty_vbap WITH HEADER LINE.
DATA : wa_vbap_sel TYPE ty_vbap,
gt_vbap_sel TYPE TABLE OF ty_vbap.
TYPES : BEGIN OF ty_vbak,
ck,
vbeln LIKE vbak-vbeln,
kunnr LIKE vbak-kunnr,
name4 TYPE ad_name1,
kunnr_s LIKE vbpa-kunnr,
name5 TYPE ad_name1,
kunnr_j LIKE vbpa-kunnr,
name6 TYPE ad_name1,
bzirk LIKE t171t-bzirk,
vkbur LIKE vbak-vkbur,
vkgrp LIKE vbak-vkgrp, "办事处
name7 TYPE ad_name1,
bzirk_txt LIKE t171t-bztxt,
telf1 LIKE kna1-telf1,
erdat LIKE vbak-erdat,
erzet LIKE vbak-erzet,
auart LIKE vbak-auart,
bezei LIKE v_tvak-bezei,
street LIKE adrc-street,
edatu LIKE vbep-edatu,
ezeit LIKE vbep-ezeit,
datbi LIKE lv50c-datbi, "KETDAT
klimk LIKE knkk-klimk, "信贷余额
cmgst LIKE vbuk-cmgst,
cmgst_text(10),
vkbur_text TYPE bezei20,
txt30 LIKE tj30t-txt30, "审批文本
bstkd LIKE vbkd-bstkd,
hdtxt(100) TYPE c, "抬头文本
zh_kwert LIKE konv-kwert,
knumv LIKE konv-knumv,
END OF ty_vbak.
DATA : wa_vbak TYPE ty_vbak,
gt_vbak
TYPE TABLE OF ty_vbak.
*"---------------add by ymq---------------------------\
*DATA: BEGIN OF l_s066 , "取清销售订单信贷值
* knkli LIKE s066-knkli,
* oeikw LIKE s066-oeikw,
* END OF l_s066.
*data: lt_s066 like l_s066 occurs 0 with header line.
*data: begin of l_s067 occurs 0, " 未清交货单信贷值
* knkli like s067-knkli,
* olikw like s067-olikw,
* ofakw like s067-ofakw,
* end of l_s067.
*data: lt_s067 like l_s067 occurs 0 with header line.
*data: begin of l_knkk occurs 0 , "未清开票信贷值
* knkli like knkk-knkli,
* skfor like knkk-skfor,
* klimk like knkk-klimk,
* ctlpc like knkk-ctlpc,
* end of l_knkk .
*data: lt_knkk like l_knkk occurs 0 with header line.
*
*types: BEGIN OF type_detail, "用户所有信贷值结构
* kunnr like vbak-kunnr, "客户编号
* oeikw LIKE s066-oeikw, "未清销售订单信贷值
* olikw LIKE s067-olikw, "未清交货单信贷值
* ofakw LIKE s067-ofakw, "未清开票信贷值
* skfor LIKE knkk-skfor, "客户往来余额 ,如果为负,表示由余款,为其绝对值
* klimk LIKE knkk-klimk, "客户信用额度
* klimks LIKE knkk-klimk, "当前客户信用额度
* ctlpc LIKE knkk-ctlpc, "是否检查信用额
* END OF type_detail.
*DATA: wa_detail TYPE type_detail.
*
*DATA: BEGIN OF itab ,
* vbeln LIKE vbak-vbeln, "无用
* erdat LIKE vbak-erdat,
* auart LIKE vbak-auart,
* cmgst LIKE vbuk-cmgst,
* END OF itab.
*DATA: gt_itab TYPE itab OCCURS 0 WITH HEADER LINE. " add by ymq 2014.11.23 更新信贷状态通过
*BDC定义
DATA: c_update TYPE c VALUE 'S'.
DATA: bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE.
DATA: messtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.
DATA: gt_msg TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.
*审核
TYPES : BEGIN OF ty_ztsd003.
TYPES : ck.
INCLUDE STRUCTURE ztsd024.
TYPES: adrnr LIKE vbpa-adrnr,
kunnr
LIKE vbak-kunnr,
name4
TYPE ad_name1,
kunnr_s
LIKE vbpa-kunnr,
name5
TYPE ad_name1,
vkgrp
LIKE vbak-vkgrp, "办事处
name7
TYPE ad_name1,
bzirk
LIKE t171t-bzirk,
bzirk_txt
LIKE t171t-bztxt,
erdat_c
LIKE vbak-erdat,
erzet_c
LIKE vbak-erzet,
auart
LIKE vbak-auart,
bezei
LIKE v_tvak-bezei,
name_text
TYPE ad_namtext.
TYPES : END OF ty_ztsd003.
DATA : wa_ztsd003 TYPE ty_ztsd003,
gt_ztsd003
TYPE TABLE OF ty_ztsd003.
TYPES:BEGIN OF ty_konv,
kwert
LIKE konv-kwert,
knumv
LIKE konv-knumv,
END OF ty_konv.
DATA:git_konv TYPE ty_konv OCCURS 0 WITH HEADER LINE.
DATA:gwa_konv TYPE ty_konv.
RANGES : lt_spart FOR vbak-spart.
RANGES : lt_spart2 FOR vbak-spart.
*&---------------------------------------------------------------------*
*& Form alpha_input
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_P text
*----------------------------------------------------------------------*
FORM alpha_input CHANGING p_p.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_p
IMPORTING
output = p_p.
ENDFORM. " alpha_input
*&---------------------------------------------------------------------*
*& Form frm_build_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_build_fieldcat .
CLEAR : gt_fieldcat,gt_fieldcat[].
CLEAR : gt_fieldcat_d,gt_fieldcat_d[].
DEFINE alv_head.
clear gt_fieldcat.
if &1 = 'CK'.
gt_fieldcat
-checkbox = 'X'.
gt_fieldcat
-edit = 'X'.
else.
gt_fieldcat
-edit = ''.
endif.
gt_fieldcat
-fieldname = &1.
gt_fieldcat
-tabname = &4.
gt_fieldcat
-seltext_s = &2 .
gt_fieldcat
-seltext_m = &2 .
gt_fieldcat
-seltext_l = &2 .
gt_fieldcat
-outputlen = &3.
gt_fieldcat
-just = &5.
gt_fieldcat
-key = &6.
gt_fieldcat
-no_zero = 'X'.
* gt_fieldcat-decimals_out = 2.
if &1 = 'DATBI'.
gt_fieldcat
-edit = 'X'.
endif.
append gt_fieldcat.
END-OF-DEFINITION.
DEFINE alv_head_d.
clear gt_fieldcat_d.
if &1 = 'CK'.
gt_fieldcat_d
-checkbox = 'X'.
gt_fieldcat_d
-edit = 'X'.
else.
gt_fieldcat_d
-edit = ''.
endif.
gt_fieldcat_d
-fieldname = &1.
gt_fieldcat_d
-tabname = &4.
gt_fieldcat_d
-seltext_s = &2 .
gt_fieldcat_d
-seltext_m = &2 .
gt_fieldcat_d
-seltext_l = &2 .
gt_fieldcat_d
-outputlen = &3.
gt_fieldcat_d
-just = &5.
gt_fieldcat_d
-KEY = &6.
gt_fieldcat_d
-no_zero = 'X'.
if &1 = 'KWMENG_J' or &1 = 'KWMENG' or &1 = 'NETWR'.
gt_fieldcat_d
-do_sum = 'X'.
endif.
* gt_fieldcat-decimals_out = 2.
append gt_fieldcat_d.
END-OF-DEFINITION.
*头 R)ight (L)eft (C)ent.
alv_head
'CK' 'SEL' 4 'GT_VBAK' 'L' 'X'.
alv_head
'VBELN' '订单号' 8 'GT_VBAK' 'L' 'X'.
* alv_head 'KUNNR' '售达方' 10 'GT_VBAK'.
alv_head
'NAME4' '售达方名称' 10 'GT_VBAK' 'L' ''.
* alv_head 'KUNNR_S' '送达方' 10 'GT_VBAK'.
alv_head
'NAME5' '送达方名称' 10 'GT_VBAK' 'L' ''.
* alv_head 'KUNNR_J' '经办人' 10 'GT_VBAK'.
* alv_head 'VKBUR' '销售大区' 10 'GT_VBAK'.
* alv_head 'VKGRP' '办事处' 10 'GT_VBAK'.
alv_head
'BZIRK_TXT' '销售部' 10 'GT_VBAK' 'L' ''.
alv_head
'VKBUR_TEXT' '销售区域' 10 'GT_VBAK' 'L' ''.
alv_head
'NAME7' '销售片区' 10 'GT_VBAK' 'L' ''.
* alv_head 'TELF1' '客户联系方式' 10 'GT_VBAK'.
alv_head
'ERDAT' '订单日期' 10 'GT_VBAK' 'L' ''.
alv_head
'ERZET' '订单时间' 10 'GT_VBAK' 'L' ''.
* alv_head 'AUART' '订单类型' 10 'GT_VBAK' 'L'.
alv_head
'BEZEI' '订单描述' 10 'GT_VBAK' 'L' ''.
* alv_head 'STREET' '配送地址' 10 'GT_VBAK'.
* alv_head 'EDATU' '到货日期' 10 'GT_VBAK' 'L'.
* alv_head 'EZEIT' '到货时间' 10 'GT_VBAK' 'L'.
alv_head
'DATBI' '缺省交货日期' 12 'GT_VBAK' 'L' ''.
* alv_head 'TXT30' '审批状态' 10 'GT_VBAK' 'L'.
alv_head
'CMGST_TEXT' '信贷状态' 8 'GT_VBAK' 'L' ''.
alv_head
'KLIMK' '可用信贷' 15 'GT_VBAK' 'L' ''.
alv_head
'BSTKD' '采购订单编号' 15 'GT_VBAK' 'L' ''.
alv_head
'HDTXT' '采购订单抬头文本' 100 'GT_VBAK' 'L' ''.
*明细
* alv_head_d 'CK' '行号' 8 'GT_VBAP' 'R'.
alv_head_d
'POSNR' '行号' 8 'GT_VBAP' 'R' ''.
alv_head_d
'MATNR' '物料号' 8 'GT_VBAP' 'L' ''.
alv_head_d
'ARKTX' '物料描述' 18 'GT_VBAP' 'L' ''.
*
alv_head_d
'KWMENG_J' ' 计价数量' 8 'GT_VBAP' 'L' ''.
alv_head_d
'NETWR_D' ' 单价' 8 'GT_VBAP' 'L' ''.
alv_head_d
'MEINS' ' 计价单位' 8 'GT_VBAP' 'C' ''.
* alv_head_d 'KPEIN' ' 定价单位' 8 'GT_VBAP' 'L'.
alv_head_d
'KWMENG' ' 销售数量' 8 'GT_VBAP' 'L' ''.
"alv_head_d 'KDMAT' ' 头数' 8 'GT_VBAP' 'L'.
alv_head_d
'NETWR_S' ' 销售单价' 8 'GT_VBAP' 'L' ''.
alv_head_d
'VRKME' ' 销售单位' 8 'GT_VBAP' 'C' ''.
alv_head_d
'NETWR' ' 金额' 8 'GT_VBAP' 'L' ''.
*
alv_head_d
'WERKS' '工厂' 8 'GT_VBAP' 'L' ''.
alv_head_d
'NAME1' '工厂描述' 8 'GT_VBAP' 'L' ''.
alv_head_d
'LGORT' '仓库' 8 'GT_VBAP' 'L' ''.
alv_head_d
'NAME2' '仓库描述' 8 'GT_VBAP' 'L' ''.
alv_head_d
'VSTEL' ' 装运点' 8 'GT_VBAP' 'L' ''.
alv_head_d
'NAME3' ' 装运点描述' 8 'GT_VBAP' 'L' ''.
alv_head_d
'PRSDT' ' 定价日期' 8 'GT_VBAP' 'L' ''.
"alv_head_d 'TXT_POSNR' ' 工艺描述' 8 'GT_VBAP' 'L'.
" alv_head 'ZH_KWERT' ' 总共折扣金额' 8 'GT_VBAK' 'L'.
*
ENDFORM. " frm_build_fieldcat
*&---------------------------------------------------------------------*
*& Form frm_display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_display_data .
gs_layout
-box_fieldname = 'CK'.
gs_layout
-box_tabname = 'GT_VBAK'.
gs_layout
-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_callback_pf_status_set
= 'SET_STATUS'
i_callback_user_command
= 'USER_COMMAND'
is_layout
= gs_layout
it_fieldcat
= gt_fieldcat[]
i_save
= 'A'
TABLES
t_outtab
= gt_vbak[]
EXCEPTIONS
program_error
= 1
OTHERS = 2.
* is_keyinfo-header01 = 'VBELN'.
* is_keyinfo-item01 = 'VBELN'.
* CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
* EXPORTING
* i_callback_program = sy-repid
* i_callback_pf_status_set = 'SET_STATUS'
* i_callback_user_command = 'USER_COMMAND'
* is_layout = gs_layout
* it_fieldcat = gt_fieldcat[]
* i_default = 'X'
* i_save = 'A'
** is_variant = alv_variant
** it_events = gt_events[] "n777869
* i_tabname_header = 'GT_VBAK'
* i_tabname_item = 'GT_VBAP'
* is_keyinfo = is_keyinfo
* TABLES
* t_outtab_header = gt_vbak[]
* t_outtab_item = gt_vbap[]
* EXCEPTIONS
* program_error = 1
* OTHERS = 2.
* IF sy-subrc <> 0.
* ENDIF.
ENDFORM. " frm_display_data
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RF_UCOMM text
* -->RS text
*----------------------------------------------------------------------*
FORM user_command USING rf_ucomm LIKE sy-ucomm
rs
TYPE slis_selfield.
DATA : wa_vbak_tmp TYPE ty_vbak,
gt_vbak_tmp
TYPE TABLE OF ty_vbak.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
*------------------------记录表---------------------------------------------
DATA : wa_ztsd003_tmp TYPE ztsd024,
gt_ztsd003_tmp
TYPE TABLE OF ztsd024.
*---------------------------------------------------------------------
*Begin SO
DATA : salesdocument TYPE bapivbeln-vbeln,
order_header_in
TYPE bapisdh1,
order_header_inx
TYPE bapisdh1x,
wa_return
TYPE bapiret2,
lt_return
TYPE TABLE OF bapiret2,
wa_order_item_in
TYPE bapisditm,
lt_order_item_in
TYPE TABLE OF bapisditm,
wa_order_item_inx
TYPE bapisditmx,
lt_order_item_inx
TYPE TABLE OF bapisditmx,
wa_schedule_lines
TYPE bapischdl,
lt_schedule_lines
TYPE TABLE OF bapischdl,
wa_schedule_linesx
TYPE bapischdlx,
lt_schedule_linesx
TYPE TABLE OF bapischdlx.
DATA : ls_msg(220),
ls_msg_s
(220),
ls_msg_e
(220).
*End
*Begin DN
DATA : l_ship_point TYPE bapidlvcreateheader-ship_point,
l_due_date
TYPE bapidlvcreateheader-due_date,
l_delivery
TYPE bapishpdelivnumb-deliv_numb.
DATA : wa_sales_order_items TYPE bapidlvreftosalesorder,
lt_sales_order_items
TYPE TABLE OF bapidlvreftosalesorder.
* lt_RETURN LIKE BAPIRET2 .
DATA : ls_abgru LIKE vbap-abgru.
*End
* BREAK-POINT.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid
= lr_grid.
CALL METHOD lr_grid->check_changed_data.
rs
-col_stable = 'X'.
rs
-row_stable = 'X'.
rs
-refresh = 'X'.
gt_vbak_tmp[]
= gt_vbak[].
DELETE gt_vbak_tmp WHERE ck <> 'X'.
* BREAK-POINT.
DATA:count TYPE i VALUE 0.
CASE rf_ucomm.
WHEN '&CREA'. " 创建
CALL TRANSACTION 'VA01'.
WHEN '©'. "复制
CLEAR : bdcdata,bdcdata[].
IF lines( gt_vbak_tmp ) > 1.
MESSAGE '一次只能参考一张销售订单!' TYPE 'E'.
ENDIF.
READ TABLE gt_vbak_tmp INTO wa_vbak_tmp INDEX 1.
IF sy-subrc = 0.
PERFORM bdc_dynpro USING 'SAPMV45A' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR' 'VBAK-AUART'.
PERFORM bdc_field USING 'BDC_OKCODE' '=COPY'.
PERFORM bdc_field USING 'VBAK-AUART' wa_vbak_tmp-auart.
PERFORM bdc_dynpro USING 'SAPLV45C' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=RAUF'.
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLV45C'.
PERFORM bdc_field USING 'BDC_CURSOR' 'LV45C-VBELN'.
PERFORM bdc_dynpro USING 'SAPLV45C' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=UEBR'.
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLV45C'.
PERFORM bdc_field USING 'BDC_CURSOR' 'LV45C-VBELN'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = wa_vbak_tmp-vbeln
IMPORTING
output = wa_vbak_tmp-vbeln.
PERFORM bdc_field USING 'LV45C-VBELN' wa_vbak_tmp-vbeln.
PERFORM call_transaction_form USING 'VA01'.
ENDIF.
WHEN '&MODI'. "修改
IF lines( gt_vbak_tmp ) > 1.
MESSAGE '一次只能修改一张销售订单!' TYPE 'E'.
ENDIF.
READ TABLE gt_vbak_tmp INTO wa_vbak_tmp INDEX 1.
IF sy-subrc = 0.
SET PARAMETER ID 'AUN' FIELD wa_vbak_tmp-vbeln.
CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.
ENDIF.
WHEN '&REA'. "拒绝
LOOP AT gt_vbak INTO wa_vbak WHERE ck = 'X'. "选择行
*检查是否已经拒绝
CLEAR : ls_abgru.
SELECT SINGLE abgru
INTO ls_abgru
FROM vbap WHERE vbeln = wa_vbak-vbeln.
IF sy-subrc = 0 AND ls_abgru = 'Z1'.
MESSAGE '该销售单已拒绝!' TYPE 'E'.
ENDIF.
"ADD BY YMQ 2015.11.10 新增拒绝警告信息
TYPE-POOLS:icon.
TYPES: BEGIN OF typ_pop,
iconbox
TYPE icon_d , "警告图标
message(30) TYPE c , "警告信息
msgtype
(1) TYPE c , "消息类型
END OF typ_pop.
DATA: lt_pop TYPE typ_pop OCCURS 0 WITH HEADER LINE .
DATA: e_exit(1) TYPE c .
DATA: tmp_msg(30) TYPE c .
DATA: pop_field TYPE slis_t_fieldcat_alv WITH HEADER LINE,
pop_layout
TYPE slis_layout_alv.
lt_pop
-iconbox = icon_led_yellow.
CONCATENATE ' 是否拒绝订单:' wa_vbak-vbeln '' INTO tmp_msg.
lt_pop
-message = tmp_msg.
lt_pop
-msgtype = 'W'.
APPEND lt_pop.
pop_field
-fieldname = 'ICONBOX'.
pop_field
-tabname = 'LT_POP'.
pop_field
-seltext_m = '消息类型'.
pop_field
-col_pos = 1 .
pop_field
-outputlen = 4 .
APPEND pop_field.
pop_field
-fieldname = 'MESSAGE'.
pop_field
-tabname = 'LT_POP'.
pop_field
-seltext_m = '消息文本'.
pop_field
-col_pos = 2 .
pop_field
-outputlen = 55 .
APPEND pop_field.
pop_field
-fieldname = 'MSGTYPE'.
pop_field
-tabname = 'LT_POP'.
pop_field
-seltext_m = 'Type'.
pop_field
-col_pos = 3 .
pop_field
-outputlen = 4 .
APPEND pop_field.
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_title
= '消息'
i_selection
= 'X'
* I_ALLOW_NO_SELECTION =
i_zebra
= ' '
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_CHECKBOX_FIELDNAME = tmp_chose
* I_LINEMARK_FIELDNAME =
i_scroll_to_sel_line
= 'X'
i_tabname
= 'LT_POP'
* I_STRUCTURE_NAME =
it_fieldcat
= pop_field[]
* IT_EXCLUDING =
i_callback_program
= sy-repid
* I_CALLBACK_USER_COMMAND =
* IS_PRIVATE =
IMPORTING
* ES_SELFIELD =
e_exit
= e_exit
TABLES
t_outtab
= lt_pop[]
EXCEPTIONS
program_error
= 1
OTHERS = 2.
IF sy-subrc = 0 AND e_exit = 'X'. "取消
RETURN.
ENDIF. "add by tractor 2015.11.17
LOOP AT gt_vbap INTO wa_vbap WHERE vbeln = wa_vbak-vbeln. "SO对应的所有行
CLEAR : salesdocument,
wa_return
,
lt_return
,
wa_order_item_in
,
lt_order_item_in
,
wa_order_item_inx
,
lt_order_item_inx
,
wa_schedule_lines
,
lt_schedule_lines
,
wa_schedule_linesx
,
lt_schedule_linesx
.
wa_order_item_in
-itm_number = wa_vbap-posnr.
wa_order_item_in
-reason_rej = 'Z1'.
APPEND wa_order_item_in TO lt_order_item_in.
wa_order_item_inx
-itm_number = wa_vbap-posnr.
wa_order_item_inx
-updateflag = 'U'.
wa_order_item_inx
-reason_rej = 'X'.
APPEND wa_order_item_inx TO lt_order_item_inx.
order_header_inx
-updateflag = 'U'.
WAIT UP TO 2 SECONDS. "等待2秒
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument
= wa_vbap-vbeln
order_header_in
= order_header_in
order_header_inx
= order_header_inx
behave_when_error
= 'P'
TABLES
return = lt_return
order_item_in
= lt_order_item_in
order_item_inx
= lt_order_item_inx
* schedule_lines = lt_schedule_lines
* schedule_linesx = lt_schedule_linesx.
.
READ TABLE lt_return INTO wa_return WITH KEY type = 'S'.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
IF ls_msg_s IS INITIAL.
ls_msg_s
= wa_vbap-posnr.
ELSE.
CONCATENATE ls_msg_s ',' wa_vbap-posnr INTO ls_msg_s.
ENDIF.
ELSE.
* CLEAR : ls_msg.
LOOP AT lt_return INTO wa_return.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= wa_return-id
msgnr
= wa_return-number
msgv1
= wa_return-message_v1
msgv2
= wa_return-message_v2
msgv3
= wa_return-message_v3
msgv4
= wa_return-message_v4
IMPORTING
message_text_output
= ls_msg_e.
ENDLOOP.
IF ls_msg_s IS INITIAL.
ls_msg_e
= wa_vbap-posnr.
ELSE.
CONCATENATE ls_msg_e ',' wa_vbap-posnr INTO ls_msg_e.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
IF ls_msg_e IS INITIAL.
CONCATENATE '销售订单' wa_vbap-vbeln ':行项目' ls_msg_s ' 未发货数量已拒绝!' INTO ls_msg.
ELSEIF ls_msg_s IS INITIAL.
CONCATENATE '销售订单' wa_vbap-vbeln ':行项目' ls_msg_e ' 未发货数量拒绝失败,请手工更改!' INTO ls_msg.
* ELSE.
* CONCATENATE '销售订单' wa_vbap-vbeln ':行项目' ls_msg_s ' 未发货数量已拒绝,行项目:' ls_msg_e '未发货数量拒绝失败,请手工更改!' INTO ls_msg.
ENDIF.
MESSAGE ls_msg TYPE 'I'.
CLEAR : ls_msg.
CLEAR : ls_msg_e.
CLEAR : ls_msg_s.
WHEN '&TUR'. "转交货单
* IF sy-uname <> 'XH003'.
* MESSAGE '正在修改,不能使用此功能' TYPE 'I'.
* EXIT.
* ENDIF.
DATA:BEGIN OF gwa_lips,
vgbel
LIKE lips-vgbel,
END OF gwa_lips.
DATA:git_lips LIKE gwa_lips OCCURS 0 WITH HEADER LINE.
"LOOP AT gt_vbak INTO wa_vbak WHERE ck = 'X'.
"select vgbel into table git_lips from lips where vgbel = wa_vbak-vbeln and vgpos = wa_vbak-posnr.
"if git_lips[] is not initial.
"message '不允许同一张订单,同一行项目二次发货' type 'I'.
"leave to screen 0.
"endif.
"endloop.
CLEAR : l_ship_point,l_due_date,wa_sales_order_items,lt_sales_order_items.
SORT gt_vbap BY vbeln ASCENDING
vstel
ASCENDING.
CLEAR : wa_vbap_vl , gt_vbap_vl.
LOOP AT gt_vbap INTO wa_vbap .
wa_vbap_vl
-vbeln = wa_vbap-vbeln.
wa_vbap_vl
-vstel = wa_vbap-vstel.
COLLECT wa_vbap_vl INTO gt_vbap_vl.
ENDLOOP.
SORT gt_vbap_vl BY vbeln ASCENDING
vstel
ASCENDING.
LOOP AT gt_vbak INTO wa_vbak WHERE ck = 'X'.
CLEAR : wa_sales_order_items , lt_sales_order_items,bdcdata,bdcdata[].
LOOP AT gt_vbap_vl INTO wa_vbap_vl WHERE vbeln = wa_vbak-vbeln.
*-----------------------------------------------
AT NEW vstel.
l_ship_point
= wa_vbap_vl-vstel. "装运点
l_due_date
= wa_vbak-datbi.
PERFORM bdc_dynpro USING 'SAPMV50A' '4001'.
PERFORM bdc_field USING 'BDC_CURSOR' 'LV50C-VBELN'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM bdc_field USING 'LIKP-VSTEL' l_ship_point.
PERFORM bdc_field USING 'LV50C-DATBI' l_due_date.
PERFORM bdc_field USING 'LV50C-VBELN' wa_vbak-vbeln.
PERFORM bdc_dynpro USING 'SAPMV50A' '1000'.
PERFORM bdc_field USING 'BDC_OKCODE' '=SICH_T'.
PERFORM call_transaction_form_vl01n USING 'VL01N' CHANGING l_delivery .
* BREAK-POINT.
IF NOT l_delivery IS INITIAL.
CLEAR : wa_ztsd003_tmp , gt_ztsd003_tmp.
CONCATENATE '成功生成交货单:' l_delivery '!' INTO ls_msg_s .
wa_ztsd003_tmp
-vbeln_vl = l_delivery.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_ztsd003_tmp-vbeln_vl
IMPORTING
output = wa_ztsd003_tmp-vbeln_vl.
*--------记录成功消息---------------------
DATA : l_posnr_vl TYPE posnr_vl.
l_posnr_vl
= 10.
LOOP AT gt_vbap INTO wa_vbap WHERE vstel = wa_vbap_vl-vstel AND vbeln = wa_vbap_vl-vbeln.
wa_ztsd003_tmp
-mandt = sy-mandt.
wa_ztsd003_tmp
-vbeln = wa_vbap-vbeln.
wa_ztsd003_tmp
-posnr = wa_vbap-posnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_posnr_vl
IMPORTING
output = l_posnr_vl.
wa_ztsd003_tmp
-posnr_vl = l_posnr_vl.
wa_ztsd003_tmp
-erdat = sy-datum.
wa_ztsd003_tmp
-erzet = sy-uzeit.
wa_ztsd003_tmp
-ernam = sy-uname.
APPEND wa_ztsd003_tmp TO gt_ztsd003_tmp.
l_posnr_vl
= l_posnr_vl + 10.
ENDLOOP.
MODIFY ztsd024 FROM TABLE gt_ztsd003_tmp.
COMMIT WORK.
CLEAR : wa_ztsd003_tmp,gt_ztsd003_tmp.
* MESSAGE ls_msg_s TYPE 'I'.
DELETE gt_vbak WHERE vbeln = wa_vbak-vbeln.
ELSE.
CLEAR : wa_ztsd003,gt_ztsd003.
CLEAR : ls_msg.
LOOP AT lt_return INTO wa_return.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= wa_return-id
msgnr
= wa_return-number
msgv1
= wa_return-message_v1
msgv2
= wa_return-message_v2
msgv3
= wa_return-message_v3
msgv4
= wa_return-message_v4
IMPORTING
message_text_output
= ls_msg_e.
CONCATENATE ls_msg '/' ls_msg_e INTO ls_msg.
ENDLOOP.
MESSAGE '销售订单转交未成功,检查数据完整性!' TYPE 'E'.
CONTINUE.
ENDIF.
ENDAT.
ENDLOOP.
ENDLOOP.
IF sy-subrc EQ 0.
MESSAGE '转交成功!' TYPE 'I'.
ELSE.
MESSAGE '部分转交成功或转交失败!' TYPE 'E'.
ENDIF.
WHEN '&IC1'. "双击
* READ TABLE gt_vbak INTO wa_vbak_tmp INDEX rs-tabindex.
* IF sy-subrc = 0.
* SET PARAMETER ID 'AUN' FIELD wa_vbak_tmp-vbeln.
* CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
* ENDIF.
IF rs-tabname EQ 'GT_VBAK'.
READ TABLE gt_vbak INTO wa_vbak INDEX rs-tabindex.
IF sy-subrc = 0.
gt_vbap_sel[]
= gt_vbap[].
DELETE gt_vbap_sel WHERE vbeln <> wa_vbak-vbeln.
DELETE ADJACENT DUPLICATES FROM gt_vbap_sel.
PERFORM frm_display_data_d.
ENDIF.
ENDIF.
* WHEN '&F03'.
* count = count - 1.
* LEAVE TO SCREEN 0.
WHEN '&CHG'. " add by ymq 2014.11.23 更新信贷状态
DATA: lc_tabix TYPE sy-tabix.
DATA l_cmgst LIKE TABLE OF vbuk WITH HEADER LINE.
DATA: lt_cmgst LIKE LINE OF l_cmgst.
LOOP AT gt_vbak INTO wa_vbak WHERE ck = 'X'.
CALL FUNCTION 'SD_ORDER_CREDIT_RECHECK'
EXPORTING
flg_update
= 'X'
vbeln
= wa_vbak-vbeln
EXCEPTIONS
error_message
= 4.
ENDLOOP.
COMMIT WORK AND WAIT.
LOOP AT gt_vbak INTO wa_vbak WHERE ck = 'X'.
lc_tabix
= sy-tabix.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF lt_cmgst
FROM vbuk WHERE vbeln = wa_vbak-vbeln AND cmgst ='A'.
IF sy-subrc = 0.
CASE lt_cmgst-cmgst.
WHEN ''.
wa_vbak
-cmgst_text = '未执行'.
WHEN 'A'.
wa_vbak
-cmgst_text = '通过'.
WHEN 'B'.
wa_vbak
-cmgst_text = '不通过'.
WHEN 'C'.
wa_vbak
-cmgst_text = '部分通过'.
WHEN 'D'.
wa_vbak
-cmgst_text = '批准后通过'.
ENDCASE.
MODIFY gt_vbak[] INDEX lc_tabix FROM wa_vbak.
ENDIF.
ENDLOOP.
CALL METHOD lr_grid->refresh_table_display.
MESSAGE '订单状态已更新!' TYPE 'S'.
* data: lc_tabix type sy-tabix.
* select vbak~vbeln "取所有未通过信用状态
* vbak~erdat
* vbak~auart
* vbuk~cmgst
* into corresponding fields of table gt_itab
* from vbak
* inner join vbuk on vbuk~vbeln = vbak~vbeln
* where vbuk~cmgst <> 'A'.
* select s066~knkli s066~oeikw into corresponding fields of table lt_s066 "取所有未清销售订单信贷
* from s066.
* sort lt_s066.
* select knkli olikw ofakw into corresponding fields of table lt_s067 "取所有未清交货单信贷
* from s067.
* sort lt_s067.
* select knkli skfor klimk ctlpc into corresponding fields of table lt_knkk "取所有开票信贷额
* from knkk.
* sort lt_knkk.
* LOOP AT gt_vbak INTO wa_vbak WHERE ck = 'X'. "循环选择内表
* lc_tabix = sy-tabix.
* clear wa_detail.
* loop at gt_itab.
* wa_detail-kunnr = wa_vbak-kunnr.
* if wa_detail-kunnr is not initial.
* "-----process : 未清销售订单信贷
* read table lt_s066 with key knkli = wa_detail-kunnr binary search.
* if sy-subrc = 0.
* wa_detail-oeikw = lt_s066-oeikw.
* endif.
* "-----process : 未清交货信贷
* read table lt_s067 with key knkli = wa_detail-kunnr binary search.
* if sy-subrc = 0.
* wa_detail-olikw = lt_s067-olikw.
* endif.
* wa_detail-ofakw = wa_detail-oeikw + wa_detail-olikw + lt_s067-ofakw.
* clear lt_s067.
* "-----process : 未清开票信贷
* read table lt_knkk with key knkli = wa_detail-kunnr binary search.
* if sy-subrc = 0.
* wa_detail-skfor = lt_knkk-skfor. "客户往来余额
* wa_detail-klimk = lt_knkk-klimk. "客户信用额度
* wa_detail-ctlpc = lt_knkk-ctlpc. "是否检查信贷
* endif.
* wa_detail-klimks = wa_detail-klimk - wa_detail-skfor - wa_detail-ofakw.
* if wa_detail-klimks > 0.
* update vbuk set cmgst = 'A' where vbeln = wa_vbak-vbeln.
* wa_vbak-cmgst_text = '通过'.
* modify gt_vbak[] index lc_tabix from wa_vbak.
* endif.
* endif. "kunnr is not initial.
* endloop.
* endloop.
* commit work and wait.
* message '订单状态已更新' type 'S'.
* " add by ymq 2014.11.23
*
WHEN OTHERS.
EXIT.
ENDCASE.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form set_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM set_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD' EXCLUDING rt_extab .
ENDFORM. "set_status
*&---------------------------------------------------------------------*
*& Form FRM_READ_VBAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_read_vbap .
TYPES: BEGIN OF ty_vl02,
vbelv
LIKE vbfa-vbelv, "销售单 J
posnv
TYPE posnr_von,
vbeln
LIKE vbfa-vbeln, "交货单
posnn
TYPE posnr_nach,
END OF ty_vl02.
DATA : wa_vl02 TYPE ty_vl02,
lt_vl02
TYPE TABLE OF ty_vl02.
SELECT b~auart
b
~vbeln "LIKE vbak-vbeln,
b
~kunnr "LIKE vbak-kunnr,
b
~spart AS spart1
a
~spart AS spart2
* kunnr_s "LIKE vbpa-kunnr,
* kunnr_j "LIKE vbpa-kunnr,
vkbur
"LIKE vbak-vkbur,
vkgrp
"LIKE vbak-vkgrp,
* telf1 "LIKE kna1-telf1,
b
~erdat "LIKE vbak-erdat,
b
~erzet "LIKE vbak-erzet,
a
~posnr "LIKE vbap-posnr,
a
~meins "LIKE vbap-meins,
a
~kdmat "红白条头数
matnr
"LIKE vbap-matnr,
arktx
"LIKE vbap-arktx,
werks
"LIKE vbap-werks,
lgort
"LIKE vbap-lgort,
vstel
"LIKE vbap-vstel,
kwmeng
"LIKE vbap-kwmeng,
a
~vrkme "LIKE vbap-vrkme,
kpein
"LIKE vbap-kpein,
kmein
"LIKE vbap-kmein,
* netwr_d "LIKE vbap-netwr, "单价
mwsbp
"LIKE vbap-mwsbp,
a
~umvkz "LIKE vbap-umvkz,
a
~umvkn "LIKE vbap-umvkn,
a
~netwr "LIKE vbap-netwr, "金额
* kwmeng_j "LIKE vbap-kwmeng, "计价数量
* 配送方式
* stype(10),
* street "LIKE adrc-street,
edatu
"LIKE vbep-edatu,
ezeit
"LIKE vbep-ezeit,
c~edatu AS datbi "like LV50C-DATBI, "KETDAT VBAK-VDATU
kzwi1
taxk1
taxm1
netpr
knumv
e
~bzirk
e
~prsdt
INTO CORRESPONDING FIELDS OF TABLE gt_vbap
FROM vbap AS a
INNER
JOIN vbak AS b
ON a~vbeln = b~vbeln
INNER
JOIN vbep AS c
ON a~vbeln = c~vbeln AND a~posnr = c~posnr
INNER
JOIN vbup AS d
ON a~vbeln = d~vbeln AND a~posnr = d~posnr
INNER
JOIN vbkd AS e
ON b~vbeln = e~vbeln "AND a~posnr = e~posnr
WHERE auart IN auart
AND vkorg IN vkorg
AND vtweg IN vtweg
"AND b~spart IN spart
"AND a~spart IN spart2
AND vkbur IN vkbur
AND vkgrp IN vkgrp
AND wmeng <> 0
AND kunnr IN kunnr
AND werks IN werks
AND lgort IN lgort
AND vstel IN vstel
AND b~ernam IN ernam
AND b~vbeln IN vbeln
AND b~erdat IN erdat
AND edatu IN edatu
AND ezeit IN ezeit
*AND d~lfgsk <> 'C'
AND d~lfgsa <> 'C'
AND d~absta <> 'C'
AND e~bzirk IN bzrik "add by trator 2015.08.21
.
LOOP AT gt_vbap INTO wa_vbap .
AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
ID 'VKORG' DUMMY
ID 'VTWEG' DUMMY
ID 'SPART' FIELD wa_vbap-spart1
ID 'ACTVT' DUMMY.
IF sy-subrc <> 0. "抬头
READ TABLE lt_spart WITH KEY low = wa_vbap-spart1.
IF sy-subrc <> 0.
DELETE gt_vbap.
ENDIF.
ENDIF.
ENDLOOP.
*--取销售订单的折扣金额的值
SELECT kwert knumv INTO TABLE git_konv FROM konv FOR ALL ENTRIES IN gt_vbap WHERE knumv = gt_vbap-knumv AND kschl = 'ZP85'.
*取得已交货的SO
* CLEAR : wa_vl02,lt_vl02.
* SELECT vbelv "销售单 J
* posnv
* vbeln
* posnn
* INTO CORRESPONDING FIELDS OF TABLE lt_vl02
* FROM vbfa
* FOR ALL ENTRIES IN gt_vbap
* WHERE vbelv = gt_vbap-vbeln
* AND vbtyp_n = 'J'
* .
* DELETE ADJACENT DUPLICATES FROM lt_vl02 .
* SORT lt_vl02 ASCENDING BY vbelv.
DATA : BEGIN OF lt_cmgst OCCURS 0,
vbeln
LIKE vbuk-vbeln,
cmgst
LIKE vbuk-cmgst,
END OF lt_cmgst.
IF NOT gt_vbap[] IS INITIAL.
SELECT vbeln cmgst
INTO TABLE lt_cmgst
FROM vbuk
FOR ALL ENTRIES IN gt_vbap
WHERE vbeln = gt_vbap-vbeln
.
SORT lt_cmgst BY vbeln ASCENDING.
ENDIF.
DATA : BEGIN OF lt_tvkbt OCCURS 0,
vkbur
LIKE tvkbt-vkbur,
bezei
LIKE tvkbt-bezei,
END OF lt_tvkbt.
SELECT vkbur bezei
INTO TABLE lt_tvkbt
FROM tvkbt
WHERE spras = 1.
SORT lt_tvkbt BY vkbur ASCENDING.
DATA : BEGIN OF lt_vbkd OCCURS 0,
vbeln
LIKE vbkd-vbeln,
posnr
LIKE vbkd-posnr,
prsdt
LIKE vbkd-prsdt,
bstkd
LIKE vbkd-bstkd,
END OF lt_vbkd.
IF NOT gt_vbap[] IS INITIAL.
SELECT vbeln posnr prsdt bstkd
INTO TABLE lt_vbkd
FROM vbkd
FOR ALL ENTRIES IN gt_vbap
WHERE vbeln = gt_vbap-vbeln
AND ( posnr = gt_vbap-posnr "行
OR posnr = '000000' ). "抬头
SORT lt_vbkd BY vbeln ASCENDING
posnr
ASCENDING.
ENDIF.
DATA : BEGIN OF lt_tvgrt OCCURS 0,
vkgrp
LIKE tvgrt-vkgrp,
bezei
LIKE tvgrt-bezei,
END OF lt_tvgrt.
SELECT vkgrp bezei
INTO TABLE lt_tvgrt
FROM tvgrt
WHERE vkgrp IN vkgrp
AND spras = 1.
SORT lt_tvgrt BY vkgrp ASCENDING.
DATA : BEGIN OF lt_vstel OCCURS 0,
vstel
LIKE tvstt-vstel,
vtext
LIKE tvstt-vtext,
END OF lt_vstel.
SELECT vstel vtext
INTO TABLE lt_vstel
FROM tvstt WHERE spras = 1 ."装运点描述' 8 'GT_VBAP'.
SORT lt_vstel BY vstel ASCENDING.
DATA : BEGIN OF lt_lgort OCCURS 0,
werks
TYPE werks_d,
lgort
TYPE lgort_d,
lgobe
TYPE lgobe,
END OF lt_lgort.
SELECT werks lgort lgobe
INTO TABLE lt_lgort
FROM t001l WHERE werks IN werks ."仓库描述'
SORT lt_lgort BY werks ASCENDING lgort ASCENDING.
DATA : BEGIN OF lt_werks OCCURS 0,
werks
LIKE t001w-werks,
name1
LIKE t001w-name1,
END OF lt_werks.
SELECT werks name1
INTO TABLE lt_werks
FROM t001w WHERE werks IN werks.
SORT lt_werks BY werks ASCENDING.
DATA : lt_tvakt LIKE TABLE OF tvakt WITH HEADER LINE .
CLEAR : lt_tvakt,lt_tvakt[].
SELECT * INTO TABLE lt_tvakt FROM tvakt WHERE spras = '1'.
SORT lt_tvakt BY auart ASCENDING.
DATA : BEGIN OF lt_name OCCURS 0,
vbeln
LIKE vbpa-vbeln,
parvw
LIKE vbpa-parvw,
name
LIKE adrc-name1,
END OF lt_name .
IF NOT gt_vbap[] IS INITIAL.
CLEAR : lt_name, lt_name[].
SELECT vbeln parvw name1 AS name
INTO TABLE lt_name
FROM vbpa AS a
INNER
JOIN adrc AS b ON a~adrnr = b~addrnumber
FOR ALL ENTRIES IN gt_vbap
"WHERE parvw IN ('AG','WE')
WHERE vbeln = gt_vbap-vbeln.
SORT lt_name BY vbeln ASCENDING
parvw
ASCENDING.
ENDIF.
LOOP AT gt_vbap INTO wa_vbap.
SELECT SINGLE bztxt INTO wa_vbap-bzirk_txt
FROM t171t
WHERE bzirk EQ wa_vbap-bzirk.
* READ TABLE lt_vl02 INTO wa_vl02 WITH KEY vbelv = wa_vbap-vbeln
* posnv = wa_vbap-posnr.
* sy-subrc = 4. "不删除
* IF sy-subrc = 0. "已有交货
* DELETE gt_vbap WHERE vbeln = wa_vbap-vbeln
* AND posnr = wa_vbap-posnr.
* CONTINUE.
* ENDIF.
* break: xh003.
*售达方
* SELECT SINGLE kunnr adrnr
* INTO (wa_vbap-kunnr , wa_vbap-adrnr)
* FROM vbpa
* WHERE vbeln = wa_vbap-vbeln
** AND posnr = wa_vbap-posnr
* AND parvw = 'AG'.
* IF NOT wa_vbap-adrnr IS INITIAL.
* SELECT SINGLE name1 INTO wa_vbap-name4
* FROM adrc
* WHERE addrnumber = wa_vbap-adrnr.
* ENDIF.
READ TABLE lt_name WITH KEY vbeln = wa_vbap-vbeln parvw = 'AG' BINARY SEARCH.
IF sy-subrc = 0.
wa_vbap
-name4 = lt_name-name.
ENDIF.
*送达方
* SELECT SINGLE kunnr adrnr
* INTO (wa_vbap-kunnr_s , wa_vbap-adrnr)
* FROM vbpa
* WHERE vbeln = wa_vbap-vbeln
** AND posnr = wa_vbap-posnr
* AND parvw = 'WE'
* .
* IF NOT wa_vbap-adrnr IS INITIAL.
* SELECT SINGLE name1 INTO wa_vbap-name5
* FROM adrc
* WHERE addrnumber = wa_vbap-adrnr.
* ENDIF.
READ TABLE lt_name WITH KEY vbeln = wa_vbap-vbeln parvw = 'WE' BINARY SEARCH.
IF sy-subrc = 0.
wa_vbap
-name5 = lt_name-name.
ENDIF.
*经办人
* SELECT SINGLE kunnr
* INTO wa_vbap-kunnr_j
* FROM vbpa
* WHERE vbeln = wa_vbap-vbeln
** AND posnr = wa_vbap-posnr
* AND parvw = 'Z1'
* .
* SELECT SINGLE telf1
* INTO wa_vbap-telf1
* FROM kna1 WHERE kunnr = wa_vbap-kunnr.
* STYPE
* CASE wa_vbap-auart.
* WHEN 'ZBV' .
* wa_vbap-stype = '现金自提'.
* WHEN 'ZBV1'.
* wa_vbap-stype = '客户自提'.
* WHEN 'ZOR'.
* IF vbak-augru = 'Z01'.
* wa_vbap-stype = '客户自提'.
* ELSE.
* wa_vbap-stype = '其他 公司配送'.
* ENDIF.
* ENDCASE.
* SELECT SINGLE street
* INTO wa_vbap-street
* FROM adrc
* WHERE addrnumber = wa_vbap-adrnr.
wa_vbap
-kwmeng_j = wa_vbap-umvkz / wa_vbap-umvkn * wa_vbap-kwmeng.
* wa_vbap-netwr_d = wa_vbap-mwsbp + wa_vbap-netwr / wa_vbap-kwmeng.
*单价
* BREAK-POINT.
wa_vbap
-netwr_d = 0.
* IF wa_vbap-taxk1 = '0'.
* wa_vbap-netwr_d = wa_vbap-netpr.
* ELSE.
* CASE wa_vbap-taxm1.
* WHEN '0'.
* wa_vbap-netwr_d = wa_vbap-netpr.
* WHEN '1'.
* wa_vbap-netwr_d = wa_vbap-netpr * '1.04'.
* WHEN '2'.
* wa_vbap-netwr_d = wa_vbap-netpr * '1.13'.
* WHEN '3'.
* wa_vbap-netwr_d = wa_vbap-netpr * '1.17'.
* ENDCASE.
* ENDIF.
wa_vbap
-netwr_d = wa_vbap-umvkn * ( wa_vbap-netwr + wa_vbap-mwsbp ) / ( wa_vbap-kwmeng * wa_vbap-umvkz ).
* BREAK-POINT.
wa_vbap
-netwr_s = ( wa_vbap-netwr + wa_vbap-mwsbp ) / wa_vbap-kwmeng .
wa_vbap
-netwr = wa_vbap-mwsbp + wa_vbap-netwr.
* SELECT SINGLE name1 "工厂描述'
* INTO wa_vbap-name1
* FROM t001w WHERE werks = wa_vbap-werks.
READ TABLE lt_werks WITH KEY werks = wa_vbap-werks BINARY SEARCH.
IF sy-subrc = 0.
wa_vbap
-name1 = lt_werks-name1.
ENDIF.
* SELECT SINGLE lgobe
* INTO wa_vbap-name2
* FROM t001l WHERE werks = wa_vbap-werks AND lgort = wa_vbap-lgort."仓库描述'
READ TABLE lt_lgort WITH KEY werks = wa_vbap-werks lgort = wa_vbap-lgort BINARY SEARCH.
IF sy-subrc = 0.
wa_vbap
-name2 = lt_lgort-lgobe.
ENDIF.
* DATA : BEGIN OF lt_vstel OCCURS 0,
* vstel LIKE tvstt-vstel,
* vtext LIKE tvstt-vtext,
* END OF lt_vstel.
*
* SELECT SINGLE vtext
* INTO wa_vbap-name3
* FROM tvstt WHERE spras = 1
* AND vstel = wa_vbap-vstel."装运点描述' 8 'GT_VBAP'.
READ TABLE lt_vstel WITH KEY vstel = wa_vbap-vstel BINARY SEARCH.
IF sy-subrc = 0.
wa_vbap
-name3 = lt_vstel-vtext.
ENDIF.
*办事处
* DATA : BEGIN OF lt_tvgrt OCCURS 0,
* vkgrp LIKE tvgrt-vkgrp,
* bezei LIKE tvgrt-bezei,
* END OF lt_tvgrt.
*
* SELECT SINGLE bezei
* INTO wa_vbap-name7
* FROM tvgrt
* WHERE vkgrp = wa_vbap-vkgrp
* AND spras = 1.
READ TABLE lt_tvgrt WITH KEY vkgrp = wa_vbap-vkgrp BINARY SEARCH.
IF sy-subrc = 0.
wa_vbap
-name7 = lt_tvgrt-bezei.
ENDIF.
*定价日期
* DATA : BEGIN OF lt_vbkd OCCURS 0,
* vbeln LIKE vbkd-vbeln,
* posnr LIKE vbkd-posnr,
* prsdt LIKE vbkd-prsdt,
* bstkd LIKE vbkd-bstkd,
* END OF lt_vbkd.
*
* SELECT SINGLE prsdt bstkd
* INTO (wa_vbap-prsdt,wa_vbak-bstkd)
* FROM vbkd
* WHERE vbeln = wa_vbap-vbeln
* AND ( posnr = wa_vbap-posnr "行
* OR posnr = '000000' ). "抬头
* READ TABLE lt_vbkd WITH KEY vbeln = wa_vbap-vbeln posnr = wa_vbap-posnr BINARY SEARCH.
* IF sy-subrc = 0.
* wa_vbap-prsdt = lt_vbkd-prsdt.
* ENDIF.
READ TABLE lt_vbkd WITH KEY vbeln = wa_vbap-vbeln posnr = '000000' BINARY SEARCH.
IF sy-subrc = 0.
wa_vbap
-bstkd = lt_vbkd-bstkd.
ENDIF.
*工艺描述
DATA : BEGIN OF lt_line_txt OCCURS 0,
vbeln
LIKE vbap-vbeln,
posnr
LIKE vbap-posnr,
txt
(100),
END OF lt_line_txt.
*---------------取抬头--------------------------------------
DATA : ls_tdname LIKE rstxt-tdname.
DATA : lt_lines LIKE TABLE OF tline WITH HEADER LINE.
"$ Region add by zhouliangliang on 2010.11.29
CLEAR: lt_lines[].
"$ Endregion add by zhouliangliang on 2010.11.29
CONCATENATE wa_vbap-vbeln wa_vbap-posnr INTO ls_tdname .
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = '0001'
language = '1'
name
= ls_tdname
object
= 'VBBP'
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name
= 3
not_found
= 4
object
= 5
reference_check
= 6
wrong_access_to_archive
= 7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_lines.
CONCATENATE wa_vbap-txt_posnr lt_lines-tdline INTO wa_vbap-txt_posnr.
ENDLOOP.
MODIFY gt_vbap FROM wa_vbap.
*添加到表头
CLEAR : wa_vbak.
wa_vbak
-vbeln = wa_vbap-vbeln."'订单号' 8 'GT_VBAK'.
wa_vbak
-kunnr = wa_vbap-kunnr ."售达方' 10 'GT_VBAK'.
wa_vbak
-name4 = wa_vbap-name4."送达方' 10 'GT_VBAK'.
wa_vbak
-kunnr_s = wa_vbap-kunnr_s."送达方' 10 'GT_VBAK'.
wa_vbak
-name5 = wa_vbap-name5."送达方' 10 'GT_VBAK'.
wa_vbak
-kunnr_j = wa_vbap-kunnr_j."经办人' 10 'GT_VBAK'.
wa_vbak
-vkbur = wa_vbap-vkbur."销售大区' 10 'GT_VBAK'.
wa_vbak
-vkgrp = wa_vbap-vkgrp."办事处' 10 'GT_VBAK'.
wa_vbak
-name7 = wa_vbap-name7."办事处' 10 'GT_VBAK'
wa_vbak
-bzirk_txt = wa_vbap-bzirk_txt."办事处' 10 'GT_VBAK'
.
wa_vbak
-telf1 = wa_vbap-telf1."客户联系方式' 10 'VBAK'.
wa_vbak
-erdat = wa_vbap-erdat."订单日期' 10 'GT_VBAK'.
wa_vbak
-erzet = wa_vbap-erzet."订单时间' 10 'GT_VBAK'.
wa_vbak
-auart = wa_vbap-auart."订单类型' 10 'GT_VBAK'.
wa_vbak
-bezei = wa_vbap-bezei.
wa_vbak
-street = wa_vbap-street."配送地址' 10 'GT_VBAK'.
* wa_vbak-edatu = wa_vbap-edatu."到货日期' 10 'GT_VBAK'.
* wa_vbak-ezeit = wa_vbap-ezeit."到货时间' 10 'GT_VBAK'.
IF wa_vbap-datbi < sy-datum. "如果交货时间小于当天就置换为当天
wa_vbap
-datbi = sy-datum.
ENDIF.
IF wa_vbak-datbi < wa_vbap-datbi.
wa_vbak
-datbi = wa_vbap-datbi.
ENDIF.
"wa_vbak-datbi = wa_vbap-datbi.
wa_vbak
-bstkd = wa_vbap-bstkd.
"--抬头文本
DATA: ls_hdname LIKE rstxt-tdname.
CLEAR: lt_lines[] .
ls_hdname
= wa_vbak-vbeln .
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = '0001'
language = '1'
name
= ls_hdname
object
= 'VBBK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name
= 3
not_found
= 4
object
= 5
reference_check
= 6
wrong_access_to_archive
= 7
OTHERS = 8.
IF sy-subrc = 0.
READ TABLE lt_lines INDEX 1 .
wa_vbak
-hdtxt = lt_lines-tdline .
CLEAR lt_lines[].
ENDIF.
wa_vbak
-knumv = wa_vbap-knumv.
*---------
* DATA : BEGIN OF lt_tvkbt OCCURS 0,
* vkbur LIKE tvkbt-vkbur,
* bezei LIKE tvkbt-bezei,
* END OF lt_tvkbt.
*
* SELECT SINGLE bezei
* INTO wa_vbak-vkbur_text
* FROM tvkbt
* WHERE spras = 1
* AND vkbur = wa_vbak-vkbur.
READ TABLE lt_tvkbt WITH KEY vkbur = wa_vbak-vkbur BINARY SEARCH.
IF sy-subrc = 0.
wa_vbak
-vkbur_text = lt_tvkbt-bezei.
ENDIF.
*--------
* data : BEGIN OF lt_cmgst OCCURS 0,
* vbeln like vbuk-vbeln,
* cmgst like vbuk-cmgst,
* end of lt_cmgst.
* SELECT SINGLE cmgst
* INTO wa_vbak-cmgst
* FROM vbuk
* WHERE vbeln = wa_vbak-vbeln
* .
READ TABLE lt_cmgst WITH KEY vbeln = wa_vbak-vbeln BINARY SEARCH.
IF sy-subrc = 0.
CASE lt_cmgst-cmgst.
WHEN ''.
wa_vbak
-cmgst_text = '未执行'.
WHEN 'A'.
wa_vbak
-cmgst_text = '通过'.
WHEN 'B'.
wa_vbak
-cmgst_text = '不通过'.
WHEN 'C'.
wa_vbak
-cmgst_text = '部分通过'.
WHEN 'D'.
wa_vbak
-cmgst_text = '批准后通过'.
ENDCASE.
ENDIF.
COLLECT wa_vbak INTO gt_vbak.
ENDLOOP.
*信贷余额
DATA : l_waerk LIKE vbak-waerk,
l_skfor
LIKE knkk-skfor,
l_oeikw
LIKE s066-oeikw,
l_olikw
LIKE s067-olikw,
l_ofakw
LIKE s067-ofakw.
DATA : BEGIN OF lt_waerk OCCURS 0,
vbeln
LIKE vbak-vbeln,
kunnr
LIKE vbak-kunnr,
waerk
LIKE vbak-waerk,
END OF lt_waerk.
IF NOT gt_vbak[] IS INITIAL.
SELECT vbeln kunnr waerk
INTO TABLE lt_waerk
FROM vbak
FOR ALL ENTRIES IN gt_vbak
WHERE vbeln = gt_vbak-vbeln.
SORT lt_waerk BY vbeln.
DATA : BEGIN OF lt_knkk OCCURS 0,
kunnr
LIKE knkk-kunnr,
klimk
LIKE knkk-klimk,
skfor
LIKE knkk-skfor,
END OF lt_knkk.
DATA : lt_knkk_tmp LIKE TABLE OF lt_knkk WITH HEADER LINE .
SELECT kunnr a~klimk skfor
INTO TABLE lt_knkk_tmp
FROM knkk AS a
INNER
JOIN t014 AS b ON a~kkber = b~kkber
FOR ALL ENTRIES IN lt_waerk
WHERE kunnr = lt_waerk-kunnr AND a~kkber = '1000' AND waers = lt_waerk-waerk
.
SORT lt_knkk_tmp BY kunnr ASCENDING.
CLEAR : lt_knkk,lt_knkk[].
LOOP AT lt_knkk_tmp.
MOVE-CORRESPONDING lt_knkk_tmp TO lt_knkk.
COLLECT lt_knkk.
ENDLOOP.
SORT lt_knkk BY kunnr ASCENDING.
DATA : BEGIN OF lt_s066 OCCURS 0,
kunnr
LIKE s066-knkli,
oeikw
LIKE s066-oeikw,
END OF lt_s066.
DATA : lt_s066_tmp LIKE TABLE OF lt_s066 WITH HEADER LINE .
SELECT knkli AS kunnr oeikw
INTO TABLE lt_s066_tmp
FROM s066
FOR ALL ENTRIES IN lt_waerk
WHERE knkli = lt_waerk-kunnr AND kkber = '1000' AND cmwae = lt_waerk-waerk
.
CLEAR : lt_s066,lt_s066[].
LOOP AT lt_s066_tmp.
MOVE-CORRESPONDING lt_s066_tmp TO lt_s066.
COLLECT lt_s066.
ENDLOOP.
DATA : BEGIN OF lt_s067 OCCURS 0,
kunnr
LIKE s066-knkli,
olikw
LIKE s067-olikw,
ofakw
LIKE s067-ofakw,
END OF lt_s067.
DATA : lt_s067_tmp LIKE TABLE OF lt_s067 WITH HEADER LINE .
SELECT knkli AS kunnr olikw ofakw
INTO TABLE lt_s067_tmp
FROM s067
FOR ALL ENTRIES IN lt_waerk
WHERE knkli = lt_waerk-kunnr AND kkber = '1000' AND cmwae = lt_waerk-waerk.
CLEAR : lt_s067,lt_s067[].
LOOP AT lt_s067_tmp.
MOVE-CORRESPONDING lt_s067_tmp TO lt_s067.
COLLECT lt_s067.
ENDLOOP.
ENDIF.
LOOP AT gt_vbak INTO wa_vbak.
** KNKK-KLIMK – ( KNKK-SKFOR + S067-OLIKW + S067-OFAKW + SUM(S066-OEIKW) )
* SELECT SINGLE waerk
* INTO l_waerk
* FROM vbak WHERE vbeln = wa_vbak-vbeln.
*--取折扣总额
LOOP AT git_konv.
IF wa_vbak-knumv = git_konv-knumv.
wa_vbak
-zh_kwert = wa_vbak-zh_kwert + git_konv-kwert.
CLEAR git_konv.
ENDIF.
ENDLOOP.
READ TABLE lt_tvakt WITH KEY auart = wa_vbak-auart BINARY SEARCH.
IF sy-subrc = 0.
wa_vbak
-bezei = lt_tvakt-bezei.
ENDIF.
READ TABLE lt_waerk WITH KEY vbeln = wa_vbak-vbeln BINARY SEARCH.
IF sy-subrc = 0.
* KNKK-KLIMK – ( KNKK-SKFOR + S067-OLIKW + S067-OFAKW + SUM(S066-OEIKW) )
* DATA : BEGIN OF lt_knkk OCCURS 0,
* kunnr LIKE knkk-kunnr,
* klimk LIKE knkk-klimk,
* skfor LIKE knkk-skfor,
* END OF lt_knkk.
*
* SELECT SUM( a~klimk ) SUM( skfor )
* INTO (wa_vbak-klimk,l_skfor)
* FROM knkk AS a
* INNER JOIN t014 AS b ON a~kkber = b~kkber
* WHERE kunnr = wa_vbak-kunnr AND a~kkber = '1000' AND waers = l_waerk.
READ TABLE lt_knkk WITH KEY kunnr = lt_waerk-kunnr BINARY SEARCH.
IF sy-subrc = 0.
wa_vbak
-klimk = lt_knkk-klimk.
l_skfor
= lt_knkk-skfor.
ELSE.
CLEAR: wa_vbak-klimk,l_skfor.
ENDIF.
* DATA : BEGIN OF lt_s066 OCCURS 0,
* kunnr LIKE s066-knkli,
* oeikw LIKE s066-oeikw,
* END OF lt_s066.
*
* SELECT SUM( oeikw )
* INTO l_oeikw
* FROM s066 WHERE knkli = wa_vbak-kunnr AND kkber = '1000' AND cmwae = l_waerk.
READ TABLE lt_s066 WITH KEY kunnr = wa_vbak-kunnr BINARY SEARCH.
IF sy-subrc = 0.
l_oeikw
= lt_s066-oeikw.
ELSE.
CLEAR: l_oeikw.
ENDIF.
* SELECT SUM( olikw ) SUM( ofakw )
* INTO (l_olikw,l_ofakw)
* FROM s067 WHERE knkli = wa_vbak-kunnr AND kkber = '1000' AND cmwae = l_waerk.
READ TABLE lt_s067 WITH KEY kunnr = wa_vbak-kunnr BINARY SEARCH.
IF sy-subrc = 0.
l_olikw
= lt_s067-olikw.
l_ofakw
= lt_s067-ofakw.
ELSE.
CLEAR: l_olikw,l_ofakw.
ENDIF.
wa_vbak
-klimk = wa_vbak-klimk - ( l_skfor + l_olikw + l_ofakw + l_oeikw ).
ENDIF.
*审批文本
DATA : anw_stat_existing TYPE xfeld,
e_stsma
LIKE jsto-stsma,
line LIKE bsvx-sttxt,
user_line
LIKE bsvx-sttxt,
stonr
LIKE tj30-stonr.
DATA : objnr LIKE jest-objnr.
CLEAR : objnr.
CONCATENATE 'VB' wa_vbak-vbeln '000000' INTO objnr.
*VB0010000005000000
CALL FUNCTION 'STATUS_TEXT_EDIT'
EXPORTING
client = sy-mandt
flg_user_stat
= 'X'
objnr
= objnr
spras
= '1'
IMPORTING
anw_stat_existing
= anw_stat_existing
e_stsma
= e_stsma
line = line
user_line
= user_line
stonr
= stonr
EXCEPTIONS
object_not_found
= 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
SELECT SINGLE txt30
INTO wa_vbak-txt30
FROM tj30t
WHERE stsma = e_stsma
AND spras = '1'
AND txt04 = user_line.
ENDIF.
MODIFY gt_vbak FROM wa_vbak.
ENDLOOP.
ENDFORM. " FRM_READ_VBAP
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata
-program = program.
bdcdata
-dynpro = dynpro.
bdcdata
-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "BDC_DYNPRO
*********************************************
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata
-fnam = fnam.
bdcdata
-fval = fval.
APPEND bdcdata.
ENDFORM. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form CALL_TRANSACTION_form
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM call_transaction_form USING tcode.
DATA : ls_message_text_output(255).
CLEAR : gt_msg,gt_msg[].
CALL TRANSACTION tcode
USING bdcdata
MODE 'E' "错误时弹出屏幕
UPDATE 'S'
MESSAGES
INTO gt_msg.
break
:xh003.
READ TABLE gt_msg WITH KEY msgtyp = 'S' msgnr = '100'.
IF sy-subrc = 0.
CLEAR : ls_message_text_output.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= gt_msg-msgid
msgnr
= gt_msg-msgnr
msgv1
= gt_msg-msgv1
msgv2
= gt_msg-msgv2
msgv3
= gt_msg-msgv3
msgv4
= gt_msg-msgv4
IMPORTING
message_text_output
= ls_message_text_output.
* MESSAGE ls_message_text_output TYPE 'S'.
ELSE.
LOOP AT gt_msg.
CLEAR : ls_message_text_output.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= gt_msg-msgid
msgnr
= gt_msg-msgnr
msgv1
= gt_msg-msgv1
msgv2
= gt_msg-msgv2
msgv3
= gt_msg-msgv3
msgv4
= gt_msg-msgv4
IMPORTING
message_text_output
= ls_message_text_output.
MESSAGE ls_message_text_output TYPE 'W'.
ENDLOOP.
ENDIF.
CLEAR bdcdata.CLEAR bdcdata[].
ENDFORM. "CALL_TRANSACTION_form
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_DATA_D
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_display_data_d .
gs_layout
-box_fieldname = 'CK'.
gs_layout
-box_tabname = 'gt_vbap_sel'.
gs_layout
-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_callback_pf_status_set
= 'SET_STATUS'
i_callback_user_command
= 'USER_COMMAND'
is_layout
= gs_layout
it_fieldcat
= gt_fieldcat_d[]
i_save
= 'A'
TABLES
t_outtab
= gt_vbap_sel[]
EXCEPTIONS
program_error
= 1
OTHERS = 2.
ENDFORM. " FRM_DISPLAY_DATA_D
*&---------------------------------------------------------------------*
*& Form FRM_READ_ZTSD003
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_read_ztsd003 .
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_ztsd003
FROM ztsd024
WHERE vbeln_vl IN p_vl_s
AND vbeln IN p_vbn_s
AND erdat IN p_erdat
AND ernam IN p_ernam.
LOOP AT gt_ztsd003 INTO wa_ztsd003.
* SO INFO
SELECT SINGLE auart kunnr erdat erzet vkgrp
INTO (wa_ztsd003-auart , wa_ztsd003-kunnr,
wa_ztsd003
-erdat_c , wa_ztsd003-erzet_c,
wa_ztsd003
-vkgrp)
FROM vbak WHERE vbeln = wa_ztsd003-vbeln
.
IF sy-subrc <> 0.
DELETE gt_ztsd003 .
CONTINUE.
ENDIF.
SELECT SINGLE bezei
INTO wa_ztsd003-bezei
FROM tvakt
WHERE auart = wa_ztsd003-auart
AND spras = '1'
.
*售达方
SELECT SINGLE kunnr adrnr
INTO (wa_ztsd003-kunnr , wa_ztsd003-adrnr)
FROM vbpa
WHERE vbeln = wa_ztsd003-vbeln
AND posnr = '000000'
AND parvw = 'AG'.
IF NOT wa_ztsd003-adrnr IS INITIAL.
SELECT SINGLE name1 INTO wa_ztsd003-name4
FROM adrc
WHERE addrnumber = wa_ztsd003-adrnr.
ENDIF.
*送达方
SELECT SINGLE kunnr adrnr
INTO (wa_ztsd003-kunnr_s , wa_ztsd003-adrnr)
FROM vbpa
WHERE vbeln = wa_ztsd003-vbeln
AND posnr = '000000'
AND parvw = 'WE'
.
IF NOT wa_ztsd003-adrnr IS INITIAL.
SELECT SINGLE name1 INTO wa_ztsd003-name5
FROM adrc
WHERE addrnumber = wa_ztsd003-adrnr.
ENDIF.
*办事处
SELECT SINGLE bezei
INTO wa_ztsd003-name7
FROM tvgrt
WHERE vkgrp = wa_ztsd003-vkgrp
AND spras = 1.
* user name
SELECT SINGLE name_text
INTO wa_ztsd003-name_text
FROM v_username
WHERE bname = wa_ztsd003-ernam.
CLEAR : wa_ztsd003-posnr,wa_ztsd003-posnr_vl.
MODIFY gt_ztsd003 FROM wa_ztsd003.
ENDLOOP.
SORT gt_ztsd003 BY erdat DESCENDING
erzet
DESCENDING
ernam
DESCENDING
vbeln_vl
DESCENDING
posnr_vl
ASCENDING
.
DELETE ADJACENT DUPLICATES FROM gt_ztsd003.
DATA : l_vkorg LIKE vbak-vkorg.
break
: xh003.
DATA : l_spart_vbak LIKE vbak-spart,
l_spart_vbap
LIKE vbap-spart.
LOOP AT gt_ztsd003 INTO wa_ztsd003.
CLEAR : l_vkorg.
SELECT SINGLE vkorg a~spart b~spart
INTO (l_vkorg,l_spart_vbak,l_spart_vbap)
FROM vbak AS a
INNER
JOIN vbap AS b
ON a~vbeln = b~vbeln
WHERE a~vbeln = wa_ztsd003-vbeln
AND a~vkorg IN vkorg
AND a~vtweg IN vtweg
"AND a~spart IN spart
"AND b~spart IN spart2
AND werks IN werks
AND vkbur IN vkbur
AND vkgrp IN vkgrp
.
IF l_vkorg IS INITIAL.
DELETE gt_ztsd003.
ELSE.
AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
ID 'VKORG' DUMMY
ID 'VTWEG' DUMMY
ID 'SPART' FIELD l_spart_vbap
ID 'ACTVT' DUMMY.
IF sy-subrc <> 0. "抬头
DELETE gt_ztsd003.
ENDIF.
ENDIF.
ENDLOOP.
break
:xh003.
ENDFORM. " FRM_READ_ZTSD003
*&---------------------------------------------------------------------*
*& Form frm_build_fieldcat_s
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_build_fieldcat_s .
CLEAR : gt_fieldcat_s,gt_fieldcat_s[].
DEFINE alv_head.
clear gt_fieldcat_s.
if &1 = 'CK'.
gt_fieldcat_s
-checkbox = 'X'.
gt_fieldcat_s
-edit = 'X'.
else.
gt_fieldcat_s
-edit = ''.
endif.
if &1 = 'VBELN_VL' or &1 = 'VBELN'.
gt_fieldcat_s
-hotspot = 'X'.
endif.
gt_fieldcat_s
-fieldname = &1.
gt_fieldcat_s
-tabname = &4.
gt_fieldcat_s
-seltext_s = &2 .
gt_fieldcat_s
-seltext_m = &2 .
gt_fieldcat_s
-seltext_l = &2 .
gt_fieldcat_s
-outputlen = &3.
gt_fieldcat_s
-just = &5.
gt_fieldcat
-key = &6.
gt_fieldcat_s
-no_zero = 'X'.
* gt_fieldcat-decimals_out = 2.
if &1 = 'DATBI'.
gt_fieldcat_s
-edit = 'X'.
endif.
append gt_fieldcat_s.
END-OF-DEFINITION.
alv_head
'CK' 'SEL' 4 'GT_ZTSD003' 'L' ''.
alv_head
'VBELN_VL' '交货单' 8 'GT_ZTSD003' 'L' ''.
* alv_head 'POSNR_VL' '交货单行项目' 8 'GT_ZTSD003' 'L'.
alv_head
'VBELN' '销售单' 8 'GT_ZTSD003' 'L' ''.
* alv_head 'POSNR' '行项目' 6 'GT_ZTSD003' 'L' ''.
alv_head
'NAME4' '售达方名称' 16 'GT_VBAK' 'L' ''.
* alv_head 'KUNNR_S' '送达方' 10 'GT_VBAK'.
alv_head
'NAME5' '送达方名称' 16 'GT_VBAK' 'L' ''.
* alv_head 'KUNNR_J' '经办人' 10 'GT_VBAK'.
* alv_head 'VKBUR' '销售大区' 10 'GT_VBAK'.
* alv_head 'VKGRP' '办事处' 10 'GT_VBAK'.
alv_head
'NAME7' '办事处' 10 'GT_VBAK' 'L' ''.
* alv_head 'TELF1' '客户联系方式' 10 'GT_VBAK'.
alv_head
'ERDAT_C' '订单日期' 10 'GT_VBAK' 'L' ''.
alv_head
'ERZET_C' '订单时间' 8 'GT_VBAK' 'L' ''.
* alv_head 'AUART' '订单类型' 10 'GT_VBAK' 'L'.
alv_head
'BEZEI' '订单描述' 8 'GT_VBAK' 'L' ''.
alv_head
'ERDAT' '转交日期' 10 'GT_ZTSD003' 'L' ''.
alv_head
'ERZET' '转交时间' 8 'GT_ZTSD003' 'L' ''.
* alv_head 'ERNAM' '审核人' 10 'GT_ZTSD003' 'L'.
alv_head
'NAME_TEXT' '转交操作员' 10 'GT_ZTSD003' 'L' ''.
ENDFORM. " frm_build_fieldcat
*&---------------------------------------------------------------------*
*& Form frm_display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_display_data_s .
gs_layout
-box_fieldname = 'CK'.
gs_layout
-box_tabname = 'GT_ZTSD003'.
gs_layout
-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_callback_pf_status_set
= 'SET_STATUS_S'
i_callback_user_command
= 'USER_COMMAND_S'
is_layout
= gs_layout
it_fieldcat
= gt_fieldcat_s[]
i_save
= 'A'
TABLES
t_outtab
= gt_ztsd003[]
EXCEPTIONS
program_error
= 1
OTHERS = 2.
ENDFORM. " frm_display_data
*&---------------------------------------------------------------------*
*& Form user_command_S
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RF_UCOMM text
* -->RS text
*----------------------------------------------------------------------*
FORM user_command_s USING rf_ucomm LIKE sy-ucomm
rs
TYPE slis_selfield.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
DATA : ls_mkpf TYPE emkpf,
lt_mesg
TYPE TABLE OF mesg.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid
= lr_grid.
CALL METHOD lr_grid->check_changed_data.
rs
-refresh = 'X'.
CASE rf_ucomm.
WHEN '&IC1'.
break
: xh003.
CASE rs-fieldname.
WHEN 'VBELN_VL'.
SET PARAMETER ID 'VL' FIELD rs-value.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
WHEN 'VBELN'.
SET PARAMETER ID 'AUN' FIELD rs-value.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDCASE.
WHEN '&VL09'. " 冲销
AUTHORITY-CHECK OBJECT 'Z_SD_DNDEL'
ID 'ACTVT' FIELD '06'.
IF sy-subrc <> 0.
MESSAGE '权限不足,不能删除!' TYPE 'E'.
ENDIF.
DATA : l_vbeln_vl TYPE vbeln_vl.
* BREAK-POINT.
CLEAR : bdcdata[],bdcdata.
LOOP AT gt_ztsd003 INTO wa_ztsd003 WHERE ck = 'X'..
*冲销
* CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
* EXPORTING
* i_vbeln = wa_ztsd003-vbeln_vl
* i_budat = sy-datum
* i_vbtyp = 'J'
* IMPORTING
* es_emkpf = ls_mkpf
* TABLES
* t_mesg = lt_mesg
* EXCEPTIONS
* error_reverse_goods_issue = 1
* OTHERS = 2.
* IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* ENDIF.
*删除
PERFORM bdc_dynpro USING 'SAPMV50A' '4004'.
PERFORM bdc_field USING 'BDC_CURSOR' 'LIKP-VBELN'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM bdc_field USING 'LIKP-VBELN' wa_ztsd003-vbeln_vl.
PERFORM bdc_dynpro USING 'SAPMV50A' '1000'.
PERFORM bdc_field USING 'BDC_OKCODE' '/ELOES_T'.
PERFORM call_transaction_form_vl02n USING 'VL02N' ."CHANGING l_vbeln_vl.
ENDLOOP.
ENDCASE.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid
= lr_grid.
CALL METHOD lr_grid->check_changed_data.
rs
-refresh = 'X'.
ENDFORM. "user_command_S
*&---------------------------------------------------------------------*
*& Form set_status_s
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM set_status_s USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD_S' EXCLUDING rt_extab .
ENDFORM. "set_status
*&---------------------------------------------------------------------*
*& Form call_transaction_form_vl01n
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->TCODE text
*----------------------------------------------------------------------*
FORM call_transaction_form_vl01n USING tcode CHANGING p_delivery LIKE likp-vbeln.
DATA : ls_message_text_output(255).
CLEAR : gt_msg,gt_msg[].
DATA: l_mode.
l_mode
= 'E'. "错误时弹出屏幕
CALL TRANSACTION tcode
USING bdcdata
MODE l_mode "错误时弹出屏幕
UPDATE 'S'
MESSAGES
INTO gt_msg.
break
:xh003.
READ TABLE gt_msg WITH KEY msgtyp = 'S' msgnr = '311'.
IF sy-subrc = 0.
CLEAR : ls_message_text_output.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= gt_msg-msgid
msgnr
= gt_msg-msgnr
msgv1
= gt_msg-msgv1
msgv2
= gt_msg-msgv2
msgv3
= gt_msg-msgv3
msgv4
= gt_msg-msgv4
IMPORTING
message_text_output
= ls_message_text_output.
p_delivery
= gt_msg-msgv2.
MESSAGE ls_message_text_output TYPE 'S'.
ELSE.
LOOP AT gt_msg.
CLEAR : ls_message_text_output.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= gt_msg-msgid
msgnr
= gt_msg-msgnr
msgv1
= gt_msg-msgv1
msgv2
= gt_msg-msgv2
msgv3
= gt_msg-msgv3
msgv4
= gt_msg-msgv4
IMPORTING
message_text_output
= ls_message_text_output.
MESSAGE ls_message_text_output TYPE 'W'.
ENDLOOP.
ENDIF.
CLEAR bdcdata.CLEAR bdcdata[].
ENDFORM. "CALL_TRANSACTION_form
*&---------------------------------------------------------------------*
*& Form call_transaction_form_vl02n
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->TCODE text
*----------------------------------------------------------------------*
FORM call_transaction_form_vl02n USING tcode.
DATA : ls_message_text_output(255).
CLEAR : gt_msg,gt_msg[].
CALL TRANSACTION tcode
USING bdcdata
MODE 'E' "错误时弹出屏幕
UPDATE 'S'
MESSAGES
INTO gt_msg.
break
:xh003.
READ TABLE gt_msg WITH KEY msgtyp = 'S' msgnr = '310'.
IF sy-subrc = 0.
*删除记录表
DELETE FROM ztsd024 WHERE vbeln_vl = wa_ztsd003-vbeln_vl.
COMMIT WORK.
DELETE gt_ztsd003 WHERE vbeln_vl = wa_ztsd003-vbeln_vl. .
CLEAR : ls_message_text_output.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= gt_msg-msgid
msgnr
= gt_msg-msgnr
msgv1
= gt_msg-msgv1
msgv2
= gt_msg-msgv2
msgv3
= gt_msg-msgv3
msgv4
= gt_msg-msgv4
IMPORTING
message_text_output
= ls_message_text_output.
* MESSAGE ls_message_text_output TYPE 'S'.
ELSE.
LOOP AT gt_msg.
CLEAR : ls_message_text_output.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= gt_msg-msgid
msgnr
= gt_msg-msgnr
msgv1
= gt_msg-msgv1
msgv2
= gt_msg-msgv2
msgv3
= gt_msg-msgv3
msgv4
= gt_msg-msgv4
IMPORTING
message_text_output
= ls_message_text_output.
MESSAGE ls_message_text_output TYPE 'W'.
ENDLOOP.
ENDIF.
CLEAR bdcdata.CLEAR bdcdata[].
ENDFORM. "CALL_TRANSACTION_form
INITIALIZATION.
AT SELECTION-SCREEN.
DATA : l_where(20).
RANGES : lt_werks FOR marc-werks ,
lt_vkorg
FOR vbak-vkorg .
* lt_spart FOR vbak-spart.
CLEAR : lt_werks,lt_werks[],lt_vkorg,lt_vkorg[].
IF vkorg[] IS INITIAL AND werks[] IS INITIAL.
MESSAGE '销售组织和工厂必须选取一项!' TYPE 'E'.
ENDIF.
*工厂
SELECT werks AS low
INTO CORRESPONDING FIELDS OF TABLE lt_werks
FROM t001w
WHERE werks IN werks.
*销售组织
SELECT vkorg AS low
INTO CORRESPONDING FIELDS OF TABLE lt_vkorg
FROM tvko
WHERE vkorg IN vkorg.
*工厂
* IF NOT werks[] IS INITIAL.
* LOOP AT lt_werks.
* AUTHORITY-CHECK OBJECT 'Z_SD_WERKS'
* ID 'WERKS' FIELD lt_werks-low.
* IF sy-subrc <> 0.
* CLEAR : l_where.
* CONCATENATE '工厂:' lt_werks-low ',访问权限不足!' INTO l_where.
* MESSAGE l_where TYPE 'E'.
* ENDIF.
* ENDLOOP.
* ENDIF.
IF NOT vkorg[] IS INITIAL .
LOOP AT lt_vkorg.
AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
ID 'VKORG' FIELD lt_vkorg-low
ID 'VTWEG' DUMMY
ID 'SPART' DUMMY
ID 'ACTVT' DUMMY.
IF sy-subrc <> 0.
CLEAR : l_where.
CONCATENATE '销售组织:' lt_vkorg-low ',访问权限不足!' INTO l_where.
MESSAGE l_where TYPE 'E'.
ENDIF.
ENDLOOP.
ENDIF.
START-OF-SELECTION.
*产品组(抬头)
SELECT spart AS low
INTO CORRESPONDING FIELDS OF TABLE lt_spart
FROM tspa.
"WHERE spart IN spart.
*产品组(抬头)
SELECT spart AS low
INTO CORRESPONDING FIELDS OF TABLE lt_spart2
FROM tspa.
"WHERE spart IN spart2.
IF ck_audit = ''.
*读取数据
PERFORM frm_read_vbap.
*ALV显示
IF NOT gt_vbak[] IS INITIAL.
PERFORM frm_build_fieldcat .
PERFORM frm_display_data.
ENDIF.
ELSE. "审核
PERFORM frm_read_ztsd003.
IF NOT gt_ztsd003[] IS INITIAL.
PERFORM frm_build_fieldcat_s .
PERFORM frm_display_data_s.
ENDIF.
ENDIF.