The Problem
Oracle's Payment Process Profile (PPP) generates its built-in sequence numbers in steps of 2 like 2, 4, 6, 8, 10 …
For Our NACHA files we expect a clean, incrementing sequence like - 1, 2, 3, 4, 5 …
This post walks through the logic used to convert the PPP's "every-other-number" output into the correct simple sequence.
The Data, Visualized
Here's what the transformation looks like in practice. The Template Output column is what Oracle's PPP produces natively in our output, and Desired Value is the sequence we actually need:
The pattern is clear: every time the PPP's raw counter jumps by 2, our desired output should only increase by 1. So the fix boils down to dividing the running offset by 2 and padding it back into the standard 3-digit sequence format.
The very first row is a special case - there's no PPP value yet (LastValue is empty), so the desired output simply starts at 1. This is exactly what the DECODE(..., '', '001', ...) branch of the logic below handles.
The Logic Used
DECODE(
/OutboundPaymentInstruction/PaymentInstructionInfo/PaymentSequence
[SequenceName='US_NACHA_DAILY_SEQ']/LastValue,
'',
'001',
LPAD(
(SEQUENCE_NUMBER(US_NACHA_DAILY_SEQ)
- (/OutboundPaymentInstruction/PaymentInstructionInfo/PaymentSequence
[SequenceName='US_NACHA_DAILY_SEQ']/LastValue) div 2
),
3,
'0'
)
)
Or
/OutboundPaymentInstruction/PaymentInstructionInfo/PaymentSequence
[SequenceName='US_NACHA_DAILY_SEQ']/LastValue) div 2
Breaking It Down
1. DECODE(... , '', '001', ...)
Checks whether LastValue for the US_NACHA_DAILY_SEQ sequence is empty. If it's the very first run (no prior value exists), the sequence starts fresh at 001.
2. SEQUENCE_NUMBER(US_NACHA_DAILY_SEQ) - LastValue
If a prior value does exist, this calculates the difference between the current auto-generated sequence number and the last recorded value — effectively measuring how far the counter has advanced since the last run.
3. ... div 2
Because the PPP always advances in steps of 2, dividing that difference by 2 converts the raw counter movement back into a true incrementing count — 1, 2, 3, 4 … instead of 2, 4, 6, 8 …
4. LPAD(..., 3, '0')
Finally, the result is zero-padded to 3 digits (e.g., 6 becomes 006), matching the format NACHA and other downstream systems expect.
Result
With this logic in place, the PPP's native 2-step counter is transparently converted into a clean, correctly-padded 1-step sequence with no changes needed anywhere else in the payment process.
No comments:
Post a Comment