SAP RFC Calls From To PLC

Is it possible to do a RFC call from SAP directly to a PLC? Or does that depend on the PLC?

Suggestion:

This will depends on the PLC (sounds an interesting project). If the language used to control the PLC is RFC or CPIC enabled it should work.

As for an example of an RFC enabled function module, the only real difference between that and any other module is that the RFC Enabled radio button is checked in the attributes, and all parameters are passed by Value. It is also a good idea to use strings for your parameters rather than binary data (ie convert your numbers to strings).

To give you some idea of programming from the PLC end, here are some functions in VBA that will point you in the right direction:

Logon to SAP:

***************************************************************************
*
* Function: Logon_To_SAP as Object
*
* Purpose:  Logs onto an SAP system using the provided criteria and returns
*           a connection object to the caller
*
* Entry:    System name to log on to as string
*           Client of system as string
*           User name as string
*           Password as String
*
* Exit:     SAP Connection object
*
* Calls:
*
***************************************************************************
*

Function Logon_To_Sap(System As String, Client As String, User As String, Password As String, Router As String) As Object

         Dim Sap       As Object
         Dim iUser     As String
         Dim iPass     As String
         Dim iClient   As String
         Dim iPassword As String
         Dim iRouter   As String
         Dim iSystem   As String
*
         Call Push_Status("Communicating With SAP")
*
* For some reason,  this version of SAP changes the password variable so hard code them here
*

         iUser = User
         iPass = Password
         iClient = Client
         iSystem = System
         iRouter = Router

         Set Sap = CreateObject("SAP.Functions")

         Sap.Connection.ApplicationServer = iSystem
         Sap.Connection.Client = iClient
         Sap.Connection.SystemNumber = "10"
         Sap.Connection.User = iUser
         Sap.Connection.Password = iPass
         Sap.Connection.Language = "E"
         Sap.Connection.SapRouter = iRouter
*
        If Sap.Connection.logon(0, iPass <> "") = False Then
            Set Sap = Nothing
         End If

         Set Logon_To_Sap = Sap
End Function

And finally, an RFC call using standard and table parameters:

*
***************************************************************************
*
* Function: SAP_Read_Abap_Source
*
* Purpose:  Retreives the source code for the specified Abap Module
*
* Entry:    Abap Module Name to read the source for
*
* Exit:     Array of strings containing the Abap Source code
*
* Calls:    Z_GET_CODE
*
*           FUNCTION Z_GET_CODE.
*           *"----------------------------------------------------------------------
*           *"
*           *"Local Interface:
*           *"  IMPORTING
*           *"     VALUE(I_ABAPNAME) TYPE  PROGRAM
*           *"  TABLES
*           *"      T_SOURCE_LINES TYPE  ZSOURCE_LINES
*           *"----------------------------------------------------------------------
*           *
*           Data: t_Source Type Standard Table of Char255,
*                 w_Source Type Char255,
*                 w_Output Type ZSource_Line.
*           *
*           Read Report i_AbapName into t_Source.
*           Loop at t_Source into w_Source.
*                w_Output-Line   = Sy-tabix.
*                w_Output-Source = w_Source.
*                Append w_Output to t_Source_Lines.
*           EndLoop.
*           ENDFUNCTION.
*

Function SAP_Read_Abap_Source(Abap_Name As String) As String()

*
         ReDim Module_Source(0) As String

         Dim R3                 As Object
         Dim Table_Factory      As Object
         Dim Source_Table       As Object
         Dim Table_Row          As Object
         Dim Exception          As Variant
*
         Set R3 = Logon_To_Sap(g_Sys, g_Client, g_User, g_Pass, g_Router)

         Call Push_Status("Reading Source For " & Abap_Name)

         If Not R3 Is Nothing Then

            Set Table_Factory = CreateObject("Sap.TableFactory.1")
            Set Source_Table = Table_Factory.NewTable

            If Source_Table.CreateFromR3Repository(R3.Connection, "ZSOURCE_LINE", "T_SOURCE_LINES") = True Then
               If R3.Z_GET_CODE(i_AbapName:=Abap_Name, T_Source_Lines:=Source_Table) Then
                  For Each Table_Row In Source_Table.Rows
                      Module_Source(UBound(Module_Source)) = Table_Row(2)
                      ReDim Preserve Module_Source(UBound(Module_Source) + 1) As String
                  Next Table_Row
               End If
            End If
         End If

         Set Table_Row = Nothing
         Set Source_Table = Nothing
         Set R3 = Log_Off_Sap(R3)

         Call Pop_Status

         SAP_Read_Abap_Source = Module_Source()

End Function

Notes:

What are PLCs and how do they work?

PLCs are often defined as miniature industrial computers that contain hardware and software that is used to perform control functions. A PLC consists of two basic sections: the central processing unit (CPU) and the input/output interface system. The CPU, which controls all PLC activity, can further be broken down into the processor and memory system. The input/output system is physically connected to field devices (e.g., switches, sensors, etc.) and provides the interface between the CPU and the information providers (inputs) and controllable devices (outputs).

To operate, the CPU "reads" input data from connected field devices through the use of its input interfaces, and then "executes", or performs the control program that has been stored in its memory system. Programs are typically created in ladder logic, a language that closely resembles a relay-based wiring schematic, and are entered into the CPU's memory prior to operation. Finally, based on the program, the PLC "writes", or updates output devices via the output interfaces. This process, also known as scanning, continues in the same sequence without interruption, and changes only when a change is made to the control program.

ABAP Tips

Read Also
How to Write Web Reports in SAP

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.