SAP PO for Beginners Part – 14 – Introduction to Java Mapping with Examples in SAP PO – Part – 1

This blog will serve as an introduction to Java Mapping with Examples in SAP PO, helping you learn how to write, validate, and export Java mappings using SAP NWDS software.

So, underneath is the substance we will be intricate in this instructional exercise:

  • Overview
  • JAVA PROGRAM -1 – Copy the contents from input to output file
  • Import Java Mapping libraries
  • Write a simple Java Program on copy the contents from input to output file
  • Compile Java Program
  • Extracting as JAR file
  • Import JAR file and test run Operation Mapping
  • JAVA PROGRAM -2 – Copy the contents from input to output by reading line-by-line
  • JAVA PROGRAM – 3 – Adding traces to java program on copying contents

1. Overview:

Here, we will foster java programs in NWDS programming, approve it and product it as a Container record for bringing in it in ESR vault as a Java Planning document in Activity Planning. Java Planning is a Java based program that is written in NWDS Manager with Java Planning Libraries and afterward transferred in the ESR. Java Planning is elective way to deal with composing Graphical Message Planning/XSLT Planning.

We should get everything rolling.

2. JAVA PROGRAM – 1 – Copy the contents from input to output file:

Prior to continuing with the production of Java Undertaking, one need to arrangement NWDS programming with the JAVA JDK document. Allude to the arrangement present on NWDS on PI:

Click on Document – > NEW – > Java Task

Give a substantial Undertaking name. Under JRE, select “Use project explicit JRE – JDK 1.8” and click on Straightaway and FINISH.

You can see under the work area; new envelope will be made with project name as organizer name.

Within it contains two primary envelopes, Src and Container organizer which holds the source code and receptacle organizer contains the class document once you characterize new class.

To make another class, Right snap on the venture name – > New – > Class

Class name will be same as undertaking name. Tick “public static void primary”. When done, this is the manner by which starter format seems to be.

3. Import Java Mapping libraries

Whenever you have made the Java Task, subsequent stage is to add the Java Planning Libraries to your venture. For that, right snap on the .java document – > Fabricate Way – > Arrange Assemble Way

Under libraries tab – > click on Add Outside Containers button and import the java planning library records. Click on Apply and Save.

For our sap java planning point of view, we are including those Container records. Once imported, you can see those records in the venture sheet – > Referred to libraries.

4. Write a simple Java program on copy the contents from input to output file

Presently we will compose a basic Java Program which will peruse the items in the information document or from the info field and duplicate for what it’s worth to yield record or result field.

First thing we need to do is, broaden the class Conceptual change. This class is the expansion of the planning program that you as of now have is important for graphical planning. As you are utilizing dynamic strategy, we really want to abrogate the change technique.

@Override
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
	try{
	  execute(arg0.getInputPayload().getInputStream(),arg1.getOutputPayload().getOutputStream());
	}
       catch(Exception ee){

          throw new StreamTransformationException(ee.toString());
	}
}

The principal strategy that will be executed by PI is the change technique at runtime. This change technique will call the execute as displayed in the code above. We should characterize the execute public technique.

The explanation EXCEUTE technique is added is for In reverse Similarity. If you have any desire to run this code in XI framework, then execute is the technique which it anticipates. Thus, we are including it. It’s in every case great to compose the code in attempt and catch block to get the exemptions and showing it in logs.

public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
	try{
	   int buffer;  
           // variable for holding the copied contents
	   while((buffer = in.read()) != -1) { 
           // checking if chars reached end of line
	   out.write(buffer);
	   }
	out.flush();
	}

        catch(Exception ee)
       {
         throw new StreamTransformationException(ee.toString());
       }
}

Then, we will focus on adding contents in principal technique.

public static void main(String[] args) {
	try{
	   FileInputStream fin = new FileInputStream("inputFile.txt");
	   FileOutputStream fout = new FileOutputStream("outputFile.txt");
			
	   JM_FirstJavaMapping instance = new JM_FirstJavaMapping();
	   instance.execute(fin, fout);
// passing the input file as IN to execute method and performing operations in execute method. Same way output filename is also passed for writing the copied contents.
	}
        catch(Exception ee)
        {
	  ee.printStackTrace();
	}
}

IMPORT STATEMENTS OF LIBRARIES/PACKAGES:

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;

5. Compile Java Program:

While in Java document, in the menu bar, click on Run – > Run. Remember to put the inputFile.txt with some example contents put on it.

As we haven’t referenced the way of the document where it is situated in the java code, it will default get set in the work area organizer.

Java Program is working fine.

GITHUB REPO:

6. Exporting as JAR file:

For transferring the .container document to Drain PO ESB, we really want to get the .container record. In the container envelope, you can see the class record. Right snap on it – > 7zip – > Add to “JM_First… 7z”. It will get packed. Change the augmentation from .Flash to .Container.

If necessary, you can duplicate the .java document and spot it in .Compress record and afterward change the expansion to .Container

7. Import JAR file and test run Operation mapping:

Make a new namespace and under it, make IMPORTED Documents.

Give the imported document name same as Class Name. Import the record.

We will make test information type with one field and check whether the items in the information field gets replicated to yield field.

Data type:

Message Type:

SI – Outbound:

SI – Inbound:

Message Mapping:

NA. No need of message planning as we are utilizing Java planning for the change.

Operation Mapping:

Testing:

Operation Mapping -> Test tab

JAVA PROGRAM – 2 – Copy the contents from input to output by reading line-by-line:

Scenario:

Compose a Java Program on perusing the items in the record line by line and duplicate it to the result document.

The distinction between prior program and that’s what this program is, in program 1, the code will duplicate the items without perusing line by line and gluing it in yield document. However, in this program 2, we can peruse the items line by line, so that assuming there is any change required in the approaching lines, it tends to be done which is unimaginable in Program 1.

The change technique and the primary strategy will be the equivalent on the grounds that change strategy just calls the execute strategy by passing contentions and void strategy makes another article and passes it to execute strategy.

Execute method:

public void execute(InputStream in, OutputStream out) throws StreamTransformationException{
	try {
	   StringBuffer sourcePayload = new StringBuffer();
	   BufferedReader docInput = new BufferedReader(new InputStreamReader(in));			
			
	   String inputLine = "";
			
	   while( (inputLine = docInput.readLine() ) != null ) 
           {
	      sourcePayload.append(inputLine + "\r\n");
	   }
			
	   out.write( new String(sourcePayload).getBytes("UTF-8") );
	   out.flush();			
			
        }catch(Exception ee) 
        {
	   throw new StreamTransformationException(ee.toString());
	}		
}

Same way, place an info document and incorporate the java program to check whether its functioning true to form.

GITHUB REPO:

JAVA PROGRAM – 3 – Adding traces to java program on copying contents:

Scenario:

In this program we will figure out how to compose data, troubleshoot, and cautioning messages from Java planning, such as following the execution of the java program. Follow is only the review logs that we can see when the code is executed at runtime in ESB/AEX.

There are three sorts of follows:

Data

Troubleshoot

Caution

We will utilize a similar existing Java Program-2 which peruses the document line by line and add follows to it.

Make another Java Undertaking and class. Add Outside Containers. Duplicate the current Java Program and glue it in recently made Java document. Supplant the Class name.

Adding traces to Java Program:

GITHUB REPO:

Import the Container record to Activity planning and Actuate it.

Activity Planning – > Test tab – > Glue an example test lines of string type and change it to see the hints of the result.

Trust you loved it. Assuming you feel somewhat skeptical, questions or ideas for us, kindly put your remarks underneath.

 

YOU MAY LIKE THIS

SPTA Parallel Processing Framework in ABAP

Power of Parallel Cursor in SAP ABAP

SAP ABAP CRM Tips

₹25,000.00

SAP SD S4 HANA

SAP SD (Sales and Distribution) is a module in the SAP ERP (Enterprise Resource Planning) system that handles all aspects of sales and distribution processes. S4 HANA is the latest version of SAP’s ERP suite, built on the SAP HANA in-memory database platform. It provides real-time data processing capabilities, improved…
₹25,000.00

SAP HR HCM

SAP Human Capital Management (SAP HCM)  is an important module in SAP. It is also known as SAP Human Resource Management System (SAP HRMS) or SAP Human Resource (HR). SAP HR software allows you to automate record-keeping processes. It is an ideal framework for the HR department to take advantage…
₹25,000.00

Salesforce Administrator Training

I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
₹25,000.00

Salesforce Developer Training

Salesforce Developer Training Overview Salesforce Developer training advances your skills and knowledge in building custom applications on the Salesforce platform using the programming capabilities of Apex code and the Visualforce UI framework. It covers all the fundamentals of application development through real-time projects and utilizes cases to help you clear…
₹25,000.00

SAP EWM

SAP EWM stands for Extended Warehouse Management. It is a best-of-breed WMS Warehouse Management System product offered by SAP. It was first released in 2007 as a part of SAP SCM meaning Supply Chain Management suite, but in subsequent releases, it was offered as a stand-alone product. The latest version…
₹25,000.00

Oracle PL-SQL Training Program

Oracle PL-SQL is actually the number one database. The demand in market is growing equally with the value of the database. It has become necessary for the Oracle PL-SQL certification to get the right job. eLearning Solutions is one of the renowned institutes for Oracle PL-SQL in Pune. We believe…
₹25,000.00

Pega Training Courses in Pune- Get Certified Now

Course details for Pega Training in Pune Elearning solution is the best PEGA training institute in Pune. PEGA is one of the Business Process Management tool (BPM), its development is based on Java and OOP concepts. The PAGA technology is mainly used to improve business purposes and cost reduction. PEGA…
₹27,000.00

SAP PP (Production Planning) Training Institute

SAP PP Training Institute in Pune SAP PP training (Production Planning) is one of the largest functional modules in SAP. This module mainly deals with the production process like capacity planning, Master production scheduling, Material requirement planning shop floor, etc. The PP module of SAP takes care of the Master…
X
WhatsApp WhatsApp us
Call Now Button