‎2008 Apr 25 1:11 PM
Hi Guys,
I have to extract data from r3 to 5 files and these files must be placed into an interface folder?
Please tell me the steps how to proceed with an example? as it is very urgent?
<REMOVED BY MODERATOR>
Thanks in advance
MS
Edited by: Alvaro Tejada Galindo on Apr 25, 2008 5:37 PM
‎2008 Apr 25 1:21 PM
Hello,
I suggest you to read this [https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5564] [original link is broken] [original link is broken] [original link is broken];.
Regards,
‎2008 Apr 25 1:21 PM
Hello,
I suggest you to read this [https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5564] [original link is broken] [original link is broken] [original link is broken];.
Regards,
‎2008 Apr 25 1:27 PM
Hi,
The Function module GUI_DOWNLOAD is used to download the data into presentation server and Dataset concepts to download the data into Application server. Sometimes we may require to download the data into other system (3rd Party System) from SAP. In such scenarios, the concept of FTP commands comes into picture through which data (internal table data) from SAP can be transffered to other system.
This scenarios can be achieved through SAP using the FTP Commands which are available within SAP. The data gets transferred to other systems. The concept is that the internal table data will be placed as a file in other systems using the FTP concept.
The various FTP commands which are needed for this prupose are HTTP_SCRAMBLE, FTP_CONNECT, FTP_R3_TO_SERVER, FTP_DISCONNECT, RFC_CONNECTION_CLOSE function modules.
HTTP_SCRAMBLE: This is used to scramble the password provided into a format which is been recognized by SAP.
l_pwd = p_pwd.
l_slen = STRLEN( l_pwd ).
CALL FUNCTION 'HTTP_SCRAMBLE'
exporting
source = l_pwd
sourcelen = l_slen
key = c_key
importing
destination = l_pwd.
FTP_CONNECT : This is used to connect to other system from SAP with the help of Userid & amp; scrambled password & Host string & destination (default 'SAPFTP').
To Connect to the Server using FTP
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = p_user
password = l_pwd
host = p_host
rfc_destination = c_dest
IMPORTING
handle = w_hdl
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
FTP_R3_TO_SERVERThis is 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 = <file path of destination system>
character_mode = 'X'
TABLES
text = <internal table data>
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.
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 = c_dest
EXCEPTIONS
OTHERS = 1.
‎2008 Apr 25 1:29 PM
Hello Misbah,
You need to use SAP Exchange Infrastructure for this ..I t can handle it easily...
Technnical Details
USe Proxy to File Scenario
In which we need to configure 5 communication channels for 5 files to which we need to passt the data.
Advanatage is we can monitor how the data is moving and we can automate the process effiicently and irrespective of the file format and size and also reusabily comes in picture ,if same logic has to use for another system
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Apr 25, 2008 5:37 PM
‎2008 Apr 26 12:49 PM
hi check this interface this will download to the pc and application server...
REPORT REPORT
NO STANDARD PAGE HEADING
line-size 120
MESSAGE-ID zhris.
----
T A B L E S
----
TABLES: pa0105,
pa0002.
----
T Y P E D E C L A R A T I O N S
----
*---Types for the final table
types : begin of ty_final ,
pernr like pa0000-pernr, "Personnel number
nachn like pa0002-nachn, "Last Name
vorna like pa0002-vorna, "First Name
usrid like pa0105-usrid, "Communication ID/Number
usrid_long like pa0105-usrid_long,"Communication: Long
end of ty_final.
----
I N T E R N A L T A B L E S
----
*-----Internal table to hold the data of emp like userid, email
data: it_pa0105 like p0105 occurs 0 with header line ,
*-----Internal table to check for active employee
it_pa0000 like pa0000 occurs 0 with header line,
*-----Internal table to hold the data of emp like first, last name
it_pa0002 like p0002 occurs 0 with header line,
*-----Internal table for final data
it_final type standard table of ty_final with header line.
*-----Internal table for Error Records
DATA: BEGIN OF T_ERROR OCCURS 0,
PERNR LIKE PERNR-PERNR,
MESSAGE(60) TYPE C,
END OF T_ERROR.
----
VARIABLE DECLARATIONS *
----
data : v_pernr like pa0000-pernr,
v_lines type i.
DATA: W_MSG(150) TYPE C.
----
S E L E C T I O N - S C R E E N
----
SELECTION-SCREEN BEGIN OF BLOCK FILE WITH FRAME TITLE TEXT-FIL.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: P_PC RADIOBUTTON GROUP RAD USER-COMMAND USR. "PC
SELECTION-SCREEN COMMENT 3(5) TEXT-SC1.
PARAMETERS: P_UNIX RADIOBUTTON GROUP RAD DEFAULT 'X'. "UNIX
SELECTION-SCREEN COMMENT 11(5) TEXT-SC2.
parameters:p_file like rlgrap-filename.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK FILE.
----
INITIALIZATION *
----
initialization.
data: v_date like pa0002-begda.
write: sy-datum to v_date .
concatenate '/VOLSAP/Corpedia_' v_date '.txt' into p_file.
----
AT SELECTION-SCREEN *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
F4 help for the flat file path
PERFORM F4_FILEPATH.
----
S T A R T - O F - S E L E C T I O N
----
START-OF-SELECTION.
*---Get the active employyes
select * from pa0000
into table it_pa0000 up to 100 rows
where endda >= sy-datum
and begda <= sy-datum
and stat2 = '3'.
if sy-subrc = 0.
sort it_pa0000 by pernr endda descending.
delete adjacent duplicates from it_pa0000 comparing pernr.
endif.
loop at it_pa0000.
clear : it_pa0002 ,it_pa0105,
it_pa0002[] , it_pa0105[] ,
v_pernr.
v_pernr = it_pa0000-pernr.
*---Get first name, last name of the active employee
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
PERNR = v_pernr
INFTY = '0002'
BEGDA = sy-datum
ENDDA = sy-datum
TABLES
INFTY_TAB = it_pa0002.
*---Get SAP ID , email of the active employee
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
PERNR = v_pernr
INFTY = '0105'
BEGDA = sy-datum
ENDDA = sy-datum
TABLES
INFTY_TAB = it_pa0105.
sort it_pa0002 by pernr begda descending.
delete adjacent duplicates from it_pa0002 comparing pernr.
sort it_pa0105 by pernr begda descending.
delete adjacent duplicates from it_pa0105 comparing pernr.
if not it_pa0002[] is initial.
read table it_pa0002 index 1.
if sy-subrc = 0.
it_final-pernr = it_pa0002-pernr.
it_final-nachn = it_pa0002-nachn.
it_final-vorna = it_pa0002-vorna.
else.
T_ERROR-PERNR = it_pa0002-PERNR.
CONCATENATE TEXT-EMI '0002'
INTO T_ERROR-MESSAGE SEPARATED BY SPACE.
APPEND T_ERROR.
CLEAR T_ERROR.
ENDIF.
endif.
if not it_pa0105[] is initial.
read table it_pa0105 index 1.
if sy-subrc = 0.
if it_pa0105-subty = '0001'.
it_final-usrid = it_pa0105-usrid.
endif.
if it_pa0105-subty = '0010'.
it_final-usrid_long = it_pa0105-usrid_long.
endif.
else.
T_ERROR-PERNR = it_pa0105-PERNR.
CONCATENATE TEXT-EMI '0105'
INTO T_ERROR-MESSAGE SEPARATED BY SPACE.
APPEND T_ERROR. CLEAR T_ERROR.
ENDIF.
endif.
if not it_final-pernr is initial.
append it_final.
endif.
clear it_final.
endloop.
----
END- O F - S E L E C T I O N
----
END-OF-SELECTION.
describe table it_final lines v_lines .
*---get data into Application Server.
PERFORM OUTPUT_CORPEDIA_VENDOR_FILE .
SKIP 2.
WRITE:/ 'FILE NAME :' , P_FILE .
WRITE:/ 'NO OF RECORDS DOWNLOADED : ', V_LINES .
perform write_error_messages.
&----
*& Form F4_FILEPATH
&----
F4 HELP FOR FILE PATH
----
FORM F4_FILEPATH.
IF P_UNIX = 'X'.
F4 help for UNIX
CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
EXPORTING
DYNPFIELD_FILENAME = 'P_FILE'
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
FILETYPE = 'P'
LOCATION = 'A'
SERVER = ''.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH TEXT-E01 P_FILE.
ENDIF.
ELSEIF P_PC = 'X'.
F4 help for PC
clear p_file.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = P_FILE
MASK = ',..'
MODE = '0 '
TITLE = 'Choose File'
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDIF.
ENDFORM. " F4_FILEPATH
&----
*& Form WRITE_ERROR_MESSAGES
&----
Writes the error messages
----
FORM WRITE_ERROR_MESSAGES.
PERFORM WRITE_ERROR_HEADERS.
LOOP AT T_ERROR.
WRITE: / T_ERROR-PERNR,
15 T_ERROR-MESSAGE.
IF SY-LINNO = 64.
PERFORM WRITE_ERROR_HEADERS.
ENDIF.
ENDLOOP.
ENDFORM. " WRITE_ERROR_MESSAGES
&----
*& Form WRITE_ERROR_HEADERS
&----
Error Headers
----
FORM WRITE_ERROR_HEADERS.
NEW-PAGE.
ULINE. SKIP.
format color col_negative.
WRITE: / 'Employee ID',
15 'Error Message'.
format color off.
WRITE: / '***********',
15 '*******************************'.
ENDFORM. " WRITE_ERROR_HEADERS
&----
*& Form OUTPUT_CITISTREET_DEMO_FILE
&----
Output the Schwab Demographic file
----
FORM OUTPUT_CORPEDIA_VENDOR_FILE .
IF P_PC = 'X'.
data: v_pcfile type string.
v_pcfile = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = v_pcfile
FILETYPE = 'ASC'
TABLES
DATA_TAB = it_final.
else.
data: outrec(200) type c .
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE encoding DEFAULT.
loop at it_final.
outrec+0(8) = it_final-pernr.
outrec+8(40) = it_final-nachn.
outrec+48(40) = it_final-vorna.
outrec+88(30) = it_final-usrid.
outrec+118(40) = it_final-usrid_long.
transfer outrec to p_file.
clear outrec.
endloop.
CLOSE DATASET OUTREC.
IF SY-SUBRC = 0.
CLEAR W_MSG.
CONCATENATE 'Corpedia Vendor Demographic File successfully written to:'
P_FILE
INTO W_MSG SEPARATED BY SPACE.
ULINE. SKIP.
WRITE : W_MSG.
ENDIF.
ENDIF.
ENDFORM. " OUTPUT_CORPEDIA_VENDOR_FILE
Regards,
venkat.