Thursday, 27 July 2017

Creating New Date Rules in SAP CRM

This blog explains the process for creating new date rules in SAP CRM.

To create a new date rule, you need to perform a series of configuration and development steps:

1. Open the Date Rule customizing screen by going into the IMG and following the menu path: Customer Relationship Management > Basic Functions > Date Management > Define Date Types, Duration Types and Date Rules.

2. In the dialog structure that appears, select Date Rules, and then click the New Entries button. The screen shown below appears.

SAP Customer Relationship Management, SAP CRM, SAP All Modules, SAP Modules

Enter a technical name for the rule such as “ZBOOKEX1”, and then enter a description such as “Book Example”.

4. Click Save, and you are prompted for a customizing request. If you don’t have an existing customizing request, you’ll create a new one; otherwise, you’ll select one for your work.

5. Go back to the overview screen of all existing date rules as shown below, select the date rule that you created, and then click the Details icon.

SAP Customer Relationship Management, SAP CRM, SAP All Modules, SAP Modules, SAP Tutorials and Materials

6. An overview screen appears showing all of the versions of the underlying XML that makes up the date rule as shown in the figure below. Double-click on the only row, and then you’re ready to start editing the XML of the date rule. There isn’t much documentation on this format, but to invoke an ABAP function module for date rules, you can enter a certain pattern as shown in the second figure and code below.

7. When you first open the editor, it will be in display mode. Click the Change button to insert the necessary XML code.

SAP Customer Relationship Management, SAP CRM, SAP All Modules, SAP Modules, SAP Tutorials and Materials

The Editor for Date Rules screen expects a certain pattern of XML to be entered that specifies the date rule as shown in the following code. The pattern has been derived by examining the delivered date rule in the system called “Planned Date (Activities)” with a technical key of “000000000002”.

<?xml version="1.0"?>

<SAPTimeRule>

  <ABAPTimeRule function="Z_CRM_DATE_CALC"/>

</SAPTimeRule>

SAP Customer Relationship Management, SAP CRM, SAP All Modules, SAP Modules, SAP Tutorials and Materials

8. After you’ve created the XML for the date rule that calls the ABAP function module you’ll create in the next step, save your work.

9. Before you can use this date rule in a date profile, you now must code the ABAP logic that will evaluate the date passed and return a result. Create a function module that has two importing parameters:
  • _ CONTEXT: A type reference to IF_TIMECONTEXT.
  • _ TIMEMESSAGE: A type reference to CL_TIMEMESSAGE.
Your function module also must return a reference value named ERROR that is of type XFLAG.

The context reference provides you access to the date data being manipulated in your function module. The interface allows you to retrieve the list of time events and then add back a special time event called the result, which is the result of your calculation and will populate the date type that will use this rule.

1 Function Module Logic: Date Context

To better understand this logic, let’s take a look at the following function module that calculates your date. The first call will be to get the event set from the context as shown in the code fragment:

li_eventset = context->get_eventset( ).

This is always needed to provide the result back and calculate any dates you may encounter.

Next you’ll get the GUID of the current transaction you’re processing so you can access any data needed for the calculation via the one order API. You’ll use the function module CRM_CONTEXT_GET_ACTUALGUID_OW to get this GUID.

After you have the GUID, you retrieve any other data from the business transaction using the one order OW function modules by passing in the header GUID. As you might have noticed, your function module doesn’t provide any data about the business transaction you’re working with directly.

If your calculation is based on another date, you first need to retrieve the value of that date by retrieving it from the event set. The following code fragment can be used to achieve this in your date rule function module:

li_tns_zfirstcont ?= li_eventset->get_by_name( lv_name ).

if li_tns_zfirstcont is initial.

  exit.

endif.

Note that you won’t want to process the date rule if the date you need to calculate hasn’t been entered or already calculated. Thus, you’ll exit the function module to prevent any short dumps with improper date calls.

One big difference of working with a date context as compared to standard ABAP time and date types is that you can’t perform simple add or subtract functions on the dates themselves. You instead need to create a duration that corresponds to how much you want to increment or decrement the date and then apply the duration to the date itself. To do this, create a new duration object using the class CL_TIMEDURA. You can then calculate the new date by using the static method CL_TIMECALC.

Wednesday, 12 July 2017

SAP MII connection to External HANA database

SAP MII (Manufacturing Integration and Intelligence) is a very powerful tool provided by SAP to connect shop floor systems (PLC / SCADA / Historians) to ERP (SAP ECC / SAP S/4 HANA). By such seamless integration between shop floor and ERP systems, it provides customers better visibility in terms of manufacturing production and it helps in reducing operational costs by providing various dashboards, KPI monitoring and visual representation of machine data. In today’s world where everyone is talking and researching about IoT and the massive amount of data that any manufacturing company is going to deal with, the expectation from the SAP MII customers is to handle huge volume of time-series and tabular data collected from operations/PLCs at the manufacturing plants to perform long-term trend and regression analysis on it near real time. Moreover, customers also want to predict and prevent operational issues such as machine downtimes, material quality and performance bottlenecks in production lines.

MII in its traditional architecture usually has its own Netweaver database and an external database (commonly known as Application Database) where most of transaction data and certain master data is stored. In this blog, we are solely going to concentrate on external application database that MII connects to. Before the birth of HANA database, MII generally had MS SQL or Oracle as its application database. But looking at the computing power of HANA database and its massively fast i/o operations, customers are demanding HANA as their external database that should connect to MII for all the transaction data and analytics.

There are many ways MII can connect to external HANA database but we are going to learn how to connect to HANA database using JDBC API. To install JDBC driver for HANA, please follow these two very detailed and informative blogs:

◉ Connect to SAP HANA via JDBC

Now once we have a confirmation that HANA database has JDBC driver installed and configured,we can perform belowsteps in MII to connect to HANA database.

1. Go to Data Sevices / Data Servers :


Tips & Tricks, SAP ERP Modules, SAP Online Guide, SAP HANA, SAP Certifications

2. Click on Create and below screen will be shown:


Tips & Tricks, SAP ERP Modules, SAP Online Guide, SAP HANA, SAP Certifications
  • Provide Server Name – Any meaningful name
  • Connector Type: IDBC (As we are going to use JDBC connection, connector type would be IDBC)
  • Description: Meaningful Description
  • Click on Finish

3. Provide Server Details and other information (Critical Step) :


a. Check “Enabled” & “Allow Dynamic Query” Checkboxes in Settings tab:

Tips & Tricks, SAP ERP Modules, SAP Online Guide, SAP HANA, SAP Certifications

b.Open Connection Tab:

Tips & Tricks, SAP ERP Modules, SAP Online Guide, SAP HANA, SAP Certifications
  • JDBC Driver: com.sap.db.jdbc.Driver
  • Server URL:
jdbc:sap://<server>:<port>[/?<options>] where <port> should be 3<instance number>15

Lets say Server name in MySERVER101.com & HANA Database instance is 01.Then Server URL would be: jdbc:sap://MySERVER101.com:30115/?autocommit=false
  • User Name: User Name of the HANA Database
  • Password: Password of the HANA Databse
  • Validation Query: Select ‘Hello World’ from Dummy
If we have provided all the correct information then if we go to Status tab, we can see ‘Running’ Status:

Tips & Tricks, SAP ERP Modules, SAP Online Guide, SAP HANA, SAP Certifications

4. Open MII Workbench, select New SQL Query and newly created data server External-HANA-DB will appear in Available Servers:


Tips & Tricks, SAP ERP Modules, SAP Online Guide, SAP HANA, SAP Certifications

5. We can see all the tables and can query them:


Tips & Tricks, SAP ERP Modules, SAP Online Guide, SAP HANA, SAP Certifications

Please note that by directly querying HANA database tables via MII SQL Query will not give us any benefits that HANA’s in-memory database management provides. Hence optimal way to perform this activity is to create tables in HANA as columnar tables and then define the Attribute views (fact tables), Analytic views (measure and dimensions) and Calculation views (complex calculations and data processing). Then MII SQL Query can directly query these views and can enjoy all of the HANA benefits.