• 创建物料批次特性


    这是做零售的项目用到的,已经很久没用了。。。找出来记录一下:(我自己是宁愿用自建表也不用批次)

    TABLE:MCH1:批量(如果批次管理多工厂)

               AUSP:特征值

               CABN:特征

               INOB:在内部编号和对象之间的链接

    创建批次特性:创建物料和批次之间的关系,然后给批次创建属性

    修改批次特性:查询出批次特性,然后更新

    FUNCTION Z_MM000_BATCH_CREATE.
    *"----------------------------------------------------------------------
    *"*"本地接口:
    *"  IMPORTING
    *"     REFERENCE(I_ZDJLSHC) TYPE  ZMMEDJLSHC OPTIONAL
    *"     REFERENCE(I_DJLX) TYPE  ZMMEDJLX OPTIONAL
    *"     REFERENCE(I_ZMMT0003) TYPE  ZMMT0003
    *"  TABLES
    *"      T_ZMMT0004 STRUCTURE  ZMMT0004 OPTIONAL
    *"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
    *"----------------------------------------------------------------------
      DATA:S_RETURN     TYPE BAPIRET2,
           S_ZMMT0004   TYPE ZMMT0004,
           LV_CHAR01(1) TYPE C.
      DATA:GT_MCH1 TYPE TABLE OF MCH1,
           GS_MCH1 TYPE          MCH1.
      "输入参数检查
      IF I_ZDJLSHC IS NOT INITIAL.
        SELECT * INTO CORRESPONDING FIELDS OF TABLE T_ZMMT0004
          FROM ZMMT0004 WHERE ZDJLSHC = I_ZDJLSHC.
      ENDIF.
    
      IF T_ZMMT0004[] IS INITIAL.
        S_RETURN-TYPE = 'E'.
        S_RETURN-ID = 'ZMESG'.
        S_RETURN-NUMBER = '081'.
        S_RETURN-MESSAGE_V1 = '参数缺失,或参数不正确'.
        APPEND S_RETURN TO T_RETURN.
        EXIT.
      ELSE.
        SELECT MATNR CHARG INTO CORRESPONDING FIELDS OF TABLE GT_MCH1
        FROM MCH1 FOR ALL ENTRIES IN T_ZMMT0004
        WHERE MATNR = T_ZMMT0004-ZGSKH
        AND   CHARG = T_ZMMT0004-CHARG.
    
        DELETE GT_MCH1 WHERE CHARG IS INITIAL.
    
        IF GT_MCH1[] IS NOT INITIAL.
          SORT GT_MCH1[] BY CHARG.
        ENDIF.
    
        PERFORM PRM_GET_FIELD_ATT."提前或许ZMMS0004结构字段
      ENDIF.
    
    * 检查批次特性是否被锁
      PERFORM FRM_CHECK_CL02_LOCK CHANGING LS_RETURN.
      IF LS_RETURN IS NOT INITIAL.
        APPEND LS_RETURN TO T_RETURN.
        CHECK LS_RETURN-TYPE NE 'E'.
      ENDIF.
    
      SELECT SINGLE ZPCSM INTO LV_CHAR01 FROM ZMMT0070 WHERE ZDJLX = I_ZMMT0003-ZDJLX.
    
      LOOP AT T_ZMMT0004 INTO S_ZMMT0004.
    
        IF S_ZMMT0004-CHARG IS INITIAL."批号存在检查
          PERFORM PRM_GENERATE_BATCH USING LV_CHAR01 CHANGING S_ZMMT0004-CHARG.
        ENDIF.
    
        READ TABLE GT_MCH1 INTO GS_MCH1 WITH KEY CHARG = S_ZMMT0004-CHARG BINARY SEARCH.
        IF SY-SUBRC <> 0."物料批次关联检查
          CLEAR:LS_RETURN.
          PERFORM PRM_GENERATE_MC USING S_ZMMT0004-CHARG S_ZMMT0004-ZGSKH CHANGING LS_RETURN.
          IF LS_RETURN IS NOT INITIAL.
            APPEND LS_RETURN TO T_RETURN.
          ENDIF.
        ENDIF.
    
        MODIFY T_ZMMT0004 FROM S_ZMMT0004."更新结果
    
      ENDLOOP.
    
      LOOP AT T_ZMMT0004 INTO S_ZMMT0004.
        CLEAR:LT_ALLOC_NUM[],LS_ALLOC_NUM,LT_ALLOC_CHAR[],LS_ALLOC_CHAR,LT_ALLOC_CURR[],LS_ALLOC_CURR,LS_RETURN.
        PERFORM PRM_SET_BATCH_ATT USING S_ZMMT0004 I_ZMMT0003 CHANGING LS_RETURN.
        IF LS_RETURN IS NOT INITIAL.
          APPEND LS_RETURN TO T_RETURN.
        ENDIF.
      ENDLOOP.
    
    
    
    ENDFUNCTION.
    FORM FRM_CHECK_CL02_LOCK  CHANGING P_RETURN STRUCTURE BAPIRET2.
      DATA : IT_LOCKS TYPE TABLE OF SEQG3 WITH HEADER LINE,
             LV_KEYS  TYPE          SEQG3-GARG.
    
      CALL FUNCTION 'ENQUE_READ'
        EXPORTING
          GCLIENT = SY-MANDT
          GNAME   = 'KSSKX'
    *     GARG    = LV_KEYS
    *     GUNAME  = SY-UNAME
        TABLES
          ENQ     = IT_LOCKS.
    
      LOOP AT IT_LOCKS WHERE GMODE = 'E'  AND GTARG CS '023Z_CLASS_BATCH'.
        P_RETURN-TYPE = 'E'.
        P_RETURN-ID = 'ZMESG'.
        P_RETURN-NUMBER = '081'.
        P_RETURN-MESSAGE_V1 = '批次被锁定'.
      ENDLOOP.
    ENDFORM.                    " FRM_CHECK_CL02_LOCK
    FORM PRM_GENERATE_BATCH  USING    P_CHAR01
                             CHANGING P_CHARG.
      DATA:C_CHAR09(9) TYPE C.
      CLEAR:C_CHAR09,LV_LOCK.
      LV_LOCK = 'E'.
    
      WHILE LV_LOCK IS NOT INITIAL.
    
        CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'
          EXPORTING
            OBJECT           = 'Z_R_BATCH'
          EXCEPTIONS
            FOREIGN_LOCK     = 1
            OBJECT_NOT_FOUND = 2
            SYSTEM_FAILURE   = 3
            OTHERS           = 4.
        IF SY-SUBRC = 0.
          CALL FUNCTION 'NUMBER_GET_NEXT'
            EXPORTING
              NR_RANGE_NR             = '01'
              OBJECT                  = 'Z_R_BATCH'
            IMPORTING
              NUMBER                  = C_CHAR09
            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.
    
          CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
            EXPORTING
              OBJECT           = 'Z_R_BATCH'
            EXCEPTIONS
              OBJECT_NOT_FOUND = 1
              OTHERS           = 2.
          CONCATENATE P_CHAR01 C_CHAR09 INTO P_CHARG.
    
          CLEAR LV_LOCK.
    
        ENDIF.
      ENDWHILE.
    
    ENDFORM.                    " PRM_GENERATE_BATCH
    FORM PRM_GENERATE_MC  USING    P_S_ZMMT0004_CHARG
                                   P_S_ZMMT0004_ZGSKH
                          CHANGING P_LS_RETURN STRUCTURE BAPIRET2.
      DATA:LV_BATCH TYPE CHARG_D.
    
    * Call BAPI 产生物料批次号码
      LS_BATCHCONTROLFIELDS-CLASS_NUM  = 'Z_CLASS_BATCH'.
      LS_BATCHCONTROLFIELDS-DOCLASSIFY = 'X'.
    
      CALL FUNCTION 'BAPI_BATCH_CREATE'
        EXPORTING
          MATERIAL           = P_S_ZMMT0004_ZGSKH
          BATCH              = P_S_ZMMT0004_CHARG
          BATCHCONTROLFIELDS = LS_BATCHCONTROLFIELDS
        IMPORTING
          BATCH              = LV_BATCH
        TABLES
          RETURN             = LT_RETURN.
      READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
      IF SY-SUBRC = 0.
        MOVE-CORRESPONDING LS_RETURN TO P_LS_RETURN.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    *      EXPORTING
    *        WAIT = 'X'.
      ENDIF.
    
    
    ENDFORM.                    " PRM_GENERATE_MC
    FORM PRM_SET_BATCH_ATT  USING    P_ZMMS0004 STRUCTURE ZMMT0004
                                     P_ZMMT0003  STRUCTURE ZMMT0003
                            CHANGING P_RETURN    STRUCTURE BAPIRET2.
      DATA:LS_ZMMS0004 TYPE ZMMS0004.
      CLEAR:LS_ZMMS0004.
      MOVE-CORRESPONDING P_ZMMS0004 TO LS_ZMMS0004.
    
      LS_ZMMS0004-ZZSPCH2 = P_ZMMS0004-ZZSPCH1. "主石批次号2
      LS_ZMMS0004-ZZSSL2 = P_ZMMS0004-ZZSSL1. "主石数量1
      LS_ZMMS0004-ZZSZL2 = P_ZMMS0004-ZZSZL1. "主石重量1
      LS_ZMMS0004-ZZSDJ2 = P_ZMMS0004-ZZSDJ1. "主石单价1
      LS_ZMMS0004-ZZSCB2 = P_ZMMS0004-ZZSCB1. "主石成本1
      LS_ZMMS0004-ZGJJCZSH = P_ZMMS0004-ZGJZSH. "国际证书号
      LS_ZMMS0004-ZXSDD    = P_ZMMT0003-VBELN. "销售订单
      LS_ZMMS0004-ZSCCKJ   = P_ZMMS0004-ZSJCB."市场参考价
      LS_ZMMS0004-ZCSSCCKJ = P_ZMMS0004-ZSJCB."初始市场参考价
      LS_ZMMS0004-ZPJSL1   = P_ZMMS0004-ZMENGE1. "配件数量1
      LS_ZMMS0004-ZPJSL2   = P_ZMMS0004-ZMENGE2. "配件数量2
      LS_ZMMS0004-ZJBGF    = P_ZMMS0004-ZJGF. "基本工费
      LS_ZMMS0004-ZXSLX    = P_ZMMT0003-AUART. "销售类型
      LS_ZMMS0004-ZJCS     = P_ZMMS0004-ZJCS.    "成色
      LS_ZMMS0004-ZGJJCJD  = P_ZMMS0004-ZGJJD. "国际净度
      LS_ZMMS0004-ZGJJCYS  = P_ZMMS0004-ZGJSD. "国际色度
      LS_ZMMS0004-ZGJJCQG  = P_ZMMS0004-ZGJQG. "国际切工
      LOOP AT LT_FIELD INTO LS_FIELD WHERE FIELDNAME NE 'ZDJBTHB'.
        CASE LS_FIELD-DATATYPE.
          WHEN 'CHAR'.
            LV_TYPE = '1'.
          WHEN 'DEC' OR 'QUAN'.
            LV_TYPE = '2'.
          WHEN 'CURR'.
            LV_TYPE = '3'.
          WHEN OTHERS.
            ...
        ENDCASE.
        CLEAR LV_FIELD.
        CONCATENATE 'Z_' LS_FIELD-FIELDNAME INTO LV_FIELD.
        ASSIGN COMPONENT LS_FIELD-FIELDNAME OF STRUCTURE LS_ZMMS0004 TO <FS_VALUE>.
        IF SY-SUBRC EQ 0.
          APPEND_ALLOC_VALUE LV_TYPE LV_FIELD <FS_VALUE>.
          UNASSIGN <FS_VALUE>.
        ENDIF.
    
      ENDLOOP.
    
      READ TABLE LT_ALLOC_CHAR INTO LS_ALLOC_CHAR WITH KEY CHARACT = 'Z_ZHPBM'.
      IF SY-SUBRC EQ 0.
        LS_ALLOC_CHAR-VALUE_CHAR = P_ZMMS0004-CHARG.
        LS_ALLOC_CHAR-VALUE_NEUTRAL = P_ZMMS0004-CHARG.
        MODIFY LT_ALLOC_CHAR FROM LS_ALLOC_CHAR INDEX SY-TABIX.
      ELSE.
        LS_ALLOC_CHAR-CHARACT = 'Z_ZHPBM'.
        LS_ALLOC_CHAR-VALUE_CHAR = P_ZMMS0004-CHARG.
        LS_ALLOC_CHAR-VALUE_NEUTRAL = P_ZMMS0004-CHARG.
        APPEND LS_ALLOC_CHAR TO LT_ALLOC_CHAR.
      ENDIF.
    
    * 更新物料的批次属性值
      CLEAR LV_KEY.
      LV_KEY+0(18) = P_ZMMS0004-ZGSKH.
      LV_KEY+18(10) = P_ZMMS0004-CHARG.
    *--------------------TUS-CHARG-BEGIN---------------------------------*
    * Update material class
      CALL FUNCTION 'BAPI_OBJCL_CHANGE'
        EXPORTING
          OBJECTKEY          = LV_KEY
          OBJECTTABLE        = LV_TABLE
          CLASSNUM           = LV_CLASS
          CLASSTYPE          = LV_CLASS_TYPE
          STATUS             = '1'
          KEYDATE            = SY-DATUM
        IMPORTING
          CLASSIF_STATUS     = LV_STATUS
        TABLES
          ALLOCVALUESNUMNEW  = LT_ALLOC_NUM
          ALLOCVALUESCHARNEW = LT_ALLOC_CHAR
          ALLOCVALUESCURRNEW = LT_ALLOC_CURR
          RETURN             = LT_RETURN.
    *--------------------TUS-CHARG-END-----------------------------------*
      READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE = 'E'.
      IF SY-SUBRC = 0.
        MOVE-CORRESPONDING LS_RETURN TO P_RETURN.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT = 'X'.
      ENDIF.
    
    ENDFORM.                    " PRM_SET_BATCH_ATT
  • 相关阅读:
    第十六周 项目一-平方根中的异常
    LeetCode之小孩分糖果
    C#中怎样将List&lt;自己定义&gt;转为Json格式 及相关函数-DataContractJsonSerializer
    (016)给定一个有序数组(递增),敲代码构建一棵具有最小高度的二叉树(keep it up)
    物化视图
    FZU2171:防守阵地 II(线段树)
    鸡尾酒排序
    Android BlueDroid(三):BlueDroid蓝牙开启过程enable
    CF Codeforces Round #256 (Div. 2) D (448D) Multiplication Table
    window.open()具体解释及浏览器兼容性问题
  • 原文地址:https://www.cnblogs.com/sapSB/p/6400249.html
Copyright © 2020-2023  润新知