TRANSACTION_HEADER_ID & TRANSACTION_BATCH_ID & TRANSACTION_BATCH_SEQ

本文详细解析了MTL_TRANSACTIONS_INTERFACE表中的TRANSACTION_HEADER_ID、TRANSACTION_BATCH_ID及TRANSACTION_BATCH_SEQ三个字段的作用与分工。TRANSACTION_HEADER_ID用于标识交易组并确保同一组内的所有记录作为一个整体进行处理;TRANSACTION_BATCH_ID与TRANSACTION_BATCH_SEQ则共同定义了批次内的交易序列,确保交易按指定顺序执行。

MTL_TRANSACTIONS_INTERFACE和MTL_MATERIAL_TRANSACTIONS_TEMP有三个类似的字段:TRANSACTION_HEADER_ID & TRANSACTION_BATCH_ID & TRANSACTION_BATCH_SEQ

以下为eTRM里关于这三个字段的解释:

TRANSACTION_HEADER_ID:Transaction group identifier and Workers, only user-specified values will be ignored.

TRANSACTION_BATCH_ID:Batch id for transaction

TRANSACTION_BATCH_SEQ:Batch sequence for transaction


从字面上看,三个字段意思似乎是一样的,但其实三个字段有不同的分工。

TRANSACTION_HEADER_ID

INV Manager的校验会把同样transaction_header_id的一批记录一起丢到代码中校验和处理。

Package inv_txn_manager_pub
...
   -----------------------------------------------------------------------
   -- Name : validate_group
   -- Desc : Validate a group of MTI records in a batch together.
   --          This is called from process_transaction() when TrxMngr processes
   --          a batch of records
   -- I/P params :
   --     p_header_id : transaction_header_id
   -----------------------------------------------------------------------
   PROCEDURE validate_group(p_header_id NUMBER
                                ,x_return_status OUT NOCOPY VARCHAR2
                                ,x_msg_count OUT NOCOPY NUMBER
                                ,x_msg_data OUT NOCOPY VARCHAR2
                                ,p_userid NUMBER DEFAULT -1
                ,p_loginid NUMBER DEFAULT -1);



   -----------------------------------------------------------------------
   -- Name : validate_lines (wrapper)
   -- Desc : Validate each record of a batch in MTI .
   --        This procedure acts as a wrapper and calls the inner validate_lines.
   --
   -- I/P params :
   --     p_header_id : transaction_header_id
   --     p_validation_level : Validation level
   -----------------------------------------------------------------------
   PROCEDURE validate_lines(p_header_id NUMBER,
                           p_commit VARCHAR2 := fnd_api.g_false     ,
                           p_validation_level NUMBER  := fnd_api.g_valid_level_full  ,
                           x_return_status OUT NOCOPY VARCHAR2,
                           x_msg_count OUT NOCOPY NUMBER,
                           x_msg_data OUT NOCOPY VARCHAR2,
                           p_userid NUMBER DEFAULT -1,
                           p_loginid NUMBER DEFAULT -1,
                           p_applid NUMBER DEFAULT NULL,
                           p_progid NUMBER DEFAULT NULL);
...


TRANSACTION_BATCH_ID & TRANSACTION_BATCH_SEQ

Refer:bug 3663786

In 11.5.10 transaction_group_id and transaction_group_seq are not used.
Instead,transaction_batch_id and transaction_batch_seq are used.
So, one can start using the batch id and the batch seq to achieve the purpose.

The transaction worker would pick up everything in a batch and process them together as per the sequence number.However, if anything in that batch fails, it will rollback all the transactions in that batch. That is the current architecture.

All these values should be populated in the MTL_TRANSACTIONS_INTERFACE table.

You can populate the sequence value to the transaction_batch_seq column and the batch_id to the transaction_batch_id to column.

However, all the transactions belonging to a batch should all have the same transaction_header_id.
The inventory transaction manager picks up all the records for a specific header and then processes everything in a batch together.


So, a single header may have multiple batches but, if one record fails, we only fail that batch and not the other batches.

So, for the records to be processed in certain order
1. They all should have the same transaction_header_id
2. They all should have the same transaction_batch_id
3. They should have a transaction_batch_seq in the order they have to be processed.

you can leave the transaction batch seq as null. If you want the records to error out

1)You should have the same transaction_header_id
2)You should have the same transaction batch id.



CREATE DEFINER=`root`@`%` PROCEDURE `sync_order_consumption_copy1`() BEGIN #Routine body goes here... -- 定义批次大小和起始点 SET @batch_size = 1; SET @min_id = (SELECT MIN(order_id) FROM c_order where delmark in (1,2,3)); SET @max_id = (SELECT MAX(order_id) FROM c_order where delmark in (1,2,3)); -- 循环处理每个批次 WHILE @min_id <= @max_id DO START TRANSACTION; CREATE TEMPORARY TABLE id_mapping ( seq INT AUTO_INCREMENT PRIMARY KEY, source_id INT ); INSERT INTO id_mapping (source_id) SELECT order_consumption_id FROM c_order_consumption WHERE order_id BETWEEN @min_id AND @min_id + @batch_size - 1 AND delmark IN (1,2,3) AND order_consumption_record_id = 0 ORDER BY order_consumption_id; -- 置换订单明细 -- 消耗完 INSERT INTO c_order_consumption_record( sign, consumption_date, customer_id, agent_id, user_id, comment_id, detection, clean_hair, effect, create_time, create_by, update_time, update_by, delmark, remark ) SELECT sign, consumption_date, customer_id, agent_id, user_id, null, 0, 0, 0, create_time, create_by, update_time, update_by, delmark, remark FROM c_order_consumption c JOIN id_mapping m ON c.id = m.source_id ORDER BY m.seq; -- 获取自增ID SET @first_id = LAST_INSERT_ID(); SET @row_count = ROW_COUNT(); -- 通过序号映射更新 UPDATE c_order_consumption dest JOIN id_mapping m ON dest.id = m.source_id SET dest.order_consumption_record_id = @first_id + m.seq - 1 -- 计算自增ID WHERE m.seq <= @row_count; -- 数据一致性校验:检查行数是否匹配 SET @order_info_count = (SELECT COUNT(1) FROM c_order_consumption WHERE order_consumption_record_id = @first_id ); SET @order_count = (SELECT count(1) from c_order_consumption_record c where c.order_consumption_record_id = @first_id); -- 如果校验失败,回滚事务 IF @order_info_count != @order_count THEN ROLLBACK; SELECT @min_id,@min_id + @batch_size - 1,'This is a log error message' AS LogMessage; SELECT @order_info_count, @order_count AS LogMessage; SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Data inconsistency detected, rolled back batch'; ELSE COMMIT; END IF; -- 更新批次起始点 SET @min_id = @min_id + @batch_size; END WHILE; -- 释放表锁 -- UNLOCK TABLES; END
最新发布
11-03
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值