Skip to content
Aug 14 16

New Features in ABAP 7.4 – Conditional Logic

by admin
Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

ABAPAnthony Cecchini is the President of Information Technology Partners (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 20 years of experience in SAP business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at ajcecchini@itpsap.com.

Conditional Logic in ABAP 7.4

In ABAP 7.40, the IF/THEN and CASE constructs you know and love keep on getting easier. let’s take a detailed look!

Functional Methods in Logical Expressions

One of the great features of ABAP 7.02 was the concept of functional methods and how you could use them in logical expressions. Functional methods allow you to eliminate the use of a helper variable. Thus, you can simplify the code. lets review a quick example…

Without Functional Method.

LV_HELPER = STRLEN( LV_STRING ).
IF LV_HELPER > 10 THEN…..

With Functional Method.

IF STRLEN( LV_STRING ) > 10 THEN…

And the same principle applies to return variables from method calls, so you can have code that looks like the statement below…

IF zcl_system=>is_production( ) = abap_false...

Omitting ABAP_TRUE

When functional methods were first introduced in ABAP, the idea was that this would make the code read like English. Over the years, the general consensus both inside and outside of SAP was that if you were creating a method that returned a value declaring whether or not something is true, then the returning parameter should be typed as ABAP_BOOL.

So you began seeing code that looked something along the lines below…

IF zcl_system=>is_production( ) = abap_true.
"In production we never want a short dump
    TRY.
      zcl_application=>main( ).
      CATCH cx_sy_no_handler INTO gcl_no_handler.
    ENDTRY.

Why do you need the = ABAP_TRUE at the end? It seems apparent what resukt we are looking for. The answer is that you had to do this, because otherwise the syntax check would fail. Well, as of release 7.4 (SP 8), you can now omit ABAP_TRUE.

IF zcl_system=>is_production( ).
"In production we never want a short dump
    TRY.
      zcl_application=>main( ).
      CATCH cx_sy_no_handler INTO gcl_no_handler.
    ENDTRY.

Why does this work? Well from a technical point of view, if we do not specify anything after the functional method, the ABAP 7.4 compiler evaluates it as IS_PRODUCTION( ) IS NOT INITIAL. An ABAP_TRUE value is really the letter X, so the result is not initial, and the statement is resolved as true.

That being said, you have to be really careful though when using this syntax; it only makes sense when the functional method is passing back a parameter typed as ABAP_BOOL.

Using XSDBOOL as a Workaround for BOOLC

Another common situation with respect to Boolean logic in ABAP, is when you want to send a TRUE/FALSE value to a method or get such a value back from a functional method. For instance, did you ever stumble over this one?

Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest
Jul 18 16

New Features in ABAP 7.4 – Calling Methods and Functions

by admin
Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

ABAPAnthony Cecchini is the President of Information Technology Partners (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 20 years of experience in SAP business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at ajcecchini@itpsap.com.

Calling Methods and Functions in ABAP 7.4

This blog will discuss the new ABAP 7.4 functionalities that make calling functions and methods easier to code and easier to read. lets start with METHOD CHAINING.

Method Chaining

You can now directly pass the returning value of one method call to a next method call without using any helper variable. This is referred as method chaining. Previously it was only allowed to create a chain of statements using attributes of the class. Now you can include methods as well as attributes in a chained call. Method chaining is available since ABAP Release 7.0 EhP2.

Don’t get it confused with the chained statements, which You write using colon symbol colon symbol ( : ) .

We can directly pass the result of one method into the input parameter of another method without the need for a helper variable. Normally, we would declare a helper variable, fill it with the result of a method call, and pass that helper variable into another method. When using this chain of method feature, we reduce a lot of helper variables. This should improve code readability. Lets take an example.

CATCH zcx_exception INTO lo_exception.
ld_helper = lo_exception->get_text( ).
zcl_my_screen_message=>output( id_text = ld_helper ).

By using Method Chaining, we can do away with having to declare the ld_helper variable by chaining the two method calls together.

CATCH zcx_exception INTO lo_exception.
zcl_my_screen_message=>output( id_text = lo_exception->get_text( ) ).

OK, I can hear you… Big Deal! At first this may not seem like much of a saving, but the benefit increases proportionately to the number of related method calls that are made one after the other.

Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest
Jun 13 16

New Features in ABAP 7.4 – String Processing

by admin
Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

97be63abb66b42f281dff9197b6b35da_WglrP9Anthony Cecchini is the President of Information Technology Partners (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 17 years of experience in SAP R/3 business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at ajcecchini@itpsap.com.

String Processing in ABAP 7.4

Some fairly major changes to string processing were introduced with release of ABAP 7.2 and ABAP 7.4. But if you read this blog, you won’t have any problems answering ABAP string processing interview questions!

Here are some of the more important changes to string processing in ABAP 7.2 and ABAP 7.4:

» Chaining Operator: chain two character-like operands into one new character string.

» String Templates: the option to create a character string out of literal texts, expressions, and control characters.

» Character String Functions: built-in functions

Chaining Operator

The Chaining Operator && can be used to create one character string out of multiple other strings and literals. The use of the chaining operator largely replaces the CONCATENATE statement. In this example, three variables are concatenated together using the && chaining operator.

DATA: v_var1 TYPE char30, 
      v_var2 TYPE char30, 
      v_var3 TYPE char30.
DATA: lv_result TYPE string.   

v_var1 = 'Building'. 
v_var2 = 'A'. 
v_var3 = 'String'.   

lv_result = v_var1 && v_var2 && v_var3. 
WRITE: /(30) 'Using &&', lv_result
While this definitely saves a bit of room in your code, it does not seem to handle the spaces you often want between variables very well. Well, to solve that, we have String Templates…
Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest
May 15 16

New Features in ABAP 7.4 – Declaring and Creating Variables

by admin
Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

97be63abb66b42f281dff9197b6b35da_WglrP9Anthony Cecchini is the President of Information Technology Partners (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 17 years of experience in SAP R/3 business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at ajcecchini@itpsap.com.

Declaring and Creating Variables in ABAP 7.4

One of the main differences between ABAP and other languages is that in ABAP we have been taught to declare all our variables at the start of the program—for example, in the TOP INCLUDE. While this may be an Official ABAP programming Guideline, many of my ABAP brethren will declare a variable just before it is used. This helps with context and readability.

The good news is that as time goes on, changes in the ABAP language make this unofficial practice more and more acceptable. This blog will discuss several features that contribute to this shift.

Omitting Data Type Declarations

In ABAP the compiler knows what data type it wants, in fact it has to know in order to be able to perform a syntax check, so why not let it decide the data type of your variable and create it? This is the very feature now available to us in ABAP 7.4. In the examples ahead, you will see how letting the compiler decide the data type—instead of declaring it yourself—can save you several lines of code.

For instance, here is some code you are probably used to …

Before ABAP 7.4

DATA: lv_vehicle TYPE string.
lv_vehicle = 'Mercedes'.

What if instead, you could code this…

With ABAP 7.4

DATA(lv_vehicle) = 'Mercedes'.

OR this…

Before ABAP 7.4

DATA: lv_rows TYPE i.
lv_rows  = LINES( itab)

Becomes…

With ABAP 7.4

DATA(lv_rows) = LINES( itab ).

As you can see, this has the potential to dramatically reduce the number of lines in your programs. The new declaration operator DATA(…) is called an inline declaration.

What about field symbols? Well For field symbols there is the new declaration operator FIELD-SYMBOL(…) that you can use now. Lets look at the 3 examples of how to use this new operator below…

With ABAP 7.4

ASSIGN ... TO FIELD-SYMBOL(<fs>). 

LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).
...
ENDLOOP. 

READ TABLE itab ASSIGNING FIELD-SYMBOL(<line>) ...

read more…

Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest
Apr 17 16

New Features in ABAP 7.4 – Database Access

by admin
Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

97be63abb66b42f281dff9197b6b35da_WglrP9Anthony Cecchini is the President of Information Technology Partners (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 17 years of experience in SAP R/3 business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at ajcecchini@itpsap.com.

Introduction to ABAP 7.4

As time has gone by, more and more commands and constructs have been added to the ABAP language. While nothing has been taken away, this is to ensure backward compatibility, the rate of change seems to be accelerating. While many changes came as a result of the introduction of SAP NetWeaver 7.02, that is nothing compared to the deluge of change that came with version 7.4.

This blog series will focus on the changes that came with version 7.4 by breaking the blog up into sections a developer would normally be interested in, like string processing, or conditional logic…etc. Since you and I are developers, we tend to spend a good bit of time accessing the database when developing ABAP programs, so let’s begin this series here….

New Commands in OpenSQL for ABAP 7.4

CASE Statements In OPEN SQL Queries in ABAP 7.4

One of the new features of ABAP 7.4 is the ability to insert CASE statements into SQL queries. The code below shows an example of this. In this example there is a field in a local structure named ERNAM, and it should be filled with the literals “NAME1″, “NAME2″, or “NAME3″ respectively, depending on the contents of the database field AUART (DocType).

DATA: ls_vbak TYPE vbak,
      ld_vbeln LIKE vbak-vbeln.

PARAMETERS: p_vbeln like vbak-vbeln.

CONSTANTS: lc_name1(5) TYPE c VALUE 'name1',
           lc_name2(5) TYPE c VALUE 'name2',
           lc_name3(5) TYPE c VALUE 'name3'.

ld_vbeln = p_vbeln.

SELECT vbeln, vbtyp,
 CASE
   WHEN auart = 'ZAMA' THEN @lc_name1
   WHEN auart = 'ZACR' THEN @lc_name2
  ELSE @lc_name3
END AS ernam
FROM vbak
WHERE vbeln = @ld_vbeln
 INTO CORRESPONDING FIELDS of @ls_vbak.
ENDSELECT.

You will notice that you have to put an @ symbol in front of your ABAP variables (or constants) when using the fancy new features, such as CASE, in order to let the compiler know that you are not talking about a field in the database. (This is called “Escaping” the Host Variable).  You also have to put commas between the fields you are bringing back from the database and put the INTO statement at the end. This is a result of a new “strict” syntax check that comes into force when the compiler notices you are using one of the new features. In other words, if you try and use a new feature like a CASE statement in an SQL query but do not put an @ symbol beside the variable name, then you will get a hard error. In this way, SAP can still being backward compatible.

read more…

Recommend This Post! Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Pin on Pinterest

Pin It on Pinterest