This is a test message to test the length of the message box.
Login
|
ABAP XCO Message and Language
Created by Software-Heroes

ABAP - XCO Message and Language

982

What else can you do with messages and the language objects of the XCO library in ABAP Cloud? Let's explore this question in more detail.



The XCO classes are helper classes that provide various everyday functions bundled together under a public API. Further information and an overview of the XCO libraries can be found on the overview page.

 

Introduction

In this article, we'll look at message handling and the various functions in this area. We'll also look at the languages and how you can use them in development.

 

Language

Let's start in the first chapter with an analysis of the language and what you can use it for. If you've followed the previous XCO articles, we've already had access to the current language in the system fields.

 

Creation

If we want to create a specific language, we call the factory via XCO_CP and pass the language in SAP format. Basically, we would like the factory to be a bit more flexible and also accept languages in ISO format.

DATA(language) = xco_cp=>language( 'E' ).

 

Methods

Various methods are then available to us via the object. Using VALUE, we access the object's set language, and the various methods provide further information about the language.

 

Let's execute the methods once and access the various values. Using VALUE, we access the SAP language; we can output the short and long text, and using the AS method and the XCO_CP_LANGUAGE class, we access the ISO code of the language.

language->value
language->get_long_text_description( )
language->get_name( )
language->as( xco_cp_language=>format->iso_639 )

 

Let's look at the output for German and English.

 

A final fun fact: Internally, the two texts are only read via the table T002TX and not via a corresponding Core Data Service. Before that, however, the ISO is derived using the function module CONVERT_SAP_LANG_TO_ISO_LANG, which in turn calls the classic conversion exit.

 

Message

In this chapter, we'll look at the messages we can generate using the XCO_CP class and what we can then do with them.

 

Creation

Similar to the language, we can create a new message object using the factory. Unlike the system fields, we can pass all the information here and receive our message back.

DATA(message) = xco_cp=>message( VALUE #( msgid = 'ZBS_DEMO_XCO'
                                          msgno = '001'
                                          msgty = 'W'
                                          msgv1 = 'Message'
                                          msgv2 = 'Placeholder' ) ).

 

With the message, we now have several options and methods available.

 

Output

Using the VALUE attribute, we access the structure with the message and the individual fields. Using GET_TEXT, we receive the complete message with all placeholders filled in.

message->value
message->get_text( )

 

Types

We can access the current message type using the GET_TYPE method. In our example, we generated a warning, W.

DATA(type) = message->get_type( ).

 

We can then access the individual value (W) using VALUE. If we have a second message, we can use OCCURS_IN to check whether the type is also contained in our current message.

DATA(compare) = xco_cp=>message( VALUE #( msgid = 'ZBS_DEMO_XCO'
                                          msgno = '001'
                                          msgty = 'W'
                                          msgv1 = 'Test'
                                          msgv2 = 'Compare' ) ).

type->value
type->occurs_in( compare )

 

Comparing two messages isn't quite as useful, but if we use the different types of the XCO_CP_MESSAGE class, we can check whether our message is a warning or an error.

xco_cp_message=>type->warning->occurs_in( message )

 

Replace

How can we change components of a message? We have two methods available for this. With OVERWRITE, we can specifically overwrite individual components of the message; all fields are offered here. In this example, we overwrite placeholder 2.

DATA(overwrite) = message->overwrite( iv_msgv2 = 'New' ).

 

Using the PLACE_STRING method, you can insert text into the various placeholders. To do this, you pass a string and the import parameters you want to overwrite. Please note, however, that a placeholder can only have 50 characters.

DATA(new_place) = message->place_string( iv_string = `Place me`
                                         iv_msgv2  = abap_true ).

 

Messages

The MESSAGES object is a simple container for passing or storing multiple messages. To do this, we fill the container with our two messages from the previous example.

DATA(message_container) = xco_cp=>messages( VALUE #( ( message ) ( compare ) ) ).

 

For output and further processing, we could now loop over VALUE and process the messages individually. However, this object has no other methods.

LOOP AT message_container->value INTO DATA(local_message).
  out->write( local_message->get_text( ) ).
ENDLOOP.

 

Complete Example

You can find the complete example of both classes in our GitHub repository. In this commit you will find the changes from today's article and can replicate the steps in your system.


 

Conclusion

The two objects offer some small additional functions in the form of access to master data, simpler mappings, and derivations. In addition to filling messages, you can also modify them and forward them via a message container.


Included topics:
Modernes ABAPXCOMessageLanguage
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 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 - XCO Class Runner

Category - ABAP

What about the execution of ABAP classes in the XCO area? Let's take a closer look at the Class Runner.

02/04/2025

ABAP - XCO Excel

Category - ABAP

What can the XCO library for Excel in ABAP actually do? Here we look at the current status of the API.

11/29/2024

ABAP - SELECT FROM @itab

Category - ABAP

Selecting via an internal table used to be realized with many lines of code, but today it also works practically via the select.

01/20/2021