• JAVA Functions in XI(转)


    JAVA Functions in XI
      1. Split Function  按字符分割成字符串数组

              String [ ] StrArray = LGORT.split(",") //-- pass LGORT to this UDF
              int len1 = LGORT.length;
              for ( i=0;i<len1;i++){ result.addValue(StrArray[i]); }

      2. Global Containers   全局参数
           2.1 To store values in global variable

              container.getGlobalContainer ().setParameter ("str", FIELDNAME);

           2.2 To get the value already stored in global variable.

              String myStr = (String) container.getGlobalContainer().getParameter ("str");

      3. RemoveLeadingZeros   删除前导零

              int value = Integer.parseInt(str);
              String str1 = Integer.toString(value) ;
              return str1;

             You can also use this code.

               Here a is input string.

                //write your code here
                String b = a.replaceFirst("^0+", "");
               return b;

      4. Unique Value     全局唯一值,一次mapping,run time

              String strLocal =
                   (String) container.getGlobalContainer().getParameter ("strGlobal");
              container.getGlobalContainer ().setParameter ("strGlobal", str);
              if (!str.equals(strLocal))
              return "1";
              else
              return "0"; 

      5. Credit/Debit using Substring      字符比较

              int i = str.length();
              String str1 = str.substring(i-1,i);
              if (str1.equals("-"))
              return "D";
              else
              return "K";         

    6. Capturing Input File name in output file   修改文本名,本blog有更详细的

               DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

               DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File" , "FileName");

              String Outputfile = conf.get(key,a); //ENABLE ASMA in Receiver File Channel
              return Outputfile;

    7. Remove Comma from string    查找替换

            Here 'a' is a input string.

            //write your code here
            String b = "";
            b = a.replaceAll(",", "");
           return b;

    8. Find Index of a word or sentence inside one sentence and get sub string starting from that index

    Fixed string to find in sentence coming from input "a". Result will contain that index no as start point of index in other sentence.

       //write your code here
    String  fixed = "ORDER OF"; //Fixed string to find in sentence coming from input "a". Result will contain that index no as start point of index in other sentence.
    String res = "";
    int index = 0;
    index = a.indexOf(fixed);
    res = b.substring(index+9,index+12);
    return res;

    9. Add New line in End of Each xml tag  

    xmlstring is input to this program.

       //write your code here
    String res = "";
    int flag = 0;
    for(int i = 0;i<xmlString.length();i++)
    {  if(xmlString.charAt =='<')  

    Unknown macro: {   flag = 1;   res = res + xmlString.charAt (i);   }

    else
    {   if(xmlString.charAt =='>')   

    Unknown macro: {    flag = 0;    res = res +xmlString.charAt (i) + "n";   }

      else

    Unknown macro: {    res = res +xmlString.charAt (i);    }

    }
    }

    return res;

    10. Displaying XMLString in single line into approriate XML format

    xmlString = xmlString.replaceALL("><","">\n<");

    11. Check if Integer

    try
    {
    int i=Integer.parseInt(input,10);
    return "Integer";
    }catch (NumberFormatException exception)
    {
    return "String";
    }

    12. Remove duplicates from list

       //write your code here  
    HashSet h = new HashSet();
    for (int i=0; i<a.length; i++)
    {      if (! h.contains(a[i]))    

    Unknown macro: {        h.add(a[i]);        result.addValue(a[i]);     }

    }

    http://wiki.sdn.sap.com/wiki/display/XI/JAVA+Functions+in+XI

    收藏

  • 相关阅读:
    'static' can indeed be used in C++ to create a Static Member Function
    关闭QQ2008迷你首页
    开机无法使用欢迎屏幕
    关于U盘”无法复制:磁盘被写保护…”的解决办法
    SQL企业管理器下servers组下无项目解决方法
    COM+应用程序错误8004E00F COM+ 无法与Microsoft 分布
    安装Ms SQL Server 2005 开发版时出现性能计数器要求安装错误的解决办法
    牛人教你这样用Google
    在K3凭证处理中的部份实用操作
    KIS7.5SP2迷你版、标准版在查询数量金额明细账时提示“发生未知错误,系统当前操作被取消,请与金蝶公司的技术支持机构联系”
  • 原文地址:https://www.cnblogs.com/byfhd/p/2154951.html
Copyright © 2020-2023  润新知