cancel
Showing results for 
Search instead for 
Did you mean: 

udf for exists

Former Member
0 Kudos

I have to concat 14 Idoc text fields into a string at a varying position. Mostly some of the fields are not assigned, a normal concat does not work(no output if one field is missing). I created a workaround with the exists function (graphical) which is about 25 meter long (my colleague imediately started to cry). It works but it is ugly.

Does anybody know how the exists function works. If one of the IDoc fields is missing I do not get <b>any</b> output of my udf whatever I do inside. How can I change this.

Regards, Thomas

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thomas,

You can handle the absence of values in two ways.

1. Using <b>MapWithDefault</b> Standard function.

Field1- MapWithDefault(Default value single space)-> 
    							->Concat/UDF -> TargetField
    Field2- MapWithDefault(Default value single space)->

2. In UDF check for SUPPRESS value like this:

public String UDF_Name(String StrVal1,String StrVal2,Container container){
          if((!StrVal1.equals(ResultList.SUPPRESS)) && (!StrVal1.equals(ResultList.SUPPRESS))  ){
              //concat...
          }
  
}

Hope this helps.

Regards,

Ananth

Former Member
0 Kudos

Hi Ananth,

thank you for the tip. My mapping is a one page mapping now

Answers (3)

Answers (3)

bhavesh_kantilal
Active Contributor
0 Kudos

Thomas,

<b>Use MAPWITHDEFAULT</b> .

<i>Source Fields --> MAPWITHDEFAULT --> CONCAT.</i>

MAPWITHDEFAULT will allow you to give a default value if the field is not found in the source.

Map with default --> EXISTS + DEFAULT VALUE.

Regards,

Bhavesh

Former Member
0 Kudos

Hi Bhavesh,

thank you. MapWithDefault works much better than exists.

Regards,

Thomas

Former Member
0 Kudos

hi thomas,

U can use a alternative method. U can write 2 UDFs. One for concatinating the strings as u require.

The other one takes the inputs as the 14 fields with a "exists" function in front of them. So in the UDF u can check whether the values are "true" or "false". If atleast one is false then u can return "false" from the second UDF.

Give the output of two UDF's to an if - then - else function to get the required correct mapping.

This is just a work around.

Hope this helps.

Regards,

P.Venkat

Former Member
0 Kudos

Hi P.Venkat,

that should work. Thank you. I did it with MapWithDefault with a bit less of udf coding. But: how can I solve this without standard function? How works exists.

Regards,

Thomas

Former Member
0 Kudos

Hi Thomas,

AFAIK, <b>Exists</b> checks for existance of a value within a context change else produces a <b>False</b> value.

Internally it uses ContextChange marker and SUPPRESS marker to identify the existance of a value within a context change.

Regards,

Ananth

former_member206604
Active Contributor
0 Kudos

Hi,

You can do the same exist functionality inside the UDF using this syntax

if(a.equals(null)) --> the value does not exist.

Thanks,

Prakash

Former Member
0 Kudos

Hi Prakash,

that was the first I tried. But it does not work. In fact my udf does not do anything if "a" is not delivered. I still cannot determine if "a" is delivered.

A good question is how function Exists or MapWithDefault works on the inside. How is it possible they process anything. How can I copy or modify them.

Regards,

Thomas