ABAP Daemon Framework

4869

What is ABAP Daemon?

ABAP Daemons are provided by the ABAP Daemon Framework (ADF). These are similar to Linux cron jobs or Windows Services.  ABAP Daemons are nothing but long-living ABAP sessions with unlimited lifetime. They are used to handle events in a reliable way by running in sessions.  These are contrary to other session types, i.e. HTTP, GUI or RFC sessions, daemons are robust against errors, Even if there is an ABAP runtime error, or a work process in the application server crashes, the ABAP Daemon session is not terminated and the session gets restarted immediately.  ABAP programs can communicate with the daemons by sending messages to them using ABAP Messaging Channels and message type Push Channel Protocol.

When do we use ABAP Daemons?

Most applications use either batch jobs or session-based polling techniques to detect an event (e.g. changes on shared tables or objects) and then apply the next required steps (e.g. synchronization of buffered/cached areas or execution of workflows and the like). With the introduction of ABAP Channels, more and more polling techniques are replaced by near real-time events. To subscribe to those events, a long-lived session is required that is mostly resilient against any kind of errors. ABAP Daemons provide this foundation. For example, we can go for ABAP Daemons when our customers need to trigger processing for large data to create or delete or modify the transactional data.

Which programming model is used by ABAP Daemons?

The ABAP Daemon programming is an event-driven programming model. Event-driven means a daemon application implements different methods e.g. ON_START, ON_MESSAGE, ON_ERROR, etc.

These methods are triggered by the ABAP Daemon runtime when the associated event has been received/created.

How does it work?

An ABAP Daemon application is an ABAP class that inherits from the superclass, i.e. ABAP Daemon base class, CL_ABAP_DAEMON_EXT_BASE. The instance generation of the ABAP Daemon class must be of type Public.

The ABAP Daemon base class CL_ABAP_DAEMON_EXT_BASE consists of the following event handling methods that should be implemented by the ABAP Daemon application class. Find those event handling methods in the below figure.

SAP Deamon

IF_ABAP_DAEMON_EXTENSION~ON_ACCEPT: This method is executed to allow the application to accept or reject the instantiation of the ABAP Daemon application. This decision can depend on the context information and start parameters provided optionally by the client.
By setting the export parameter e_setup_mode, the creation can be accepted or rejected.

IF_ABAP_DAEMON_EXTENSION~ON_START: This method is executed once after the daemon start has been accepted. It is used to establish the application specific context of the ABAP Daemon application. It is only called if the creation of the daemon has been accepted by method IF_ABAP_DAEMON_EXTENSION~ON_ACCEPT.

IF_ABAP_DAEMON_EXTENSION~ON_MESSAGE: This method is executed every time the daemon receives a message that has been sent by a client application via the associated ABAP Daemon Instance ID.

IF_ABAP_DAEMON_EXTENSION~ON_STOP: This method is executed as soon as the daemon receives a stop message. A stop message can be either sent via the associated ABAP Daemon Instance ID or triggered by the ABAP Daemon itself. After executing this method, the daemon will be terminated.

IF_ABAP_DAEMON_EXTENSION~ON_ERROR: This method is executed if the ABAP Daemon has been restarted because of an error.

IF_ABAP_DAEMON_EXTENSION~ON_RESTART: This method is executed when the application processes the interface method IF_ABAP_DAEMON_CONTEXT~RESTART. In this case, the ABAP memory has been freed before the ON_RESTART method is called.
Using this method, a daemon application can recreate its daemon context.

IF_ABAP_DAEMON_EXTENSION~ON_BEFORE_RESTART_BY_SYSTEM: This method is executed by the system when the daemon session is in an inconsistent state.

IF_ABAP_DAEMON_EXTENSION~ON_SERVER_SHUTDOWN: This method is executed when a soft shutdown is triggered for the application server. The daemon is stopped immediately after processing this method. It is reasonable to relocate the daemon and its context to an alternative application server in the system.

IF_ABAP_DAEMON_EXTENSION~ON_SYSTEM_SHUTDOWN: This method is executed when a soft shutdown is triggered for the entire system. The daemon is stopped immediately after processing this method.

You can monitor all running ABAP Daemons using the transaction SMDAEMON in SAPGUI. There you can see their state, check for errors, and also restart and terminate them.

Implementation of sample ABAP Daemon Application:
Implement your ABAP Daemon application class by inheriting the standard ABAP Daemon class cl_abap_daemon_ext_base. Along with implementing standard inherited methods, you need to add and implement 3 more static methods in your ABAP Daemon application class.

START: To start your ABAP Daemon.
SEND: To interact with Daemon using PCP protocol to send messages.
STOP: To stop or terminate ABAP Daemon.

Please find below implementation for your Daemon application class:

CLASS zcl_kk_sample_daemon DEFINITION
PUBLIC
INHERITING FROM cl_abap_daemon_ext_base
FINAL
CREATE PUBLIC .

PUBLIC SECTION.
METHODS: if_abap_daemon_extension~on_error REDEFINITION,
if_abap_daemon_extension~on_message REDEFINITION,
if_abap_daemon_extension~on_restart REDEFINITION,
if_abap_daemon_extension~on_server_shutdown REDEFINITION,
if_abap_daemon_extension~on_accept REDEFINITION,
if_abap_daemon_extension~on_start REDEFINITION,
if_abap_daemon_extension~on_stop REDEFINITION,
if_abap_daemon_extension~on_system_shutdown REDEFINITION,
if_abap_daemon_extension~on_before_restart_by_system REDEFINITION.
CLASS-METHODS start
IMPORTING
iv_daemon_name TYPE string
RAISING
cx_abap_daemon_error
cx_ac_message_type_pcp_error.
CLASS-METHODS send
IMPORTING
iv_daemon_name TYPE string
iv_text TYPE string
RAISING
cx_abap_daemon_error
cx_ac_message_type_pcp_error.
CLASS-METHODS stop
IMPORTING
iv_daemon_name TYPE string
RAISING
cx_abap_daemon_error.
CLASS-METHODS display
RAISING
cx_abap_daemon_error.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS zcl_kk_sample_daemon IMPLEMENTATION.
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_KK_SAMPLE_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.

METHOD if_abap_daemon_extension~on_before_restart_by_system.

ENDMETHOD.

METHOD if_abap_daemon_extension~on_error.

ENDMETHOD.

METHOD if_abap_daemon_extension~on_message.
TRY.
” get text from PCP message
DATA(lv_text) = i_message->get_text( ).
” display popup
CALL FUNCTION ‘TH_POPUP’
EXPORTING
client = sy-mandt
user = sy-uname
message = CONV th_popup( |Message received: { lv_text }| ).
CATCH cx_ac_message_type_pcp_error.
” to do: error handling, e.g. write error log!
ENDTRY.
ENDMETHOD.

METHOD if_abap_daemon_extension~on_restart.

ENDMETHOD.

METHOD if_abap_daemon_extension~on_server_shutdown.

ENDMETHOD.

METHOD if_abap_daemon_extension~on_start.

ENDMETHOD.

METHOD if_abap_daemon_extension~on_stop.

ENDMETHOD.

METHOD if_abap_daemon_extension~on_system_shutdown.

ENDMETHOD.

METHOD start.
” start the daemon application using the ABAP Daemon Manager
cl_abap_daemon_client_manager=>start(
i_class_name = ‘ZCL_KK_SAMPLE_DAEMON’
i_name = CONV #( iv_daemon_name )
i_priority = cl_abap_daemon_client_manager=>co_session_priority_low
).
zcl_kk_sample_daemon=>display( ).
ENDMETHOD.

METHOD send.
” retrieve the list of ABAP Daemon instances
DATA(lt_ad_info) = cl_abap_daemon_client_manager=>get_daemon_info( i_class_name = ‘ZCL_KK_SAMPLE_DAEMON’).

” create PCP message with text
DATA(lo_pcp) = cl_ac_message_type_pcp=>create( ).
lo_pcp->set_text( iv_text ).

” for each running daemon instance of this class
LOOP AT lt_ad_info ASSIGNING FIELD-SYMBOL(<ls_info>).

” send a message if the names match
IF iv_daemon_name = <ls_info>-name.
cl_abap_daemon_client_manager=>attach( <ls_info>-instance_id )->send( lo_pcp ).
ENDIF.

ENDLOOP.
ENDMETHOD.

METHOD stop.
” retrieve the list of ABAP Daemon instances
DATA(lt_ad_info) = cl_abap_daemon_client_manager=>get_daemon_info( i_class_name = ‘ZCL_KK_SAMPLE_DAEMON’).

” for each running daemon instance of this class
LOOP AT lt_ad_info ASSIGNING FIELD-SYMBOL(<ls_info>).

” stop the daemon if the names match
IF iv_daemon_name = <ls_info>-name.
cl_abap_daemon_client_manager=>stop( i_instance_id = <ls_info>-instance_id ).
ENDIF.

ENDLOOP.
ENDMETHOD.

METHOD display.
cl_Demo_output=>display( ‘This is sample ABAP daemon demo application’ ).
ENDMETHOD.

ENDCLASS.

Test your application using a report to start the ABAP Daemon:

Then if you execute the report and you can see the below result:

Interacting with sample ABAP Daemon by sending a message:

Now, if run the report you will be able to see a popup like below:

To stop the ABAP Daemon:

You can terminate your ABAP Daemon using the transaction SMDAEMON in sap GUI or else you can execute the below line of code from report to stop your ABAP Daemon.

zcl_kk_sample_daemon=>stop( iv_daemon_name = ‘sample_daemon’ ).

For further more information regarding ABAP Daemons: See the ABAP Daemon Documentation.

4,869 Comments

  1. sildenafil no rx on

    I’m commenting to let you be aware of of the beneficial discovery my child developed browsing the blog. She came to find a lot of details, including how it is like to have a great coaching character to get certain people completely comprehend a number of complex issues. You actually did more than her desires. I appreciate you for coming up with such effective, dependable, edifying and cool guidance on that topic to Ethel. https://johnpisanohomeimprovements.com/

  2. tadalafil online on

    I am only writing to make you understand what a really good experience my wife’s princess obtained viewing your webblog. She noticed some things, which included what it is like to possess an ideal teaching spirit to make others without difficulty learn about specific tortuous things. You undoubtedly surpassed readers’ expected results. Thanks for rendering those productive, trusted, informative as well as unique tips on your topic to Mary. https://hillsdaledowcenter.com/

  3. Needed to send you this very little word to finally thank you so much the moment again relating to the striking thoughts you have shared on this site. This has been simply tremendously open-handed with you to present unreservedly what most people would have sold for an electronic book to help with making some profit on their own, primarily seeing that you might well have tried it in the event you wanted. Those techniques likewise worked to become a great way to recognize that someone else have the same passion similar to my very own to see somewhat more with regard to this problem. I know there are some more pleasurable situations up front for people who see your website. https://gemerekliler.com/

  4. viagra viagra on

    I wanted to post you that tiny remark to say thanks a lot over again just for the pleasant solutions you have featured in this case. It was really shockingly open-handed with you to grant publicly just what many of us might have offered for an ebook to generate some dough for themselves, mostly now that you might have tried it in case you desired. These secrets as well served to be a good way to fully grasp that other people online have the identical fervor much like my personal own to know the truth more regarding this matter. I am sure there are numerous more pleasant periods in the future for many who read your site. https://gemerekliler.com/

  5. cialis generic on

    I am glad for writing to make you know what a nice encounter my wife’s girl had studying your web site. She mastered several pieces, which include what it’s like to possess an awesome helping nature to let other individuals very easily know precisely some problematic subject matter. You truly exceeded people’s expectations. Thank you for presenting these powerful, trusted, informative and in addition fun tips about this topic to Kate. https://azzaroelectric.com/

  6. levitra pills on

    I needed to post you that little bit of observation to say thanks once again for your personal magnificent principles you’ve featured in this article. It is quite tremendously open-handed with you to present unreservedly what most people would have sold for an electronic book to help with making some profit on their own, primarily seeing that you might well have tried it in the event you wanted. Those techniques likewise worked to become a great way to recognize that someone else have the same passion similar to my very own to see somewhat more with regard to this problem. I know there are some more pleasurable situations up front for people who see your website. https://eskaliths.com/

  7. order propecia on

    A lot of thanks for all your valuable efforts on this site. Kate loves engaging in investigation and it’s really easy to understand why. I know all concerning the dynamic medium you give important secrets on this web blog and as well as foster participation from others on that content plus our daughter is always discovering a lot. Have fun with the remaining portion of the new year. You are conducting a great job. https://harrington-service.com/

  8. kamagra no rx on

    I intended to compose you a bit of note in order to give many thanks again considering the beautiful basics you’ve contributed above. It’s extremely generous of people like you giving easily all a few people could have advertised as an e-book in making some bucks for their own end, certainly considering that you could have done it if you considered necessary. The basics additionally acted as a easy way to be aware that many people have a similar desire just as mine to figure out a great deal more concerning this condition. Certainly there are a lot more enjoyable instances ahead for folks who check out your blog. https://jlsmithjax.com/

  9. kamagra no rx on

    I intended to compose you a bit of note in order to give many thanks again considering the beautiful basics you’ve contributed above. It’s extremely generous of people like you to provide without restraint what exactly numerous people would have supplied for an electronic book to make some profit on their own, principally since you might well have tried it in the event you wanted. Those tips likewise worked to provide a great way to understand that the rest have the same zeal the same as my very own to understand way more with regards to this problem. I think there are thousands of more pleasurable times up front for those who take a look at your website. https://jlsmithjax.com/

  10. I am just writing to make you understand what a perfect experience my wife’s girl obtained using your webblog. She noticed so many pieces, which included what it is like to possess an excellent helping spirit to let others with no trouble learn about specific specialized things. You truly surpassed readers’ expected results. Thank you for providing these priceless, trusted, informative as well as fun tips about this topic to Lizeth. https://azzaroelectric.com/

  11. abilify tablets on

    I simply needed to thank you so much once again. I am not sure the things that I would’ve implemented without the type of recommendations provided by you on such a question. It previously was a very frightful dilemma in my opinion, however , noticing the very specialised mode you processed that made me to leap over gladness. I am just happy for this information and in addition hope that you know what a great job you are always getting into teaching people thru your web blog. More than likely you have never got to know any of us. https://abilifyaripiprazoles.com/

  12. generic finasteride on

    I am glad for writing to make you know what a magnificent encounter my friend’s girl gained studying your web site. She learned plenty of pieces, which include what it’s like to possess an awesome helping nature to let other folks very easily know just exactly several multifaceted subject matter. You truly exceeded people’s expectations. Thank you for presenting these powerful, safe, explanatory and in addition fun tips about this topic to Julie. https://harrington-service.com/

  13. amitriptyline pills on

    Thanks for your whole work on this website. My niece takes pleasure in working on research and it is simple to grasp why. We all notice all relating to the powerful ways you render vital tips and tricks via your website and therefore welcome response from website visitors on this topic while our own simple princess is without question understanding so much. Take pleasure in the rest of the year. Your performing a very good job. https://endepamitriptyline.com/

  14. I’m just commenting to let you be aware of of the exceptional discovery my cousin’s child enjoyed going through your blog. She discovered a wide variety of details, most notably how it is like to have a very effective coaching heart to get many more effortlessly fully understand certain extremely tough matters. You actually did more than my desires. I appreciate you for displaying such helpful, healthy, educational and also cool guidance on that topic to Evelyn. https://lexaproescitalopram.com/

  15. nortriptyline tablets on

    I simply wished to thank you very much yet again. I do not know what I would have worked on without those tricks shown by you relating to this topic. This was the troublesome situation in my view, nevertheless witnessing your well-written way you treated the issue took me to weep with joy. Now i am thankful for your work as well as wish you recognize what an amazing job your are undertaking training the rest with the aid of your websites. Probably you haven’t met any of us. https://pamelornortriptyline.com/

  16. generic fluvoxamine on

    I am glad for writing to make you know what a magnificent encounter my friend’s girl gained studying your web site. She learned plenty of pieces, which include what it’s like to possess an awesome helping nature to let other folks very easily know just exactly several multifaceted subject matter. You truly exceeded people’s expectations. Thank you for presenting these powerful, safe, explanatory and in addition fun tips about this topic to Julie. https://luvoxfluvoxamine.com/

  17. My husband and i ended up being absolutely delighted Chris could complete his homework from the ideas he came across from your own site. It’s not at all simplistic just to be giving away procedures which others may have been selling. So we grasp we have got the writer to give thanks to for that. The main illustrations you have made, the simple web site navigation, the relationships you will help foster – it’s got many incredible, and it’s really helping our son in addition to the family know that the matter is excellent, which is quite mandatory. Thank you for everything! https://geodonziprasidone.com/

  18. risperidone no rx on

    I enjoy you because of all of the effort on this blog. Debby delights in conducting internet research and it’s easy to see why. A number of us hear all about the compelling form you convey both useful and interesting guidelines by means of the blog and boost contribution from other individuals about this area of interest and my child has been becoming educated a great deal. Enjoy the remaining portion of the new year. You’re carrying out a dazzling job. https://risniarisperidone.com/

  19. risnia online on

    A lot of thanks for all your efforts on this site. Gloria loves engaging in investigation and it’s easy to understand why. Almost all know all concerning the dynamic means you give important secrets on the web blog and as well encourage contribution from others on that concern plus our daughter is always discovering a lot. Have fun with the remaining portion of the new year. You’re the one conducting a good job. https://risniarisperidone.com/

  20. cheap nortriptyline on

    I am glad for writing to make you know what a notable encounter my wife’s girl had studying your web site. She mastered several pieces, which include what it’s like to possess an awesome helping nature to let other individuals with ease know precisely some problematic subject matter. You truly exceeded people’s expectations. Thank you for producing these practical, trusted, informative and in addition fun tips about this topic to Kate. https://pamelornortriptyline.com/

  21. venlafaxine generic on

    Thank you for every one of your labor on this web site. My daughter really loves making time for investigations and it’s really obvious why. Most people learn all regarding the lively mode you present reliable tactics through this web site and even inspire participation from some others on the point then our favorite princess is really starting to learn a whole lot. Take advantage of the rest of the year. You are always doing a splendid job. https://venlorz.com/#

  22. wellbutrin price on

    I am commenting to let you know of the fine encounter my friend’s daughter found reading your site. She figured out many issues, not to mention what it’s like to have a wonderful giving mindset to have men and women quite simply have an understanding of selected hard to do subject areas. You really exceeded our expectations. Many thanks for giving the insightful, safe, explanatory and as well as easy thoughts on the topic to Jane. https://wellbutrinbupropions.com/#

  23. order venlafaxine on

    Thanks for your own work on this website. My mother take interest in participating in research and it is simple to grasp why. My spouse and i notice all relating to the powerful way you provide valuable tips via your website and in addition recommend response from visitors on this subject matter while our own simple princess is undoubtedly studying so much. Take pleasure in the rest of the year. You have been performing a terrific job. https://venlorz.com/#

  24. A lot of thanks for all your valuable hard work on this web page. Kim loves getting into investigation and it’s really easy to understand why. Many of us know all of the dynamic medium you make insightful solutions on this web blog and as well as improve participation from people on that idea so our girl is certainly discovering a lot of things. Have fun with the remaining portion of the new year. You are conducting a terrific job. https://venlorz.com/#

  25. purchase olanzapine on

    Thanks for the useful information on credit repair on your web-site. The thing I would offer as advice to people will be to give up a mentality they will buy at this moment and pay back later. As being a society most people tend to repeat this for many factors. This includes family vacations, furniture, plus items we really want to have. However, you must separate a person’s wants from the needs. When you’re working to fix your credit score you really have to make some trade-offs. For example you possibly can shop online to economize or you can click on second hand suppliers instead of highly-priced department stores to get clothing. https://zyprexaolanzapine.com/#

  26. https://www.vfv79.com/ on

    Anyway, I like the way you presented the mistakes and how I could avoid them. I liked more the step-by-step guide to make helpful comments.
    Being social as a blogger is a great tip. Or, as I put it in “The Howdy Neighbor Technique” post I wrote over on Be A Better Blogger: be friendly! It goes a long way.
    카지노사이트

  27. https://txt2080.com/woori/ on

    Agreed. There really is no good way to respond to a generic or vague comment. Such comments take all the fun out of responding!
    Every company is unique and has an entirely different DNA. A particular strategy may not work for your company, but that doesn’t mean that it won’t work for mine and vice versa. My piece of advice is that you should always ask yourself: Why didn’t that strategy didn’t work for them, and will it work for me?”
    퍼스트카지노

  28. https://liveone9.com/woori/ on

    Recently I’ve quoted some of the more negative emails and comments people have sent me…But today I thought I’d share some of the positive ones that I’ve got over the last two days:
    One of my big goals with Two Step Speaking is to make it as practical as possible, and actually get you DOING the process I teach, as you go through the course.
    더존카지노

  29. 우리카지노
    While the slot machines are probably the best in quality and offer the very best chance of striking a huge jackpot, it’s the other games available that really stand out. Blackjack and baccarat are usually two of the game titles that offer the most effective odds of receiving and this combined with the graphics and noise options really help the player to feel relaxed while playing. One of the games how the King delivers with the highest top quality visuals and fantastic sound effects is the game called “Rush”. Rush is designed to simulate the excitement and adventure of playing a real baccarat or blackjack activity. The graphics are so realistic they make the overall game seem as if it was essentially going to transpire in true to life.

  30. 우리카지노
    While the slot machine games are probably the very best in quality and provide the most effective chance of reaching an enormous jackpot, it is the other games on offer that really stick out. Blackjack and baccarat are two of the game titles that offer most effective odds of succeeding and this combined with the graphics and noise options really aid the player to feel at ease while playing. Among the games that this King presents with the highest top quality visuals and excellent sound effects may be the game known as “Rush”. Rush was created to simulate the buzz and experience of playing a genuine baccarat or blackjack game. The graphics are so realistic they make the overall game seem as though it was essentially going to transpire in real life.