Application Logging in SAP Using ABAP



Similar documents
SAP BI Generic Extraction Using a Function Module

Offsetting Account Description in FBL3N and FAGLL03 GL Line Item Display Reports

Step by Step Guide to Fiscal Week and Fiscal Quarter

Step by Step Guide for Language Translation Tool

Release Strategy Enhancement in Purchase Order

Scenario... 3 Step-by-Step Solution Virtual Infocube... 4 Function Module (Virtual InfoCube)... 5 Infocube Data Display... 7

Step by Step Guide How to Copy Flat File from Other Application Server to BI and Load through Info Package

Display Popup Window and Dialog Box in ALV

Restricting Search Operators in any Search View

Deleting the User Personalization done on Enterprise Portal

Exposing RFC as Web Service and Consuming Web Service in Interactive Forms in ABAP

Deleting the Requests from the PSA and Change Log Tables in Business Intelligence

Reverse Transport Mechanism in SAP BI

Creating Transaction and Screen Variants

Table of Contents. Passing Data across Components through Component Controller between Two Value Nodes

SAP CRM Campaign Automation

ALV List with Radio Buttons

How to Generate Stack Xml for Ehp4 and Above Upgrade

Creation and Configuration of Business Partners in SAP CRM

Message handling in SAP CRM Web UI

How to Assign Transport Request for Language Translation?

Embedding Crystal Reports inside ECC ALV Reports

Quick Viewer: SAP Report Generating Tool

A Wrapper to Call Dynamically Function via RFC

Configuration of Enterprise Services using SICF and SOA Manager

Sending an Image File Through XI in a File-to-Mail Scenario

Create Automatic Mail Notification/ Alert for Process Chain Monitoring

SAP FI - Automatic Payment Program (Configuration and Run)

Creating Web Service from Function Modules/BAPIs & Integrating with SAP Interactive Forms

SAP CRM 7.0 E2C Setup: CRM via Toolset

ABAP Debugging Tips and Tricks

Workflow Troubleshooting and Monitoring in SAP ECC 6.0

Step by Step Guide to Archiving and Deleting of XML Messages in SAP NetWeaver PI

Creating New Unit of Measure in SAP BW

LSMW: Upload Master Data using Batch Input Recording

BW Performance Monitoring

Tutorial - Creating Pop Up Window Using New Features in WebDynpro Java CE 7.1 Ehp1

ALE Settings, for Communication between a BW System and an SAP System

Display Options in Transaction SE16

Standard SAP Configuration of SMS through HTTP with Third Party SMS Gateway

Web Dynpro ABAP: ALV and Table in Popup Window

Process Controlled Workflow SRM 7.0 (Using BRF)

Creating Mobile Applications on Top of SAP, Part 1

Creating and Scheduling Publications for Dynamic Recipients on SAP Business Objects Enterprise

Creating Content Using SO10 Objects and Text Symbols

ABAP How To on SQL Trace Analysis

Configuring HTTPs Connection in SAP PI 7.10

ABAP Proxy Interfacing

Step by Step Procedures to Load Master Data (Attribute and Text) from FlatFile in BI 7.0

How to Modify, Create and Delete Table Entries from SE16

Web Dynpro: Multiple ALV Grids and Layouts in ALV

Dynamic Authorization Concept and Role Assignment in BI

A Step-by-Step guide on SMTP Configuration and File to Mail Scenario Using Process Integration Scenario in PI 7.1

SAP CRM 7.0 for Newbies: (Part 1) Simple BOL Object Creation for CRM Webclient UI

SAP NetWeaver Developer Studio 7.30 Installation Guide

SAP BW - Excel Pivot Chart and Pivot Table report (Excel)

Customer Exit Variables in SAP BW/BI Reports First day of the Current/Previous Month

Deploying Crystal Reports on Top of a SAP BI Query

Step by Step Guide to Extract Batch Master Data via Generic and Classification Datasource to BW

Converting and Exporting Data in XML Format

Step by Step guide of Report-to- Report Interface in BW Reporting

Order Split Usage in Production Orders

Changing Partner s Address Data of the Sales Order

Step by Step Procedure to Block and Debug a CIF Queue Flowing from R/3 to APO System

How to Integrate CRM 2007 WebClient UI with SAP NetWeaver Portal

SPDD & SPAU Adjustments Handbook

Transfer of GL Master from Source SAP System to a Target SAP System through IDOCS

Forgot or Lock "Administrator or J2EE_ADMIN" Password

BOM Header and Item Extraction in SAP - Business Intelligence

SDN Community Contribution

SAP Workflow in Plain English

Table of Content. SAP Query creation and transport Procedure in ECC6

XSLT Mapping in SAP PI 7.1

SAP BW - Generic Datasource Function Module (Multiple Delta Fields)

Salesforce.com Integration Using SAP PI: A Case Study

SAP BW 7.3: Exploring Semantic Partitioning

Splitting the Custom Container & Display more than one ALV

SAP CRM System 6.0/7.0. For more information, visit the Customer Relationship Management homepage

Web Application Designer for Beginners

Business Partner in the Human Resources (HR) System

Merge PDF files in ABAP

Guidelines for Effective Data Migration

How to Develop Programs for SAP Mobile RF

Direct Subcontracting Process (SAP SD & MM)

How to Extract Data for Multi- Value Characteristics to SAP BW

Multi Level Purchase Order Release Strategy

Middleware Configuration and Monitoring for Master Data Transfer from SRM to ECC

First step to Understand a Payroll Schema

Compounding in Infoobject and Analyzing the Infoobject in a Query

Quick Guide EDI/IDoc Interfacing to SAP ECC from External System

Integration of SAP R/3 with BO Universe Using Data Federator Connector

Mandatory Field Check in Web Dynpro- ABAP

Credit Management in Sales and Distribution

How to Get Work Items from Workflow in your Outlook Inbox

Step by Step Guide to Create a Generic Datasource Based on Infoset Query Populated Via External Program

Connecting to SAP BW with Microsoft Excel PivotTables and ODBO

Salesforce Integration Using PI: How to Perform Query and Other DML Operations Using the Enterprise WSDL

SAP CRM Middleware Configurations

How to Create an ecatt?

SAP CRM-BW Adapter an Overview

Transcription:

Application Logging in SAP Using ABAP Applies to: SAP R3/ISU/CRM ABAP side Summary This article explains how to create your own application logging program in ABAP Author(s): Ashim Chowdhury Company: Tata Consultancy Services Ltd. Created on: 08 September 2006 Author Bio Ashim Chowdhury is an SAP Technical consultant with Tata Consultancy, India. He works in the SAP technical area(abap, Net weaver, XI). 2006 SAP AG 1

Table of Contents Applies to:... 1 Summary... 1 Author Bio... 1 Application Logging in SAP... 2 Configuration step:... 2 Development Step:... 2 Using the function module:... 6 Related Content... 7 Disclaimer and Liability Notice... 8 Application Logging in SAP SAP provides standard functionality to write into as well as view the application log. This article will explain in detail how to create your own logging function module for application logging using standard SAP log facility. Two transaction code related to application logging are SLG0 -> Used to maintain the log object SLG1 -> Used to view the log Configuration step: In this step create a log object. 1. Open transaction SLG0. An information message about cross-client table will come. 2. Click the button New Entries. Enter the name and description of your log object (say ZTESTLOG as object name and Test Log as object description) and save. Development Step: The following standard function modules provided by SAP has been used to create the Z function module for logging. BAL_GLB_MSG_DEFAULTS_SET BAL_DB_SAVE BAL_LOG_MSG_ADD Here are the steps: 2006 SAP AG 2

1. Go to transaction SE11. Create a z-structure Z_LOG_MESSAGE having the following fields Component MSGTY MSG_TEXT_1 MSG_TEXT_2 MSG_TEXT_3 MSG_TEXT_4 Component Type SYMSGTY SYMSGV SYMSGV SYMSGV SYMSGV 2. Crate a message class say ZMESSAGE in transaction SE91 and a message 999 with four placeholder ( & ) as the text. 3. Go to transaction SE37. Create a function group say ZLOG 4. After the function group is created, create a function module in that group. Let is name it ZIU_MESSAGE_LOGGING. Import parameters: a. I_LOG_OBJECT type BALOBJ_D -> Application log: Object name (Application code) b. I_EXTNUMBER type String -> Application Log: External ID Export parameters: None Changing parameters: None Tables parameters: T_LOG_MESSAGE type Z_LOG_MESSAGE Exceptions: LOG_HEADER_INCONSISTENT LOGGING ERROR Paste the code below as the source code FUNCTION ZIU_MESSAGE_LOGGING. *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" REFERENCE(I_LOG_OBJECT) TYPE BALOBJ_D *" REFERENCE(I_EXTNUMBER) TYPE STRING *" TABLES 2006 SAP AG 3

*" T_LOG_MESSAGE STRUCTURE Z_LOG_MESSAGE *" *" LOG_HEADER_INCONSISTENT *" LOGGING_ERROR *"---------------------------------------------------------------------- * Author :Ashim Chowdhury * DESCRIPTION: This function module is used insert messages in the * application log CONSTANTS: c_message TYPE syst-msgid VALUE 'ZMESSAGE', c_999 TYPE syst-msgno VALUE '999'. DATA: l_log_handle l_s_log l_dummy l_ext_no l_s_mdef TYPE balloghndl, TYPE bal_s_log, type string, type bal_s_log-extnumber, TYPE bal_s_mdef. if T_LOG_MESSAGE[] is not initial. l_s_log-object = I_LOG_OBJECT. l_ext_no = I_EXTNUMBER. l_s_log-extnumber = l_ext_no. * Create the log with header data CALL FUNCTION 'BAL_LOG_CREATE' i_s_log = l_s_log IMPORTING E_LOG_HANDLE = l_log_handle LOG_HEADER_INCONSISTENT = 1 OTHERS = 2. IF sy-subrc <> 0. case sy-subrc. when 1. raise LOG_HEADER_INCONSISTENT. when others. raise LOGGING_ERROR. endcase. l_s_mdef-log_handle = l_log_handle. * Set the default value CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET' i_s_msg_defaults = l_s_mdef 2006 SAP AG 4

OTHERS = 0. * Loop the message table and write the messages into the log loop at T_LOG_MESSAGE. * Use the message type ZMESSAGE and msg no 999 * Issue the message in a dummy variable message ID C_message type t_log_message-msgty number C_999 with t_log_message-msg_text_1 t_log_message-msg_text_2 t_log_message-msg_text_3 t_log_message-msg_text_4 into l_dummy. * The parameters set by message statement will be used * Add the message in the log PERFORM msg_add. endloop. * save logs in the database CALL FUNCTION 'BAL_DB_SAVE' I_SAVE_ALL = 'X' LOG_NOT_FOUND = 1 SAVE_NOT_ALLOWED = 2 NUMBERING_ERROR = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. ENDFUNCTION. *-------------------------------------------------------------------- * FORM MSG_ADD *-------------------------------------------------------------------- * Add the message to the log *-------------------------------------------------------------------* FORM msg_add. DATA: l_s_msg TYPE bal_s_msg. * define data of message for Application Log l_s_msg-msgty = sy-msgty. l_s_msg-msgid = sy-msgid. l_s_msg-msgno = sy-msgno. l_s_msg-msgv1 = sy-msgv1. l_s_msg-msgv2 = sy-msgv2. l_s_msg-msgv3 = sy-msgv3. 2006 SAP AG 5

l_s_msg-msgv4 = sy-msgv4. * add this message to log file * (I_LOG_HANDLE is not specified, we want to add to the default log. * If it does not exist we do not care => log_not_found = 0) CALL FUNCTION 'BAL_LOG_MSG_ADD' * I_LOG_HANDLE = i_s_msg = l_s_msg log_not_found = 0 OTHERS = 1. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDFORM. Using the function module: In your ABAP program write the following code and use this function module ZIU_MESSAGE_LOGGING for logging. Data declaration-> * Internal table for message logging DATA: it_log_message TYPE STANDARD TABLE OF z_log_message, wa_log_message TYPE z_log_message, l_ext_number TYPE string. Constants: c_obj_zxiproxy TYPE balobj_d VALUE 'ZTESTLOG'. * Now populate the internal table with the log messages as shown below. wa_log_message- * msgty is the type of the message. * E -> Error, W -> Warning, S -> Success * Logging code for insert message into log CLEAR wa_log_message. wa_log_message-msgty = 'E'. Can use W or S wa_log_message-msg_text_1 = < Message text 1>. wa_log_message-msg_text_2 = < Message text 2> 2006 SAP AG 6

wa_log_message-msg_text_3 = < Message text 3> wa_log_message-msg_text_4 = < Message text 4> * Append the message into the internal table APPEND wa_log_message TO it_log_message. At the end transfer the log message to the system log by calling function module ZIU_MESSAGE_LOGGING. L_EXT_NUMBER will bt any string of your choice. * Function module ZIU_MESSAGE_LOGGING will do the logging * i_log_object is the object type (to be configrd using txn SLG0 CALL FUNCTION 'ZIU_MESSAGE_LOGGING' i_log_object = c_obj_zxiproxy i_extnumber = l_ext_number TABLES t_log_message = it_log_message log_header_inconsistent = 1 logging_error = 2 OTHERS = 3. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. The logged messages can be viewed in transaction SLG1. For filtering the messages use the Object type. Related Content Please include at least three references to SDN documents or web pages. http://abap4.tripod.com/using_application_logging.html 2006 SAP AG 7

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document. 2006 SAP AG 8