cancel
Showing results for 
Search instead for 
Did you mean: 

JAVA Mapping: Write to trace

Former Member
0 Kudos

Hi everybody,

how can I write into trace in java mapping.

final AbstractTrace trace = null;
trace.addInfo("test Trace");		

causes a null-pointer exception

Thanks regards

Mario

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos

> Hi everybody,

>

> how can I write into trace in java mapping.

>

>

final AbstractTrace trace = null;
> trace.addInfo("test Trace");		

> causes a null-pointer exception

>

> Thanks regards

> Mario

http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm

refer the sample code in the sap help link.

You will get an idea then

Shabarish_Nair
Active Contributor
0 Kudos

also my understanding is you cannot test the trace when you test the mapping in the development environment like NWDS.

The traces work only in XI environment. So if you are getting it while an independent test it will cause issues.

Former Member
0 Kudos

Hi,

I still get the nullPointer

Regards

Mario

Edited by: Mario Müller on Apr 22, 2009 3:49 AM

Shabarish_Nair
Active Contributor
0 Kudos

did you see the sample code in the link i had posted?

instead of final the line should be

private AbstractTrace  trace = null;

Former Member
0 Kudos

Hi all,

we got it.

You have to override/add new method:

	/***************************************************************************
	 * private class MyTrace extends AbstractTrace {
	 **************************************************************************/
	private class MyTrace extends AbstractTrace {

		@Override
		public void addInfo(String arg0) {
			System.out.println(arg0);
		}

		@Override
		public void addWarning(String arg0) {
			System.out.println(arg0);
		}
	}//private class MyTrace extends AbstractTrace

In the main-method, that is used for local tests, you have to add:

(Info: InputStream_2_OutputStream is the name of the class)

		InputStream_2_OutputStream mapping = new InputStream_2_OutputStream();
		HashMap map = new HashMap();
		map.put(StreamTransformationConstants.MAPPING_TRACE, mapping.new MyTrace());
		
		mapping.setParameter(map);

If I have time, I will blog this.

Regards Mario

jagdishwar_b
Active Participant
0 Kudos

I dont think you really have to override addInfo() addWarning methods etc.

below are the steps to use AbstractTrace Object in Java Mapping



...
// import the AbstractTrace object
import com.sap.aii.mapping.api.AbstractTrace;

...
//create object reference variables
private AbstractTrace trace = null;
private Map map = null;

//initialize the map object of the current mapping using setParameter
public void setParameter (Map param) {
	this.map = param;
}
...

//get the AbstractTrace object into the trace object.
trace = (AbstractTrace)map.get( StreamTransformationConstants.MAPPING_TRACE );

//use the trace ojbect.
trace.addInfo("the info to be printed");

Answers (1)

Answers (1)

former_member181985
Active Contributor
0 Kudos

Try this,

private AbstractTrace trace = null;
trace = (AbstractTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo("test Trace");