This is a test message to test the length of the message box.
Login
ABAP Quick Generic types
Created by Software-Heroes

ABAP Quick - Generic Data Types

413

What exactly distinguishes CLIKE from CSEQUENCE? Generic types can sometimes be a bit opaque, and as ABAP developers, we might choose a type that's too generic.



In this article, we'll look at the topic of generic data types and how you can easily handle them in the future to find the perfect type for you.

 

Introduction

What exactly are generic data types? They are a grouping of various base types into a superordinate category. For example, if you define a transfer parameter with them, you can pass specific data types to the interface without having to perform a conversion beforehand. If a type doesn't fit into the parent group, you'll see it highlighted by the compiler.

 

Generic Types

The various generic types can be divided into different subcategories, which we'll look at in this chapter. You'll find a good overview in SAP Help (see link below).

 

Elementary

There are numerous elementary data types in ABAP, from characters to dates to strings, a wide range of types is represented. Therefore, there are also a large number of generic types. These types represent groups of elementary data types that you can then use in the interface. To return to the initial question, what is the difference between CLIKE and CSEQUENCE?

  • CSEQUENCE - Possible types are C and STRING.
  • CLIKE - Possible types are C and STRING, but also D (date), T (time), and N (numeric character).

 

Would you also imagine CLIKE as a date or a time when you read the name of the type (character-like)? This could lead to problems during processing, and you might want to look at CSEQUENCE if you actually want to receive text.

Other generic types summarize the various numbers, such as DECFLOAT or NUMERIC. If you don't really care and want to use a basic type, you can also use SIMPLE.

 

Complex

Complex types include structures, tables, and meshes. The generality here is primarily found in the various table types. Since access to the different types can vary, there are specific types and summaries. For example, INDEX TABLE groups together Standard and Sorted tables, since you can access both of these with a numeric index.

DATA(selected_entry) = table[ 1 ].

 

If, for example, the type of table is unimportant to you, you can also specify ANY TABLE, which allows all types of tables to be passed to your interface.

 

Object

One of the simplest types is objects; these basically only include the class and the interface. In most cases, you specify the interface in the interface, since you can map different classes that implement the interface here anyway. If you want to allow all types of objects that do not share the same base class or interface, you can use OBJECT.

 

Generic

If you want to allow everything, you can use ANY or DATA. But be careful, since all types of data can now be passed, you must be able to handle them. Otherwise, you should decide to use a more specific type.

 

ABAP Generic Types

We've talked about the various generic data types, but what about their application and use? Generally speaking, you shouldn't work too generically, so use ANY if you only want to allow text. We provide you with a small tool for this on our website: ABAP Generic Types. In the tool, you select the data types that your method, for example, should support.

 

After execution, you will receive a list of possible data types, from the most specific type to the most general type. This allows you to see at a glance which generic data type is suitable for your scenario and what you could also obtain using it.

 

Hint: If you simply want an overview, you can also run the tool without restrictions. You will then receive a list of all generic data types and their assignments.

 

Complete Example

You can find the complete example of the test program in the GitHub repository, where the configuration for the tool is also located. If you would like to experiment with the types, please take a look at this class.

 

Conclusion

With the help of the documentation and our tool, you should now be able to make the right choice for you. In the next project, the scope for the handover should be appropriate, and you should not experience any surprises or terminations.

 

Source:
SAP Help - Types and Objects


Included topics:
QuickData typeGeneric
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 Quick - Handling of Function modules

Category - ABAP

How do you actually handle function modules and error handling within ABAP? In this short tip, we'll also look at handling them within the context of RFC.

08/26/2025

BTP - Quick Deployment

Category - ABAP

Want to make Fiori Elements apps available even faster after RAP modeling? Quick Deployment is now possible.

07/18/2025

Recycling Heroes (Explained)

Category - ABAP

What do the Recycling Heroes have to do with modern ABAP development and ABAP Cloud? In this article, we provide insights into the idea.

07/15/2025

ABAP Quick - Ranges and Select Options

Category - ABAP

Ranges and Select Options in ABAP are very similar, yet there are subtle differences in their use in the ABAP OO context. Here we'll look at their modern usage.

05/09/2025

ABAP Quick - Generic Query Implementation

Category - ABAP

Tired of the same old query class implementation for custom entities in RAP? It's time for a reusable component.

04/22/2025