cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to create a empty value if No field exists in the source message

Former Member
0 Kudos

Hi All,

I want to generate a empty value when the source field is missing ( UDF code is required). In the below example P19 segment is unbounded. IDNT file may or may not occur. When the IDNT file is not existing in the source idoc, I want to have as empty value in the output

I have an input structure as

IDOC

PO1 u2013 Parent Segment

P19 u2013 child segment

Qual u2013 field 1

IDNT u2013 field 2

Target structure as

PO1

D34 u2013 field name

I want to add a empty value when there is no IDNT field in the source structure. For example

<PO1> u2013 Parent Segment

<P19> u2013 child segment

<Qual> 001 <\Qual>

<IDNT> ATN <\IDNT>

<\P19>

<P19> u2013 child segment

<Qual> 002 <\Qual>

<\P19>

<P19> u2013 child segment

<Qual> 003 <\Qual>

<IDNT> ATN 3<\IDNT>

<\P19>

</PO1>

Output should be

<PO1>

<D34> ATN </D34>

<D34> </D34>

<D34> ATN3 </D34>

</PO1>

Can some help me to write a udf for this requirement?

Thanks in advance.

Regards

Sarkar

Accepted Solutions (1)

Accepted Solutions (1)

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

Use mapwith default and pass an empty value.

Regards

Priyanka

Former Member
0 Kudos

Hi,

Thanks for your response.

if use mapwithdefault with PO1 as context, it is not showing up any empty value. because there is atleast one field by that name.

but i want to add the empty value at context level.

i.e. ATN

[]

ATN3

Regards

Sarkar

Former Member
0 Kudos

dont change the context of IDNT field...

IDNTmapwithdefault-removecontext---target

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

Please follow the below logic.write a simple udf with execution type all values of queue.

idnt-->mapwithdefault[a]-->addEmptyValue-->remove context->D34

public void addemptyvalue(String[] var1, ResultList result, Container container) throws StreamTransformationException{

for(int i=0;i<var1.length;i++){

if(var1<i> == "a");

result.addValue(" ");

else

result.addValue(var1<i>);

}

}

Thanks

Priyanka

Former Member
0 Kudos

Use Remove Context after Map with default.

Regards,

Gouri

Former Member
0 Kudos

Hi Priyanka,

This will result either a empty value or values which IDNT has. But i am looking to add empty value at right context.

Let me explain, Lets say i have 4 IDNT in 4 PO1 segments and third PO1 segment is not having the IDNT field, then the udf should result as

IDNT1

IDNT2

[]

IDN4

UDF which you provided either result ONLY [] or

IDNT1

IDNT2

IDNT4.

My requiremtn is to get the [] value after IDNT2 value.

I hope iam clear.

thanks again .

Regards

Sarak

Former Member
0 Kudos

did u check the mapping replied above??



IDNT--mapwithdefault---removecontext---target 
 

Former Member
0 Kudos

Hi Amit,

I did check and its not working.

If the context is P19 then I get the empty value but when I change the context to PO1 the empty value is not coming up.

I want the empty value at PO1 level.

Thanks.

Regards

Sarakar

Former Member
0 Kudos

>>Lets say i have 4 IDNT in 4 PO1 segments

by looking ur query it seems that u are having multiple PO1 as well as multiple P19 segments???

If yes then do ur mapping like this:



P01 ---> P01



IDNT---Mapwithdefault---
               ------------formatby example-----D34
P19---------------------

Input:

<PO1>

<P19>

<IDNT> ATN1<\IDNT>

<\P19>

<P19>

<\P19>

<P19>

<IDNT> ATN 3<\IDNT>

<\P19>

</PO1>

<PO1>

<P19>

<IDNT>ATN4<\IDNT>

<\P19>

<IDNT>ATN5<\IDNT>

<P19>

<\P19>

<P19>

<\P19>

</PO1>

ur output will be something like this:

<PO1>

<D34>ATN1</D34>

<D34> </D34>

<D34> ATN3 </D34>

</PO1>

<PO1>

<D34>ATN4 </D34>

<D34>ATN5 </D34>

<D34> </D34>

</PO1>

Former Member
0 Kudos

Hi Amit,

Excellent. Issue is solved.

Thank You ver much. i have given the full points.

Regards

Sarkar.

Answers (0)