Você está na página 1de 27

Implementing IPC Java user exit to enable calculation

of EMI
Narinder Hartala

14th October 2010

SAP Global Delivery

Document Details
Name Objective Audience Version Description
Implementing IPC CRM 1.0 Implementing IPC Java user
Java user exit to exit to calculate EMI
calculate EMI

Change Log
Version Date Author Description Approved By
1.0 October 14, 2010 Narinder Hartala Implementing IPC
Java user exit to
calculate EMI

For any info on this document please contact:


Name Email ID Contact No
Narinder Hartala narinder.hartala@sap.com +91-124-673-2114
2008 by SAP AG.
All rights reserved. SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products
and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several
other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data
contained in this document serves informational purposes only. National product specifications may vary.
CONTENT
1. Implementing IPC Java user exit to calculate EMI .................................................................. 4
2. Setting up development infrastructure .................................................................................... 5
3. Details of steps required to set up the dev environment........................................................ 5
4. User exit development using NWDS ....................................................................................... 9
5. Userexit administration and configurations ........................................................................... 13
6. VMC reset and Pricing buffer refresh .................................................................................... 14
8. Troubleshooting ..................................................................................................................... 16
9. Useful transaction and links .................................................................................................. 20
10. Documents and Sample Code .............................................................................................. 21

Implementing IPC Java user exit to calculate EMI

This document will walk through the process of developing pricing userexit in general and will cater to
one specific customer requirement explained below.

Some companies provide after sales services and sells contracts to customers. Generally these contracts
have an annual price agreed to and client wants to bill periodically an equal amount to the customer.

In the standard system, for yearly prices, pricing calculates proportional periods based on days. As a
result, the billing amounts vary, for example in monthly settlement, according to the different
numbers of days in a month.
Example:

Yearly price: 12000 INR for a rental contract. Settlement should be carried out quarterly.

1. Quarter (JAN/01 to MAR/31): 3 months, 90 days -> Year proportion 0.2466

2. Quarter (APR/01 to JUN/30): 3 months, 91 days -> Year proportion 0.2493

3. Quarter (JUL/01 to SEPT/30): 3 months, 92 days -> Year proportion 0.2521

4. Quarter (OCT/01 to DEC/31): 3 months, 92 days -> Year proportion 0.2521

Settled: Required:

1. Quarter: INR 2958.90 INR 3000.00

2. Quarter: INR 2991.78 INR 3000.00

3. Quarter: INR 3024.66 INR 3000.00

4. Quarter: INR 3024.66 INR 3000.00

SAP has suggested a workaround for the above requirement. See OSS Note 882075
https://service.sap.com/sap/support/notes/882075

We will be implementing the suggested solution here.

Setting up development infrastructure

Download SAP Note https://service.sap.com/sap/support/notes/809820

This note has two attachments

Pricing Userexit manual


A .zip file containing a prepared Eclipse project to be used in NWDS while developing the
customer user exit

Download both attachments and read the pricing userexit manual thoroughly. Follow the steps
mentioned in Section 2 of pricing user exit manual or section 3 of this document. In case you facing any
problems please take help from local IT to setup the Java development environment. Pricing userexit
manual and prepared Eclipse project are attached in the last section of this document also.

3. Details of steps required to set up the dev environment

Create an empty folder which will be used as workspace folder for NWDS e.g.
D:\NWDS_WORKSPACE
Unpack the ZIP file attached to the note 809820 into the empty folder created in step 1. Then a
sub directory with the name PRC_UE_CUSTOMER should appear containing the project files. See
snapshot

Launch SAP GUI, type /n/SAPCND/UE_DEV in the command field and hit enter
Select the Download option and activate the option Libraries. Enter the newly created subfolder
in the Target Directory and hit the execute button. Two folders lib_api and lib_src will be
created in the existing subfolder PRC_UE_CUSTOMER

Note: In situations where exits have already been implemented, and we need to do
changes in an exit, we need to do the following.
Select the Userexits radio button, give the name of the package where the userexits are
stored previously and the target directory created earlier and folder SRC
A userexit folder should appear under PRC_UE_CUSTOMER folder

Start NWDS installed on your machine and set the folder created in step 1 as the workspace

Import already prepared File->Import, select Existing Project into Workspace, ( In eclipse,
Select General, then Existing Project into Workspace )and click Next in the pop-up. Now use
browse button, select existing folder PRC_UE_CUSTOMER in workspace as the root directory
and hit OK. NWDS should show the PRC_UE_CUSTOMER as Project name.

Now the JRE System Libraries have to be added to build path of the NWDS/Eclipse. Right click on
the project folder and select Properties. In the resulting popup choose Java Build Path, tab
Libraries and button Add Library. Then choose library type JRE System Library and use a 1.4.x
version
Prepare the API source and build the HTML documentation. Right click on build_api_doc.xml
and select Run As->Ant Build. Ignore the error message thrown during this process.
Refresh the NWDS project by right clicking on the project and choose refresh.

Now the default project is ready to be used for custom developments. Java Documentation for all API
classes is available and can be viewed by NWDS auto completion help or by opening the file
PRC_UE_CUSTOMER/api_doc/index.html

4. User exit development using NWDS

As the development environment is ready now we can go ahead and do the required JAVA
development. In case you new to Java please search for Java basis tutorials on internet.

The project has following structure:

Src: folder should contain the customer developments. It is recommended to use also in java some
naming convention to better distinguish standard coding and own developments. We can use concept of
package in java to achieve that.

OSS Note 92655 and 882075 would be useful to write the desired java code.

Create package hierarchy in the src folder e.g. com.yourcompany.pricing.userexits


Right click on folder userexits choose New - > File. Enter java class name to be created
e.g. ZCalculateEmi.java and click button Finish.
Write the java code as described in OSS Notes 92655 and 882075. Sample code is
attached in the section 10.
Save, Compile and rebuild the project

Right click on create_PRC_UE_CUSTOMER_jar.jardesc and choose Create JAR from the


context menu. This will automatically export the jar file PRC_UE_CUSTOMER.jar into the
workspace folder.

Upload the developed userexit to the CRM database. It is done with the same
transaction which is used to download the initial API libraries. Create a workbench
request beforehand to record the userexit upload. Execute transaction
/SAPCND/UE_DEV, select upload, input Transport Request, ABAP Package, Jar File path
and click execute(F8)

For each ABAP package only one jar file can be uploaded. We can see already uploaded
jar files using transaction SM53
5. Userexit administration and configurations

Customer pricing userexit has to be known to the runtime. Each implementation is loaded during
runtime and controlled by configuration available through transaction /SAPCND/UEASS. Follow below
steps:

Register implementation executing transaction /SAPCND/UEASS. Input usage PR and execute.


Select userexit type BAS from the table and double click on Implementation in Dialog Structure.
Click button New Entries , input details as shown below and save

Now create a formula by clicking on the Formulas in Dialog Structure. Choose


Application CRM usage PR and User Exit Type BAS. Click New Entries button in the
application toolbar. Input formula no. 600(see transaction /SAPCND/UEASS to check
customer number range) and Userexit name entered in registration step. Save.
Now we need to assign this base formula to the Condition Type in the Pricing Procedure.
Please check with Functional to get the required Condition Type and Pricing Procedure.

6. VMC reset and Pricing buffer refresh

Before testing the new userexit below steps are mandatory.

VMC reset: Execute transaction SM52. Choose menu Virtual Machine Contatiner ->
Reset
Refresh Pricing buffer by executing FM IPC_DET_CLEAR_CUST_BUFFER passing
parameter value CRM and PR.

Now test it with the Function Consultant by creating a service transaction which uses the
Pricing Procedure where you have included the newly created Condition Base Formula to
which userexit is assigned.
Troubleshooting

Sometimes system doesnt behave as we want it to for such cases we have to troubleshoot. We
have two methods to achieve it.

Java debugger
VMC Log Files

**edited by Sandeep salaria ****

Create a transaction and enter an item, before pressing enter, write /h and then press enter

Breakpoint at statement->RFC

Breakpoint at FM PRC_INT_PRICING_PROCEDURE_INFO

In eclipse, go to debug, and then remote java applications, give the port name and host name as
displayed in the FM earlier
Host name could be taken from the sap GUI, by pressing the system and pressing on change item

After you enter the values, you might have to press F8 few times, before you get into eclipse
debugger
***end****

To run java debugger we need to follow below steps:

Set VMC in debug mode


First check if debugging is enabled. We can check this using link similar to
Error! Hyperlink reference not valid. replace <host_name> and <port> with
actual values.

Set Parameter PRC_RFC using transaction SU3 to X

Create a breakpoint in Java Source file in NWDS/Eclipse


Now create change any business transaction which access pricing using WEB UI
or SAP GUI

Attach NWDS/Eclipse Java Debugger


System will automatically break and open ABAP Debugger session keep pressing
F5. System will display one pop with VMC port

You can execute SM52 and see the VMC work process

Now in the NDWS/Eclipse open menu Run ->Debug and create a new Remote
Java Application Configuration.
Enter Host(FQDN) and port which is shown in the popup and SM52

Click button Debug available in the bottom system will break to ABAP debugger
session

Keep pressing F8 until control is passed to NWDS/Eclipse java debugger. You


will see something like below snapshot. Now you can use familial keys i.e. F5,
F6, F7 and F8
We can see variable value by keeping curser over it and in the Variable window
as well
We can use the VMC log files also to do an error analysis in case not able to debug properly. We can
insert some useful comments, values etc. which can help us to understand that program flow and
data. Important: We should remove all logs logic before moving to production as it will create
unnecessarily load on system resources.

We can use class com.sap.spe.base.logging.UserexitLogger to write log entries.


Declare private static reference variable of type Userexitlogger and create an instance by
supplying <your_exit_class_name>.class as parameter to constructor
Use method writeLogDebug( ) to insert a log entry. You will be able to see this log entry
later on in SAP system using transaction SM53.
You can see attached java file, logs related code is commented.
To see log entries we need to register our exit class in Log Configuration.
Execute transaction SM53 chose Log Administration -> Log Configuration in left
Navigation dialog structure.
Enter your class name in the long input field, chose DEBUG in the dropdown next to it
and hit button Transfer.
Now create/change a business transaction which uses the pricing procedure where we
have added the newly created formula attached to userexit. Make change to price and
billing plan.
Execute transaction SM53 chose Log Administration -> Log Display in left Navigation
dialog structure. Select ZCalculateEmi in the Log Selection and click button Update Log
Messages. Log messages are displayed as shown below.

** Edited By Arun Singh**


3) Issue with the Compilation and IPC not working as expected.

If you see any missing file in SM53 i.e either .java or .class file is missing then it is
highly likely compilation issue. Follow the steps under B.2 to resolve them.
First things first. Try compiling any Routine and Requirements with minimal coding.
That is just RETURN TRUE. Compile the package and upload the jar file as usual. Test
Run the IPC .

B.1) Now if the IPC works it means there is SYNTAX error or the LOGICAL errors. Please
check out the METHOD parameters and the signatures of the used method. They have to be
exactly like the SAP guidelines. Also check out that the java code you have written is compiled
without errors in the code. Remove any errors present and then compile and upload again and
check again.

B.2) If still the IPC doesnt work with the minimal coding then we need to ensure that the the
JRE used is in compilation with SAP. Download the JRE/JDK 1.4.2_09 from the Oracle
Website which is available as a free download and install them . Now we will have two versions
of java installed on our system.Do remember the path where we have installed the Java JRE/JDK
1.4.2_09 which will be used later in the ECLIPSE.

Once we have installed the JRE 1.4.2_09 we will compile our source code from the eclipse. It is
better if we download the older version of Eclipse i.e the same one used in this document to
describe the process.

Now follow the process as described before to develop your source code and while compilation ensure
the following steps.

Right Click on PRC_UE_CUSTOMER >Build Path>Configure Build Path and ensure that the JRE 1.4.X is
present there.If not then please add them.
Secondly ensure that the JDK compliance level is set to 1.4.X. as shown in the below screenshot.

And we can try that the 2 ANTBUILD is set for JRE 1.4.X as shown below .
Also after ANT Build you can have a look at the compilation path shown in the CONSOLE window. It shall
show JRE 1.4.X under Ant Build Path as we are expecting that.

Useful transaction and links


Transactions:
SM52
SM53
/SAPCND/UE_DEV
/SAPCND/UEASS
/SAPCND/UERNG
Function Module:

IPC_DET_CLEAR_CUST_BUFFER

Quick Reference to Class used:-

Requirement (REQ) - public class ZSpecialRequirement extends RequirementAdapter {}

Condition Base Formula (BAS) - public class ZSpecialBaseFormula extends BaseFormulaAdapter


{}

Scale Base Formula (SCL) - public class ZSpecialScaleBaseFormula extends


ScaleBaseFormulaAdapter {}

Condition Value Formula (VAL) - public class ZSpecialRoundingValueFormula extends


ValueFormulaAdapter {}

Copy Formula (CPY) - public class ZSpecialCopyFormula extends PricingCopyFormulaAdapter {}

Documents and Sample Code

Você também pode gostar