cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping logic required-UDF

Former Member
0 Kudos

Hi,

My sender structure is as follows

<zaction>(1:1)

--Trans

<Zcode>(0:999)

--Code

--Id

My target field is

<code>(0:999)

--ID

My requirement is

if code= CE,CB,CH,CJ,CI,CO then don't create target field ID.

else

if code=AF and Trans=01 then ID=axv0001

or

if code=AF and Trans=02 then ID=axv0002

if none of the above conditions matches pass ID received from sender.

I am confused at using context type UDF. As suppress result is completely supressing the target field. it's not looking into the rest of logic. Can you provide me an appropraite UDF for this logic please.

TIA,

Mahesh

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You can use this context type UDF:


Arguments: inTrans
inCode
inID

for(int a=0;a<inCode.length;a++){
	if(inCode[a].equals("CE")|inCode[a].equals("CB")|inCode[a].equals("CH")|inCode[a].equals("CJ")|inCode[a].equals("CI")|inCode[a].equals("CO")){
		result.addSuppress();
	}
	else if(inCode[a].equals("AF")&inTrans[0].equals("01")){
		result.addValue("axv0001");
	}
	else if(inCode[a].equals("AF")&inTrans[0].equals("02")){
		result.addValue("axv0002");
	}
	else{
		result.addValue(inID[a]);
	}
}

Logic is like this:

For code


Trans -> removeContext -> \
Code --> removeContext -> UDF -> code
ID ----> removeContext -> /

For ID


Trans -> removeContext -> \
Code --> removeContext -> UDF -> splitByValue:eachValue -> ID
ID -----> removeContext -> /

Hope this helps,

Mark

Edited by: Mark Dihiansan on Nov 9, 2011 3:47 AM

Former Member
0 Kudos

Hi mark,

thanks it was helpful. Only one change i required is field Id is not mandatory. It may not come sometimes. So when i tested with a data witout the 3rd input parameter . The code returned error. How to handle this?

Former Member
0 Kudos

Use mapWithDefault with Marks logic. Such as

Trans -> removeContext -> \
Code --> removeContext -> UDF -> splitByValue:eachValue -> ID
ID ----->mapWithDefault-----> removeContext -> /

Regards

Raj

Former Member
0 Kudos

Hi Raj,

MapwithDefault creates the field on target side with empty value. I dont want the field to be created if it's not coming from sender side.

Thanks,

Former Member
0 Kudos

Thanks i changed the code myself. Solved.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Raj is right, you need to use mapWithDefault


Trans -> removeContext ----------------------------------> \
Code --> removeContext ----------------------------------> UDF -> splitByValue:eachValue -> ID
ID ----->mapWithDefault:Suppressed------> removeContext -> / 

You just need a little tweaking from the UDF to control the output


Arguments: inTrans
inCode
inID
 
for(int a=0;a<inCode.length;a++){
	if(inCode[a].equals("CE")|inCode[a].equals("CB")|inCode[a].equals("CH")|inCode[a].equals("CJ")|inCode[a].equals("CI")|inCode[a].equals("CO")){
		result.addSuppress();
	}
	else if(inCode[a].equals("AF")&inTrans[0].equals("01")){
		result.addValue("axv0001");
	}
	else if(inCode[a].equals("AF")&inTrans[0].equals("02")){
		result.addValue("axv0002");
	}
	else{
		if(inID[a].equals("Suppressed")){
                result.addSuppress();
                }
                else{
                result.addValue(inID[a]);
                }
	}
}

Hope this helps,

Mark

Answers (1)

Answers (1)

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

as i can see, you can solve you requirement ussing a UDF but also ussing standard functions.

for example you know the rigths codes. so you can do this:

change the context of <Code> to the nameof your message Type > rigth click> context-->MT_XXX

once you did it use the Equals function (Text group) and compear with 'AF':


<Code>---------------Equals---->And----->Trans-->Equals-------IF(true)---->axv0001
AF(constant)---------                                 01------>                      (false)---> Trans-->Equals--->ifWithOutElse-->axv0002
                                                                                02---->