This is a test message to test the length of the message box.
Login
Rules for data definition
Created by Software-Heroes

ABAP - Rules for data definition

For the inline declaration of variables, there are special rules to watch out for. We want to give you a closer look in this article.

Advertising

As we described in the last article, the definition of data types and variables has become a bit simpler and clearer. For simple assignments, this also works in all cases, especially if there is a returning parameter.

A returning parameter always returns a variable, structure or table and is uniquely defined. Therefore, you can save the result of the return directly in a new created variable.


" Create data for returning parameter
DATA(ld_erg) = lo_obj->get_data( ).

" Create with a function
DATA(ld_cnt) = LINES( lt_t001 ).

For explanation:

  • The first example calls the get_data method of the object lo_obj, which returns a result as the returning parameter.
  • In the second example, the number of rows of the table lt_t001 is determined and made available as a variable in the program.

 

Hint: A returning parameter of the REF TO DATA type is also clearly defined, which fits very well for generic data returns.

 

Methods

In addition to the returning parameters, export parameters of methods can also be defined at runtime in the program. If a method provides a large number of export parameters, they can be generated quickly at runtime when the method is called, which provides a lot of overview in your coding.


" Method call
lo_obj->get_parameter(
  EXPORTING
    id_key     = ld_key
    id_name    = 'Text Example'
  IMPORTING
    et_data    = DATA(lt_data)
    et_address = DATA(lt_address)
    et_num     = DATA(lt_num)
    es_header  = DATA(ls_head)
    ed_count   = DATA(ld_cnt)
).

Normally in this case 5 variables would have to be created in the head of the method or the form, which will then save the values, but this will now be omitted.

 

Function module

For function modules this "fast" feature does not work. Returning parameters do not work with function modules, changing parameters also and exporting parameters must be defined in the calling program. Even for the parameters that have a clear type, the inline declaration does not work.

This has two reasons:

  • The compiler would complain if there are not clearly defined data types in the interface
  • RFC-able function modules do not necessarily have to be known in the system, so the data types that are used are not known

 

Trick 17

However, to ensure that the logic still works for BAPIs or function modules, you can also embed them in a method, especially if you then need that BAPI more often. Thus, an inline declaration of the variables is possible, especially since BAPIs usually have quite extensive return structures.

So you realize, even for this problem, there is a solution. But you should not use it in any case, only when it's worth and you use it more often.

 

Summary

So you have learned that there are additional special rules when using function modules and methods, but these are not so complicated and easy to implement.


Included topics:
New ABAPDATAInline declaration
Comments (0)
Advertising

ABAP - Performance for the SELECT

Category - ABAP

In this article we will look at a few special cases with the SELECT and examine the performance of these constructs. We'll show you the current alternatives and give you little tips while reading.

04/02/2021

ABAP - Check objects (Instances)

Category - ABAP

In this article we will show you how you can analyze instances and react to them correctly, for example if you hand them over during processing and want to react individually.

03/19/2021

ABAP - Loops

Category - ABAP

With New ABAP, new loops and possibilities for restricting table contents were created. We'll take a closer look at these new commands in this article.

02/19/2021

ABAP - Comparison

Category - ABAP

Today we'll look at comparisons and comparison operators in terms of the new commands and their current usage. What has changed so far and what should still be done?

02/12/2021

ABAP - String Functions (Part 3)

Category - ABAP

This article is about other new string functions and a replacement for CONDENSE. We would like to show you why you should use the new functions.

01/22/2021

We use cookies for our services and functions. More informations