Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
ebrambilla
Contributor III
Contributor III

Customer switch problem

Hello,

in our ERP SAP R/3 in the customer record we can use a field containing the "previous customer code". When a new customer record is created to substitute an old one (this may happen for different reasons like changes in VAT, Bankrupty etc.) in the new record we put the old customer code in that field.

So, I can have a table like this:

OLDCODENEWCOD
AB
BC
CD
DE
FG
HK

Here, means customer record A was replaced by Customer record B, customer record B was replaced by customer record C and so on.

Now, I want to build a new table showing only initial-final relationships; in the last column we will have the final customer:

INITIALCODEFINALCODE
AE
BE
CE
DE
FG
HK

The number of levels is not known but we could assume is limited to 10.

Anyone has an idea on how to afford the problem?

Thanks!

1 Solution

Accepted Solutions
Gysbert_Wassenaar

mapCode:

mapping LOAD

     OLDCODE,

     NEWCOD

FROM ...mysource1...;

FinalCode:

LOAD

     INITIALCODE,

     applymap('mapCode',

           applymap('mapCode',

               applymap('mapCode',

               ....nested to 10 levels,

               ....applymap('mapCode',INITIALCODE) ))))))))) as FINALCODE

FROM ...mysource2...;

Another option you can try is using the Hierachy() function to build the replacement tree and then use the root and the leaf for each code.


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar

mapCode:

mapping LOAD

     OLDCODE,

     NEWCOD

FROM ...mysource1...;

FinalCode:

LOAD

     INITIALCODE,

     applymap('mapCode',

           applymap('mapCode',

               applymap('mapCode',

               ....nested to 10 levels,

               ....applymap('mapCode',INITIALCODE) ))))))))) as FINALCODE

FROM ...mysource2...;

Another option you can try is using the Hierachy() function to build the replacement tree and then use the root and the leaf for each code.


talk is cheap, supply exceeds demand
ebrambilla
Contributor III
Contributor III
Author

Thank you Gysbert,

PERFECT, I tested the ApplyMap solution. Efficient and easy!