SAP 直营验单
*&---------------------------------------------------------------------*
*& Report ZSDR005
*&
*&---------------------------------------------------------------------*
*&程序名称:直营平台-
*&事物代码:ZSD025
*&导入模板:直接下载
*&作者:
*&时间:2016/2/29
*&---------------------------------------------------------------------*
REPORT ZSDR046 MESSAGE-ID 00.
TYPE-POOLS:OLE2,SLIS,ICON.
FIELD-SYMBOLS: <FS>.
TABLES: SSCRFIELDS,ZTSD008,ZTSD009,MCHB.
TYPES: BEGIN OF TY_OUTPUT,
SEL TYPE C,
BATNO TYPE ZTSD008-BATNO, "批导序号
BATPO TYPE ZTSD009-BATPO, "验单批导序号
VERNO TYPE ZTSD010-VERNO, "版本号
ZDATE TYPE ZTSD008-ZDATE, "导入日期
INDAT TYPE ZTSD009-INDAT, "验单日期
LFDAT TYPE LIKP-LFDAT, "实际交货日期
* KUNNR TYPE KUNNR, "客户号
* NAME1 TYPE KNA1-NAME1, "客户名称
ZSJ TYPE KUNNR, "司机
ZR TYPE CHAR30, "主任
ZYWY TYPE CHAR30, "业务员
NAME2 TYPE KNA1-NAME1, "司机名称
* KUNNR1 TYPE KUNNR, "司机系统
* NAME2 TYPE KNA1-NAME1, "司机系统名称
MATNR TYPE ZTSD009-MATNR, "物料号
MAKTX TYPE MAKT-MAKTX, "物料描述
MENGE TYPE ZTSD009-MENGE, "验单数量
MEINS TYPE MEINS, "数量单位
* CHARG TYPE CHARG_D, "批次
ZYDJG TYPE ZTSD009-ZYDJG, "验单价格
ZYDJE TYPE ZTSD009-ZYDJE, "合计金额
ZYDDH TYPE ZTSD009-ZYDDH, "验单单号
SO TYPE ZTSD009-VBELN, "SO
DN TYPE VBELN_VL, "DN
ZICON1 TYPE CHAR4, "导入状态
VKBUR TYPE VKBUR, "销售部门
VKORG TYPE VKORG,
LGORT TYPE LGORT_D,
RESLO TYPE RESLO, "发货库存地
SHPTO TYPE KUNNR, "送达方
NAME_HP TYPE NAME1, "送达方名称
SLDTO TYPE KUNNR, "售达方
NAME_LD TYPE NAME1, "售达方名称
CELLCOLOR TYPE LVC_T_SCOL, "控制单元格颜色
STYLE TYPE LVC_T_STYL, "控制单元格可否编辑
MSSG TYPE BAPI_MSG, "消息内容
ZFREE TYPE C,
BEIZHU TYPE CHAR255, "备注
ZUSER TYPE ZTSD008-ZUSER,
WBSTK TYPE VBUK-WBSTK, "货物移动状态
FKSTK TYPE VBUK-FKSTK, "开票状态
END OF TY_OUTPUT.
TYPES: BEGIN OF TY_LOAD,
INDAT TYPE ZTSD009-INDAT, "验单日期
LFDAT TYPE LIKP-LFDAT, "交货日期
* KUNNR TYPE KUNNR,
* BLANK TYPE C, "占位
SLDTO TYPE KUNNR, "售达方
* BLANK1 TYPE C, "占位
SHPTO TYPE KUNNR, "送达方
* BLANK2 TYPE C, "占位
ZYDDH TYPE ZTSD009-ZYDDH, "验单单号
ZSJ TYPE KUNNR, "司机
* BLANK5 TYPE C, "占位
ZR TYPE CHAR30, "主任
ZYWY TYPE CHAR30, "业务员
VKBUR TYPE VKBUR, "销售部门
* BLANK3 TYPE C, "占位
BEIZHU TYPE CHAR255, "备注
MEINS TYPE MEINS, "数量单位
MATNR TYPE ZTSD009-MATNR,
MENGE TYPE MENGE_D, "验单数量
ZYDJG TYPE ZTSD009-ZYDJG, "验单价格
ZYDJE TYPE ZTSD009-ZYDJE, "验单金额
* BLANK4 TYPE C, "
END OF TY_LOAD.
TYPES: BEGIN OF TY_SODATA,
ZYDDH TYPE ZTSD009-ZYDDH, "验单单号
INDAT TYPE ZTSD009-INDAT,
LFDAT TYPE LIKP-LFDAT,
* 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, "销售组
VKBUR TYPE VBAK-VKBUR, "销售部门
VSBED TYPE KNVV-VSBED, "装运条件
MATNR TYPE EKPO-MATNR, "物料代码
VSTEL TYPE VSTEL, "装运点
RESLO TYPE RESLO, "发货库存地
WERKS TYPE VBAP-WERKS, "
MENGE TYPE KWMENG, "数量
MEINS TYPE MEINS, "单位
* CHARG TYPE CHARG_D, "批次
ZYDJE TYPE ZTSD009-ZYDJE, "验单价格
BATNO TYPE ZTSD008-BATNO, "批导序号
BATPO TYPE ZTSD009-BATPO, "批导行项目号
SO TYPE VBAK-VBELN, "销售订单号
DN TYPE LIKP-VBELN, "交货单号
KPEIN TYPE KOMV-KPEIN, "条件定价单位
KMEIN TYPE KOMV-KMEIN, "条件单位
END OF TY_SODATA.
TYPES: BEGIN OF TYP_HEADER,
ZTEXT(10),
END OF TYP_HEADER.
TYPES: BEGIN OF TY_MESG,
MESG TYPE CHAR255,
END OF TY_MESG.
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 TABLE OF TY_LOAD,
GT_OUTPUT TYPE TABLE OF TY_OUTPUT,
GT_SODATA TYPE TABLE OF TY_SODATA.
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 P_MODE TYPE C VALUE 'N'.
DATA: BEGIN OF GT_BATNO OCCURS 0,
BATNO TYPE ZBATNO,
BATPO TYPE ZBATPO,
END OF GT_BATNO.
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.
DATA: GT_DEL TYPE TABLE OF ZTSD009 WITH HEADER LINE.
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.
*SELECT-OPTIONS:
PARAMETERS: P_VKORG TYPE VBAK-VKORG,
P_LGORT
TYPE T001L-LGORT.
PARAMETERS: P_UFILE LIKE RLGRAP-FILENAME MODIF ID M1."上传文件路径
SELECT-OPTIONS:
S_ZUSER
FOR ZTSD008-ZUSER MODIF ID M2,"导入用户
S_INDAT
FOR ZTSD009-INDAT MODIF ID M2,"验单日期
S_ZDATE
FOR ZTSD008-ZDATE MODIF ID M2,"导入日期
S_SJ
FOR ZTSD009-KUNNR MODIF ID M2,"客户编号
S_MATNR
FOR ZTSD009-MATNR MODIF ID M2,"物料编号
S_SHPTO
FOR ZTSD009-SHPTO MODIF ID M2, "送达方
S_SLDTO
FOR ZTSD009-SLDTO MODIF ID M2, "售达方
S_VKBUR
FOR ZTSD009-VKBUR MODIF ID M2, "销售部门
S_ZYDDH
FOR ZTSD009-ZYDDH LOWER CASE MODIF ID M2, "验单单号
S_VBELN
FOR ZTSD009-VBELN MODIF ID M2. "销售订单号
*PARAMETERS: P_CB1 TYPE C AS CHECKBOX MODIF ID M4,
* P_CB2 TYPE C AS CHECKBOX MODIF ID M4.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN: FUNCTION KEY 1. "激活按钮
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TITLE1.
PARAMETERS: R1 RADIOBUTTON GROUP RG1 USER-COMMAND USR DEFAULT 'X', "上传批导
R2
RADIOBUTTON GROUP RG1, "提交验单
R3
RADIOBUTTON GROUP RG1. "显示导入数据
SELECTION-SCREEN END OF BLOCK B2.
*SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TITLE2.
*SELECTION-SCREEN BEGIN OF LINE.
*PARAMETERS: R3 RADIOBUTTON GROUP RG2 DEFAULT 'X'."本品
*SELECTION-SCREEN COMMENT (5) TEXT-001 FOR FIELD R1.
*PARAMETERS: R4 RADIOBUTTON GROUP RG2."赠品
*SELECTION-SCREEN COMMENT (5) TEXT-002 FOR FIELD R2."
*SELECTION-SCREEN END OF LINE.
*SELECTION-SCREEN END OF BLOCK B3.
SELECTION-SCREEN BEGIN OF BLOCK B4 WITH FRAME TITLE TEXT-007.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: R5 RADIOBUTTON GROUP RG3 USER-COMMAND USR2 DEFAULT 'X'."石家庄直营
SELECTION-SCREEN COMMENT (7) TEXT-005 FOR FIELD R5.
PARAMETERS: R6 RADIOBUTTON GROUP RG3 ."未打印
SELECTION-SCREEN COMMENT (7) TEXT-006 FOR FIELD R6."外阜直营
*PARAMETERS: R6 RADIOBUTTON GROUP RG2."全部
*SELECTION-SCREEN COMMENT (5) TEXT-005 FOR FIELD R6."全部
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B4.
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
SSCRFIELDS
-FUNCTXT_01 = '下载模板'. "定义按钮文本
TITLE1
= '操作类型'.
* TITLE2 = '验收产品类型'.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE SSCRFIELDS-UCOMM. "处理按钮命令
WHEN'FC01'.
PERFORM FRM_DOWNLOAD_TEMPLATE.
ENDCASE.
AT SELECTION-SCREEN OUTPUT.
IF R5 EQ 'X'.
* SUBMIT ZSDR005 VIA SELECTION-SCREEN .
ELSEIF R6 EQ 'X'.
SUBMIT ZSDR019 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 R3 EQ 'X'.
SCREEN-ACTIVE = 1.
ELSE.
SCREEN-ACTIVE = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M3'.
IF R3 EQ 'X'.
SCREEN-ACTIVE = 1.
ELSE.
SCREEN-ACTIVE = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M4'.
IF R2 EQ 'X'.
SCREEN-ACTIVE = 1.
ELSE.
SCREEN-ACTIVE = 0.
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','LT_RETURN'.
IF P_VKORG IS INITIAL.
MESSAGE '请输入销售组织。' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF P_LGORT IS INITIAL.
MESSAGE '请输入库存地点。' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
PERFORM FRM_AUTHORITY_CHECK.
*上传文件
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'
*显示保存的数据
*DELETE FROM: ZTSD008,ZTSD009,ZTSD010,ZTSD011. COMMIT WORK AND WAIT.
PERFORM FRM_GET_DATA.
PERFORM FRM_PROCESS_DATA.
ENDIF.
IF GT_OUTPUT IS INITIAL.
MESSAGE '没有符合要求的数据' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF R2 EQ '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
.
PRIVATE SECTION.
DATA ROWS TYPE LVC_T_ROW.
DATA RS TYPE LVC_S_ROW.
DATA ERROR_IN_DATA TYPE C.
DATA LS_MODI TYPE LVC_S_MODI.
DATA G_IND TYPE I.
DATA LV_SEL TYPE C.
METHODS:
GET_ZYDJE
IMPORTING
E_MODI
TYPE LVC_S_MODI
E_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL,
GET_MENGE
IMPORTING
E_MODI
TYPE LVC_S_MODI
E_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
ENDCLASS. "GC_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------
* CLASS GC_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------
CLASS GC_EVENT_RECEIVER IMPLEMENTATION.
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.
IF R3 NE 'X'.
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.
ENDIF.
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'.
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-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@'."红灯.
* LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X' AND SO IS INITIAL.
* ENDLOOP.
* CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
* EXPORTING
* IS_STABLE = GS_STABLE
* I_SOFT_REFRESH = 'X'.
WHEN 'CAN_ALL'.
CLEAR GS_OUTPUT.
GS_OUTPUT
-SEL = ' '.
MODIFY GT_OUTPUT FROM GS_OUTPUT TRANSPORTING SEL WHERE SEL EQ 'X'.
LOOP AT GT_OUTPUT INTO GS_OUTPUT.
PERFORM SET_STYLE USING '' SY-TABIX.
ENDLOOP.
* CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
* EXPORTING
* IS_STABLE = GS_STABLE
* I_SOFT_REFRESH = 'X'.
WHEN 'DEL'.
*询问是否确认
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION
= '确认删除所选数据?'
TEXT_BUTTON_1
= '是'(003)
TEXT_BUTTON_2
= '否'(004)
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 'OKAY'.
PERFORM FRM_CONFIRM_DATA CHANGING LV_RESULT.
CHECK 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.
*DN过账
PERFORM FRM_POST_DN.
WHEN OTHERS.
ENDCASE.
CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE
= GS_STABLE
I_SOFT_REFRESH
= 'X'.
ENDMETHOD.
METHOD HANDLE_DATA_CHANGED.
LOOP AT ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MODI.
CASE LS_MODI-FIELDNAME.
WHEN 'MENGE'.
CALL METHOD GET_MENGE
EXPORTING
E_MODI
= LS_MODI
E_DATA_CHANGED
= ER_DATA_CHANGED.
WHEN 'ZYDJE'.
CALL METHOD GET_ZYDJE
EXPORTING
E_MODI
= LS_MODI
E_DATA_CHANGED
= ER_DATA_CHANGED.
ENDCASE.
ENDLOOP.
CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE
= GS_STABLE
I_SOFT_REFRESH
= 'X'.
ENDMETHOD.
METHOD HANDLE_CHANGE_FINISH.
DATA: LS_CELL TYPE LVC_S_MODI.
CLEAR LS_CELL.
READ TABLE ET_GOOD_CELLS INTO LS_CELL INDEX 1.
CASE LS_CELL-FIELDNAME.
WHEN 'SEL'.
PERFORM SET_STYLE USING LS_CELL-VALUE LS_CELL-ROW_ID.
CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE
= GS_STABLE
I_SOFT_REFRESH
= 'X'.
ENDCASE.
ENDMETHOD.
METHOD GET_ZYDJE.
DATA LV_YDJE TYPE ZTSD009-ZYDJE.
DATA LV_TABIX LIKE SY-TABIX.
CALL METHOD E_DATA_CHANGED->GET_CELL_VALUE
EXPORTING
I_ROW_ID
= E_MODI-ROW_ID
I_FIELDNAME
= E_MODI-FIELDNAME
IMPORTING
E_VALUE
= LV_YDJE.
* CHECK NOT LV_YDJE IS INITIAL.
READ TABLE GT_OUTPUT ASSIGNING <WA_DATA> INDEX E_MODI-ROW_ID.
* CHECK <WA_DATA>-MEINS IS NOT INITIAL.
IF SY-SUBRC EQ 0.
<WA_DATA>
-MSSG = ' '.
IF LV_YDJE LE 0.
<WA_DATA>
-MSSG = '合计金额不能为零,请修改!'.
ERROR_IN_DATA
= 'X'.
* CALL METHOD E_DATA_CHANGED->ADD_PROTOCOL_ENTRY
* EXPORTING
* I_MSGID = 'ZSD001'
* I_MSGNO = '000'
* I_MSGTY = 'E'
* I_MSGV1 = LV_YDJE
* I_MSGV2 = '合计金额不能为零,请修改!'
* I_MSGV3 = ''
* I_FIELDNAME = E_MODI-FIELDNAME
* I_ROW_ID = E_MODI-ROW_ID.
* IF ERROR_IN_DATA = 'X'.
* CALL METHOD E_DATA_CHANGED->DISPLAY_PROTOCOL.
* ENDIF.
ELSE.
* BREAK B012.
IF <WA_DATA>-MENGE NE 0.
<WA_DATA>
-ZYDJG = LV_YDJE / <WA_DATA>-MENGE.
ELSE.
<WA_DATA>
-ZYDJG = 0.
ENDIF.
ENDIF.
ENDIF.
UNASSIGN <WA_DATA>
.
FREE:LV_YDJE.
ENDMETHOD.
METHOD GET_MENGE.
DATA LV_MENGE TYPE ZTSD009-MENGE.
DATA LV_MEINS TYPE MEINS.
DATA LV_TABIX LIKE SY-TABIX.
DATA:
LV_STRING
TYPE STRING,
S1
TYPE STRING,
S2
TYPE STRING.
CALL METHOD E_DATA_CHANGED->GET_CELL_VALUE
EXPORTING
I_ROW_ID
= E_MODI-ROW_ID
I_FIELDNAME
= E_MODI-FIELDNAME
IMPORTING
E_VALUE
= LV_MENGE.
READ TABLE GT_OUTPUT ASSIGNING <WA_DATA> INDEX E_MODI-ROW_ID.
IF SY-SUBRC EQ 0.
<WA_DATA>
-MSSG = ' '.
IF LV_MENGE LE 0.
<WA_DATA>
-MSSG = '验收数量不能为零,请修改!'.
ERROR_IN_DATA
= 'X'.
* CALL METHOD E_DATA_CHANGED->ADD_PROTOCOL_ENTRY
* EXPORTING
* I_MSGID = 'ZSD001'
* I_MSGNO = '000'
* I_MSGTY = 'E'
* I_MSGV1 = LV_MENGE
* I_MSGV2 = '验收数量不能为零,请修改!'
* I_MSGV3 = ''
* I_FIELDNAME = E_MODI-FIELDNAME
* I_ROW_ID = E_MODI-ROW_ID.
* IF ERROR_IN_DATA = 'X'.
* CALL METHOD E_DATA_CHANGED->DISPLAY_PROTOCOL.
* ENDIF.
ELSE.
LV_STRING
= LV_MENGE.
SPLIT LV_STRING AT '.' INTO S1 S2.
IF S2 NE 0.
<WA_DATA>
-MSSG = '验收数量不能含小数。'.
ERROR_IN_DATA
= 'X'.
* CALL METHOD E_DATA_CHANGED->ADD_PROTOCOL_ENTRY
* EXPORTING
* I_MSGID = 'ZSD001'
* I_MSGNO = '000'
* I_MSGTY = 'E'
* I_MSGV1 = LV_MENGE
* I_MSGV2 = '验收数量不能含小数。请修改!'
* I_MSGV3 = ''
* I_FIELDNAME = E_MODI-FIELDNAME
* I_ROW_ID = E_MODI-ROW_ID.
* IF ERROR_IN_DATA = 'X'.
* CALL METHOD E_DATA_CHANGED->DISPLAY_PROTOCOL.
* ENDIF.
* ENDIF.
ENDIF.
*更新验单价格
<WA_DATA>
-ZYDJG = <WA_DATA>-ZYDJE / <WA_DATA>-MENGE.
ENDIF.
ENDIF.
UNASSIGN <WA_DATA>
.
FREE:LV_MEINS, LV_MENGE.
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.
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:LV_MSG TYPE STRING.
DATA: LS_ROWDATA TYPE TRUXS_T_TEXT_DATA.
DATA: X TYPE I."两个物料列的间隔
DATA:LV_N TYPE I.
DATA: LV_COUNT 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
= 2
I_END_COL
= 255
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 DESCENDING.
READ TABLE ITAB INDEX 1.
MOVE ITAB-ROW TO LV_LINES.
SORT ITAB[] BY ROW COL.
LOOP AT ITAB.
LV_MSG
= '检查数据...' && ITAB-ROW && '/' && LV_LINES.
ON CHANGE OF ITAB-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.
IF GS_OUTPUT-ZICON1 = '@0A@'."红灯
PERFORM SET_STYLE(ZSDR018) USING 'SEL' 'DISABLE' CHANGING GS_OUTPUT-STYLE.
ENDIF.
APPEND GS_OUTPUT TO GT_OUTPUT.
CLEAR GS_LOAD.
CLEAR GS_OUTPUT.
CLEAR GS_CELLCOLOR.
ENDIF.
ENDON.
ASSIGN COMPONENT ITAB-COL OF STRUCTURE GS_LOAD TO <FS>.
"动态方法将值传到相应的内表
* <FS> = ITAB-VALUE.
TRY.
MOVE ITAB-VALUE TO <FS>.
CATCH CX_ROOT INTO L_EXCEPTION.
PERFORM SET_CALLSYTLE(ZSDR006) 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 OR ITAB-COL EQ 2.
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(ZSDR006) USING ITAB-COL GS_LOAD '日期格式错误' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
*检查送达方售达方是否存在
IF ITAB-COL EQ 3 OR ITAB-COL EQ 4.
*添加前置零
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = <FS>
IMPORTING
OUTPUT = <FS>.
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'
.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING ITAB-COL GS_LOAD '司机编号不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
IF ITAB-COL EQ 9.
SELECT SINGLE BEZEI INTO @DATA(BEZEI)
FROM TVKBT
WHERE VKBUR EQ @<FS>
AND SPRAS EQ @SY-LANGU.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING ITAB-COL GS_LOAD '部门编码不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
*检查产品是否存在
IF ITAB-COL EQ 12.
*取物料描述
*添加前置零
*判断是否含非数字的字符
IF <FS> CN '1234567890 '.
ELSE.
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(ZSDR006) USING ITAB-COL GS_LOAD '物料编码不正确' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
*
**检查验单单号是否已导入
SELECT SINGLE ZYDDH INTO @DATA(LV_ZYDDH)
FROM ZTSD009
WHERE ZYDDH EQ @GS_LOAD-ZYDDH
AND MATNR EQ @GS_LOAD-MATNR
AND SHPTO EQ @GS_LOAD-SHPTO.
IF SY-SUBRC EQ 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING 6 GS_LOAD '含相同产品的验单号已存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
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(ZSDR018) 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.
*下载模板
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_004' 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 .
DATA: LV_COND TYPE CHAR100.
IF R3 EQ 'X'.
SELECT
A
~* ,
A
~VBELN AS SO,
A
~VBELN_VL AS DN,
B
~ZDATE,
B
~VKORG,
B
~LGORT,
B
~ZUSER,
* B~NAME1,
C~MAKTX
INTO CORRESPONDING FIELDS OF TABLE @GT_OUTPUT
FROM ZTSD009 AS A
INNER
JOIN ZTSD008 AS B
ON A~BATNO EQ B~BATNO
* INNER JOIN KNA1 AS B ON A~KUNNR EQ B~KUNNR
INNER
JOIN MAKT AS C ON A~MATNR EQ C~MATNR
WHERE INDAT IN @S_INDAT
AND A~ZSJ IN @S_SJ
AND A~MATNR IN @S_MATNR
AND A~SHPTO IN @S_SHPTO "送达方
AND A~SLDTO IN @S_SLDTO "售达方
AND A~VKBUR IN @S_VKBUR "销售部门
AND A~ZYDDH IN @S_ZYDDH
AND A~VBELN IN @S_VBELN
AND B~ZDATE IN @S_ZDATE
AND B~VKORG EQ @P_VKORG
AND B~LGORT EQ @P_LGORT
AND B~ZUSER IN @S_ZUSER
.
ELSEIF R2 EQ 'X'.
* IF P_CB1 EQ 'X'.
* LV_COND = 'A~VBELN
SELECT
A
~* ,
A
~VBELN AS SO,
A
~VBELN_VL AS DN,
B
~ZDATE,
B
~VKORG,
B
~LGORT,
B
~ZUSER,
* B~NAME1,
C~MAKTX
INTO CORRESPONDING FIELDS OF TABLE @GT_OUTPUT
FROM ZTSD009 AS A
INNER
JOIN ZTSD008 AS B
ON A~BATNO EQ B~BATNO
* INNER JOIN KNA1 AS B ON A~KUNNR EQ B~KUNNR
INNER
JOIN MAKT AS C ON A~MATNR EQ C~MATNR
WHERE INDAT IN @S_INDAT
AND A~ZSJ IN @S_SJ
AND A~MATNR IN @S_MATNR
AND A~SHPTO IN @S_SHPTO "送达方
AND A~SLDTO IN @S_SLDTO "售达方
AND A~VKBUR IN @S_VKBUR "销售部门
AND A~ZYDDH IN @S_ZYDDH
* AND A~VBELN EQ @SPACE
AND A~VBELN IN @S_VBELN
AND B~ZDATE IN @S_ZDATE
AND B~VKORG EQ @P_VKORG
AND B~LGORT EQ @P_LGORT
AND B~ZUSER IN @S_ZUSER
.
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.
LOOP AT GT_OUTPUT ASSIGNING <WA_DATA>.
GT_BATNO
-BATNO = <WA_DATA>-BATNO.
GT_BATNO
-BATPO = <WA_DATA>-BATPO.
APPEND GT_BATNO.
* IF <WA_DATA>-SO NE SPACE.
* MOVE '-' TO <WA_DATA>-SEL.
* ENDIF.
<WA_DATA>
-RESLO = <WA_DATA>-LGORT(3) && '9'.
* SELECT SINGLE NAME1 INTO <WA_DATA>-NAME1
* FROM KNA1
* WHERE KUNNR = <WA_DATA>-KUNNR.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME2
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-ZSJ.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_HP
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-SHPTO.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_LD
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-SLDTO.
*价格
IF <WA_DATA>-MENGE NE 0.
<WA_DATA>
-ZYDJG = <WA_DATA>-ZYDJE / <WA_DATA>-MENGE.
ELSE.
<WA_DATA>
-ZYDJG = 0.
ENDIF.
* <WA_DATA>-ZYDJE = <WA_DATA>-ZYDJG * <WA_DATA>-MENGE.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDJE' 'DISABLE' CHANGING <WA_DATA>-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDDH' 'DISABLE' CHANGING <WA_DATA>-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'MENGE' 'DISABLE' CHANGING <WA_DATA>-STYLE.
IF R3 EQ 'X'.
*取状态
SELECT SINGLE WBSTK FKSTK
INTO ( <WA_DATA>-WBSTK, <WA_DATA>-FKSTK )
FROM VBUK
WHERE VBELN EQ <WA_DATA>-DN.
ENDIF.
ENDLOOP.
UNASSIGN <WA_DATA>
.
*将初始内表放入内存
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
-KEY = &6.
GS_STRUCTURE
-NO_ZERO = 'X'.
* IF R4 EQ 'X' AND R2 EQ 'X'.
* IF R2 EQ 'X'.
* ELSE.
IF &1 EQ 'SEL'.
GS_STRUCTURE
-CHECKBOX = 'X'.
GS_STRUCTURE
-EDIT = 'X'.
ENDIF.
* ENDIF.
IF R2 EQ 'X'.
IF &1 EQ 'ZYDJE'
OR &1 EQ 'ZYDDH'
OR &1 EQ 'MENGE'.
GS_STRUCTURE
-EDIT = 'X'.
ENDIF.
ENDIF.
IF &1 EQ 'ZYDDH'.
GS_STRUCTURE
-LOWERCASE = 'X'.
ENDIF.
APPEND GS_STRUCTURE TO GT_STRUCTURE.
CLEAR GS_STRUCTURE.
END-OF-DEFINITION.
IF R3 NE 'X'.
BUILD_FC
:
'SEL' '选择列' '' '' '' 'X',
'MSSG' '错误消息' '' '' '' ''.
ENDIF.
IF R1 EQ 'X'.
BUILD_FC
:
'ZICON1' '指示灯' '' 'ICON' 'ID' 'X'.
ENDIF.
BUILD_FC
:
'INDAT' '验单日期' '' 'ZTSD009' 'INDAT' 'X',
'ZSJ' '司机' '' 'KNA1' 'KUNNR' 'X',
'NAME2' '司机名称' '' 'KNA1' 'NAME1' 'X',
'SHPTO' '送达方编号' '' 'KNA1' 'KUNNR' 'X',
'NAME_HP' '送达方名称' '' 'KNA1' 'NAME1' 'X',
'SLDTO' '售达方编号' '' 'KNA1' 'KUNNR' 'X',
'NAME_LD' '售达方名称' '' 'KNA1' 'NAME1' 'X',
*'ZDATE' '导入日期' '' 'ZTSD008' 'ZDATE' '',
'LFDAT' '交货日期' '' 'LIKP' 'LFDAT' '',
'BATNO' '导入编号' '' 'ZTSD002' 'BATNO' '',
'BATPO' '导入项目' '' 'ZTSD002' 'BATPO' '',
'VKBUR' '销售部门' '' 'VBAK' 'VKBUR' '',
'ZR' '主任' '' 'ZTSD009' 'ZR' '',
'ZYWY' '业务员' '' 'ZTSD009' 'ZYWY' '',
'MATNR' '物料编号' '' 'MARA' 'MATNR' '',
'MAKTX' '物料名称' '' 'MAKT' 'MAKTX' '',
'MENGE' '验收数量' '' 'LIPS' 'LFIMG' '',
'MEINS' '数量单位' '' 'MARA' 'MEINS' '',
* 'CHARG' '批次' '' '' '',
'ZYDJG' '验收单价格' '' 'ZTSD009' 'ZYDJG' '',
'ZYDJE' '合计金额' '' 'ZTSD009' 'ZYDJE' '',
'ZYDDH' '验收单号' '' 'ZTSD009' 'ZYDDH' '',
'SO' '销售订单号' '' 'VBAK' 'VBELN' '',
'DN' '交货单号' '' 'LIKP' 'VBELN' '',
'BEIZHU' '备注' '' '' '' '',
'ZUSER' '导入人员' '' 'ZTSD008' 'ZUSER' ''.
IF R3 EQ 'X'.
BUILD_FC
:
'WBSTK' '发货状态' '' 'VBUK' 'WBSTK' '',
'FKSTK' '开票状态' '' 'VBUK' 'FKSTK' ''.
ENDIF.
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: CHECK_OKAY TYPE STRING.
CLEAR OK_CODE.
OK_CODE
= SY-UCOMM.
DATA: ANS TYPE STRING."GUI返回值
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'.
PERFORM FRM_CHECK_CHANGES CHANGING CHECK_OKAY.
IF CHECK_OKAY EQ 'F'."没做修改
*释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
ELSEIF CHECK_OKAY EQ 'T'."做了修改
*询问是否保存
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION
= '数据已修改,是否保存?'
TEXT_BUTTON_1
= '是'(003)
TEXT_BUTTON_2
= '否'(004)
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'."是
PERFORM FRM_SAVE_DATA USING ' ' CHANGING LV_RESULT.
IF LV_RESULT EQ 'S'.
MESSAGE '保存成功!' TYPE 'S'.
ELSEIF LV_RESULT EQ 'E'.
MESSAGE '保存失败!' TYPE 'S' DISPLAY LIKE 'E'.
ELSEIF LV_RESULT EQ 'N'.
MESSAGE '数据没有修改!' TYPE 'S'.
ENDIF.
**释放内存
* FREE MEMORY.
* "直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ELSEIF ANS EQ 'A'."取消
RETURN.
ELSE."否
**释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ENDIF.
ENDIF.
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 R3 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.
*显示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[].
*注册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.
*&---------------------------------------------------------------------*
*& Module MOD_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE MOD_COMMAND_9000 INPUT.
* DATA: CHECK_OKAY TYPE STRING.
CLEAR OK_CODE.
OK_CODE
= SY-UCOMM.
* DATA: ANS TYPE STRING."GUI返回值
CASE OK_CODE.
WHEN 'BACK'.
PERFORM FRM_CHECK_CHANGES CHANGING CHECK_OKAY.
IF CHECK_OKAY EQ 'F'."没做修改
*释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
ELSEIF CHECK_OKAY EQ 'T'."做了修改
*询问是否保存
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION
= '未保存数据将丢失,是否退出?'
TEXT_BUTTON_1
= '是'(001)
TEXT_BUTTON_2
= '否'(002)
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'."是
PERFORM FRM_SAVE_DATA USING ' ' CHANGING LV_RESULT.
IF LV_RESULT EQ 'S'.
MESSAGE '保存成功!' TYPE 'S'.
ELSEIF LV_RESULT EQ 'E'.
MESSAGE '保存失败!' TYPE 'S' DISPLAY LIKE 'E'.
ELSEIF LV_RESULT EQ 'N'.
MESSAGE '数据没有修改!' TYPE 'S'.
ENDIF.
**释放内存
* FREE MEMORY.
* "直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ELSEIF ANS EQ 'A'."取消
RETURN.
ELSE."否
**释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ENDIF.
ENDIF.
WHEN OTHERS.
ENDCASE.
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_ZTSD008
TYPE TABLE OF ZTSD008,
LT_ZTSD009
TYPE TABLE OF ZTSD009,
LT_ZTSD010
TYPE TABLE OF ZTSD010,
LT_ZTSD011
TYPE TABLE OF ZTSD011,
LT_OUTPUT
TYPE TABLE OF TY_OUTPUT,
LS_ZTSD008
TYPE ZTSD008, "超市验收单抬头
LS_ZTSD009
TYPE ZTSD009, "验收单明细
LS_ZTSD010
TYPE ZTSD010, "验收单修改日志
LS_ZTSD011
TYPE ZTSD011, "验收单与SO对应关系
LS_OUTPUT
TYPE TY_OUTPUT.
DATA: LV_BATNO TYPE CHAR10, "批导编号
LV_VERNO
TYPE CHAR3. "版本号
DATA: CHECK_OK TYPE STRING.
CLEAR:LV_BATNO, C_RESULT.
CLEAR:
LT_ZTSD008
,
LT_ZTSD009
,
LT_ZTSD010
,
LT_ZTSD011
,
LT_OUTPUT
,
LS_ZTSD008
,
LS_ZTSD009
,
LS_ZTSD010
,
LS_ZTSD011
,
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.
*生成批导编号
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR
= '02'
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.
*新版本号
MOVE 1 TO LV_VERNO.
*填充抬头表ZTSD008
MOVE LV_BATNO TO LS_ZTSD008-BATNO.
MOVE SY-UNAME TO LS_ZTSD008-ZUSER.
MOVE SY-DATUM TO LS_ZTSD008-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD008-ZTIME.
MOVE P_VKORG TO LS_ZTSD008-VKORG.
MOVE P_LGORT TO LS_ZTSD008-LGORT.
MODIFY ZTSD008 FROM LS_ZTSD008.
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_ZTSD009.
APPEND LS_ZTSD009 TO LT_ZTSD009.
CLEAR LS_ZTSD009.
*填充超市验单日志表
MOVE-CORRESPONDING GS_OUTPUT TO LS_ZTSD010.
* MOVE LV_BATNO TO LS_ZTSD003-BATNO.
* MOVE LV_VERNO TO LS_ZTSD003-VERNO.
MOVE SY-UNAME TO LS_ZTSD010-ZUSER.
MOVE SY-DATUM TO LS_ZTSD010-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD010-ZTIME.
APPEND LS_ZTSD010 TO LT_ZTSD010.
CLEAR LS_ZTSD010.
ENDLOOP.
ELSEIF R2 EQ 'X' ."如果是显示已导入数据,则检查是否有修改数据
C_RESULT
= 'N'.
SORT GT_OUTPUT BY BATNO."按批导编号排序
LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X'.
LS_OUTPUT
= GS_OUTPUT.
AT NEW BATNO.
LV_VERNO
= LS_OUTPUT-VERNO + 1."产生下一个版本,否则C_RESULT EQ SPACE
LS_OUTPUT
-VERNO = LV_VERNO.
*按批导编号更新版本号
MODIFY GT_OUTPUT FROM LS_OUTPUT TRANSPORTING VERNO
WHERE BATNO EQ LS_OUTPUT-BATNO.
* CLEAR LS_OUTPUT.
ENDAT.
*填充超市订单日志表
MOVE-CORRESPONDING LS_OUTPUT TO LS_ZTSD010.
* MOVE LS_OUTPUT-BATNO TO LS_ZTSD003-BATNO.
* MOVE LS_OUTPUT-VERNO TO LS_ZTSD003-VERNO.
MOVE LS_OUTPUT-SO TO LS_ZTSD010-VBELN.
MOVE LS_OUTPUT-DN TO LS_ZTSD010-VBELN_VL.
MOVE SY-UNAME TO LS_ZTSD010-ZUSER.
MOVE SY-DATUM TO LS_ZTSD010-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD010-ZTIME.
APPEND LS_ZTSD010 TO LT_ZTSD010.
CLEAR LS_ZTSD010.
*填充超市订单明细表
MOVE-CORRESPONDING LS_OUTPUT TO LS_ZTSD009.
MOVE LS_OUTPUT-SO TO LS_ZTSD009-VBELN.
MOVE LS_OUTPUT-DN TO LS_ZTSD009-VBELN_VL.
*如果是审批通过则修改状态
* IF U_STR EQ 'APPROVAL'.
* MOVE 'B' TO LS_ZTSD002-ZSTAT.
* ENDIF.
APPEND LS_ZTSD009 TO LT_ZTSD009.
CLEAR LS_ZTSD009.
*填充ZTSD011 销售订单表
IF U_STR EQ 'APPROVAL'.
MOVE: LS_OUTPUT-BATNO TO LS_ZTSD011-BATNO,
LS_OUTPUT
-BATPO TO LS_ZTSD011-BATPO,
LS_OUTPUT
-SO TO LS_ZTSD011-VBELN,
LS_OUTPUT
-ZYDDH TO LS_ZTSD011-ZYDDH.
MOVE SY-UNAME TO LS_ZTSD011-ZUSER.
MOVE SY-DATUM TO LS_ZTSD011-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD011-ZTIME.
APPEND LS_ZTSD011 TO LT_ZTSD011.
CLEAR LS_ZTSD011.
ENDIF.
CLEAR LS_OUTPUT.
ENDLOOP.
ENDIF.
DELETE GT_OUTPUT WHERE SEL EQ 'X'.
*更新数据库表
MODIFY ZTSD009 FROM TABLE LT_ZTSD009.
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
C_RESULT
= 'S'.
ELSE.
ROLLBACK WORK.
C_RESULT
= 'E'.
ENDIF.
MODIFY ZTSD010 FROM TABLE LT_ZTSD010.
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
C_RESULT
= 'S'.
ELSE.
ROLLBACK WORK.
C_RESULT
= 'E'.
ENDIF.
MODIFY ZTSD011 FROM TABLE LT_ZTSD011.
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
C_RESULT
= 'S'.
ELSE.
ROLLBACK WORK.
C_RESULT
= 'E'.
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.
MOVE: GS_SODATA-SO TO <WA_DATA>-SO,
GS_SODATA
-DN TO <WA_DATA>-DN.
ENDIF.
ENDLOOP.
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_MSG TYPE STRING.
CLEAR GT_SODATA.
LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X' AND SO EQ SPACE.
IF GS_OUTPUT-MSSG IS NOT INITIAL.
MESSAGE '存在错误数据,请检查!' TYPE 'S' DISPLAY LIKE 'E'.
C_RESULT
= 'E'.
RETURN.
ENDIF.
MOVE-CORRESPONDING GS_OUTPUT TO GS_SODATA.
MOVE GS_OUTPUT-MENGE TO GS_SODATA-KPEIN.
MOVE GS_OUTPUT-MEINS TO GS_SODATA-KMEIN.
MOVE '1000' TO GS_SODATA-WERKS.
* IF GS_SODATA-SHPTO IS INITIAL.
* GS_SODATA-SHPTO = GS_SODATA-KUNNR.
* ENDIF.
* IF GS_SODATA-SLDTO IS INITIAL.
* GS_SODATA-SLDTO = GS_SODATA-KUNNR.
* ENDIF.
GS_SODATA
-VSTEL = GS_SODATA-RESLO.
* PERFORM FRM_GET_SHIPPOINT USING GS_SODATA CHANGING GS_SODATA-VSTEL.
*售达方数据
* SELECT SINGLE VKORG VTWEG SPART VKBUR VKGRP
* INTO ( GS_SODATA-VKORG,GS_SODATA-VTWEG,GS_SODATA-SPART,
* GS_SODATA-VKBUR,GS_SODATA-VKGRP )
* FROM KNVV
* WHERE KUNNR EQ GS_OUTPUT-SLDTO
* AND VTWEG EQ '20'"直营
* AND LOEVM NE 'X'"删除标记
** AND VSBED EQ '99'"装运条件
* .
PERFORM FRM_CHECK_PARTNER USING GS_SODATA-SLDTO CHANGING LV_RESULT.
IF LV_RESULT EQ 'E'.
C_RESULT
= 'E'.
RETURN.
ENDIF.
* IF SY-SUBRC NE 0.
* MESSAGE '销售组织数据不正确,请检查分销渠道(20)。' TYPE 'S'.
* RETURN.
* ENDIF.
*检查条件记录是否存在
* SELECT SINGLE * INTO LS_A502
* FROM A502
* WHERE KSCHL EQ 'PRZ0'
* AND MATNR EQ GS_SODATA-MATNR.
* SELECT SINGLE * INTO LS_A515
* FROM A515
* WHERE KSCHL EQ 'PRZ0'
* AND KUNNR EQ GS_SODATA-KUNNR
* AND MATNR EQ GS_SODATA-MATNR.
*
* IF SY-SUBRC NE 0.
* MESSAGE '条件记录PRZ0不存在。' TYPE 'S'.
*
* 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 && '对应的成本中心不存在。'.
* MESSAGE S001 WITH LV_MSG 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 TYPE CHAR3,
LV_STRING
TYPE STRING.
DATA: LV_SO TYPE VBELN,
LV_DN
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: 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 ZYDDH.
LOOP AT GT_SODATA ASSIGNING <WA_SODATA>.
*做标记
<WA_SODATA>
-SO = 'X'.
<WA_SODATA>
-DN = '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>-RESLO."司机库
LS_ITEM
-TARGET_QU = <WA_SODATA>-MEINS.
LS_ITEM
-SALES_UNIT = <WA_SODATA>-MEINS.
* PERFORM FRM_GET_SHIPPOINT USING <WA_SODATA> CHANGING LS_ITEM-SHIP_POINT.
* LS_ITEM-SHIP_POINT = 9079.
LS_ITEM
-SHIP_POINT = <WA_SODATA>-VSTEL.
LS_ITEM
-ITEM_CATEG = 'TAN1'.
* LS_ITEM-CUST_MAT35 = <WA_SODATA>-ZYDDH."售达方客户物料记验单单号
* LS_ITEM-BATCH = <WA_SODATA>-CHARG.
* LS_ITEM-ITEM_CATEG = 'ZTN'.
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
-SHIP_POINT = 'X'.
* LS_ITEMX-CUST_MAT35 = 'X'.
* LS_ITEMX-BATCH = '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.
PERFORM GET_KSCHL(ZSDR021)
USING 'ZSO1'
<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>-ZYDJE.
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.
IF LV_POSNR EQ '300'.
CLEAR LV_POSNR.
LS_HEADER
-DOC_TYPE = 'ZSO1'.
LS_HEADER
-DOC_DATE = <WA_SODATA>-INDAT.
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
-PURCH_NO_C = 'ZY'.
LS_HEADER
-PURCH_NO_S = <WA_SODATA>-ZYDDH.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
TESTRUN
= TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'W'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ENDIF.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
* TESTRUN = TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
C_RESULT
= 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
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.
DO 5 TIMES .
SELECT SINGLE VBELN INTO LV_DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
ENDDO.
ENDIF.
CLEAR: LT_RETURN,
LT_ITEM
,
LT_ITEMX
,
LT_PNR
,
LT_SCH
,
LT_SCHX
,
LT_COND
,
LT_CONDX
,
LS_HEADER
.
*将单据号更新到内表
* IF LV_SO IS NOT INITIAL AND LV_DN IS NOT INITIAL.
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.
IF LV_DN IS NOT INITIAL.
LS_SODATA
-DN = LV_DN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_SODATA-DN
IMPORTING
OUTPUT = LS_SODATA-DN.
ELSE.
DO 5 TIMES.
SELECT SINGLE VBELN INTO LS_SODATA-DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
IF SY-SUBRC NE 0.
CLEAR LS_SODATA-DN .
ENDIF.
ENDDO.
ENDIF.
MODIFY GT_SODATA FROM LS_SODATA TRANSPORTING SO DN
WHERE SO EQ 'X' AND DN EQ 'X'.
CLEAR:LV_SO,LV_DN.
ELSE.
* PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
EXIT.
ENDIF.
CONTINUE.
ENDIF.
AT END OF ZYDDH.
CLEAR LV_POSNR.
LS_HEADER
-DOC_TYPE = 'ZSO1'.
LS_HEADER
-DOC_DATE = <WA_SODATA>-INDAT.
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
-PURCH_NO_C = 'ZY'.
LS_HEADER
-PURCH_NO_S = <WA_SODATA>-ZYDDH.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
TESTRUN
= TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'W'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ENDIF.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
* TESTRUN = TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
C_RESULT
= 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
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.
DO 5 TIMES .
SELECT SINGLE VBELN INTO LV_DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
ENDDO.
ENDIF.
CLEAR: LT_RETURN,
LT_ITEM
,
LT_ITEMX
,
LT_PNR
,
LT_SCH
,
LT_SCHX
,
LT_COND
,
LT_CONDX
,
LS_HEADER
.
*将单据号更新到内表
* IF LV_SO IS NOT INITIAL AND LV_DN IS NOT INITIAL.
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.
IF LV_DN IS NOT INITIAL.
LS_SODATA
-DN = LV_DN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_SODATA-DN
IMPORTING
OUTPUT = LS_SODATA-DN.
ELSE.
DO 5 TIMES.
SELECT SINGLE VBELN INTO LS_SODATA-DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
IF SY-SUBRC NE 0.
CLEAR LS_SODATA-DN .
ENDIF.
ENDDO.
ENDIF.
MODIFY GT_SODATA FROM LS_SODATA TRANSPORTING SO DN
WHERE SO EQ 'X' AND DN EQ 'X'.
CLEAR:LV_SO,LV_DN.
ELSE.
* PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
EXIT.
ENDIF.
CONTINUE.
ENDAT.
ENDLOOP.
IF C_RESULT IS INITIAL.
C_RESULT
= 'S'.
ENDIF.
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_OUTPUT1
-STYLE,
LS_OUTPUT
-SEL,
LS_OUTPUT
-STYLE.
IF LS_OUTPUT1 NE LS_OUTPUT.
MOVE 'T' TO C_OK."有区别
EXIT."只要有一个数据有区别就要记录
ELSE.
MOVE 'F' TO C_OK."没有区别
ENDIF.
ELSE.
*没读到初始数据说明是新数据
MOVE 'T' TO C_OK."有区别
EXIT."只要有一个数据有区别就要记录
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_POST_GOODS_ISSUE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_POST_DN.
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
.
FREE LT_SODATA.
LT_SODATA
= GT_SODATA.
SORT LT_SODATA BY DN.
DELETE ADJACENT DUPLICATES FROM LT_SODATA COMPARING DN.
LOOP AT LT_SODATA INTO LS_SODATA.
LV_VBELN
= LS_SODATA-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 = LS_SODATA-LFDAT .
* LV_VBKOK-BLDAT = SY-DATUM .
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'.
EXIT.
ELSE.
* C_RESULT = 'S'.
* RETURN.
ENDIF.
ENDLOOP.
CLEAR: LV_VBKOK,LT_VBPOK,LT_PROTT.
* CLEAR:LS_HEADER1,LS_CONTROL1,DELIVERY1,LS_TECH,HEADER_DEADLINE[],
* HEADER_DEADLINE,LT_RETURN[],LT_RETURN.
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.
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: LT_ZTSD009 TYPE TABLE OF ZTSD009,
LS_ZTSD009
TYPE ZTSD009,
LT_ZTSD006
TYPE TABLE OF ZTSD006,
LS_ZTSD006
TYPE ZTSD006.
DATA: L_LINE1 TYPE I,
L_LINE2
TYPE I.
*删除数量为0的行
DELETE GT_OUTPUT WHERE MENGE EQ 0.
CLEAR: LT_OUTPUT,LT_OUTPUT[].
LT_OUTPUT
= GT_OUTPUT.
SORT LT_OUTPUT BY ZYDDH MATNR ZSJ SLDTO SHPTO.
DELETE ADJACENT DUPLICATES FROM LT_OUTPUT COMPARING ZYDDH MATNR ZSJ SLDTO SHPTO.
L_LINE1
= LINES( LT_OUTPUT[] ).
L_LINE2
= LINES( GT_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.
LOOP AT GT_OUTPUT ASSIGNING <WA_DATA> WHERE ZICON1 NE '@0A@'.
IF <WA_DATA>-INDAT IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 1 GS_LOAD '请填写订单日期' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-LFDAT IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 2 GS_LOAD '请填写发货日期' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-SLDTO IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 3 GS_LOAD '请填写售达方' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-SHPTO IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 4 GS_LOAD '请填写送达方' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-ZYDDH IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 5 GS_LOAD '请填写验单单号' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-ZSJ IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 6 GS_LOAD '请填写司机' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-VKBUR IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 9 GS_LOAD '请填写销售部门' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
<WA_DATA>
-SEL = 'X'.
<WA_DATA>
-ZDATE = SY-DATUM.
<WA_DATA>
-VKORG = P_VKORG.
<WA_DATA>
-LGORT = P_LGORT.
* IF R4 EQ 'X'.
* <WA_DATA>-ZFREE = 'X'.
* ENDIF.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME2
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-ZSJ.
SELECT SINGLE MEINS INTO LV_MEINS
FROM MARA
WHERE MATNR EQ <WA_DATA>-MATNR.
*数量单位转换
TRANSLATE <WA_DATA>-MEINS TO UPPER CASE.
* IF <WA_DATA>-SHPTO IS INITIAL.
* MOVE <WA_DATA>-KUNNR TO <WA_DATA>-SHPTO.
* ENDIF.
* IF <WA_DATA>-SLDTO IS INITIAL.
* MOVE <WA_DATA>-KUNNR TO <WA_DATA>-SLDTO.
* ENDIF.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_HP
FROM KNA1
WHERE KUNNR = <WA_DATA>-SHPTO.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING 4 GS_LOAD '送达方不正确' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
ENDIF.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_LD
FROM KNA1
WHERE KUNNR = <WA_DATA>-SLDTO.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING 3 GS_LOAD '售达方不正确' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
ENDIF.
IF <WA_DATA>-MENGE GT '99999'.
PERFORM SET_CALLSYTLE(ZSDR006) USING 13 GS_LOAD '数量只能小于10万' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
ENDIF.
*价格
<WA_DATA>
-ZYDJG = <WA_DATA>-ZYDJE / <WA_DATA>-MENGE.
* <WA_DATA>-ZHJJE = <WA_DATA>-ZYDJG * <WA_DATA>-MENGE.
ENDLOOP.
UNASSIGN <WA_DATA>
.
*将初始内表放入内存
* LT_OUTPUT = GT_OUTPUT.
FREE LT_OUTPUT.
EXPORT LT_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.
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 = '9079'."司机库
LS_ITEM
-TARGET_QU = <WA_SODATA>-MEINS.
* LS_ITEM-BATCH = <WA_SODATA>-CHARG.
LS_ITEM
-ITEM_CATEG = 'TAN1'.
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
-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.
AT END OF SHPTO.
CLEAR LV_POSNR.
LS_HEADER
-DOC_TYPE = 'ZSO1'.
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.
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.
ENDAT.
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_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 VKORG EQ GS_SODATA-VKORG
AND VTWEG EQ '20'"直营
AND VKBUR EQ GS_SODATA-VKBUR
AND LOEVM NE 'X'"删除标记
.
IF SY-SUBRC NE 0.
C_RESULT
= 'E'.
LV_MSG
= '售达方' && U_SLDTO && '销售组织数据不正确,请检查。'.
MESSAGE S001 WITH LV_MSG DISPLAY LIKE 'E'.
* MESSAGE '销售组织数据不正确,请检查。' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* SELECT SINGLE SPOFI INTO @DATA(LV_SPOFI)
* FROM TVLK
* WHERE LFART EQ 'ZLF'."直营交货
*
* 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'.
** MESSAGE '售达方按工厂1000确定的装运点不存在。' TYPE 'S' 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'.
** MESSAGE '条件记录PRZ0不存在。' TYPE 'S' 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'.
** MESSAGE '条件记录PRZ0价格不能为0。' TYPE 'S' DISPLAY LIKE 'E'.
*
* RETURN.
* ENDIF.
* ENDIF.
C_RESULT
= 'S'.
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SET_STYLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM SET_STYLE USING P_VALUE P_ROWID.
DATA: L_STYPE TYPE STRING,
L_ROWID
TYPE I.
L_ROWID
= P_ROWID.
CLEAR GS_OUTPUT.
READ TABLE GT_OUTPUT INTO GS_OUTPUT INDEX L_ROWID.
L_STYPE
= 'DISABLE'.
IF P_VALUE EQ 'X'.
CHECK GS_OUTPUT-SO IS INITIAL.
L_STYPE
= 'ENABLE'.
ELSE.
L_STYPE
= 'DISABLE'.
ENDIF.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDJE' L_STYPE CHANGING GS_OUTPUT-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDDH' L_STYPE CHANGING GS_OUTPUT-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'MENGE' L_STYPE CHANGING GS_OUTPUT-STYLE.
MODIFY GT_OUTPUT FROM GS_OUTPUT INDEX L_ROWID.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_SHIPPOINT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<WA_DATA> text
* <--P_LS_ITEM_SHIP_POINT text
*----------------------------------------------------------------------*
FORM FRM_GET_SHIPPOINT USING U_WA TYPE TY_SODATA
CHANGING C_SHIP_POINT.
DATA: LV_VSBED TYPE KNVV-VSBED,
LV_VWERK
TYPE KNVV-VWERK,
LV_LGORT
TYPE LGORT_D,
LV_LFARV
TYPE TVAK-LFARV,
LV_SPOFI
TYPE TVLK-SPOFI,
LV_VSTEL
TYPE TVSTZ-VSTEL.
SELECT SINGLE VSBED VWERK
INTO ( LV_VSBED, LV_VWERK )
FROM KNVV
WHERE KUNNR EQ U_WA-SHPTO
AND VKORG EQ U_WA-VKORG
* AND VTWEG EQ U_WA-VTWEG
AND VTWEG EQ '20'"直营
AND SPART EQ U_WA-SPART
AND LOEVM NE 'X'"删除标记
.
SELECT SINGLE LFARV INTO LV_LFARV
FROM TVAK
WHERE AUART EQ 'ZSO1'.
SELECT SINGLE SPOFI INTO LV_SPOFI
FROM TVLK
WHERE LFART EQ LV_LFARV.
IF SY-SUBRC EQ 0.
IF LV_SPOFI EQ SPACE. "特定工厂装运点
SELECT SINGLE VSTEL INTO C_SHIP_POINT
FROM TVSTZ
WHERE VSBED EQ LV_VSBED
AND LADGR EQ '0001'
AND WERKS EQ LV_VWERK.
ELSE."按库存地点确定装运点
LV_LGORT
= U_WA-RESLO."司机库
*将库存地点带入行项目中
SELECT SINGLE VSTEL INTO C_SHIP_POINT
FROM TVSTZ_STORLOC
WHERE VSBED EQ LV_VSBED
AND LADGR EQ '0001'
AND WERKS EQ LV_VWERK
AND LGORT EQ LV_LGORT.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SEL_ALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SEL_ALL .
DATA : LT_FILTERED_ENTRIES TYPE LVC_T_FIDX,
LV_INDEX
TYPE SY-TABIX.
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.
LV_INDEX
= SY-TABIX.
READ TABLE LT_FILTERED_ENTRIES TRANSPORTING NO FIELDS WITH KEY TABLE_LINE = LV_INDEX.
IF SY-SUBRC NE 0.
<WA_DATA>
-SEL = 'X'.
PERFORM SET_STYLE USING 'X' LV_INDEX.
ENDIF.
CLEAR LV_INDEX.
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_AUTHORITY_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_AUTHORITY_CHECK .
AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
ID 'VKORG' FIELD P_VKORG
ID 'VTWEG' DUMMY
ID 'SPART' DUMMY
ID 'ACTVT' DUMMY.
IF SY-SUBRC <> 0.
MESSAGE '您没有销售组织' && P_VKORG && '的权限' TYPE 'E'.
RETURN.
ENDIF.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'ACTVT' DUMMY
ID 'WERKS' FIELD '1000'
ID 'LGORT' FIELD P_LGORT
ID 'BWART' DUMMY.
IF SY-SUBRC <> 0.
MESSAGE '您没有库存地点' && P_LGORT && '的权限' TYPE 'E'.
RETURN.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DELETE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DELETE_DATA .
LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X' AND SO IS NOT INITIAL.
*判断销售订单是否被删除
SELECT SINGLE VBELN INTO @DATA(LV_VBELN)
FROM VBAK
WHERE VBELN EQ @GS_OUTPUT-SO.
IF SY-SUBRC EQ 0.
MESSAGE '所选择数据存在已创建订单,不允许删除' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
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 GT_DEL.
GT_DEL
-BATNO = GS_OUTPUT-BATNO.
GT_DEL
-BATPO = GS_OUTPUT-BATPO.
GT_DEL
-INDAT = GS_OUTPUT-INDAT.
APPEND GT_DEL TO GT_DEL.
CLEAR GS_OUTPUT.
ENDLOOP.
DELETE GT_OUTPUT WHERE SEL EQ 'X'.
IF GT_DEL[] IS NOT INITIAL.
DELETE ZTSD009 FROM TABLE GT_DEL[].
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
MESSAGE '删除成功!' TYPE 'S'.
*&---------------------------------------------------------------------*
*& Report ZSDR005
*&
*&---------------------------------------------------------------------*
*&程序名称:直营平台-超市验单导入
*&事物代码:ZSD025
*&导入模板:直接下载
*&作者:侯康明
*&时间:2016/2/29
*&---------------------------------------------------------------------*
REPORT ZSDR046 MESSAGE-ID 00.
TYPE-POOLS:OLE2,SLIS,ICON.
FIELD-SYMBOLS: <FS>.
TABLES: SSCRFIELDS,ZTSD008,ZTSD009,MCHB.
TYPES: BEGIN OF TY_OUTPUT,
SEL
TYPE C,
BATNO
TYPE ZTSD008-BATNO, "批导序号
BATPO
TYPE ZTSD009-BATPO, "验单批导序号
VERNO
TYPE ZTSD010-VERNO, "版本号
ZDATE
TYPE ZTSD008-ZDATE, "导入日期
INDAT
TYPE ZTSD009-INDAT, "验单日期
LFDAT
TYPE LIKP-LFDAT, "实际交货日期
* KUNNR TYPE KUNNR, "客户号
* NAME1 TYPE KNA1-NAME1, "客户名称
ZSJ
TYPE KUNNR, "司机
ZR
TYPE CHAR30, "主任
ZYWY
TYPE CHAR30, "业务员
NAME2
TYPE KNA1-NAME1, "司机名称
* KUNNR1 TYPE KUNNR, "司机系统
* NAME2 TYPE KNA1-NAME1, "司机系统名称
MATNR
TYPE ZTSD009-MATNR, "物料号
MAKTX
TYPE MAKT-MAKTX, "物料描述
MENGE
TYPE ZTSD009-MENGE, "验单数量
MEINS
TYPE MEINS, "数量单位
* CHARG TYPE CHARG_D, "批次
ZYDJG
TYPE ZTSD009-ZYDJG, "验单价格
ZYDJE
TYPE ZTSD009-ZYDJE, "合计金额
ZYDDH
TYPE ZTSD009-ZYDDH, "验单单号
SO
TYPE ZTSD009-VBELN, "SO
DN
TYPE VBELN_VL, "DN
ZICON1
TYPE CHAR4, "导入状态
VKBUR
TYPE VKBUR, "销售部门
VKORG
TYPE VKORG,
LGORT
TYPE LGORT_D,
RESLO
TYPE RESLO, "发货库存地
SHPTO
TYPE KUNNR, "送达方
NAME_HP
TYPE NAME1, "送达方名称
SLDTO
TYPE KUNNR, "售达方
NAME_LD
TYPE NAME1, "售达方名称
CELLCOLOR
TYPE LVC_T_SCOL, "控制单元格颜色
STYLE
TYPE LVC_T_STYL, "控制单元格可否编辑
MSSG
TYPE BAPI_MSG, "消息内容
ZFREE
TYPE C,
BEIZHU
TYPE CHAR255, "备注
ZUSER
TYPE ZTSD008-ZUSER,
WBSTK
TYPE VBUK-WBSTK, "货物移动状态
FKSTK
TYPE VBUK-FKSTK, "开票状态
END OF TY_OUTPUT.
TYPES: BEGIN OF TY_LOAD,
INDAT
TYPE ZTSD009-INDAT, "验单日期
LFDAT
TYPE LIKP-LFDAT, "交货日期
* KUNNR TYPE KUNNR,
* BLANK TYPE C, "占位
SLDTO
TYPE KUNNR, "售达方
* BLANK1 TYPE C, "占位
SHPTO
TYPE KUNNR, "送达方
* BLANK2 TYPE C, "占位
ZYDDH
TYPE ZTSD009-ZYDDH, "验单单号
ZSJ
TYPE KUNNR, "司机
* BLANK5 TYPE C, "占位
ZR
TYPE CHAR30, "主任
ZYWY
TYPE CHAR30, "业务员
VKBUR
TYPE VKBUR, "销售部门
* BLANK3 TYPE C, "占位
BEIZHU
TYPE CHAR255, "备注
MEINS
TYPE MEINS, "数量单位
MATNR
TYPE ZTSD009-MATNR,
MENGE
TYPE MENGE_D, "验单数量
ZYDJG
TYPE ZTSD009-ZYDJG, "验单价格
ZYDJE
TYPE ZTSD009-ZYDJE, "验单金额
* BLANK4 TYPE C, "
END OF TY_LOAD.
TYPES: BEGIN OF TY_SODATA,
ZYDDH
TYPE ZTSD009-ZYDDH, "验单单号
INDAT
TYPE ZTSD009-INDAT,
LFDAT
TYPE LIKP-LFDAT,
* 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, "销售组
VKBUR
TYPE VBAK-VKBUR, "销售部门
VSBED
TYPE KNVV-VSBED, "装运条件
MATNR
TYPE EKPO-MATNR, "物料代码
VSTEL
TYPE VSTEL, "装运点
RESLO
TYPE RESLO, "发货库存地
WERKS
TYPE VBAP-WERKS, "
MENGE
TYPE KWMENG, "数量
MEINS
TYPE MEINS, "单位
* CHARG TYPE CHARG_D, "批次
ZYDJE
TYPE ZTSD009-ZYDJE, "验单价格
BATNO
TYPE ZTSD008-BATNO, "批导序号
BATPO
TYPE ZTSD009-BATPO, "批导行项目号
SO
TYPE VBAK-VBELN, "销售订单号
DN
TYPE LIKP-VBELN, "交货单号
KPEIN
TYPE KOMV-KPEIN, "条件定价单位
KMEIN
TYPE KOMV-KMEIN, "条件单位
END OF TY_SODATA.
TYPES: BEGIN OF TYP_HEADER,
ZTEXT
(10),
END OF TYP_HEADER.
TYPES: BEGIN OF TY_MESG,
MESG
TYPE CHAR255,
END OF TY_MESG.
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 TABLE OF TY_LOAD,
GT_OUTPUT
TYPE TABLE OF TY_OUTPUT,
GT_SODATA
TYPE TABLE OF TY_SODATA.
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 P_MODE TYPE C VALUE 'N'.
DATA: BEGIN OF GT_BATNO OCCURS 0,
BATNO
TYPE ZBATNO,
BATPO
TYPE ZBATPO,
END OF GT_BATNO.
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.
DATA: GT_DEL TYPE TABLE OF ZTSD009 WITH HEADER LINE.
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.
*SELECT-OPTIONS:
PARAMETERS: P_VKORG TYPE VBAK-VKORG,
P_LGORT
TYPE T001L-LGORT.
PARAMETERS: P_UFILE LIKE RLGRAP-FILENAME MODIF ID M1."上传文件路径
SELECT-OPTIONS:
S_ZUSER
FOR ZTSD008-ZUSER MODIF ID M2,"导入用户
S_INDAT
FOR ZTSD009-INDAT MODIF ID M2,"验单日期
S_ZDATE
FOR ZTSD008-ZDATE MODIF ID M2,"导入日期
S_SJ
FOR ZTSD009-KUNNR MODIF ID M2,"客户编号
S_MATNR
FOR ZTSD009-MATNR MODIF ID M2,"物料编号
S_SHPTO
FOR ZTSD009-SHPTO MODIF ID M2, "送达方
S_SLDTO
FOR ZTSD009-SLDTO MODIF ID M2, "售达方
S_VKBUR
FOR ZTSD009-VKBUR MODIF ID M2, "销售部门
S_ZYDDH
FOR ZTSD009-ZYDDH LOWER CASE MODIF ID M2, "验单单号
S_VBELN
FOR ZTSD009-VBELN MODIF ID M2. "销售订单号
*PARAMETERS: P_CB1 TYPE C AS CHECKBOX MODIF ID M4,
* P_CB2 TYPE C AS CHECKBOX MODIF ID M4.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN: FUNCTION KEY 1. "激活按钮
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TITLE1.
PARAMETERS: R1 RADIOBUTTON GROUP RG1 USER-COMMAND USR DEFAULT 'X', "上传批导
R2
RADIOBUTTON GROUP RG1, "提交验单
R3
RADIOBUTTON GROUP RG1. "显示导入数据
SELECTION-SCREEN END OF BLOCK B2.
*SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TITLE2.
*SELECTION-SCREEN BEGIN OF LINE.
*PARAMETERS: R3 RADIOBUTTON GROUP RG2 DEFAULT 'X'."本品
*SELECTION-SCREEN COMMENT (5) TEXT-001 FOR FIELD R1.
*PARAMETERS: R4 RADIOBUTTON GROUP RG2."赠品
*SELECTION-SCREEN COMMENT (5) TEXT-002 FOR FIELD R2."
*SELECTION-SCREEN END OF LINE.
*SELECTION-SCREEN END OF BLOCK B3.
SELECTION-SCREEN BEGIN OF BLOCK B4 WITH FRAME TITLE TEXT-007.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: R5 RADIOBUTTON GROUP RG3 USER-COMMAND USR2 DEFAULT 'X'."石家庄直营
SELECTION-SCREEN COMMENT (7) TEXT-005 FOR FIELD R5.
PARAMETERS: R6 RADIOBUTTON GROUP RG3 ."未打印
SELECTION-SCREEN COMMENT (7) TEXT-006 FOR FIELD R6."外阜直营
*PARAMETERS: R6 RADIOBUTTON GROUP RG2."全部
*SELECTION-SCREEN COMMENT (5) TEXT-005 FOR FIELD R6."全部
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B4.
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
SSCRFIELDS
-FUNCTXT_01 = '下载模板'. "定义按钮文本
TITLE1
= '操作类型'.
* TITLE2 = '验收产品类型'.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE SSCRFIELDS-UCOMM. "处理按钮命令
WHEN'FC01'.
PERFORM FRM_DOWNLOAD_TEMPLATE.
ENDCASE.
AT SELECTION-SCREEN OUTPUT.
IF R5 EQ 'X'.
* SUBMIT ZSDR005 VIA SELECTION-SCREEN .
ELSEIF R6 EQ 'X'.
SUBMIT ZSDR019 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 R3 EQ 'X'.
SCREEN-ACTIVE = 1.
ELSE.
SCREEN-ACTIVE = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M3'.
IF R3 EQ 'X'.
SCREEN-ACTIVE = 1.
ELSE.
SCREEN-ACTIVE = 0.
ENDIF.
MODIFY SCREEN.
WHEN 'M4'.
IF R2 EQ 'X'.
SCREEN-ACTIVE = 1.
ELSE.
SCREEN-ACTIVE = 0.
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','LT_RETURN'.
IF P_VKORG IS INITIAL.
MESSAGE '请输入销售组织。' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF P_LGORT IS INITIAL.
MESSAGE '请输入库存地点。' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
PERFORM FRM_AUTHORITY_CHECK.
*上传文件
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'
*显示保存的数据
*DELETE FROM: ZTSD008,ZTSD009,ZTSD010,ZTSD011. COMMIT WORK AND WAIT.
PERFORM FRM_GET_DATA.
PERFORM FRM_PROCESS_DATA.
ENDIF.
IF GT_OUTPUT IS INITIAL.
MESSAGE '没有符合要求的数据' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
IF R2 EQ '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
.
PRIVATE SECTION.
DATA ROWS TYPE LVC_T_ROW.
DATA RS TYPE LVC_S_ROW.
DATA ERROR_IN_DATA TYPE C.
DATA LS_MODI TYPE LVC_S_MODI.
DATA G_IND TYPE I.
DATA LV_SEL TYPE C.
METHODS:
GET_ZYDJE
IMPORTING
E_MODI
TYPE LVC_S_MODI
E_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL,
GET_MENGE
IMPORTING
E_MODI
TYPE LVC_S_MODI
E_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
ENDCLASS. "GC_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------
* CLASS GC_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------
CLASS GC_EVENT_RECEIVER IMPLEMENTATION.
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.
IF R3 NE 'X'.
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.
ENDIF.
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'.
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-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@'."红灯.
* LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X' AND SO IS INITIAL.
* ENDLOOP.
* CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
* EXPORTING
* IS_STABLE = GS_STABLE
* I_SOFT_REFRESH = 'X'.
WHEN 'CAN_ALL'.
CLEAR GS_OUTPUT.
GS_OUTPUT
-SEL = ' '.
MODIFY GT_OUTPUT FROM GS_OUTPUT TRANSPORTING SEL WHERE SEL EQ 'X'.
LOOP AT GT_OUTPUT INTO GS_OUTPUT.
PERFORM SET_STYLE USING '' SY-TABIX.
ENDLOOP.
* CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
* EXPORTING
* IS_STABLE = GS_STABLE
* I_SOFT_REFRESH = 'X'.
WHEN 'DEL'.
*询问是否确认
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION
= '确认删除所选数据?'
TEXT_BUTTON_1
= '是'(003)
TEXT_BUTTON_2
= '否'(004)
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 'OKAY'.
PERFORM FRM_CONFIRM_DATA CHANGING LV_RESULT.
CHECK 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.
*DN过账
PERFORM FRM_POST_DN.
WHEN OTHERS.
ENDCASE.
CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE
= GS_STABLE
I_SOFT_REFRESH
= 'X'.
ENDMETHOD.
METHOD HANDLE_DATA_CHANGED.
LOOP AT ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MODI.
CASE LS_MODI-FIELDNAME.
WHEN 'MENGE'.
CALL METHOD GET_MENGE
EXPORTING
E_MODI
= LS_MODI
E_DATA_CHANGED
= ER_DATA_CHANGED.
WHEN 'ZYDJE'.
CALL METHOD GET_ZYDJE
EXPORTING
E_MODI
= LS_MODI
E_DATA_CHANGED
= ER_DATA_CHANGED.
ENDCASE.
ENDLOOP.
CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE
= GS_STABLE
I_SOFT_REFRESH
= 'X'.
ENDMETHOD.
METHOD HANDLE_CHANGE_FINISH.
DATA: LS_CELL TYPE LVC_S_MODI.
CLEAR LS_CELL.
READ TABLE ET_GOOD_CELLS INTO LS_CELL INDEX 1.
CASE LS_CELL-FIELDNAME.
WHEN 'SEL'.
PERFORM SET_STYLE USING LS_CELL-VALUE LS_CELL-ROW_ID.
CALL METHOD GCT_ALV->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE
= GS_STABLE
I_SOFT_REFRESH
= 'X'.
ENDCASE.
ENDMETHOD.
METHOD GET_ZYDJE.
DATA LV_YDJE TYPE ZTSD009-ZYDJE.
DATA LV_TABIX LIKE SY-TABIX.
CALL METHOD E_DATA_CHANGED->GET_CELL_VALUE
EXPORTING
I_ROW_ID
= E_MODI-ROW_ID
I_FIELDNAME
= E_MODI-FIELDNAME
IMPORTING
E_VALUE
= LV_YDJE.
* CHECK NOT LV_YDJE IS INITIAL.
READ TABLE GT_OUTPUT ASSIGNING <WA_DATA> INDEX E_MODI-ROW_ID.
* CHECK <WA_DATA>-MEINS IS NOT INITIAL.
IF SY-SUBRC EQ 0.
<WA_DATA>
-MSSG = ' '.
IF LV_YDJE LE 0.
<WA_DATA>
-MSSG = '合计金额不能为零,请修改!'.
ERROR_IN_DATA
= 'X'.
* CALL METHOD E_DATA_CHANGED->ADD_PROTOCOL_ENTRY
* EXPORTING
* I_MSGID = 'ZSD001'
* I_MSGNO = '000'
* I_MSGTY = 'E'
* I_MSGV1 = LV_YDJE
* I_MSGV2 = '合计金额不能为零,请修改!'
* I_MSGV3 = ''
* I_FIELDNAME = E_MODI-FIELDNAME
* I_ROW_ID = E_MODI-ROW_ID.
* IF ERROR_IN_DATA = 'X'.
* CALL METHOD E_DATA_CHANGED->DISPLAY_PROTOCOL.
* ENDIF.
ELSE.
* BREAK B012.
IF <WA_DATA>-MENGE NE 0.
<WA_DATA>
-ZYDJG = LV_YDJE / <WA_DATA>-MENGE.
ELSE.
<WA_DATA>
-ZYDJG = 0.
ENDIF.
ENDIF.
ENDIF.
UNASSIGN <WA_DATA>
.
FREE:LV_YDJE.
ENDMETHOD.
METHOD GET_MENGE.
DATA LV_MENGE TYPE ZTSD009-MENGE.
DATA LV_MEINS TYPE MEINS.
DATA LV_TABIX LIKE SY-TABIX.
DATA:
LV_STRING
TYPE STRING,
S1
TYPE STRING,
S2
TYPE STRING.
CALL METHOD E_DATA_CHANGED->GET_CELL_VALUE
EXPORTING
I_ROW_ID
= E_MODI-ROW_ID
I_FIELDNAME
= E_MODI-FIELDNAME
IMPORTING
E_VALUE
= LV_MENGE.
READ TABLE GT_OUTPUT ASSIGNING <WA_DATA> INDEX E_MODI-ROW_ID.
IF SY-SUBRC EQ 0.
<WA_DATA>
-MSSG = ' '.
IF LV_MENGE LE 0.
<WA_DATA>
-MSSG = '验收数量不能为零,请修改!'.
ERROR_IN_DATA
= 'X'.
* CALL METHOD E_DATA_CHANGED->ADD_PROTOCOL_ENTRY
* EXPORTING
* I_MSGID = 'ZSD001'
* I_MSGNO = '000'
* I_MSGTY = 'E'
* I_MSGV1 = LV_MENGE
* I_MSGV2 = '验收数量不能为零,请修改!'
* I_MSGV3 = ''
* I_FIELDNAME = E_MODI-FIELDNAME
* I_ROW_ID = E_MODI-ROW_ID.
* IF ERROR_IN_DATA = 'X'.
* CALL METHOD E_DATA_CHANGED->DISPLAY_PROTOCOL.
* ENDIF.
ELSE.
LV_STRING
= LV_MENGE.
SPLIT LV_STRING AT '.' INTO S1 S2.
IF S2 NE 0.
<WA_DATA>
-MSSG = '验收数量不能含小数。'.
ERROR_IN_DATA
= 'X'.
* CALL METHOD E_DATA_CHANGED->ADD_PROTOCOL_ENTRY
* EXPORTING
* I_MSGID = 'ZSD001'
* I_MSGNO = '000'
* I_MSGTY = 'E'
* I_MSGV1 = LV_MENGE
* I_MSGV2 = '验收数量不能含小数。请修改!'
* I_MSGV3 = ''
* I_FIELDNAME = E_MODI-FIELDNAME
* I_ROW_ID = E_MODI-ROW_ID.
* IF ERROR_IN_DATA = 'X'.
* CALL METHOD E_DATA_CHANGED->DISPLAY_PROTOCOL.
* ENDIF.
* ENDIF.
ENDIF.
*更新验单价格
<WA_DATA>
-ZYDJG = <WA_DATA>-ZYDJE / <WA_DATA>-MENGE.
ENDIF.
ENDIF.
UNASSIGN <WA_DATA>
.
FREE:LV_MEINS, LV_MENGE.
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.
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:LV_MSG TYPE STRING.
DATA: LS_ROWDATA TYPE TRUXS_T_TEXT_DATA.
DATA: X TYPE I."两个物料列的间隔
DATA:LV_N TYPE I.
DATA: LV_COUNT 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
= 2
I_END_COL
= 255
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 DESCENDING.
READ TABLE ITAB INDEX 1.
MOVE ITAB-ROW TO LV_LINES.
SORT ITAB[] BY ROW COL.
LOOP AT ITAB.
LV_MSG
= '检查数据...' && ITAB-ROW && '/' && LV_LINES.
ON CHANGE OF ITAB-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.
IF GS_OUTPUT-ZICON1 = '@0A@'."红灯
PERFORM SET_STYLE(ZSDR018) USING 'SEL' 'DISABLE' CHANGING GS_OUTPUT-STYLE.
ENDIF.
APPEND GS_OUTPUT TO GT_OUTPUT.
CLEAR GS_LOAD.
CLEAR GS_OUTPUT.
CLEAR GS_CELLCOLOR.
ENDIF.
ENDON.
ASSIGN COMPONENT ITAB-COL OF STRUCTURE GS_LOAD TO <FS>.
"动态方法将值传到相应的内表
* <FS> = ITAB-VALUE.
TRY.
MOVE ITAB-VALUE TO <FS>.
CATCH CX_ROOT INTO L_EXCEPTION.
PERFORM SET_CALLSYTLE(ZSDR006) 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 OR ITAB-COL EQ 2.
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(ZSDR006) USING ITAB-COL GS_LOAD '日期格式错误' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
*检查送达方售达方是否存在
IF ITAB-COL EQ 3 OR ITAB-COL EQ 4.
*添加前置零
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = <FS>
IMPORTING
OUTPUT = <FS>.
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'
.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING ITAB-COL GS_LOAD '司机编号不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
IF ITAB-COL EQ 9.
SELECT SINGLE BEZEI INTO @DATA(BEZEI)
FROM TVKBT
WHERE VKBUR EQ @<FS>
AND SPRAS EQ @SY-LANGU.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING ITAB-COL GS_LOAD '部门编码不存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
*检查产品是否存在
IF ITAB-COL EQ 12.
*取物料描述
*添加前置零
*判断是否含非数字的字符
IF <FS> CN '1234567890 '.
ELSE.
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(ZSDR006) USING ITAB-COL GS_LOAD '物料编码不正确' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
*
**检查验单单号是否已导入
SELECT SINGLE ZYDDH INTO @DATA(LV_ZYDDH)
FROM ZTSD009
WHERE ZYDDH EQ @GS_LOAD-ZYDDH
AND MATNR EQ @GS_LOAD-MATNR
AND SHPTO EQ @GS_LOAD-SHPTO.
IF SY-SUBRC EQ 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING 6 GS_LOAD '含相同产品的验单号已存在' CHANGING GS_OUTPUT-CELLCOLOR GS_OUTPUT-MSSG.
ENDIF.
ENDIF.
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(ZSDR018) 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.
*下载模板
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_004' 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 .
DATA: LV_COND TYPE CHAR100.
IF R3 EQ 'X'.
SELECT
A
~* ,
A
~VBELN AS SO,
A
~VBELN_VL AS DN,
B
~ZDATE,
B
~VKORG,
B
~LGORT,
B
~ZUSER,
* B~NAME1,
C~MAKTX
INTO CORRESPONDING FIELDS OF TABLE @GT_OUTPUT
FROM ZTSD009 AS A
INNER
JOIN ZTSD008 AS B
ON A~BATNO EQ B~BATNO
* INNER JOIN KNA1 AS B ON A~KUNNR EQ B~KUNNR
INNER
JOIN MAKT AS C ON A~MATNR EQ C~MATNR
WHERE INDAT IN @S_INDAT
AND A~ZSJ IN @S_SJ
AND A~MATNR IN @S_MATNR
AND A~SHPTO IN @S_SHPTO "送达方
AND A~SLDTO IN @S_SLDTO "售达方
AND A~VKBUR IN @S_VKBUR "销售部门
AND A~ZYDDH IN @S_ZYDDH
AND A~VBELN IN @S_VBELN
AND B~ZDATE IN @S_ZDATE
AND B~VKORG EQ @P_VKORG
AND B~LGORT EQ @P_LGORT
AND B~ZUSER IN @S_ZUSER
.
ELSEIF R2 EQ 'X'.
* IF P_CB1 EQ 'X'.
* LV_COND = 'A~VBELN
SELECT
A
~* ,
A
~VBELN AS SO,
A
~VBELN_VL AS DN,
B
~ZDATE,
B
~VKORG,
B
~LGORT,
B
~ZUSER,
* B~NAME1,
C~MAKTX
INTO CORRESPONDING FIELDS OF TABLE @GT_OUTPUT
FROM ZTSD009 AS A
INNER
JOIN ZTSD008 AS B
ON A~BATNO EQ B~BATNO
* INNER JOIN KNA1 AS B ON A~KUNNR EQ B~KUNNR
INNER
JOIN MAKT AS C ON A~MATNR EQ C~MATNR
WHERE INDAT IN @S_INDAT
AND A~ZSJ IN @S_SJ
AND A~MATNR IN @S_MATNR
AND A~SHPTO IN @S_SHPTO "送达方
AND A~SLDTO IN @S_SLDTO "售达方
AND A~VKBUR IN @S_VKBUR "销售部门
AND A~ZYDDH IN @S_ZYDDH
* AND A~VBELN EQ @SPACE
AND A~VBELN IN @S_VBELN
AND B~ZDATE IN @S_ZDATE
AND B~VKORG EQ @P_VKORG
AND B~LGORT EQ @P_LGORT
AND B~ZUSER IN @S_ZUSER
.
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.
LOOP AT GT_OUTPUT ASSIGNING <WA_DATA>.
GT_BATNO
-BATNO = <WA_DATA>-BATNO.
GT_BATNO
-BATPO = <WA_DATA>-BATPO.
APPEND GT_BATNO.
* IF <WA_DATA>-SO NE SPACE.
* MOVE '-' TO <WA_DATA>-SEL.
* ENDIF.
<WA_DATA>
-RESLO = <WA_DATA>-LGORT(3) && '9'.
* SELECT SINGLE NAME1 INTO <WA_DATA>-NAME1
* FROM KNA1
* WHERE KUNNR = <WA_DATA>-KUNNR.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME2
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-ZSJ.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_HP
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-SHPTO.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_LD
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-SLDTO.
*价格
IF <WA_DATA>-MENGE NE 0.
<WA_DATA>
-ZYDJG = <WA_DATA>-ZYDJE / <WA_DATA>-MENGE.
ELSE.
<WA_DATA>
-ZYDJG = 0.
ENDIF.
* <WA_DATA>-ZYDJE = <WA_DATA>-ZYDJG * <WA_DATA>-MENGE.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDJE' 'DISABLE' CHANGING <WA_DATA>-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDDH' 'DISABLE' CHANGING <WA_DATA>-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'MENGE' 'DISABLE' CHANGING <WA_DATA>-STYLE.
IF R3 EQ 'X'.
*取状态
SELECT SINGLE WBSTK FKSTK
INTO ( <WA_DATA>-WBSTK, <WA_DATA>-FKSTK )
FROM VBUK
WHERE VBELN EQ <WA_DATA>-DN.
ENDIF.
ENDLOOP.
UNASSIGN <WA_DATA>
.
*将初始内表放入内存
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
-KEY = &6.
GS_STRUCTURE
-NO_ZERO = 'X'.
* IF R4 EQ 'X' AND R2 EQ 'X'.
* IF R2 EQ 'X'.
* ELSE.
IF &1 EQ 'SEL'.
GS_STRUCTURE
-CHECKBOX = 'X'.
GS_STRUCTURE
-EDIT = 'X'.
ENDIF.
* ENDIF.
IF R2 EQ 'X'.
IF &1 EQ 'ZYDJE'
OR &1 EQ 'ZYDDH'
OR &1 EQ 'MENGE'.
GS_STRUCTURE
-EDIT = 'X'.
ENDIF.
ENDIF.
IF &1 EQ 'ZYDDH'.
GS_STRUCTURE
-LOWERCASE = 'X'.
ENDIF.
APPEND GS_STRUCTURE TO GT_STRUCTURE.
CLEAR GS_STRUCTURE.
END-OF-DEFINITION.
IF R3 NE 'X'.
BUILD_FC
:
'SEL' '选择列' '' '' '' 'X',
'MSSG' '错误消息' '' '' '' ''.
ENDIF.
IF R1 EQ 'X'.
BUILD_FC
:
'ZICON1' '指示灯' '' 'ICON' 'ID' 'X'.
ENDIF.
BUILD_FC
:
'INDAT' '验单日期' '' 'ZTSD009' 'INDAT' 'X',
'ZSJ' '司机' '' 'KNA1' 'KUNNR' 'X',
'NAME2' '司机名称' '' 'KNA1' 'NAME1' 'X',
'SHPTO' '送达方编号' '' 'KNA1' 'KUNNR' 'X',
'NAME_HP' '送达方名称' '' 'KNA1' 'NAME1' 'X',
'SLDTO' '售达方编号' '' 'KNA1' 'KUNNR' 'X',
'NAME_LD' '售达方名称' '' 'KNA1' 'NAME1' 'X',
*'ZDATE' '导入日期' '' 'ZTSD008' 'ZDATE' '',
'LFDAT' '交货日期' '' 'LIKP' 'LFDAT' '',
'BATNO' '导入编号' '' 'ZTSD002' 'BATNO' '',
'BATPO' '导入项目' '' 'ZTSD002' 'BATPO' '',
'VKBUR' '销售部门' '' 'VBAK' 'VKBUR' '',
'ZR' '主任' '' 'ZTSD009' 'ZR' '',
'ZYWY' '业务员' '' 'ZTSD009' 'ZYWY' '',
'MATNR' '物料编号' '' 'MARA' 'MATNR' '',
'MAKTX' '物料名称' '' 'MAKT' 'MAKTX' '',
'MENGE' '验收数量' '' 'LIPS' 'LFIMG' '',
'MEINS' '数量单位' '' 'MARA' 'MEINS' '',
* 'CHARG' '批次' '' '' '',
'ZYDJG' '验收单价格' '' 'ZTSD009' 'ZYDJG' '',
'ZYDJE' '合计金额' '' 'ZTSD009' 'ZYDJE' '',
'ZYDDH' '验收单号' '' 'ZTSD009' 'ZYDDH' '',
'SO' '销售订单号' '' 'VBAK' 'VBELN' '',
'DN' '交货单号' '' 'LIKP' 'VBELN' '',
'BEIZHU' '备注' '' '' '' '',
'ZUSER' '导入人员' '' 'ZTSD008' 'ZUSER' ''.
IF R3 EQ 'X'.
BUILD_FC
:
'WBSTK' '发货状态' '' 'VBUK' 'WBSTK' '',
'FKSTK' '开票状态' '' 'VBUK' 'FKSTK' ''.
ENDIF.
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: CHECK_OKAY TYPE STRING.
CLEAR OK_CODE.
OK_CODE
= SY-UCOMM.
DATA: ANS TYPE STRING."GUI返回值
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'.
PERFORM FRM_CHECK_CHANGES CHANGING CHECK_OKAY.
IF CHECK_OKAY EQ 'F'."没做修改
*释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
ELSEIF CHECK_OKAY EQ 'T'."做了修改
*询问是否保存
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION
= '数据已修改,是否保存?'
TEXT_BUTTON_1
= '是'(003)
TEXT_BUTTON_2
= '否'(004)
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'."是
PERFORM FRM_SAVE_DATA USING ' ' CHANGING LV_RESULT.
IF LV_RESULT EQ 'S'.
MESSAGE '保存成功!' TYPE 'S'.
ELSEIF LV_RESULT EQ 'E'.
MESSAGE '保存失败!' TYPE 'S' DISPLAY LIKE 'E'.
ELSEIF LV_RESULT EQ 'N'.
MESSAGE '数据没有修改!' TYPE 'S'.
ENDIF.
**释放内存
* FREE MEMORY.
* "直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ELSEIF ANS EQ 'A'."取消
RETURN.
ELSE."否
**释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ENDIF.
ENDIF.
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 R3 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.
*显示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[].
*注册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.
*&---------------------------------------------------------------------*
*& Module MOD_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE MOD_COMMAND_9000 INPUT.
* DATA: CHECK_OKAY TYPE STRING.
CLEAR OK_CODE.
OK_CODE
= SY-UCOMM.
* DATA: ANS TYPE STRING."GUI返回值
CASE OK_CODE.
WHEN 'BACK'.
PERFORM FRM_CHECK_CHANGES CHANGING CHECK_OKAY.
IF CHECK_OKAY EQ 'F'."没做修改
*释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
ELSEIF CHECK_OKAY EQ 'T'."做了修改
*询问是否保存
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TEXT_QUESTION
= '未保存数据将丢失,是否退出?'
TEXT_BUTTON_1
= '是'(001)
TEXT_BUTTON_2
= '否'(002)
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'."是
PERFORM FRM_SAVE_DATA USING ' ' CHANGING LV_RESULT.
IF LV_RESULT EQ 'S'.
MESSAGE '保存成功!' TYPE 'S'.
ELSEIF LV_RESULT EQ 'E'.
MESSAGE '保存失败!' TYPE 'S' DISPLAY LIKE 'E'.
ELSEIF LV_RESULT EQ 'N'.
MESSAGE '数据没有修改!' TYPE 'S'.
ENDIF.
**释放内存
* FREE MEMORY.
* "直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ELSEIF ANS EQ 'A'."取消
RETURN.
ELSE."否
**释放内存
* FREE MEMORY.
"直接退出
PERFORM FRM_RESET_LOCK.
LEAVE TO SCREEN 0.
*
ENDIF.
ENDIF.
WHEN OTHERS.
ENDCASE.
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_ZTSD008
TYPE TABLE OF ZTSD008,
LT_ZTSD009
TYPE TABLE OF ZTSD009,
LT_ZTSD010
TYPE TABLE OF ZTSD010,
LT_ZTSD011
TYPE TABLE OF ZTSD011,
LT_OUTPUT
TYPE TABLE OF TY_OUTPUT,
LS_ZTSD008
TYPE ZTSD008, "超市验收单抬头
LS_ZTSD009
TYPE ZTSD009, "验收单明细
LS_ZTSD010
TYPE ZTSD010, "验收单修改日志
LS_ZTSD011
TYPE ZTSD011, "验收单与SO对应关系
LS_OUTPUT
TYPE TY_OUTPUT.
DATA: LV_BATNO TYPE CHAR10, "批导编号
LV_VERNO
TYPE CHAR3. "版本号
DATA: CHECK_OK TYPE STRING.
CLEAR:LV_BATNO, C_RESULT.
CLEAR:
LT_ZTSD008
,
LT_ZTSD009
,
LT_ZTSD010
,
LT_ZTSD011
,
LT_OUTPUT
,
LS_ZTSD008
,
LS_ZTSD009
,
LS_ZTSD010
,
LS_ZTSD011
,
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.
*生成批导编号
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR
= '02'
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.
*新版本号
MOVE 1 TO LV_VERNO.
*填充抬头表ZTSD008
MOVE LV_BATNO TO LS_ZTSD008-BATNO.
MOVE SY-UNAME TO LS_ZTSD008-ZUSER.
MOVE SY-DATUM TO LS_ZTSD008-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD008-ZTIME.
MOVE P_VKORG TO LS_ZTSD008-VKORG.
MOVE P_LGORT TO LS_ZTSD008-LGORT.
MODIFY ZTSD008 FROM LS_ZTSD008.
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_ZTSD009.
APPEND LS_ZTSD009 TO LT_ZTSD009.
CLEAR LS_ZTSD009.
*填充超市验单日志表
MOVE-CORRESPONDING GS_OUTPUT TO LS_ZTSD010.
* MOVE LV_BATNO TO LS_ZTSD003-BATNO.
* MOVE LV_VERNO TO LS_ZTSD003-VERNO.
MOVE SY-UNAME TO LS_ZTSD010-ZUSER.
MOVE SY-DATUM TO LS_ZTSD010-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD010-ZTIME.
APPEND LS_ZTSD010 TO LT_ZTSD010.
CLEAR LS_ZTSD010.
ENDLOOP.
ELSEIF R2 EQ 'X' ."如果是显示已导入数据,则检查是否有修改数据
C_RESULT
= 'N'.
SORT GT_OUTPUT BY BATNO."按批导编号排序
LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X'.
LS_OUTPUT
= GS_OUTPUT.
AT NEW BATNO.
LV_VERNO
= LS_OUTPUT-VERNO + 1."产生下一个版本,否则C_RESULT EQ SPACE
LS_OUTPUT
-VERNO = LV_VERNO.
*按批导编号更新版本号
MODIFY GT_OUTPUT FROM LS_OUTPUT TRANSPORTING VERNO
WHERE BATNO EQ LS_OUTPUT-BATNO.
* CLEAR LS_OUTPUT.
ENDAT.
*填充超市订单日志表
MOVE-CORRESPONDING LS_OUTPUT TO LS_ZTSD010.
* MOVE LS_OUTPUT-BATNO TO LS_ZTSD003-BATNO.
* MOVE LS_OUTPUT-VERNO TO LS_ZTSD003-VERNO.
MOVE LS_OUTPUT-SO TO LS_ZTSD010-VBELN.
MOVE LS_OUTPUT-DN TO LS_ZTSD010-VBELN_VL.
MOVE SY-UNAME TO LS_ZTSD010-ZUSER.
MOVE SY-DATUM TO LS_ZTSD010-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD010-ZTIME.
APPEND LS_ZTSD010 TO LT_ZTSD010.
CLEAR LS_ZTSD010.
*填充超市订单明细表
MOVE-CORRESPONDING LS_OUTPUT TO LS_ZTSD009.
MOVE LS_OUTPUT-SO TO LS_ZTSD009-VBELN.
MOVE LS_OUTPUT-DN TO LS_ZTSD009-VBELN_VL.
*如果是审批通过则修改状态
* IF U_STR EQ 'APPROVAL'.
* MOVE 'B' TO LS_ZTSD002-ZSTAT.
* ENDIF.
APPEND LS_ZTSD009 TO LT_ZTSD009.
CLEAR LS_ZTSD009.
*填充ZTSD011 销售订单表
IF U_STR EQ 'APPROVAL'.
MOVE: LS_OUTPUT-BATNO TO LS_ZTSD011-BATNO,
LS_OUTPUT
-BATPO TO LS_ZTSD011-BATPO,
LS_OUTPUT
-SO TO LS_ZTSD011-VBELN,
LS_OUTPUT
-ZYDDH TO LS_ZTSD011-ZYDDH.
MOVE SY-UNAME TO LS_ZTSD011-ZUSER.
MOVE SY-DATUM TO LS_ZTSD011-ZDATE.
MOVE SY-UZEIT TO LS_ZTSD011-ZTIME.
APPEND LS_ZTSD011 TO LT_ZTSD011.
CLEAR LS_ZTSD011.
ENDIF.
CLEAR LS_OUTPUT.
ENDLOOP.
ENDIF.
DELETE GT_OUTPUT WHERE SEL EQ 'X'.
*更新数据库表
MODIFY ZTSD009 FROM TABLE LT_ZTSD009.
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
C_RESULT
= 'S'.
ELSE.
ROLLBACK WORK.
C_RESULT
= 'E'.
ENDIF.
MODIFY ZTSD010 FROM TABLE LT_ZTSD010.
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
C_RESULT
= 'S'.
ELSE.
ROLLBACK WORK.
C_RESULT
= 'E'.
ENDIF.
MODIFY ZTSD011 FROM TABLE LT_ZTSD011.
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
C_RESULT
= 'S'.
ELSE.
ROLLBACK WORK.
C_RESULT
= 'E'.
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.
MOVE: GS_SODATA-SO TO <WA_DATA>-SO,
GS_SODATA
-DN TO <WA_DATA>-DN.
ENDIF.
ENDLOOP.
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_MSG TYPE STRING.
CLEAR GT_SODATA.
LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X' AND SO EQ SPACE.
IF GS_OUTPUT-MSSG IS NOT INITIAL.
MESSAGE '存在错误数据,请检查!' TYPE 'S' DISPLAY LIKE 'E'.
C_RESULT
= 'E'.
RETURN.
ENDIF.
MOVE-CORRESPONDING GS_OUTPUT TO GS_SODATA.
MOVE GS_OUTPUT-MENGE TO GS_SODATA-KPEIN.
MOVE GS_OUTPUT-MEINS TO GS_SODATA-KMEIN.
MOVE '1000' TO GS_SODATA-WERKS.
* IF GS_SODATA-SHPTO IS INITIAL.
* GS_SODATA-SHPTO = GS_SODATA-KUNNR.
* ENDIF.
* IF GS_SODATA-SLDTO IS INITIAL.
* GS_SODATA-SLDTO = GS_SODATA-KUNNR.
* ENDIF.
GS_SODATA
-VSTEL = GS_SODATA-RESLO.
* PERFORM FRM_GET_SHIPPOINT USING GS_SODATA CHANGING GS_SODATA-VSTEL.
*售达方数据
* SELECT SINGLE VKORG VTWEG SPART VKBUR VKGRP
* INTO ( GS_SODATA-VKORG,GS_SODATA-VTWEG,GS_SODATA-SPART,
* GS_SODATA-VKBUR,GS_SODATA-VKGRP )
* FROM KNVV
* WHERE KUNNR EQ GS_OUTPUT-SLDTO
* AND VTWEG EQ '20'"直营
* AND LOEVM NE 'X'"删除标记
** AND VSBED EQ '99'"装运条件
* .
PERFORM FRM_CHECK_PARTNER USING GS_SODATA-SLDTO CHANGING LV_RESULT.
IF LV_RESULT EQ 'E'.
C_RESULT
= 'E'.
RETURN.
ENDIF.
* IF SY-SUBRC NE 0.
* MESSAGE '销售组织数据不正确,请检查分销渠道(20)。' TYPE 'S'.
* RETURN.
* ENDIF.
*检查条件记录是否存在
* SELECT SINGLE * INTO LS_A502
* FROM A502
* WHERE KSCHL EQ 'PRZ0'
* AND MATNR EQ GS_SODATA-MATNR.
* SELECT SINGLE * INTO LS_A515
* FROM A515
* WHERE KSCHL EQ 'PRZ0'
* AND KUNNR EQ GS_SODATA-KUNNR
* AND MATNR EQ GS_SODATA-MATNR.
*
* IF SY-SUBRC NE 0.
* MESSAGE '条件记录PRZ0不存在。' TYPE 'S'.
*
* 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 && '对应的成本中心不存在。'.
* MESSAGE S001 WITH LV_MSG 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 TYPE CHAR3,
LV_STRING
TYPE STRING.
DATA: LV_SO TYPE VBELN,
LV_DN
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: 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 ZYDDH.
LOOP AT GT_SODATA ASSIGNING <WA_SODATA>.
*做标记
<WA_SODATA>
-SO = 'X'.
<WA_SODATA>
-DN = '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>-RESLO."司机库
LS_ITEM
-TARGET_QU = <WA_SODATA>-MEINS.
LS_ITEM
-SALES_UNIT = <WA_SODATA>-MEINS.
* PERFORM FRM_GET_SHIPPOINT USING <WA_SODATA> CHANGING LS_ITEM-SHIP_POINT.
* LS_ITEM-SHIP_POINT = 9079.
LS_ITEM
-SHIP_POINT = <WA_SODATA>-VSTEL.
LS_ITEM
-ITEM_CATEG = 'TAN1'.
* LS_ITEM-CUST_MAT35 = <WA_SODATA>-ZYDDH."售达方客户物料记验单单号
* LS_ITEM-BATCH = <WA_SODATA>-CHARG.
* LS_ITEM-ITEM_CATEG = 'ZTN'.
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
-SHIP_POINT = 'X'.
* LS_ITEMX-CUST_MAT35 = 'X'.
* LS_ITEMX-BATCH = '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.
PERFORM GET_KSCHL(ZSDR021)
USING 'ZSO1'
<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>-ZYDJE.
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.
IF LV_POSNR EQ '300'.
CLEAR LV_POSNR.
LS_HEADER
-DOC_TYPE = 'ZSO1'.
LS_HEADER
-DOC_DATE = <WA_SODATA>-INDAT.
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
-PURCH_NO_C = 'ZY'.
LS_HEADER
-PURCH_NO_S = <WA_SODATA>-ZYDDH.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
TESTRUN
= TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'W'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ENDIF.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
* TESTRUN = TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
C_RESULT
= 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
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.
DO 5 TIMES .
SELECT SINGLE VBELN INTO LV_DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
ENDDO.
ENDIF.
CLEAR: LT_RETURN,
LT_ITEM
,
LT_ITEMX
,
LT_PNR
,
LT_SCH
,
LT_SCHX
,
LT_COND
,
LT_CONDX
,
LS_HEADER
.
*将单据号更新到内表
* IF LV_SO IS NOT INITIAL AND LV_DN IS NOT INITIAL.
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.
IF LV_DN IS NOT INITIAL.
LS_SODATA
-DN = LV_DN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_SODATA-DN
IMPORTING
OUTPUT = LS_SODATA-DN.
ELSE.
DO 5 TIMES.
SELECT SINGLE VBELN INTO LS_SODATA-DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
IF SY-SUBRC NE 0.
CLEAR LS_SODATA-DN .
ENDIF.
ENDDO.
ENDIF.
MODIFY GT_SODATA FROM LS_SODATA TRANSPORTING SO DN
WHERE SO EQ 'X' AND DN EQ 'X'.
CLEAR:LV_SO,LV_DN.
ELSE.
* PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
EXIT.
ENDIF.
CONTINUE.
ENDIF.
AT END OF ZYDDH.
CLEAR LV_POSNR.
LS_HEADER
-DOC_TYPE = 'ZSO1'.
LS_HEADER
-DOC_DATE = <WA_SODATA>-INDAT.
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
-PURCH_NO_C = 'ZY'.
LS_HEADER
-PURCH_NO_S = <WA_SODATA>-ZYDDH.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
TESTRUN
= TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'W'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ENDIF.
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
EXPORT LT_RETURN TO MEMORY ID 'LT_RETURN'.
PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
RETURN.
ELSE.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN
= LS_HEADER
* TESTRUN = TESTRUN
IMPORTING
SALESDOCUMENT
= LV_SO
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
ORDER_CONDITIONS_IN
= LT_COND
ORDER_CONDITIONS_INX
= LT_CONDX.
C_RESULT
= 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
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.
DO 5 TIMES .
SELECT SINGLE VBELN INTO LV_DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
ENDDO.
ENDIF.
CLEAR: LT_RETURN,
LT_ITEM
,
LT_ITEMX
,
LT_PNR
,
LT_SCH
,
LT_SCHX
,
LT_COND
,
LT_CONDX
,
LS_HEADER
.
*将单据号更新到内表
* IF LV_SO IS NOT INITIAL AND LV_DN IS NOT INITIAL.
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.
IF LV_DN IS NOT INITIAL.
LS_SODATA
-DN = LV_DN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_SODATA-DN
IMPORTING
OUTPUT = LS_SODATA-DN.
ELSE.
DO 5 TIMES.
SELECT SINGLE VBELN INTO LS_SODATA-DN FROM VBFA
WHERE VBELV EQ LV_SO
AND VBTYP_N EQ 'J'.
IF SY-SUBRC NE 0.
CLEAR LS_SODATA-DN .
ENDIF.
ENDDO.
ENDIF.
MODIFY GT_SODATA FROM LS_SODATA TRANSPORTING SO DN
WHERE SO EQ 'X' AND DN EQ 'X'.
CLEAR:LV_SO,LV_DN.
ELSE.
* PERFORM FRM_SHOW_MESSAGE.
C_RESULT
= 'E'.
EXIT.
ENDIF.
CONTINUE.
ENDAT.
ENDLOOP.
IF C_RESULT IS INITIAL.
C_RESULT
= 'S'.
ENDIF.
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_OUTPUT1
-STYLE,
LS_OUTPUT
-SEL,
LS_OUTPUT
-STYLE.
IF LS_OUTPUT1 NE LS_OUTPUT.
MOVE 'T' TO C_OK."有区别
EXIT."只要有一个数据有区别就要记录
ELSE.
MOVE 'F' TO C_OK."没有区别
ENDIF.
ELSE.
*没读到初始数据说明是新数据
MOVE 'T' TO C_OK."有区别
EXIT."只要有一个数据有区别就要记录
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_POST_GOODS_ISSUE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_POST_DN.
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
.
FREE LT_SODATA.
LT_SODATA
= GT_SODATA.
SORT LT_SODATA BY DN.
DELETE ADJACENT DUPLICATES FROM LT_SODATA COMPARING DN.
LOOP AT LT_SODATA INTO LS_SODATA.
LV_VBELN
= LS_SODATA-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 = LS_SODATA-LFDAT .
* LV_VBKOK-BLDAT = SY-DATUM .
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'.
EXIT.
ELSE.
* C_RESULT = 'S'.
* RETURN.
ENDIF.
ENDLOOP.
CLEAR: LV_VBKOK,LT_VBPOK,LT_PROTT.
* CLEAR:LS_HEADER1,LS_CONTROL1,DELIVERY1,LS_TECH,HEADER_DEADLINE[],
* HEADER_DEADLINE,LT_RETURN[],LT_RETURN.
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.
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: LT_ZTSD009 TYPE TABLE OF ZTSD009,
LS_ZTSD009
TYPE ZTSD009,
LT_ZTSD006
TYPE TABLE OF ZTSD006,
LS_ZTSD006
TYPE ZTSD006.
DATA: L_LINE1 TYPE I,
L_LINE2
TYPE I.
*删除数量为0的行
DELETE GT_OUTPUT WHERE MENGE EQ 0.
CLEAR: LT_OUTPUT,LT_OUTPUT[].
LT_OUTPUT
= GT_OUTPUT.
SORT LT_OUTPUT BY ZYDDH MATNR ZSJ SLDTO SHPTO.
DELETE ADJACENT DUPLICATES FROM LT_OUTPUT COMPARING ZYDDH MATNR ZSJ SLDTO SHPTO.
L_LINE1
= LINES( LT_OUTPUT[] ).
L_LINE2
= LINES( GT_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.
LOOP AT GT_OUTPUT ASSIGNING <WA_DATA> WHERE ZICON1 NE '@0A@'.
IF <WA_DATA>-INDAT IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 1 GS_LOAD '请填写订单日期' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-LFDAT IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 2 GS_LOAD '请填写发货日期' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-SLDTO IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 3 GS_LOAD '请填写售达方' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-SHPTO IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 4 GS_LOAD '请填写送达方' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-ZYDDH IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 5 GS_LOAD '请填写验单单号' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-ZSJ IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 6 GS_LOAD '请填写司机' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
IF <WA_DATA>-VKBUR IS INITIAL.
PERFORM SET_CALLSYTLE(ZSDR006) USING 9 GS_LOAD '请填写销售部门' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
<WA_DATA>
-ZICON1 = '@0A@'."红灯
ENDIF.
<WA_DATA>
-SEL = 'X'.
<WA_DATA>
-ZDATE = SY-DATUM.
<WA_DATA>
-VKORG = P_VKORG.
<WA_DATA>
-LGORT = P_LGORT.
* IF R4 EQ 'X'.
* <WA_DATA>-ZFREE = 'X'.
* ENDIF.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME2
FROM KNA1
WHERE KUNNR EQ <WA_DATA>-ZSJ.
SELECT SINGLE MEINS INTO LV_MEINS
FROM MARA
WHERE MATNR EQ <WA_DATA>-MATNR.
*数量单位转换
TRANSLATE <WA_DATA>-MEINS TO UPPER CASE.
* IF <WA_DATA>-SHPTO IS INITIAL.
* MOVE <WA_DATA>-KUNNR TO <WA_DATA>-SHPTO.
* ENDIF.
* IF <WA_DATA>-SLDTO IS INITIAL.
* MOVE <WA_DATA>-KUNNR TO <WA_DATA>-SLDTO.
* ENDIF.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_HP
FROM KNA1
WHERE KUNNR = <WA_DATA>-SHPTO.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING 4 GS_LOAD '送达方不正确' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
ENDIF.
SELECT SINGLE NAME1 INTO <WA_DATA>-NAME_LD
FROM KNA1
WHERE KUNNR = <WA_DATA>-SLDTO.
IF SY-SUBRC NE 0.
PERFORM SET_CALLSYTLE(ZSDR006) USING 3 GS_LOAD '售达方不正确' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
ENDIF.
IF <WA_DATA>-MENGE GT '99999'.
PERFORM SET_CALLSYTLE(ZSDR006) USING 13 GS_LOAD '数量只能小于10万' CHANGING <WA_DATA>-CELLCOLOR <WA_DATA>-MSSG.
ENDIF.
*价格
<WA_DATA>
-ZYDJG = <WA_DATA>-ZYDJE / <WA_DATA>-MENGE.
* <WA_DATA>-ZHJJE = <WA_DATA>-ZYDJG * <WA_DATA>-MENGE.
ENDLOOP.
UNASSIGN <WA_DATA>
.
*将初始内表放入内存
* LT_OUTPUT = GT_OUTPUT.
FREE LT_OUTPUT.
EXPORT LT_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.
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 = '9079'."司机库
LS_ITEM
-TARGET_QU = <WA_SODATA>-MEINS.
* LS_ITEM-BATCH = <WA_SODATA>-CHARG.
LS_ITEM
-ITEM_CATEG = 'TAN1'.
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
-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.
AT END OF SHPTO.
CLEAR LV_POSNR.
LS_HEADER
-DOC_TYPE = 'ZSO1'.
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.
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.
ENDAT.
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_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 VKORG EQ GS_SODATA-VKORG
AND VTWEG EQ '20'"直营
AND VKBUR EQ GS_SODATA-VKBUR
AND LOEVM NE 'X'"删除标记
.
IF SY-SUBRC NE 0.
C_RESULT
= 'E'.
LV_MSG
= '售达方' && U_SLDTO && '销售组织数据不正确,请检查。'.
MESSAGE S001 WITH LV_MSG DISPLAY LIKE 'E'.
* MESSAGE '销售组织数据不正确,请检查。' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
* SELECT SINGLE SPOFI INTO @DATA(LV_SPOFI)
* FROM TVLK
* WHERE LFART EQ 'ZLF'."直营交货
*
* 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'.
** MESSAGE '售达方按工厂1000确定的装运点不存在。' TYPE 'S' 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'.
** MESSAGE '条件记录PRZ0不存在。' TYPE 'S' 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'.
** MESSAGE '条件记录PRZ0价格不能为0。' TYPE 'S' DISPLAY LIKE 'E'.
*
* RETURN.
* ENDIF.
* ENDIF.
C_RESULT
= 'S'.
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SET_STYLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM SET_STYLE USING P_VALUE P_ROWID.
DATA: L_STYPE TYPE STRING,
L_ROWID
TYPE I.
L_ROWID
= P_ROWID.
CLEAR GS_OUTPUT.
READ TABLE GT_OUTPUT INTO GS_OUTPUT INDEX L_ROWID.
L_STYPE
= 'DISABLE'.
IF P_VALUE EQ 'X'.
CHECK GS_OUTPUT-SO IS INITIAL.
L_STYPE
= 'ENABLE'.
ELSE.
L_STYPE
= 'DISABLE'.
ENDIF.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDJE' L_STYPE CHANGING GS_OUTPUT-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'ZYDDH' L_STYPE CHANGING GS_OUTPUT-STYLE.
PERFORM SET_STYLE(ZSDR018) USING 'MENGE' L_STYPE CHANGING GS_OUTPUT-STYLE.
MODIFY GT_OUTPUT FROM GS_OUTPUT INDEX L_ROWID.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_SHIPPOINT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<WA_DATA> text
* <--P_LS_ITEM_SHIP_POINT text
*----------------------------------------------------------------------*
FORM FRM_GET_SHIPPOINT USING U_WA TYPE TY_SODATA
CHANGING C_SHIP_POINT.
DATA: LV_VSBED TYPE KNVV-VSBED,
LV_VWERK
TYPE KNVV-VWERK,
LV_LGORT
TYPE LGORT_D,
LV_LFARV
TYPE TVAK-LFARV,
LV_SPOFI
TYPE TVLK-SPOFI,
LV_VSTEL
TYPE TVSTZ-VSTEL.
SELECT SINGLE VSBED VWERK
INTO ( LV_VSBED, LV_VWERK )
FROM KNVV
WHERE KUNNR EQ U_WA-SHPTO
AND VKORG EQ U_WA-VKORG
* AND VTWEG EQ U_WA-VTWEG
AND VTWEG EQ '20'"直营
AND SPART EQ U_WA-SPART
AND LOEVM NE 'X'"删除标记
.
SELECT SINGLE LFARV INTO LV_LFARV
FROM TVAK
WHERE AUART EQ 'ZSO1'.
SELECT SINGLE SPOFI INTO LV_SPOFI
FROM TVLK
WHERE LFART EQ LV_LFARV.
IF SY-SUBRC EQ 0.
IF LV_SPOFI EQ SPACE. "特定工厂装运点
SELECT SINGLE VSTEL INTO C_SHIP_POINT
FROM TVSTZ
WHERE VSBED EQ LV_VSBED
AND LADGR EQ '0001'
AND WERKS EQ LV_VWERK.
ELSE."按库存地点确定装运点
LV_LGORT
= U_WA-RESLO."司机库
*将库存地点带入行项目中
SELECT SINGLE VSTEL INTO C_SHIP_POINT
FROM TVSTZ_STORLOC
WHERE VSBED EQ LV_VSBED
AND LADGR EQ '0001'
AND WERKS EQ LV_VWERK
AND LGORT EQ LV_LGORT.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SEL_ALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SEL_ALL .
DATA : LT_FILTERED_ENTRIES TYPE LVC_T_FIDX,
LV_INDEX
TYPE SY-TABIX.
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.
LV_INDEX
= SY-TABIX.
READ TABLE LT_FILTERED_ENTRIES TRANSPORTING NO FIELDS WITH KEY TABLE_LINE = LV_INDEX.
IF SY-SUBRC NE 0.
<WA_DATA>
-SEL = 'X'.
PERFORM SET_STYLE USING 'X' LV_INDEX.
ENDIF.
CLEAR LV_INDEX.
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_AUTHORITY_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_AUTHORITY_CHECK .
AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
ID 'VKORG' FIELD P_VKORG
ID 'VTWEG' DUMMY
ID 'SPART' DUMMY
ID 'ACTVT' DUMMY.
IF SY-SUBRC <> 0.
MESSAGE '您没有销售组织' && P_VKORG && '的权限' TYPE 'E'.
RETURN.
ENDIF.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'ACTVT' DUMMY
ID 'WERKS' FIELD '1000'
ID 'LGORT' FIELD P_LGORT
ID 'BWART' DUMMY.
IF SY-SUBRC <> 0.
MESSAGE '您没有库存地点' && P_LGORT && '的权限' TYPE 'E'.
RETURN.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DELETE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DELETE_DATA .
LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE SEL EQ 'X' AND SO IS NOT INITIAL.
*判断销售订单是否被删除
SELECT SINGLE VBELN INTO @DATA(LV_VBELN)
FROM VBAK
WHERE VBELN EQ @GS_OUTPUT-SO.
IF SY-SUBRC EQ 0.
MESSAGE '所选择数据存在已创建订单,不允许删除' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
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 GT_DEL.
GT_DEL
-BATNO = GS_OUTPUT-BATNO.
GT_DEL
-BATPO = GS_OUTPUT-BATPO.
GT_DEL
-INDAT = GS_OUTPUT-INDAT.
APPEND GT_DEL TO GT_DEL.
CLEAR GS_OUTPUT.
ENDLOOP.
DELETE GT_OUTPUT WHERE SEL EQ 'X'.
IF GT_DEL[] IS NOT INITIAL.
DELETE ZTSD009 FROM TABLE GT_DEL[].
IF SY-SUBRC EQ 0.
COMMIT WORK AND WAIT.
MESSAGE '删除成功!' TYPE 'S'.
ELSE.
ROLLBACK WORK.
MESSAGE '删除失败!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
CLEAR: GT_DEL,GT_DEL[].
ENDIF.
ENDFORM.
ELSE.
ROLLBACK WORK.
MESSAGE '删除失败!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
CLEAR: GT_DEL,GT_DEL[].
ENDIF.
ENDFORM.
SAP 直营验单的更多相关文章
- SAP打印出库单 新需求
*&---------------------------------------------------------------------* *& Report Z_SD_CKD ...
- SAP打印出库单需求
*&---------------------------------------------------------------------* *& Report Z_SD_CKD ...
- JavaScript高级程序设计之表单基础
A FORM <form id='form' action='http://a-response-url' method="post"> <!--maxlengt ...
- 原创:XXX公司-基于SAP的库存管理系统解决方案
XXX公司-基于SAP的库存管理系统 解决方案 版本:V0.3.0 Excel_Cortan 文件状态: [ ] 草稿 [ ] 正式发布 [√] 正在修改 文件标识: 当前版本: V0.3 作 者 ...
- HTML表格和表单
<table>格式: 注意:1. 合并单元格:COLSPAN(跨列)ROWSPAN(跨行) 2.cellspacing属性定义单元格之间的间距(以像素为单位). cellpadding属性 ...
- SD--怎样增强是同一类出库单使用不同号码段
在现实的业务中,一个公司有多个销售组织,它们使用同一个出库类型,业务往往希望它们创建的出库单的号码採用不同号码范围.但在sap里出库单号码范围是在出库单类型里设置,也就是使用同样的出库单类型,也就使用 ...
- ABAP 订单-交货单-发货过账自动完成 案例
*&---------------------------------------------------------------------* *& Report ZSDR006 ...
- 数据分析侠A的成长故事
数据分析侠A的成长故事 面包君 同学A:22岁,男,大四准备实习,计算机专业,迷茫期 作为一个很普通的即将迈入职场的他来说,看到周边的同学都找了技术开发的岗位,顿觉自己很迷茫,因为自己不是那么喜欢钻 ...
- 从苏宁电器到卡巴斯基第12篇:我在苏宁电器当营业员 IV
卖iPhone首先是需要接受培训的 像iPhone这样的重点产品,并不是只要选好了人(营业员),说卖就能卖的,在正式销售之前需要接受厂家的培训.如果说人事关系或者产品源隶属于苹果,那么是由苹果中国公司 ...
随机推荐
- appium常用方法整理
1.相对坐标解锁九宫格 应用场景 QQ解锁屏幕如上,可见九个按键在同一个View下面,要实现解锁,用press moveTo release perform方法 实现代码如下: WebElem ...
- AC自动机 HDU 2896
n个字串 m个母串 字串在母串中出现几次 #include<stdio.h> #include<algorithm> #include<string.h> #inc ...
- OC中的多继承
可以间接实现,方法有: 1.消息转发 2.协议 3.组合模式 4.代理 5.分类 直接上code,分别说明集中方法的实现 一.消息转发 消息转发可以参考我的另外一篇博客:http://www.cnbl ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
- 编译OpenCV文档
概述 使用OpenCV的过程中经常查看文档,每次都去官网查看,不过国内访问速度很慢,有一份本地的文档就好了.本文列出了在Linux(Fedora)系统上从OpenCV源码编译出documentatio ...
- django表单验证和跨站伪造csrf
Form验证 django中的Form一般有两种功能: 输入html 验证用户输入 django使用内置form方法验证表单提交的数据 html页面 <!DOCTYPE html> < ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- SAM初探
SAM,即Suffix Automaton,后缀自动机. 关于字符串有很多玩法,有很多算法都是围绕字符串展开的.为什么?我的理解是:相较于数字组成的序列,字母组成的序列中每个单位上元素的个数是有限的. ...
- IT这一行,如可高速下载国外资源之迅雷设置免费SSH代理下载国外资源
本文转自SUN'S BLOG 原文地址:IT这一行,如可高速下载国外资源之迅雷 我们这些做IT这一行的人,经常,下载一些国外的一些资源,可是让人蛋碎的是,往往这些资源下载都慢的像蜗牛,真的让人无法忍受 ...
- SQL 同时查看2个表
1.要想上下查看2个表,一定要2个表显示的字段数量一致,格式一致 2.格式不一致就统一转换为字符串 -- to_char(s.saleid,'999999999') ,-- to_char(s.upd ...