Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP Channels 

AMC - ABAP Messaging Channels

ABAP messaging channels (AMC) are a method of communication between ABAP programs using messages. Messages can be exchanged between any AS ABAP programs, including communication between different user sessions and application services. Data objects with specific data types are allowed as messages. Messages that can be sent and received are:

  • Text strings
  • Byte strings
  • Content that can be serialized in accordance with fixed protocols. Helper classes are available for serializations and deserializations.

ABAP messaging channels are implemented as repository objects that can be accessed in sender and receiver programs using an interface-based an class-based programming interface (API). The classes and interfaces of the API use the naming convention CL_AMC_... and IF_AMC_... respectively. .

Other versions: 7.31 | 7.40 | 7.54


Notes

  • Any data object can be sent by being serialized in a suitable way by the sender and deserialized by the receiver. Possible formats include XML or JSON in strings or SAP's own Push Channel Protocol.

  • The length of messages that can be sent is currently restricted to approximately 30000 bytes. Character strings are converted to the UTF-8 format.

Messaging Channels as Repository Objects

An ABAP messaging channel defined as a repository object must exist for each AMC communication. ABAP messaging channels can be created in Repository Browser in ABAP Workbench by opening the context menu of a package and choosing Connectivity. Connectivity Browser in Object Navigator provides another means of access. To open Object Navigator for AMCs, use transaction SAMC.

An ABAP messaging channel is identified by its assignment to an application and by its name. The name must start with a forward slash character (/) and is not case-sensitive. The following properties can be defined for an ABAP messaging channel:

  • Message type
The message type determines the data type of the data objects that can be sent as messaging channels messages. Current scopes are
  • TEXT for text strings
  • BINARY for byte strings
  • Scope
The scope defines who can receive a message sent using this messaging channel. Current scopes are
  • System
All programs of all users sessions in the current AS ABAP can receive messages.
  • Client
All programs of user sessions in the current AS ABAP logged on with the same client ID as the sender program can receive messages.
  • User
Only programs of user sessions in the current AS ABAP logged on with the same user name and the same client ID as the sender program can receive messages.
No other restrictions apply apart from these settings. More specifically, it is possible to send and receive messages between different application servers.
  • Authorized programs
Each program that is authorized to send or receive messages using the messaging channel (or a predecessor program in the current call sequence) must be specified with the appropriate activity in a whitelist. Possible activities are:
  • Send, which authorizes the program to send AMC messages
  • Receive, which authorizes the program to receive AMC messages
  • Bind APC WebSocket as Consumer, which authorizes the program (usually the class pool of an APC handler class) to bind its WebSocket connection to an ABAP messaging channel. This makes the APC clients into AMC consumers.

Any violations of the rules defined by these properties for a messaging channel raise exceptions of the class CX_AMC_ERROR in sender and receiver programs.


Example

See the messaging channels /demo_text and /demo_binary of the application DEMO_AMC in the package SABAPDEMOS.

Sending AMC Messages

Before an AMC message can be sent in an authorized program, the factory method CREATE_MESSAGE_PRODUCER of the system class CL_AMC_CHANNEL_MANAGER must be used to create a sender object for a messaging channel from the repository. The application and name of the channel are passed here. The returned reference variable of type IF_AMC_MESSAGE_PRODUCER must be cast to a type-specific interface that contains a method SEND used to send type-appropriate messages. The following interfaces are possible, depending on the type of messaging channel used:

  • IF_AMC_MESSAGE_PRODUCER_TEXT
  • IF_AMC_MESSAGE_PRODUCER_BINARY
  • IF_AMC_MESSAGE_PRODUCER_PCP

Objects of the class CL_AC_MESSAGE_TYPE_PCP, which implement the interface IF_AC_MESSAGE_TYPE_PCP, can be used to create messages for the Push Channel Protocol.


Example

See Sending AMC Messages.

Receiving AMC Messages

Before an AMC message can be received in an authorized program, the factory method CREATE_MESSAGE_CONSUMER of the system class CL_AMC_CHANNEL_MANAGER must be used to create a consumer for a messaging channel from the repository. The application and name of the channel are passed here. The returned reference variable has the type IF_AMC_MESSAGE_CONSUMER. The consumer methods START_MESSAGE_DELIVERY and STOP_MESSAGE_DELIVERY have two tasks:

  • Definition of the AMC receiver phase
The method START_MESSAGE_DELIVERY makes the receiver program for the messaging channel of the consumer ready to receive messages. The method STOP_MESSAGE_DELIVERY undoes this step. Messages sent using the messaging channel are received only if the program is made ready to receive.
  • Registration of the receiver objects for messaging channel messages
Receiver objects are instances of local or global classes that implement at least one of the type-specific interfaces
  • IF_AMC_MESSAGE_RECEIVER_TEXT
  • IF_AMC_MESSAGE_RECEIVER_BINARY
  • IF_AMC_MESSAGE_RECEIVER_PCP
. These interfaces each have a RECEIVE method used as a callback routine for the messaging channel for which a receiver object is registered. The input parameters of the callback routines receive, appropriate to type, the messages sent during registration and can be processed or forwarded in the methods. An object of the class CL_AC_MESSAGE_TYPE_PCP, pointed to by the attribute PCP_MESSAGE of the receiver object, can be used to read messages in SAP's own Push Channel Protocol.
When the receiver objects are registered, object references to them are created in the AMC framework to keep them alive. It is also possible to deregister the objects using the method STOP_MESSAGE_DELIVERY. This deletes the references. The objects are deregistered implicitly at the end of the program.

Once one or more receiver objects have been registered, the statement WAIT FOR MESSAGING CHANNELS can be used to put the program in a wait state where it is ready to receive the messages. If, while the program is waiting, a message is received through a messaging channel for which a receiver object is registered, the associated RECEIVE method is executed and a check is made to see whether a logical condition is true or false. The wait state is persisted as long as the condition is false (but a maximum duration can be configured). In this way, multiple messages can be consumed until a message is received that ends the wait state.


Notes

  • The methods START_MESSAGE_DELIVERY and STOP_MESSAGE_DELIVERY both cause a database commit.

  • It is not possible to receive AMC messages during the update process.

Example

See Receiving AMC Messages.

AMC Security

Access to an ABAP messaging channel is controlled by specifying the authorized programs and their activities. When binding an APC WebSocket and when receiving using an APC WebSocket as a Consumer, it is also possible to specify a virus scan profile to be used for the check performed by the virus scan interface (VSI).

AMC - Test and Analysis

AMC messages are both sent and received in AS ABAP, which means that existing test and analysis tools, such as ABAP Debugger, runtime analysis, or performance trace can be used as previously. There is also a special AMC logger:

  • The transaction AMC_LOG_ADMIN can be used to switch AMC logging on and off for specific ABAP messaging channels.
  • The transaction AMC_LOG_PROCESSING can be used to manage the AMC log entries.

The transaction SMAMC provides an overview of all ABAP messaging channels for which AMC consumers are registered.

More Information

For more information about AMC, read the

SAP NetWeaver documentation in SAP Help Portal.

Continue

WAIT FOR MESSAGING CHANNELS

Examples of AMC