我是靠谱客的博主 想人陪电灯胆,最近开发中收集的这篇文章主要介绍自动处理【库存物料交易MMT接口表】程序,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

这个程序,根据输入的参数可以自动处理MTL_TRANSACTIONS_INTERFACE表或者MTL_MATERIAL_TRANSACTIONS_TEMP表。

处理有2中方式:

1 自动提交请求Inventory transaction worker处理。处理对应的TRANSACTION_HEADER_ID的数据。只是负责提请求处理接口表数据,后期是否成功不是它可以知道的。

2 立刻过账。如果有1笔过账不了,则返回错误。

可以根据实际需要选择不同的处理接口的方式。

提交请求的好处是,处理大批量的数据的时候,处理速度快。但是不可以保证处理的完整性。因为数据随时可能卡接口。所以建议增加库存或者库存转移的交易可以选择这种处理。

而立刻过账的好处是,可以保证整个流程可以完整完成,因为它可以完全保证丢到接口表的数据一定可以产生交易。缺点是处理速度慢。当过账的数据超过500行,联机处理起来速度极慢。致命的缺点。扣减库存的最好选择这种处理。(曾经试过过账1500行杂发数据,立刻过账逻辑处理,它处理了3个多小时,还没完成。后来改为直接丢接口,不用几分钟就跑完了。。。)

这个东西还是蛮实用的。

具体请看输入参数

   -----------------------------
   --处理接口表,可选处理方式
   -----------------------------
   PROCEDURE PROCESS_TRANSACTION_INTERFACE(
      P_PROCESS_TABLE           VARCHAR2  ---处理表格,是 INTERFACE 表 还是 TEMP 表
     ,P_PROCESS_TYPE           VARCHAR2  ---处理方式,是 提交请求 SUBMIT_REQUEST 还是 立刻过账 PROCESS_ONLINE
     ,P_TRANSACTION_HEADER_ID  NUMBER    ---处理的头ID
     ,x_REQUEST_ID           OUT NUMBER --输出的请求ID
     ,x_retcode              OUT NUMBER  ---0:成功  非0:失败( 或者:0:成功  1:警告   2:错误  ----注意:确定警告的时候要做什么动作)
     ,x_errbuf               OUT VARCHAR2  ---具体的错误信息
   )

      IS
       L_PROCESS_PHASE     NUMBER;                             --标识程序的进度
       ---
       L_REQUEST_TABLE     VARCHAR2(1);
       L_REQUEST_ID        NUMBER;
       ---
       ---INTERFACE Online Deal
       L_OUTCOME               BOOLEAN;
       L_TIMEOUT               NUMBER := 100;
       L_ERROR_CODE            VARCHAR2(4000);
       L_ERROR_EXPLANATION     VARCHAR2(4000);
       ---
       ---TEMP Online Deal
       L_RETURN_COUNT                NUMBER;
       X_TRANS_COUNT                 NUMBER;
       X_RETURN_STATUS               VARCHAR2 (1);
       X_MSG_COUNT                   NUMBER;
       X_MSG_DATA                    VARCHAR2 (2000);
   BEGIN
      x_retcode := 0;
      x_errbuf := Null;

      L_PROCESS_PHASE := 0;

      ---首先的第一步是:检查不可以为空的参数
      IF P_PROCESS_TABLE IS NULL OR P_PROCESS_TYPE IS NULL OR P_TRANSACTION_HEADER_ID IS NULL
      THEN
         x_errbuf := '调用PROCESS_TRANSACTION_INTERFACE的时候,必要的参数不存在,请检查参数!';
         x_retcode := 2;
         RETURN;
      END IF;

      L_PROCESS_PHASE := 1;

     ------------Start------------
      IF P_PROCESS_TYPE = 'SUBMIT_REQUEST' THEN
        ---自动提交过账的请求
        --Process transaction interface
        /*L_REQUEST_ID :=
         FND_REQUEST.SUBMIT_REQUEST('INV'
                                   ,'INCTCM'
                                   ,''
                                   ,TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS')
                                   ,FALSE
                                   ,CHR(0)
                                   );*/
        ---Inventory transaction worker
        IF P_PROCESS_TABLE = 'INTERFACE' THEN
          L_REQUEST_TABLE := '1';
        ELSIF P_PROCESS_TABLE = 'TEMP' THEN
          L_REQUEST_TABLE := '2';
        ELSE
         x_errbuf := '参数P_PROCESS_TABLE('||P_PROCESS_TABLE||')无效,请检查参数!';
         x_retcode := 2;
         RETURN;
        END IF;
        L_REQUEST_ID :=
        FND_REQUEST.SUBMIT_REQUEST( 'INV', -- application
                                    'INCTCW', -- program
                                    NULL, --'Inventory Transaction Worker', description optional)
                                    NULL, -- start_time (optional)
                                    FALSE, -- sub_request
                                    to_char(P_TRANSACTION_HEADER_ID), -- header id to process
                                    L_REQUEST_TABLE, -- 1 is the interface table 2 is temp table
                                    '', -- group to process required
                                    '', -- source to process
                                    chr(0)
                                    );
        L_PROCESS_PHASE := 2;
        dbms_output.PUT_LINE('自动产生的请求ID:'||L_REQUEST_ID);
        IF L_REQUEST_ID = 0 THEN
          x_errbuf := '自动提交请求失败!';
          x_retcode := 2;
          RETURN;
        ELSE
          x_errbuf := x_errbuf||'自动提交请求成功!请求ID:'||L_REQUEST_ID;
        END IF;
        x_REQUEST_ID := L_REQUEST_ID;
        L_PROCESS_PHASE := 3;
      ELSIF P_PROCESS_TYPE = 'PROCESS_ONLINE' THEN
         IF P_PROCESS_TABLE = 'INTERFACE' THEN
             L_TIMEOUT := 100;
             -- Auto commit whenever success or failure!!but by sam.t modify:no auto commit;
             L_OUTCOME :=
                XYG_MTL_ONLINE_TRANSACTION_PUB.PROCESS_ONLINE(
                   P_TRANSACTION_HEADER_ID   => P_TRANSACTION_HEADER_ID
                  ,P_TIMEOUT                 => L_TIMEOUT
                  ,P_ERROR_CODE              => L_ERROR_CODE
                  ,P_ERROR_EXPLANATION       => L_ERROR_EXPLANATION
                );
            L_PROCESS_PHASE := 4;

             IF (L_OUTCOME = FALSE)
             THEN
                DBMS_OUTPUT.PUT_LINE('Failed to process the transaction');
                DBMS_OUTPUT.PUT_LINE('Error code: ' || L_ERROR_CODE);
                DBMS_OUTPUT.PUT_LINE('Error message: ' || L_ERROR_EXPLANATION);

                --删除批次接口表数据
                DELETE MTL_TRANSACTION_LOTS_INTERFACE
                 WHERE TRANSACTION_INTERFACE_ID IN
                             (SELECT TRANSACTION_INTERFACE_ID
                                FROM MTL_TRANSACTIONS_INTERFACE
                               WHERE TRANSACTION_HEADER_ID =
                                        P_TRANSACTION_HEADER_ID);
                --删除物料事务处理接口表数据
                DELETE INV.MTL_TRANSACTIONS_INTERFACE
                 WHERE TRANSACTION_HEADER_ID = P_TRANSACTION_HEADER_ID;

                x_retcode := 2;
                x_errbuf :=
                      '过账捆绑编码('|| P_TRANSACTION_HEADER_ID||')在INTERFACE接口表处理错误!错误信息:'
                   || CHR(10)
                   || L_ERROR_CODE
                   || '-'
                   || L_ERROR_EXPLANATION;
                ---必须做回滚!因为可能部分数据已经丢到接口表!
                ROLLBACK;
                ----
                RETURN;
             ELSE
                NULL;
                DBMS_OUTPUT.PUT_LINE(   'INTERFACE Transaction with header id '
                                     || TO_CHAR(P_TRANSACTION_HEADER_ID)
                                     || ' has been processed successfully');
             END IF;
         ELSIF P_PROCESS_TABLE = 'TEMP' THEN
            FND_MSG_PUB.INITIALIZE;
            X_RETURN_STATUS            := FND_API.G_RET_STS_SUCCESS;
            --0 to indicate successful processing and value -1 to indicate failure processing
            L_RETURN_COUNT             :=
              INV_TXN_MANAGER_PUB.PROCESS_TRANSACTIONS
                                    (P_API_VERSION           => 1.0
                                    ,P_INIT_MSG_LIST         => FND_API.G_FALSE
                                    ,P_COMMIT                => FND_API.G_FALSE
                                    ,P_VALIDATION_LEVEL      => FND_API.G_VALID_LEVEL_FULL
                                    ,X_RETURN_STATUS         => X_RETURN_STATUS
                                    ,X_MSG_COUNT             => X_MSG_COUNT
                                    ,X_MSG_DATA              => X_MSG_DATA
                                    ,X_TRANS_COUNT           => X_TRANS_COUNT
                                    ,P_TABLE                 => 2   --1==MTI,2==MMTT
                                    ,P_HEADER_ID             => P_TRANSACTION_HEADER_ID
                                    );

            IF L_RETURN_COUNT = -1 OR X_RETURN_STATUS <> FND_API.G_RET_STS_SUCCESS
            THEN
              FOR A_REC IN (SELECT MMTT.TRANSACTION_TEMP_ID
                                  ,MMTT.ERROR_CODE
                                  ,MMTT.ERROR_EXPLANATION
                              FROM MTL_MATERIAL_TRANSACTIONS_TEMP MMTT
                             WHERE MMTT.TRANSACTION_HEADER_ID = P_TRANSACTION_HEADER_ID
                               AND ROWNUM=1) --只取1个错误显示出来
              LOOP
                 DBMS_OUTPUT.PUT_LINE (   'transaction_temp_id: '
                                       || A_REC.TRANSACTION_TEMP_ID
                                      );
                 DBMS_OUTPUT.PUT_LINE ('error_code: ' || A_REC.ERROR_CODE);
                 DBMS_OUTPUT.PUT_LINE ('error_explanation: '
                                       || A_REC.ERROR_EXPLANATION
                                      );
                x_errbuf :=
                      '过账捆绑编码('|| P_TRANSACTION_HEADER_ID||')在TEMP接口表时处理错误!错误信息:'
                   || CHR(10)
                   || A_REC.ERROR_CODE
                   || '-'
                   || A_REC.ERROR_EXPLANATION;
              END LOOP;
              x_retcode := 2;
              ---必须做回滚!因为可能部分数据已经丢到接口表!
              ROLLBACK;
                ----
              RETURN;
            ELSE
               NULL;
                DBMS_OUTPUT.PUT_LINE(   'TEMP Transaction with header id '
                                     || TO_CHAR(P_TRANSACTION_HEADER_ID)
                                     || ' has been processed successfully');
            END IF;
         ELSE
             x_errbuf := '参数P_PROCESS_TABLE('||P_PROCESS_TABLE||')无效,请检查参数!';
             x_retcode := 2;
             RETURN;
         END IF;
        L_PROCESS_PHASE := 5;
      ELSE
         x_errbuf := '参数P_PROCESS_TYPE('||P_PROCESS_TYPE||')无效,请检查参数!';
         x_retcode := 2;
         RETURN;
      END IF;
      ------------End--------------

      L_PROCESS_PHASE := 6;

   EXCEPTION
      WHEN OTHERS
      THEN
         x_retcode := 2;
         x_errbuf :=
               'P_PROCESS_TYPE:'
            || P_PROCESS_TYPE
            || ' P_TRANSACTION_HEADER_ID:'
            || P_TRANSACTION_HEADER_ID
            || ' 产生交易的时候有异常错误!'
            || CHR(10)
            || '错误信息:'
            || TO_CHAR(SQLCODE)
            || '-'
            || SQLERRM
            || CHR(10)
            || '程序进度:'
            || L_PROCESS_PHASE;
   END;

最后

以上就是想人陪电灯胆为你收集整理的自动处理【库存物料交易MMT接口表】程序的全部内容,希望文章能够帮你解决自动处理【库存物料交易MMT接口表】程序所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部