cancel
Showing results for 
Search instead for 
Did you mean: 

Help with UDF

Former Member
0 Kudos

Dear All,

  From Source i had a field 'SOURCE' and target side,there are two fields 'TARGETA' & 'TARGETB'

Now my requirement is,from source side the values comes like

:61:1303080308AF62942,N001NBN130670017//XX1362745739190

0001051/052013XXX/O1/

:61:1303080308AF92705,XXXXREF//001XXXX130670022

XXXXXXXREF00004198/052013

:61:1303080308BF111531,X001XXXX130670016//XX1362746022195

0001418/052013XXX/O1

:61:1303080308BF145868,X001XXXX130670016//XX1362746022195

0001418/052013XXX/O1

In the source value the fields which contains A after the date,then it should go to 'TARGETA' with total value i.e after F,if B comes means it should go to 'TARGETB' with all total value.

for e.g

in the above fields,we have two fields with A, so the total value 62942+92705=155647 should go to the TARGETA

similarly the with B, 111531+145868=257399.

for this how can we write UDF,please suggest me.

thanks & regards

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Raj,

             you can try this UDF

public void sumTotal(String[] a,String Type[], ResultList result,Container container)

{

    

  String sumA="",sumB="";

  int i,indexOfF,totalA=0,totalB=0;

  for(i=0;i<a.length;++i)

  {

        indexOfF=a[i].indexOf('F');

        if(indexOfF>0)

        {

              if(a[i].charAt(indexOfF-1)=='A')

              {

                    sumA=a[i].substring(indexOfF+1,a[i].indexOf(','));

                    totalA=totalA+ Integer.parseInt(sumA);

              }

        }

        if(indexOfF>0)

        {

              if(a[i].charAt(indexOfF-1)=='B')

              {

                    sumB=a[i].substring(indexOfF+1,a[i].indexOf(','));

                    totalB=totalB+ Integer.parseInt(sumB);

              }

        }

  }

  if(Type[0].equals("A"))

  {

       result.addValue(""+totalA);

  }

  if(Type[0].equals("B"))

  {

        result.addValue(""+totalB);

  }

   return;

}

Input to the UDF will be SOURCE and an constant with value "A" or "B";

Thus mapping will be like this

                             

SOURCE--------\

                       sumTotal--------------TARGETA

Constant("A")--/

SOURCE--------\

                       sumTotal--------------TARGETB

Constant("B")--/

Hope this resolves the problem.

Regards

Anupam

Former Member
0 Kudos

Hi Anupam,

   thank u for the response.

sorry for late response

the following error occurs when i test in IR

  Source text of object Message Mapping: MM_Bank | http://filetofile has syntax errors:

Source text of object Message Mapping: MM_Bank | http://filetofile has syntax errors:

Source code has syntax error: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java:266: cannot find symbol symbol : variable Type location: class com.sap.xi.tf._MM_Bank_ if(Type[0].equals("D")) ^ D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java:270: cannot find symbol symbol : variable Type location: class com.sap.xi.tf._MM_Bank_ if(Type[0].equals("C")) ^ Note: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 2 errors

  • Source code has syntax error:
    D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java:266: cannot find symbol
    symbol : variable Type
    location: class com.sap.xi.tf._MM_Bank_
    if(Type[0].equals("D"))
    ^
    D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java:270: cannot find symbol
    symbol : variable Type
    location: class com.sap.xi.tf._MM_Bank_
    if(Type[0].equals("C"))
    ^
    Note: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    2 errors

Also in your code i can see STRING TYPE[],but when i created its showing STRING [] TYPE.

please suggest me where i am doing mistake

Former Member
0 Kudos

Hello,

Small observation, variable name is "Type" not "TYPE"

Correct the same it will work.

Thanks

Amit Srivastava

anupam_ghosh2
Active Contributor
0 Kudos

Hi Raj,

            Could you please paste the screen shot of the UDF in PI server?

Please check if you have correctly mentioned the input parameter (spelling) to the mapping.

Regards

Anupam

Former Member
0 Kudos

Hi Anupam,

 

    thank for your response

Answers (3)

Answers (3)

iaki_vila
Active Contributor
0 Kudos

Hi Raj,

I assume in your requeriments that the string length to the F is constant and the number to comma with variable length.

You can do this mapping:

You need to specify a dynamic substring easily with this UDF:

public String dynamicSubstring(String stringToSub, int begin, int end, Container container) throws StreamTransformationException{

return stringToSub.substring(begin,end);

}

With targetfiedb you copy this schema and you change only the const A by B.

With your example i get:

Regards.

Former Member
0 Kudos

You don't necessarily need a UDF, standard mapping functions should be sufficient.

Text functions

- substring

- equalsS (compare to Constant 'A' or 'B')

Statistic functions

- sum

Former Member
0 Kudos

Hello,

The position of A and B in source value (currently i can see it as 15) is fixed or it can vary??

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

  thank u for response,

Position of A & B are fixed but the values which should be calculated after F ,its length is not fixed.

thanks

Raj

Former Member
0 Kudos

Hello,

Logic has already been provided to u by others so i don't have much to say...

Thanks

Amit Srivastava