Use scripts variables in inline Java code

For mappings created in the Business Integration Converter (BIC) at times you need local or global procedures following the DRY principles in coding (Don't repeat yourself)
Maybe you need to enhance the BIC script by adding some inline Java code like shown in eg the unescapeHTML  procedure found on these pages

It can be parameters in procedure signature or local variables, in the unescapeHTML procedure we can find this code

// Procedure parameter used in java code
String source = _StrVar_PSOURCE.getString();

You can find a lot of examples of this style of Java code in your build folders, in <source>\<project>\build\test\com\seeburger\jucon\mapping you can examine the Java files from your recent build

An example

// Java code example assigning an IDOC numer to a numeric variable
_NumVar_IDOC_NUMBER.setNum(stdin.getField("THIS:DOCNUM"));

Another small example which uses Java variables described is the getUUID method

You can find some examples on this site: Methods using inline Java

 

 

 

 

 

getCurrentYear

An utility to retrieve current year

This is a procedure to use in Seeburger BIC Mapping Designer

/*  -----------------------------
    Peter Lykkegaard, 25 apr 2023
    -----------------------------
    procedure getUUID
  
    Parameters:
        None
    Output
        String
    Get ramdom UUID
    ----------------------------- */
 
#importJavaStart
    import java.util.UUID;
#importJavaEnd

local 
    lvOutput$;

#javastart
    _StrVar_LVOUTPUT.setString(UUID.randomUUID().toString());
#javaend

exitProc(lvOutput$);

 

Get current date time in UTC RFC 3339 format

An utility to format current datetime as a UTC string according to RFC 3339

A procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling

  • Get current date / time with time zone (system default)
  • Format output
// -----------------------------
// Peter Lykkegaard, 30 okt 2024
// -----------------------------
// procedure getCurrentDateTimeUTC
// Parameters: None
//     Get current date / time
//     Format as String in UTC RFC 3339 format (eg 2022-10-13T23:37:18+02:00)
// Output
//    alphanumeric / String 
// Ref: https://medium.easyread.co/understanding-about-rfc-3339-for-datetime-formatting-in-software-engineering-940aa5d5f68a

#importJavaStart
    import java.time.format.DateTimeFormatter;
    import java.time.OffsetDateTime;
#importJavaEnd

local output$;

#javaStart
    String output;

    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
    OffsetDateTime now = OffsetDateTime.now();
    output = dtf.format(now);

    _StrVar_OUTPUT.setString(output);
#javaEnd

exitProc(output$);

Same but with inout parameters

  • Concatenate parameters
  • Parse string
  • Add system default time zone
  • Format output
// -----------------------------
// Peter Lykkegaard, 24 okt 2024
// -----------------------------
// procedure getCurrentDateTimeUTC
// Parameters: None
//     Parse given date / time from IDOC
//     Format expected is yyyyMMdd / HHmmss
//     Format as String in UTC RFC 3339 format (eg 2022-10-13T23:37:18+02:00)
// Params
//    Date$:    Alphanyumeric 
//    Time$:    Alphanyumeric
// Output
//    alphanumeric / String 
// Ref: https://medium.easyread.co/understanding-about-rfc-3339-for-datetime-formatting-in-software-engineering-940aa5d5f68a
 
#importJavaStart
    import java.time.*;
    import java.time.format.DateTimeFormatter;
    import java.time.OffsetDateTime;
#importJavaEnd

local output$;

#javaStart
    String documentDate = _StrVar_DATE.getString();
    String documentTime = _StrVar_TIME.getString();

    String output;

    String localDateTimePattern = "yyyyMMddHHmmss";
    String offsetDataTimePattern = "yyyy-MM-dd'T'HH:mm:ssXXX";

    String documentDateTime = documentDate + documentTime;

    DateTimeFormatter dtf;
    
    dtf = DateTimeFormatter.ofPattern(localDateTimePattern); 
    LocalDateTime dateTime = LocalDateTime.parse(documentDateTime, dtf);  
    
    ZoneId zoneId = ZoneId.systemDefault();
    OffsetDateTime odt = ZonedDateTime.of(dateTime, zoneId).toOffsetDateTime();
    
    dtf = DateTimeFormatter.ofPattern(offsetDataTimePattern);  
    output = dtf.format(odt);

    _StrVar_OUTPUT.setString(output);
#javaEnd
 
exitProc(output$);

 

UnZeroFill

An utility to remove leading zeros from a string 

A procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling

//    -----------------------------
//    Peter Lykkegaard, 18 april 2020
//    -----------------------------
//    Remove leading zeros
 
//    TODO! Check parameters if they are of valid type/content
//
//    Name: unZeroFill
//    Description:
//    Parameters
//        input$, alphanumerical / String which have leading zeros removed
//        Output, alphanumeric / String without leading zeros

local output$;

#javaStart
    String output = _StrVar_INPUT.getString();
    // Only if numeric remove leading zeros
    if (output.matches("\\d+"))
    {
        output = output.replaceFirst("^0+(?!$)", "");
    }
    _StrVar_OUTPUT.setString(output);
#javaEnd

exitProc(output$);

 

Split string

An utility to split a string based on an character 

A procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling

//    -----------------------------
//    Peter Lykkegaard, 22 mar 2019
//    -----------------------------
//    Split string into its sub components based input characters

//    TODO! Check paramteters if they are of valid type/content
//
//    Name: splitString
//    Description: 
//    Parameters
//        input$, alphanumerical / String which needs to be split
//        criteria$, alphanumerical / Character to split
//    Output, alphanumeric / array / Array of strings to return

local output$[];

#javastart

    final String input = _StrVar_INPUT.getString();
    final String criteria = _StrVar_CRITERIA.getString();

    String[] data;

    if ((criteria == "-") || (criteria == "+") || (criteria == "|"))
    {
        data = input.split("\\" + criteria + "|\\*|\\/");
    }
    else
    {
        data = input.split(criteria, 0);
    }
    
    int idx = 0;

    for (int i = 0; i < data.length; i++) 
    { 
        _StrVar_OUTPUT.getJuVar(idx, 2).setString(data[i]);
        idx++;
    }

#javaEnd
    
exitProc(output$);