Review Part 3 – Calculations and Character Strings

This is a guest article is by Plamen Velkov, who is taking my Beginners Guide To SAP ABAP programming course. This is part 3 of his course review / journey. (See if you can spot his error with the Keywords Calculations. Plamen, do you see it?)

Take it away Plamen…

Performing calculations

Performing calculations in ABAP is as simple as in every other programming language. The only different thing is you can perform calculations by keywords as well as the regular mathematical operators. These keywords are mentioned in the course but I’d like to present the whole statement constructions because I came across some while examining some ABAP code. The statements are fairly logical but still – here they are:

Operation Regular math. Statement Statement using Keyword
Addition c = a + b ADD a TO b.
Subtraction c = a – b SUBTRACT b FROM a.
Multiplication c = a * b MULTIPLY a BY b.
Division c = a / b DIVIDE a BY b.

Another thing came on my mind – the Power operator (**) was not mentioned in the course. It’s also a simple thing to do – if you want to calculate the following:

c = 2 to the power 16

You just have to use this statement:

c = 2 ** 16.

Calculator ABAPCalculations in structures

While I was moving through some ABAP code in my company’s system I saw some statements that surprised me at first. They seemed partly familiar but not at all – the first part of the statement was a regular arithmetic calculation keyword and the second was the CORRESPONDING keyword. I googled the statement and found out that we can use those kind of statements to perform arithmetic operations between the components of structures. The statements I talk about are the following:

ADD-CORRESPONDING
SUBTRACT-CORRESPONDING
MULTIPY-CORRESPONDING
DIVIDE-CORRESPONDING

Of course, the components of our structures must have the same name and have numerical values.

I want to point out I’m writing this paragraph because I saw nothing about calculation in structures in the relevant course module. I haven’t finished the whole course yet, so I don’t know if this is covered in any of the following modules. If it is, I want to apologize to Mr. Moxon for my remark.

Character strings

ABAP is unique to me with the existence of the numeric string data type. I believe this is very often used in transactions and financial stuff in order to introduce a completely separate data type. The SEARCH statement also has very advanced functionality and will definitely be of help to me. As for the other string modifying statements in ABAP – (CONDENSE, REPLACE, SEARCH, SHIFT, SPLIT and the STRLEN() function) – they give you the power to edit and modify in any way you need. Moreover, they are beautifully explained in the course, so you surely won’t have any problems with your string variables from now on.

Plamen Velkov

Categories

About the Author:

Pete has been working with SAP technologies for over 10 years. He started out as an ABAP consultant and then moved on to BW where he has worked many different clients covering a wide variety of industries. "I love introducing SAP technology (especially BI) to new clients and showing them how they can go from zero to hero within their business in super fast time". Contact me on twitter @PeterMoxon

4 Comments