A manufacturing plant or an industrial site consists of machinery to process or manufacture goods. These machines continue its functionality as long as they are in good condition. However, due to breakdowns and preventive maintenance they need to be serviced with labor, parts or both. SAP plant maintenance has rich functionality to manage equipment, functional locations and entire PM processes.
To avoid machine breakdown or notify when a breakdown occurs or to make a request for maintenance there is functionality in SAP called PM (Plant Maintenance) Notification. SAP Maintenance functionality is used to alert the department about an abnormal condition in the machinery. It is kind of a trigger to initiate PM cycle. PM notifications can be created using transaction code IW21 within SAP.
It may be noted that external non SAP applications may be monitoring assets and SAP may not be the only application within customers landscape. In this article, I am going to walk you through how integrate SAP with an external system to create PM notification in SAP. In this we are taking external system to be a .NET based application which can be integrated using Visual Studio (Creating console application) which is integrated with SAP to create PM notifications in SAP.
SAP Third party integration for Plant Maintenance
The section below describes a step by step guide on how to integrate with SAP to create PM Notifications using .NET connector. You may require an understanding of .NET and ABAP languages to be able to get the most out of this tutorial.
Step 1: Creating a .NET application referencing SAP NCO libraries
- Create a web application and add reference of sapnco.dll and sapnco_utils.dll (shown in below screenshot) which are required to connect with SAP. If you do not have these libraries , reach out to SAP Basis team or you can download them yourself from SAP Marketplace out here.
Step 2: Develop the .NET code for creating PM Notifications in SAP
- MainClass is used to connect to the SAP system and to create PM Notifications in SAP.
using BapiTest.model; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BapiTest { class MainClass { static void Main(string[] args) { PlantMaint data =new PlantMaint(); SapBapiConnection cnn = new SapBapiConnection("SAP_HOST", "SAP_SYSNUM", "SAP_CLIENT", "SAP_USER", "SAP_PASSWORD", "SAP_SYSID", true); PMNotificationCriteriaBapi.Execute(data,cnn); } } }
SapBapiConnection cnn = new SapBapiConnection(“SAP_HOST”, “SAP_SYSNUM”, “SAP_CLIENT”, “SAP_USER”, “SAP_PASSWORD”, “SAP_SYSID”, true);
- In the above line we are connecting to SAP using SAP .Net Connector by providing all the SAP credentials such as host server, system number, client, username, password, system id.
PMNotificationCriteriaBapi.CreatePMNotifications(data,cnn);
- The above line is used to create PM Notifications in SAP by calling a function called CreatePMNotifications with two parameters where,
- First parameter defines the object for a class called PlantMaint which consists of values required to create PM Notifications in SAP.
PlantMaint data =new PlantMaint();
In the below screenshot, you can observe how the values are passed to a function CreatePMNotifications. In this example, we are creating a notification which describes the situation (Oil leak in bearing) for equipment (10003588) in the function location (1034-LABS-002).
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BapiTest.model { public class PlantMaint { static public string WorkType = "M1"; static public string Priority = "1"; static public string Title = "OIL LEAK IN BEARING test"; static public string AssetId = "10003588"; static public string LocationId = "1034-LABS-002"; internal PlantMaint() { } } }
- And the second parameter defines the connectivity to SAP.
- Add a class called PMNotificationCriteriaBapi in which the above called CreatePMNotifications method is defined.
using SAP.Middleware.Connector; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BapiTest.model { class PMNotificationCriteriaBapi { internal static void Execute(PlantMaint criteria, SapBapiConnection cnn) { ExecuteStandardBapi(criteria, cnn); } private static void ExecuteStandardBapi(PlantMaint criteria, SapBapiConnection cnn) { string createdNotificationId = string.Empty; try { RfcDestination ECCSystem = cnn.GetDestination(); RfcRepository repo = ECCSystem.Repository; RfcSessionManager.BeginContext(ECCSystem); IRfcFunction bapi = repo.CreateFunction("BAPI_ALM_NOTIF_CREATE"); bapi.SetValue("NOTIF_TYPE", PlantMaint.WorkType); IRfcStructure options = bapi.GetStructure("NOTIFHEADER"); options.SetValue("PRIORITY", PlantMaint.Priority); options.SetValue("SHORT_TEXT", PlantMaint.Title); options.SetValue("EQUIPMENT", PlantMaint.AssetId); options.SetValue("FUNCT_LOC", PlantMaint.LocationId); bapi.Invoke(ECCSystem); IRfcStructure notifHeaderExport = bapi.GetStructure("NOTIFHEADER_EXPORT"); createdNotificationId = notifHeaderExport.GetString("NOTIF_NO").ToString(); IRfcFunction bapi1 = repo.CreateFunction("BAPI_ALM_NOTIF_SAVE"); bapi1.SetValue("NUMBER", createdNotificationId); bapi1.Invoke(ECCSystem); IRfcFunction RfcFunction = repo.CreateFunction("BAPI_TRANSACTION_COMMIT"); RfcFunction.SetValue("WAIT", "X"); RfcFunction.Invoke(ECCSystem); RfcSessionManager.EndContext(ECCSystem); } catch (Exception ex) { throw new SapException("SAP ERROR for Standar BAPI : BAPI_ALM_NOTIF_CREATE " + ex.ToString()); } } } }
- To create PM Notifications in SAP, we use BAPI called BAPI_ALM_NOTIF_CREATE and pass the required values to create PM Notifications in SAP.
- Now Run the Console Application and check in SAP using transaction code IW23.
- In the above screen you can notice the notification number created in SAP.
- Now check with that number in SAP.
Step 3: Check the PM notification returned from application within SAP
- Enter transaction code IW23 in SAP to display the notification.
- Enter Notification number which you get from the console application.
- Click on Enter.
- In the below screen you can see that PM Notification has been created in SAP.
By following the above steps, you can Integrate SAP with an external system to create PM Notifications. We sincerely hope that this was useful and any comment of feedback will be very helpful.
Who we are
We are passionate about SAP consulting and executing SAP Integration projects. Reach out to us for a free assessment of your SAP needs.