*&---------------------------------------------------------------------*
*& Report ZSDR006
*&
*&---------------------------------------------------------------------*
*&程序名称:
*&事物代码
*&导入模板:
*&作者
*&时间
*&---------------------------------------------------------------------*
REPORT zsdr006_1 MESSAGE-ID 00.
TYPE-POOLS:ole2,slis,icon.
FIELD-SYMBOLS: <fs>.
TABLES: sscrfields,ztsd014,ztsd015,mchb,t001l.
TYPES: BEGIN OF ty_output,
sel TYPE c,
batno TYPE ztsd015-batno, "批导序号
batpo TYPE ztsd015-batpo, "验单批导序号
verno TYPE ztsd016-verno, "版本号
indat TYPE ztsd015-indat, "日期
* KUNNR TYPE KUNNR, "客户号
* NAME1 TYPE KNA1-NAME1, "客户名称
lgort TYPE lgort_d, "库存地点
lgobe TYPE lgobe, "库存地点描述
matnr TYPE ztsd015-matnr, "物料号
maktx TYPE makt-maktx, "物料描述
menge TYPE ztsd015-menge, "退货数量
meins TYPE meins, "数量单位
zsl1 TYPE menge_d,
zdw1 TYPE meins,
* CHARG TYPE CHARG_D, "批次
* ZYDJG TYPE ZTSD009-ZYDJG, "验单价格
* ZYDDH TYPE ZTSD009-ZYDDH, "验单单号
zthdd TYPE ztsd016-zthdd, "退货订单
zthdn TYPE likp-vbeln, "退货发货单号
zmfck TYPE ztsd016-zmfck, "免费出库订单
zdn TYPE ztsd015-zdn, "免费出库交货单
zstat TYPE ztsd015-zstat, "退货已过帐
ztext TYPE char10, "状态描述
zicon1 TYPE char4, "导入状态
* VKBUR TYPE VKBUR, "销售部门
* BEZEI TYPE TVKBT-BEZEI, "销售部门描述
shpto TYPE kunnr, "送达方
name2 TYPE kna1-name1,
sldto TYPE kunnr, "售达方
name3 TYPE kna1-name1,
zyddh(35), "验单单号
zthlx TYPE zthlx, "退货类型
zthms TYPE char4, "退货类型描述
augru TYPE augru, "退货原因
zthyy TYPE ztsd015-zthyy, "退货原因
cellcolor TYPE lvc_t_scol, "控制单元格颜色
style TYPE lvc_t_styl, "控制单元格可否编辑
zddjg TYPE kbetr_kond, "订单价格
zddje TYPE kbetr_kond, "总金额
zr TYPE char30, "主任
zywy TYPE char30, "业务员
pstyv TYPE lips-pstyv, "交货项目类型
mssg TYPE bapi_msg, "消息内容
zuser TYPE ztsd014-zuser,
zdate TYPE ztsd014-zdate,
wbstk1 TYPE vbuk-wbstk, "货物移动状态1
fkstk1 TYPE vbuk-fkstk, "开票状态
fkstk2 TYPE vbuk-fkstk, "开票状态
wbstk2 TYPE vbuk-wbstk, "货物移动状态
key TYPE char15,
budat TYPE mkpf-budat,
END OF ty_output.
TYPES: BEGIN OF ty_load,
indat TYPE ztsd015-indat, "日期 1
sldto TYPE kunnr, "售达方 2
shpto TYPE kunnr, "送达方 3
zywy TYPE char30, "业务员 4
zr TYPE char30, "主任 5
zyddh TYPE char35, "退单单号 6
augru TYPE tvau-augru, "退货原因编码 7
lgort TYPE lgort_d, "库存地 点 8
pstyv TYPE lips-pstyv, "交货项目类型 9
matnr TYPE ztsd015-matnr, "物料编码 10
menge TYPE menge_d, "退货数量 11
meins TYPE meins, "数量单位 12
zddjg TYPE kbetr_kond, "订单价格 13
zddje TYPE kbetr_kond, "订单金额 14
budat TYPE mkpf-budat,
END OF ty_load.
TYPES: BEGIN OF ty_sodata,
* ZYDDH TYPE ZTSD009-ZYDDH, "验单单号
zstring TYPE string,
indat TYPE ztsd009-indat,
* KUNNR TYPE KNA1-KUNNR,
shpto TYPE kunnr,
sldto TYPE kunnr,
vkorg TYPE vbak-vkorg, "销售组织
vtweg TYPE vbak-vtweg, "分销渠道
spart TYPE vbak-spart, "产品组
vkgrp TYPE vbak-vkgrp, "销售组
vsbed TYPE knvv-vsbed, "装运条件
augru TYPE tvau-augru, "退货原因编码
vkbur TYPE vbak-vkbur, "销售部门
matnr TYPE ekpo-matnr, "物料代码
lgort TYPE ekpo-lgort, "收货库存地点 8
werks TYPE vbap-werks, "
menge TYPE menge_d, "数量
meins TYPE meins, "单位
charg TYPE charg_d, "批次
* ZDDJG TYPE ZTSD015-ZDDJG, "退货价格
zddje TYPE ztsd015-zddje, "退货价格
batno TYPE ztsd015-batno, "批导序号
batpo TYPE ztsd015-batpo, "批导行项目号
pstyv TYPE lips-pstyv, "交货项目类型
zyddh(35), "验单单号
so TYPE vbak-vbeln, "销售订单号
zdn TYPE likp-vbeln, "交货单号
* SO1 TYPE VBAK-VBELN, "销售订单号
* ZDN1 TYPE LIKP-VBELN, "交货单号
kpein TYPE komv-kpein, "条件定价单位
kmein TYPE komv-kmein, "条件单位
key TYPE char15,
budat TYPE mkpf-budat,
END OF ty_sodata.
TYPES: BEGIN OF typ_header,
ztext(10),
END OF typ_header.
TYPES: BEGIN OF ty_charg,
charg TYPE mchb-charg,
clabs TYPE mchb-clabs,
END OF ty_charg.
TYPES: BEGIN OF ty_dn,
kunnr TYPE kunnr,
matnr TYPE matnr,
lgort TYPE lgort_d,
werks TYPE werks,
charg TYPE charg_d.
TYPES END OF ty_dn.
TYPES: BEGIN OF ty_mesg,
mesg TYPE char255,
END OF ty_mesg.
DATA: BEGIN OF gt_batno OCCURS 0,
batno TYPE zbatno,
batpo TYPE zbatpo,
END OF gt_batno.
DATA: gt_mesg TYPE TABLE OF ty_mesg,
gs_mesg TYPE ty_mesg.
DATA : gt_exclude TYPE ui_functions.
DATA: gs_layout TYPE lvc_s_layo,
gs_cellcolor TYPE lvc_s_scol,
gs_style TYPE lvc_s_styl,
gs_stable TYPE lvc_s_stbl,
gs_variant TYPE disvariant,
gt_structure TYPE lvc_t_fcat,
gs_structure TYPE lvc_s_fcat.
DATA: itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
DATA: gt_load TYPE STANDARD TABLE OF ty_load,
gt_output TYPE TABLE OF ty_output,
gt_sodata TYPE TABLE OF ty_sodata,
gt_charg TYPE TABLE OF ty_charg,
gs_charg TYPE ty_charg,
gt_f4 TYPE lvc_t_f4,
gs_f4 TYPE lvc_s_f4.
DATA: gs_load TYPE ty_load,
gs_output TYPE ty_output,
gs_sodata TYPE ty_sodata.
DATA: gds_bdcdata TYPE bdcdata,
gdt_bdcdata
TYPE TABLE OF bdcdata.
DATA: gds_messtab TYPE bdcmsgcoll,
gdt_messtab
TYPE TABLE OF bdcmsgcoll.
DATA: g_message TYPE balmsgtxtp.
DATA: gds_return TYPE bapiret2,
gdt_return
TYPE TABLE OF bapiret2.
DATA: g_check_auth TYPE c.
DATA:gt_knvp TYPE knvp OCCURS 0,
gs_knvp
TYPE knvp.
DATA: status_buff_init TYPE c VALUE 'X',
call_activity
(4), " Aktiver Aufrufer bei Call
g_no_dequeue_sd_sales
TYPE c.
*DATA P_MODE TYPE C VALUE 'N'.
DATA: gv_charg TYPE charg_d VALUE 'INISTOCK'."期初库存批次
DATA: gv_charg1 TYPE charg_d VALUE 'A999999999'."期初库存批次
DATA: gt_header TYPE STANDARD TABLE OF typ_header,
gs_header
TYPE typ_header.
CLASS gc_event_receiver DEFINITION DEFERRED.
* Define objects used in screen
*DATA: GCTR_ALV TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA:
gctr_alv
TYPE REF TO cl_gui_docking_container,
gct_alv
TYPE REF TO cl_gui_alv_grid,
g_event
TYPE REF TO gc_event_receiver.
DATA:p_filepath TYPE string.
DATA: me TYPE REF TO cl_akb_progress_indicator.
CONSTANTS: c_yes TYPE c VALUE 'X'.
*DATA: C_PATH TYPE RLGRAP-FILENAME VALUE 'C:\TMP\财务批导模板.xls',
DATA: c_path TYPE string VALUE 'C:\TMP\',
c_fullpath
TYPE string VALUE 'C:\TMP\退货批导模板.xls',
c_filename
TYPE string VALUE '退货批导模板.xls',
user_action
TYPE i,
encoding TYPE abap_encoding.
*定义OLE变量
DATA:g_excel TYPE ole2_object,
g_applica
TYPE ole2_object,
g_sheet
TYPE ole2_object,
g_cell
TYPE ole2_object,
g_workbook
TYPE ole2_object.
FIELD-SYMBOLS:<wa_data> TYPE ty_output,
<wa_sodata>
TYPE ty_sodata.
*----------------------------------------------------------------
* SELECTION-SCREEN DEFINITION
*----------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_ufile LIKE rlgrap-filename MODIF ID m1."上传文件路径
SELECT-OPTIONS:
s_lgort
FOR t001l-lgort MODIF ID m2,"库存地点
s_indat
FOR ztsd015-indat MODIF ID m2,"退货日期
s_zdate
FOR ztsd014-zdate MODIF ID m2,"导入日期
s_batno
FOR ztsd015-batno MODIF ID m2 NO-DISPLAY,"批导编号
s_zuser
FOR ztsd014-zuser MODIF ID m2,"导入人
s_sndto
FOR ztsd015-shpto MODIF ID m2,"送达方
s_selto
FOR ztsd015-sldto MODIF ID m2,"客户编号
s_matnr
FOR ztsd015-matnr MODIF ID m2,"物料编号
s_zyddh
FOR ztsd015-zyddh LOWER CASE MODIF ID m2,"验单单号
s_zthdd
FOR ztsd015-zthdd MODIF ID m3,"退货订单
s_zmfck
FOR ztsd015-zmfck MODIF ID m3,"免费出库订单
s_zthdn
FOR ztsd015-zthdn MODIF ID m3."退货交货单
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN: FUNCTION KEY 1. "激活按钮
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: r1 RADIOBUTTON GROUP rg1 USER-COMMAND fcode DEFAULT 'X', "上传批导
r2
RADIOBUTTON GROUP rg1, "退货审批
r3
RADIOBUTTON GROUP rg1 MODIF ID m4 , "免费发货
r6
RADIOBUTTON GROUP rg1 "查询
. "
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE title.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: r4 RADIOBUTTON GROUP rg2 USER-COMMAND fcode DEFAULT 'X' MODIF ID m5."实退
SELECTION-SCREEN COMMENT (5) text-004 FOR FIELD r4.
PARAMETERS: r5 RADIOBUTTON GROUP rg2."空退
SELECTION-SCREEN COMMENT (5) text-005 FOR FIELD r5."空退
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE title4.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: r7 RADIOBUTTON GROUP rg3 USER-COMMAND fcode."石家庄
SELECTION-SCREEN COMMENT (8) text-007 FOR FIELD r7.
PARAMETERS: r8 RADIOBUTTON GROUP rg3 DEFAULT 'X'."外阜
SELECTION-SCREEN COMMENT (8) text-008 FOR FIELD r8."
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b4.
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
sscrfields
-functxt_01 = '下载模板'. "定义按钮文本
title = '退货类型'.
title4
= '业务类型'.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sscrfields-ucomm. "处理按钮命令
WHEN'FC01'.
PERFORM frm_download_template.
ENDCASE.
AT SELECTION-SCREEN OUTPUT.
IF r7 EQ 'X'.
SUBMIT zsdr006
WITH p_ufile = p_ufile
WITH r1 = r1
WITH r2 = r2
WITH r3 = r3
WITH r4 = r4
WITH r5 = r5
WITH r6 = r6
VIA
SELECTION-SCREEN.
ENDIF.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'M1'.
IF r1 EQ 'X'.
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M2'.
IF ( r2 EQ 'X' OR r6 EQ 'X' ) OR ( r3 EQ 'X' AND r5 EQ 'X' ).
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M3'.
IF r5 EQ 'X' AND r3 EQ 'X'.
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M4'.
IF r5 EQ 'X'.
screen-input = 1.
ELSE.
screen-input = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M5'.
IF r3 EQ 'X'.
screen-input = 0.
ELSE.
screen-input = 1.
ENDIF.
MODIFY SCREEN.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ufile.
PERFORM frm_get_filepath.
*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
FREE MEMORY ID :'GT_OUTPUT','BATNO'.
*上传文件
IF r1 EQ 'X'.
IF p_ufile IS INITIAL.
MESSAGE '请选择需要上传的文件' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
PERFORM frm_upload_file USING p_ufile.
PERFORM frm_post_upload.
ELSE."R2 EQ 'X'
*显示保存的数据
IF s_lgort-low IS INITIAL.
MESSAGE '请输入库存地点。' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
PERFORM frm_authority_check.
*DELETE FROM: ZTSD014,ZTSD015,ZTSD016. COMMIT WORK AND WAIT.
PERFORM frm_get_data.
PERFORM frm_process_data.
ENDIF.
IF gt_output IS INITIAL.
MESSAGE '没有符合条件的数据。' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
IF r1 NE 'X' AND r6 NE 'X'.
PERFORM frm_check_lock.
CHECK gt_mesg IS NOT INITIAL.
LOOP AT gt_mesg INTO gs_mesg.
WRITE: / gs_mesg-mesg.
ENDLOOP.
RETURN.
ENDIF.
*----------------------------------------------------------------------*
* END-OF-SELECTION *
*----------------------------------------------------------------------*
END-OF-SELECTION.
PERFORM frm_define_layout.
PERFORM frm_build_fieldcat.
PERFORM frm_exclude_buttons TABLES gt_exclude.
* PERFORM FRM_DISPLAY_DATA.
CALL SCREEN 9000.
*----------------------------------------------------------------
* CLASS GC_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------
CLASS gc_event_receiver DEFINITION.
PUBLIC SECTION.
"添加工具条
METHODS toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object
e_interactive
.
*
"字段修改时触发
* METHODS HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
* IMPORTING
* ER_DATA_CHANGED.
*
*
* METHODS HANDLE_CHANGE_FINISH FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
* IMPORTING
* E_MODIFIED
* ET_GOOD_CELLS.
* "某字段设置热键后,单击此单元格时触发
* METHODS HANDLE_CELL_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
* IMPORTING
* E_ROW_ID
* E_COLUMN_ID
* ES_ROW_NO.
*
* "双击时触发
METHODS handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
.
*
* "按F1时触发
* METHODS HANDLE_ONF1 FOR EVENT ONF1 OF CL_GUI_ALV_GRID
* IMPORTING
* E_FIELDNAME
* ES_ROW_NO
* ER_EVENT_DATA.
*
* "当用户按屏幕上按钮时触发
METHODS handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
.
*F4帮助
METHODS on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING
e_fieldname
es_row_no
er_event_data
et_bad_cells
e_display
.
ENDCLASS. "GC_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------
* CLASS GC_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------
CLASS gc_event_receiver IMPLEMENTATION.
METHOD on_f4.
DATA: lv_menge TYPE menge_d.
CASE e_fieldname.
WHEN 'CHARG'.
READ TABLE gt_output ASSIGNING <wa_data> INDEX es_row_no-row_id.
IF sy-subrc = 0.
* PERFORM FRM_CHARG_F4 CHANGING <WA_DATA>-CHARG .
*实发数量
* LV_MENGE = <WA_DATA>-ZSFSL.
* IF <WA_DATA>-CHARG IS NOT INITIAL.
* LOOP AT GT_DETAIL ASSIGNING <DETAIL>
* WHERE INDAT EQ <WA_DATA>-INDAT
* AND MATNR EQ <WA_DATA>-MATNR
* AND SHPTO EQ <WA_DATA>-SHPTO
* AND SLDTO EQ <WA_DATA>-SLDTO .
**自动分配实发数量到明细表
* IF LV_MENGE GT 0.
* <DETAIL>-ZSFSL = <DETAIL>-ZWFSL.
*
* IF <DETAIL>-ZSFSL LT LV_MENGE.
* LV_MENGE = ABS( <DETAIL>-ZSFSL - LV_MENGE ).
* ELSE.
* <DETAIL>-ZSFSL = LV_MENGE.
* LV_MENGE = 0.
* ENDIF.
* ENDIF.
**分配批次到明细表
* MOVE <WA_DATA>-CHARG TO <DETAIL>-CHARG .
* ENDLOOP.
* CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY.
* ENDIF.
ENDIF.
UNASSIGN
: <wa_data>.
ENDCASE.
ENDMETHOD.
METHOD handle_double_click.
* BREAK B012.
* IF R6 EQ 'X'.
IF e_column-fieldname EQ 'ZTHDN'.
READ TABLE gt_output INTO gs_output INDEX e_row-index.
CHECK gs_output-zthdn IS NOT INITIAL.
SET PARAMETER ID 'VL' FIELD gs_output-zthdn.
CALL TRANSACTION 'VL03N' WITH AUTHORITY-CHECK AND SKIP FIRST SCREEN.
*返回时检查是否已过账
* BREAK B012.
WAIT UP TO 1 SECONDS.
PERFORM frm_check_post USING gs_output-zthdn 1.
ENDIF.
IF e_column-fieldname EQ 'ZDN'.
READ TABLE gt_output INTO gs_output INDEX e_row-index.
CHECK gs_output-zdn IS NOT INITIAL.
SET PARAMETER ID 'VL' FIELD gs_output-zdn.
CALL TRANSACTION 'VL03N' WITH AUTHORITY-CHECK AND SKIP FIRST SCREEN.
*返回时检查是否已过账
WAIT UP TO 1 SECONDS.
PERFORM frm_check_post USING gs_output-zdn 2.
ENDIF.
* ENDIF.
CALL METHOD gct_alv->refresh_table_display
EXPORTING
is_stable
= gs_stable
i_soft_refresh
= 'X'.
ENDMETHOD.
METHOD toolbar.
DATA: ls_toolbar TYPE stb_button.
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type. "分隔符
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'SEL_ALL' TO ls_toolbar-function. "添加全选
MOVE icon_select_all TO ls_toolbar-icon.
MOVE '全选' TO ls_toolbar-quickinfo.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'CAN_ALL' TO ls_toolbar-function. "取消全选
MOVE icon_deselect_all TO ls_toolbar-icon.
MOVE '全部取消 ' TO ls_toolbar-quickinfo.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type."分隔符
APPEND ls_toolbar TO e_object->mt_toolbar.
IF r1 EQ 'X' OR r2 EQ 'X'.
CLEAR ls_toolbar.
MOVE 'DEL' TO ls_toolbar-function.
MOVE icon_delete_row TO ls_toolbar-icon.
MOVE '删除行' TO ls_toolbar-quickinfo.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDIF.
IF r2 EQ 'X' OR r3 EQ 'X'.
* CLEAR LS_TOOLBAR.
* MOVE 'ADD' TO LS_TOOLBAR-FUNCTION.
* MOVE ICON_INSERT_ROW TO LS_TOOLBAR-ICON.
* MOVE '添加行' TO LS_TOOLBAR-QUICKINFO.
* MOVE ' ' TO LS_TOOLBAR-DISABLED.
* APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
*
* CLEAR LS_TOOLBAR.
* MOVE 'DEL' TO LS_TOOLBAR-FUNCTION.
* MOVE ICON_DELETE_ROW TO LS_TOOLBAR-ICON.
* MOVE '删除行' TO LS_TOOLBAR-QUICKINFO.
* MOVE ' ' TO LS_TOOLBAR-DISABLED.
* APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
CLEAR ls_toolbar.
MOVE 'OKAY' TO ls_toolbar-function.
MOVE icon_okay TO ls_toolbar-icon.
MOVE '审批通过' TO ls_toolbar-quickinfo.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDIF.
* IF R6 EQ 'X'.
* CLEAR LS_TOOLBAR.
* MOVE 'POST_GMVT' TO LS_TOOLBAR-FUNCTION.
** MOVE ICON_OKAY TO LS_TOOLBAR-ICON.
* MOVE 0 TO LS_TOOLBAR-BUTN_TYPE.
* MOVE '发货过账' TO LS_TOOLBAR-TEXT.
* APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
* ENDIF.
ENDMETHOD.
METHOD handle_user_command.
DATA(ok_code) = e_ucomm.
DATA: error TYPE c,
lv_result
TYPE string.
DATA: ans TYPE string."GUI返回值
CASE ok_code.
WHEN 'SEL_ALL'.
PERFORM frm_sel_all.
* CLEAR GS_OUTPUT.
* GS_OUTPUT-SEL = 'X'.
* MODIFY GT_OUTPUT FROM GS_OUTPUT TRANSPORTING SEL WHERE SEL EQ SPACE AND ZICON1 NE '@0A@'."红灯
WHEN 'CAN_ALL'.
CLEAR gs_output.
gs_output
-sel = ' '.
MODIFY gt_output FROM gs_output TRANSPORTING sel WHERE sel EQ 'X'.
WHEN 'OKAY'.
PERFORM frm_confirm_data CHANGING lv_result.
IF lv_result EQ 'S'.
CLEAR lv_result.
PERFORM frm_save_data USING 'APPROVAL' CHANGING lv_result.
IF lv_result EQ 'S'.
MESSAGE '审批成功!' TYPE 'S'.
ELSE.
MESSAGE '审批失败!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
CLEAR lv_result.
ENDIF.
* WHEN 'ADD'.
* PERFORM FRM_ADD_ROW.
*
WHEN 'DEL'.
*询问是否确认
READ TABLE gt_output TRANSPORTING NO FIELDS WITH KEY sel = 'X'.
IF sy-subrc NE 0.
MESSAGE '请至少选择一条数据!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question
= '确认删除所选数据?'
text_button_1
= '是'(009)
text_button_2
= '否'(010)
default_button
= '1'
display_cancel_button
= 'X'
start_column
= 25
start_row
= 6
IMPORTING
answer
= ans
EXCEPTIONS
text_not_found
= 1
OTHERS = 2.
IF ans EQ '1'."是
IF r1 EQ 'X'.
DELETE gt_output WHERE sel EQ 'X'.
ELSE.
PERFORM frm_delete_data.
ENDIF.
ENDIF.
WHEN 'POST_GMVT'.
PERFORM frm_post_gmvt CHANGING lv_result.
IF lv_result EQ 'S'.
CLEAR lv_result.
PERFORM frm_save_data USING 'POST' CHANGING lv_result.
IF lv_result EQ 'S'.
MESSAGE '过账成功!' TYPE 'S'.
ELSE.
MESSAGE '过账失败!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
CLEAR lv_result.
ENDIF.
WHEN OTHERS.
ENDCASE.
CALL METHOD gct_alv->refresh_table_display
EXPORTING
is_stable
= gs_stable
i_soft_refresh
= 'X'.
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Form FRM_GET_FILEPATH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM frm_get_filepath .
DATA: l_rc TYPE i.
DATA: lt_filetab TYPE filetable.
CREATE OBJECT me.
CALL METHOD me->display
EXPORTING
message = '选择上传文件路径......'.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title
= '请选择本地文件'
multiselection
= space
CHANGING
file_table
= lt_filetab
rc
= l_rc
EXCEPTIONS
file_open_dialog_failed
= 1
cntl_error
= 2
error_no_gui
= 3
not_supported_by_gui
= 4
OTHERS = 5.
IF sy-subrc EQ 0 AND l_rc EQ 1.
READ TABLE lt_filetab INTO p_ufile INDEX 1.
ENDIF.
ENDFORM. " FRM_GET_FILEPATH
*&---------------------------------------------------------------------*
*& Form FRM_UPLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_UFILE text
*----------------------------------------------------------------------*
FORM frm_upload_file USING p_ufile TYPE rlgrap-filename.
DATA: ls_rowdata TYPE truxs_t_text_data,
lv_lines
TYPE i,
lv_msg
TYPE string,
lv_n
TYPE i,
lv_count
TYPE i. "计数器
DATA: lv_posnr(4) TYPE n."批导行项目号
CREATE OBJECT me.
CALL METHOD me->display
EXPORTING
message = '读取上传文件内容...'.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header
= '1'
i_tab_raw_data
= ls_rowdata
i_filename
= p_ufile
TABLES
i_tab_converted_data
= gt_load[]
EXCEPTIONS
conversion_failed
= 1.
IF sy-subrc NE 0.
* MESSAGE SY-MSGID WITH 'Excel导入错误。'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* BREAK B012.
CREATE OBJECT me.
CALL METHOD me->display
EXPORTING
message = '检查数据...'.
DELETE gt_load WHERE menge EQ 0.
DESCRIBE TABLE gt_load LINES lv_lines.
LOOP AT gt_load INTO gs_load.
lv_msg
= '检查数据...' && sy-tabix && '/' && lv_lines.
CALL METHOD me->display
EXPORTING
message = lv_msg.
*检查日期格式
ASSIGN COMPONENT 1 OF STRUCTURE gs_load TO <fs>.
CALL FUNCTION 'RP_CHECK_DATE'
EXPORTING
date = <fs>
EXCEPTIONS
date_invalid
= 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE '日期格式不正确' TYPE 'S' DISPLAY LIKE 'E'.
* STOP.
PERFORM set_callsytle USING 1 gs_load '日期格式错误' CHANGING gs_output-cellcolor gs_output-mssg.
ELSEIF <fs> GT sy-datum.
PERFORM set_callsytle USING 1 gs_load '日期大于当天' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
*检查客户编号是否存在
* ASSIGN COMPONENT 2 OF STRUCTURE GS_LOAD TO <FS>.
*
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = <FS>
* IMPORTING
* OUTPUT = <FS>.
*
** SELECT SINGLE NAME1 INTO GS_OUTPUT-NAME1
** FROM KNA1
** WHERE KUNNR EQ <FS>
** AND KTOKD EQ 'Z003'
* .
*
* IF SY-SUBRC NE 0.
* PERFORM SET_CALLSYTLE USING 2 GS_LOAD '客户不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
*检查送达方售达方是否存在
*添加前置零
ASSIGN COMPONENT 2 OF STRUCTURE gs_load TO <fs>.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs>
IMPORTING
output = <fs>.
SELECT SINGLE name1 INTO gs_output-name3
FROM kna1
WHERE kunnr EQ <fs>
* AND KTOKD EQ 'Z003'
.
IF sy-subrc NE 0.
PERFORM set_callsytle USING 2 gs_load '售达方不存在' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
*添加前置零
ASSIGN COMPONENT 3 OF STRUCTURE gs_load TO <fs>.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs>
IMPORTING
output = <fs>.
SELECT SINGLE name1 INTO gs_output-name2
FROM kna1
WHERE kunnr EQ <fs>
.
IF sy-subrc NE 0.
PERFORM set_callsytle USING 3 gs_load '送达方不存在' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
*检查退货原因是否存在
ASSIGN COMPONENT 7 OF STRUCTURE gs_load TO <fs>.
PERFORM add_lead_zero USING 3 CHANGING <fs>.
SELECT SINGLE bezei INTO gs_output-zthyy
FROM tvaut
WHERE augru EQ <fs>.
IF sy-subrc NE 0.
PERFORM set_callsytle USING 7 gs_load '原因代码不存在' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
*检查产品是否存在
*取物料描述
*添加前置零
ASSIGN COMPONENT 10 OF STRUCTURE gs_load TO <fs>.
UNPACK <fs> TO <fs>.
SELECT SINGLE maktx INTO gs_output-maktx
FROM makt
WHERE matnr EQ <fs>
AND spras EQ 1.
IF sy-subrc NE 0.
PERFORM set_callsytle USING 10 gs_load '物料不存在' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
****检查单位
ASSIGN COMPONENT 12 OF STRUCTURE gs_load TO <fs>.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = <fs>
language = sy-langu
IMPORTING
output = <fs>
EXCEPTIONS
unit_not_found
= 1
OTHERS = 2.
IF sy-subrc NE 0.
PERFORM set_callsytle USING 12 gs_load '单位不存在' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
*检查库存地点
ASSIGN COMPONENT 8 OF STRUCTURE gs_load TO <fs>.
SELECT SINGLE lgort FROM t001l
INTO @DATA(lv_lgort)
WHERE lgort EQ @<fs>.
IF sy-subrc NE 0.
PERFORM set_callsytle USING 8 gs_load '库存地不存在' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
*检查订单行项目类型
ASSIGN COMPONENT 9 OF STRUCTURE gs_load TO <fs>.
TRANSLATE <fs> TO UPPER CASE.
IF <fs> NE 'REN' AND <fs> NE 'REN4'.
PERFORM set_callsytle USING 9 gs_load '行项目类型不正确' CHANGING gs_output-cellcolor gs_output-mssg.
ENDIF.
MOVE-CORRESPONDING gs_load TO gs_output.
ADD 1 TO lv_posnr.
MOVE lv_posnr TO gs_output-batpo.
APPEND gs_output TO gt_output.
CLEAR:gs_load,gs_output.
ENDLOOP.
* DATA: LV_LENTH TYPE I.
* DATA: LV_FLAG TYPE C.
* DATA: LV_POSNR(4) TYPE N."批导行项目号
* DATA: L_EXCEPTION TYPE REF TO CX_ROOT.
*
* DATA: LV_LINES TYPE I,
* LV_ROW TYPE I,
* LV_COL TYPE I,
* LV_COL1 TYPE I,
* LV_COL2 TYPE I,
* LV_FIXED TYPE I.
*
* DATA: LT_TAB TYPE TABLE OF ALSMEX_TABLINE,
* LT_TAB1 TYPE TABLE OF ALSMEX_TABLINE,
* LS_TAB TYPE ALSMEX_TABLINE,
* LS_TAB1 TYPE ALSMEX_TABLINE.
*
* DATA: X TYPE I."两个物料列的间隔
*
* FIELD-SYMBOLS: <L_FS> TYPE ALSMEX_TABLINE.
*
* CLEAR: LV_COUNT,X,LV_LINES.
* CREATE OBJECT ME.
* CALL METHOD ME->DISPLAY
* EXPORTING
* MESSAGE = '读取上传文件内容...'.
*
* CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
* EXPORTING
* FILENAME = P_UFILE
* I_BEGIN_COL = 1
* I_BEGIN_ROW = 1
* I_END_COL = 13555
* I_END_ROW = 65536
* TABLES
* INTERN = ITAB[]
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3.
* IF SY-SUBRC NE 0.
* MESSAGE E001 WITH 'Excel导入错误。'.
* ENDIF.
*
**行列转换
* CALL FUNCTION 'ZSDF001'
* IMPORTING
* FIXED_COL = LV_FIXED
* TABLES
* ITAB_IN = ITAB[]
* ITAB_OUT = ITAB[].
*
*
* SORT ITAB[] BY ROW COL.
**删除不必要的列
* DELETE ITAB[] WHERE COL EQ 3 AND COL EQ 5 AND COL EQ 7 AND COL EQ 12.
* DESCRIBE TABLE ITAB[] LINES LV_LINES.
*
* LOOP AT ITAB.
* LV_MSG = '检查数据...' && SY-TABIX && '/' && LV_LINES.
*
* ON CHANGE OF ITAB-ROW.
* IF SY-TABIX NE 1.
*
* IF GS_LOAD-MENGE GT 0.
* APPEND GS_LOAD TO GT_LOAD.
* MOVE-CORRESPONDING GS_LOAD TO GS_OUTPUT.
*
* ADD 1 TO LV_POSNR.
* MOVE LV_POSNR TO GS_OUTPUT-BATPO.
*
* IF GS_OUTPUT-CELLCOLOR IS NOT INITIAL.
* GS_OUTPUT-ZICON1 = '@0A@'."红灯
* ELSE.
* GS_OUTPUT-ZICON1 = '@08@'."绿灯
*
* ENDIF.
*
* IF GS_OUTPUT-ZICON1 = '@0A@'."红灯
* PERFORM SET_STYLE USING 'SEL' 'DISABLE' CHANGING GS_OUTPUT-STYLE.
* ENDIF.
* APPEND GS_OUTPUT TO GT_OUTPUT.
*
* CLEAR GS_LOAD.
* CLEAR GS_OUTPUT.
* CLEAR GS_CELLCOLOR.
* ELSE.
* CLEAR GS_LOAD.
* CLEAR GS_OUTPUT.
* CLEAR GS_CELLCOLOR.
* ENDIF.
* ENDIF.
* ENDON.
*
* ASSIGN COMPONENT ITAB-COL OF STRUCTURE GS_LOAD TO <FS>.
* IF SY-SUBRC NE 0.
* CONTINUE.
* ENDIF.
*
* "动态方法将值传到相应的内表
** <FS> = ITAB-VALUE.
* TRY.
* MOVE ITAB-VALUE TO <FS>.
* CATCH CX_ROOT INTO L_EXCEPTION.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '数据格式不正确' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* CONTINUE.
* ENDTRY.
*
* CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
* EXPORTING
* PERCENTAGE = 0
** TEXT = '检查数据... '.
* TEXT = LV_MSG.
*
**检查日期格式
* IF ITAB-COL EQ 1.
*
* CALL FUNCTION 'RP_CHECK_DATE'
* EXPORTING
* DATE = <FS>
* EXCEPTIONS
* DATE_INVALID = 1
* OTHERS = 2.
*
* IF SY-SUBRC NE 0.
** MESSAGE '日期格式不正确' TYPE 'S' DISPLAY LIKE 'E'.
** STOP.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '日期格式错误' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ELSEIF <FS> GT SY-DATUM.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '日期大于当天' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
* ENDIF.
**检查客户编号是否存在
* IF ITAB-COL EQ 2.
**取客户名称
**添加前置零
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = <FS>
* IMPORTING
* OUTPUT = <FS>.
*
* SELECT SINGLE NAME1 INTO GS_OUTPUT-NAME1
* FROM KNA1
* WHERE KUNNR EQ <FS>
** AND KTOKD EQ 'Z003'
* .
*
* IF SY-SUBRC NE 0.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '客户不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
* ENDIF.
*
**检查送达方售达方是否存在
* IF ITAB-COL EQ 4.
**添加前置零
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = <FS>
* IMPORTING
* OUTPUT = <FS>.
*
* SELECT SINGLE NAME1 INTO GS_OUTPUT-NAME3
* FROM KNA1
* WHERE KUNNR EQ <FS>
** AND KTOKD EQ 'Z003'
* .
* IF SY-SUBRC NE 0.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '售达方不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
*
* ENDIF.
*
* IF ITAB-COL EQ 6.
**添加前置零
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = <FS>
* IMPORTING
* OUTPUT = <FS>.
*
* SELECT SINGLE NAME1 INTO GS_OUTPUT-NAME2
* FROM KNA1
* WHERE KUNNR EQ <FS>
** AND KTOKD EQ 'Z003'
* .
*
* ENDIF.
*
* IF ITAB-COL EQ 11.
**检查退货原因是否存在
* PERFORM ADD_LEAD_ZERO USING 3 CHANGING <FS>.
*
* SELECT SINGLE * INTO @DATA(LS_TVAU)
* FROM TVAU
* WHERE AUGRU EQ @<FS>.
*
* IF SY-SUBRC NE 0.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '原因代码不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
* ENDIF.
*
**检查产品是否存在
* IF ITAB-COL EQ LV_FIXED.
**取物料描述
**添加前置零
*
* UNPACK <FS> TO <FS>.
*
* SELECT SINGLE MAKTX INTO GS_OUTPUT-MAKTX
* FROM MAKT
* WHERE MATNR EQ <FS>
* AND SPRAS EQ 1.
*
* IF SY-SUBRC NE 0.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '物料不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
*
*****检查单位
* IF ITAB-COL EQ 15.
*
* CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
* EXPORTING
* INPUT = <FS>
* LANGUAGE = SY-LANGU
* IMPORTING
* OUTPUT = <FS>
* EXCEPTIONS
* UNIT_NOT_FOUND = 1
* OTHERS = 2.
*
* IF SY-SUBRC NE 0.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '单位不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
* ENDIF.
*
**检查库存地点
* IF ITAB-COL EQ 13.
* SELECT SINGLE LGORT FROM T001L
* INTO @DATA(LV_LGORT)
* WHERE LGORT EQ @<FS>.
*
* IF SY-SUBRC NE 0.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '库存地不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
*
* ENDIF.
*
**检查订单行项目类型
* IF ITAB-COL EQ 14.
* IF <FS> NE 'REN' AND <FS> NE 'REN2'.
* PERFORM SET_CALLSYTLE USING ITAB-COL GS_LOAD '行项目类型不正确' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
* ENDIF.
*
* ENDIF.
*
** ENDIF.
** AT END OF ROW.
** IF SY-TABIX NE 1.
** APPEND GS_LOAD TO GT_LOAD.
** MOVE-CORRESPONDING GS_LOAD TO GS_OUTPUT.
**
** ADD 1 TO LV_POSNR.
** MOVE LV_POSNR TO GS_OUTPUT-BATPO.
**
** IF GS_OUTPUT-CELLCOLOR IS NOT INITIAL.
** GS_OUTPUT-ZICON1 = '@0A@'."红灯
** ELSE.
** GS_OUTPUT-ZICON1 = '@08@'."绿灯
**
** ENDIF.
**
*** GS_OUTPUT-ZICON2 = ICON_SET_STATE.
** IF GS_OUTPUT-ZICON1 = '@0A@'."红灯
** PERFORM SET_STYLE USING 'SEL' 'DISABLE' CHANGING GS_OUTPUT-STYLE.
** ENDIF.
** APPEND GS_OUTPUT TO GT_OUTPUT.
**
** CLEAR GS_LOAD.
** CLEAR GS_OUTPUT.
** CLEAR GS_CELLCOLOR.
** ENDIF.
** ENDAT.
* ENDLOOP.
*
* IF GS_LOAD-MENGE GT 0.
*
* APPEND GS_LOAD TO GT_LOAD.
*
* MOVE-CORRESPONDING GS_LOAD TO GS_OUTPUT.
** MOVE GS_LOAD-ZJHSL TO GS_OUTPUT-ZTZSL.
* ADD 1 TO LV_POSNR.
* MOVE LV_POSNR TO GS_OUTPUT-BATPO.
*
* IF GS_OUTPUT-CELLCOLOR IS NOT INITIAL.
* GS_OUTPUT-ZICON1 = '@0A@'."红灯
* ELSE.
* GS_OUTPUT-ZICON1 = '@08@'."绿灯
* ENDIF.
*
** GS_OUTPUT-ZICON2 = ICON_SET_STATE.
* IF GS_OUTPUT-ZICON1 = '@0A@'."红灯
* PERFORM SET_STYLE USING 'SEL' 'DISABLE' CHANGING GS_OUTPUT-STYLE.
* ENDIF.
* APPEND GS_OUTPUT TO GT_OUTPUT.
* CLEAR: GS_OUTPUT,GS_CELLCOLOR.
* ELSE.
* CLEAR: GS_OUTPUT,GS_CELLCOLOR.
* ENDIF.
*
* IF GT_LOAD[] IS INITIAL.
* MESSAGE '文件名或数据为空,请确认后重试!' TYPE 'I'.
* ELSE.
* ENDIF.
ENDFORM. " FRM_UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_download_template .
CLEAR: gt_header.
*填充抬头
*财务批导模板抬头
gs_header
-ztext = '日期'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
* GS_HEADER-ZTEXT = '客户编码'.
* APPEND GS_HEADER TO GT_HEADER.
* CLEAR GS_HEADER.
*
gs_header
-ztext = '售达方编码'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
*
gs_header
-ztext = '送达方编码'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
*
gs_header
-ztext = '业务员'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
*
gs_header
-ztext = '主任'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '退单单号'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '退货原因编码'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '库存地点编码'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '退货项目类型'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '产品编号'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '退货数量'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '数量单位'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '退货价格'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '金额'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
gs_header
-ztext = '过账日期'.
APPEND gs_header TO gt_header.
CLEAR gs_header.
*下载模板
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title
= '财务批导模板'
with_encoding
= 'X'
initial_directory
= c_path
prompt_on_overwrite
= 'X'
default_file_name
= c_filename
CHANGING
filename
= c_filename
path
= c_path
fullpath
= c_fullpath
user_action
= user_action
file_encoding
= encoding
EXCEPTIONS
cntl_error
= 1
error_no_gui
= 2
not_supported_by_gui
= 3
OTHERS = 4.
IF user_action <> cl_gui_frontend_services=>action_ok.
EXIT.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename
= c_fullpath
filetype
= 'DAT'
TABLES
data_tab
= gt_load
fieldnames
= gt_header
EXCEPTIONS
file_write_error
= 1
no_batch
= 2
gui_refuse_filetransfer
= 3
invalid_type
= 4.
* DATA: LV_OBJDATA LIKE WWWDATATAB,
* LV_OBJ_NAME LIKE WWWDATATAB-OBJID,
* LV_DESTINATION LIKE RLGRAP-FILENAME,
* LV_OBJID LIKE SY-REPID,
* LV_SUBRC LIKE SY-SUBRC.
* DATA:L_RET TYPE ABAP_BOOL,
* LV_ANSWER.
* DATA:LV_FILE TYPE STRING.
*
* MOVE C_PATH TO LV_FILE.
* CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
* EXPORTING
* WINDOW_TITLE = '退货批导模板'
* WITH_ENCODING = 'X'
* INITIAL_DIRECTORY = C_PATH
* PROMPT_ON_OVERWRITE = 'X'
* DEFAULT_FILE_NAME = C_FILENAME
* CHANGING
* FILENAME = C_FILENAME
* PATH = C_PATH
* FULLPATH = C_FULLPATH
* USER_ACTION = USER_ACTION
* FILE_ENCODING = ENCODING
* EXCEPTIONS
* CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* NOT_SUPPORTED_BY_GUI = 3
* OTHERS = 4.
*
* IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* EXIT.
* ENDIF.
*
* CREATE OBJECT G_EXCEL 'EXCEL.APPLICATION'.
* GET PROPERTY OF G_EXCEL 'Workbooks' = G_WORKBOOK .
* CALL METHOD OF
* G_WORKBOOK
* 'Close'.
*
* IF USER_ACTION EQ '0'.
* MOVE 'ZSD_XLS_005' TO LV_OBJ_NAME.
* SELECT SINGLE RELID OBJID
* FROM WWWDATA
* INTO CORRESPONDING FIELDS OF LV_OBJDATA
* WHERE SRTF2 = 0 AND RELID = 'MI'
* AND OBJID = LV_OBJ_NAME.
*
* LV_DESTINATION = C_FULLPATH.
*
* CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
* EXPORTING
* KEY = LV_OBJDATA
* DESTINATION = LV_DESTINATION
* IMPORTING
* RC = LV_SUBRC.
* IF LV_SUBRC = 0.
* P_FILEPATH = C_PATH.
* ENDIF.
* ENDIF.
*
* CALL METHOD OF
* G_WORKBOOK
* 'open'
* EXPORTING
* #1 = C_FULLPATH.
*
* CALL METHOD OF
* G_EXCEL
* 'worksheets' = G_SHEET
* EXPORTING
* #1 = 1.
*
* CALL METHOD OF
* G_SHEET
* 'activate'.
*
* SET PROPERTY OF G_EXCEL 'visible' = 1.
*
* FREE OBJECT G_SHEET.
* FREE OBJECT G_APPLICA.
* FREE OBJECT G_WORKBOOK.
* FREE OBJECT G_EXCEL.
ENDFORM. " FRM_DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_data .
IF r4 EQ 'X'.
*IF R2 EQ 'X'.
SELECT
a
~*,
b
~zthlx,
b
~zuser,
b
~zdate
INTO CORRESPONDING FIELDS OF TABLE @gt_output
FROM ztsd015 AS a
INNER
JOIN ztsd014 AS b ON a~batno EQ b~batno
WHERE a~batno IN @s_batno
AND a~indat IN @s_indat
AND a~zyddh IN @s_zyddh
AND a~lgort IN @s_lgort
* AND KUNNR IN @S_KUNNR
AND shpto IN @s_sndto
AND sldto IN @s_selto
AND matnr IN @s_matnr
AND b~zdate IN @s_zdate
AND b~zuser IN @s_zuser
* AND A~ZSTAT EQ 'A'"初始状态
AND b~zthlx EQ 'A'."实退
*elseIF R6 EQ 'X'."过账货物移动
* SELECT
* A~*,
* B~ZTHLX
* INTO CORRESPONDING FIELDS OF TABLE @GT_OUTPUT
* FROM ZTSD015 AS A
* INNER JOIN ZTSD014 AS B ON A~BATNO EQ B~BATNO
* WHERE A~BATNO IN @S_BATNO
* AND A~INDAT IN @S_INDAT
* AND KUNNR IN @S_KUNNR
* AND SHPTO IN @S_SNDTO
* AND SLDTO IN @S_SELTO
* AND MATNR IN @S_MATNR
* AND A~ZSTAT EQ 'B'"未过账
* AND B~ZTHLX EQ 'A'."实退
ELSEIF r5 EQ 'X'.
SELECT
a
~*,
b
~zthlx,
b
~zuser,
b
~zdate
INTO CORRESPONDING FIELDS OF TABLE @gt_output
FROM ztsd015 AS a
INNER
JOIN ztsd014 AS b ON a~batno EQ b~batno
WHERE a~batno IN @s_batno
AND a~indat IN @s_indat
AND a~zyddh IN @s_zyddh
AND a~lgort IN @s_lgort
* AND KUNNR IN @S_KUNNR
AND shpto IN @s_sndto
AND sldto IN @s_selto
AND matnr IN @s_matnr
AND zthdd IN @s_zthdd
AND zmfck IN @s_zmfck
AND zdn IN @s_zthdn
AND b~zdate IN @s_zdate
AND b~zuser IN @s_zuser
AND b~zthlx EQ 'B'."空退
ENDIF.
ENDFORM. " FRM_GET_DATA
*&---------------------------------------------------------------------*
*& Form FRM_PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_process_data .
DATA: lt_output TYPE TABLE OF ty_output.
DATA lv_meins TYPE meins.
DATA:lv_auart TYPE auart.
" DATA:lv_bstkd TYPE vbkd-bstkd_e.
LOOP AT gt_output ASSIGNING <wa_data>.
gt_batno
-batno = <wa_data>-batno.
gt_batno
-batpo = <wa_data>-batpo.
APPEND gt_batno.
<wa_data>
-key = <wa_data>-batno && <wa_data>-batpo.
*客户名称
SELECT SINGLE name1 INTO <wa_data>-name2
FROM kna1
WHERE kunnr EQ <wa_data>-shpto.
*客户名称
SELECT SINGLE name1 INTO <wa_data>-name3
FROM kna1
WHERE kunnr EQ <wa_data>-sldto.
*物料描述
SELECT SINGLE maktx INTO <wa_data>-maktx
FROM makt
WHERE matnr EQ <wa_data>-matnr
AND spras EQ 1.
*库存底单描述
SELECT SINGLE lgobe INTO <wa_data>-lgobe
FROM t001l
WHERE werks EQ '1000'
AND lgort EQ <wa_data>-lgort.
IF <wa_data>-zthlx EQ 'A'.
<wa_data>
-zthms = '实退'.
ELSEIF <wa_data>-zthlx EQ 'B'.
<wa_data>
-zthms = '空退'.
ENDIF.
<wa_data>
-zddjg = <wa_data>-zddje / <wa_data>-menge.
lv_meins
= 'EA'.
<wa_data>
-zdw1 = lv_meins.
PERFORM frm_convert_unit(zsdr019) USING <wa_data>-matnr
<wa_data>
-meins
lv_meins
<wa_data>
-menge
CHANGING <wa_data>-zsl1.
PERFORM frm_get_stat USING <wa_data>-zthdd.
*已审批的不允许再选择
IF <wa_data>-zthdd NE space
OR <wa_data>-zmfck NE space.
* <WA_DATA>-SEL = '-'.
gs_style
-fieldname = 'MENGE'.
gs_style
-style = cl_gui_alv_grid=>mc_style_disabled.
READ TABLE <wa_data>-style TRANSPORTING NO FIELDS WITH KEY fieldname = gs_style-fieldname.
IF sy-subrc EQ 0.
MODIFY <wa_data>-style FROM gs_style INDEX sy-tabix.
ELSE.
INSERT gs_style INTO TABLE <wa_data>-style .
ENDIF.
CLEAR gs_style.
gs_style
-fieldname = 'ZDDJE'.
gs_style
-style = cl_gui_alv_grid=>mc_style_disabled.
READ TABLE <wa_data>-style TRANSPORTING NO FIELDS WITH KEY fieldname = gs_style-fieldname.
IF sy-subrc EQ 0.
MODIFY <wa_data>-style FROM gs_style INDEX sy-tabix.
ELSE.
INSERT gs_style INTO TABLE <wa_data>-style .
ENDIF.
CLEAR gs_style.
gs_style
-fieldname = 'ZYDDH'.
gs_style
-style = cl_gui_alv_grid=>mc_style_disabled.
READ TABLE <wa_data>-style TRANSPORTING NO FIELDS WITH KEY fieldname = gs_style-fieldname.
IF sy-subrc EQ 0.
MODIFY <wa_data>-style FROM gs_style INDEX sy-tabix.
ELSE.
INSERT gs_style INTO TABLE <wa_data>-style .
ENDIF.
CLEAR gs_style.
ENDIF.
SELECT SINGLE mseg~budat_mkpf INTO <wa_data>-budat
FROM vbkd
INNER
JOIN lips ON vbkd~vbeln EQ lips~vgbel AND vbkd~posnr EQ lips~vgpos
INNER
JOIN mseg ON lips~vbeln EQ mseg~vbeln_im AND lips~posnr EQ mseg~vbelp_im
WHERE vbkd~bstkd_e EQ <wa_data>-key.
ENDLOOP.
* IF R6 EQ 'X'.
*过账只显示生成了交货单且未过账的项目
* DELETE GT_OUTPUT WHERE ( ZTHDN IS INITIAL AND ZDN IS INITIAL )
* OR ( WBSTK1 EQ 'C' OR WBSTK2 EQ 'C' ).
* ENDIF.
IF r3 EQ 'X'.
*空退免费发货只显示已退货过账且未生成免费订单的项目
DELETE gt_output WHERE ( zthdd IS INITIAL OR zmfck IS NOT INITIAL )
OR wbstk1 NE 'C'.
ENDIF.
IF r2 EQ 'X'.
DELETE gt_output WHERE zthdd IS NOT INITIAL." AND wbstk1 EQ 'C'.
ENDIF.
SORT gt_output BY indat zyddh matnr.
*将初始内表放入内存
lt_output
= gt_output.
EXPORT lt_output TO MEMORY ID 'GT_OUTPUT'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DEFINE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_define_layout .
gs_layout
-zebra = 'X'.
gs_layout
-cwidth_opt = 'A'.
gs_layout
-ctab_fname = 'CELLCOLOR'.
gs_layout
-stylefname = 'STYLE'.
* GS_LAYOUT-NO_ROWMARK = 'X'.
gs_variant
-report = sy-repid.
gs_stable
-row = 'X'.
gs_stable
-col = 'X'.
ENDFORM. " FRM_DEFINE_LAYOUT
*&---------------------------------------------------------------------*
*& Form FRM_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_build_fieldcat .
DEFINE build_fc.
GS_STRUCTURE
-FIELDNAME = &1.
GS_STRUCTURE
-COLTEXT = &2.
GS_STRUCTURE
-JUST = &3.
GS_STRUCTURE
-REF_TABLE = &4.
GS_STRUCTURE
-REF_FIELD = &5.
GS_STRUCTURE
-NO_ZERO = 'X'.
GS_STRUCTURE
-EMPHASIZE = &6.
IF &1 EQ 'SEL'.
GS_STRUCTURE
-CHECKBOX = 'X'.
GS_STRUCTURE
-EDIT = 'X'.
ENDIF.
IF &1 EQ 'ZYDDH' .
GS_STRUCTURE
-NO_ZERO = ' '.
ENDIF.
IF ( &1 EQ 'MENGE' OR &1 EQ 'ZDDJE' OR &1 EQ 'ZYDDH' OR &1 EQ 'BUDAT' ) AND ( R1 EQ 'X' OR R2 EQ 'X' ).
GS_STRUCTURE
-EDIT = 'X'.
ENDIF.
*批次F4
* IF GS_STRUCTURE-FIELDNAME EQ 'CHARG'.
* GS_STRUCTURE-F4AVAILABL = 'X'.
* GS_STRUCTURE-EDIT = 'X'.
* ENDIF.
APPEND GS_STRUCTURE TO GT_STRUCTURE.
CLEAR GS_STRUCTURE.
END-OF-DEFINITION.
IF r6 NE 'X'.
build_fc
:
'SEL' '选择列' '' '' '' ''.
ENDIF.
build_fc
:
'INDAT' '退货日期' '' 'ZTSD015' 'INDAT' '',
'BUDAT' '过账日期' '' 'MKPF' 'BUDAT' '',
'SHPTO' '送达方编号' '' 'KNA1' 'KUNNR' '',
'NAME2' '送达方名称' '' 'KNA1' 'NAME1' '',
'SLDTO' '售达方编号' '' 'KNA1' 'KUNNR' '',
'NAME3' '售达方名称' '' 'KNA1' 'NAME1' '',
'ZYDDH' '退货单号' '' 'ZTSD015' 'ZYDDH' '',
* 'VKBUR' '销售部门' '' '' '' '',
'ZR' '主任' '' 'ZTSD015' 'ZR' '',
'ZYWY' '业务员' '' 'ZTSD015' 'ZYWY' '',
'LGORT' '库存地点编号' '' 'T001L' 'LGORT' '',
'LGOBE' '库存地点' '' 'T001L' 'LGOBE' '',
* 'ZDATE' '导入日期' '' 'ZTSD014' 'ZDATE' '',
'MATNR' '物料编号' '' 'MARA' 'MATNR' '',
'MAKTX' '物料名称' '' 'MAKT' 'MAKTX' '',
* 'CHARG' '批次' '' '' '',
'MENGE' '退货数量' '' 'LIPS' 'LFIMG' '',
'MEINS' '单位' '' 'MARA' 'MEINS' '',
'ZDDJG' '价格' '' 'ZTSD015' 'ZDDJG' '' ,
'ZDDJE' '金额' '' 'ZTSD015' 'ZDDJG' '',
'ZSL1' '基本单位数量' '' 'LIPS' 'LFIMG' '',
'ZDW1' '基本单位' '' 'MARA' 'MEINS' '',
'ZTHMS' '退货类型' '' '' '' '',
'PSTYV' '行项目类型' '' 'LIPS' 'PSTYV' 'C111',
'AUGRU' '退货原因编码' '' 'TVAU' 'AUGRU' '',
'ZTHYY' '退货原因' '' 'ZTSD015' 'ZTHYY' '',
'ZTHDD' '退货订单号' '' 'ZTSD015' 'ZTHDD' '',
'ZTHDN' '退货交货单' '' 'ZTSD015' 'ZDN' 'C111',
'WBSTK1' '退货状态' '' 'VBUK' 'WBSTK' '', "退货货物移动状态
'FKSTK1' '退货开票状态' '' 'VBUK' 'FKSTK' '', "退货开票状态
'ZMFCK' '免费出库单号' '' 'ZTSD015' 'ZMFCK' '',
'ZDN' '免费交货单号' '' 'ZTSD015' 'ZTHDN' 'C111',
* 'ZTEXT' '发货状态' '' '' '' ''.
'WBSTK2' '免费发货状态' '' 'VBUK' 'WBSTK' '', "免费发货货物移动状态
'FKSTK2' '免费开票状态' '' 'VBUK' 'FKSTK' '', "退货开票状态
'ZUSER' '导入人员' '' 'ZTSD014' 'ZUSER' '',
'ZDATE' '导入日期' '' 'ZTSD014' 'ZDATE' ''.
IF r1 EQ 'X'.
build_fc
:
'ZICON1' '指示灯' '' 'ICON' 'ID' '',
'MSSG' '消息' '' '' '' ''.
ENDIF.
gs_f4
-fieldname = 'CHARG'.
gs_f4
-register = 'X'.
gs_f4
-getbefore = 'X'.
gs_f4
-chngeafter = 'X'.
INSERT gs_f4 INTO TABLE gt_f4.
ENDFORM. " FRM_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
DATA: lv_lines TYPE i.
DESCRIBE TABLE gt_output LINES lv_lines.
SET PF-STATUS '9000' .
SET TITLEBAR 'TITLE01' WITH '条目数:' lv_lines.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
DATA(ok_code) = sy-ucomm.
DATA lv_result TYPE string.
DATA: lt_output TYPE TABLE OF ty_output.
CLEAR lt_output.
CASE ok_code.
WHEN 'SAVE'.
IF r1 NE 'X'.
RETURN.
ENDIF.
PERFORM frm_save_data USING ' ' CHANGING lv_result.
IF lv_result EQ 'S'.
MESSAGE '保存成功!' TYPE 'S'.
*更新内存
lt_output
= gt_output.
EXPORT lt_output TO MEMORY ID 'GT_OUTPUT'.
ELSEIF lv_result EQ 'E'.
MESSAGE '保存失败!' TYPE 'S' DISPLAY LIKE 'E'.
ELSEIF lv_result EQ 'N'.
MESSAGE '数据没有修改!' TYPE 'S'.
ENDIF.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
CALL METHOD gct_alv->refresh_table_display
EXPORTING
is_stable
= gs_stable
i_soft_refresh
= 'X'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module MOD_ALV_DISPLAY OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE mod_alv_display OUTPUT.
IF gctr_alv IS INITIAL.
*创建底层容器
CREATE OBJECT gctr_alv
EXPORTING
repid
= sy-repid
dynnr
= '9000'
side
= cl_gui_docking_container=>dock_at_left "ALV贴屏幕左边,从左边算屏幕宽度,
extension
= 1500 "屏幕宽度
* STYLE = CL_GUI_CONTROL=>WS_CHILD "可选参数,设置ALV是否可用手动拖动大小
EXCEPTIONS
cntl_error
= 1
cntl_system_error
= 2
create_error
= 3
lifetime_error
= 4
lifetime_dynpro_dynpro_link
= 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE s001(00) WITH '屏幕初始化失败'.
LEAVE LIST-PROCESSING.
ENDIF.
*创建ALV控件
CREATE OBJECT gct_alv
EXPORTING
i_parent
= gctr_alv.
IF r6 EQ 'X'.
CALL METHOD gct_alv->set_ready_for_input
EXPORTING
i_ready_for_input
= 0.
ENDIF.
CREATE OBJECT g_event.
*注册自定义工具条
SET HANDLER g_event->toolbar FOR gct_alv.
CALL METHOD gct_alv->register_f4_for_fields
EXPORTING
it_f4
= gt_f4[].
*显示ALV
CALL METHOD gct_alv->set_table_for_first_display
EXPORTING
is_variant
= gs_variant
i_save
= 'A'
i_default
= 'X'
is_layout
= gs_layout
it_toolbar_excluding
= gt_exclude
CHANGING
it_outtab
= gt_output
it_fieldcatalog
= gt_structure[].
*注册F4
SET HANDLER g_event->on_f4 FOR gct_alv.
**注册double click
SET HANDLER g_event->handle_double_click FOR gct_alv.
*注册User command
SET HANDLER g_event->handle_user_command FOR gct_alv.
*注册data_change
* SET HANDLER G_EVENT->HANDLE_DATA_CHANGED FOR GCT_ALV.
* SET HANDLER G_EVENT->HANDLE_CHANGE_FINISH FOR GCT_ALV.
*以下两个方法达到的效果是:光标离开正在编辑的单元格时,就触发handle_data_changed
CALL METHOD gct_alv->register_edit_event
EXPORTING
i_event_id
= cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD gct_alv->register_edit_event
EXPORTING
i_event_id
= cl_gui_alv_grid=>mc_evt_enter.
*
CALL METHOD cl_gui_control=>set_focus "设置焦点在REF_ALVG1上
EXPORTING
control = gct_alv.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form FRM_EXCLUDE_BUTTONS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_exclude_buttons TABLES t_exclude TYPE ui_functions.
CLEAR gt_exclude.
DATA: ls_exclude TYPE ui_func.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_MAXIMUM .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_MINIMUM .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_SUBTOT .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_SUM .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_AVERAGE .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_MB_SUM .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_MB_SUBTOT .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_SORT_ASC.
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_SORT_DSC .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
ls_exclude
= cl_gui_alv_grid=>mc_fc_find .
APPEND ls_exclude TO gt_exclude.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_FILTER .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
ls_exclude
= cl_gui_alv_grid=>mc_fc_print .
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_print_prev .
APPEND ls_exclude TO gt_exclude.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_MB_EXPORT .
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
ls_exclude
= cl_gui_alv_grid=>mc_fc_graph .
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_mb_view .
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_detail .
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_help .
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_info .
APPEND ls_exclude TO gt_exclude.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_MB_VARIANT.
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO gt_exclude.
ls_exclude
= cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO gt_exclude.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
* LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
* APPEND LS_EXCLUDE TO GT_EXCLUDE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SAVE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_save_data USING u_str TYPE string CHANGING c_result TYPE string.
DATA:
lt_ztsd014
TYPE TABLE OF ztsd014,
lt_ztsd015
TYPE TABLE OF ztsd015,
lt_ztsd016
TYPE TABLE OF ztsd016,
lt_output
TYPE TABLE OF ty_output,
ls_ztsd014
TYPE ztsd014, "直营平台-销售退货抬头
ls_ztsd015
TYPE ztsd015, "直营平台-销售退货行项目
ls_ztsd016
TYPE ztsd016, "直营平台-销售退货行项目修改日志
ls_output
TYPE ty_output.
DATA: lv_batno TYPE char10, "批导编号
lv_verno
TYPE char3. "版本号
DATA: check_ok TYPE string.
DATA: check_okay TYPE string.
CLEAR c_result.
CLEAR:
lt_ztsd014
,
lt_ztsd015
,
lt_ztsd016
,
lt_output
,
ls_ztsd014
,
ls_ztsd015
,
ls_ztsd016
,
ls_output
.
*检查数据是否有修改
PERFORM frm_check_changes CHANGING check_okay.
*如果是批导数据,则生成批导序号和版本号
IF r1 EQ 'X'.
*检查是否选择了数据
READ TABLE gt_output TRANSPORTING NO FIELDS WITH KEY sel = 'X'.
IF sy-subrc NE 0.
MESSAGE '请至少选择一条数据!' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
LOOP AT gt_output INTO gs_output WHERE sel = 'X'.
IF gs_output-zicon1 EQ '@0A@'.
MESSAGE '数据有误,请检查。' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
ENDLOOP.
*检查是否当前已经生成了批导流水号
* BREAK-POINT.
IMPORT lv_batno FROM MEMORY ID 'BATNO'.
IF lv_batno IS INITIAL.
*若没有生成则新生成
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr
= '03'
object
= 'ZSD001'
* QUANTITY = '1'
* SUBOBJECT = ' '
* TOYEAR = '0000'
* IGNORE_BUFFER = ' '
IMPORTING
number = lv_batno
* QUANTITY =
* RETURNCODE =
EXCEPTIONS
interval_not_found
= 1
number_range_not_intern
= 2
object_not_found
= 3
quantity_is_0
= 4
quantity_is_not_1
= 5
interval_overflow
= 6
buffer_overflow
= 7
OTHERS = 8.
*将生成的流水号保存到内存
EXPORT lv_batno TO MEMORY ID 'BATNO'.
*新版本号
MOVE 1 TO lv_verno.
*填充抬头表ZTSD014
MOVE lv_batno TO ls_ztsd014-batno.
MOVE sy-uname TO ls_ztsd014-zuser.
MOVE sy-datum TO ls_ztsd014-zdate.
MOVE sy-uzeit TO ls_ztsd014-ztime.
IF r4 EQ 'X'.
MOVE 'A' TO ls_ztsd014-zthlx.
ELSEIF r5 EQ 'X'.
MOVE 'B' TO ls_ztsd014-zthlx.
ENDIF.
MODIFY ztsd014 FROM ls_ztsd014.
*若已生成流水号
ELSEIF lv_batno IS NOT INITIAL
AND check_okay EQ 'F'.
*若没有修改则不进行保存
c_result
= 'N'."表示没有修改
EXIT.
ENDIF.
LOOP AT gt_output INTO gs_output WHERE sel EQ 'X'.
*更新内表
MOVE lv_batno TO gs_output-batno.
IF lv_verno IS NOT INITIAL.
MOVE lv_verno TO gs_output-verno.
ENDIF.
MODIFY gt_output FROM gs_output.
*填充退货订单明细表
MOVE-CORRESPONDING gs_output TO ls_ztsd015.
APPEND ls_ztsd015 TO lt_ztsd015.
CLEAR ls_ztsd015.
*填充退货订单日志表
MOVE-CORRESPONDING gs_output TO ls_ztsd016.
* MOVE LV_BATNO TO LS_ZTSD003-BATNO.
* MOVE LV_VERNO TO LS_ZTSD003-VERNO.
MOVE sy-uname TO ls_ztsd016-zuser.
MOVE sy-datum TO ls_ztsd016-zdate.
MOVE sy-uzeit TO ls_ztsd016-ztime.
APPEND ls_ztsd016 TO lt_ztsd016.
CLEAR ls_ztsd016.
ENDLOOP.
ELSE."IF." R2 EQ 'X' ."如果是显示已导入数据,则检查是否有修改数据
c_result
= 'N'.
* LT_OUTPUT = GT_OUTPUT.
SORT gt_output BY batno."按批导编号排序
* SORT LT_OUTPUT BY BATNO."按批导编号排序
LOOP AT gt_output ASSIGNING <wa_data> WHERE sel EQ 'X'.
ls_output
= <wa_data>.
AT NEW batno.
lv_verno
= ls_output-verno + 1."产生下一个版本,否则C_RESULT EQ SPACE
ls_output
-verno = lv_verno.
*填充抬头表ZTSD014
* MOVE LS_OUTPUT-BATNO TO LS_ZTSD014-BATNO.
* MOVE LS_OUTPUT-ZTHLX TO LS_ZTSD014-ZTHLX.
* MOVE SY-UNAME TO LS_ZTSD014-ZUSER.
* MOVE SY-DATUM TO LS_ZTSD014-ZDATE.
* MOVE SY-UZEIT TO LS_ZTSD014-ZTIME.
*
* MODIFY ZTSD014 FROM LS_ZTSD014.
*按批导编号更新版本号
MODIFY gt_output FROM ls_output TRANSPORTING verno
WHERE batno EQ ls_output-batno.
* CLEAR LS_OUTPUT.
ENDAT.
*填充退货订单日志表
MOVE-CORRESPONDING ls_output TO ls_ztsd016.
* MOVE LS_OUTPUT-BATNO TO LS_ZTSD003-BATNO.
* MOVE LS_OUTPUT-VERNO TO LS_ZTSD003-VERNO.
* MOVE LS_OUTPUT-ZMFCK TO LS_ZTSD016-ZMFCK.
* MOVE LS_OUTPUT-ZTHDD TO LS_ZTSD016-ZTHDD.
MOVE sy-uname TO ls_ztsd016-zuser.
MOVE sy-datum TO ls_ztsd016-zdate.
MOVE sy-uzeit TO ls_ztsd016-ztime.
APPEND ls_ztsd016 TO lt_ztsd016.
CLEAR ls_ztsd016.
*填充退货订单明细表
* MOVE-CORRESPONDING LS_OUTPUT TO LS_ZTSD015.
CLEAR ls_output.
ENDLOOP.
ENDIF.
DELETE gt_output WHERE sel EQ 'X'.
UNASSIGN <wa_data>
.
*更新数据库表
IF lt_ztsd014 IS NOT INITIAL.
MODIFY ztsd014 FROM TABLE lt_ztsd014.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
c_result
= 'S'.
ELSE.
ROLLBACK WORK.
c_result
= 'E'.
ENDIF.
ENDIF.
IF lt_ztsd015 IS NOT INITIAL.
MODIFY ztsd015 FROM TABLE lt_ztsd015.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
c_result
= 'S'.
ELSE.
ROLLBACK WORK.
c_result
= 'E'.
ENDIF.
ENDIF.
IF lt_ztsd016 IS NOT INITIAL.
MODIFY ztsd016 FROM TABLE lt_ztsd016.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
c_result
= 'S'.
ELSE.
ROLLBACK WORK.
c_result
= 'E'.
ENDIF.
ENDIF.
lt_output
= gt_output.
EXPORT lt_output TO MEMORY ID 'GT_OUTPUT'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CONFIRM_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LV_RESULT text
*----------------------------------------------------------------------*
FORM frm_confirm_data CHANGING c_result.
DATA:
* LT_OUTPUT TYPE TABLE OF TY_OUTPUT,
ls_output
TYPE ty_output.
DATA: lv_csyd TYPE char10, "超市验单
lv_so
TYPE vbeln. "SO
DATA: lv_result TYPE string.
CLEAR:c_result,lv_csyd,ls_output.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage
= 0
text = '正在操作销售订单... '.
*整理创建SO的数据
PERFORM frm_prepare_so_data CHANGING lv_result.
*创建SO
IF lv_result EQ 'E'.
c_result
= 'E'.
EXIT.
ENDIF.
PERFORM frm_create_so CHANGING lv_result.
CHECK lv_result EQ 'S'.
MOVE 'S' TO c_result.
LOOP AT gt_sodata INTO gs_sodata.
READ TABLE gt_output ASSIGNING <wa_data>
WITH KEY batno = gs_sodata-batno batpo = gs_sodata-batpo.
IF sy-subrc EQ 0.
* IF R4 EQ 'X'.
IF r2 EQ 'X'.
MOVE: gs_sodata-so TO <wa_data>-zthdd,
gs_sodata
-zdn TO <wa_data>-zthdn
.
ENDIF.
* ELSEIF R5 EQ 'X'.
IF r3 EQ 'X'.
MOVE: gs_sodata-so TO <wa_data>-zmfck,
gs_sodata
-zdn TO <wa_data>-zdn
.
ENDIF.
ENDIF.
ENDLOOP.
PERFORM frm_show_message.
UNASSIGN <wa_data>
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_PREPARE_SO_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_prepare_so_data CHANGING c_result.
DATA:
ls_a515
TYPE a515,
ls_ztsd007
TYPE ztsd007.
DATA: lv_result TYPE string.
DATA lv_msg TYPE string.
CLEAR gt_sodata.
LOOP AT gt_output INTO gs_output WHERE sel EQ 'X' ."AND SO IS INITIAL.
IF r2 EQ 'X' AND gs_output-zthdd NE space.
CONTINUE.
ENDIF.
IF r3 EQ 'X' AND gs_output-zmfck NE space.
CONTINUE.
ENDIF.
MOVE-CORRESPONDING gs_output TO gs_sodata.
gs_sodata
-zstring = gs_sodata-sldto && gs_sodata-shpto && gs_sodata-zyddh && gs_sodata-budat.
MOVE gs_output-menge TO gs_sodata-kpein.
MOVE gs_output-meins TO gs_sodata-kmein.
MOVE '1000' TO gs_sodata-werks.
PERFORM frm_check_partner USING gs_sodata-sldto CHANGING lv_result.
IF lv_result EQ 'E'.
c_result
= 'E'.
RETURN.
ENDIF.
*检查销售组织对应的成本中心是否存在
SELECT SINGLE * INTO ls_ztsd007
FROM ztsd007
WHERE vkbur EQ gs_sodata-vkbur
AND vkgrp EQ gs_sodata-vkgrp.
IF sy-subrc NE 0.
c_result
= 'E'.
* LV_MSG = '售达方' && GS_SODATA-SLDTO && '的销售组' && GS_SODATA-VKBUR && '和销售部门' && GS_SODATA-VKGRP && '对应的成本中心不存在。'.
lv_msg
= '销售组' && gs_sodata-vkbur && '和销售部门' && gs_sodata-vkgrp && '对应的成本中心不存在。'.
MESSAGE s001 WITH lv_msg DISPLAY LIKE 'E'.
* MESSAGE '客户的销售组和销售办部门对应的成本中心不存在。' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
APPEND gs_sodata TO gt_sodata.
CLEAR: gs_sodata,gs_output.
c_result
= 'S'.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_SO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LV_RESULT text
*----------------------------------------------------------------------*
FORM frm_create_so CHANGING c_result.
DATA:lt_sodata TYPE TABLE OF ty_sodata,
ls_sodata
TYPE ty_sodata.
DATA:lv_posnr(6) TYPE n,
lv_string
TYPE string.
DATA: lv_so TYPE vbeln,
* LV_SO1 TYPE VBELN,
lv_dn
TYPE vbeln_vl,
* LV_DN1 TYPE VBELN_VL,
l_update
,
l_kschl
TYPE kschl, "条件类型
l_st_no
TYPE stunr.
DATA: ls_output TYPE ty_output.
DATA:
ls_header
TYPE bapisdhd1,
ls_headerx
TYPE bapisdhd1x,
testrun
TYPE bapiflag-bapiflag VALUE 'X',
lt_return
TYPE TABLE OF bapiret2,
ls_return
TYPE bapiret2,
lt_item
TYPE TABLE OF bapisditm,
ls_item
TYPE bapisditm,
lt_itemx
TYPE TABLE OF bapisditmx,
ls_itemx
TYPE bapisditmx,
lt_pnr
TYPE TABLE OF bapiparnr,
ls_pnr
TYPE bapiparnr,
lt_sch
TYPE TABLE OF bapischdl,
ls_sch
TYPE bapischdl,
lt_schx
TYPE TABLE OF bapischdlx,
ls_schx
TYPE bapischdlx,
lt_cond
TYPE TABLE OF bapicond,
ls_cond
TYPE bapicond,
lt_condx
TYPE TABLE OF bapicondx,
ls_condx
TYPE bapicondx.
DATA: lt_so_item TYPE TABLE OF bapidlvreftosalesorder,
ls_so_item
TYPE bapidlvreftosalesorder.
* DATA: LV_POSNR TYPE POSNR.
DATA: status_buff_init TYPE c VALUE 'X',
call_activity
(4), " Aktiver Aufrufer bei Call
g_no_dequeue_sd_sales
TYPE c.
* DATA: LV_POSNR TYPE POSNR.
CALL FUNCTION 'RV_DELIVERY_INIT'
EXPORTING
status_buff_init
= status_buff_init
i_call_activity
= call_activity
if_no_deque
= g_no_dequeue_sd_sales.
SORT gt_sodata BY zstring.
* PERFORM FRM_CHECK_SODATA CHANGING C_RESULT.
LOOP AT gt_sodata ASSIGNING <wa_sodata>.
*做标记
<wa_sodata>
-so = 'X'.
<wa_sodata>
-zdn = 'X'.
* <WA_SODATA>-SO1 = 'X'.
* <WA_SODATA>-ZDN1 = 'X'.
*
ls_sodata
= <wa_sodata>.
ADD 10 TO lv_posnr.
ls_item
-itm_number = lv_posnr.
ls_item
-material = <wa_sodata>-matnr.
ls_item
-target_qty = <wa_sodata>-menge.
ls_item
-plant = <wa_sodata>-werks.
ls_item
-store_loc = <wa_sodata>-lgort.
ls_item
-target_qu = <wa_sodata>-meins.
ls_item
-sales_unit = <wa_sodata>-meins.
ls_item
-purch_no_s = <wa_sodata>-key.
* IF <wa_sodata>-key IS NOT INITIAL.
*
* IF r3 EQ 'X'.
* SELECT SINGLE vbeln INTO @DATA(lv_vbelnso)
* FROM vbkd
* WHERE bstkd_e EQ @<wa_sodata>-key AND bstkd EQ 'WFZYTH'.
* IF sy-subrc EQ 0.
* MESSAGE '已有免费订单:' && lv_vbelnso && '生成!' TYPE 'S' DISPLAY LIKE 'E'.
* EXIT.
* ENDIF.
* ENDIF.
*
** IF r2 EQ 'X'.
** SELECT SINGLE vbeln INTO @DATA(lv_vbelnso1)
** FROM vbkd
** WHERE bstkd_e EQ @<wa_sodata>-key AND bstkd NE 'WFZYTH'.
** IF sy-subrc EQ 0.
** MESSAGE '已有退货订单:' && lv_vbelnso1 && '生成!' TYPE 'S' DISPLAY LIKE 'E'.
** EXIT.
** ENDIF.
** ENDIF.
*
* ENDIF.
IF r5 EQ 'X' OR r4 EQ 'X'.
*检查物料是否启用了批次管理
SELECT SINGLE xchpf INTO @DATA(xchpf)
FROM mara
WHERE matnr EQ @ls_item-material.
IF xchpf EQ 'X'.
ls_item
-batch = gv_charg.
IF R4 EQ 'X'.
ls_item
-batch = gv_charg1.
ENDIF.
ls_itemx
-batch = 'X'.
ENDIF.
ENDIF.
* LS_ITEM-SHIP_POINT = <WA_SODATA>-LGORT."装运点与库存地点相同
IF r3 EQ 'X'."
ls_item
-item_categ = 'ZTN1'.
ls_itemx
-item_categ = 'X'.
ENDIF.
IF r2 EQ 'X'."实退需指定行项目类型
ls_item
-item_categ = <wa_sodata>-pstyv.
ls_itemx
-item_categ = 'X'.
ENDIF.
APPEND ls_item TO lt_item.
CLEAR ls_item.
ls_itemx
-itm_number = lv_posnr.
ls_itemx
-material = 'X'.
ls_itemx
-target_qty = 'X'.
ls_itemx
-plant = 'X'.
ls_itemx
-store_loc = 'X'.
ls_itemx
-target_qu = 'X'.
ls_itemx
-sales_unit = 'X'.
ls_itemx
-purch_no_s = 'X'.
* LS_ITEMX-SHIP_POINT = 'X'.
APPEND ls_itemx TO lt_itemx.
CLEAR ls_itemx.
ls_pnr
-partn_role = 'AG'." 'SP'."售达方
ls_pnr
-partn_numb = <wa_sodata>-sldto.
APPEND ls_pnr TO lt_pnr.
CLEAR ls_pnr.
ls_pnr
-partn_role = 'WE'." 'SH'."送达方
ls_pnr
-partn_numb = <wa_sodata>-shpto.
APPEND ls_pnr TO lt_pnr.
CLEAR ls_pnr.
ls_sch
-itm_number = lv_posnr.
ls_sch
-sched_line = 1.
ls_sch
-req_qty = <wa_sodata>-menge.
APPEND ls_sch TO lt_sch.
CLEAR ls_sch.
ls_schx
-itm_number = lv_posnr.
ls_schx
-sched_line = 1.
ls_schx
-req_qty = 'X'.
APPEND ls_schx TO lt_schx.
CLEAR ls_schx.
*费用类型退货不需要检查手工条件
IF <wa_sodata>-pstyv NE 'REN4'.
PERFORM get_kschl(zsdr021)
USING 'ZRE1'
<wa_sodata>
-vkorg
<wa_sodata>
-vtweg
<wa_sodata>
-spart
<wa_sodata>
-sldto
CHANGING l_kschl l_update l_st_no.
ls_cond
-itm_number = lv_posnr.
ls_cond
-cond_st_no = l_st_no.
ls_cond
-cond_count = 1.
ls_cond
-cond_type = l_kschl.
ls_cond
-cond_updat = l_update.
* LS_COND-COND_VALUE = <WA_SODATA>-ZDDJG.
ls_cond
-cond_value = <wa_sodata>-zddje.
ls_cond
-cond_p_unt = <wa_sodata>-kpein.
ls_cond
-cond_unit = <wa_sodata>-kmein.
*LS_COND-CONDCHAMAN = 'X'.
ls_cond
-currency = 'CNY'.
APPEND ls_cond TO lt_cond.
CLEAR ls_cond.
ls_condx
-itm_number = lv_posnr.
ls_condx
-cond_st_no = l_st_no.
ls_condx
-cond_count = 1.
ls_condx
-cond_type = l_kschl.
ls_condx
-updateflag = l_update.
ls_condx
-cond_value = 'X'.
ls_condx
-cond_p_unt = 'X'.
ls_condx
-cond_unit = 'X'.
APPEND ls_condx TO lt_condx.
CLEAR ls_condx.
ENDIF.
UPDATE ztsd015 SET zthdd = 'X'
WHERE batno EQ <wa_sodata>-batno
AND batpo EQ <wa_sodata>-batpo.
AT END OF zstring.
CLEAR lv_posnr.
ls_header
-sales_org = <wa_sodata>-vkorg.
ls_header
-distr_chan = <wa_sodata>-vtweg.
ls_header
-division = <wa_sodata>-spart.
ls_header
-sales_grp = <wa_sodata>-vkgrp.
ls_header
-sales_off = <wa_sodata>-vkbur.
ls_header
-ord_reason = <wa_sodata>-augru."退货原因
ls_header
-purch_no_s = <wa_sodata>-zyddh.
ls_header
-purch_no_c = 'WFZYTH'.
*实退
*SO
IF r2 EQ 'X'.
ls_header
-doc_type = 'ZRE1'."不关联退货订单
PERFORM frm_create_returnso
TABLES lt_item lt_itemx lt_pnr lt_sch lt_schx lt_cond lt_condx
USING ls_header
CHANGING lv_so c_result.
*创建DN
IF c_result EQ 'S'.
"WAIT UP TO 1 SECONDS.
DO 1000 TIMES.
SELECT SINGLE vbeln INTO @DATA(kk)
FROM vbak
WHERE vbeln EQ @lv_so.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ENDDO.
"IF sy-subrc EQ 0.
"PERFORM frm_create_dn USING lv_so CHANGING lv_dn c_result.
"ENDIF.
PERFORM frm_create_dn(zsdr006)
USING lv_so CHANGING lv_dn c_result.
ENDIF.
CALL FUNCTION 'RV_DELIVERY_INIT'
EXPORTING
status_buff_init
= status_buff_init
i_call_activity
= call_activity
if_no_deque
= g_no_dequeue_sd_sales.
WAIT UP TO 1 SECONDS.
IF lv_so IS NOT INITIAL.
IF lv_dn IS INITIAL.
DO 1000 TIMES.
SELECT SINGLE vbeln INTO lv_dn FROM vbfa
WHERE ( vbelv EQ lv_so
AND vbtyp_n EQ 'J' )
OR ( vbelv EQ lv_so
AND vbtyp_n EQ 'T' ).
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ENDDO.
ENDIF.
PERFORM frm_modify_sodata USING lv_so lv_dn
CHANGING c_result.
ENDIF.
ENDIF.
*空退后继免费
IF r3 EQ 'X'.
ls_header
-doc_type = 'ZSD9'."后继免费订单
*SO
PERFORM frm_create_returnso1
TABLES lt_item lt_itemx lt_pnr lt_sch lt_schx lt_cond lt_condx
USING ls_header
CHANGING lv_so c_result.
*DN
IF c_result EQ 'S'.
DO 1000 TIMES.
SELECT SINGLE vbeln INTO @DATA(kkk)
FROM vbak
WHERE vbeln EQ @lv_so.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ENDDO.
"IF sy-subrc EQ 0.
"PERFORM frm_create_dn USING lv_so CHANGING lv_dn c_result.
"ENDIF.
PERFORM frm_create_dn(zsdr006)
USING lv_so CHANGING lv_dn c_result.
ENDIF.
CALL FUNCTION 'RV_DELIVERY_INIT'
EXPORTING
status_buff_init
= status_buff_init
i_call_activity
= call_activity
if_no_deque
= g_no_dequeue_sd_sales.
WAIT UP TO 1 SECONDS.
IF lv_so IS NOT INITIAL.
IF lv_dn IS INITIAL.
DO 1000 TIMES.
SELECT SINGLE vbeln INTO lv_dn FROM vbfa
WHERE ( vbelv EQ lv_so
AND vbtyp_n EQ 'J' )
OR ( vbelv EQ lv_so
AND vbtyp_n EQ 'T' ).
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ENDDO.
ENDIF.
PERFORM frm_modify_sodata USING lv_so lv_dn
CHANGING c_result.
ENDIF.
ENDIF.
CLEAR: lt_return,
lt_item
,
lt_itemx
,
lt_pnr
,
lt_sch
,
lt_schx
,
lt_cond
,
lt_condx
,
ls_header
.
ENDAT.
ENDLOOP.
UNASSIGN <wa_sodata>
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_CHANGES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_CHECK_OKAY text
*----------------------------------------------------------------------*
FORM frm_check_changes CHANGING c_ok TYPE string.
DATA: lt_output TYPE TABLE OF ty_output,
lt_output1
TYPE TABLE OF ty_output.
DATA: ls_output TYPE ty_output,
ls_output1
TYPE ty_output.
MOVE 'F' TO c_ok.
CLEAR: lt_output,lt_output1.
*从内存读取最初的内表
IMPORT lt_output FROM MEMORY ID 'GT_OUTPUT'.
*将当前全局内表赋予本地内表
lt_output1
= gt_output.
*排序
* SORT: LT_OUTPUT1 BY INDAT KUNNR ZCSDD.
SORT: lt_output BY batno batpo.
*检查勾选项是否有修改
LOOP AT lt_output1 INTO ls_output1 WHERE sel EQ 'X'.
READ TABLE lt_output INTO ls_output
WITH KEY batno = ls_output1-batno
batpo
= ls_output1-batpo BINARY SEARCH.
IF sy-subrc EQ 0.
*比较当前数据与初始数据是否有区别
CLEAR: ls_output1-sel,
ls_output
-sel.
IF ls_output1 NE ls_output.
MOVE 'T' TO c_ok."有区别
EXIT."只要有一个数据有区别就要记录
ELSE.
MOVE 'F' TO c_ok."没有区别
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_POST_GOODS_ISSUE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_post_dn USING u_dn TYPE vbeln_vl.
DATA: lt_sodata TYPE TABLE OF ty_sodata,
ls_sodata
TYPE ty_sodata.
DATA: lv_result TYPE c,
lv_vbeln
TYPE vbeln_vl,
lv_posnr
TYPE posnr.
DATA: lv_tstmp TYPE tzntstmps.
DATA:
lv_vbkok
TYPE vbkok,
lv_wabuc
TYPE wabuc VALUE 'X',
lt_vbpok
TYPE TABLE OF vbpok,
ls_vbpok
TYPE vbpok,
lt_prott
TYPE TABLE OF prott WITH HEADER LINE,
ls_prott
TYPE prott,
lt_return
TYPE TABLE OF bapiret2,
wa_return
TYPE bapiret2
.
* LT_SODATA = GT_SODATA.
*
* SORT LT_SODATA BY ZDN.
*
* DELETE ADJACENT DUPLICATES FROM LT_SODATA COMPARING ZDN.
*
* LOOP AT LT_SODATA INTO LS_SODATA.
* LV_VBELN = LS_SODATA-ZDN.
lv_vbeln
= u_dn.
UNPACK lv_vbeln TO lv_vbeln.
lv_posnr
= 10.
lv_vbkok
-vbeln_vl = lv_vbeln .
* LV_VBKOK-KOMUE = 'X' .
lv_vbkok
-wabuc = lv_wabuc .
lv_vbkok
-wadat_ist = <wa_sodata>-budat .
lv_vbkok
-bldat = <wa_sodata>-budat .
WAIT UP TO 1 SECONDS.
CALL FUNCTION 'SD_DELIVERY_UPDATE_PICKING'
EXPORTING
vbkok_wa
= lv_vbkok
* SYNCHRON = ' '
* NO_MESSAGES_UPDATE = ' '
* NICHT_SPERREN = ' '
* AUFRUFER_T = ' '
* IF_ERROR_MESSAGES_SEND = 'X'
TABLES
vbpok_tab
= lt_vbpok[]
prot
= lt_prott[].
READ TABLE lt_prott TRANSPORTING NO FIELDS WITH KEY msgty = 'E'.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT lt_prott WHERE msgty EQ 'E'.
CLEAR wa_return.
wa_return
-type = 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= lt_prott-msgid
msgnr
= lt_prott-msgno
msgv1
= lt_prott-msgv1
msgv2
= lt_prott-msgv2
msgv3
= lt_prott-msgv3
msgv4
= lt_prott-msgv4
IMPORTING
message_text_output
= wa_return-message.
APPEND wa_return TO gdt_return.
CLEAR lt_prott.
ENDLOOP.
RETURN.
ENDIF.
CLEAR wa_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = wa_return.
IF wa_return-type EQ 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
APPEND wa_return TO lt_return.
EXPORT lt_return TO MEMORY ID 'LT_RETURN'.
PERFORM frm_show_message.
* C_RESULT = 'E'.
EXIT.
ELSE.
* C_RESULT = 'S'.
* RETURN.
ENDIF.
* ENDLOOP.
CLEAR: lv_vbkok,lt_vbpok,lt_prott.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR gds_bdcdata.
gds_bdcdata
-program = program.
gds_bdcdata
-dynpro = dynpro.
gds_bdcdata
-dynbegin = 'X'.
APPEND gds_bdcdata TO gdt_bdcdata.
ENDFORM. "bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR gds_bdcdata.
gds_bdcdata
-fnam = fnam.
gds_bdcdata
-fval = fval.
CONDENSE gds_bdcdata-fval NO-GAPS.
APPEND gds_bdcdata TO gdt_bdcdata.
ENDFORM. "bdc_field
*&---------------------------------------------------------------------*
*& Form FRM_OUT_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_out_message .
LOOP AT gdt_return INTO gds_return.
WRITE:gds_return-type, gds_return-message.
ENDLOOP.
ENDFORM. " FRM_OUT_MESSAGE
*&---------------------------------------------------------------------*
*& Form GET_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GDS_MESSTAB text
* <--P_G_MESSAGE text
*----------------------------------------------------------------------*
FORM get_message USING u_message TYPE bdcmsgcoll
CHANGING cg_message TYPE balmsgtxtp.
CLEAR cg_message.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= u_message-msgid
msgnr
= u_message-msgnr
msgv1
= u_message-msgv1
msgv2
= u_message-msgv2
msgv3
= u_message-msgv3
msgv4
= u_message-msgv4
IMPORTING
message_text_output
= cg_message.
ENDFORM. " GET_MESSAGE
*&---------------------------------------------------------------------*
*& Form FRM_CALL_TRANSACTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*FORM FRM_CALL_TRANSACTION CHANGING C_SO TYPE VBELN
* C_DN TYPE VBELN_VL.
** DATA L_MODE TYPE C VALUE 'N'.
** BREAK B012.
* CALL TRANSACTION 'VA01' USING GDT_BDCDATA MODE P_MODE MESSAGES INTO GDT_MESSTAB.
*
* LOOP AT GDT_MESSTAB INTO GDS_MESSTAB.
**提取SO和DN号
* IF GDS_MESSTAB-MSGTYP EQ 'S'.
* MOVE GDS_MESSTAB-MSGV3+0(10) TO C_DN.
* MOVE GDS_MESSTAB-MSGV2+0(10) TO C_SO.
*
* CONDENSE C_DN NO-GAPS.
* CONDENSE C_SO NO-GAPS.
* ENDIF.
* PERFORM GET_MESSAGE USING GDS_MESSTAB
* CHANGING G_MESSAGE .
* GDS_RETURN-TYPE = GDS_MESSTAB-MSGTYP.
** CONCATENATE GS_OUTPUT-IDNRK GS_OUTPUT-POSNR G_MESSAGE INTO GDS_RETURN-MESSAGE SEPARATED BY ''.
* MOVE G_MESSAGE TO GDS_RETURN-MESSAGE.
* APPEND GDS_RETURN TO GDT_RETURN.
* CLEAR GDS_RETURN.
* CLEAR G_MESSAGE.
* ENDLOOP.
* SORT GDT_RETURN BY MESSAGE.
* DELETE ADJACENT DUPLICATES FROM GDT_RETURN COMPARING MESSAGE.
*
*ENDFORM. " FRM_CALL_TRANSACTION
*&---------------------------------------------------------------------*
*& Form FRM_CALL_TRANSACTION1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*FORM FRM_CALL_TRANSACTION1 CHANGING C_RESULT TYPE C .
* CLEAR:GDT_MESSTAB.
*
* CALL TRANSACTION 'VL02N' USING GDT_BDCDATA MODE P_MODE MESSAGES INTO GDT_MESSTAB.
* LOOP AT GDT_MESSTAB INTO GDS_MESSTAB.
* PERFORM GET_MESSAGE USING GDS_MESSTAB
* CHANGING G_MESSAGE .
* GDS_RETURN-TYPE = GDS_MESSTAB-MSGTYP.
* IF GDS_MESSTAB-MSGTYP EQ 'E'.
* C_RESULT = 'E'.
* ELSEIF GDS_MESSTAB-MSGTYP EQ 'S'.
* C_RESULT = 'S'.
* ENDIF.
*
** CONCATENATE GS_OUTPUT-IDNRK GS_OUTPUT-POSNR G_MESSAGE INTO GDS_RETURN-MESSAGE SEPARATED BY ''.
* MOVE G_MESSAGE TO GDS_RETURN-MESSAGE.
* APPEND GDS_RETURN TO GDT_RETURN.
* CLEAR GDS_RETURN.
* CLEAR G_MESSAGE.
*
* ENDLOOP.
* SORT GDT_RETURN BY MESSAGE.
* DELETE ADJACENT DUPLICATES FROM GDT_RETURN COMPARING MESSAGE.
*
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CALL_TRANSACTION2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*FORM FRM_CALL_TRANSACTION2 .
* CLEAR: GDT_MESSTAB.
** BREAK B012.
* WAIT UP TO 1 SECONDS.
*
* CALL TRANSACTION 'VF01' USING GDT_BDCDATA MODE P_MODE MESSAGES INTO GDT_MESSTAB.
*
* LOOP AT GDT_MESSTAB INTO GDS_MESSTAB.
* PERFORM GET_MESSAGE USING GDS_MESSTAB
* CHANGING G_MESSAGE .
* GDS_RETURN-TYPE = GDS_MESSTAB-MSGTYP.
** CONCATENATE GS_OUTPUT-IDNRK GS_OUTPUT-POSNR G_MESSAGE INTO GDS_RETURN-MESSAGE SEPARATED BY ''.
* MOVE G_MESSAGE TO GDS_RETURN-MESSAGE.
* APPEND GDS_RETURN TO GDT_RETURN.
* CLEAR GDS_RETURN.
* CLEAR G_MESSAGE.
* ENDLOOP.
* SORT GDT_RETURN BY MESSAGE.
* DELETE ADJACENT DUPLICATES FROM GDT_RETURN COMPARING MESSAGE.
*
*
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SHOW_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_show_message .
DATA lv_title TYPE string.
DATA:lt_return TYPE TABLE OF bapiret2,
ls_return
TYPE bapiret2,
ls_layout
TYPE slis_layout_alv.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.
CLEAR: lt_return,ls_layout.
CLEAR:lt_fieldcat.
ls_layout
-zebra = 'X'.
ls_layout
-colwidth_optimize = 'A'.
PERFORM frm_set_catalog CHANGING lt_fieldcat.
IMPORT lt_return FROM MEMORY ID 'LT_RETURN'.
APPEND LINES OF gdt_return TO lt_return.
CHECK lt_return IS NOT INITIAL.
lv_title
= '退货操作日志'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout
= ls_layout
it_fieldcat
= lt_fieldcat
i_screen_start_column
= 10
i_screen_start_line
= 1
i_screen_end_column
= 120
i_screen_end_line
= 25
TABLES
t_outtab
= lt_return
EXCEPTIONS
program_error
= 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
FREE MEMORY ID 'LT_RETURN'.
REFRESH gdt_return.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LT_FIELDCAT text
*----------------------------------------------------------------------*
FORM frm_set_catalog CHANGING c_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
DEFINE add_fieldcat.
LS_FIELDCAT
-FIELDNAME = &1.
LS_FIELDCAT
-SELTEXT_L = &2.
APPEND LS_FIELDCAT TO C_FIELDCAT.
CLEAR LS_FIELDCAT.
END-OF-DEFINITION.
add_fieldcat
:
'TYPE' '消息类型',
'NUMBER' '消息编号',
'MESSAGE' '消息文本',
'MESSAGE_V1' '消息变量',
'MESSAGE_V2' '消息变量',
'MESSAGE_V3' '消息变量',
'MESSAGE_V4' '消息变量',
'PARAMETER' '参数名称',
'ROW' '参数中的行',
'FIELD' '参数中的字段'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_POST_UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_post_upload .
DATA: lt_output TYPE TABLE OF ty_output.
DATA: lv_meins TYPE mara-meins.
DATA: l_line1 TYPE i,
l_line2
TYPE i.
DATA:
lv_string1
TYPE string,
s1
TYPE string,
s2
TYPE string.
DATA:
lv_zthlx_con
TYPE string.
CLEAR: lt_output,lt_output[].
APPEND LINES OF gt_output TO lt_output.
SORT lt_output BY zyddh sldto shpto matnr.
DELETE ADJACENT DUPLICATES FROM lt_output COMPARING zyddh sldto shpto matnr.
l_line1
= lines( gt_output[] ).
l_line2
= lines( lt_output[] ).
IF l_line1 NE l_line2.
CLEAR gs_output.
gs_output
-zicon1 = '@0A@'.
CONCATENATE gs_output-mssg '数据存在重复' INTO gs_output-mssg.
MODIFY gt_output FROM gs_output TRANSPORTING zicon1 mssg WHERE matnr IS NOT INITIAL.
ENDIF.
CLEAR: lt_output,lt_output[].
IF gt_output IS NOT INITIAL.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_knvp
FROM knvp
FOR ALL ENTRIES IN gt_output
WHERE kunnr EQ gt_output-sldto
AND parvw EQ 'WE'.
ENDIF.
SORT gt_knvp BY kunnr kunn2.
LOOP AT gt_output ASSIGNING <wa_data> WHERE zicon1 NE '@0A@'."红灯.
*检查单位是否为空
IF <wa_data>-meins IS INITIAL.
PERFORM set_callsytle USING 12 gs_load '单位不能为空' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
*判断数量是否含小数
IF <wa_data>-menge IS NOT INITIAL.
lv_string1
= <wa_data>-menge.
SPLIT lv_string1 AT '.' INTO s1 s2.
IF s2 NE 0.
PERFORM set_callsytle USING 17 gs_load '数量不能有小数' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
ENDIF.
* TRANSLATE <WA_DATA>-ZYDDH TO UPPER CASE.
IF r4 EQ 'X'."实退
lv_zthlx_con
= 'B~ZTHLX EQ ''A'''.
* <WA_DATA>-ZTHLX = 'A'.
* <WA_DATA>-ZTHMS = '实退'.
ELSEIF r5 EQ 'X'.
lv_zthlx_con
= 'B~ZTHLX EQ ''B'''.
* <WA_DATA>-ZTHLX = 'B'."空退
* <WA_DATA>-ZTHMS = '空退'.
ENDIF.
*****检查是否存在重复 的已导入
SELECT SINGLE zyddh INTO <wa_data>-zyddh
FROM ztsd015 AS a
INNER
JOIN ztsd014 AS b
ON a~batno EQ b~batno
WHERE zyddh = <wa_data>-zyddh
AND (lv_zthlx_con)
AND sldto = <wa_data>-sldto
AND matnr = <wa_data>-matnr.
IF sy-subrc EQ 0.
<wa_data>
-zicon1 = '@0A@'.
<wa_data>
-mssg = '系统已存在该条目'.
CONTINUE.
ENDIF.
IF <wa_data>-pstyv IS INITIAL.
PERFORM set_callsytle USING 9 gs_load '行项目类型不能为空' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
IF <wa_data>-zr IS INITIAL.
PERFORM set_callsytle USING 5 gs_load '主任不能为空' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
IF <wa_data>-zywy IS INITIAL.
PERFORM set_callsytle USING 5 gs_load '业务员不能为空' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
IF <wa_data>-lgort IS INITIAL.
PERFORM set_callsytle USING 8 gs_load '库存地点不能为空' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
IF <wa_data>-augru IS INITIAL.
PERFORM set_callsytle USING 7 gs_load '退货原因不能为空' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
IF <wa_data>-zyddh IS INITIAL.
PERFORM set_callsytle USING 6 gs_load '退单号不能为空' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
ENDIF.
*****
* SELECT SINGLE meins INTO lv_meins
* FROM mara
* WHERE matnr EQ <wa_data>-matnr.
**数量单位转换
*
* TRANSLATE <wa_data>-meins TO UPPER CASE.
*
* CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
* EXPORTING
* i_matnr = <wa_data>-matnr
* i_in_me = <wa_data>-meins
* i_out_me = lv_meins
* i_menge = <wa_data>-menge
* IMPORTING
* e_menge = <wa_data>-menge
* EXCEPTIONS
* error_in_application = 1
* error = 2
* OTHERS = 3.
* IF sy-subrc <> 0.
** Implement suitable error handling here
* ENDIF.
*
* MOVE lv_meins TO <wa_data>-meins.
* MODIFY GT_OUTPUT FROM GS_OUTPUT TRANSPORTING MENGE MEINS.
* CLEAR GS_OUTPUT.
* IF <WA_DATA>-SHPTO IS INITIAL.
* MOVE <WA_DATA>-KUNNR TO <WA_DATA>-SHPTO.
*
* SELECT SINGLE NAME1 INTO <WA_DATA>-NAME2
* FROM KNA1
* WHERE KUNNR EQ <WA_DATA>-KUNNR
** AND KTOKD EQ 'Z003'
* .
*
* ENDIF.
* IF <WA_DATA>-SLDTO IS INITIAL.
* MOVE <WA_DATA>-KUNNR TO <WA_DATA>-SLDTO.
* ENDIF.
READ TABLE gt_knvp INTO gs_knvp WITH KEY kunnr = <wa_data>-sldto kunn2 = <wa_data>-shpto BINARY SEARCH.
IF sy-subrc NE 0 .
PERFORM set_callsytle(zsdr006) USING 10 gs_load '客户与送达方没有对应关系' CHANGING <wa_data>-cellcolor <wa_data>-mssg.
<wa_data>
-zicon1 = '@0A@'."红灯
ENDIF.
SELECT SINGLE name1 INTO <wa_data>-name3
FROM kna1
WHERE kunnr EQ <wa_data>-sldto
* AND KTOKD EQ 'Z003'
.
IF r4 EQ 'X'."实退
<wa_data>
-zthlx = 'A'.
<wa_data>
-zthms = '实退'.
ELSEIF r5 EQ 'X'.
<wa_data>
-zthlx = 'B'."空退
<wa_data>
-zthms = '空退'.
ENDIF.
SELECT SINGLE lgobe INTO <wa_data>-lgobe
FROM t001l
WHERE lgort EQ <wa_data>-lgort
AND werks EQ '1000'.
* <WA_DATA>-ZDDJE = <WA_DATA>-ZDDJG * <WA_DATA>-MENGE.
<wa_data>
-zddjg = <wa_data>-zddje / <wa_data>-menge.
IF <wa_data>-mssg IS NOT INITIAL.
<wa_data>
-zicon1 = '@0A@'."红灯
ELSE.
<wa_data>
-zicon1 = '@08@'."绿灯
ENDIF.
IF <wa_data>-zicon1 = '@0A@'."红灯
MOVE '-' TO <wa_data>-sel.
PERFORM set_style USING 'SEL' 'DISABLE' CHANGING <wa_data>-style.
ENDIF.
ENDLOOP.
UNASSIGN <wa_data>
.
*将初始内表放入内存
lt_output
= gt_output.
EXPORT gt_output TO MEMORY ID 'GT_OUTPUT'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_SODATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_C_RESULT text
*----------------------------------------------------------------------*
FORM frm_check_sodata CHANGING c_result.
DATA:
ls_header
TYPE bapisdhd1,
ls_headerx
TYPE bapisdhd1x,
testrun
TYPE bapiflag-bapiflag VALUE 'X',
lt_return
TYPE TABLE OF bapiret2,
ls_return
TYPE bapiret2,
lt_item
TYPE TABLE OF bapisditm,
ls_item
TYPE bapisditm,
lt_itemx
TYPE TABLE OF bapisditmx,
ls_itemx
TYPE bapisditmx,
lt_pnr
TYPE TABLE OF bapiparnr,
ls_pnr
TYPE bapiparnr,
lt_sch
TYPE TABLE OF bapischdl,
ls_sch
TYPE bapischdl,
lt_schx
TYPE TABLE OF bapischdlx,
ls_schx
TYPE bapischdlx
.
DATA: lv_posnr TYPE posnr.
* LOOP AT GT_SODATA ASSIGNING <WA_SODATA>.
*
* ADD 10 TO LV_POSNR.
*
* LS_ITEM-ITM_NUMBER = LV_POSNR.
* LS_ITEM-MATERIAL = <WA_SODATA>-MATNR.
* LS_ITEM-TARGET_QTY = <WA_SODATA>-MENGE.
* LS_ITEM-PLANT = <WA_SODATA>-WERKS.
* LS_ITEM-STORE_LOC = <WA_SODATA>-LGORT.
* LS_ITEM-TARGET_QU = <WA_SODATA>-MEINS.
* LS_ITEM-BATCH = <WA_SODATA>-CHARG.
* LS_ITEM-SHIP_POINT = <WA_SODATA>-LGORT."装运点与库存地点相同
** LS_ITEM-ITEM_CATEG = 'REN'.
* APPEND LS_ITEM TO LT_ITEM.
* CLEAR LS_ITEM.
*
* LS_ITEMX-ITM_NUMBER = LV_POSNR.
* LS_ITEMX-MATERIAL = 'X'.
* LS_ITEMX-TARGET_QTY = 'X'.
* LS_ITEMX-PLANT = 'X'.
* LS_ITEMX-STORE_LOC = 'X'.
* LS_ITEMX-TARGET_QU = 'X'.
* LS_ITEMX-BATCH = 'X'.
* LS_ITEMX-SHIP_POINT = 'X'.
** LS_ITEMX-ITEM_CATEG = 'X'.
* APPEND LS_ITEMX TO LT_ITEMX.
* CLEAR LS_ITEMX.
*
* LS_PNR-PARTN_ROLE = 'AG'." 'SP'."售达方
* LS_PNR-PARTN_NUMB = <WA_SODATA>-SLDTO.
* APPEND LS_PNR TO LT_PNR.
* CLEAR LS_PNR.
*
* LS_PNR-PARTN_ROLE = 'WE'." 'SH'."送达方
* LS_PNR-PARTN_NUMB = <WA_SODATA>-SHPTO.
* APPEND LS_PNR TO LT_PNR.
* CLEAR LS_PNR.
*
* LS_SCH-ITM_NUMBER = LV_POSNR.
* LS_SCH-SCHED_LINE = 1.
* LS_SCH-REQ_QTY = <WA_SODATA>-MENGE.
*
* APPEND LS_SCH TO LT_SCH.
* CLEAR LS_SCH.
*
* LS_SCHX-ITM_NUMBER = LV_POSNR.
* LS_SCHX-SCHED_LINE = 1.
* LS_SCHX-REQ_QTY = 'X'.
*
* APPEND LS_SCHX TO LT_SCHX.
* CLEAR LS_SCHX.
*
* AT END OF KUNNR.
*
* CLEAR LV_POSNR.
*
* LS_HEADER-DOC_TYPE = 'ZRE1'."不关联退货订单
* LS_HEADER-SALES_ORG = <WA_SODATA>-VKORG.
* LS_HEADER-DISTR_CHAN = <WA_SODATA>-VTWEG.
* LS_HEADER-DIVISION = <WA_SODATA>-SPART.
* LS_HEADER-SALES_GRP = <WA_SODATA>-VKGRP.
* LS_HEADER-SALES_OFF = <WA_SODATA>-VKBUR.
* LS_HEADER-ORD_REASON = <WA_SODATA>-AUGRU."退货原因
**实退
* CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
* EXPORTING
* SALES_HEADER_IN = LS_HEADER
** SALES_HEADER_INX =
* TESTRUN = TESTRUN
* TABLES
* RETURN = LT_RETURN
* SALES_ITEMS_IN = LT_ITEM
* SALES_ITEMS_INX = LT_ITEMX
* SALES_PARTNERS = LT_PNR.
**空退后继免费
* IF R5 EQ 'X'.
* LS_HEADER-DOC_TYPE = 'ZSD9'."后继免费订单
*
* CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
* EXPORTING
* ORDER_HEADER_IN = LS_HEADER
* TESTRUN = TESTRUN
* TABLES
* RETURN = LT_RETURN
* ORDER_ITEMS_IN = LT_ITEM
* ORDER_ITEMS_INX = LT_ITEMX
* ORDER_PARTNERS = LT_PNR
* ORDER_SCHEDULES_IN = LT_SCH
* ORDER_SCHEDULES_INX = LT_SCHX.
*
* ENDIF.
* ENDAT.
*
* READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'W'.
* IF SY-SUBRC EQ 0.
* C_RESULT = 'E'.
*
* EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
* PERFORM FRM_SHOW_MESSAGE.
* RETURN.
* ENDIF.
*
* READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
*
* IF SY-SUBRC EQ 0.
* C_RESULT = 'E'.
*
* EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
* PERFORM FRM_SHOW_MESSAGE.
* RETURN.
* ELSE.
* C_RESULT = 'S'.
* ENDIF.
* ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_BILLING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LV_RESULT text
*----------------------------------------------------------------------*
*FORM FRM_BILLING CHANGING C_RESULT.
* DATA: LT_SODATA TYPE TABLE OF TY_SODATA,
* LS_SODATA TYPE TY_SODATA.
*
* DATA: LV_RESULT TYPE C.
* LT_SODATA = GT_SODATA.
*
* SORT LT_SODATA BY ZDN.
*
* DELETE ADJACENT DUPLICATES FROM LT_SODATA COMPARING ZDN.
*
* LOOP AT LT_SODATA INTO LS_SODATA.
*
* CLEAR GDT_BDCDATA.
* PERFORM BDC_DYNPRO USING 'SAPMV60A' '0102'.
* PERFORM BDC_FIELD USING 'BDC_CURSOR' 'KOMFK-VBELN(01)'.
* PERFORM BDC_FIELD USING 'BDC_OKCODE' '=SICH'.
* PERFORM BDC_FIELD USING 'KOMFK-VBELN(01)' LS_SODATA-SO.
*
* PERFORM FRM_CALL_TRANSACTION2."调用事务
*
* IF LV_RESULT EQ 'E'.
* PERFORM FRM_SHOW_MESSAGE.
* C_RESULT = 'E'.
* EXIT.
* ELSE.
* C_RESULT = 'S'.
* ENDIF.
* ENDLOOP.
*
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHARG_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_<WA_DATA>_CHARG text
* <--P_<WA_DATA>_ZSFSL text
*----------------------------------------------------------------------*
FORM frm_charg_f4 CHANGING
c_charg
TYPE charg_d"批次
* C_ZSFSL TYPE MENGE_D "实发数量
.
DATA: lt_ddshretval TYPE STANDARD TABLE OF ddshretval,
ls_return
TYPE ddshretval,
l_it_cells
TYPE lvc_t_cell,
l_gw_cells
TYPE lvc_s_cell.
DATA: lt_ftab TYPE TABLE OF dfies,
ls_ftab
TYPE dfies,
lt_dn
TYPE TABLE OF ty_dn,
ls_dn
TYPE ty_dn.
DATA:
l_tabname
TYPE dd03v-tabname,
l_fieldname
TYPE dd03v-fieldname,
l_help_valu
TYPE help_info-fldvalue.
REFRESH gt_charg.
REFRESH lt_ddshretval.
*取已发货的批次
SELECT
a
~kunnr
b
~matnr
b
~charg
b
~werks
b
~lgort
INTO CORRESPONDING FIELDS OF TABLE lt_dn
FROM likp AS a
INNER
JOIN lips AS b ON a~vbeln EQ b~vbeln
WHERE a~kunnr EQ <wa_data>-shpto
AND b~matnr EQ <wa_data>-matnr
AND b~werks EQ 1000
AND b~lgort EQ <wa_data>-lgort.
*取批次数量
IF lt_dn IS NOT INITIAL.
* SELECT CHARG CLABS
* FROM MCHB INTO TABLE GT_CHARG
* WHERE MATNR EQ <WA_DATA>-MATNR
* AND WERKS = '1000'
* AND LGORT = <WA_DATA>-LGORT.
SELECT charg clabs
FROM mchb INTO TABLE gt_charg
FOR ALL ENTRIES IN lt_dn
WHERE matnr EQ lt_dn-matnr
AND werks = '1000'
AND lgort = lt_dn-lgort
AND charg EQ lt_dn-charg
.
ENDIF.
SORT gt_charg BY charg.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield
= 'CHARG' "指定ALV用F4的字段
dynpprog
= sy-repid
value_org
= 'S'
TABLES
value_tab
= gt_charg
field_tab
= lt_ftab
return_tab
= lt_ddshretval
EXCEPTIONS
parameter_error
= 1
no_values_found
= 2
OTHERS = 3.
IF sy-subrc = 0 AND lt_ddshretval IS NOT INITIAL .
CLEAR ls_return.
READ TABLE lt_ddshretval INTO ls_return INDEX 1.
c_charg
= ls_return-fieldval.
READ TABLE gt_charg INTO gs_charg WITH KEY charg = c_charg BINARY SEARCH.
IF sy-subrc EQ 0.
IF gs_charg-clabs LT <wa_data>-menge."批次数量大于实发数量
MESSAGE '批次数量小于退货数量' TYPE 'S' DISPLAY LIKE 'E'.
CLEAR c_charg.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_POST_GMVT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_post_gmvt CHANGING c_result.
DATA:
lv_vbkok
TYPE vbkok,
lv_wabuc
TYPE wabuc VALUE 'X',
lt_vbpok
TYPE TABLE OF vbpok,
ls_vbpok
TYPE vbpok,
lt_prott
TYPE TABLE OF prott WITH HEADER LINE,
ls_prott
TYPE prott,
lt_return
TYPE TABLE OF bapiret2,
wa_return
TYPE bapiret2.
DATA: lv_result TYPE c,
lv_vbeln
TYPE vbeln_vl,
lv_posnr
TYPE posnr_vl.
DATA: lt_output TYPE TABLE OF ty_output,
ls_output
TYPE ty_output.
*
* DATA:
* LS_HEADER TYPE BAPIOBDLVHDRCON,
* LS_CONTROL TYPE BAPIOBDLVHDRCTRLCON,
* DELIVERY TYPE BAPIOBDLVHDRCON-DELIV_NUMB,
* LS_TECH TYPE BAPIDLVCONTROL,
* LV_VBELN TYPE VBELN_VL,
* LT_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE
* .
c_result
= 'S'.
lt_output
= gt_output.
DELETE lt_output WHERE sel NE 'X'.
* IF R4 EQ 'X'.
SORT lt_output BY zthdn.
DELETE ADJACENT DUPLICATES FROM lt_output COMPARING zthdn.
* ELSEIF R5 EQ 'X'.
* SORT LT_OUTPUT BY ZDN.
* ENDIF.
LOOP AT lt_output INTO ls_output.
IF r6 EQ 'X'.
lv_vbkok
-vbeln_vl = ls_output-zthdn.
lv_vbkok
-wabuc = lv_wabuc .
lv_vbkok
-wadat_ist = sy-datum .
lv_vbkok
-bldat = sy-datum .
* LS_CONTROL-DELIV_NUMB = LS_OUTPUT-ZTHDN.
*
* LS_CONTROL-POST_GI_FLG = 'X'.
*
* DELIVERY = LS_OUTPUT-ZTHDN.
ENDIF.
IF r3 EQ 'X'.
lv_vbkok
-vbeln_vl = ls_output-zdn.
lv_vbkok
-wabuc = lv_wabuc .
lv_vbkok
-wadat_ist = sy-datum .
lv_vbkok
-bldat = sy-datum .
* LS_CONTROL-DELIV_NUMB = LS_OUTPUT-ZDN.
*
* LS_CONTROL-POST_GI_FLG = 'X'.
*
* DELIVERY = LS_OUTPUT-ZDN.
ENDIF.
WAIT UP TO 1 SECONDS.
CALL FUNCTION 'SD_DELIVERY_UPDATE_PICKING'
EXPORTING
vbkok_wa
= lv_vbkok
* SYNCHRON = ' '
* NO_MESSAGES_UPDATE = ' '
* NICHT_SPERREN = ' '
* AUFRUFER_T = ' '
* IF_ERROR_MESSAGES_SEND = 'X'
TABLES
vbpok_tab
= lt_vbpok[]
prot
= lt_prott[].
READ TABLE lt_prott TRANSPORTING NO FIELDS WITH KEY msgty = 'E'.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT lt_prott WHERE msgty EQ 'E'.
CLEAR wa_return.
wa_return
-type = 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid
= lt_prott-msgid
msgnr
= lt_prott-msgno
msgv1
= lt_prott-msgv1
msgv2
= lt_prott-msgv2
msgv3
= lt_prott-msgv3
msgv4
= lt_prott-msgv4
IMPORTING
message_text_output
= wa_return-message.
APPEND wa_return TO lt_return.
CLEAR lt_prott.
ENDLOOP.
RETURN.
ENDIF.
CLEAR wa_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = wa_return.
IF wa_return-type EQ 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
APPEND wa_return TO lt_return.
EXPORT lt_return TO MEMORY ID 'LT_RETURN'.
PERFORM frm_show_message.
* C_RESULT = 'E'.
RETURN.
ELSE.
* C_RESULT = 'S'.
* RETURN.
ENDIF.
* LS_TECH-UPD_IND = 'U'.
**发货过账
* CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
* EXPORTING
* HEADER_DATA = LS_HEADER
* HEADER_CONTROL = LS_CONTROL
* DELIVERY = DELIVERY
* TECHN_CONTROL = LS_TECH
* TABLES
* RETURN = LT_RETURN[].
* READ TABLE LT_RETURN TRANSPORTING NO FIELDS WITH KEY TYPE = 'E'.
* IF SY-SUBRC EQ 0.
* CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
** IMPORTING
** RETURN =
* .
* C_RESULT = 'E'.
* EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
* PERFORM FRM_SHOW_MESSAGE.
*
* RETURN.
* ENDIF.
ENDLOOP.
* IF C_RESULT EQ 'S'.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT = 'X'
** IMPORTING
** RETURN =
* .
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SET_STYLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM set_style USING fieldname
style
TYPE string
CHANGING it_styles TYPE lvc_t_styl.
DATA: ls_style TYPE lvc_s_styl.
CLEAR ls_style.
ls_style
-fieldname = fieldname.
IF style EQ 'ENABLE'.
ls_style
-style = cl_gui_alv_grid=>mc_style_enabled.
ELSE.
ls_style
-style = cl_gui_alv_grid=>mc_style_disabled.
ENDIF.
READ TABLE it_styles TRANSPORTING NO FIELDS WITH KEY fieldname = fieldname.
IF sy-subrc EQ 0.
MODIFY it_styles FROM ls_style INDEX sy-tabix.
ELSE.
INSERT ls_style INTO TABLE it_styles.
ENDIF.
FREE: ls_style.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SET_CALLSYTLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM set_callsytle USING p_pos
wa_struct
p_mssg
CHANGING it_cellcolor TYPE lvc_t_scol e_mssg.
DATA: wa_cellcolor TYPE lvc_s_scol.
CLEAR wa_cellcolor.
PERFORM get_fieldname_load USING p_pos wa_struct CHANGING wa_cellcolor-fname.
wa_cellcolor
-color-col = '6'.
wa_cellcolor
-color-int = '1'.
wa_cellcolor
-color-inv = '1'.
SORT it_cellcolor BY fname.
READ TABLE it_cellcolor TRANSPORTING NO FIELDS WITH KEY fname = wa_cellcolor-fname BINARY SEARCH.
IF sy-subrc EQ 0.
MODIFY it_cellcolor FROM wa_cellcolor INDEX sy-tabix.
ELSE.
APPEND wa_cellcolor TO it_cellcolor.
ENDIF.
PERFORM biuld_message USING wa_cellcolor-fname p_mssg CHANGING e_mssg.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_FIELDNAME_LOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_fieldname_load USING p_pos gs_struct
CHANGING p_fname.
DATA: po_struct TYPE REF TO cl_abap_structdescr,
lt_comptab
TYPE cl_abap_structdescr=>component_table.
FIELD-SYMBOLS: <f_comp> TYPE cl_abap_structdescr=>component.
po_struct ?= cl_abap_structdescr
=>describe_by_data( gs_struct ).
lt_comptab
= po_struct->get_components( ).
CHECK lt_comptab[] IS NOT INITIAL.
READ TABLE lt_comptab ASSIGNING <f_comp> INDEX p_pos.
CHECK sy-subrc EQ 0.
p_fname
= <f_comp>-name.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ADD_LEAD_ZERO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM add_lead_zero USING p_len
CHANGING e_field.
DATA: l_line TYPE i.
CLEAR l_line.
l_line
= strlen( e_field ).
l_line
= p_len - l_line.
DO l_line TIMES.
CONCATENATE '0' e_field INTO e_field.
ENDDO.
FREE: l_line.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BIULD_MESSAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM biuld_message USING p_fname
p_mssg
CHANGING e_mssg.
DATA: l_temp TYPE string.
CONCATENATE p_fname ':' p_mssg INTO l_temp.
IF e_mssg IS INITIAL.
e_mssg
= l_temp.
ELSE.
CONCATENATE e_mssg ';' l_temp INTO e_mssg.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_POST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_check_post USING u_vbeln u_flag.
DATA lv_result TYPE string.
SELECT SINGLE wbstk INTO @DATA(lv_wbstk)
FROM vbuk
WHERE vbeln EQ @u_vbeln.
*BREAK B012.
IF lv_wbstk EQ 'C'.
gs_output
-sel = 'X'.
IF u_flag EQ 1.
MODIFY gt_output FROM gs_output TRANSPORTING sel
WHERE zthdn EQ u_vbeln.
PERFORM frm_save_data USING 'POST1' CHANGING lv_result.
ELSEIF u_flag EQ 2.
MODIFY gt_output FROM gs_output TRANSPORTING sel
WHERE zdn EQ u_vbeln.
PERFORM frm_save_data USING 'POST2' CHANGING lv_result.
ENDIF.
* IF LV_RESULT EQ 'S'.
* MESSAGE '过账成功!' TYPE 'S'.
* ELSE.
* MESSAGE '过账失败!' TYPE 'S' DISPLAY LIKE 'E'.
* ENDIF.
CLEAR lv_result.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_RETURNSO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_HEADER text
* -->P_LT_ITEM text
* -->P_LT_ITEMX text
* -->P_LT_PNR text
* -->P_LT_SCH text
* -->P_LT_SCHX text
* -->P_LT_COND text
* -->P_LT_CONDX text
* <--P_LV_SO text
* <--P_LT_RETURN text
*----------------------------------------------------------------------*
FORM frm_create_returnso
TABLES
* ,T_RETURN STRUCTURE BAPIRET2
t_item
STRUCTURE bapisditm
t_itemx
STRUCTURE bapisditmx
t_pnr
STRUCTURE bapiparnr
t_sch
STRUCTURE bapischdl
t_schx
STRUCTURE bapischdlx
t_cond
STRUCTURE bapicond
t_condx
STRUCTURE bapicondx
USING
u_header
CHANGING c_so c_result.
DATA:
lt_return
TYPE TABLE OF bapiret2,
ls_return
TYPE bapiret2.
CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
EXPORTING
return_header_in
= u_header
* return_header_inx = ls_bapisdhdx
IMPORTING
salesdocument
= c_so
TABLES
return = lt_return[]
return_items_in
= t_item[]
return_items_inx
= t_itemx[]
return_partners
= t_pnr[]
return_schedules_in
= t_sch[]
return_schedules_inx
= t_schx[]
return_conditions_in
= t_cond[].
* READ TABLE lt_return INTO ls_return WITH KEY type = 'W'.
* IF sy-subrc EQ 0.
* c_result = 'E'.
* CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
** IMPORTING
** RETURN =
* .
*
* EXPORT lt_return TO MEMORY ID 'LT_RETURN'.
* PERFORM frm_show_message.
* RETURN.
* ENDIF.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
c_result
= 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT lt_return TO MEMORY ID 'LT_RETURN'.
PERFORM frm_show_message.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
c_result
= 'S'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_RETURNSO1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_RETURN text
* -->P_LS_HEADER text
* -->P_LT_ITEM text
* -->P_LT_ITEMX text
* -->P_LT_PNR text
* -->P_LT_SCH text
* -->P_LT_SCHX text
* -->P_LT_COND text
* -->P_LT_CONDX text
* <--P_LV_SO text
*----------------------------------------------------------------------*
FORM frm_create_returnso1
TABLES
* T_RETURN STRUCTURE BAPIRET2
t_item
STRUCTURE bapisditm
t_itemx
STRUCTURE bapisditmx
t_pnr
STRUCTURE bapiparnr
t_sch
STRUCTURE bapischdl
t_schx
STRUCTURE bapischdlx
t_cond
STRUCTURE bapicond
t_condx
STRUCTURE bapicondx
USING
u_header
CHANGING c_so
c_result
.
DATA:
lt_return
TYPE TABLE OF bapiret2,
ls_return
TYPE bapiret2.
* BREAK B012.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in
= u_header
IMPORTING
salesdocument
= c_so
TABLES
return = lt_return[]
order_items_in
= t_item[]
order_items_inx
= t_itemx[]
order_partners
= t_pnr[]
order_schedules_in
= t_sch[]
order_schedules_inx
= t_schx[]
* ORDER_CONDITIONS_IN = T_COND[]
* ORDER_CONDITIONS_INX = T_CONDX[]
.
* READ TABLE lt_return INTO ls_return WITH KEY type = 'W'.
* IF sy-subrc EQ 0.
* c_result = 'E'.
* CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
** IMPORTING
** RETURN =
* .
*
* EXPORT lt_return TO MEMORY ID 'LT_RETURN'.
* PERFORM frm_show_message.
* RETURN.
* ENDIF.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
c_result
= 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT lt_return TO MEMORY ID 'LT_RETURN'.
PERFORM frm_show_message.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
c_result
= 'S'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_DN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LV_SO text
* <--P_LV_DN text
*----------------------------------------------------------------------*
FORM frm_create_dn USING u_so
CHANGING c_dn c_result.
DATA: lt_so_item TYPE TABLE OF bapidlvreftosalesorder,
ls_so_item
TYPE bapidlvreftosalesorder,
lt_return
TYPE TABLE OF bapiret2,
ls_return
TYPE bapiret2.
ls_so_item
-ref_doc = u_so.
APPEND ls_so_item TO lt_so_item.
CLEAR ls_so_item.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
IMPORTING
delivery
= c_dn
TABLES
sales_order_items
= lt_so_item
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
c_result
= 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT lt_return TO MEMORY ID 'LT_RETURN'.
PERFORM frm_show_message.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
c_result
= 'S'.
ENDIF.
CALL FUNCTION 'RV_DELIVERY_INIT'
EXPORTING
status_buff_init
= status_buff_init
i_call_activity
= call_activity
if_no_deque
= g_no_dequeue_sd_sales.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_MODIFY_SODATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LV_SO text
* -->P_LV_DN text
*----------------------------------------------------------------------*
FORM frm_modify_sodata USING u_so
u_dn
CHANGING c_result.
DATA ls_sodata TYPE ty_sodata.
DATA: lv_so TYPE vbeln,
lv_dn
TYPE vbeln_vl.
lv_so
= u_so.
lv_dn
= u_dn.
IF lv_so IS NOT INITIAL.
ls_sodata
-so = lv_so.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_sodata-so
IMPORTING
output = ls_sodata-so.
ls_sodata
-zdn = lv_dn.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_sodata-zdn
IMPORTING
output = ls_sodata-zdn.
MODIFY gt_sodata FROM ls_sodata TRANSPORTING so zdn
WHERE so EQ 'X' AND zdn EQ 'X'.
PERFORM frm_post_dn USING lv_dn .
CALL FUNCTION 'RV_DELIVERY_INIT'
EXPORTING
status_buff_init
= status_buff_init
i_call_activity
= call_activity
if_no_deque
= g_no_dequeue_sd_sales.
CLEAR:lv_so,lv_dn.
ELSE.
PERFORM frm_show_message.
c_result
= 'E'.
EXIT.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_MODIFY_SODATA1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LV_SO1 text
* -->P_LV_DN1 text
* <--P_C_RESULT text
*----------------------------------------------------------------------*
*FORM FRM_MODIFY_SODATA USING U_SO
* U_DN
* CHANGING C_RESULT.
* DATA LS_SODATA TYPE TY_SODATA.
* DATA: LV_SO TYPE VBELN,
* LV_DN TYPE VBELN_VL.
*
* LV_SO = U_SO.
* LV_DN = U_DN.
*
* IF LV_SO IS NOT INITIAL.
* LS_SODATA-SO = LV_SO.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = LS_SODATA-SO1
* IMPORTING
* OUTPUT = LS_SODATA-SO1.
*
* LS_SODATA-ZDN = LV_DN.
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* INPUT = LS_SODATA-ZDN1
* IMPORTING
* OUTPUT = LS_SODATA-ZDN1.
*
*
* MODIFY GT_SODATA FROM LS_SODATA TRANSPORTING SO1 ZDN1
* WHERE SO1 EQ 'X' AND ZDN1 EQ 'X'.
*
* CLEAR:LV_SO,LV_DN.
*
* ELSE.
* PERFORM FRM_SHOW_MESSAGE.
* C_RESULT = 'E'.
* EXIT.
* ENDIF.
*ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_PARTNER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_OUTPUT_SLDTO text
* <--P_LV_RESULT text
*----------------------------------------------------------------------*
FORM frm_check_partner USING u_sldto
CHANGING c_result.
DATA:lv_msg TYPE string.
DATA:
ls_a515
TYPE a515,
lt_a515
TYPE TABLE OF a515.
SELECT SINGLE vkorg vtweg spart vkbur vkgrp vsbed
INTO ( gs_sodata-vkorg,gs_sodata-vtweg,gs_sodata-spart,
gs_sodata
-vkbur,gs_sodata-vkgrp,gs_sodata-vsbed )
FROM knvv
WHERE kunnr EQ u_sldto
AND vtweg EQ '20'"直营
AND loevm NE 'X'"删除标记
* AND VSBED EQ '99'"装运条件
.
IF sy-subrc NE 0.
c_result
= 'E'.
lv_msg
= '售达方' && u_sldto && '销售组织数据不正确,请检查。'.
MESSAGE s001 WITH lv_msg DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* SELECT SINGLE SPOFI INTO @DATA(LV_SPOFI)
* FROM TVLK
* WHERE LFART EQ 'ZLR'."退货交货
*
* IF SY-SUBRC EQ 0.
*
* IF LV_SPOFI EQ SPACE. "特定工厂装运点
* SELECT SINGLE VSTEL INTO @DATA(LV_VSTEL)
* FROM TVSTZ
* WHERE VSBED EQ @GS_SODATA-VSBED
* AND LADGR EQ '0001'
* AND WERKS EQ '1000'.
* IF SY-SUBRC NE 0.
* C_RESULT = 'E'.
* LV_MSG = '售达方' && U_SLDTO && '按工厂1000确定的装运点不存在。'.
* MESSAGE S001 WITH LV_MSG DISPLAY LIKE 'E'.
* RETURN.
* ENDIF.
* ELSE."按库存地点确定装运点
*
* SELECT SINGLE LGORT INTO @DATA(LV_LGORT)
* FROM KNA1
* WHERE KUNNR EQ @U_SLDTO.
*
* SELECT SINGLE VSTEL INTO LV_VSTEL
* FROM TVSTZ_STORLOC
* WHERE VSBED EQ GS_SODATA-VSBED
* AND LADGR EQ '0001'
* AND WERKS EQ '1000'
* AND LGORT EQ LV_LGORT.
*
* IF SY-SUBRC NE 0.
* C_RESULT = 'E'.
* LV_MSG = '售达方' && U_SLDTO && '按库存地点' && LV_LGORT && '确定的装运点不存在。'.
* MESSAGE S001 WITH LV_MSG DISPLAY LIKE 'E'.
* RETURN.
* ENDIF.
* ENDIF.
*
**检查条件记录是否存在
* SELECT
* *
* INTO TABLE LT_A515
* FROM A515
* WHERE KSCHL EQ 'PRZ0'
* AND KUNNR EQ U_SLDTO
* AND MATNR EQ GS_SODATA-MATNR.
*
* IF SY-SUBRC NE 0.
* C_RESULT = 'E'.
*
* LV_MSG = '售达方' && U_SLDTO && '物料' && GS_SODATA-MATNR && '条件记录PRZ0不存在。'.
* MESSAGE S001 WITH LV_MSG DISPLAY LIKE 'E'.
*
* RETURN.
*
* ELSE.
* SORT LT_A515 BY DATBI DESCENDING.
* DELETE ADJACENT DUPLICATES FROM LT_A515 COMPARING KAPPL KSCHL KUNNR MATNR.
*
* READ TABLE LT_A515 INTO LS_A515 INDEX 1.
*
* SELECT SINGLE KBETR INTO @DATA(KBETR)
* FROM KONP
* WHERE KNUMH EQ @LS_A515-KNUMH
* AND KSCHL EQ 'PRZ0'
* AND KBETR EQ 0.
*
* IF SY-SUBRC EQ 0.
* C_RESULT = 'E'.
*
* LV_MSG = '售达方' && U_SLDTO && '物料' && GS_SODATA-MATNR && '条件记录PRZ0价格不能为0。'.
* MESSAGE S001 WITH LV_MSG DISPLAY LIKE 'E'.
*
* RETURN.
* ENDIF.
* ENDIF.
*
c_result
= 'S'.
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SEL_ALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_sel_all .
DATA : lt_filtered_entries TYPE lvc_t_fidx.
FREE lt_filtered_entries.
CALL METHOD gct_alv->get_filtered_entries
IMPORTING
et_filtered_entries
= lt_filtered_entries.
LOOP AT gt_output ASSIGNING <wa_data> WHERE sel EQ space.
READ TABLE lt_filtered_entries TRANSPORTING NO FIELDS WITH KEY table_line = sy-tabix.
IF sy-subrc NE 0.
<wa_data>
-sel = 'X'.
ENDIF.
ENDLOOP.
UNASSIGN <wa_data>
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_LOCK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_check_lock .
SORT gt_batno[] BY batno batpo.
DELETE ADJACENT DUPLICATES FROM gt_batno[] COMPARING ALL FIELDS.
LOOP AT gt_batno.
CALL FUNCTION 'ENQUEUE_EZSD001'
EXPORTING
mode_ztsd002
= 'E'
batno
= gt_batno-batno
batpo
= gt_batno-batpo
* X_BATNO = ' '
* X_BATPO = ' '
* _SCOPE = '2'
* _WAIT = ' '
* _COLLECT = ' '
EXCEPTIONS
foreign_lock
= 1
system_failure
= 2
OTHERS = 3.
IF sy-subrc <> 0.
gs_mesg
-mesg = '批导编号' && gt_batno-batno && '行号' && gt_batno-batpo && '的订单' && '被用户' && sy-msgv1 && '锁定'.
* GS_MESG-MSGNO = SY-MSGNO.
* GS_MESG-MSGTY = SY-MSGTY.
* GS_MESG-MSGV1 = SY-MSGV1.
* GS_MESG-MSGV2 = SY-MSGV2.
* GS_MESG-MSGV3 = SY-MSGV3.
* GS_MESG-MSGV4 = SY-MSGV4.
APPEND gs_mesg TO gt_mesg.
CLEAR gs_mesg.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_RESET_LOCK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_reset_lock .
LOOP AT gt_batno.
CALL FUNCTION 'DEQUEUE_EZSD001'
EXPORTING
mode_ztsd002
= 'E'
batno
= gt_batno-batno
batpo
= gt_batno-batpo
x_batno
= ' '
x_batpo
= ' '
_scope
= '3'
_synchron
= ' '
_collect
= ' '.
ENDLOOP.
FREE gt_batno.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DELETE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_delete_data .
DATA: lt_del TYPE TABLE OF ztsd015 WITH HEADER LINE.
LOOP AT gt_output INTO gs_output WHERE sel EQ 'X'.
* IF GS_OUTPUT-ZTHDD IS INITIAL.
* DELETE GT_OUTPUT.
* DELETE FROM ZTSD015 WHERE BATNO EQ GS_OUTPUT-BATNO AND BATPO EQ GS_OUTPUT-BATPO.
** DELETE FROM ZTSD016 WHERE BATNO EQ GS_OUTPUT-BATNO AND BATPO EQ GS_OUTPUT-BATPO.
* ELSE.
SELECT SINGLE vbeln INTO @DATA(lv_vbeln)
FROM likp
WHERE vbeln EQ @gs_output-zthdd.
IF sy-subrc EQ 0.
MESSAGE '已生成退货订单不允许删除。' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* ENDIF.
ENDLOOP.
CLEAR gs_output.
LOOP AT gt_output INTO gs_output WHERE sel EQ 'X'.
IF gs_output-zuser NE sy-uname.
MESSAGE '不允许删除其他用户的验单数据。' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
CLEAR lt_del.
lt_del
-batno = gs_output-batno.
lt_del
-batpo = gs_output-batpo.
lt_del
-sldto = gs_output-sldto.
lt_del
-shpto = gs_output-shpto.
lt_del
-matnr = gs_output-matnr.
APPEND lt_del TO lt_del.
CLEAR gs_output.
ENDLOOP.
DELETE gt_output WHERE sel EQ 'X'.
IF lt_del[] IS NOT INITIAL.
DELETE ztsd015 FROM TABLE lt_del[].
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
MESSAGE '删除成功!' TYPE 'S'.
ELSE.
ROLLBACK WORK.
MESSAGE '删除失败!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
CLEAR: lt_del,lt_del[].
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_STAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<WA_DATA>_ZTHDD text
*----------------------------------------------------------------------*
FORM frm_get_stat USING u_so TYPE vbeln.
DATA: lv_so TYPE vbeln,
lv_dn
TYPE vbeln_vl.
lv_so
= u_so.
CHECK lv_so IS NOT INITIAL.
SELECT SINGLE a~vbeln INTO <wa_data>-zthdd
FROM vbkd AS a
INNER
JOIN vbap AS b
ON a~vbeln EQ b~vbeln
AND a~posnr EQ b~posnr
INNER
JOIN vbak AS c
ON a~vbeln EQ c~vbeln
WHERE bstkd_e EQ <wa_data>-key
AND b~abgru EQ space
AND c~auart EQ 'ZRE1'.
* SELECT SINGLE A~VBELN INTO <WA_DATA>-ZTHDD
* FROM VBKD AS A
* INNER JOIN VBAK AS B
* ON A~VBELN EQ B~VBELN
* WHERE ( BSTKD_E = <WA_DATA>-KEY
* AND B~AUART EQ 'ZRE1'
* AND A~POSNR NE SPACE )
* OR ( BSTKD_E = <WA_DATA>-ZYDDH
* AND B~AUART EQ 'ZRE1'
* AND A~POSNR EQ SPACE )
* OR ( BSTKD = <WA_DATA>-ZYDDH
* AND B~AUART EQ 'ZRE1'
* AND A~POSNR EQ SPACE ).
IF sy-subrc EQ 0.
SELECT SINGLE vbeln INTO <wa_data>-zthdn
FROM vbfa
WHERE ( vbelv EQ <wa_data>-zthdd
AND vbtyp_n EQ 'J' )
OR ( vbelv EQ <wa_data>-zthdd AND vbtyp_n EQ 'T' ).
IF sy-subrc EQ 0.
ELSE.
CLEAR <wa_data>-zthdn.
ENDIF.
ELSE.
CLEAR <wa_data>-zthdd.
CLEAR <wa_data>-zthdn.
ENDIF.
*取状态
lv_dn
= <wa_data>-zthdn.
SELECT SINGLE wbstk fkstk
INTO ( <wa_data>-wbstk1, <wa_data>-fkstk1 )
FROM vbuk
WHERE vbeln EQ lv_dn.
CLEAR lv_dn.
SELECT SINGLE a~vbeln INTO <wa_data>-zmfck
FROM vbkd AS a
INNER
JOIN vbap AS b
ON a~vbeln EQ b~vbeln
AND a~posnr EQ b~posnr
INNER
JOIN vbak AS c
ON a~vbeln EQ c~vbeln
WHERE bstkd_e EQ <wa_data>-key
AND b~abgru EQ space
AND c~auart EQ 'ZSD9'.
* SELECT SINGLE A~VBELN INTO <WA_DATA>-ZMFCK
* FROM VBKD AS A
* INNER JOIN VBAK AS B
* ON A~VBELN EQ B~VBELN
* WHERE ( BSTKD_E = <WA_DATA>-KEY
* AND B~AUART EQ 'ZSD9'
* AND A~POSNR NE SPACE )
* OR ( BSTKD_E = <WA_DATA>-ZYDDH
* AND B~AUART EQ 'ZSD9'
* AND A~POSNR EQ SPACE )
* OR ( BSTKD = <WA_DATA>-ZYDDH
* AND B~AUART EQ 'ZSD9'
* AND A~POSNR EQ SPACE ).
IF sy-subrc EQ 0.
SELECT SINGLE vbeln INTO <wa_data>-zdn
FROM vbfa
WHERE ( vbelv EQ <wa_data>-zmfck
AND vbtyp_n EQ 'J' )
OR ( vbelv EQ <wa_data>-zmfck AND vbtyp_n EQ 'T' ).
IF sy-subrc EQ 0.
ELSE.
"CLEAR <wa_data>-zmfck.
CLEAR <wa_data>-zdn.
ENDIF.
ELSE.
CLEAR <wa_data>-zdn.
CLEAR <wa_data>-zmfck.
ENDIF.
*取状态
lv_dn
= <wa_data>-zdn.
IF lv_dn IS NOT INITIAL.
SELECT SINGLE wbstk fkstk
INTO ( <wa_data>-wbstk2,<wa_data>-fkstk2 )
FROM vbuk
WHERE vbeln EQ lv_dn.
ENDIF.
CLEAR lv_dn.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_AUTHORITY_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_authority_check .
DATA: l_temp TYPE string.
DATA: lt_t001l TYPE TABLE OF t001l WITH HEADER LINE.
SELECT lgort
INTO CORRESPONDING FIELDS OF TABLE lt_t001l
FROM t001l
WHERE werks EQ 1000
AND lgort IN s_lgort.
IF lt_t001l[] IS INITIAL.
MESSAGE '没有库存地点记录' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
LOOP AT lt_t001l.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'ACTVT' DUMMY
ID 'WERKS' FIELD '1000'
ID 'LGORT' FIELD lt_t001l-lgort
ID 'BWART' DUMMY.
IF sy-subrc <> 0.
MESSAGE '您没有库存地点' && lt_t001l-lgort && '的权限' TYPE 'E'.
RETURN.
* Implement a suitable exception handling here
ENDIF.
ENDLOOP.
FREE lt_t001l.
FREE: l_temp.
ENDFORM.