07-05-2011 11:18 AM
Hello Experts,
I am trying to execute an ABAP report, which creates a text file as output. When i run the report in foreground, the report executes and creates the text file as output.
However, when i run the report in the background,it doesnt creates the text file. I have scheduled this as background job to run every 5 mins. when i check SM37, the job is actually running every 5 mins and it's status is FINISHED, but it's not creating the text file as output.
I have used GUI_DOWNLOAD function in my ABAP program. I have googled and found that GUI_DOWNLOAD doesnt work in back ground processing.
Can you guys advise,
1) which function module to be used for back ground processing.
2) I have read somewhere that defining a RFC to communicate between the presentation server (desktop) and the Application server (SAP), which would help in executing the job in background. If yes, can you please guide me, how to create a RFC communication and how could i run the ABAP report in backgound process.
Appreciate your fast response.
Thanks and Regards
Arif Ahmed.
Moderator Message: Urgency downgraded
Edited by: Suhas Saha on Jul 5, 2011 4:06 PM
07-05-2011 11:32 AM
Hi Arif,
2) I have read somewhere that defining a RFC to communicate between the presentation server (desktop) and the Application server (SAP),
I guess the below link should help you achieve your requirement.
http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/9831750a-0801-0010-1d9e-f8c64efb2bd2
Regards,
Chen
07-05-2011 12:35 PM
Hi Chen,
thanks for your prompt reply.
I have gone through the manual, I tried configuring the RFC but i wasnt able to find the "RFCSDK" on the local computer as mentioned on the manual.
Can you please guide.
Thanks and Regards
Arif.
07-05-2011 12:43 PM
Hi Arif,
Please tell your functional consultant that background job cannot handle presentation server files.
Using RFC or mapping a shared drive to SAP Application server directory are not preferred solutions .
07-05-2011 1:20 PM
07-05-2011 1:30 PM
Hi Nilima,
I cannot send that text file via email, because this file is actually a feed for LED system. The Data in the text file is actually the PRODUCTION LIVE DATA, which needs to be displayed on the LED SIGN BOARDS.
The LED software pushes the data in the text file to the LED Displays. Thus, i cannot use email option.
As you mentioned in your post, Can i use OPEN DATASET , TRANSFER AND CLOSE DATASET. Can you please give me an example on using that. OR Creating and RFC between the desktop and the SAP will help.
Please advise.
Thanks and Regards
Arif.
07-05-2011 5:17 PM
Hello Arif,
If you want to write the file to a directory(which cannot or shouldn't be mapped to the SAP AS for e.g., a 3rd party app) you can use [FTP|http://wiki.sdn.sap.com/wiki/display/ABAP/StandardSAPFTP+programs] to place your file.
Otherwise you can use the SAP AS to download the file & ask the external system to pick the file from the SAP AS.
As for the solution with defining the local disk as a RFC, what'll happen if the system is shut down? I think in this case you'll get a COMMUNICATION_FAILURE exception in your RFC call!
BR,
Suhas
07-05-2011 5:41 PM
Hi,
This is a sample program using OPEN DATASET. Wrote in a hurry do dont worry about internal table declarations.
REPORT ZFILE_TO_APP .
&----
*& Data Transfer to APP Server
&----
Parameters to enter the path
PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/app_file.dat'.
Table Declaration
TABLES VBAK.
Data Declaration
DATA lv_msg(50).
Get data for file transfer
DATA lt_vbak LIKE VBAK OCCURS 100
WITH HEADER LINE.
SELECT * FROM VBAK INTO TABLE lt_vbak.
SORT lt_vbak BY VBELN.
LOOP AT lt_vbak.
WRITE: / lt_vbak-VBELN,
lt_vbak-KUNNR.
ENDLOOP.
Opening the File
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
MESSAGE lv_msg.
IF SY-SUBRC NE 0.
WRITE: 'Error opening File. Reason:', lv_msg.
EXIT.
ENDIF.
Transferring Data
LOOP AT lt_vbak.
TRANSFER lt_vbak-VBELN TO FILENAME.
ENDLOOP.
Closing the File
CLOSE DATASET FILENAME.
Hope this solves your issue
Enjoy SAP
AbapRaj
07-06-2011 9:24 AM
Hi Raj,
Thanks alot for the your prompt reply.
I tried using your sample code and re-wrote my program like this
TYPES : Begin of ty_out,
line(250),
end of ty_out.
Data : it_out type standard table of ty_out with header line.
DATA: p_file type rlgrap-filename .
p_file = 'D:/LEDDISPLAY/PRDtext.rft'.
****To display total of line1 and line2*****
Concatenate 'TOTAL PRD' TOTAL' CANS'
INTO it_out-line .
append it_out.
CLEAR : it_out.
****To display line1 prd****
Concatenate 'Line1 PRD' TOTAL1' CANS'
INTO it_out-line .
append it_out.
CLEAR : it_out.
DATA: file type string.
file = p_file.
Data Declaration
DATA lv_msg(50).
OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
MESSAGE lv_msg.
IF SY-SUBRC NE 0.
WRITE: 'Error opening File. Reason:', lv_msg.
EXIT.
ENDIF.
LOOP AT it_out. " into l_text_data.
TRANSFER it_out TO file.
ENDLOOP.
CLOSE DATASET file.
However, when i'm executing, This throwing me an error " Error opening File. Reason: Permission denied".
Secondly, Will the above code work, when I'm scheduling this program in background. I have ftp server and i created a new folder called LEDDISPLAY, Is it possible to write directly on the ftp server using DATASET.
Appreciate your response.
Thanks alot
07-06-2011 9:45 AM
Hi Arif,
If you are dropping the file on the FTP server, the p_file should contain the complete filepath to the FTP server, and the username with which the background program will be run should have sufficient authorization on the target FTP server.
p_file = 'D:/LEDDISPLAY/PRDtext.rft'.
The above code will fail.
Why don't you try to FTP the file to the FTP server. Below is an examples.
http://wiki.sdn.sap.com/wiki/display/ABAP/WorkingwithFTP+Server
From your first post i thought the requirement was to download a file from a background program onto your local PC.
The RFCSDK must be on your SAPGui installation disk.
Regards,
Chen
07-06-2011 10:28 AM
Hi ,
My requirement is that my ABAP program, which i want to schedule as background proces must create the output in text file.
IF I USE FM GUI_DOWNLOAD, THE PROGRAM WORKS IN FOREGROUND AND CREATES THE OUTPUT FILE. BUT I WANT TO SCHEDULE THE PROGRAM IN BACKGROUND.
To attain that, I am trying both the methods of
1) DATASET
2) FTP
but, both of the methods mentioned above are giving me errors.
1) When I use DATASET, to download the data on my local hard disk D drive using the code which i posted before. It's throwing me an error "Error opening File. Reason: Permission denied"
I have already given full access to the folder.
2) When I use FTP,It is throwing me this error " FTP subcommand: Server reports error Message no. 04209"
I use the below code
TYPES : Begin of ty_out,
line(250),
end of ty_out.
Data : it_out type standard table of ty_out with header line.
DATA: p_file type rlgrap-filename.
p_file = 'ftp://192.168.100.11/LEDDISPLAY/PRDtext.txt'.
Concatenate 'TOTAL PRD' TOTAL' CANS'
INTO it_out-line .
append it_out.
CLEAR : it_out.
****To display line1 prd****
Concatenate 'Line1 PRD' TOTAL1' CANS'
INTO it_out-line .
append it_out.
CLEAR : it_out.
****To display line2 prd****
Concatenate 'Line2 PRD' TOTAL2'CANS'
INTO it_out-line .
append it_out.
CLEAR : it_out.
****ENd of displaying****
DATA: file type string.
file = p_file.
DATA: l_user(30) TYPE c VALUE '****, "user name of ftp server
l_pwd(30) TYPE c VALUE '******'. "password of ftp server
DATA: l_host(64) TYPE c VALUE 'xxx.xxx.xxx.xx', "ip address of FTP server
l_dest LIKE rfcdes-rfcdest VALUE 'SAPFTPA'."Background RFC destination
DATA: w_hdl TYPE i value 1,
c_key TYPE i VALUE 26101957,
l_slen TYPE i.
*HTTP_SCRAMBLE: used to scramble the password provided in a format recognized by SAP.
SET EXTENDED CHECK OFF.
l_slen = STRLEN( l_pwd ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = l_pwd
sourcelen = l_slen
key = c_key
IMPORTING
destination = l_pwd.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Connect to FTP Server'.
To Connect to the Server using FTP
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = l_user
password = l_pwd
host = l_host
rfc_destination = l_dest
IMPORTING
handle = w_hdl
EXCEPTIONS
OTHERS = 1.
if sy-subrc ne 0.
format color col_negative.
write:/ 'Error in Connection'.
else.
write:/ 'FTP Connection is opened '.
endif.
Create file on FTP server
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Create file on FTP Server'.
*Loop at it_out.
*FTP_R3_TO_SERVER:used to transfer the internal table data as a file to other system in the character mode.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = w_hdl
fname = p_file "file path of destination system
CHARACTER_mode = 'X'
TABLES
text = it_out
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING invalid_output_file.
ENDIF.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Writing Contents to the file'.
*ENDLOOP.
*FTP_DISCONNECT: This is used to disconnect the connection between SAP and other system.
To disconnect the FTP
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = w_hdl.
*RFC_CONNECTION_CLOSE:This is used to disconnect the RFC connection between SAP and other system.
CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = l_dest
EXCEPTIONS
OTHERS = 1.
07-06-2011 10:41 AM
Arif,
1) When I use DATASET, to download the data on my local hard disk D drive using the code which i posted before. It's throwing me an error "Error opening File. Reason: Permission denied"
I have already given full access to the folder.
You cannot use DATASET ABAP construct to transfer data from App server to your local drive, irrespective of how you run it - Fore/Background. GUI_DOWNLOAD will work only in foreground as you have realized already.
DATA: p_file type rlgrap-filename.
p_file = 'ftp://192.168.100.11/LEDDISPLAY/PRDtext.txt'.
I presume the above IP is that of your local machine, if so have you activated the FTP service on your local machine and the FTP port is open without any restrictions?
I thought you had a FTP server installed, anyways if your requirement is still the same - that is download a text file from an ABAP program running in background, your best bet is still the option that i mentioned in my first reply to your OP.
If you do not have RFC SDK, then re-install SAPGui in custom mode and choose to install all the components, this shoudl get you the RFCSDK folder.
Regards,
Chen
Edited by: Chen K V on Jul 6, 2011 3:18 PM
07-06-2011 12:31 PM
Hi Achmed,
hammer it into your brain: FM GUI_DOWNLOAD does not work in background. The GUI in the name implies you need a SAP GUI - you never have such in background. That's where the name background comes from.
Various possibilities have been name as ftp, shared drives etc.
I'm convinced your basis people know which server drive can be accessed by follow-up-process.
The it is your job to check SY-BATCH background flag and in this case use OPEN / TRANFER / CLOSE DATASET.
There is no upload/download in background, only READ and TRANSFER (write) to and from DATASET (file) . You can use this also online because you always are connected to SAP server.
What else can I say to make this more understandable.
Regards,
Clemens
07-06-2011 1:25 PM
Hi All,
I would like to thank everyone of you, who took some time out of their valuable time to reply to my post.
I got my desired result.
I used DATASET and wrote the contents to a shared drive.
Thank you all
Regards
Arif Ahmed.
12-10-2013 7:43 AM
07-10-2011 9:00 AM
Hi All,
Is it possible to change the font size and font color of the text file , which is generated.
Appreciate your responses.
Thanks
Arif Ahmed.
07-10-2011 1:02 PM
Hi Arif,
according to forum rules this should be a new question.
A text file is widely understood as a file containing only printable characters and some control characters like carriage return and line feed depending on operating system and code page.
Font size and color are interpretation of a special text format by a special interpreting program.
SAP lists and spool files use a completely different way as standard html or MS word or PDF or what ever.
First answer the question as how the file will be displayed or printed, then check what kind of font and color control is used, then analyze if it is possible to apply this technique when creating the text file.
Regards,
Clemens
12-18-2012 3:40 PM
Hi Arif
How did you resolve this?
Please share your Solutions for this post