Tracing Errors and Messages 

Use

To create a log file that traces errors that occur when you use the IDoc Connector for XML component with your application, you use the ITrace object.

You can use this log file to communicate problems to SAP support regarding the use of the component.

You can also log errors that occur within your application into the same file.

Procedure

To log IDoc Connector for XML errors:

  1. Instantiate the ITrace object.
  2. Set the TraceLevel property of the ITrace object.
  3. The TraceLevel property uses an enumerated type, with the following values:

    Trace Level

    Constant

    Meaning

    0

    NOMESG

    Nothing is traced

    1

    ERRMESG

    Only errors are traced

    2

    MESG

    Both errors and informational messages are traced

    Notice that using trace level 2 includes both messages and errors.

  4. Open the log file with the OpenFile method of the ITrace object, specifying the full path of the log file.
  5. Assign the ITrace object to the Trace property of the SAPIDocProcessorOutbound object.

To log errors within your application to the same log file:

  1. Get the name of the log file using the filename property of the ITrace object.
  2. Set the TraceLevel property to the desired level.
  3. Depending on the trace level you have set, when error or message occurs, use the appropriate Write method to log the error or message to the file:

If you specify trace level…

You can use…

1 or 2

either WriteErrMsg (without a timestamp)

or WriteErrMsgTime (with a timestamp)

2

either WriteMsg or WriteMsgTime

Notice that if you specify trace level 2, both errors and messages are traced, and therefore you can use both WriteErrMsg and WriteMsg to log both errors and messages. However, when you specify trace level 1, only errors are traced, so using WriteMsg or WriteMsgTime does not result in any log entry.

Example

The following example logs both errors and messages that occur when using the IDoc Connector for XML component:

Dim oTrace As New ITrace
oTrace.FileOpen("C:\temp\log1.txt")
oTrace.TraceLevel = 2
Set idoc.Trace = oTrace