This chapter provides an overview of the outside of the WWW interface to SAP. The assumption is being made that the SAP side of things, ABAP/4, system configuration and user setup has already been accomplished. If more information is needed on RFCs in general, please look at the RFC WWW site referenced in the SAP_RFC manual page.
This chapter describes how to use the SAP_RFC extension to perl to create an interface to SAP via the SAP Remote Function Call (RFC) library.
Notes:
Because a positive response from SAP to the open command does not indicate that the user has been logged into SAP, it is highly recommended that a SAP_RFC::ping command be used to verify that the user has, in fact, been logged into SAP.
If the trace flag is set, that is the first character is "Y", a file, named dev_rfc will be created in the local directory with the contents of the exchanges to and from SAP. This file may get to be very large. It is not recommended that this flag be set except for test and debugging reasons.
If more information is desired on the SAP_RFC perl extensions, please refer to the SAP_RFC manual.
# Define the connection parameters $sap_system = 'DEV'; $sap_client = '100'; $sap_user = 'TEST_USER'; $sap_passwd = 'PASSWORD'; $sap_trace = 'NO'. $ret = 0; $ret1 = 0; $ret_str = ' '; # Try to connect and login to SAP $ret = &SAP_RFC::open($sap_system, $sap_client, $sap_user, $sap_passwd, $sap_trace); # check that open worked - verify login OK if ($ret != 0) # open failed !! { print "SAP_RFC::open() Failed !!!\n"; exit; # quit the program } # open failed else # OK the open worked, are we really logged in ?? { ($ret1, $ret_str) = &SAP_RFC::ping(); if (ret1 != 0) # not logged in { print "SAP_RFC::ping() - Could not connect. "; print "No login !! \n"; exit; # quit the program } else { print "User $sap_user logged in to SAP System "; print "$sap_system in Client $sap_client \n"; } } # end of block to verify login
This example block of code demonstrates what is probably a minimal set of code to connect to and login to an SAP system.
The parameters required to execute an SAP transaction are 1) the target ABAP program and 2) the message string to be sent to the ABAP program. This example will not worry about the structure or content of the message strings.
The following code block demonstrate the execution of a single string call-receive transaction.
# Create dummy message string $mess_str = "This is a test message string I could be "; $mess_str = $mess_str1 . "up to 248 characters long"; # concatenate the strings # Define an ABAP program as an RFC destination $mess_abap = "Z_TEST_TEST"; # initialize return variables $ret = 0; $ret_str = ' '; ($ret, $ret_str) = &SAP_RFC::callrx1($mess_abap, $mess_str); if ($ret != 0) # the transaction failed # do something about the error { print "The transaction failed \n"; } else # the transaction succeed { # it was OK - now what . print "The transaction was OK \n"; }
The following code block demonstrate the execution of a two string return call-receive transaction.
# Create dummy message string $mess_str = "This is a test message string I could be "; $mess_str = $mess_str1 . "up to 248 characters long"; # concatenate the strings # Define an ABAP program as an RFC destination $mess_abap = "Z_TEST_TEST"; # initialize return variables $ret = 0; $ret_str1 = ' '; $ret_str2 = ' '; ($ret, $ret_str1, $ret_str2) = &SAP_RFC::callrx2($mess_abap, $mess_str); if ($ret != 0) # the transaction failed # do something about the error { print "The transaction failed \n"; } else # the transaction succeed { # it was OK - now what . print "The transaction was OK \n"; }
# initialize the return variable $ret = 0; # now close the connection $ret = &SAP_RFC::close(); if ($ret != 0) { print "the SAP_RFC::close Failed !!\n"; } else { print "the SAP_RFC::close was OK !\n"; }