Class JCoHelper


  • public class JCoHelper
    extends java.lang.Object
    Convenience class for the management of JCo. The implementation of JCo is sometimes a little bit low level for the purposes of the internet sales application. Because of this the JCoHelper class provides some helper classes and convenience methods to simplify the handling of JCo and especially its data structures.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JCoHelper.RecordWrapper
      Wraps around a JCo record and decorates the record with convenient methods to set the record's data.
      static class  JCoHelper.ReturnValue
      Represents the data returned by a call to the function module.
    • Constructor Summary

      Constructors 
      Constructor Description
      JCoHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean getBoolean​(com.sap.conn.jco.JCoField field)
      Converts the ABAP logic for booleans, "" = false, "X" = true into a Java boolean.
      static boolean getBoolean​(com.sap.conn.jco.JCoRecord record, java.lang.String field)
      Converts the ABAP logic for booleans, "" = false, "X" = true into a Java boolean.
      static boolean getBoolean​(java.lang.String string)
      Converts the ABAP logic for booleans, "" = false, "X" = true into a Java boolean.
      static java.util.Date getDate​(com.sap.conn.jco.JCoRecord record, java.lang.String field)
      Returns the specified field of a JCo record converted to a date.
      static java.lang.String getExceptionGroupAsString​(com.sap.conn.jco.JCoException jcoEx)
      Returns the group of the JCOException as a String.
      static java.lang.String getString​(com.sap.conn.jco.JCoRecord record, java.lang.String field)
      Returns the specified field of a JCo record converted to a string.
      static java.lang.String getStringFromNUMC​(com.sap.conn.jco.JCoRecord record, java.lang.String field)
      Converts an ABAP NUMC data type to an String which means it's trims all leading zeros.
      static java.lang.String getStringFromRaw​(com.sap.conn.jco.JCoRecord record, java.lang.String field)
      Returns the specified raw field of a JCo record converted to a string.
      static java.lang.String getStringPerfOpt​(com.sap.conn.jco.JCoRecord jcoRecord, java.lang.String arg0)
      This methods avoids creation of independent copies of "" in order to save memory.
      static TechKey getTechKey​(com.sap.conn.jco.JCoRecord record, java.lang.String field)
      Converts a technical key stored in a JCo record into an object of type TechKey.
      static TechKey getTechKeyFromRaw​(com.sap.conn.jco.JCoRecord record, java.lang.String field)
      Converts a technical key stored in a JCo record as raw value into an object of type TechKey.
      static java.lang.String lFillStr​(java.lang.String src, java.lang.String filler, int len)
      Helper for String-formatting Returns a String filled up to the left with filler up to the length len.
      protected static void logCall​(java.lang.String functionName, com.sap.conn.jco.JCoRecord input, com.sap.conn.jco.JCoRecord output)
      Logs a RFC-call into the log file of the application.
      static void logCall​(java.lang.String functionName, com.sap.conn.jco.JCoRecord input, com.sap.conn.jco.JCoRecord output, org.apache.log4j.Logger log)
      Logs a RFC-call into the log file of the application.
      protected static void logCall​(java.lang.String functionName, com.sap.conn.jco.JCoTable input, com.sap.conn.jco.JCoTable output)
      Logs a RFC-call into the log file of the application.
      static void logCall​(java.lang.String functionName, com.sap.conn.jco.JCoTable input, com.sap.conn.jco.JCoTable output, Log4JWrapper log)
      Logs a RFC-call into the log file of the application.
      protected static void logCall​(java.lang.String functionName, JCoHelper.RecordWrapper input, JCoHelper.RecordWrapper output)
      Logs a RFC-call into the log file of the application.
      static void logCall​(java.lang.String functionName, JCoHelper.RecordWrapper input, JCoHelper.RecordWrapper output, org.apache.log4j.Logger log)
      Logs a RFC-call into the log file of the application.
      static void logCall​(java.lang.String functionName, java.lang.String marker, com.sap.conn.jco.JCoTable table, java.lang.String[] obfuscatedColumns, org.apache.log4j.Logger log)
      Logs a RFC-call into the log file of the application.
      protected static void logException​(java.lang.String functionName, com.sap.conn.jco.JCoException ex)
      Log an exception with level ERROR.
      static java.lang.String obfuscate​(java.lang.String value)
      Obfuscate string value.
      static void setValue​(com.sap.conn.jco.JCoRecord record, boolean value, java.lang.String field)
      Sets the given field of the JCo structure to the provided value.
      static void setValue​(com.sap.conn.jco.JCoRecord record, double value, java.lang.String field)
      Sets the given field of the JCo structure to the provided value.
      static void setValue​(com.sap.conn.jco.JCoRecord record, int value, java.lang.String field)
      Sets the given field of the JCo structure to the provided value.
      static void setValue​(com.sap.conn.jco.JCoRecord record, TechKey value, java.lang.String field)
      Sets the given field of the JCo structure to the provided value.
      static void setValue​(com.sap.conn.jco.JCoRecord record, java.lang.String value, java.lang.String field)
      Sets the given field of the JCo structure to the provided value.
      static void setValueAsRaw​(com.sap.conn.jco.JCoRecord record, TechKey value, java.lang.String field)
      Sets the given string field of the JCo structure to the provided value as Raw, that means the value is converted into a byte Array.
      static void setValueAsRaw​(com.sap.conn.jco.JCoRecord record, java.lang.String value, java.lang.String field)
      Sets the given string field of the JCo structure to the provided value as Raw, that means the value is converted into a byte Array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JCoHelper

        public JCoHelper()
    • Method Detail

      • lFillStr

        public static java.lang.String lFillStr​(java.lang.String src,
                                                java.lang.String filler,
                                                int len)
        Helper for String-formatting Returns a String filled up to the left with filler up to the length len.
        Parameters:
        src - the source
        filler - the filler
        len - the length
        Returns:
        newStr
      • getExceptionGroupAsString

        public static java.lang.String getExceptionGroupAsString​(com.sap.conn.jco.JCoException jcoEx)
        Returns the group of the JCOException as a String.
        Parameters:
        jcoEx - the JCO exception
        Returns:
        string describing the group of the exception
      • getBoolean

        public static boolean getBoolean​(java.lang.String string)
        Converts the ABAP logic for booleans, "" = false, "X" = true into a Java boolean. Instead of using this method, you may want to use the Wrapper class. The use of this method is only helpful, if you want to convert a limited amount of fields, mostly booleans.
        Parameters:
        string - String to be converted into a boolean
        Returns:
        false if the string is empty, otherwise true.
      • getBoolean

        public static boolean getBoolean​(com.sap.conn.jco.JCoField field)
        Converts the ABAP logic for booleans, "" = false, "X" = true into a Java boolean. Instead of using this method, you may want to use the Wrapper class. The use of this method is only helpful, if you want to convert a limited amount of fields, mostly booleans.
        Parameters:
        field - JCO.Field to be converted into a boolean
        Returns:
        false if the string is empty, otherwise true.
      • getBoolean

        public static boolean getBoolean​(com.sap.conn.jco.JCoRecord record,
                                         java.lang.String field)
        Converts the ABAP logic for booleans, "" = false, "X" = true into a Java boolean. Instead of using this method, you may want to use the Wrapper class. The use of this method is only helpful, if you want to convert a limited amount of fields, mostly booleans.
        Parameters:
        record - JCO.Record containing the column to be converted into a boolean
        field - Name of the column to be converted
        Returns:
        false if the string is empty, otherwise true.
      • getString

        public static java.lang.String getString​(com.sap.conn.jco.JCoRecord record,
                                                 java.lang.String field)
        Returns the specified field of a JCo record converted to a string.
        Parameters:
        record - JCO.Record containing the column to be converted into a String
        field - Name of the column to be converted
        Returns:
        The value as String
      • getStringFromRaw

        public static java.lang.String getStringFromRaw​(com.sap.conn.jco.JCoRecord record,
                                                        java.lang.String field)
        Returns the specified raw field of a JCo record converted to a string.
        Parameters:
        record - JCO.Record containing the column to be converted into a String
        field - Name of the column to be converted
        Returns:
        The value as String
      • getDate

        public static java.util.Date getDate​(com.sap.conn.jco.JCoRecord record,
                                             java.lang.String field)
        Returns the specified field of a JCo record converted to a date.
        Parameters:
        record - JCO.Record containing the column to be converted into a Date
        field - Name of the column to be converted
        Returns:
        The value as Date
      • getTechKey

        public static TechKey getTechKey​(com.sap.conn.jco.JCoRecord record,
                                         java.lang.String field)
        Converts a technical key stored in a JCo record into an object of type TechKey. The use of this method is only helpful, if you want to convert a limited amount of fields, mostly booleans.
        Parameters:
        record - JCO.Record containing the column to be converted into a technical key. If this parameter is null the method returns null
        field - Name of the column to be converted
        Returns:
        a technical key for the specified column.
      • getTechKeyFromRaw

        public static TechKey getTechKeyFromRaw​(com.sap.conn.jco.JCoRecord record,
                                                java.lang.String field)
        Converts a technical key stored in a JCo record as raw value into an object of type TechKey. T
        Parameters:
        record - JCO.Record containing the column to be converted into a technical key. If this parameter is null the method returns null
        field - Name of the column to be converted
        Returns:
        a technical key for the specified column.
      • setValue

        public static void setValue​(com.sap.conn.jco.JCoRecord record,
                                    int value,
                                    java.lang.String field)
        Sets the given field of the JCo structure to the provided value.
        Parameters:
        record - The JCo record to work with
        value - Value to be set
        field - JCo field to be filled with the value
      • setValue

        public static void setValue​(com.sap.conn.jco.JCoRecord record,
                                    java.lang.String value,
                                    java.lang.String field)
        Sets the given field of the JCo structure to the provided value.
        Parameters:
        record - The JCo record to work with
        value - Value to be set
        field - JCo field to be filled with the value
      • setValueAsRaw

        public static void setValueAsRaw​(com.sap.conn.jco.JCoRecord record,
                                         java.lang.String value,
                                         java.lang.String field)
        Sets the given string field of the JCo structure to the provided value as Raw, that means the value is converted into a byte Array.
        Parameters:
        record - The JCo record to work with
        value - Value to be set
        field - JCo field to be filled with the value
      • setValue

        public static void setValue​(com.sap.conn.jco.JCoRecord record,
                                    double value,
                                    java.lang.String field)
        Sets the given field of the JCo structure to the provided value.
        Parameters:
        record - The JCo record to work with
        value - Value to be set
        field - JCo field to be filled with the value
      • setValue

        public static void setValue​(com.sap.conn.jco.JCoRecord record,
                                    boolean value,
                                    java.lang.String field)
        Sets the given field of the JCo structure to the provided value.
        Parameters:
        record - The JCo record to work with
        value - Value to be set
        field - JCo field to be filled with the value
      • setValue

        public static void setValue​(com.sap.conn.jco.JCoRecord record,
                                    TechKey value,
                                    java.lang.String field)
        Sets the given field of the JCo structure to the provided value. If the provided tech key is null nothing is done and the method returns immediately.
        Parameters:
        record - The JCo record to work with
        value - Value to be set
        field - JCo field to be filled with the value
      • setValueAsRaw

        public static void setValueAsRaw​(com.sap.conn.jco.JCoRecord record,
                                         TechKey value,
                                         java.lang.String field)
        Sets the given string field of the JCo structure to the provided value as Raw, that means the value is converted into a byte Array. If the provided tech key is null nothing is done and the method returns immediately.
        Parameters:
        record - The JCo record to work with
        value - Value to be set
        field - JCo field to be filled with the value
      • getStringFromNUMC

        public static java.lang.String getStringFromNUMC​(com.sap.conn.jco.JCoRecord record,
                                                         java.lang.String field)
        Converts an ABAP NUMC data type to an String which means it's trims all leading zeros.
        Parameters:
        record - the JCo record to extract field from
        field - the name of the field that should be extracted from the record
        Returns:
        the trimed string
      • logCall

        public static void logCall​(java.lang.String functionName,
                                   com.sap.conn.jco.JCoRecord input,
                                   com.sap.conn.jco.JCoRecord output,
                                   org.apache.log4j.Logger log)
        Logs a RFC-call into the log file of the application.
        Parameters:
        functionName - the name of the JCo function that was executed
        input - input data for the function module. You may set this parameter to null if you don't have any data to be logged.
        output - output data for the function module. You may set this parameter to null if you don't have any data to be logged.
        log - the logging context to be used
      • logCall

        public static void logCall​(java.lang.String functionName,
                                   JCoHelper.RecordWrapper input,
                                   JCoHelper.RecordWrapper output,
                                   org.apache.log4j.Logger log)
        Logs a RFC-call into the log file of the application.
        Parameters:
        functionName - the name of the JCo function that was executed
        input - input data for the function module. You may set this parameter to null if you don't have any data to be logged.
        output - output data for the function module. You may set this parameter to null if you don't have any data to be logged.
        log - the logging context to be used
      • logCall

        public static void logCall​(java.lang.String functionName,
                                   com.sap.conn.jco.JCoTable input,
                                   com.sap.conn.jco.JCoTable output,
                                   Log4JWrapper log)
        Logs a RFC-call into the log file of the application.
        Parameters:
        functionName - the name of the JCo function that was executed
        input - input data for the function module. You may set this parameter to null if you don't have any data to be logged.
        output - output data for the function module. You may set this parameter to null if you don't have any data to be logged.
        log - the logging context to be used
      • logCall

        protected static void logCall​(java.lang.String functionName,
                                      com.sap.conn.jco.JCoRecord input,
                                      com.sap.conn.jco.JCoRecord output)
        Logs a RFC-call into the log file of the application.
        Parameters:
        functionName - the function name to be logged
        input - input record
        output - output record
      • logCall

        protected static void logCall​(java.lang.String functionName,
                                      JCoHelper.RecordWrapper input,
                                      JCoHelper.RecordWrapper output)
        Logs a RFC-call into the log file of the application.
        Parameters:
        functionName - the function name to be logged
        input - input record wrapper
        output - output record wrapper
      • logCall

        protected static void logCall​(java.lang.String functionName,
                                      com.sap.conn.jco.JCoTable input,
                                      com.sap.conn.jco.JCoTable output)
        Logs a RFC-call into the log file of the application.
        Parameters:
        functionName - the function name to be logged
        input - input JCo table
        output - output JCo table
      • logException

        protected static void logException​(java.lang.String functionName,
                                           com.sap.conn.jco.JCoException ex)
        Log an exception with level ERROR.
        Parameters:
        functionName - the function name to be logged
        ex - the Exception to be logged
      • getStringPerfOpt

        public static java.lang.String getStringPerfOpt​(com.sap.conn.jco.JCoRecord jcoRecord,
                                                        java.lang.String arg0)
        This methods avoids creation of independent copies of "" in order to save memory.
        Parameters:
        jcoRecord - the JCo record
        arg0 - argument
        Returns:
        result
      • obfuscate

        public static java.lang.String obfuscate​(java.lang.String value)
        Obfuscate string value. String is replaced with a list of "*".
        Parameters:
        value - the value to be obfuscated
        Returns:
        obfuscated value
      • logCall

        public static void logCall​(java.lang.String functionName,
                                   java.lang.String marker,
                                   com.sap.conn.jco.JCoTable table,
                                   java.lang.String[] obfuscatedColumns,
                                   org.apache.log4j.Logger log)
        Logs a RFC-call into the log file of the application.
        Parameters:
        functionName - the name of the JCo function that was executed
        marker - textual maker to identify a particular logging
        table - input data for the function module. You may set this parameter to null if you don't have any data to be logged.
        obfuscatedColumns - columns, values of this columns will be obfuscated
        log - the logging context to be used