Chinaunix首页 | 论坛 | 博客
  • 博客访问: 484149
  • 博文数量: 199
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2020-05-14 13:25
个人简介

代码5S

文章分类

全部博文(199)

文章存档

2021年(5)

2020年(194)

我的朋友

分类: 其他平台

2020-08-28 08:17:02


点击(此处)折叠或打开

  1. FORM FRM_1501_CREATE_BOM TABLES PT_FPJGD STRUCTURE GS_FPJGD.
  2.   TYPES:BEGIN OF TY_HEAD,
  3.           PSPNR TYPE CS_PSPNR,
  4.           MATNR TYPE MATNR,
  5.           WERKS TYPE WERKS_D,
  6.           BMENG TYPE BASMN,
  7.           STLNR TYPE STNUM,
  8.         END OF TY_HEAD.
  9.   DATA: LS_HEAD TYPE TY_HEAD,
  10.         LT_HEAD TYPE TABLE OF TY_HEAD,
  11.         LV_TEXT TYPE STRING,
  12.         LV_ERROR TYPE CHAR01,
  13.         L_ANSWER TYPE CHAR01,
  14.         LS_FPJGD TYPE ZTPS_ECCSJGD,
  15.         LT_FPJGD TYPE TABLE OF ZTPS_ECCSJGD,
  16.         LS_PRST TYPE PRST,
  17.         LS_FPDEL TYPE ZTPS_ECCSJGD,
  18.         LT_FPDEL TYPE TABLE OF ZTPS_ECCSJGD,
  19.         LTWMS_WERK TYPE TABLE OF ZWMST_WERKS,
  20.         LSWMS_WERK TYPE ZWMST_WERKS.

  21. * 创建BOM定义变量
  22.   DATA: WA_CSIN TYPE CSIN,
  23.         WA_STPOB TYPE STPOB,
  24.         LT_STPOB TYPE TABLE OF STPOB,
  25.         WA_STZUB TYPE STZUB,
  26.         WA_STKOB TYPE STKOB,
  27.         LV_STLNR TYPE STZUB-STLNR,
  28.         LV_POSNR TYPE N LENGTH 4,
  29.         LV_FLWARNING TYPE CAPIFLAG-FLWARNING.

  30.   DATA:LV_S1 TYPE STRING,
  31.        LV_S2 TYPE STRING,
  32.        LV_S3 TYPE STRING.
  33.   REFRESH:GT_MSG.

  34.   READ TABLE PT_FPJGD INTO GS_FPJGD WITH KEY ICON = '@0A@'.
  35.   IF SY-SUBRC EQ 0.
  36.     APP_MSG: 'E' 'ZPSMES' '000' '存在错误,不能创建BOM' '' '' ''.
  37.     CHECK 1 EQ 2.
  38.   ENDIF.

  39.   READ TABLE PT_FPJGD INTO GS_FPJGD WITH KEY ICON = '@09@'.
  40.   IF SY-SUBRC NE 0.
  41.     READ TABLE PT_FPJGD INTO GS_FPJGD WITH KEY ICON = '@08@'.
  42.     IF SY-SUBRC NE 0.
  43.       APP_MSG: 'E' 'ZPSMES' '000' '未保存数据,不能创建BOM' '' '' ''.
  44.       CHECK 1 EQ 2.
  45.     ENDIF.
  46.   ENDIF.

  47.   IF ZSPS_ECCS_FPJGD_HEAD-PSPNR IS INITIAL.
  48.     APP_MSG: 'E' 'ZPSMES' '000' '基地分批号不存在,不能创建BOM' '' '' ''.
  49.     CHECK 1 EQ 2.
  50.   ENDIF.

  51.   IF ZSPS_ECCS_FPJGD_HEAD-WERKS IS INITIAL.
  52.     APP_MSG: 'E' 'ZPSMES' '000' '基地分批工厂不存在,不能创建BOM' '' '' ''.
  53.     CHECK 1 EQ 2.
  54.   ENDIF.

  55. * CLEAR: L_ANSWER.
  56. * CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
  57. * EXPORTING
  58. * DEFAULTOPTION = 'Y'
  59. * TEXTLINE1 = '点击"是"创建BOM'
  60. * TEXTLINE2 = ''
  61. * TITEL = '保存确认提示'
  62. * START_COLUMN = 25
  63. * START_ROW = 6
  64. * CANCEL_DISPLAY = ''
  65. * IMPORTING
  66. * ANSWER = L_ANSWER.
  67. * IF L_ANSWER NE 'J'.
  68. * MESSAGE '操作取消' TYPE 'S' DISPLAY LIKE 'E'.
  69. * EXIT.
  70. * ENDIF.

  71.   REFRESH LTWMS_WERK.
  72.   SELECT * INTO TABLE LTWMS_WERK FROM ZWMST_WERKS.

  73.   LOOP AT PT_FPJGD INTO GS_FPJGD.
  74. ** 保存bom抬头
  75.     CLEAR LS_HEAD.
  76.     LS_HEAD-PSPNR = ZSPS_ECCS_FPJGD_HEAD-PSPNR.
  77.     LS_HEAD-MATNR = GS_FPJGD-MATNR.
  78.     LS_HEAD-WERKS = ZSPS_ECCS_FPJGD_HEAD-WERKS.
  79.     LS_HEAD-BMENG = GS_FPJGD-BMENG.
  80.     APPEND LS_HEAD TO LT_HEAD.
  81.   ENDLOOP.

  82.   SORT LT_HEAD BY MATNR.
  83.   DELETE ADJACENT DUPLICATES FROM LT_HEAD COMPARING MATNR.

  84.   LOOP AT LT_HEAD INTO LS_HEAD.
  85.     CLEAR:LV_ERROR.
  86. ** 再检查BOM是否已存在
  87.     SELECT SINGLE * FROM PRST INTO LS_PRST
  88.      WHERE PSPNR EQ LS_HEAD-PSPNR
  89.        AND MATNR EQ LS_HEAD-MATNR
  90.        AND WERKS EQ LS_HEAD-WERKS
  91.        AND STLAN EQ '1'.
  92.     IF SY-SUBRC EQ 0.
  93.       APP_MSG: 'S' 'ZPSMES' '000' '正在删除历史BOM...' LS_HEAD-MATNR '' ''.
  94. *** 调用删除BOM的BAPI
  95.       CLEAR: WA_CSIN,LV_TEXT,LV_ERROR.
  96.       WA_CSIN-MATNR = LS_PRST-MATNR.
  97.       WA_CSIN-DATUV = SY-DATUM.
  98.       WA_CSIN-PSPNR = LS_PRST-PSPNR.
  99.       WA_CSIN-WERKS = LS_PRST-WERKS.
  100.       WA_CSIN-STLAN = '1'.
  101.       WA_CSIN-STLTY = 'P'.

  102.       CALL FUNCTION 'CSAI_BOM_DELETE'
  103.         EXPORTING
  104.           ECSIN = WA_CSIN
  105.           FL_COMMIT_AND_WAIT = 'X'
  106.         IMPORTING
  107.           FL_WARNING = LV_FLWARNING
  108.         EXCEPTIONS
  109.           ERROR = 1
  110.           OTHERS = 2.

  111.       IF SY-SUBRC NE 0.
  112.         LV_ERROR = 'E'.
  113.         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO INTO LV_TEXT
  114.                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  115.         APP_MSG: 'E' 'ZPSMES' '000' '删除BOM错误:' LV_TEXT '' ''.
  116.         APP_MSG: SY-MSGTY SY-MSGID SY-MSGNO SY-MSGV1 SY-MSGV2 SY-MSGV3
  117.           SY-MSGV4.
  118.         LOOP AT PT_FPJGD INTO GS_FPJGD WHERE MATNR EQ LS_HEAD-MATNR.
  119.           GS_FPJGD-ICON = '@0A@'.
  120.           GS_FPJGD-MSG = '删除历史BOM发生错误:' && LV_TEXT.
  121.           MODIFY PT_FPJGD FROM GS_FPJGD.
  122.         ENDLOOP.
  123.       ELSE.
  124.         APP_MSG: 'S' 'ZPSMES' '000' 'BOM成功删除:' LS_PRST-STLNR '' ''.
  125.       ENDIF.
  126.     ENDIF.

  127.     CHECK LV_ERROR IS INITIAL.

  128.     CLEAR: WA_CSIN,WA_STPOB,LT_STPOB[],WA_STZUB,WA_STKOB,
  129.            LV_STLNR,LV_POSNR,LV_FLWARNING,LV_TEXT.

  130.     WA_CSIN-MATNR = LS_HEAD-MATNR.
  131.     WA_CSIN-EMENG = LS_HEAD-BMENG.
  132.     WA_CSIN-DATUV = SY-DATUM.
  133.     WA_CSIN-PSPNR = ZSPS_ECCS_FPJGD_HEAD-PSPNR.
  134.     WA_CSIN-WERKS = ZSPS_ECCS_FPJGD_HEAD-WERKS.
  135.     WA_CSIN-STLAN = ZSPS_ECCS_FPJGD_HEAD-STLAN.
  136.     WA_CSIN-STLTY = 'P'.
  137.     WA_STKOB-STLTY = 'P'.
  138.     WA_STKOB-BMENG = LS_HEAD-BMENG.
  139.     WA_STZUB-STLTY = 'P'.

  140.     LOOP AT PT_FPJGD INTO GS_FPJGD WHERE MATNR EQ LS_HEAD-MATNR.

  141. *** 剔除不创建BOM的数据
  142.       IF GS_FPJGD-ZAZWZ EQ '外部人员现场安装 ' OR
  143.          GS_FPJGD-ZAZWZ EQ 'X' OR GS_FPJGD-MENGE EQ 0 OR
  144.          GS_FPCLD-ZAZWZ EQ 'S'.
  145.         CONTINUE.
  146.       ENDIF.

  147. *** 创建BOM的组件内表
  148.       CLEAR WA_STPOB.
  149.       LV_POSNR = LV_POSNR + 10.
  150.       WA_STPOB-STLTY = 'P'.
  151.       WA_STPOB-IDNRK = GS_FPJGD-IDNRK.
  152.       WA_STPOB-POSTP = 'L'.
  153.       WA_STPOB-POSNR = LV_POSNR.
  154.       WA_STPOB-MENGE = GS_FPJGD-BOMMG.
  155.       WA_STPOB-MEINS = GS_FPJGD-MEINS.
  156.       WA_STPOB-DATUV = SY-DATUM.
  157.       CASE GS_FPJGD-ZWLLB.
  158.         WHEN '01'. "型材
  159.           WA_STPOB-SORTF = GS_FPJGD-MENGE.
  160.           WA_STPOB-POTX1 = GS_FPJGD-ZCLCD.
  161.           CONDENSE WA_STPOB-SORTF NO-GAPS. "去掉空格
  162.           CONDENSE WA_STPOB-POTX1 NO-GAPS. "去掉空格
  163.         WHEN '02'. "玻璃
  164.           WA_STPOB-SORTF = GS_FPJGD-MENGE.
  165.           LV_S1 = GS_FPJGD-ZBLMJ.
  166.           LV_S2 = GS_FPJGD-ZBLKD.
  167.           LV_S3 = GS_FPJGD-ZBLGD.
  168.           WA_STPOB-POTX2 = GS_FPJGD-ZBLKD && '*' && GS_FPJGD-ZBLGD.
  169.           CONDENSE:LV_S1,LV_S2,LV_S3.
  170.           CONCATENATE LV_S1 '/' LV_S2 '/' LV_S3
  171.             INTO WA_STPOB-POTX1. "面积/宽度/高度
  172.           CONDENSE WA_STPOB-SORTF NO-GAPS. "去掉空格
  173.           CONDENSE WA_STPOB-POTX1 NO-GAPS. "去掉空格
  174.           CONDENSE WA_STPOB-POTX2 NO-GAPS. "去掉空格
  175.         WHEN '03' OR '04'.
  176.           IF GS_FPJGD-ZCLCD NE 0.
  177.             WA_STPOB-POTX1 = GS_FPJGD-ZCLCD.
  178.             WA_STPOB-SORTF = GS_FPJGD-MENGE.
  179.             CONDENSE WA_STPOB-POTX1 NO-GAPS. "去掉空格
  180.             CONDENSE WA_STPOB-SORTF NO-GAPS. "去掉空格
  181.           ENDIF.
  182.       ENDCASE.
  183.       APPEND WA_STPOB TO LT_STPOB.
  184.     ENDLOOP.

  185.     APP_MSG: 'S' 'ZPSMES' '000' '正在创建BOM' LS_HEAD-MATNR '' ''.

  186.     CALL FUNCTION 'CSAI_BOM_CREATE'
  187.       EXPORTING
  188.         ECSIN = WA_CSIN
  189.         ESTKOB = WA_STKOB
  190.         ESTZUB = WA_STZUB
  191.       IMPORTING
  192.         FL_WARNING = LV_FLWARNING
  193.         ASTLNR = LV_STLNR
  194.       TABLES
  195.         T_STPOB = LT_STPOB
  196.       EXCEPTIONS
  197.         ERROR = 1
  198.         OTHERS = 2.
  199.     IF SY-SUBRC NE 0.
  200.       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO INTO LV_TEXT
  201.               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  202.       APP_MSG: 'E' 'ZPSMES' '000' '创建BOM错误:' LV_TEXT '' ''.
  203.       APP_MSG: SY-MSGTY SY-MSGID SY-MSGNO SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  204.       LOOP AT PT_FPJGD INTO GS_FPJGD WHERE MATNR EQ LS_HEAD-MATNR.
  205.         GS_FPJGD-ICON = '@0A@'.
  206.         GS_FPJGD-MSG = '删除历史BOM发生错误:' && LV_TEXT.
  207.         MODIFY PT_FPJGD FROM GS_FPJGD.
  208.       ENDLOOP.
  209.     ELSE.
  210.       APP_MSG: 'S' 'ZPSMES' '000' 'BOM成功创建:' LS_HEAD-MATNR '' ''.
  211.       UPDATE ZTPS_ECCSJGD SET WERKS = WA_CSIN-WERKS
  212.                               STLNR = LV_STLNR
  213.                               STLAN = WA_CSIN-STLAN
  214.                         WHERE PSPNR = GV_PSPNR
  215.                           AND POSNR = GV_POSNR
  216.                           AND ZMCH = GS_FPJGD-ZMCH
  217.                           AND ZJGDLX = ZSPS_ECCS_FPJGD_HEAD-ZJGDLX
  218.                           AND ZZYLX = ZPSS_SJRWGL-ZZYLX.
  219.       COMMIT WORK.

  220.       LOOP AT PT_FPJGD INTO GS_FPJGD WHERE MATNR EQ LS_HEAD-MATNR.
  221.         GS_FPJGD-ICON = '@08@'.
  222.         GS_FPJGD-MSG = 'BOM成功创建:' && LV_STLNR.
  223.         GS_FPJGD-STLNR = LV_STLNR.
  224.         MODIFY PT_FPJGD FROM GS_FPJGD.
  225.       ENDLOOP.
  226.     ENDIF.

  227.     AT LAST.
  228.       READ TABLE LTWMS_WERK INTO LSWMS_WERK WITH KEY WERKS = WA_CSIN-WERKS.
  229.       IF SY-SUBRC = 0.
  230.         CALL FUNCTION 'ZPS_SET_ZTPP_DBH'

阅读(7313) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~