SAP ABAP – Program Flow Control and Logical Expressions

As said in the course, logical expressions are the principal statements used to build up your program logic and algorithms. ABAP offers all the classical loop statements and logical expressions, so you won’t miss anything for sure. I personally missed the for loop from Java and C/C++, but then realized there are other ways to perform this kind of iterations. What I liked in ABAP was the Pattern tool which can save you a lot of time when building loops or logical expressions.

IF and CASE statements

Everyone who has ever programmed should be familiar with these two statements. The IF statement is the simplest of all and maybe the most frequently used. You will find nothing difficult in understanding it, and if you do, you will surely find the answer in the course videos.

The CASE statement is like the SWITCH-CASE statement in the C-based languages. In the beginning I had some issues getting used to the CASE-WHEN construct, but it wasn’t hard to learn. It even turned out that the ABAP way is easier to read and understandable. In that context I’ll make a quick comparison between ABAP and Java to show you what I mean:

ABAP JAVA
JAVA_SWITCH_STATEMENT ABAP_CASE_STATEMENT

Just to say something about the logical operators, and especially – the text form of those in ABAP. It’s really good that the text form is mentioned in the course. Apparently this form was used a lot by the old ABAP developers. I had to do minor changes in some ABAP code in my company and it turned out all the logical expressions in the program were in the text form. I have to thank Mr. Moxon for including this in the videos.

Loops

Loops are the other key element of a program. And in ABAP, giving you work with big amount of data and thousands of records, you simply couldn’t do without loops. I’ve already mentioned the SELECT loop which iterates through the tables’ contents. The other loops explained in the course are DO and WHILE.

I found the DO loop very convenient the first time I saw it. In Java and C/C++ you have to increment a variable to count loop iterations and in ABAP the DO loops does it for you.

One thing I can advise you (it is also mentioned in the video) is to pay attention to loop termination statements. You don’t want to end up terminating a whole block of code, so you should be careful when using CHECK and EXIT. I made some mistakes with those statements but fortunately in my example programs, so no one suffered.

This is a guest article is by Plamen Velkov, who is taking my Beginners Guide To SAP ABAP programming course. This is part 6 of his course review / journey.

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