Showing posts with label rfc. Show all posts
Showing posts with label rfc. Show all posts

Wednesday, May 7, 2008

Interview Question on BAPI, RFC, ABAP Objects, Tables

1) What is the difference between RFC and BAPI ?
What are subclasses and super classes in BAPI and also what are the methods in BAPI ?
2) Is it possible to connect SAP to Non-SAP systems to retrieve data using RFC alone with out using BAPI ?
3) What is the difference between Function module and BAPI ?
4) What are the types of tables?
5) What are pooled table ?
6) What are Hashed Tables ?
7) What are advantages of using ABAP objects?
8) What is the advantage of using ABAP objects in Reports ?

1) BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA. in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

The following standardized BAPIs are provided:
Reading instances of SAP business objects
GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.

The BAPI GetList() is a class method.
GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type

The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.

Create( ) and CreateFromData! ( )
The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.

Change( )
The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.

Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.

The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.

Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.

Add ( ) and Remove ( ) The BAPI Add adds a subobject to an existing object inst! ance and the BAPI and Remove removes a subobject from an object instance. These BAPIs are instance methods.

2) No it is not possible to connect SAP to Non-SAP systems to retrieve data using RFC alone. RFC can acces the SAP from outside only through BAPI and same is for vice versa access.

3) Each Bapi Object has Interface, Key Fields, Attributes,Methods and Events.
Bapi Function Modules can be attached to these Bapi objects .Function module has a single bound functionality while a BAPI object can contain many functionalities

4) Transparent table, Pool table and cluster table are data dictionary table objects sorted table, indexed table and hash table are internal tables.

5)Table pools (pools) and table clusters (clusters) are special table types in the ABAP Dictionary. The data from several different tables can be stored together in a table pool or table cluster. Tables assigned to a table pool or table cluster are referred to as pooled tables or cluster tables.

A table in the database in which all records from the pooled tables assigned to the table pool are stored corresponds to a table pool.

The definition of a pool consists essentially of two key fields (Tabname and Varkey) and a long argument field (Vardata).
Table Clusters Several logical data records from different cluster tables can be stored together in one physical
record in a table cluster.

A cluster key consists of a series of freely definable key fields and a field (Pageno) for distinguishing continuation records. A cluster also contains a long field (Vardata) that contains the contents of the data fields of the cluster tables for this key. If the data does not fit into the long field, continuation records are created. Control information on the structure of the data string is still written at the beginning of the Vardata field.

6) Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.

Sample Prog: This does nothing.
REPORT Z_1 .
tables: mara.
data: i type hashed table of mara with unique key matnr

7) and 8) ABAP objects are root for your program and reports.

RFC Vs BAPI

BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA.

In this case you only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI. It is not possible to connect SAP to Non-SAP systems to retrieve data using RFC alone. RFC can acces the SAP from outside only through BAPI and same is for vice versa access.

RFC is the protocol used by SAP for remote communication, that is, for communications between remote (independent) systems. RFC is used for communications between two independent SAP systems, or for communications between an SAP system and a non-SAP system, such as an external application. It can also be used for communications between modules on the same system. Using the RFC interfaces you can extend the functionality of R/3 applications from an external program.

What is the different btween clear and refresh?

There are 2 types of clear statements we can use:
Clear ITAB : This Statement will clear the Internal Table Header content.
To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.

Refresh will deletes the Internal Table content but still memory is not freed.

What is the pick statment do?

Pick Statemnt will captures the UserAction.
Eg: if SY-UCOMM = 'X'.
This type of user actions can be captured thru PICK Statement only.

What is the different between sesstion method and call transaction method and suppose I used one method to transform the data next time suppose I want transform the data which method I can use.

There are many difference between Session method and Call Transaction.
Which method we have to use will be found based on Volume Of data and Accuracy of data given. Mainly Call Transaction used for small sets of data because in Call Transaction we have to Handle the Processing errors explicitly. We can do this by BDCMSGCOLL structure.
In Session method seperate session will crate for errors. Calll Transaction will update the Database fastly compare with Session Method.

What is single and upto one row different?

The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.
Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.
Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.
Thus Select Single will take much processing time when compare with Select UPTO 1 rows.

What is the differences between selection screen and selection screen out?

The difference between Selection Screen and Selection Screen Output is we use the Selection Screen Output Event before the Selection Screen will displayed. Eg: Suppose if we want to disable some fields and enable some fields in the Selection Screen then we can code that in Section-Screen Output event.
Selection-Screen Event will trigger after section-screen is displayed and user action takes place on that.

Friday, November 23, 2007

Interview Question on BAPI, RFC, ABAP Objects, Tables

What is the difference between RFC and BAPI ?
What are subclasses and super classes in BAPI and also what are the methods in BAPI ?
2) Is it possible to connect SAP to Non-SAP systems to retrieve data using RFC alone with out using BAPI ?
3) What is the difference between Function module and BAPI ?
4) What are the types of tables?
5) What are pooled table ?
6) What are Hashed Tables ?
7) What are advantages of using ABAP objects?
8) What is the advantage of using ABAP objects in Reports ?

1) BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA. in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

The following standardized BAPIs are provided:
Reading instances of SAP business objects
GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.

The BAPI GetList() is a class method.
GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type

The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.

Create( ) and CreateFromData! ( )
The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.

Change( )
The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.

Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.

The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.

Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.

Add ( ) and Remove ( ) The BAPI Add adds a subobject to an existing object inst! ance and the BAPI and Remove removes a subobject from an object instance. These BAPIs are instance methods.

2) No it is not possible to connect SAP to Non-SAP systems to retrieve data using RFC alone. RFC can acces the SAP from outside only through BAPI and same is for vice versa access.

3) Each Bapi Object has Interface, Key Fields, Attributes,Methods and Events.
Bapi Function Modules can be attached to these Bapi objects .Function module has a single bound functionality while a BAPI object can contain many functionalities

4) Transparent table, Pool table and cluster table are data dictionary table objects sorted table, indexed table and hash table are internal tables.

5)Table pools (pools) and table clusters (clusters) are special table types in the ABAP Dictionary. The data from several different tables can be stored together in a table pool or table cluster. Tables assigned to a table pool or table cluster are referred to as pooled tables or cluster tables.

A table in the database in which all records from the pooled tables assigned to the table pool are stored corresponds to a table pool.

The definition of a pool consists essentially of two key fields (Tabname and Varkey) and a long argument field (Vardata).
Table Clusters Several logical data records from different cluster tables can be stored together in one physical
record in a table cluster.

A cluster key consists of a series of freely definable key fields and a field (Pageno) for distinguishing continuation records. A cluster also contains a long field (Vardata) that contains the contents of the data fields of the cluster tables for this key. If the data does not fit into the long field, continuation records are created. Control information on the structure of the data string is still written at the beginning of the Vardata field.

6) Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.

Sample Prog: This does nothing.
REPORT Z_1 .
tables: mara.
data: i type hashed table of mara with unique key matnr

7) and 8) ABAP objects are root for your program and reports.

RFC Vs BAPI

BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA.

In this case you only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI. It is not possible to connect SAP to Non-SAP systems to retrieve data using RFC alone. RFC can acces the SAP from outside only through BAPI and same is for vice versa access.

RFC is the protocol used by SAP for remote communication, that is, for communications between remote (independent) systems. RFC is used for communications between two independent SAP systems, or for communications between an SAP system and a non-SAP system, such as an external application. It can also be used for communications between modules on the same system. Using the RFC interfaces you can extend the functionality of R/3 applications from an external program.

What is the different btween clear and refresh?

There are 2 types of clear statements we can use:
Clear ITAB : This Statement will clear the Internal Table Header content.
To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.

Refresh will deletes the Internal Table content but still memory is not freed.

What is the pick statment do?

Pick Statemnt will captures the UserAction.
Eg: if SY-UCOMM = 'X'.
This type of user actions can be captured thru PICK Statement only.

What is the different between sesstion method and call transaction method and suppose I used one method to transform the data next time suppose I want transform the data which method I can use.

There are many difference between Session method and Call Transaction.
Which method we have to use will be found based on Volume Of data and Accuracy of data given. Mainly Call Transaction used for small sets of data because in Call Transaction we have to Handle the Processing errors explicitly. We can do this by BDCMSGCOLL structure.
In Session method seperate session will crate for errors. Calll Transaction will update the Database fastly compare with Session Method.

What is single and upto one row different?

The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.
Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.
Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.
Thus Select Single will take much processing time when compare with Select UPTO 1 rows.

What is the differences between selection screen and selection screen out?

The difference between Selection Screen and Selection Screen Output is we use the Selection Screen Output Event before the Selection Screen will displayed. Eg: Suppose if we want to disable some fields and enable some fields in the Selection Screen then we can code that in Section-Screen Output event.
Selection-Screen Event will trigger after section-screen is displayed and user action takes place on that.

SAP_RFC - Perl extension to Interface with SAP RFC

SAP_RFC - Perl extension to Interface with SAP RFC

Permission to use, copy, and distribute without charge this software, documentation etc. is granted, provided that this comment and the author's name is retained. Neither the author or Abapers.com assume any responsibility for problems resulting from the use of this software, documentation. SAP and ABAP/4 are copyrights of SAP AG

SYNOPSIS

use SAP_RFC;

$ret = &SAP_RFC::open($system, $client, $user, $passwd, $trace);

$ret = &SAP_RFC::close();

($ret, $string) = &SAP_RFC::ping();

($ret, $string) = &SAP_RFC::callrx1($abap, $string1);

($ret, $string1, $string2) = &SAP_RFC::callrx2($abap, $string3);

($ret, $string) = &SAP_RFC::callrxx($abap, $string1, $from_rec, $to_rec);

$string = &SAP_RFC::help();

($ret, $string) = &SAP_RFC::sysinfo();

$ver = &SAP_RFC::version();

DESCRIPTION

SAP_RFC is an extension to Perl which allows access to SAP's RFC interface through a scripting mechanism. This extension requires that you have the SAP RFC libraries and include files. These should come standard with an SAP system. (If you don't have an SAP system, or have to ask what SAP is, then this extension is of no use to you.) This extension creates a statically linked perl executable called rfcperl. The SAP libraries require that the resulting rfcperl

SAP_RFC was developed for two primary reasons. First was an effort to not require the use of C for all interface activities, and second was a desire to be able to quickly make changes to interfaces and immediately see the result. A result is the capability to, outside of SAP, quickly put together interface programs for a variety of short term needs.

A secondary purpose in the development of SAP_RFC was to have a mechanism by which CGI-BIN access to SAP systems could be provided, without being required to use C.

Principal Functions

The functions for SAP_RFC are open, close, ping, callrx1, callrx2, callrxx, help, sysinfo and version.

* open

Open a connection to an SAP Instance

$ret = &SAP_RFC::open($system, $client, $user, $passwd, $trace)

The open function tries to make a connection and then login into a SAP System. This requires that a SAP sideinfo file be present (in the local directory or in other normal SAP places).

Please note that ALL SAP userids and password MUST be in upper case.

Open returns a value of zero (0) if a successful connection was made. This does not guarantee that the login was also successful. To verify that the login to SAP was successful, it is strongly recommended that a SAP_RFC::ping command be executed after successful completion of the SAP_RFC::open command.

* close

Close an SAP session

$ret = &SAP_RFC::close()

Close the connection to an SAP Instance. This closes the single open connection from SAP_RFC to an SAP instance. If close was successful, then close returns a value of zero (0);

* ping

Test a connection with an SAP System.

($ret, $string) = &SAP_RFC::ping()

This command attempts to execute the SAP RFCPING RFC on the SAP system to which we are connected by the SAP_RFC::open command. The primary reason for the inclusion of this command is to provide a relatively easy way to verify that an attempted was successful. A positive return from SAP_RFC::open does not make any promises about successful logins.

If the SAP_RFC::ping operation was successful, a value of zero (0) will be returned as the return value. The return string may contain an error message, for some failure categories. Do not count on finding an absolute cause for the failure in the returned string.

* callrx1

Send and receive a message string to an SAP RFC

($ret, $string) = &SAP_RFC::callrx1($abap, $message_string1)

SAP_RFC::callrx1 executes a SAP RFC RfcCallReceive() library command with the target SAP ABAP/4 program passed in the variable $abap. The message to be given to the ABAP/4 program is contained in the character string $message_string. The message_string MUST be less than 248 characters in length.

The 248 character limit is due to a 249 character limit within the ABAP development environment when the debugger is in use.

The SAP RFC library RfcCallReceive() function sends an RFC Call to the SAP system and waits to receive the transaction results from the SAP system. Only the single result string may be returned from an SAP ABAP/4 transaction.

This function assumes that the name of the record being passed to the SAP RFC ABAP/4 program is IMPORT_STRING and the record received from the SAP RFC ABAP/4 program is named EXPORT_STRING receiving end, no data will be passed.

The tables functionality of the SAP library is not implemented.

SAP_RFC::callrx1 expects the return of one string from the SAP system

If the SAP RFC library function RfcCallReceive() completed successfully, that is is the return was RFC_OK, then the return value from SAP_RFC::callrx1 is a value of zero (0).

Note: SAP seems to have a tendancy to occasionally "forget" that a connection has been made. To prevent this from "hanging" a program, a TIME_OUT response (return value of 9) will be returned after a 180 second delay. If this return value is received, retry the SAP_RFC::callrx1 transaction that timed out.

* callrx2

Send one and receive two messages to an SAP RFC

($ret, $string1, $string2) = &SAP_RFC::callrx2($abap, $string3)

SAP_RFC::callrx2 is the same as SAP_RFC::callrx1 EXCEPT that SAP_RFC::callrx2 expects the return of two (2) strings from the SAP system. This functionality is included because it is a local feature at the author's site where the second string is used for error management.

There may be situations where a return string of greater than 248 characters are required, in this case the ABAP/4 program could use both of the returned strings to pass data.

SAP_RFC::callrx2 executes a SAP RFC library RfcCallReceive() command with the ABAP passed as the target program and the message_string as the contents to be passed. The message_string MUST be less than 248 characters in length.

The 248 character limit is due to a 249 character limit within the ABAP development environment when the debugger is in use.

The SAP RFC library RfcCallReceive() function sends a call to the SAP system and waits to receive transaction results from the SAP system. Only the two result strings may be returned from a transaction.

This function assumes that the name of the record being passed to the SAP RFC ABAP/4 program is IMPORT_STRING and the first record received from the SAP RFC ABAP/4 program is named EXPORT_STRING and the second record is named EXPORT_STRING2. If the record names do not match in the ABAP/4 program and on the RFC receiving end, no data will be passed.

The tables functionality of the SAP library is not implemented.

Callrx2 expects the return of two strings from the SAP system, the contents of both strings are returned by callrx2.

If the RfcCallReceive() completed successfully, that is is the return was RFC_OK, then callrx2 returns a value of zero (0).

Note: SAP seems to have a tendancy to occasionally "forget" that a connection has been made. To prevent this from "hanging" a program, a TIME_OUT response (return value of 9) will be returned after a 180 second delay. If this return value is received, retry the SAP_RFC::callrx2 transaction that timed out.

* callrxx

Send and receive a message string to an SAP RFC

($ret, $string) = &SAP_RFC::callrxx($abap, $message_string1,

$from_record_name, $to_record_name)

SAP_RFC::callrxx executes a SAP RFC RfcCallReceive() library command with the target SAP ABAP/4 program passed in the variable $abap. The message to be given to the ABAP/4 program is contained in the character string $message_string. The name of the record to be received from the SAP APAB/4 RFC program is contained in the string $from_record_name and the name of the record to be sent to the SAP ABAP/4 RFC program is contained in the string $to_record_name names are to be less than 20 and greater than three (3) characters in length.

The 248 character limit is due to a 249 character limit within the ABAP development environment when the debugger is in use.

The SAP RFC library RfcCallReceive() function sends an RFC Call to the SAP system and waits to receive the transaction results from the SAP system. Only the single result string may be returned from an SAP ABAP/4 transaction.

This function makes no assumptions as to the names of the records passed between the SAP RFC ABAP/4 program and the SAP_RFC perl extension. This is because the record names are passed as part of the parameters of the function call. What ever the names may be, they must match or no data will be passed.

The tables functionality of the SAP library is not implemented.

SAP_RFC::callrxx expects the return of one string from the SAP system

If the SAP RFC library function RfcCallReceive() completed successfully, that is is the return was RFC_OK, then the return value from SAP_RFC::callrxx is a value of zero (0).

If the function does not like the record names passed to it, it will return a RFC_BAD_INPUT (11) value. This usually means no record names were passed to the function, or that the length of the names was too short (less than four(4) characters). The function only requires that a single name be passed, however, you may want to pass names for both send and receive in all cases.

Note: SAP seems to have a tendancy to occasionally "forget" that a connection has been made. To prevent this from "hanging" a program, a TIME_OUT response (return value of 9) will be returned after a 180 second delay. If this return value is received, retry the SAP_RFC::callrxx transaction that timed out.

* help

Brief message describing the SAP_RFC commands

$string = &SAP_RFC::help()

This returns a message containing a copyright notice and a list of the public functions in the

SAP_RFC extension.

This function is probably of minimal use.

* sysinfo

SAP_RFC::sysinfo calls the SAP ABAP/4 program RFC_SYSTEM_INFO and returns a string containing a record of system ``information'' about the connected SAP system.

($ret, $string) = &SAP_RFC::sysinfo()

This command is included mostly for demonstration purposes. This function is helpful as a means of building confidence that the interface really works.

The SAP ABAP/4 function RFC_SYSTEM_INFO should be contained on all shipped SAP systems.

The layout of the internal SAP record returned by RFC_SYSTEM_INFO is as follows:

Data Description Length Position

---------------------- ------ --------

RFC Log Version 3 0 - 2

Character Set (SAP) 4 3 - 6

Integer Format 3 7 - 9

Floating Point Format 3 10 - 12

Logical SAP Destination 32 13 - 44

Contacted Host 8 45 - 52

SAP System ID (RFC) 8 53 - 60

SAP System ID (DB) 8 61 - 68

Database Host Name 32 69 - 100

Database System Type 10 101 - 110

SAP Basis Release 4 111 - 114

SAP Machine ID 5 115 - 119

Operating System 10 120 - 129

Time Zone Offset (secs) 6 130 - 135

DST Flag 1 136 - 136

SAP_RFC::sysinfo returns the data from the SAP record as a string of of value-name pairs. Each of the value-name pairs are separated by colons (':'). The value and the name in the value-name pairs are separated by semicolons (';'). See the sample program for specifics.

As a footnote, the name of the record that the SAP ABAP program RFC_SYSTEM_INFO

returns is RFCSI_EXPORT.

* version

$ver = &SAP_RFC::version()

This is an internal function that returns an internal version number. There is no guarantee that this number will be current at any time.

This function is probably useless.

Example

The following example assumes that the SAP RFC services are established and tested. This is not the place to discuss how to establish SAP RFC services. (See the WWW site in Error! Bookmark not defined..)

There are two requirements for an rfcperl program. These are: an SAP sideinfo file and a program script. There is a sample program file included with the distribution, called sample.pl, which is similar to the program contained in this document.

The sample program has six major activities using the SAP_RFC module. These are:

Open a connection to an SAP system

Verify that there is a login on the SAP system

Get the system information from the SAP system

Execute an ABAP/4 program returning one string

Execute an ABAP/4 program returning one string

Disconnect from the SAP system

These show use of the major SAP_RFC module functions

Note: The sample program executes ABAP/4 programs local to the author's SAP system.

* sideinfo file

The sideinfo file is required by the underlying SAP libraries to provide connection path information.

This file is either in the local directory or in one of the ``standard'' SAP locations.

The following is a sample sideinfo file with a logical destination of ``C01'', the SAP host in

``c01name'' and the SAP gateway host is ``gwhost''. The services are ``00'' in both cases. The ``I''

protocol is for Unix to SAP over TCP/IP.

DEST=C01

LU=c01name

TP=sapdp00

GWHOST=gwhost

GWSERV=sapgw00

PROTOCOL=I

You may have multiple destinations in a single sideinfo file, separated by blank lines.

* Sample Program

#!./rfcperl -w

# test the SAP_RFC Module

# This is from the development library, so beware !

use lib './blib'; # For development

use SAP_RFC;

# connect to System C01, on client 888 as USER with a

# password of PASS with no trace flag.

$open_ret = &SAP_RFC::open ('C01', '888', 'USER', 'PASS', 'NO');

if ($open_ret != 0) # Return was non-zero

{

print "SAP::open() - FAILED !! \n";

print "did you specify a valid destination ? \n";

print "Bye Bye \n";

exit;

}

# Check the connection to make sure we are really logged in

($ping_ret, $ping_str) = &SAP_RFC::ping();

if ($ping_ret != 0)

{

print "SAP::ping() - FAILED !! \n";

print "Ping Error String - $ping_str \n";

print "Did you use the right client, user and password ?\n";

print "Bye Bye \n";

exit;

}

# This should work on all systems

# Go get the system info from the SAP system

print "\nSAP System Information \n";

($ret_val, $str) = &SAP_RFC::sysinfo();

if ($ret_val != 0)

{

print "SAP_RFC::sysinfo() - FAILED !! \n";

}

else

{

#split the name-value pairs

@pairs = split(/:/,$str);

foreach $pair (@pairs)

{

($name, $value) = split(/;/, $pair);

$SYS_INFO{$name} = $value;

}

# Display the pairs sorted by the key name

foreach $key (sort(keys %SYS_INFO))

{

if ($key eq 'DST_Flag')

{

if ($SYS_INFO{$key} eq 'X')

{

print "This System uses Daylight Savings Time \n";

}

else

{

print "This System DOES NOT use Daylight Savings Time \n";

}

}

else

{

print "$key = $SYS_INFO{$key} \n";

}

}

}

print "\n";

# This is a local function

# Now lets try to use callrx1.

# Z_WWW_INV1 returns the quantities of the passed item number

# in each of the inventory storage locations

$item = '0611077A70';

print "\nSAP Inventory Info for Item $item\n";

$i = 0;

$nstr = '';

$abap = 'Z_WWW_INV1'; # call this ABAP/4 program

$str = "xx$item"; # pass it this string

($inv_ret, $nstr) = &SAP_RFC::callrx1($abap, $str);

if ($inv_ret != 0) #call failed

{

print "SAP::callrx1($abap, $str) - FAILED !! \n";

}

else # call appears to be good

{

$inv_tot = 0;

$inv_nam[0] = substr($nstr,0,4);

$inv_dat[0] = substr($nstr,5, 15);

for ($i = 0; $i < 11; $i++)

{

$inv_dat[$i] = 0;

$inv_nam[$i] = ' ';

$na = ' ';

# the numbers are in the form of xx,xxx.xxx

# for a US SAP Setup

$inv_nam[$i] = substr($nstr, (22 * $i), 4);

$nb = substr($nstr, (22 * $i) + 5, 15);

$na = substr($nb, 0, 11); # strip off decimal and fractional

part

$na =~ y/0-9//cd; # get rid of non-numerics eg comma

$inv_dat[$i] = $na;

if (substr($inv_nam[$i], 0, 1) ne ' ')

{

$inv_tot += $inv_dat[$i];

}

}

for ($i = 0; $i < 11; $i++)

{

if (substr($inv_nam[$i], 0, 1) ne ' ')

{

print "$i - $inv_nam[$i] = $inv_dat[$i] \n";

}

}

print "Total Inventory = $inv_tot \n\n";

}

print "\n";

# another local function to show callrx2

# Do a call to the SAP ABAP/4 (Z_FIAM_ITEM) which returns

# -- in the first string -- (the second is for errors)

# a pair of of system parameters for the item number given to

# the ABAP/4 program.

print "\nCheck Item Number length Setting \n";

$inf_ret = 0;

$tstr = '';

$nstr = '';

$xnum = 0;

$xxnum = 0;

$xflg = '';

$abap = 'Z_FIAM_ITEM'; # call this ABAP/4

$str = '360611077A70'; # pass this string

($inf_ret, $tstr, $nstr) = &SAP_RFC::callrx2($abap, $str);

if ($inf_ret != 0) #call failed

{

print "SAP::callrx2($abap, $str) - FAILED !! \n";

}

else # call appears to be good

{

$xnum = substr($tstr, 0,4);

$xflg = substr($tstr, 5,1);

$xxnum = 0 + $xnum;

if ($xflg eq 'X')

{

print "The X flag is set and the item number length is $xxnum

\n";

}

else

{

print "The X flag is NOT set and the item number length is $xxnum

\n";

}

}

# OK we are done, close up shop

# Close the SAP connection and exit the program

$close_ret = &SAP_RFC::close();

if ($close_ret != 0) #call failed

{

print "SAP::close() - FAILED !! \n";

}

exit;

* Output from Sample program

The following is a slightly edited, to protect the innocent, output from an execution of the above script

SAP System Information

Character Set (SAP) = 1100

Contacted Host = c01name1

This System uses Daylight Savings Time

Database Host Name = c01db

Database System Type = ORACLE

Floating Point Format = IE3

Integer Format = BIG

Logical SAP Destination = c01name1_c01_00

Operating System = HP-UX

RFC Log Version = 011

SAP Basis Release = 21I

SAP Machine ID = 272

SAP System ID (DB) = c01

SAP System ID (RFC) = c01

TZ_Offset (secs) = -21600

SAP Inventory Info for Item 0611077A70

0 - 0069 = 0

1 - 0099 = 0

2 - 7600 = 0

3 - 7700 = 0

4 - MQE = 0

5 - WAHO = 5430

Total Inventory = 5430

Check Item Number length Setting

The X flag is set and the item number length is 10

NOTES

· The Author has a very limited hardware and operating system in which to test this extension. It has been built and tested with HPUX 10.20 and HPUX 9.04. Perl 5.004 is the only version of perl utilized.

· SAP R/3 version 2.2C is the only target SAP system this library has been tested against. (However, there is no reason to believe that other versions will perform differently.)

· The executable name was purposely made different than perl so that there would not be a confusion issue. Besides you may not always want to have the large executable floating around.

· The SAP libraries area apparently compiled with debugging flags set. You may wish to run strip before installing the executables.

· The SAP libraries are static only.

· RFC_SAP requires a sideinfo file in the ``local'' directory.

· Before you attempt to use the interface, make sure that the /etc/services file has the appropriate SAP specific entries.

· The tables functions of the SAP RFC libraries is not implemented.

· There is a 180 second "alarm clock" installed in case of SAP timeouts. The SAP_RFC::callrx1 (or 2 or x) function will return "TIME_OUT" (9) if the SAP system, after connection, does not respond in the 180 second window.

Blog Archive