*&---------------------------------------------------------------------*
*& Report ZMMR110
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSDR015.
TABLES:SSCRFIELDS.
TYPE-POOLS:SLIS.
"定义ALV输出所需变量
DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LS_STYLE TYPE LVC_S_STYL,
LT_STYLE TYPE TABLE OF LVC_S_STYL.
DATA RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA GT_EXDATA TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA IW_CELLCOLOR TYPE LVC_T_SCOL WITH HEADER LINE.
DATA L_FILENAME TYPE STRING .
DATA L_MUBAN TYPE STRING .
DATA GV_FULLPATH TYPE STRING .
DATA GV_PATH TYPE STRING .
DATA GV_NAME TYPE STRING .
DATA:MESSAGE TYPE BAPI_MSG .
DATA:SUBRC LIKE SYST-SUBRC .
DATA:FLAG TYPE C .
DATA:KSTBM TYPE KSTBM .
DATA:MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
TYPES: BEGIN OF GTS_DATA,
ZNOMB TYPE CHAR10, "订单序号
AUART TYPE VBAK-AUART, "订单类型
VKORG TYPE VBAK-VKORG, "销售组织
VTWEG TYPE VBAK-VTWEG, "分销渠道
SPART TYPE VBAK-SPART, "产品组
KUNNR_AG TYPE VBPA-KUNNR, "售达方
KUNNR_WE TYPE VBPA-KUNNR, "送达方
KUNNR_RE TYPE VBPA-KUNNR, "收票方
KUNNR_RG TYPE VBPA-KUNNR, "付款方
BSTKD TYPE VBKD-BSTKD, "客户参考
BSTDK TYPE VBAK-BSTDK, "客户参考日期
POSNR TYPE VBAP-POSNR, "项目号
MATNR TYPE VBAP-MATNR, "物料编码
KWMENG TYPE VBAP-KWMENG, "数量
VRKME TYPE VBAP-VRKME, "单位
ETDAT TYPE ETDAT, "交货日期
PLTYP TYPE VBKD-PLTYP, "价格清单
WERKS TYPE VBAP-WERKS, "工厂
TYPBOD TYPE CHAR4, "消息图标
MESSAGED TYPE BAPI_MSG, "报错信息
TYPBO TYPE CHAR4, "消息图标
MESSAGE TYPE BAPI_MSG, "报错信息
STYLE TYPE LVC_T_STYL, "控制不可编辑
END OF GTS_DATA.
DATA: FLAG1 TYPE C.
DATA: LV_MODE TYPE C.
DATA: GT_DATA TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_A TYPE TABLE OF GTS_DATA WITH HEADER LINE.
SELECTION-SCREEN: FUNCTION KEY 1.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME .
SELECTION-SCREEN END OF BLOCK B1.
IF P_FILE IS INITIAL .
MESSAGE '没有选择文件!' TYPE 'E'.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',Excel Files,*.xls,All Files,*.*.'(101)
TITLE = '选择文件'(100)
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0 AND SY-SUBRC <> 3.
MESSAGE '选择文件出错!' TYPE 'E'.
ENDIF.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
DATA LV_MARC TYPE MARC .
DATA LV_MVKE TYPE MVKE .
DATA LV_KNVV TYPE KNVV .
DATA LV_MARA TYPE MARA .
DATA LV_MARM TYPE MARM .
DATA LV_A305 TYPE A305 .
DATA LV_A601 TYPE A601 .
DATA LV_KONP TYPE KONP .
CLEAR GT_EXDATA[].
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' "读取excel文件中的内容
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = '1'
I_BEGIN_ROW = '3'
I_END_COL = '50'
I_END_ROW = '5000'
TABLES
INTERN = GT_EXDATA[].
SORT GT_EXDATA BY ROW COL VALUE.
**---整理到内表数据
CLEAR GT_DATA[] .
LOOP AT GT_EXDATA.
CLEAR FLAG .
AT END OF ROW .
FLAG = 'X'.
ENDAT .
CASE GT_EXDATA-COL.
WHEN 1.
GT_DATA-ZNOMB = GT_EXDATA-VALUE.
WHEN 2.
GT_DATA-AUART = GT_EXDATA-VALUE.
WHEN 3.
GT_DATA-VKORG = GT_EXDATA-VALUE.
WHEN 4.
GT_DATA-VTWEG = GT_EXDATA-VALUE.
WHEN 5.
GT_DATA-SPART = GT_EXDATA-VALUE.
WHEN 6.
GT_DATA-KUNNR_AG = GT_EXDATA-VALUE.
WHEN 7.
GT_DATA-KUNNR_WE = GT_EXDATA-VALUE.
WHEN 8.
GT_DATA-KUNNR_RE = GT_EXDATA-VALUE.
WHEN 9.
GT_DATA-KUNNR_RG = GT_EXDATA-VALUE.
WHEN 10.
GT_DATA-BSTKD = GT_EXDATA-VALUE.
WHEN 11.
GT_DATA-BSTDK = GT_EXDATA-VALUE.
WHEN 12.
GT_DATA-POSNR = GT_EXDATA-VALUE.
WHEN 13.
GT_DATA-MATNR = GT_EXDATA-VALUE.
WHEN 14.
GT_DATA-KWMENG = GT_EXDATA-VALUE.
WHEN 15.
GT_DATA-VRKME = GT_EXDATA-VALUE.
WHEN 16.
GT_DATA-ETDAT = GT_EXDATA-VALUE.
WHEN 17.
GT_DATA-PLTYP = GT_EXDATA-VALUE.
WHEN 18.
GT_DATA-WERKS = GT_EXDATA-VALUE.
ENDCASE.
IF FLAG IS NOT INITIAL.
APPEND GT_DATA."append要加在最后一列.
CLEAR GT_DATA.
ENDIF.
ENDLOOP.
LOOP AT GT_DATA.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_DATA-VTWEG
IMPORTING
OUTPUT = GT_DATA-VTWEG.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_DATA-SPART
IMPORTING
OUTPUT = GT_DATA-SPART.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_DATA-KUNNR_AG
IMPORTING
OUTPUT = GT_DATA-KUNNR_AG.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_DATA-KUNNR_WE
IMPORTING
OUTPUT = GT_DATA-KUNNR_WE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_DATA-KUNNR_RE
IMPORTING
OUTPUT = GT_DATA-KUNNR_RE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_DATA-KUNNR_RG
IMPORTING
OUTPUT = GT_DATA-KUNNR_RG.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GT_DATA-PLTYP
IMPORTING
OUTPUT = GT_DATA-PLTYP.
CLEAR LT_STYLE[] .
IF GT_DATA-ZNOMB IS INITIAL
OR GT_DATA-AUART IS INITIAL
OR GT_DATA-VKORG IS INITIAL
OR GT_DATA-VTWEG IS INITIAL
OR GT_DATA-SPART IS INITIAL
OR GT_DATA-KUNNR_AG IS INITIAL
OR GT_DATA-KUNNR_WE IS INITIAL
OR GT_DATA-KUNNR_RE IS INITIAL
OR GT_DATA-KUNNR_RG IS INITIAL
OR GT_DATA-POSNR IS INITIAL
OR GT_DATA-MATNR IS INITIAL
OR GT_DATA-KWMENG IS INITIAL
OR GT_DATA-VRKME IS INITIAL
OR GT_DATA-ETDAT IS INITIAL
OR GT_DATA-WERKS IS INITIAL
.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '存在未被填写的必输字段!'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
* A. 物料+工厂 到表MARC表检查是否有数据,如没有,则报错 “物料”+物料编码+“不存在工厂”+工厂+“数据”
CLEAR LV_MARC.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_MARC FROM MARC
WHERE WERKS = GT_DATA-WERKS
AND MATNR = GT_DATA-MATNR
.
IF LV_MARC IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '物料' && GT_DATA-MATNR && '不存在工厂' && GT_DATA-WERKS && '数据'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
* B. 物料+销售组织+分销渠道 到表 MVKE 检查是否有数据,如没有,则报错“物料”+物料编码+“不存在销售视图”+销售组织+分销渠道+“数据”
CLEAR LV_MVKE.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_MVKE FROM MVKE
WHERE MATNR = GT_DATA-MATNR
AND VKORG = GT_DATA-VKORG
AND VTWEG = GT_DATA-VTWEG
.
IF LV_MVKE IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '物料' && GT_DATA-MATNR && '不存在销售视图' && GT_DATA-VKORG && '+' && GT_DATA-VTWEG && '数据'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
* C. 分别判断售达方,送达方,收票方,付款方 +销售组织+分销渠道+产品组 到表 KNVV 检查是否有数据,如没有,则报错“客户”+客户编码+“不存在销售视图”+销售组织+分销渠道+产品组+“数据”
CLEAR LV_KNVV.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_KNVV FROM KNVV
WHERE KUNNR = GT_DATA-KUNNR_AG
AND VKORG = GT_DATA-VKORG
AND VTWEG = GT_DATA-VTWEG
AND SPART = GT_DATA-SPART
.
IF LV_MVKE IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '售达方' && GT_DATA-KUNNR_AG && '不存在销售视图' && GT_DATA-VKORG && '+' && GT_DATA-VTWEG && '+' && GT_DATA-SPART && '数据'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
CLEAR LV_KNVV.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_KNVV FROM KNVV
WHERE KUNNR = GT_DATA-KUNNR_WE
AND VKORG = GT_DATA-VKORG
AND VTWEG = GT_DATA-VTWEG
AND SPART = GT_DATA-SPART
.
IF LV_MVKE IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '送达方' && GT_DATA-KUNNR_WE && '不存在销售视图' && GT_DATA-VKORG && '+' && GT_DATA-VTWEG && '+' && GT_DATA-SPART && '数据'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
CLEAR LV_KNVV.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_KNVV FROM KNVV
WHERE KUNNR = GT_DATA-KUNNR_RE
AND VKORG = GT_DATA-VKORG
AND VTWEG = GT_DATA-VTWEG
AND SPART = GT_DATA-SPART
.
IF LV_MVKE IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '收票方' && GT_DATA-KUNNR_RE && '不存在销售视图' && GT_DATA-VKORG && '+' && GT_DATA-VTWEG && '+' && GT_DATA-SPART && '数据'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
CLEAR LV_KNVV.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_KNVV FROM KNVV
WHERE KUNNR = GT_DATA-KUNNR_RG
AND VKORG = GT_DATA-VKORG
AND VTWEG = GT_DATA-VTWEG
AND SPART = GT_DATA-SPART
.
IF LV_MVKE IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '付款方' && GT_DATA-KUNNR_RG && '不存在销售视图' && GT_DATA-VKORG && '+' && GT_DATA-VTWEG && '+' && GT_DATA-SPART && '数据'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
*D. 物料+单位 到表 MARA 该物料单位 MEINS 进行比对,不一致时,则再到表MARM 检查物料+单位 (MARM-MEINH)是否有数据,如没有,则报错:“物料”+物料编码+“单位” +单位+“在系统未维护”
CLEAR LV_MARA.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_MARA FROM MARA
WHERE MATNR = GT_DATA-MATNR
AND MEINS = GT_DATA-VRKME
.
IF LV_MARA IS INITIAL.
CLEAR LV_MARM.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_MARM FROM MARM
WHERE MATNR = GT_DATA-MATNR
AND MEINH = GT_DATA-VRKME
.
IF LV_MARM IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '物料' && GT_DATA-MATNR && '单位' && GT_DATA-VRKME && '+' && GT_DATA-VTWEG && ' 在系统未维护'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
ENDIF.
* E. 如价格清单为空时,到表 A305 根据 物料+售达方客户+销售组织+销售区域+条件类型为ZP00+DATAB起始日期<=当天日期+DATBI截止日期>=当天日期 取出条件号KNUMH,如没有,则报错“物料对此客户未维
*护有效销售价格”;如有,则继续到表 KONP 根据条件号KNUMH+条件类型为ZP00+ LOEVM_KO 为空,如没有数据,则报错“物料对此客户未维 护有效销售价格”。
IF GT_DATA-PLTYP IS INITIAL.
CLEAR LV_A305.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_A305 FROM A305
WHERE MATNR = GT_DATA-MATNR
AND KUNNR = GT_DATA-KUNNR_AG
AND VKORG = GT_DATA-VKORG
AND VTWEG = GT_DATA-VTWEG
AND KSCHL = 'ZP00'
AND DATAB <= SY-DATUM
AND DATBI >= SY-DATUM
.
IF LV_A305-KNUMH IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = ' 物料对此客户未维护有效销售价格!'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ELSE.
CLEAR LV_KONP.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_KONP FROM KONP
WHERE KNUMH = LV_A305-KNUMH
AND KSCHL = 'ZP00'
AND LOEVM_KO = ''
.
IF LV_KONP IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = ' 物料对此客户未维护有效销售价格!'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
ENDIF.
ELSE.
*F.如果价格清单不为空是,到表 A601 根据 物料+售达方客户+销售组织+销售区域+条件类型为ZP00+DATAB起始日期<=当天日期+DATBI截止日期>=当天日期 + PLTYP价格清单类型为EXCEL维护的价格清单类
*型,取出条件号KNUMH,如没有,则报错“物料对此客户未维护有效销售价格”;如有,则继续到表KONP根据条件号KNUMH+条件类型为ZP00+ LOEVM_KO 为空,如没有数据,则报错“物料对此客户未维护有效销售价格”。
CLEAR LV_A601.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_A601 FROM A601
WHERE MATNR = GT_DATA-MATNR
AND KUNNR = GT_DATA-KUNNR_AG
AND VKORG = GT_DATA-VKORG
AND VTWEG = GT_DATA-VTWEG
AND PLTYP = GT_DATA-PLTYP
AND KSCHL = 'ZP00'
AND DATAB <= SY-DATUM
AND DATBI >= SY-DATUM
.
IF LV_A601-KNUMH IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = ' 物料对此客户未维护有效销售价格!'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ELSE.
CLEAR LV_KONP.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_KONP FROM KONP
WHERE KNUMH = LV_A601-KNUMH
AND KSCHL = 'ZP00'
AND LOEVM_KO = ''
.
IF LV_KONP IS INITIAL.
GT_DATA-TYPBOD = '@0A@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = ' 物料对此客户未维护有效销售价格!'.
MODIFY GT_DATA.
CLEAR GT_DATA .
CONTINUE.
ENDIF.
ENDIF.
ENDIF.
GT_DATA-TYPBOD = '@08@'.
LS_STYLE-FIELDNAME = 'TYPBOD'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGED = '数据准备完毕!'.
MODIFY GT_DATA.
CLEAR GT_DATA .
ENDLOOP.
SORT GT_DATA BY ZNOMB POSNR.
ENDFORM.
FORM FOM_UPDATA .
DATA: HEADER_IN TYPE BAPISDHD1,
HEADER_INX TYPE BAPISDHD1X,
L_VBELN LIKE VBAK-VBELN,
L_MESSAGE TYPE STRING,
LT_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
ITEMS_IN TYPE TABLE OF BAPISDITM WITH HEADER LINE,
ITEMS_INX TYPE TABLE OF BAPISDITMX WITH HEADER LINE,
PARTNERS TYPE TABLE OF BAPIPARNR WITH HEADER LINE,
SCHEDULES_IN TYPE TABLE OF BAPISCHDL WITH HEADER LINE,
ORDER_CONDITIONS_IN TYPE BAPICOND OCCURS 0 WITH HEADER LINE,
ORDER_CONDITIONS_INX TYPE BAPICONDX OCCURS 0 WITH HEADER LINE,
LOGIC_SWITCH TYPE BAPISDLS OCCURS 0 WITH HEADER LINE,
EXTENSIONIN TYPE BAPIPAREX OCCURS 0 WITH HEADER LINE,
FLAG TYPE C.
GT_DATA_A[] = GT_DATA[].
DELETE ADJACENT DUPLICATES FROM GT_DATA_A COMPARING ZNOMB.
LOOP AT GT_DATA_A.
CLEAR SUBRC .
CLEAR MESSAGE .
CLEAR: HEADER_IN,
HEADER_INX,
ORDER_CONDITIONS_IN,
ORDER_CONDITIONS_INX,
L_VBELN,
ITEMS_IN[],ITEMS_IN,
ITEMS_INX[],ITEMS_INX,
PARTNERS[],PARTNERS,
SCHEDULES_IN[],SCHEDULES_IN.
HEADER_IN-DOC_TYPE = GT_DATA_A-AUART. "销售凭证类型
HEADER_IN-SALES_ORG = GT_DATA_A-VKORG ."销售组织
HEADER_IN-DISTR_CHAN = GT_DATA_A-VTWEG. "分销渠道
HEADER_IN-DIVISION = GT_DATA_A-SPART. "产品组
HEADER_IN-PURCH_NO_C = GT_DATA_A-BSTKD. "客户参考
HEADER_IN-PURCH_DATE = GT_DATA_A-BSTDK. "客户参考日期
* partener
PARTNERS-PARTN_ROLE = 'AG'.
PARTNERS-PARTN_NUMB = GT_DATA_A-KUNNR_AG.
APPEND PARTNERS.
CLEAR PARTNERS.
PARTNERS-PARTN_ROLE = 'WE'.
PARTNERS-PARTN_NUMB = GT_DATA_A-KUNNR_WE.
APPEND PARTNERS.
CLEAR PARTNERS.
PARTNERS-PARTN_ROLE = 'RE'.
PARTNERS-PARTN_NUMB = GT_DATA_A-KUNNR_RE.
APPEND PARTNERS.
CLEAR PARTNERS.
PARTNERS-PARTN_ROLE = 'RG'.
PARTNERS-PARTN_NUMB = GT_DATA_A-KUNNR_RG.
APPEND PARTNERS.
CLEAR PARTNERS.
LOGIC_SWITCH-PRICING = ''.
APPEND LOGIC_SWITCH.
CLEAR FLAG .
LOOP AT GT_DATA WHERE ZNOMB = GT_DATA_A-ZNOMB.
IF GT_DATA_A-AUART = GT_DATA-AUART
AND GT_DATA_A-VKORG = GT_DATA-VKORG
AND GT_DATA_A-VTWEG = GT_DATA-VTWEG
AND GT_DATA_A-SPART = GT_DATA-SPART
AND GT_DATA_A-KUNNR_AG = GT_DATA-KUNNR_AG
AND GT_DATA_A-KUNNR_WE = GT_DATA-KUNNR_WE
AND GT_DATA_A-KUNNR_RE = GT_DATA-KUNNR_RE
AND GT_DATA_A-KUNNR_RG = GT_DATA-KUNNR_RG
AND GT_DATA_A-BSTKD = GT_DATA-BSTKD
AND GT_DATA_A-BSTDK = GT_DATA-BSTDK
.
ITEMS_IN-ITM_NUMBER = GT_DATA-POSNR.
ITEMS_IN-MATERIAL_LONG = GT_DATA-MATNR.
ITEMS_IN-PLANT = GT_DATA-WERKS.
ITEMS_IN-PRICE_LIST = GT_DATA-PLTYP.
APPEND ITEMS_IN.
CLEAR ITEMS_IN.
ITEMS_INX-ITM_NUMBER = GT_DATA-POSNR.
ITEMS_INX-MATERIAL_LONG = 'X'.
ITEMS_INX-PLANT = 'X'.
ITEMS_INX-PRICE_LIST = 'X'.
APPEND ITEMS_INX.
CLEAR ITEMS_INX.
SCHEDULES_IN-ITM_NUMBER = GT_DATA-POSNR.
SCHEDULES_IN-REQ_DATE = GT_DATA-ETDAT.
SCHEDULES_IN-REQ_QTY = GT_DATA-KWMENG.
APPEND SCHEDULES_IN.
CLEAR SCHEDULES_IN.
ORDER_CONDITIONS_IN-ITM_NUMBER = GT_DATA-POSNR. "itm_number
ORDER_CONDITIONS_IN-COND_UNIT = GT_DATA-VRKME. "条件单位
APPEND ORDER_CONDITIONS_IN.
CLEAR ORDER_CONDITIONS_INX.
ORDER_CONDITIONS_INX-ITM_NUMBER = GT_DATA-POSNR.
ORDER_CONDITIONS_INX-COND_P_UNT = 'X'.
APPEND ORDER_CONDITIONS_INX.
ELSE.
FLAG = 'X'.
EXIT .
ENDIF.
ENDLOOP.
IF FLAG IS INITIAL.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
* SALESDOCUMENTIN =
ORDER_HEADER_IN = HEADER_IN
ORDER_HEADER_INX = HEADER_INX
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
LOGIC_SWITCH = LOGIC_SWITCH
IMPORTING
SALESDOCUMENT = L_VBELN
TABLES
RETURN = LT_RETURN
ORDER_ITEMS_IN = ITEMS_IN
ORDER_ITEMS_INX = ITEMS_INX
ORDER_PARTNERS = PARTNERS
ORDER_SCHEDULES_IN = SCHEDULES_IN
ORDER_CONDITIONS_IN = ORDER_CONDITIONS_IN
ORDER_CONDITIONS_INX = ORDER_CONDITIONS_INX
EXTENSIONIN = EXTENSIONIN.
LOOP AT LT_RETURN WHERE TYPE = 'E' OR TYPE = 'A'.
MESSAGE = MESSAGE && '/' && LT_RETURN-MESSAGE.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
LOOP AT GT_DATA WHERE ZNOMB = GT_DATA_A-ZNOMB.
GT_DATA-TYPBO = '@0A@'.
CLEAR LT_STYLE[] .
LS_STYLE-FIELDNAME = 'TYPBO'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGE = MESSAGE .
MODIFY GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
LOOP AT GT_DATA WHERE ZNOMB = GT_DATA_A-ZNOMB.
GT_DATA-TYPBO = '@08@'.
CLEAR LT_STYLE[] .
LS_STYLE-FIELDNAME = 'TYPBO'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGE ='SO: '&& L_VBELN && ' 导入成功!'.
MODIFY GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
ENDIF.
ELSE.
LOOP AT GT_DATA WHERE ZNOMB = GT_DATA_A-ZNOMB.
GT_DATA-TYPBO = '@0A@'.
CLEAR LT_STYLE[] .
LS_STYLE-FIELDNAME = 'TYPBO'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
GT_DATA-MESSAGE = '序号' && GT_DATA_A-ZNOMB && ' 抬头数据不一致!' .
MODIFY GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
ENDIF.
CLEAR GT_DATA_A.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY .
CLEAR S_LAYOUT.
S_LAYOUT-ZEBRA = 'X'.
S_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
S_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'. "单元格颜色内表字段
* s_layout-box_fieldname = 'BOX'.
PERFORM FRM_FILL_FIELD .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = S_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
* i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
TABLES
T_OUTTAB = GT_DATA[].
ENDFORM.
FORM FRM_FILL_FIELD .
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DEFINE FILL_FIELD.
WA_FIELDCAT-FIELDNAME = &1.
WA_FIELDCAT-SELTEXT_L = &2.
* IF WA_FIELDCAT-FIELDNAME = 'MSLJH' OR WA_FIELDCAT-FIELDNAME = 'WCBJH'.
* WA_FIELDCAT-EMPHASIZE = 'C600'. "设置字段的颜色
* ENDIF.
* IF WA_FIELDCAT-FIELDNAME = 'MSLMB' OR WA_FIELDCAT-FIELDNAME = 'WCBMB'.
* WA_FIELDCAT-EMPHASIZE = 'C710'. "设置字段的颜色
* ENDIF.l
IF WA_FIELDCAT-FIELDNAME = 'TYPBO'
OR WA_FIELDCAT-FIELDNAME = 'TYPAI'
.
WA_FIELDCAT-ICON = 'X'.
WA_FIELDCAT-OUTPUTLEN = '13'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'PLNBEZ' OR WA_FIELDCAT-FIELDNAME = 'MATNR' .
WA_FIELDCAT-REF_TABNAME = 'MARA'.
WA_FIELDCAT-REF_FIELDNAME = 'MATNR'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'ARKTX' OR WA_FIELDCAT-FIELDNAME = 'WAKTX' .
WA_FIELDCAT-REF_TABNAME = 'VBAP'.
WA_FIELDCAT-REF_FIELDNAME = 'ARKTX'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'AUFNR' .
WA_FIELDCAT-REF_TABNAME = 'AUFK'.
WA_FIELDCAT-REF_FIELDNAME = 'AUFNR'.
ENDIF.
APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.
END-OF-DEFINITION.
FILL_FIELD :
'ZNOMB' '订单序号',
'AUART' '订单类型',
'VKORG' '销售组织',
'VTWEG' '分销渠道',
'SPART' '产品组',
'KUNNR_AG' '售达方',
'KUNNR_WE' '送达方',
'KUNNR_RE' '收票方',
'KUNNR_RG' '付款方',
'BSTKD' '客户参考',
'BSTDK' '客户参考日期',
'POSNR' '项目号',
'MATNR' '物料编码',
'KWMENG' '数量',
'VRKME' '单位',
'ETDAT' '交货日期',
'PLTYP' '价格清单',
'TYPBOD' '是否成功',
'MESSAGED' '报错信息',
'TYPBO' '是否成功',
'MESSAGE' '信息'.
ENDFORM.
FORM PF_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STANDARD_FULLSCREEN'.
ENDFORM.
FORM USER_COMMAND USING I_UCOMM LIKE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD.
DATA: REF TYPE REF TO CL_GUI_ALV_GRID.
DATA : LV_STABLE TYPE LVC_S_STBL. "刷新稳定性
RANGES: L_WERKS FOR T001W-WERKS.
RANGES: L_MATNR FOR MARA-MATNR.
DATA:L_BUKRS TYPE T001K-BUKRS.
LV_STABLE-ROW = '1'.
LV_STABLE-COL = '1'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF.
CALL METHOD REF->CHECK_CHANGED_DATA.
CASE I_UCOMM.
WHEN 'GO'."表示双击
CLEAR FLAG1 .
LOOP AT GT_DATA.
IF GT_DATA-TYPBOD = '@0A@'.
FLAG1 = 'X'.
EXIT .
ENDIF.
CLEAR GT_DATA .
ENDLOOP.
IF FLAG1 IS INITIAL.
PERFORM FOM_UPDATA.
ELSE .
MESSAGE '数据存在问题,请检查!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
WHEN 'POST_T'.
ENDCASE.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
ENDFORM.
*--------------------------------------------------------------------*
* 获取下载到本地的路径
*--------------------------------------------------------------------*
FORM FRM_GET_FULLPATH CHANGING PV_FULLPATH TYPE STRING
PV_PATH TYPE STRING
PV_NAME TYPE STRING.
DATA: LV_INIT_PATH TYPE STRING,
LV_INIT_FNAME TYPE STRING,
LV_PATH TYPE STRING,
LV_FILENAME TYPE STRING,
LV_FULLPATH TYPE STRING.
*&---初始名称(输出的文件名称)
* concatenate 'Material_Doc_' SY-DATUM '.xslx' into L_INIT_FNAME.
LV_INIT_FNAME = L_FILENAME.
* 获取桌面路径
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_DESKTOP_DIRECTORY
CHANGING
DESKTOP_DIRECTORY = LV_INIT_PATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
*&---用户选择名称、路径
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
* window_title = '指定保存文件名'
* default_extension = 'DOC'
DEFAULT_FILE_NAME = LV_INIT_FNAME
FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL
* FILE_FILTER = CL_GUI_FRONTEND_SERVICES=>FILETYPE_WORD
INITIAL_DIRECTORY = LV_INIT_PATH
PROMPT_ON_OVERWRITE = 'X'
CHANGING
FILENAME = LV_FILENAME
PATH = LV_PATH
FULLPATH = LV_FULLPATH
* USER_ACTION =
* FILE_ENCODING =
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC = 0.
PV_FULLPATH = LV_FULLPATH.
PV_PATH = LV_PATH.
ENDIF.
ENDFORM.
*--------------------------------------------------------------------*
* 下载文件
*--------------------------------------------------------------------*
FORM FRM_DOWN USING PR_FILENAME.
DATA: LV_OBJDATA LIKE WWWDATATAB,
LV_MIME LIKE W3MIME,
LV_DESTINATION LIKE RLGRAP-FILENAME,
LV_OBJNAM TYPE STRING,
LV_RC LIKE SY-SUBRC,
LV_ERRTXT TYPE STRING.
DATA: LV_FILENAME TYPE STRING,
LV_RESULT,
LV_SUBRC TYPE SY-SUBRC.
DATA: LV_OBJID TYPE WWWDATATAB-OBJID .
LV_OBJID = L_MUBAN. "上传的模版名称
*&---查找文件是否存在。
SELECT SINGLE RELID OBJID
FROM WWWDATA
INTO CORRESPONDING FIELDS OF LV_OBJDATA
WHERE SRTF2 = 0
AND RELID = 'MI'
AND OBJID = LV_OBJID.
*&---判断模版不存在则报错
IF SY-SUBRC NE 0 OR LV_OBJDATA-OBJID EQ SPACE.
CONCATENATE '模板文件:' LV_OBJID '不存在,请用TCODE:SMW0进行加载'
INTO LV_ERRTXT.
MESSAGE LV_ERRTXT TYPE 'E'.
ENDIF.
LV_FILENAME = PR_FILENAME.
"判断本地地址是否已经存在此文件。
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST
EXPORTING
FILE = LV_FILENAME
RECEIVING
RESULT = LV_RESULT
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
WRONG_PARAMETER = 3
NOT_SUPPORTED_BY_GUI = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
CASE SY-SUBRC.
WHEN 1.
WHEN 2.
WHEN OTHERS.
ENDCASE.
ENDIF.
IF LV_RESULT EQ 'X'. "如果存在则删除原始文件,重新覆盖
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_DELETE
EXPORTING
FILENAME = LV_FILENAME
CHANGING
RC = LV_SUBRC
EXCEPTIONS
FILE_DELETE_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
FILE_NOT_FOUND = 4
ACCESS_DENIED = 5
UNKNOWN_ERROR = 6
NOT_SUPPORTED_BY_GUI = 7
WRONG_PARAMETER = 8
OTHERS = 9.
IF SY-SUBRC <> 0.
CASE SY-SUBRC.
WHEN 1.
WHEN 2.
WHEN OTHERS.
ENDCASE.
ENDIF.
IF LV_SUBRC <> 0. "如果删除失败,则报错。
CONCATENATE '同名EXCEL文件已打开' '请关闭该EXCEL后重试。'
INTO LV_ERRTXT.
MESSAGE LV_ERRTXT TYPE 'E'.
ENDIF.
ENDIF.
LV_DESTINATION = PR_FILENAME.
*&---下载模版。
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = LV_OBJDATA
DESTINATION = LV_DESTINATION
IMPORTING
RC = LV_RC.
IF LV_RC NE 0.
CONCATENATE '模板文件' '下载失败' INTO LV_ERRTXT.
MESSAGE LV_ERRTXT TYPE 'E'.
ENDIF.
ENDFORM.
INITIALIZATION.
SSCRFIELDS-FUNCTXT_01 = '@49@ 模板下载'.
AT SELECTION-SCREEN .
CASE SSCRFIELDS-UCOMM.
WHEN 'FC01'.
L_FILENAME = 'SO批量导入模板.xls'.
L_MUBAN = 'ZSDR015'.
*&---下载模板
PERFORM FRM_GET_FULLPATH CHANGING GV_FULLPATH GV_PATH GV_NAME.
*&---路径为空则退出
IF GV_FULLPATH IS INITIAL.
MESSAGE '用户取消操作' TYPE 'S'.
RETURN.
ENDIF.
PERFORM FRM_DOWN USING GV_FULLPATH.
WHEN OTHERS.
ENDCASE.
START-OF-SELECTION.
PERFORM FOM_GETDATA.
PERFORM FRM_DISPLAY.
SD-SO批导程序(开发笔记)
最新推荐文章于 2023-10-24 10:27:17 发布