创建一个简单的ABAP Daemon

本文档介绍了如何创建和运行ABAP Daemon,包括使用ABAP Messaging Channels和Push Channel Protocol与之通信。通过实现ABAP Daemon类的ON_ACCEPT、ON_START、ON_TIMEOUT和ON_MESSAGE方法,你可以设置定时器、处理消息并接收来自其他程序的PCP消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You will learn

  • How to create and run an ABAP Daemon
  • How to send PCP messages to an ABAP Daemon

Introduction to ABAP Daemons

ABAP Daemons are provided by the ABAP Daemon Framework (ADF). They are used to handle events in a reliable way by running in sessions with unlimited lifetime. ABAP programs can communicate with the daemons by sending messages to them using ABAP Messaging Channels and message type Push Channel Protocol.

You can make yourself more familiar with the ABAP Daemon Framework by reading the official documentation.

Push Channel Protocol (PCP) is a communications format similar to a simple HTTP message. It consists of header fields (name-value pairs) for metadata and a message body. For further information, have a look at the Specification of the Push Channel Protocol.

Step 1: Create a new ABAP Daemon class

ABAP Daemons are instances of an ABAP Daemon class that extend the base class CL_ABAP_DAEMON_EXT_BASE.

First, create a new ABAP class ZCL_TUTORIAL_SIMPLE_DAEMON and set CL_ABAP_DAEMON_EXT_BASE as its superclass.

As you can see there is an error in line 1 since the necessary abstract methods have not been implemented yet. Click on the light bulb next to the line number and select Add 9 unimplemented methods to resolve this:

Add unimplemented methods in ABAP Development Tools

完成

Log on to answer question

Step 2: Implement ON_ACCEPT method

Before a new instance of the ABAP Daemon class can be created, its ON_ACCEPT method is called to determine if the daemon should start.

Replace your ON_ACCEPT method with the following code. It accepts all start requests from your own class and rejects all requests from any other program. This is achieved by checking the calling program that initiated the start.

abap

Copy

METHOD if_abap_daemon_extension~on_accept.
  TRY.
      DATA lv_program_name TYPE program.
      lv_program_name = cl_oo_classname_service=>get_classpool_name( 'ZCL_TUTORIAL_SIMPLE_DAEMON' ).

      IF i_context_base->get_start_caller_info( )-program = lv_program_name.
        e_setup_mode = co_setup_mode-accept.
      ELSE.
        e_setup_mode = co_setup_mode-reject.
      ENDIF.
    CATCH cx_abap_daemon_error.
      " to do: error handling, e.g. write error log!
      e_setup_mode = co_setup_mode-reject.
  ENDTRY.
ENDMETHOD.

完成

Log on to answer question

Step 3: Implement ON_START method

To start the ABAP Daemon, the ON_START method is executed.

You can include a PCP message containing arbitrary st

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值