ankur udf code in groovy

 





import com.sap.it.api.mapping.*;


/*Add MappingContext parameter to read or set headers and properties

def String customFunc1(String P1,String P2,MappingContext context) {

         String value1 = context.getHeader(P1);

         String value2 = context.getProperty(P2);

         return value1+value2;

}


Add Output parameter to assign the output value.

def void custFunc2(String[] is,String[] ps, Output output, MappingContext context) {

        String value1 = context.getHeader(is[0]);

        String value2 = context.getProperty(ps[0]);

        output.addValue(value1);

        output.addValue(value2);

}*/




def String lastEightDigits(String AUFNR) {

    // Check if the length of AUFNR is greater than 8

    if (AUFNR.length() > 8) {

        // Take the last 8 characters

        AUFNR = AUFNR.substring(AUFNR.length() - 8)

    }

    // Return the processed AUFNR

    return AUFNR

}



def String Increment(String counter) {

    // Convert the string to an integer

    int countInt = Integer.parseInt(counter)

    

    // Increment the integer

    countInt++

    

    // Convert back to string

    String sequence_num = Integer.toString(countInt)

    

    // Return the sequence number

    return sequence_num

}



def String gramToKG(String weight) {

    // Initialize grams as empty string

    def grams = ""


    // Check if the first character is a space

    if (weight.charAt(0) == ' ') {

        // Extract substring up to the last space

        grams = weight.substring(0, weight.lastIndexOf(" "))

    }


    // Convert the weight string to double

    double wtgm = Double.parseDouble(weight)


    // Create DecimalFormat with pattern

    def df = new java.text.DecimalFormat("#########0.000000000")


    // Convert grams to kilograms

    double wtkg = wtgm / 1000


    // Format the weight

    String value = df.format(wtkg)


    // Concatenate and return

    return grams + value

}



def String DigigramToKG(String weight) {

    // Initialize digigram as empty

    def digigram = ""


    // Check if the first character is a space

    if (weight.charAt(0) == ' ') {

        // Extract substring up to the last space

        digigram = weight.substring(0, weight.lastIndexOf(" "))

    }


    // Convert the weight string to double

    double wtdgm = Double.parseDouble(weight)


    // Create DecimalFormat with pattern

    def df = new java.text.DecimalFormat("#########0.000000000")


    // Convert digigrams to kilograms

    double wtkg = wtdgm / 10000


    // Format the weight

    String value = df.format(wtkg)


    // Concatenate and return

    return digigram + value

}

Popular posts from this blog

SAP CPI : camle expression in sap cpi , cm, router, filter and groovy script. format

SAP CPI camel conditions and xpath conditions

oauth call to cpi integraiton suite from sap apim