2006 Jan 19 7:08 AM
Hi All,
Is it psbl to run a ABAP query to check a folder to collect data n store in SAP System from a remote server(Non-SAP System), Like if the SAP Server is in Remote place. The thing is ABAP query in Remote place SAP System should chk a particular folder for every 1 minute in the Non SAP System in India and the data's in that folder has to be loaded in the SAP system is it psbl.
If yes pls do suggest me the psbl ways to do it.
Suggestions and Help will be much Appreciated.
Ramesh.
2006 Jan 19 10:26 AM
use FTP_connect to connect the non-sap server.
use FTP_Copy to copy the file from non-sap server to the application server.
use ftp_desconnect.
then use
open dataset and read dataset to read data from application server to the internal table
2006 Jan 19 10:11 AM
Hi Ramesh,
First off I would use an FTP Script to bring the file from the Remote Server into the SAP Application Server. And then use the OPEN DATASET to read the file in a custom ABAP Program and do whatever that needs to be done with the data.. the entire process can be automated by scheduling a background job..
Regards,
Suresh Datti
2006 Jan 19 10:18 AM
Hi Ramesh,
1. The files and folder are on remote server,
hence, by using FTP or some method,
these files should COME to application SERVER.
2. Since we have to check every one minute,
the program (for uploading )
needs to run in background.
Hence, the files need to be on
application server (and not front-end server)
3. Also, we need to check, if the data / file
has been already uploaded.
4. We also need to keep trace / record
of the errors occuring during uploading !
regards,
amit m.
2006 Jan 19 10:26 AM
use FTP_connect to connect the non-sap server.
use FTP_Copy to copy the file from non-sap server to the application server.
use ftp_desconnect.
then use
open dataset and read dataset to read data from application server to the internal table
2006 Jan 19 12:05 PM
Hi Harikishore Sreenivasulu,
Can u tell me do i hav specify the RFC Destination as full IP address or by any other method.
B'cas the file has to read from remote server that 2 from Non-SAP System. I hav a big doubt in this.
Can pls explain me clearly.
Thanks & regds.
Ramesh.
2006 Jan 19 12:19 PM
Hi Ramesh
Actually the Sap system has to listen to the FTP port from where the data is transferred.
But there is one method where there are certain softwares which could transfer data from the legacy system to the sap system application server.
2006 Jan 19 12:57 PM
Hi Harikishore Sreenivasulu,
I cud not get it, can u giv me a clear example or scenario to chk with this FTP_Connect and FTP_Copy FM's.
I tried by giving the IP adress in the RFC Destination but it was not responding.
Pls do suggest me the way.
Thanks & Regds.
Ramesh.
2006 Jan 19 1:05 PM
HI Ramesh
try lsmw for transferring data.
The Legacy System Migration Workbench (LSMW) is a tool recommended by SAP that you can use to transfer data once only or periodically from legacy systems into an R/3 System.
transaction code is 'LSMW'
The LSM Workbench carries out the following tasks:
Reads the transfer data from one or more files (for example, spreadsheets, sequential files etc.)
Converts the data from the source format into the target format
2006 Jan 19 1:47 PM
I think the main problem is the reading from a remote system. Ask basis people to set up an ftp server. To make it safe, this should not be anonymous ftp. You should have an ftp user and password for starting an ftp session. An ftp port hast to be configures in your SAP system as a remote destination, the host is the ip address of the ftp server.
To establish ftp connection, use
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = p_user
password = lv_pass
host = p_host
rfc_destination = p_rfcdes
IMPORTING
handle = pv_handl
...
Then you can do (periodically) check directory listing using
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = pv_handl
command = lv_command
TABLES
data = pt_data
If command is 'ls', it will return the directory listing.
ftp commands get and mget will fetch the data. Syntax
get <file> <target file>; mget allows wildcards but then target file is equal to source file and the local directory has to be set correctly. Using Get you can specify the full path for the target file.
If you are not experienced with ftp, open a DOS session on your PC (start-run-cmd), enter ftp and try ftp commands. '?' will display the list of allowed commands.
See
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ftp.mspx
for details on (DOS/Windows) ftp; in unix it should be about the same.
For the repetition I'd suggest a background job with a loop interrpted by PAUSE statement. PAUSE will interrupt the process on system level and thus not need any resource.
Need more info? feel free to ask - this is a rough description only.
regards,
Clemens
2006 Jan 20 5:31 AM
Hi Harikishore Sreenivasulu,
I know that we can use LSMW, the thing is the server is in Remote location and the client Non SAP Server is in India.
And once when they save any data in particular folder the Query should chk for it n upload from Non SAP Server to SAP Server in Remote area.
Can u giv me a live example 2 use the FTP_Connect and FTP_Copy.
Thanks & Regds.
Ramesh.
2006 Jan 20 7:44 AM
Hi Clemens Li,
Can u giv me a live example to use the FTP_Connect, FTP_Command, FTP_Copy. to use it.
It will be much helpful.
B'cas i think u hav got my problem correctly.
Pls do suggest me.
Thanks & Regds.
Ramesh.
2006 Jan 20 8:04 AM
Hi,
here's a report for ftp get and copy to sercver, then dowmload to PC directory. You may modify to fulfill your requirements.
----
Object name................:
Transport request..........:
Author.....................: Clemens Li
Contact person.op. departm.:
Creation date..............:
Copied from................:
Functional description.....:
*
----
Change history:
----
Date Change reuest # Autor ID
Description
----
DD.MM.YYYY T00K...... Name NNYYYYMMDD
.....................
----
REPORT z_ftp_get . .
DATA:
gt_data TYPE TABLE OF text1024,
gv_folder TYPE string,
gv_handl TYPE i.
PARAMETERS:
p_host TYPE rfchost DEFAULT 'abc.def.ghi',
p_user TYPE syuname DEFAULT 'FTP_USER',
p_pass TYPE file DEFAULT '<ftp password>,
p_rfcdes TYPE rfcdest DEFAULT 'SAPFTP' OBLIGATORY,
p_rcd TYPE file DEFAULT '<remote directoiry>',
p_tmpdr TYPE fileintern
DEFAULT '<server directory',
p_lcd TYPE file,
p_prefix TYPE file DEFAULT '<files start with>',
p_list TYPE flag RADIOBUTTON GROUP func,
p_down TYPE flag RADIOBUTTON GROUP func.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lcd.
PERFORM f4_pcdir CHANGING p_lcd.
INITIALIZATION.
PERFORM initialization.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CHECK screen-name = 'P_PASS'.
screen-invisible = '1'.
MODIFY SCREEN.
ENDLOOP.
START-OF-SELECTION.
PERFORM ftp_open CHANGING gv_handl.
PERFORM ftp_command USING gv_handl:
'cd' p_rcd CHANGING gt_data,
'ls' '' CHANGING gt_data.
CASE 'X'.
WHEN p_list.
PERFORM ftp_list_files USING gt_data.
WHEN p_down.
PERFORM ftp_get_files USING gv_handl gt_data p_prefix p_tmpdr p_lcd.
ENDCASE." 'X'.
&----
*& Form ftp_open
&----
FORM ftp_open CHANGING pv_handl.
DATA:
lv_pass TYPE text40,
lv_key TYPE i VALUE 26101957,
lv_dstlen TYPE i,
lv_subrc TYPE sysubrc,
lv_direc TYPE file.
CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD p_pass ID 'KEY' FIELD lv_key
ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD lv_pass
ID 'DSTLEN' FIELD lv_dstlen.
CLEAR:
pv_handl.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = p_user
password = lv_pass
ACCOUNT =
host = p_host
rfc_destination = p_rfcdes
GATEWAY_USER =
GATEWAY_PASSWORD =
GATEWAY_HOST =
IMPORTING
handle = pv_handl
EXCEPTIONS
not_connected = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " ftp_open
&----
*& Form ftp_command
&----
FORM ftp_command
USING pv_handl TYPE i
pv_comnd TYPE file
pv_optns TYPE file
CHANGING pt_data TYPE table. .
DATA:
lv_command TYPE file.
FREE: pt_data.
CONCATENATE pv_comnd pv_optns INTO lv_command
SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = pv_handl
command = lv_command
COMPRESS =
VERIFY =
IMPORTING
FILESIZE =
FILEDATE =
FILETIME =
TABLES
data = pt_data
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4
.
""Lokale Schnittstelle:
*" IMPORTING
*" VALUE(HANDLE) TYPE I
*" VALUE(COMMAND) TYPE C
*" VALUE(COMPRESS) TYPE C OPTIONAL
*" VALUE(VERIFY) TYPE C OPTIONAL
*" EXPORTING
*" VALUE(FILESIZE) TYPE I
*" VALUE(FILEDATE) LIKE SY-DATUM
*" VALUE(FILETIME) LIKE SY-UZEIT
*" TABLES
*" DATA
*" EXCEPTIONS
*" TCPIP_ERROR
*" COMMAND_ERROR
*" DATA_ERROR
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " ftp_command
&----
*& Form ftp_get_files
&----
FORM ftp_get_files
USING
pv_handl TYPE i
pt_data TYPE table
p_prefix TYPE file
p_tmpdr TYPE fileintern
p_lcd TYPE file.
FIELD-SYMBOLS:
<fs_any> TYPE ANY.
DATA:
lt_data TYPE TABLE OF text1024,
lv_tmpdr TYPE file,
lv_tmpfil TYPE sapb-sappfad,
lv_file TYPE file,
lv_cmd TYPE file,
lv_lcfil TYPE sapb-sappfad.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
logical_filename = p_tmpdr
IMPORTING
file_name = lv_tmpdr
EXCEPTIONS
file_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT pt_data ASSIGNING <fs_any>.
CHECK <fs_any> CS p_prefix.
lv_file = <fs_any>+sy-fdpos.
CHECK lv_file CA space.
lv_file = lv_file(sy-fdpos).
CONCATENATE lv_tmpdr lv_file INTO lv_tmpfil.
CONCATENATE lv_file lv_tmpfil INTO lv_cmd SEPARATED BY space.
PERFORM ftp_command USING pv_handl 'get' lv_cmd
CHANGING lt_data.
CONCATENATE p_lcd '\' lv_file INTO lv_lcfil.
CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT'
EXPORTING
path = lv_tmpfil
targetpath = lv_lcfil
EXCEPTIONS
error_file = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
DELETE DATASET lv_tmpfil.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
text = lv_lcfil.
ENDIF.
ENDLOOP." at pt_data assigning <fs_any>.
ENDFORM. " ftp_get_files
&----
*& Form initialization
&----
FORM initialization.
DATA:
lv_dir TYPE string.
CALL METHOD cl_gui_frontend_services=>directory_get_current
CHANGING
current_directory = lv_dir.
CALL METHOD cl_gui_cfw=>flush.
p_lcd = lv_dir.
ENDFORM. " initialization
&----
*& Form f4_pcdir
&----
FORM f4_pcdir CHANGING pv_dir TYPE file.
CLEAR gv_folder.
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = 'Frontend Directory'
initial_folder = 'C:\'
CHANGING
selected_folder = gv_folder.
CALL METHOD cl_gui_cfw=>flush.
CHECK NOT gv_folder IS INITIAL.
pv_dir = gv_folder.
ENDFORM. " f4_pcdir
&----
*& Form ftp_list_files
&----
text
----
-->P_GT_DATA text
----
FORM ftp_list_files USING pt_data TYPE table.
FIELD-SYMBOLS:
<fs_any> TYPE ANY.
LOOP AT pt_data ASSIGNING <fs_any>.
CHECK <fs_any> CS p_prefix.
WRITE: / <fs_any>.
ENDLOOP." AT pt_data ASSIGNING <fs_any>.
ENDFORM. " ftp_list_files
Happy coding!
Clemens Li
2006 Jan 20 10:39 AM
Hi Clemens Li,
Thanks for the code.
I will Try with this code. Shall i msg u when its done.
I cannot view ur E-mail ID in Business Card.my id is
rameshkumard@changepond.com
Thank u very much for the effort u hav taken 2 help me.
Thanks & Regds.
Ramesh.