cancel
Showing results for 
Search instead for 
Did you mean: 

Executing graphical mapping based on Java mapping in SAP PO7.4

Former Member
0 Kudos

Hi All,

I tried to follow the blog and I using NWDS Java editor to integrate my code with the given code as per the blog.

Code Details:

package com.sap.xi.tf.user.functions;

import com.sap.aii.mapping.api.*;

import com.sap.aii.mapping.lookup.*;

import com.sap.aii.mappingtool.tf7.rt.*;

import java.io.*;

import java.lang.reflect.*;

import java.util.*;

import com.sap.ide.esr.tools.mapping.core.Init;

import com.sap.ide.esr.tools.mapping.core.Cleanup;

import java.net.URL;

public class MM_JAVAANDGRAPHICALMAPPING  {

  InputAttachments inputAttachments; 

  InputHeader inputHeader; 

  InputParameters inputParameters; 

  DynamicConfiguration dynamicConfiguration; 

  OutputAttachments outputAttachments; 

  OutputHeader outputHeader; 

  OutputParameters outputParameters; 

  public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException{ 

   try 

   { 

   dynamicConfiguration = in.getDynamicConfiguration(); 

   inputAttachments = in.getInputAttachments(); 

   inputHeader = in.getInputHeader(); 

   inputParameters = in.getInputParameters(); 

   outputAttachments = out.getOutputAttachments(); 

   outputHeader = out.getOutputHeader(); 

   outputParameters = out.getOutputParameters(); 

   InputStream is = (InputStream) in.getInputPayload().getInputStream(); 

   /*

   * **************************** GuideLines for Java Mapping ********************************************************************

   * You can have java mapping code INLINE if it is few lines. And if it is a big and complex code, then I recommend to isolate

   * java mapping logic and develop it separately as a NORMAL java program. Import it as 'imported archive' and refer it in graphical mapping

   * And then call the externally developed public method here

   * Recommendation for external method signature: public ByteArrayOutputStream YourExtBussLogicMethod(InputStream is, ...)

   * **********************************************************************************************************************************

   */ 

   /*BEGIN ************************************************* PATTERN 1 (JM - GM) **************************************************/ 

   //Java Mapping: YourExtBussLogicMethod(is) code is nothing but your java mapping logic. You can also have INLINE code here 

//  ByteArrayOutputStream baos = YourExtBussLogicMethod(is); 

//  InputStream newInputStream = new ByteArrayInputStream(baos.toByteArray()); 

   //InputPayloadImpl payloadInObj = new InputPayloadImpl(newInputStream); 

  // TransformationInputImpl transformInObj = new TransformationInputImpl(payloadInObj); 

   //Graphical mapping called here

  

  

   //My Own Code - START

  

      String str_output_temp = new String();

      String str_ULR = new String("http://XYZ/export/currrate.xml");

      String str_URLResponse_temp = new String();

      String str_URLResponse_temp2 = new String();

      String str_output_temp1 = new String();

      String str_output_temp2 = new String();

      URL url_Response = new URL(str_ULR);

      BufferedReader br_input = new BufferedReader(new InputStreamReader(url_Response.openStream()));

      while((str_URLResponse_temp = br_input.readLine()) != null)

          str_URLResponse_temp2 = str_URLResponse_temp2 + str_URLResponse_temp;

      br_input.close();

      str_output_temp = str_URLResponse_temp2;

      out.getOutputPayload().getOutputStream().write(str_output_temp.getBytes());

  

   //My Own Code - END

  

   super.transform(transformInObj, out);    >---- Error

   /*END ************************************************* PATTERN 1 (JM - GM) **************************************************/

   } 

   catch (Exception e){ 

   throw new StreamTransformationException(e.getMessage()); 

   } 

  } 

  class InputPayloadImpl extends InputPayload{ 

   InputStream in; 

     public InputPayloadImpl(InputStream in){ 

   this.in = in; 

   } 

   @Override 

     public InputStream getInputStream(){ 

   return in; 

   } 

  } 

  class TransformationInputImpl extends TransformationInput{ 

   InputPayload payload; 

   public DynamicConfiguration getDynamicConfiguration(){ 

   return dynamicConfiguration; 

   } 

   public TransformationInputImpl(InputPayload payload){ 

   this.payload = payload; 

   } 

   @Override 

   public InputAttachments getInputAttachments(){ 

   return inputAttachments; 

   } 

   @Override 

   public InputHeader getInputHeader(){ 

   return inputHeader; 

   } 

   @Override 

   public InputParameters getInputParameters(){ 

   return inputParameters; 

   } 

   @Override 

   public InputPayload getInputPayload(){ 

   return payload; 

   } 

  } 

  class OutPayloadImpl extends OutputPayload { 

     OutputStream ou; 

     public OutPayloadImpl(OutputStream ou){ 

   this.ou = ou;} 

   @Override 

     public OutputStream getOutputStream(){ 

   return ou;} 

  } 

  class TransformationOutputImpl extends TransformationOutput { 

     OutputPayload payload; 

     public TransformationOutputImpl(OutputPayload payload){ 

   this.payload = payload; 

   } 

   @Override 

     public void copyInputAttachments(){ } 

   @Override 

     public OutputAttachments getOutputAttachments(){ 

   return outputAttachments; 

   } 

   @Override 

     public OutputHeader getOutputHeader(){ 

   return outputHeader; 

   } 

   @Override 

     public OutputParameters getOutputParameters() { 

   return outputParameters; 

   } 

   @Override 

     public OutputPayload getOutputPayload(){ 

   return payload; 

   } 

  } 

  

  @Init(description="")

  public void init (

  GlobalContainer container)  throws StreamTransformationException{

  }

  @Cleanup

  public void cleanup (

  GlobalContainer container)  throws StreamTransformationException{

  }

}

I am getting error at statement    super.transform(transformInObj, out); 

Could you advice with what details I need to create transformInObj because I would like to write my java code in the same code which will provide the xml structure retrieved from URL and the same will be provided as source to graphical mapping for further mapping with IDoc.


Thanks,

Dhill


Accepted Solutions (0)

Answers (3)

Answers (3)

former_member183816
Active Participant
0 Kudos

Step1. Need to call the http  and get the XML document.

Use java mapping to fetch XML. http://scn.sap.com/docs/DOC-53784

write your XML directly in output stream as given in above doc. It will be forward to Adapter for further processing.

Or

If you have different Email and IDoc structure. Follow this solution,

ESR:
create 3 Inbound service Interfaces
SI_CheckCndition          //Inbound
SI_IDoc                         //Inbound
SI_Email                       //Inbound 

Create 3 message mappings
MM_CheckCondition    // Message mapping to fetch XMl and check whether call IDoc or Email SI
MM_IDoc                     //To map IDoc
MM_Email                    // To map Email

Create 3 Operation Mappings


OM_Determinereceiver         // call MM_CheckCondition to check condition and determine receiver. Use SI_CheckCndition
OM_IDoc                               // call MM_CheckCondition to get XML then call MM_IDoc in order. Use SI_IDoc
OM_Email                             // call MM_CheckCondition to get XML then call MM_Email in order. Use SI_Email

ID:
Create Extended Receiver determination
http://help.sap.com/saphelp_nwpi711/helpdata/en/48/ce53aea0d7154ee10000000a421937/frameset.htm
Basically you have to use OM_Determinereceiver to determine receiver here

Create 2 Interface determination

one for receiver IDoc. Use OM_IDoc
one for receiver Email. Use OM_Email

former_member183816
Active Participant
0 Kudos

Step1. Need to call the http  and get the XML document.

Use java mapping to fetch XML. http://scn.sap.com/docs/DOC-53784

write your XML directly in output stream as given in above doc. It will be forward to Adapter for further processing.

former_member181985
Active Contributor
0 Kudos

Hi Senthil,

It's good to see a first comment to my blog here. Well, the concept doesn't work in NWDS (hence my blog title starts with ESR ) since, we get only a subset of graphical mapping java code separately which doesn't extend AMappingProgram class

In ESR graphical mapping although it doesn't show AMappingProgram class, but internally it will be considered when we compile and hence it works. May be you can try by extending AMappingProgram in NWDS but I am not sure what will be consequences of this. Please let us know the outcome

Thanks,

Praveen Gujjeti

Former Member
0 Kudos

Hi Praveen,

Thanks! Looks AMappingProgram doesn't exists when I tried to extend it with my class. Can you explain with an small snippet it would be great!

Dhill

former_member181985
Active Contributor
0 Kudos

It seems the eclipse plugin jar file com.sap.ide.esr.tools.mapping.jars_1.0.0.xxxxxxxxxxx.jar doesn't have the required package com.sap.aii.mappingtool.tf7.* class files and hence you are getting 'AMappingProgram doesn't exists'


You can try adding com.sap.xi.mapping.tool.lib_api.jar file in nwds classpath and then try to extend AMappingProgram class by adding import com.sap.aii.mappingtool.tf7.*  statement


you can download com.sap.xi.mapping.tool.lib_api.jar file from browser by pointing to your xi system host and port as,


http://<xiserver>:port/rep/repository/com.sap.xi.mapping.tool.lib_api.jar


//BR,

Praveen Gujjeti

Former Member
0 Kudos

Hi Praveen,

Stuck with production issue! I would like to go inline with your blog and pasted the same code in ESR at Attributes and Methods section..

Getting the below error

Since I writing the code directly in the same place what I need to pass for transformInObj. Please advice.

Thanks,

Dhill

former_member181985
Active Contributor
0 Kudos

Hi,

I am not clear about your requirement from your code within Pattern1. I could only understand that you are trying to read some response from web (HTTP) resource. Do you want to call your actual graphical mapping using that http response?

Please explain your requirement and you can get better solutions from forum experts

//BR,

Praveen Gujjeti

Former Member
0 Kudos

Hi Praveen,

Step1. Need to call the http  and get the XML document.

Step2. check if is update for today's date if yes send a idoc to ECC if no send a mail to user

Currently the http call is being done using java mapping and then graphical mapping called to map the xml document with IDoc or mail structure.

Hope this helps! Let me know if any more details required.

Thanks,

Dhill

former_member181985
Active Contributor
0 Kudos

Hi,

First of all, I am not clear what is your source/sender system(trigger) for your scenario and what adapter you are using for sender and what you will be doing with source system data, since you haven't mentioned anything about sender system. The reason I am saying is that, you can use HTTP sender adapter with HTTP GET method to read http resource response and then transform for IDOC or email based on your requirement condition.

Explain the complete flow

//BR,

Praveen Gujjeti