
RAP - Message Length
Is your message truncated when outputting with RAP? Let's look at the problem and a solution.
Table of contents
In this article, we'll look at the length of messages output in RAP and how this affects our capabilities.
Introduction
The output of messages in RAP applications is just as important as it was in the days of reports. Messages provide us with information about errors in and during processing. The user knows when something is wrong and can react accordingly. Today we want to extend our Custom Pattern with an action and, in this context, look at the output of messages.
Preparation
To do this, we first need to implement an action in our RAP object so that we have a way to transmit messages to the frontend.
Behavior
In the first step, we extend the behavior with a new action called "CreateOutputMessage". We'll use a static action because we want to trigger this without marking a record.
static action CreateOutputMessage;
We can implement the method using CTRL + 1. The function creates the definition and implementation in the behavior implementation.
Visibility
For the action to appear in the UI, we need to add it to the entity in the UI annotations. Since we want to see it above the list in the list report, we extend the list item.
@UI.lineItem: [{ position: 10, type: #FOR_ACTION, dataAction: 'CreateOutputMessage', label: 'Create message' }]
After activating the objects, the action should now be available in the List Report.
Messages
To send a message to the UI after the action is triggered, we have the "reported" structure in the method. We can return a variety of messages via %OTHER or via the corresponding entity, in this case "swc" A corresponding message for a key is generated via the %MSG field.
We can generate messages of the type IF_ABAP_BEHV_MESSAGE using the two methods "NEW_MESSAGE" and "NEW_MESSAGE_WITH_TEXT". You can find the definition of both methods through the inheritance hierarchy in the class CL_ABAP_BEHV.
- NEW_MESSAGE - Creates a T100 message for output
- NEW_MESSAGE_WITH_TEXT - Accepts a text and outputs a message
These two methods allow us to easily create messages during processing. In principle, you can also define your own message object to output messages.
Creation
In this chapter, we will create messages and check the output results.
NEW_MESSAGE_WITH_TEXT
In the first step, we will create a message in which we only pass a text. The text is relatively long. In this case, we use %OTHER to pass different messages.
INSERT new_message_with_text( text = 'This is a message with the method NEW_MESSAGE_WITH_TEXT!' ) INTO TABLE reported-%other.
This results in the following output in the UI. If we take a closer look at the message, you will notice that it has been truncated. Not all components of the message have been output.
If we now examine the message generation in the CL_ABAP_BEHV class, we will find the following source code. Our text is passed to a message variable. If you check the characters in the output, you will notice that the message has been truncated after 50 characters, which corresponds to the length of a message variable.
obj = new_message(
id = 'SABP_BEHV'
number = 100
severity = severity
v1 = text
).
This currently allows us to create messages with a maximum length of 50 characters without truncating information.
NEW_MESSAGE
In the next example, we create a message using the second method. To do this, we create a new message in our message class ZBS_DEMO_RAP_PATTERN and add a placeholder to the message.
INSERT new_message( id = 'ZBS_DEMO_RAP_PATTERN'
number = '009'
severity = if_abap_behv_message=>severity-error
v1 = 'NEW_MESSAGE' )
INTO TABLE reported-%other.
The output now includes the entire message plus the placeholder, and no information is lost in the output. Basically, we have four times the 50 characters available, plus a small portion of the message. However, you should still not exceed the 220-character limit.
Maximum
You can check the maximum of 220 characters relatively easily. To do this, we create a new message with four placeholders and fill the message text to a maximum of 74 characters. We then create a message and pass placeholders of 50 characters each.
DATA(placeholder) = '01234567890123456789012345678901234567890123456789'.
INSERT new_message( id = 'ZBS_DEMO_RAP_PATTERN'
number = '010'
severity = if_abap_behv_message=>severity-error
v1 = placeholder
v2 = placeholder
v3 = placeholder
v4 = placeholder )
INTO TABLE reported-%other.
We can then see the result in the popup and count the string.
Complete example
You can find the entire application on our GitHub with the remaining examples from the RAP area. You can track all changes to the repository via the commit.
Conclusion
You should currently avoid using the NEW_MESSAGE_WITH_TEXT method to generate messages, as this results in information being lost. Instead, use normal T100 messages with NEW_MESSAGE or your own implementation of the class to pass messages to the user.