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

432

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.



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 Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP - Type Casting

Category - ABAP

How do you actually get the original type of a class or instance if it is passed in a generic table? In this article we examine the possibilities.

04/16/2024

ABAP - RETURN value

Category - ABAP

After all these years, the “real” return in ABAP has finally arrived. In this article we will show you how it works and what it can do.

02/13/2024

ABAP Deep Dive - FOR (Loops)

Category - ABAP

Let's take a closer look at the FOR loop. How does it work? What do I have to consider and what can I do with it?

04/14/2023

ABAP Deep Dive - Table access (internal)

Category - ABAP

In this article, let's take a look at table access to internal tables and how they replace READ TABLE.

02/03/2023

ABAP Developer still relevant

Category - ABAP

In this article we look at whether ChatGPT can already replace an ABAP developer or whether it can be used as a help in everyday life.

01/06/2023