groovy code for date and time transfer
def String DateTransfer(String arg1){
// Define the input and output date formats
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd")
// Parse the input date string to a Date object
Date date = inputFormat.parse(arg1)
// Format the Date object to the desired output format
String outputDate = outputFormat.format(date)
return outputDate
}
import com.sap.it.api.mapping.*;
import java.text.SimpleDateFormat
def String TimeTransfer(String arg1){
// Define the input and output date formats
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
SimpleDateFormat outputFormat = new SimpleDateFormat("HHmmss")
// Parse the input date string to a Date object
Date date = inputFormat.parse(arg1)
// Format the Date object to the desired output format
String outputDate = outputFormat.format(date)
return outputDate
}
-----------
concate string.
def void customFunc(String[] input, Output output, MappingContext context) {
if (input != null && input.length > 0) {
// Initialize an empty string to accumulate the concatenated values
def result = ""
// Iterate through the input array
for (int i = 0; i < input.length; i++) {
// Append each element of the array to the result string, separated by a semicolon
result += input[i]
if (i < input.length - 1) {
result += ";"
}
}
// Add the concatenated string to the output
output.addValue(result)
}
}
------------
def void customFunc(String[] input, Output output, MappingContext context) {
if (input != null && input.length > 0) {
boolean found = false
// Iterate through the input array using a for loop
for (int i = 0; i < input.length; i++) {
// Check if the item equals 4
if (input[i].toInteger() == 4) {
found = true
break
}
}
// Add "1" to the output if any item equals 4
if (found) {
output.addValue("1")
} else {
output.addValue("")
}
} else {
// If input is null or empty, add an empty value to the output
output.addValue("")
}
}
--------
def void customFunc(String[] input, Output output, MappingContext context) {
if (input != null && input.length > 0) {
boolean found = false
// Iterate through the input array using a for loop
for (int i = 0; i < input.length; i++) {
// Check if the item equals 4
if (input[i].toInteger() == 4) {
found = true
break
}
}
// Add "1" to the output if any item equals 4
if (found) {
output.addValue("1")
} else {
output.addValue("")
}
} else {
// If input is null or empty, add an empty value to the output
output.addValue("")
}
}
----
----