UDF for padding zeroes

Hi
I need a UDF Code for the following requirement ,which is used in various fields across a lot of mappings
Requirement is that if it is a fixed length file and the field length is 10 then whatever value thats coming should be right alligned and there shud be zeroes padded to the left of it
for e.g
field length is 10
input value os 3456
then the output should be 0000003456
I want to make it a generic function wher i can take the field length and the input value as inputs
Dev

Hi,
You can edit my function. What you can do is send the length as one input and then it should work. Add this code:
Create a value udf with two input arguments a and input. Then add this code:
Imports:  java.*;
int len=input.length();
int b = Integer.parseInt(a);
for(int i=0; i<b-len;i++)
input="0"+input;
return input;
Here pass the total length of the field in first argument and then send the input value to teh second argument. Then it should work for you.
Regards,
---Satish

Similar Messages

  • UDF for leading zero's in message mapping

    Dear team,
    I need UDF for leading zero's in my message mapping.
    Source and Target both structures contains matnr field.But we have to maintain total 18 chars at target matnr , because RFC in R/3 needed.So I want to add leading zero's when mapping. Can anybody provide the UDF code.
    Matnr[source]--->split by value(eachvalue) ->UDF->Matnr[Target]
    Ex::if source matnr conatains value "9846538" ; I need matnr value at target side like "000000000009846538"[total 18 chars].
    -Drumi

    Hi Ambrish,
    Good day...
    I have enterd what you said and I got below error... and I gave "input" in place of var1, 18 in place of filedlenght in below program...
    =================================
    int len = Integer.parseInt(18);
    int inputLength = input.length();
    try {
    Integer.parseInt(input);
    // If it is an integer, add 0 (len - inputLength) times
    for (int i=0; i< len-inputLength;i++)
        input = "0" + input;
    return input;
    } catch (NumberFormatException numForEx) {
    // return as it is, if alphanumeric
    return input;
    ====================================
    ERROR:
    Source text of object Message Mapping: Lubrisur_SHPMNT_SHPMNT05_TO_WMMBXY_WMMBID02_TransferPosting | urn:bp:xi:dwn:lu:common:Logistics:100 has syntax errors:
    Function LeadingZeros, Line 1:
    cannot find symbol symbol  : method parseInt(int) location: class java.lang.Integer int len = Integer.parseInt(18);                  ^ 1 error
    =======================
    Please suggest

  • Padded zeros which is removed need to be replaced by spaces

    Hi Friends,
    My requirement in XI is : Padded zeros which is removed need to be replaced by spaces.
    for removing padded zeros I used the UDF:
    int i = Integer.parseInt(a);
    return (Integer.toString(i));
    It is working fine.
    Please help as how to go abt in coding : whatever zeros get taken off , need to be replaced with spaces.
    Thanks in Advance,
    Meghna.

    Hi Raj,
    According to the logic given by Henrique, its working. But the point to the noted is that :
    The number of spaces need to be equal to the number of zeros removed, where it not happening in this case.for the below Ex when applied it returned '  12345' instead of '    12345'.
    For ex. source field is '000012345' then the target field need to be '    12345'.
    the Type declared in the data type for the receiver field is integer with length 15.
    Is it possible to move the field value to the right justified, so the the padded zeros code when applied will automatically load spaces.Becoz the code written for removing zeros contains String due to which it is left justified i think.
    The code written for removing zeros is :
    int i = Integer.parseInt(a);
    return (Integer.toString(i));
    please suggest in this regard.
    Regards,
    Meghna.
    Edited by: meghna swaraj on Feb 27, 2008 6:05 PM

  • Purchase Order Row UDF for Received Qty

    Hi experts,
    Can someone please recommend a way to create a row UDF for purchase orders to show the qty received? We cannot use a simple calculation like Qty-Open Qty because if the row is closed manually, the open qty becomes zero. Another problem is how to prompt the PO to update this value if additional GR PO's or AP Invoices are created. Thanks.

    I should explain the circumstances more clearly. There is no problem with the standard GR PO or AP invoice receiving method. What I want is a reference field on the original PO showing the total qty received to date. For example: total of 1,000 pcs ordered -> 900 pcs received against several GR PO's -> want to see that 900 has been received back on the PO. Then let's say we want to close the PO line 100 pcs short.
    I can think of 2 ways to go about this:
    Method 1: Change the ordered qty from 1,000 to 900 -> row is closed, but lose the reference of the original order qty being 1,000.
    Method 2: Close row manually and maintain the original order qty as reference, but lose b/o qty and it is difficult to tell how many pcs where received/closed short.
    Is there another way to keep all the reference information?

  • UDF for replacing special or junk characters

    Hi
    Is there any stanard function for replacing any junk characters with zero? If not, I needed UDF for fulfilling this requirement.
    My requirment is .... Am sending some files to r/3 using XI. In the source(txt file) some time some fields have some junk characters. I must make it to zero, the field which has junk. How can I acheive it? is there any UDF using which I can fulfill my requiremnt.
    Thanks.

    Hi,
    Use this UDF
    Here a is the input value.
    String b = "";
    b = a.replaceAll(",", "0");
    b = a.replaceAll("@", "0");
    Like all the special characters you can take and replace with zero.
    return b;
    Or
    Use the regular expression to check whether special characters occurs in the string then replace with zero
    http://www.j2ee.me/developer/technicalArticles/releases/1.4regex/
    Regards
    Ramesh.

  • Create UDF for table not in the List of tables

    Hi all,
    I know that my question maybe easy or been asked before, but I couldn't find the answer.
    To create a UDF in SAP B1 version 9.0 you should go Tools -> Customization Tools -> User-Defined Fields - Management...
    which is ok and working perfect. but my question is:
    If I want to create UDF for a table not in the list of tables there what should I do? I need to create 2 UDFs for table OMRC [Manufacturers], and can't find it in master data tables.
    anyone had this issue before?
    EDIT  : Is it good to add the field by using sql server? I know it's possible, but will it be visible in SAP
    thank you
    Message was edited by: Samira Haroun

    Hi Samira,
    There is noit a simple link for this, I advise you to study the documentation for TB1300 SBO Development Certification.
    Ypu should also have knowledge of .net, and C# or VB, because you have to make a small program/addon to add the fields
    Kind regards
    Ad Kerremans

  • UDF For Retrieving the Tax Code based on PO

    Hi all,
    Mine is a file to Idoc scenario.
    I wrote a FM to retrieve the Tax Code based on PO .
    Created the udf which directly gets the Taxcode from the r/3 with out importing in to the imported objects,is this correct i never tried this before.
    Find the UDF for the Same.
    final String    CHANNEL_NAME = "GeneratedReceiverChannel_RFC",
         VALNOTFOUND = "VALUE_NOT_FOUND",
         SAPRFCNS = "urn:sap-com:document:sap:rfc:functions",
         TAG_FM = "Z_P_INT012_RFC_LOOKUP",
         TAG_TAX_CODE = "T_TAX_CODE",
         TAG_TAX_CODE_P = "TAX_CODE";
    AbstractTrace trace = container.getTrace();
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              DocumentBuilder builder = null;
              factory.setNamespaceAware(false);
              factory.setValidating(false);
              try {
                   builder = factory.newDocumentBuilder();
              } catch (Exception e) {
                   trace.addWarning("Error creating DocumentBuilder - " + e.getMessage());
              Document docReq = null;
              try {
                   // Building up RFC Request Document
                   docReq = builder.newDocument();
                   Node root = docReq.appendChild(docReq.createElementNS(SAPRFCNS, TAG_FM));
                   Node nodeTbOpt = root.appendChild(docReq.createElement(TAG_TAX_CODE));
                   for (int i = 0; i < pernr.length; i++) {
                        Node nodeTbOptItem = nodeTbOpt.appendChild(docReq.createElement("item"));
                        nodeTbOptItem.appendChild(docReq.createElement(TAG_TAX_CODE_P)).appendChild(docReq.createTextNode(TAX_CODE<i>));
              } catch (Exception e) {
                   trace.addWarning("Error while building RFC Request  - " + e);
              trace.addInfo("RFC Request XML: " + docReq.toString());
                                                    //trace.addWarning("RFC Request XML: " + docReq.toString());
              // Lookup
              Payload load = null;
              try {
                   Channel channel = LookupService.getChannel(receiver[0], CHANNEL_NAME);
                   RfcAccessor accessor = LookupService.getRfcAccessor(channel);
                   InputStream is = new ByteArrayInputStream(docReq.toString().getBytes());
                   XmlPayload payload = LookupService.getXmlPayload(is);
                   load = accessor.call(payload);
              } catch (LookupException e) {
                   trace.addWarning("Error during lookup - " + e);
              // Parsing RFC Response Document
              Document docRsp = null;
              try {
                   docRsp = builder.parse(load.getContent());
              } catch (Exception e) {
                   trace.addWarning("Error when parsing RFC Response - " + e.getMessage());
              trace.addInfo("RFC Response XML: " + docRsp.toString());
                                                    //trace.addWarning("RFC Response XML: " + docRsp.toString());
              try {
                   NodeList res = docRsp.getElementsByTagName("item");
                   for(int i=0;i<res.getLength();i++){
                        NodeList itemNodes = res.item(i).getChildNodes();
                        Map itemMap = new HashMap();
                        for(int j=0;j<itemNodes.getLength();j++){
                             itemMap.put(itemNodes.item(j).getNodeName(), itemNodes.item(j).getFirstChild().getNodeValue());
                        rows.add(itemMap);
                                                            catch (Exception e) {
                   trace.addWarning("Result value not found in DOM - " + e);
                   result.addValue("true");
    Error:
    16:24:08 Start of test
    Source code has syntax error:  /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:598: 'class' or 'interface' expected public void TaxValues$(String[] a,String[] b,ResultList result,Container container){ ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:618: 'class' or 'interface' expected } ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:619: 'class' or 'interface' expected ^ 3 errors  Source code has syntax error:  /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:598: 'class' or 'interface' expected public void TaxValues$(String[] a,String[] b,ResultList result,Container container){ ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:618: 'class' or 'interface' expected } ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:619: 'class' or 'interface' expected ^ 3 errors
    16:24:11 End of test.

    Hi Potharaju,
    Why don't you try this, that really works:
    If you are using PI 7.1:
    http://help.sap.com/saphelp_nwpi71/helpdata/en/33/1ec6ced273493a993a80c2301c03da/frameset.htm
    If you are using XI 3.0, PI 7.0
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1b439
    Try with these.
    Regards,
    Juan

  • UDF for JDBC lookup in PI 71

    I am facing some issue while importing the SQL meta-data from db2 in PI 7.1 , guess the db2 version is old and not compatible with 7.1 or could be problem with drivers, I want to go head with writing UDF for the jdbc lookup, can you please let me know  the code and how it can be written or blogs, thanks

    >>> can you please let me know the code and how it can be written or blogs, thanks
    You can try this link if you dont want to use graphical jdbc lookup... Follow this link , it has code to use ...
    /people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
    Also refer these links
    For 7.0 -  http://scn.sap.com/people/william.li/blog/2007/03/30/using-jdbc-connection-pool-in-xi-message-mapping
    For 7.1 http://scn.sap.com/people/jin.shin/blog/2008/02/15/sap-pi-71-mapping-enhancements-series-graphical-support-for-jdbc-and-rfc-lookups

  • Query to Lookup Ship To in a UDF for the Inventory Transfer

    Good Day Experts!
    I created a UDF for the Ship To Code in the Inventory Transfer Window.  The problem is I do not know how to create a query to be used in the Formatted Search for this UDF wherein it will lookup all the Ship To Codes in the table CRD1 of that particular  Customer selected in the Inventory Transfer window.  The objective is to choose a Ship to code just like in the sales document.
    My next problem would be how to display automatically the whole Ship To Address in another UDF based on the Ship To Code chosen in the UDF Ship To Code.
    Your inputs would be highly appreciated.
    Regards,
    Jen

    To get the Complete ShipTO Address, use the following Code
    SELECT T0.cardname+CHAR(13)+isnull(T0.Address,'')+CHAR(13)+
    cast(T0.Building as varchar(100))+CHAR(13)+isnull(T0.city,'')+CHAR(13)
    +isnull(T0.zipcode,'') as Address FROM CRD1 T0
    WHERE T0.CardCode =$[OWTR.CardCode] and  T0.cardtype='S' and
    T0.Address=$[OWTR.UDF1]
    Here Replace UDF1 with the Name of the UDF in which Shipto Address Names are shown as per my previous post.
    Hope you understand

  • Need code for padding (spacing) 5 navigation links in my #topnavbar internal style

    need code for padding (spacing) 5 navigation links in my #topnavbar internal style

    I'm new at this and the below code is regarding the navigation bar and links
    I started using a template to create the first html page and made copies of it to create the other four.
    All the links work but I wanted to space them apart further.
    They look basically like this horizontally: Home About Us Photo Gallery Services Contact Us
    #topnavbar {
    text-align:center;
    #topnavbar a:link a:visited{
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 100%;
    font-weight: bold;
    color: #039;
    text-decoration: none;
    margin: 0 25px:
    #topnavbar a:hover a:active {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 100%;
    font-weight: bold;
    color: #039;
    text-decoration: none;
          <div id="topnavbar">
          <nav>
          <p><a href="index.html">Home</a>  
             <a href="aboutus.html">About Us</a>  
             <a href="photogallery.html">Photo Gallery</a>
             <a href="services.html">Services</a>
             <a href="contactus.html">Contact Us</a></p>  
          </nav>
           </div>

  • Reg: UDF for removing values after decimals

    HI,
      Please help me on the below issue,
      I need an UDF for the follwing requirement,
    as my input value is 12354.12354875 then the result will be like 12345.123,
    After deceimal it should get only 3 values.
    Please help me points will be awarded.
    Edited by: UDAY on Apr 5, 2010 3:56 PM

    >
    UDAY wrote:
    > yes its needed to be truncated only not rounded.
    In that case even the standard function FormatNum can also help.
    Regards,
    Abhishek.

  • UDF for Changing File Name

    Hi Experts,
    I am working on one scenrio, where i am fetching the file name dynamically by adapter module.
    Now, the file name needs to be checked for the following conditions:
    BOOKING_REF_DELIVERYNO_WB.pdf
    BOOKING_REF_DELIVERYNO_BOLCOPY.PDF
    DELIVERYNO_AWB.PDF
    Depending upon the type of file being picked up by PI from the mail box,following needs to be done:
    1.time stamp needs to be added ..
    ex..
    for file SO10162239_123_458_BOLCOPY.pdf--> the file name must be changed to :
    SO10162239_X2100_20101206_123_458_BOLCOPY.pdf.
    Please suggest if this can be done by graphical mapping ?
    Thanks,
    Sushama

    hi,
    I am using following UDF..
    FileName->ParseFile>getNykFilename>concat--
    Current date->                                                                   concat> Trim> FileName
                               concat----
    |
    constatnt[.pdf]--->
    UDF for parse file:
    String[] sarray;
    String regex = "\"";
    String retstring;
    String fname;
    int l= raw.length();
    try {
         sarray = raw.split(regex, 3);
         retstring = sarray[1];
                            fname=sarray[l-1];
            if( fname=="WB")
    raw.concat("_X2100_");
    else if (fname=="BOLCOPY")
    raw.concat("_X2101_");
    else if (fname=="AWB")
    raw.concat("_X2102_");
    } catch (Exception e) {
         retstring = "no_att_name_found.err";
    return retstring;
    UDF for getNykFileName:
    String[] sarray;
    String regex = "[_]";
    String retstring;
    if(!orgName.endsWith(".err")){
    try {
         sarray = orgName.split(regex, 3);
         retstring = sarray[0];
    } catch (Exception e) {
         retstring = "nyk_filename.err";
    return retstring;
    }else{
         return orgName;
    But, its not working..
    Its giving the file name as:
    no_att_name_found.err20101206 for the input file : 801243209_81473641_wb.pdf
    Display queue result for parsefileName:
    "no_att_name_found.err"
    Please suggest.
    Thanks,
    Suahama

  • UDF  for this mapping rule

    Hi Friends,
         I have one difficult issue which have one mapping rule to write user defined function. I am sending mapping rule Please give me java coding to create udf for this mapping rule which is following below:
    CRFT.COSTR = M_ORD_01 and
    CRFT.CRID = CRHE.CRID and
    CRFV.FTNO = CRFT.FTNO and
    CRFV.ATNAM = ZPPI_ORDER_SCHED_EN_DATE
    And
    CRFT.COSTR = M_ORD_01 and
    CRFT.CRID = CRHE.CRID and
    CRFV.FTNO = CRFT.FTNO and
    CRFV.ATNAM = ZPPI_ORDER_SCHED_EN_TIME
    From ATWRT of ZPPI_ORDER_SCHED_EN DATE+ ATWRT of ZPPIORDER_SCHED_EN_TIME
    In format yyyy-MM-ddTHH:mm:ss
    using this mapping rule, ATWART field can map with target field "End Time" i think.
    Actually source field is CALCULATE but this field is not in Source structure
    target field is "End Time"  this field is in Target Structure.
    I will wait for ur response
    Thanks adn regards
    Sai

    Hi Jagadish,
    This RFC is CONTROL_RECIPE_DOWNLOAD
    in this RFC, i want to map ATWRT field to Target field "End Time" with mapping rule which i had already given.
    In Graphical mapping, i am doing . but i can not get it because mapping condition is difficult. if you have any idea in graphical mapping give me early
    before that i have to give explantion about this is  date value and time value passed through this ATWRT field as different records.
    i am doing as a condition ie  first i have taken date condition. from that condition, first two fields  CRFT.COSTER and M_ORD_01 has given to "equals" funtion     like that have done remaining fileds then the output of those "equals" functions given to "and" functions finally i get one output of "and" function.  while sending DATE values from RFC this output  of "and " function.
    Like this, for Time condtion i have done mapping same way and giving a TIME values from RFC as Second record then output of this "and" function while sending second record with time value.
    here mainly i am getting problem is .....
    here i am taking source field ATWRT( in this field i am sending date format adn time format as different records) with the outputs of the mapping conditons as input vaules of another function. i dont have any idea for another function why because is first date record should be wait until the time record comes in this function.after then both vaules should concat .
    now here whenever you send date value through this field ATWRT as first record and after satishfy the date condition form mapping rule,  The date value of ATWRT should go to input of concat function. next i will send time value like date value through ATWRT as second record . It should go to another input of concat function. Then here both date value and time value concat with T  and should be come output in the format  yyyy-MM-ddTHH:mm:ss and this will go to Target field "End Time".
    I will be wait for ur possitive reply
    thanks for giving response
    Thanks adn regards
    sai

  • UDF for file to IDoc.

    Hi,
    I could like to create an UDF for file to IDoc secenario.
    Srouce:
    MTCashPosting_
    Header
    CashPosting
    PubDiv
    DocType
    DocDate
    PostDate
    RefDocNo
    HeaderTxt
    Customer
    Value
    Currency
    ExchangeRate
    Ledger
    Item
    Material
    TaxValue
    VAtValue
    Trailer
    Traget: (IDOC Type: FIDCCP02 Message Type: FIDCC2)
    FIDCCP02
    IDoc (Under FIDCCP02)
    Begin (Under IDoc)
    EDIDC40_:DISABLED
    E1FIKPF (Under IDoc)
    E1FISEG (Under E1FIKPF)
    Segment
    buzei
    bschl
    shkzg
    mwskz
    dmbtr
    hkont
    matnr
    "The secenario is the 'Value,TaxVAlue & VatValue' should be handled by replicating E1FISEG like (HAve used External definition for IDoc)"
    Value -> Line item 1
    IF TaxValue exists->Line Item 2
    IF VatValue exists-> Line item 3
    Finally Line item 4 for cerdit.All above are debit
    Value____________UDF______________E1FISEG
    TaxValue_________|
    VatValue_________|
    Value____________UDF______________DMBTR
    TaxValue_________|
    VatValue_________|
    How should I map?? Inputs plzzzzz

    Hi
    I am not sure whether my understanding is correct.
    As per my understanding
    You need to duplicate E1F1SEG segment 4 times as there are 4 conditions
    and those nodes need to be enabled or suppressed based on your condition .
    Regards
    sandeep

  • UDF for Special Character Conversion

    Hello All,
    Can any one help me with the UDF for special character conversion code.
    I mean if a special character is given it should pass a blankspace.
    << Moderator message - Everyone's problem is important >>
    Many thanks,
    Rahul.
    Edited by: Rob Burbank on Oct 29, 2010 4:32 PM

    Hi Rahul ,
    the best way to deal with special character is to use proper encoding in your Sender Communication channel it self .So that in your payload you will get proper value .
    IF you are getting some special character which is not covered in encoding UTF-8 thne you can use encoding IS0-8859-1 .You can easily refer in help that how to use encoding in your communication channel .
    Regards,
    Saurabh

Maybe you are looking for

  • Apple Remote Desktop and Bluetooth

    Hi, does anyone know if Apple Remote Desktop can be connected between two computers over a bluetooth equipped Mac computers. Thank you very much.

  • Auto recovery in Excel failing

    Hi guys. My finance team uses many s'sheets encompassing pivot tables, macros, charts etc.  Many of these are in the region of 70Mb in size. The auto recovery process on one of my guy's laptop seems to fail causing the program to freeze and recovery

  • 4s turn off suddenly while using

    my 4s will turn off suddenly while using ,and i have to hit home and power button same time to turn on the iphone.it happens every two days,and sometimes twice a day.is it a hardware problem?

  • Smart Brush Tool - Not working

    I can't use the smart brush tool (either for blue skies, whiten teeth etc.).  The following message comes up when I select the brush:  COULD NOT USE THE SMART BRUSH TOOL BECAUSE NO ADJUSTMENT WAS SELECTED.  Is this an installation issue? Note: when I

  • Can you advice us where is the service center in Saudi Arabia – Jeddah

    Good Morning i would like to know that where is your service center located in JEDDAH ( Saudi Arabia ) thanks Mohamed Rizwan Marzook Mob : +966 502748923