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

921

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)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Tuesday and Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP - XCO Logging

Category - ABAP

The XCO classes are part of the ABAP Cloud APIs and offer numerous functions that aren't always easy to understand. In this article, we'll take a detailed look at the logging object.

12/16/2025

ABAP - The right Key

Category - ABAP

What about the use of internal tables? Is it still just TYPE TABLE in ABAP, and the table is fully defined?

11/14/2025

ABAP - XCO Regular Expressions

Category - ABAP

Let's take a look at the XCO classes for regular expressions and how you can easily use them to execute REGEX against text and input in ABAP Cloud. We'll also compare them with classic ABAP.

11/07/2025

ABAP - Escape

Category - ABAP

In this article, let's take a closer look at different escape variants that you need for ABAP development and system security.

10/07/2025

ABAP - Date and Time

Category - ABAP

In this article, let's take a closer look at the data types for dates and times in ABAP. Have any changes been made between the various releases, and what should you still use today?

10/03/2025