The logic that I am trying to implement is:
If the first record has the code as "A" and 2nd record as "A"/"C"/"D", then I need to get the reject_cd as "M"
else
If the first record has the code as "C" and 2nd record as "A"/"C"/"D", then I need to get the reject_cd as "N"
else
If the first record has the code as "D" and 2nd record as "A"/"C"/"D", then I need to get the reject_cd as "O".

Using the above scan, the output result that I got is as under:
123|A|X| |12.0||
123|A|X|2012-02-17|18.5|M|
123|D|Y|2012-02-18|20.5|O|
123|C|X|2012-02-19|09.5|N|
123|A|X|2012-02-21|10.0|M|
123|C|X|2012-02-22|32.5|N|
123|D|X|2012-02-23|45.5|O|

Where exactly I am going wrong as the first record has NULL populated instead of "M".

You can do with little modification to finalize function you pasted in your first post. Add a ELSE portion in your "If" statement to check for temp.prev_cd being NULL that will identify first record in the group.

You can do with little modification to finalize function you pasted in your first post. Add a ELSE portion in your "If" statement to check for temp.prev_cd being NULL that will identify first record in the group.

And if Prev_cd get assigned to Blank or single space As this is the case i found when running it Abinitio , Then Have the "ELSE" condition changed to handle Blanks post trimming Prev_cd Instead of NULL.

Use the Below Code That is running successfully. Here Priority based Map rules are not there.

Hi,
One thing is still not getting resolved.
Say, if I have the below 2 records:

123|A|X|2012-02-17|18.5|
123|D|Y|2012-02-18|20.5|

Depending on the 4 values (A,X,D,Y) the final output needs to be:

123|A|X|2012-02-17|18.5|DELETE|
123|D|Y|2012-02-18|20.5|PROCESS|

The condition that I need to code is as under:
For the same Tran_Id, if the first transaction has Transaction Code of A and Source Code of X while the second transaction has Transaction code of "D" and Source Code of "Y" then I need to populate DELETE for 1st record and PROCESS for 2nd Record. Also if the first transaction has Transaction Code of D and Source Code of Y while the second transaction has Transaction code of "A" and Source Code of "X" then I need to populate PROCESS for 1st record and DELETE for 2nd Record.

When I am using the below transformation in scan, then my result is okay for the 2nd record however for the first one its getting the default value.

Hi,
As per my knowledge, you can't have a field value of first record in
each group depending upon the value of successive record. You may have to
look for some other logic to derive values for fields of first record.

The real requirement is as under:
I have 2 records which can have Transaction code (referred as source_trans_type_cd) as "A", "C", "D" and the source code (referred as source_file_cd) can be "X", "T", "D","B","V","Z&q uot; and 5 more such source codes.
To reduce the complexity (there arise close to 108 cases) I am just taking the 1st transaction code and 2nd transaction code as "A" while source codes being "X","A" only.
The business requirement is:

If firstTransaction source_trans_type_cd = 'A' AND secondTransaction source_trans_type_cd = 'A' Then
if OptionalDuplicateIndicator = 'Y' (on firstTransaction ) then
set action_cd = 'P' for both records
else
If source_file_cd IN ('X') on first Transaction and source_file_cd = 'A' on Secondtransaction then
Set action_cd = 'L' on first Transaction
Set reject_reason_cd on first transaction = '01'
set action_cd = 'P' on Second transaction ( process and add to VARSTGTransactionalDataCore )
elseif source_file_cd = 'A' on first Transaction and source_file_cd IN ('X') on Second transaction then
Set action_cd = 'L' on Second Transaction
Set reject_reason_cd on Second transaction = '01'
set action_cd = 'P' on first Transaction ( process and add to VARSTGTransactionalDataCore )
elseif source_file_cd on first Transaction = Second Row source_file_cd on Second transaction then
set action_cd = 'L' on first Transaction ( Log the record )
Set reject_reason_cd on first transaction = '01'
set action_cd = 'P' on Second transaction ( process and add to VARSTGTransactionalDataCore )
end
end

That is the reason, I am looking for the comparison of the first 2 records.

My idea of solution for this is I will simply populate the flag in the same scan component and then proceed to drop the same.

The missing question is what to do if there is only a single transaction.

SCAN is not the right component for the processing style described by the business rules. You want to read a group of records process them according to your business logic and write a group of records.

I would suggest converting to a vector using ROLLUP with the accumulation() function, keeping your business logic in a reformat and then normalising back out.