SAP Training, Tutorials, Certification and Jobs Materials
HOME TUTORIALS ARTICLES PROJECTS JOBS TOOLS REFERENCES CHAT FORUM GUESTS

Related 10 ABAP SyntaxTutorials
SELECTION-SCREEN ( SAP ABAP Keyword)
ROLLBACK (SAP ABAP Keyword)
SUBMIT ( SAP ABAP Keyword)
SEARCH ( SAP ABAP Keyword)
BREAK-POINT ( ABAP Keyword)
STOP ( SAP ABAP Keyword)
DELETE (ABAP Keyword)
CONDENSE (ABAP Keyword)
SYNTAX-CHECK ( SAP ABAP Keyword)
DIVIDE (ABAP Keyword)

  COMPUTE (ABAP Keyword)

A D V E R T I S E M E N T
home--> ABAP --> ABAP Syntax
COMPUTE (ABAP Keyword) introduction & details
COMPUTE

Basic form
COMPUTE n = arithexp.

Effect
Evaluates the arithmetic expression arithexp and places the result in the field n .

Allows use of the four basic calculation types + , - , * and / , the whole number division operators DIV (quotient) and MOD (remainder), the exponentiation operator ** (exponentiation " X ** Y means X to the power of Y ) as well as the functions listed below.

When evaluating mixed expressions, functions have priority. Then comes exponentiation, followoed by the "point operations" * , / , DIV and MOD , and finally + and - . Any combination of parentheses is also allowed.

The fields involved are usually of type I , F or P , but there are exceptions to this rule (see below).

You can omit the key word COMPUTE .
Built-in functions

Functions for all number types

ABS Amount (absolute value) |x| of x SIGN Sign (preceding sign) of x;

1 x > 0


SIGN( x ) = 0 if x = 0


-1 x < pi =" 3.1415926535897932)" e =" 2.7182818284590452"> 0 SQRT Square root of a non-negative number

String functions

STRLEN Length of a string up to the last non-blank character (i.e. the occupied length )
Function expressions consist of three parts:
Function identifier directly followed by an opening parenthesis Argument Closing parenthesis
All parts of an expression, particularly any parts of a function expression, must be separated from each other by at least one blank.

Example
The following statements, especially the arithmetic expressions, are syntactically correct:


DATA: I1 TYPE I, I2 TYPE I, I3 TYPE I,
F1 TYPE F, F2 TYPE F,
WORD1(10), WORD2(20).
...
F1 = ( I1 + EXP( F2 ) ) * I2 / SIN( 3 - I3 ).
COMPUTE F1 = SQRT( SQRT( ( I1 + I2 ) * I3 ) + F2 ).
I1 = STRLEN( WORD1 ) + STRLEN( WORD2 ).



Notes
When used in calculations, the amount of CPU time needed depends on the data type. In very simple terms, type I is the cheapest, type F needs longer and type P is the most expensive.
Normally, packed numbers arithmetic is used to evaluate arithmetic expressions. If, however, the expression contains a floating point function, or there is at least one type F operand, or the result field is type F , floating point arithmetic is used instead for the entire expression. On the other hand, if only type I fields or date and time fields occur (see below), the calculation involves integer operations.
You can also perform calculations on numeric fields other than type I , F or P . Before executing calculations, the necessary type conversions are performed (see MOVE ). You can, for instance, subtract one date field (type D ) from another, in order to calculate the number of days difference. However, for reasons of efficiency, only operands of the same number type should be used in one arithmetic expression (apart from the operands of STRLEN ). This means that no conversion is necessary and special optimization procedures can be performed.
Division by 0 results in termination unless the dividend is also 0 ( 0 / 0 ). In this case, the result is 0.
As a string processing command, the STRLEN operator treats operands (regardless of type) as character strings, without triggering internal conversions. On the other hand, the operands of floating point functions are converted to type F if they have another type.

Example
Date and time arithmetic


DATA: DAYS TYPE I,
DATE_FROM TYPE D VALUE '19911224',
DATE_TO TYPE D VALUE '19920101',
DAYS = DATE_TO - DATE_FROM.


DAYS now contains the value 8.


DATA: SECONDS TYPE I,
TIME_FROM TYPE T VALUE '200000',
TIME_TO TYPE T VALUE '020000'.
SECONDS = ( TIME_TO - TIME_FROM ) MOD 86400.


SECONDS now contains the value 21600 (i.e. 6 hours). The operation " MOD 86400 " ensures that the result is always a positive number, even if the period extends beyond midnight.

Note
Packed numbers arithmetic:

All P fields are treated as whole numbers. Calculations involving decimal places require additional programming to include multiplication or division by 10, 100, ... . The DECIMALS specification with the DATA declaration is effective only for output with WRITE .
If, however, fixed point arithmetic is active, the DECIMALS specification is also taken into account. In this case, intermediate results are calculated with maximum accuracy (31 decimal places). This applies particularly to division.
For this reason, you should always set the program attribute "Fixed point arithmetic".

Example

DATA P TYPE P.
P = 1 / 3 * 3.


Without "fixed point arithmetic", P has the value 0, since " 1 / 3 " is rounded down to 0.
With fixed point arithmetic, P has the value 1, since the intermediate result of " 1 / 3 " is 0.333333333333333333333333333333.

Note
Floating point arithmetic

With floating point arithmetic, you must always expect some loss of accuracy through rounding errors (ABAP/4 number types ).

Note
Exponentiation

The exponential expression "x**y" means x*x*...*x y times, provided that y is a natural number. For any value of y, x**y is explained by exp(y*log(x)).
Operators of the same ranke are evaluated from left to right. Only the exponential operator, as is usual in mathematics, is evaluated from right to left . The expression " 4 ** 3 ** 2 " thus corresponds to " 4 ** ( 3 ** 2 ) " and not " ( 4 ** 3 ) ** 2 ", so the result is 262144 and not 4096.
The following resrtictions apply for the expression " X ** Y ": If X is equal to 0, Y must be positive. If X is negative, Y must be a whole number.

Note
DIV and MOD

The whole number division operators DIV and MOD are defined as follows:

ndiv = n1 DIV n2
nmod = n1 MOD n2

so that:
n1 = ndiv * n2 + nmod ndiv is a whole number 0 <= nmod < |n2|
A runtime error occurs if n2 is equal to 0 and n1 is not equal to 0.

Example

DATA: D1 TYPE I, D2 TYPE I, D3 TYPE I, D4 TYPE I,
M1 TYPE P DECIMALS 1, M2 TYPE P DECIMALS 1,
M3 TYPE P DECIMALS 1, M4 TYPE P DECIMALS 1,
PF1 TYPE F VALUE '+7.3',
PF2 TYPE F VALUE '+2.4',
NF1 TYPE F VALUE '-7.3',
NF2 TYPE F VALUE '-2.4',
D1 = PF1 DIV PF2. M1 = PF1 MOD PF2.
D2 = NF1 DIV PF2. M2 = NF1 MOD PF2.
D3 = PF1 DIV NF2. M3 = PF1 MOD NF2.
D4 = NF1 DIV NF2. M4 = NF1 MOD NF2.


The variables now have the following values:

D1 = 3, M1 = 0.1,
D2 = - 4, M2 = 2.3,
D3 = - 3, M3 = 0.1,
D4 = 4, M4 = 2.3.

Example
Functions ABS , SIGN , CEIL , FLOOR , TRUNC , FRAC


DATA: I TYPE I,
P TYPE P DECIMALS 2,
M TYPE F VALUE '-3.5',
D TYPE P DECIMALS 1.
P = ABS( M ). " 3,5
I = P. " 4 - commercially rounded
I = M. " -4
I = CEIL( P ). " 4 - next largest whole number
I = CEIL( M ). " -3
I = FLOOR( P ). " 3 - next smallest whole number
I = FLOOR( M ). " -4
I = TRUNC( P ). " 3 - whole number part
I = TRUNC( M ). " -3
D = FRAC( P ). " 0,5 - decimal part
D = FRAC( M ). " -0,5



Notes
Floating point functions
Although the functions SIN , COS and TAN are defined for any numbers, the results are imprecise if the argument is greater than about 1E8 , i.e. 10**8.
The logarithm for a base other than e or 10 is calculated as follows:

Logarithm of b for base a = LOG( b ) / LOG( a )

Note
Runtime errors

Depending on the operands, the above operators and functions can cause runtime errors (e.g. when evaluating the logarithm with a negative argument).
Related ADD , SUBTRACT , MULTIPLY , DIVIDE , MOVE

Email this Tutorial to my friend
Your Mail ID :
Friend mail ID:
Also send to me

Latest Added Tutorials

SAP PRE-SALE(very urgent requirement) - SAP JOBS INDIA
SAP PRE-SALE(very urgent requirement) - SAP JOBS INDIA
Experiense Required for this job: 6-9 years exp
Job Locations: Mumbai
Apply for this SAP Job in INDIA
SAP ABAP Professionals - SAP JOBS INDIA
SAP ABAP Professionals - SAP JOBS INDIA
Experiense Required for this job: 5 - 7 years exp
Job Locations: Bengaluru / Bangalore, Chennai, Others
Apply for this SAP Job in INDIA
Junior SAP Consultants - SAP JOBS INDIA
Junior SAP Consultants - SAP JOBS INDIA
Experiense Required for this job: 0-5 years exp
Job Locations: Bengaluru/Bangalore
Apply for this SAP Job in INDIA
SAP Plant Maintanence with ETM module - SAP JOBS INDIA
SAP Plant Maintanence with ETM module - SAP JOBS INDIA
Experiense Required for this job: 2-7 years exp
Job Locations: Pune
Apply for this SAP Job in INDIA
SAP Plant Maintainence /PM Consultant/Sr.consultant/TL - SAP JOBS INDIA
SAP Plant Maintainence /PM Consultant/Sr.consultant/TL - SAP JOBS INDIA
Experiense Required for this job: 3-8 years exp
Job Locations: Gurgaon, Kolkata
Apply for this SAP Job in INDIA
Immediate position for SAP ABAP Professionals. - SAP JOBS INDIA
Immediate position for SAP ABAP Professionals. - SAP JOBS INDIA
Experiense Required for this job: 5-9 years exp
Job Locations: Bengaluru/Bangalore, Chennai, Gurgaon
Apply for this SAP Job in INDIA
SAP - IS Retail (SRS) Consultant - SAP JOBS INDIA
SAP - IS Retail (SRS) Consultant - SAP JOBS INDIA
Experiense Required for this job: 5-8 years exp
Job Locations: Bengaluru/Bangalore
Apply for this SAP Job in INDIA
SAP BPC/EPM - SAP JOBS INDIA
SAP BPC/EPM - SAP JOBS INDIA
Experiense Required for this job: 4-9 years exp
Job Locations: Bengaluru/Bangalore, Hyderabad / Secunderabad, Pune
Apply for this SAP Job in INDIA
LOOKING FOR TECHNICAL AND FUNCTIONAL LEADS AND MANAGERS(SAP) - SAP JOBS INDIA
LOOKING FOR TECHNICAL AND FUNCTIONAL LEADS AND MANAGERS(SAP) - SAP JOBS INDIA
Experiense Required for this job: 3-8 years exp
Job Locations: Bengaluru/Bangalore, Chennai
Apply for this SAP Job in INDIA
SAP FICO Consultant - SAP JOBS INDIA
SAP FICO Consultant - SAP JOBS INDIA
Experiense Required for this job: 5-10 years exp
Job Locations: Hyderabad / Secunderabad
Apply for this SAP Job in INDIA

Most readed 5 Tutorials

List of SAP MM Transaction codes
This documentation covers the details of SAP MM Transaction codes
WRITE - Output to a list ( SAP ABAP Keyword)
WRITE ( Output to a list ) is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.
FI Accounts Receivable and Accounts Payable | SAP FI PDF manual
The following topics are an introduction to the Accounts Receivable and Accounts Payable application components.
List of SAP HR TABLES and Infotypes tables
Detailed full list of tables and infotypes used in SAP HR module.
Report Programming in HR | SAP PDF study material )
This document is intended for all persons who would like to program their own reports in SAP HR or customize standard ones. The documentation is not intended to be an introduction to programming. It contains just the special features that form part of programming in SAP HR.A general knowledge of ABAP programming and HR applications is a prerequisite. This can be acquired by reading the relevant documentation and attending the courses.This document provides information which enables programmers to become acquainted with the special features of programming in HR.
  

CATEGORIES

  ABAP
  Advanced ABAP
  SAP JOBS
  SAP Functional Modules
  SAP R/3
  SAP NetWeaver
   
SAP Technical PDF Tutorials

ABAP
DICTIONARY
INTERNAL TABLES
ALV Reports
SAPSCRIPTS
SMARTFORMS
LSMW
BDC
ALE
IDOC
USER EXITS
TRANSPORTING
ITS


SAP Functional PDF  Tutorials

FI (Financial)
CO (Controlling)
HR (Human Resource)
LO (Logistics)
MM (Materials Management)
PP (Production Planning)
QM (Quality Management)
SD (Sales and Distribution)
TR (Treasury and cash)
WM (Warehouse Management)
PS (project Systems)
PM (plant Maintenance)
CA (Cross Application)


SAP References

transaction codes
System Fields
Function Modules
SAP TABLES
code optimization


TOOLS

SQL Trace tool
Runtime Analysis
LSMW
ABAP Query
CTS


SAP Emerging Technologies

SAP Advanced Planner and Optimizer (APO)
SAP Business Information Warehouse
(BW)

SAP Business Intelligence
(BI)

SAP Customer Relationship Management
(CRM)
SAP Enterprise Portal (EP)
SAP Exchange Infrastructure
(XI)

Human Resource Management Systems
(HRMS)
SAP Manufacturing
SAP Master Data Management
(MDM)

SAP Knowledge Warehouse
(KW)

SAP Product Lifecycle Management
(PLM)

SAP Service and Asset Management

SAP Strategic Enterprise Management
(SEM)

SAP Solutions for mobile business

SAP Solution Manager

SAP Training and Event Management
(TEM)
SAP Web Application Server
(Web AS)
SAP xApps



Jobs in Kerala

 
Custom Search
  site contact sapbrain.support@gmail.com All of the product names here are trademarks of their respective companies. The site www.sapbrainsonline.com no way affiliated with SAP AG. Use information on this site at your own risk. Information furnished in the site is collected from various sites and posts from users. This site does not host any files on its server. If any compliants about the posts please contact us at sapbrain.support@gmail.com, we are ready to move the posts.
Complete SAP Study materials | SAP JOBS | PDF Tutorials web counter