Communication To Presentation Server in Background Mode
Communication To Presentation Server in Background Mode
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.
Applies To:
SAP R/3 System.
This document is intended for those who want to communicate (read/write data) with the Presentation Server
(desktop system) in the Background Mode. In real time scenario some times we need to read or write data to
Presentation Server while the program is running in Background mode on the Application server. As we can
not use the usual GUI_UPLOAD / GUI_DOWNLOAD function modules for this purpose when the program is
running in Background mode, we end up with first writing data to Application Server and later again reading it
back from there. In this document we will see how to achieve Communicating to the Presentation Server
when the program is running in the Back ground mode on the Application Server, with few settings at your
SAP R/3 system and local machine.
Summary
In this article we will create one RFC destination in R/3 system to communicate with SAP front end and do
some settings at our Desktop System. Then we will write one sample program to read data from a text file on
the Presentation Server and again write back the data to an Excel file on the same Presentation Server, while
the program is running in Background mode (on the Application Server).
1. Go to SM59 transaction and press ‘Create’ button on the Application tool bar.
Here give some name (Ex:BJRFC) at the ‘RFC Destination’ field and mention ‘Connection type’ as ‘T’
(TCP/IP Connection) and enter some ‘Description’ (Ex: TCP / IP Connection to the Presentation Server.)
and SAVE it. Please see below screen.
3. After ‘Saving’ we get the below screen. Here just click the ‘Registration’ button.
4. At the above screen give some name (ex: BJACCESS) at the ‘Program ID’ field. See screen below.
5. AT the above screen, in the Menu select Destination->Gateway Options. You get the below popup
screen. Here enter your system Host name(i.e IP address of the system) and Gateway Service(This
will be sapgw00, here 00 is your system no). and click ‘OK’ .
6. After clicking ‘OK’ on the Popup screen, we are presented with the below screen . Here ‘Save’ . This
completes creating the RFC destination of TCP/IP Connection type to the Presentation Server.
Then open the SAPRFC.INI file in BIN folder and Register a RFC server program at a SAP Gateway.
We need to enter two entries for ‘R’ type in the SAPRFC.INI file like below.
DEST=RTL_R
TYPE=R
PROGID=BJACCESS.rfcexec
GWHOST=10.250.4.203
GWSERV=sapgw00
RFC_TRACE=0
DEST=RTL_R
TYPE=R
PROGID=BJACCESS.trfcexec
GWHOST=10.250.4.203
GWSERV=sapgw00
RFC_TRACE=0
Here DEST = SystemID_R, in our case system ID is RTL. So we gave like RTL_R.
TYPE = ‘R’, because we need to register a RFC server program at a SAP Gateway and wait for RFC calls by
R/3 or R/2 System.
GWHOST= this is your system I.P. address that we enter in Gateway options of RFC Destination.
GWSERV= Gateway service name (This will be sapgw00, here 00 is your system no).
Then save the file and close it. With this we have finished the settings at our Local system.
Open command prompt and go to the bin Directory, where we have RFCEXEC.EXE file. Then enter below
command and press enter it will not come back to dos prompt. If it has come back check your settings and
again try this.
After going to bin directory enter command rfcexec –a<Program ID in RFC destination>
-g<SAP Host>
Now go to SM59 Transaction and test our RFC destination BJRFC, by clicking the ‘Test Connection’ button
Be sure that the connection is successful. If it fails check your settings and try again. And we need to
remember one thing here before testing first we should run the RFCEXEC file in the command prompt like we
did here.
Now we will write a program which will read Text file from presentation server and write back to the
presentation server in Excel format while running in background mode.
Sample Program
This program will use the function module ‘RFC_REMOTE_FILE’ to read and write data to presentation
server. We use the RFC destination created above (BJRFC), when we call this RFC function module.
REPORT ZBJ_RFC
LINE-COUNT 65
LINE-SIZE 130
NO STANDARD PAGE HEADING
MESSAGE-ID ZTEST.
*----------------------------------------------------------------------*
* Developer: Srilatha T *
* Date: 12/06/2005 *
* Program Type: Executable Program *
* Description: This report will read text file from presentation*
* server and writes back to presentation server in *
* Excel file while running in Background mode *
* Tables Used: *
* Function Modules: RFC_REMOTE_FILE *
* Other Dependencies: *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* T Y P E D E C L A R A T I O N S
*----------------------------------------------------------------------*
*--Data Structure For reading data
TYPES: BEGIN OF tp_final,
pernr type pa0001-pernr, " Pernr
sname TYPE pa0001-sname, " Employee Name
END OF tp_final.
*----------------------------------------------------------------------*
* I N T E R N A L T A B L E D E C L A R A T I O N S
*----------------------------------------------------------------------*
*--Internal table declaration for Employee Details
DATA: dt_final TYPE STANDARD TABLE OF tp_final,
dt_final1 TYPE STANDARD TABLE OF tp_final.
*----------------------------------------------------------------------*
* D A T A D E C L A R A T I O N S
*----------------------------------------------------------------------*
data : dg_flag type c, " Flag
dg_flag1 type c, " Flag
ds_final type tp_final,
dg_ermsg(120). " Error message
*----------------------------------------------------------------------*
* C O N S T A N T S D E C L A R A T I O N S
*----------------------------------------------------------------------*
CONSTANTS: c_dest type rfcdes-rfcdest value 'BJRFC',
c_x TYPE c VALUE 'X'. " For X
*----------------------------------------------------------------------*
* S E L E C T I O N S C R E E N
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*----------------------------------------------------------------------*
* S T A R T O F S E L E C T I O N
*----------------------------------------------------------------------*
START-OF-SELECTION.
* Form to read data
perform read_data.
if not dt_final[] is initial.
dt_final1[] = dt_final[].
* Form to write data
perform write_data.
else.
write : / 'Data is not found'(002).
endif.
*----------------------------------------------------------------------*
* E N D O F S E L E C T I O N
*----------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form read_data
*&---------------------------------------------------------------------*
* To read data from Excel file
*----------------------------------------------------------------------*
FORM read_data.
dg_flag = c_x.
* Fom to read func for reading
perform call_func tables dt_final
using readpath
dg_flag
dg_flag1.
exporting
file = p_readpath
read = p_flag
write = p_flag1
tables
filedata = P_final
exceptions
system_failure = 1 message dg_ermsg
communication_failure = 2 message dg_ermsg.
if sy-subrc <> 0.
format reset intensified off.
write: / 'RFC ERROR:'(003), dg_ermsg.
else.
if dg_flag = c_x.
write : / 'Data is successfully Uploaded'(004).
else. dg_flag1 = c_x.
write : / 'Data is successfully Downloaded'(005).
endif.
endif.
dl_repid = sy-repid.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = dl_repid
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = dl_file
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
p_file = dl_file.
ELSE.
MESSAGE I999 WITH 'Error while getting the file name'(007).
ENDIF.
In the READPATH parameter give file path to read the file and in the WRTEPATH parameter give download
file path and run the program in Background mode. This program will read the text file from the path specified
and writes back to file in the entered path in excel format.
Sample Output:
Points to be noted
¾ Before running the program first we need to run the rfcexec in the command prompt passing
parameters –a<program ID> -g<SAP Host> -x<SAP GatewayService>.
¾ It should not come back to command prompt when we execute the rfcexec. If it is returning to
command prompt then check your settings and do it again.
¾ Be sure that rfcexec file should be running at your local machine, when ever we are communicating
to the presentation server in the background mode, then only it can communicate with the front end
in the background mode.
¾ After scheduling the Back ground job we can log off the SAP system. This does not hinder the
communication between the desktop and the App Server in any way. Of course the Desktop should
remain switched on!!
Author Bio
Srilatha Thirukkovalluri has around 5 years of experience in ABAP/4 programming techniques
using quality-driven methodologies. She has expertise in Net weaver - XI Competency and
Business Server Pages. Currently she is working with Intelligroup Asia Pvt Ltd as Systems
Analyst.