cancel
Showing results for 
Search instead for 
Did you mean: 

How to perform looping for multiple columns to get a single column data

sshaik
New Contributor III

If Iteration 1 then I have to concat all the columns with some special characters and spaces. If the iteration goes to 2nd time them concat all the columns with some special characters and spaces like this we need data for 4 iterations.
EX: IF @ITERATION=1 THEN ($TYP : $A : $B : ‘A’ : $C : SPACE(6) : $$CD : SPACE(17) )ELSE IF @ITERATION=2 THEN ($TYP : $A : $B : ‘B’ : $NO : $G : SPACE(31) )ELSE IF @ITERATION=3 THEN ($TYP : $A : $B : ‘$C’ : $NO : SPACE(16) : $F : $DT : $GH : SPACE(23) )ELSE ($TYP : $A : $B : ‘D’ : $NO : SPACE(61) : $D )

@dmiller @bojanvelevski Please help on this topic

2 ACCEPTED SOLUTIONS

sshaik
New Contributor III

image
Iteration condition: IF @ITERATION=1 THEN ($TYP : $A : $B : ‘A’ : $C : SPACE(6) : $$CD : SPACE(17) )ELSE IF @ITERATION=2 THEN ($TYP : $A : $B : ‘B’ : $NO : $G : SPACE(31) )ELSE IF @ITERATION=3 THEN ($TYP : $A : $B : ‘$C’ : $NO : SPACE(16) : $F : $DT : $GH : SPACE(23) )ELSE ($TYP : $A : $B : ‘D’ : $NO : SPACE(61) : $D )
In mapper split the Iteration conditions into 4 columns with different names
And then make copy of data. map 1st iteration column to $RECORD column and follow the same for remaining 3 iteration conditions. The target column should be $RECORD for all 4 mappers.
After that I used union and capture the $RECORD column in mapper and finally Got the result.

View solution in original post

sshaik
New Contributor III

Iteration condition: IF @ITERATION=1 THEN ($TYP : $A : $B : ‘A’ : $C : SPACE(6) : $$CD : SPACE(17) )ELSE IF @ITERATION=2 THEN ($TYP : $A : $B : ‘B’ : $NO : $G : SPACE(31) )ELSE IF @ITERATION=3 THEN ($TYP : $A : $B : ‘$C’ : $NO : SPACE(16) : $F : $DT : $GH : SPACE(23) )ELSE ($TYP : $A : $B : ‘D’ : $NO : SPACE(61) : $D )

 

According to this iteration condition, we have to generate the values till to the last iteration i.e., iteration4 ($TYP: $A: $B : ‘D’ : $NO : SPACE(61) : $D ).

 

In mapper I’m getting the $A,$B,$C,$D FIELDS along with those columns need to add spaces ….

In a mapper I have spitted the expression into 4 parts like

ITERATION=1  $TYP : $A : $B : ‘A’ : $C : SPACE(6) : $CD : SPACE(17))   ---$LVRECORD1

ITERATION=2 ($TYP : $A : $B : ‘B’ : $NO : $G : SPACE(31) )   ---$LVRECORD2

ITERATION=3  ($TYP : $A : $B : ‘$C’ : $NO : SPACE(16) : $F : $DT : $GH : SPACE(23) )--- $LVRECORD3

ITERATION=4  ($TYP: $A: $B : ‘D’ : $NO : SPACE(61) : $D ). ) ---$LVRECORD4

In the next mapper

sshaik_0-1692858183018.png

 

Next mapper

sshaik_1-1692858183020.png

 

sshaik_2-1692858183021.png

 

Same for all the 4 source columns I have taken the target as $LVRECORD

Output:

ABCD                 CD                         A                                                                                   iteration1

ABCD                 NO         G                          A                                                                     iteration2

ABCD                 CD           F            DTGH                                               A                          iteration3

TYP                     ADNO                 CD                          A                                                       iteration4

 

 

View solution in original post

8 REPLIES 8

sshaik
New Contributor III

image
Iteration condition: IF @ITERATION=1 THEN ($TYP : $A : $B : ‘A’ : $C : SPACE(6) : $$CD : SPACE(17) )ELSE IF @ITERATION=2 THEN ($TYP : $A : $B : ‘B’ : $NO : $G : SPACE(31) )ELSE IF @ITERATION=3 THEN ($TYP : $A : $B : ‘$C’ : $NO : SPACE(16) : $F : $DT : $GH : SPACE(23) )ELSE ($TYP : $A : $B : ‘D’ : $NO : SPACE(61) : $D )
In mapper split the Iteration conditions into 4 columns with different names
And then make copy of data. map 1st iteration column to $RECORD column and follow the same for remaining 3 iteration conditions. The target column should be $RECORD for all 4 mappers.
After that I used union and capture the $RECORD column in mapper and finally Got the result.

koryknick
Employee
Employee

@sshaik - In the future, it would help the Community to provide you with answers if you could provide the expected input and output along with the type of logic description you have shown.

I’m glad you found a solution that works for you!

sshaik
New Contributor III

Iteration condition: IF @ITERATION=1 THEN ($TYP : $A : $B : ‘A’ : $C : SPACE(6) : $$CD : SPACE(17) )ELSE IF @ITERATION=2 THEN ($TYP : $A : $B : ‘B’ : $NO : $G : SPACE(31) )ELSE IF @ITERATION=3 THEN ($TYP : $A : $B : ‘$C’ : $NO : SPACE(16) : $F : $DT : $GH : SPACE(23) )ELSE ($TYP : $A : $B : ‘D’ : $NO : SPACE(61) : $D )

 

According to this iteration condition, we have to generate the values till to the last iteration i.e., iteration4 ($TYP: $A: $B : ‘D’ : $NO : SPACE(61) : $D ).

 

In mapper I’m getting the $A,$B,$C,$D FIELDS along with those columns need to add spaces ….

In a mapper I have spitted the expression into 4 parts like

ITERATION=1  $TYP : $A : $B : ‘A’ : $C : SPACE(6) : $CD : SPACE(17))   ---$LVRECORD1

ITERATION=2 ($TYP : $A : $B : ‘B’ : $NO : $G : SPACE(31) )   ---$LVRECORD2

ITERATION=3  ($TYP : $A : $B : ‘$C’ : $NO : SPACE(16) : $F : $DT : $GH : SPACE(23) )--- $LVRECORD3

ITERATION=4  ($TYP: $A: $B : ‘D’ : $NO : SPACE(61) : $D ). ) ---$LVRECORD4

In the next mapper

sshaik_0-1692858183018.png

 

Next mapper

sshaik_1-1692858183020.png

 

sshaik_2-1692858183021.png

 

Same for all the 4 source columns I have taken the target as $LVRECORD

Output:

ABCD                 CD                         A                                                                                   iteration1

ABCD                 NO         G                          A                                                                     iteration2

ABCD                 CD           F            DTGH                                               A                          iteration3

TYP                     ADNO                 CD                          A                                                       iteration4

 

 

mkadange
New Contributor

Hello,

I am new to Snaplogic, need your help.
I have a similar situation, where in
I have multiple country specific ethnicity columns with which I need to derive value into a single column.
e.g. race_hispanic, race_cuban, race_mexican etc. and one of the column will have 'yes' value which I need to pick and store it in ethnicity output column. along with this I have multiple other columns for which there is 1-1 mapping between input/output columns. but only for ethnicity alone, I will have many-1 columns.

How can I do this in mapper table in Snaplogic?

Thanks!

Mallikarjun