Advertising:

Create application log in cloud development: Difference between revisions

From SAP Knowledge Base
m (Protected "Create application log in cloud development" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
No edit summary
Line 3: Line 3:
For this purpose, SAP offers several released classes for cloud development. The object and sub-object should not be created via SLG0, but via Eclipse with ABAP Development Tools.
For this purpose, SAP offers several released classes for cloud development. The object and sub-object should not be created via SLG0, but via Eclipse with ABAP Development Tools.


= How to use the classes =
== How to use the classes ==


* cl_bali_log
* cl_bali_log
Line 10: Line 10:
*cl_bali_log_db
*cl_bali_log_db


== Create new business application log object ==
=== Create new business application log object ===
<syntaxhighlight lang="abap" line copy>
<syntaxhighlight lang="abap" line copy>
TRY.
TRY.
Line 18: Line 18:
</syntaxhighlight>
</syntaxhighlight>


== Create header data ==
=== Create header data ===
<syntaxhighlight lang="abap" line copy>
<syntaxhighlight lang="abap" line copy>
  log->set_header( header = cl_bali_header_setter=>create( object = 'YOBJECT'
  log->set_header( header = cl_bali_header_setter=>create( object = 'YOBJECT'
Line 25: Line 25:
</syntaxhighlight>
</syntaxhighlight>


== Add messages ==
=== Add messages ===
<syntaxhighlight lang="abap" line copy>
<syntaxhighlight lang="abap" line copy>
  TRY.  
  TRY.  
Line 46: Line 46:
</syntaxhighlight>
</syntaxhighlight>


== Save to database ==
=== Save to database ===
There are two methods for saving the log:
There are two methods for saving the log:
* SAVE_LOG: uses the standard database connection. This means that the log is only written to the database when the application calls COMMIT_WORK.
* SAVE_LOG: uses the standard database connection. This means that the log is only written to the database when the application calls COMMIT_WORK.
Line 58: Line 58:
</syntaxhighlight>
</syntaxhighlight>


== Delete business application log from memory / Check deleting in memory ==
=== Delete business application log from memory / Check deleting in memory ===
<syntaxhighlight lang="abap" line copy>
<syntaxhighlight lang="abap" line copy>
  TRY.
  TRY.
Line 68: Line 68:
  ENDTRY.
  ENDTRY.
</syntaxhighlight>
</syntaxhighlight>
== Delete business application log ==
=== Delete business application log ===
<syntaxhighlight lang="abap" line copy>
<syntaxhighlight lang="abap" line copy>
  TRY.
  TRY.
Line 75: Line 75:
  ENDTRY.
  ENDTRY.
</syntaxhighlight>
</syntaxhighlight>
== Add business application log to Fiori Business Application Job ==
=== Add business application log to Fiori Business Application Job ===


The advantage of the classes used above when saving the log is that they are attached directly to the application job created via the Fiori app “Application job” if the corresponding parameter “ASSIGN_TO_CURRENT_APPL_JOB” is set to abap_true at cl_bali_log_db=>get_instance( )->save_log( log = log ).
The advantage of the classes used above when saving the log is that they are attached directly to the application job created via the Fiori app “Application job” if the corresponding parameter “ASSIGN_TO_CURRENT_APPL_JOB” is set to abap_true at cl_bali_log_db=>get_instance( )->save_log( log = log ).

Revision as of 10:58, 31 December 2024

For T1 / cloud developments the familiar function modules(FMs) or classic classes for creating application logs can no loger be used. For this purpose, SAP offers several released classes for cloud development. The object and sub-object should not be created via SLG0, but via Eclipse with ABAP Development Tools.

How to use the classes

  • cl_bali_log
  • cl_bali_message_setter
  • cl_bali_free_text_setter
  • cl_bali_log_db

Create new business application log object

TRY.
DATA(log) = cl_bali_log=>create( ).
CATCH cx_bali_runtime INTO DATA(runtime_exception).
ENDTRY.

Create header data

 log->set_header( header = cl_bali_header_setter=>create( object = 'YOBJECT'
                                                          subobject = 'YSUBOBJECT'
                                                          external_id = 'Ext ID' ) ).

Add messages

 TRY. 
  DATA(message) = cl_bali_message_setter=>create( severity = if_bali_constants=>c_severity_error
                                                     id = 'YMC_ABC'
                                                     number = '000' ).
   log->add_item( item = lo_message ).
  
   log->add_item( item = cl_bali_message_setter=>create_from_sy( ) ).
  
   DATA(free_text) = cl_bali_free_text_setter=>create( severity = if_bali_constants=>c_severity_error
                                                           text = 'Some Error Text' ).
   log->add_item( item = free_text ).
  
   DATA(exception) = cl_bali_exception_setter=>create(  severity = if_bali_constants=>c_severity_error
                                                       exception = ref ).
   lo_log->add_item( item = exception ).
  CATCH cx_bali_runtime INTO DATA(runtime_exception).
 ENDTRY.

Save to database

There are two methods for saving the log:

  • SAVE_LOG: uses the standard database connection. This means that the log is only written to the database when the application calls COMMIT_WORK.
  • SAVE_LOG_2ND_DB_CONNECTION: uses a service for saving that commits the log directly to the database
 TRY. 
  cl_bali_log_db=>get_instance( )->save_log( log = log ).
  cl_bali_log_db=>get_instance( )->save_log_2nd_db_connection( log = log ).
 CATCH cx_bali_runtime INTO DATA(runtime_exception).
 ENDTRY.

Delete business application log from memory / Check deleting in memory

 TRY.
  log->release_memory( ).  
  IF log->is_invalidated( ).
  ENDIF
 CATCH cx_bali_runtime INTO DATA(runtime_exception).
  runtime_exception->get_text( ).
 ENDTRY.

Delete business application log

 TRY.
   cl_bali_log_db=>get_instance( )->delete_log( log = log ).
  CATCH cx_bali_runtime INTO DATA(runtime_exception).
 ENDTRY.

Add business application log to Fiori Business Application Job

The advantage of the classes used above when saving the log is that they are attached directly to the application job created via the Fiori app “Application job” if the corresponding parameter “ASSIGN_TO_CURRENT_APPL_JOB” is set to abap_true at cl_bali_log_db=>get_instance( )->save_log( log = log ).


This is a wiki created in the spare time of a private person working in the SAP ERP area. The aim is to collect knowledge for the own use. The wiki is maintained to the best of knowledge and belief.
All products shown, including in form of screenshots, belong to SAP SE. Their trademarks are, among others: SAP®,ABAP®,SAP Fiori®,SAP HANA®,SAP NetWeaver®,SAP® R/3®,SAP S/4HANA®,SAP S/4HANA® Cloud