Calculating Dates in SAP MDM

Published on February 2017 | Categories: Documents | Downloads: 65 | Comments: 0 | Views: 456
of 12
Download PDF   Embed   Report

Comments

Content

Calculating Dates in SAP NetWeaver MDM

Calculating Dates in SAP NetWeaver MDM
Applies to
Master Data Management 5.5 SP05

Summary
This article contains an assortment of tips and examples of calculated expressions within SAP NetWeaver
MDM which are related to dates but may be applied to other types of expressions.
Author: Kristin Patterson
Company: SAP America
Created on: 15 May 2007

Author Bio
Kristin Patterson is based in SAP America’s Palo Alto office in Northern California. She has been working
with SAP NetWeaver MDM since January 2006 at numerous customer sites. With SAP NetWeaver MDM
Development, Ms. Patterson has also been testing the newest MDM releases. Most recently she has been
designing and delivering MDM training course for customers.

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
1

Calculating Dates in SAP NetWeaver MDM

Table of Contents
Introduction ...................................................................................................................................... 3
Comparison of Calculated Field and Assignment ........................................................................... 4
Basics Tips....................................................................................................................................... 4
Different Field Types........................................................................................................................ 5
Which Field Type to Use.................................................................................................................. 6
Literal Date Field ...................................................................................................................... 6
Text Field .................................................................................................................................. 6
Integer and Real Fields ............................................................................................................ 7
Ways of Entering Dates ................................................................................................................... 8
System Time .................................................................................................................................... 9
Calculating a Date ........................................................................................................................... 9
Calculating a Numerical Value....................................................................................................... 10
Related Content............................................................................................................................. 11
Copyright........................................................................................................................................ 12

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
2

Calculating Dates in SAP NetWeaver MDM

Introduction
SAP NetWeaver MDM has the capability to perform calculations on date fields in the MDM repository thereby
producing either a date or a value. The calculations can be performed when a new record is created either
manually, during import, or using APis by creating a calculated field. Another option is to apply a calculation
to a specific field using an assignment.
Both calculations and assignments use the expression editor tool (see Figure 1) which allows excel like
expressions to be used to create values and conditional statements. The expression editor tool is used
exclusively to create Calculated Fields, Assignments, and Validations. Each of these is described in great
detail in the MDM Console and Data Manager Reference Guides. It is assumed for the purpose of this article
that all readers have reviewed and are familiar with these guides’ references to the expression editor.

Figure 1: Expression editor dialog box for creating formulas.

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
3

Calculating Dates in SAP NetWeaver MDM

Comparison of Calculated Field, Assignment, and Validation
Let’s begin by comparing a calculated field with an assignment and validation of a specific field.
Calculation Types

Calculated Field

Assignment

Validation

Formula Creation

Console

Data Manager

Data Manager

Repository Loaded

No

Yes

Yes

Read Only

Yes

No

No

Field Types Applied
to

Boolean, GM Time, Integer,
Literal Date, Literal Time,
Real, Text, and Text Large.

Boolean, GM Time, Integer,
Literal Date, Literal Time,
Real, Text, and Text Large.

Can be called by a
calculated field or an
assignment.

Output

Value

Value

True or False

As a quick review the Calculated Fields and Assignments will produce a single value. Whereas a Validation
creates a true or false response and can be called by other expressions and thereby be used in a Free-Form
Search. For the purpose of this article, the concentration will be on assignments using date values. The
reason for using assignments instead of a calculated field is described under Basic Tips #2. The article will
describe both the fields that support date formats and the functions that can be used in conjunction with date
values.

Basic Tips
As with all tasks, there are many ways to do things, but the following list comes from past experience and is
highly recommended.
1. When using the expression editor never type in a field or function if it is available in the expression
editor pull down menus. This will eliminate typing errors and the possibility of the editor
misinterpreting the textual characters.
2. Calculated fields can only be created and edited when the repository is unloaded. Thereby making it
impossible to test your formula as the repository must be loaded. So when creating a calculated field
use assignments to test the expression and only after the assignment works paste the expression
into a calculated field. The copy and paste function does work between expression editor windows.
3. Carriage returns can be used anywhere in the expression editor without having any effect on the
formula. Using returns can improve the legibility of the final formula.
4. If a text field is used, make sure that the field width is set large enough to hold all the characters that
will be created by the formulas. If the width is too small, the formula will not execute.

Disclaimer
Great effort went into verifying each formula before describing it here. But since it is not possible to copy a
working expression from the expression editor to a text editor, the formulas in this article had to be manually
retyped. There is the possibility that the formulas may have a typing error.

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
4

Calculating Dates in SAP NetWeaver MDM

Different Field Types
SAP NetWeaver MDM comes with 8 predefined field types that can display date and/or time formats or
formulas. The field type selected may be based on the display format required. The following list shows the
field types and examples of their display for the date May 6, 2007 at 9:43:04:000 am PDT using a 24 hour
format.
Field Type

Description

Display Format

Create Stamp

Write Once field which stores the creation date of the record.

05/06/2007 09:43:04

GM Time

Date and time displayed with GMT at the end. Can not be
populated manually in the Data Manager but can be populated
as a calculated field or with an assignment.

05/06/2007 16:43:04 GMT

Literal Date

Displays only the date in a preformatted field that shows the
month, date, and year using a “/” separator.

05/06/2007

Literal Time

Displays only the time in a preformatted field that shows the
hour, minutes, and seconds using a “:” separator.

09:43:04

Text

Static text with “:” separators. The date is now a string and
allows for alphanumeric sorting.

2007:05:06:09:43:04:000

Time Stamp

This is a Read Only field that is automatically populated with
the date and time a specified field or fields is changed. This
field cannot be manually written to.

05/06/2007 09:43:04

Integer

May be used when whole numbers are requested. The number
is not rounded.

148,413

Real

This field will display the numeric equivalent of the date field to
a maximum of 6 decimal places but will store the entire value.

148,413.696574

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
5

Calculating Dates in SAP NetWeaver MDM

Which Field Type to Use
The data and what will be done with the data will ultimately determine what type of field to use. Another
important factor is how the data will be inputted into the repository either through import, manual entry, or
use of APIs. These different ways will be discussed in the next section and will be demonstrated with real
examples for each of the cases.
Let’s go into more detail of the most commonly used field types: Literal Date, Text, and Integer/Real. Then in
later sections examples of literal, text, and numeric fields will be used. In many cases, the same functions
may be used in multiple field types and is not limited to just the one introduced here.
Literal Date Field
) that must be followed when
The Literal Date field provides a predefined formatted layout (
entering data. It also does not allow month entries over 12 nor date entries over the number allowed for that
specific month and year. This is ideal for controlling manual entry. The Literal Date fields work well with
calculating dates for both the past and future. If the time is also important, then a Literal Time field should
also be created.
Text Field
A text field can contain text, numbers, and special characters. If a formatted date is imported into a text field
it will now be a text string and can be manipulated with the expression editor’s string functions. The string
functions reside under the pull down Functions tab of the expression editor dialog box. Shown below is a list
of those string functions.
Pull Down

¦

Function

Description

Formula (F_name is the name of a field F)

Systime

Returns the system time

SYSTIME(x/24)
X is the number of hours before GMT

Modulus

Returns the remainder after
a number is divided by a
divisor

MOD(F_name, d)
F_name is the name of a field F representing a number
d is the number by which you want to divide F

String Length

Returns the number of
characters in a text string

LEN(F_name)

String Left

Returns the specified
number of characters from
the start of a string

LEFT(F_name, n)
n specifies how many characters to return from F

String Right

Returns the specified
number of characters from
the end of a string

RIGHT(F_name, n)
n specifies how many characters to return from F

String Mid

Returns the characters from
the middle of a string, given
a starting position and a
given length

MID(F_name, p, l)
p specifies the position of the first character to extract
from F_name
l specifies how many characters to return

String Find

Returns the starting position
of a specified string within a
string given

FIND(F_name, s, p)
s specifies the characters to search within the string F
p specifies the position of the character to start the
search within the string F

String Trim All

Returns the specified string
without spaces

TRIM_ALL(“F_name”)

String Trim Left

Returns the specified string
without the leading spaces

TRIM_LEFT(“F_name”)

String Trim Right

Returns the specified string
without the ending spaces

TRIM_RIGHT(“F_name”)

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
6

Calculating Dates in SAP NetWeaver MDM

Integer and Real Fields
A Real or Integer Field can only contain numbers and is an ideal field for calculating differences in dates and
time. If the difference should be displayed with character separators then the field must be text. Shown below
are commonly used operators available in the expression editor dialog box.
Pull Down

Function

Description

Formula (F1_name is the name of a field F1)

+

Adds two numerical fields

F1_name + F2_name
both fields representing numbers

-

Subtracts two numerical fields

F1_name - F2_name
both fields representing numbers

*

Multiply two numerical fields

F1_name * F2_name
both fields representing numbers

/

Divide two numerical fields

F1_name / F2_name
both fields representing numbers

&

Concatenate the specified strings

S1 & S2
S1 and S2 are text string

()

Separate expressions or operations

““

Surrounds a text string of characters

=

Checks that two values are equals

F1_name = F2_name

<>

Checks that two values are different

F1_name <> F2_name

>

Checks that a value is strictly greater
than another value

F1_name > F2_name

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
7

Calculating Dates in SAP NetWeaver MDM

Ways of Entering Dates
There are three ways to enter data into a MDM repository: manual, import, and using APIs. The application
programming interface (API) which is available in both Java and ABAP will not be discussed in this article,
but many of the points made here may be of value when using APIs. Manual entry of data is the least
preferred way of entering data since it allows for human errors to be replicated. Where as the importing of
prescreened data, provides more accurate data integrity. This article will primarily concentrate on importing
of data but will also discuss the manual entry when this information is pertinent.
SAP NetWeaver MDM can import data from many types of files: flat files, excel, access, XML, SQL, Oracle,
and ODBC. The different types of import files may be interpreted differently by the Import Manager (IM). As
an example, if the imported source data file is excel and a date is kept in a MM/DD/YYYY format then only a
Literal Date field can be used. When importing the same date from XML then Literal Date or Text Field can
be used. The reason for this is that the IM is using Microsoft’s parser to interpret the data and when the data
is imported from Excel it recognizes the MM/DD/YYYY (and D-mmm) format as a date and will only allow
import into a Literal Date field.
Dates can be imported into MDM as MM/DD/YYYY, YYYYMMDD, or DD.MM.YYYY. The date format is set
under the IM’s Configuration > Options…

This setting applies to all dates being imported into Literal Date fields. If you need to use different date
formats for different fields then separate imports must be performed.

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
8

Calculating Dates in SAP NetWeaver MDM

System Time
One of the most recently added functions in the expression editor is the System Time function which gives
the current date and time to the millisecond. The function is SYSTIME(x) where x is the time zone. If
SYSTIME(0) then it is the current Greenwich Mean Time (GMT). Hours can be added by putting in a fraction
of 24. So SYSTIME(8/24) is equal to GMT + 08:00 (Beijing, Singapore, and Taipei.) If you want to go
backwards in time then enter SYSTIME(0-8/24) which is equal to GMT – 08:00 (PST.) Note that this is
Pacific Standard Time and not Pacific Daylight Savings Time. Make the appropriate adjustments to reflect
Daylight Savings Time if that is what is desired. Also partial hours can be added by entering
SYSTIME(2.5/24) for GMT + 02:30.
If only the date is required, then populate a Literal Date field. If only time is required then use a Literal Time
field. Table below is using SYSTIME(0) = May 1, 2007 4:31:44 GMT.
Field Type Populated

Formula

Result

Details

Literal Date

SYSTIME(0)

05/07/2007

Literal Time

SYSTIME(0)

4:31:44 AM

GM Time

SYSTIME(0)

05/07/2007 4:31:44 GMT

Integer

SYSTIME(0)

148414

Does not round number.

Real w/6 decimals

SYSTIME(0)

148414.188705

Displays the first 6 decimals but stores
148414.188704525.

Text

SYSTIME(0)

2007:05:07:04:31:44:000

Field width had to be set to 23 or more.

Calculating a Date
There are requirements to determine a date in the future, in the past, or calculated based on specific criteria.
For example, what date is 10 days after the hire date? Table below is using the Literal Date field called Hire
Date with the value of May 1, 2007.
Field Type Populated

Formula

Result

Literal Date

Hire Date + 10

05/11/2007

GM Time

Same as above

05/11/2007 0:00:00 GMT

Integer or Text

Same as above

148418

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

Details

Not a valuable display for most
people but useful for calculations.

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
9

Calculating Dates in SAP NetWeaver MDM

Calculating a Numerical Value
In this example, the days a person has worked for the company will be calculated. The repository has the
actual hire date of all employees. The table below is using Hire Date (Literal Date) = May 1, 2007 (unless
otherwise stated) and the System Time = May 7, 2007 4:31:44 GMT.
Request

Field Type
Populated

Formula

Result

Details

Number of days
since hire date

Integer1

SYSTIME(0) – Hire Date

6

Does not
number.

Number of days
since hire date

Real
w/6
decimals

Same as above

6.188705

Displays the first 6
decimals but stores
6.1887045254698.

Number of days
since hire date

Text1

Same as above

6.1887045254698

Number of days
since hire date using
string functions

Integer2

(Left(SYSTIME(0) – Hire Date,
FIND(SYSTIME(0)-Hire
Date,”.”) -1)

6

Does not round
number.

Number of days
since hire date with
“days”

Text2

(Left(SYSTIME(0) – Hire Date,
FIND(SYSTIME(0)-Hire
Date,”.”) -1) & “ days”

6 days

Combination of
integer and text.

Is it the hire date
anniversary?

Text3

IF((MOD(SYSTIME(0),6,2) –
MID(Hire Date,6,2))=0,
(IF((MID(SYSTIME(0),9,2) –
MID(Hire Date,9,2))=0,
“Anniversary Day!!”, “Day is
not equal”)),
(IF((MID(SYSTIME(0),9,2) –
MID(Hire Date,9,2))=0, “Month
is not equal”, “Month and Day
are not equal”)))

Day is not equal

Hire Date = 05/07/2002

Text3

Same as above

Anniversary Day!!

Hire Date = 04/08/2002

Text3

Same as above

Month and Day
are not equal

Hire Date = 05/01/2002

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
10

round

Calculating Dates in SAP NetWeaver MDM

Related Content
Additional MDM reading that may be of interest:
NetWeaver How to Guides or directly to MDM Guides on SAP Service Marketplace.

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
11

Calculating Dates in SAP NetWeaver MDM

Copyright
© Copyright 2007 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the
express permission of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components
of other software vendors.
Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390,
OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli,
Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of
IBM Corporation.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of
Adobe Systems Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or
registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web
Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented
and implemented by Netscape.
MaxDB is a trademark of MySQL AB, Sweden.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, 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.
These materials are subject to change without notice. These materials are provided by SAP AG and its
affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any
kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only
warranties for SAP Group products and services are those that are set forth in the express warranty
statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
These materials are provided “as is” without a warranty of any kind, either express or implied, including but
not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or
consequential damages that may result from the use of these materials.
SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items
contained within these materials. SAP has no control over the information that you may access through the
use of hot links contained in these materials and does not endorse your use of third party web pages nor
provide any warranty whatsoever relating to third party web pages.
Any software coding and/or code lines/strings (“Code”) included in this documentation are only examples and
are not intended to be used in a productive system environment. The Code is only intended better explain
and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and
completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the
usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.

SAP DEVELOPER NETWORK | sdn.sap.com
© 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com
12

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close