SAP Knowledge Base Article - Public

3442962 - Custom logic error message based on user language - SAP S/4HANA Cloud

Symptom

Using system parameter sy-langu inside a custom logic in key user extensibility.

Environment

SAP S/4HANA Cloud

Reproducing the Issue

1. Opening a custom logic that has a message class as changing/exporting parameter.

2. Using the following code:

        "  IF sy-subrc = 0.
        "      ls_message-messagetype = 'E'.
        "      ls_message-messagevariable1 = lv_message.
        "      APPEND ls_message TO messages.
        "  ENDIF.
3. lv_message should be displayed in user language.

Cause

Restricted ABAP is used in the Custom Logic app which means not all system tables and functions can be used. This is described in the blog S/4HANA Extensibility Concept Details: Restricted ABAP - SAP Community.

Statements in ABAP for Key Users | SAP Help Portal which contains a complete list of allowed keywords and statements.

SY-LANGU is not available for use in Custom Logic.

Resolution

As an alternative, you can create a custom code list with a code for every message. You can maintain the descriptions for the codes in the languages that you want to support. With the following code you can retrieve a message in the user’s logon language. Please refer to Custom Code Lists | SAP Help Portal.

For example:

          IF sy-subrc = 0.

              SELECT SINGLE FROM YY1_CODELIST fields description WHERE code = '01' into @data(lv_message_in_logon_language). 
              ls_message-messagetype = 'E'.
              ls_message-messagevariable1 = lv_message_in_logon_language.
              APPEND ls_message TO messages.

          ENDIF.

For more information, please refer to Using Language-Dependent Texts or Messages | SAP Help Portal

 

In the context of Developer extensibility, a second option would be creating a BAdI as per Implementing BAdIs | SAP Help Portal. System parameter sy-langu is available in developer extensibility (ABAP System Fields - ABAP Keyword Documentation).

Keywords

sy-langu, key user abap, restricted abap, custom logic, user language , KBA , BC-SRV-APS-EXT-BL , Custom Business Logic , Problem

Product

SAP S/4HANA Cloud Public Edition all versions ; SAP S/4HANA Cloud all versions