Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Function Module For Flat file and ftp

Former Member
0 Likes
1,125

Hi,

I need a function module to which i will pass a internal table and the output should be a flat file with pipe delimeted.

Regards

Hiren K.Chitalia

7 REPLIES 7
Read only

Former Member
0 Likes
815

And that particular flat file i need to post on a ftp server

Read only

0 Likes
815

Hi Hiren,

You have to use Open dataset, Transfer, Close dataset statements for transferring your data from the internal table to the application server.

While transferring you can concatenate the character '|' between the fields if a pipe delimited file is required.

See the link below for an example of Downloading a file to an application server.

(Its tab delimited)

Regards,

Abhishek

Read only

Former Member
0 Likes
815

Hiran,

I am not sure if you really need a function module for this task. You can directly write internal table data in application server.

Please check below code.

upload from application server.

tables : ZDEPARTMENT_TMP.

data : itab like ZDEPARTMENT_TMP occurs 0 with header line.

constants File(30) type C value '/usr/tmp/sri1111.txt'.

open dataset File for input in text mode.

do.

read dataset File into itab.

if sy-subrc <> 0.

write 😕 'No more records'.

exit.

else.

append itab.

endif.

enddo.

close dataset File.

loop at itab.

write 😕 itab-EMPID,itab-EMP_DEPT,itab-EMP_PROJ,itab-EMP_CUBE,

itab-EMP_PH_NO.

ZDEPARTMENT_TMP-EMPID = itab-EMPID.

ZDEPARTMENT_TMP-EMP_DEPT = itab-EMP_DEPT.

ZDEPARTMENT_TMP-EMP_PROJ = itab-EMP_PROJ.

ZDEPARTMENT_TMP-EMP_CUBE = itab-EMP_CUBE.

insert ZDEPARTMENT_TMP.

endloop.

Read only

Former Member
0 Likes
815

You can try with CALL FUNCTION 'GUI_UPLOAD'.

Thanks,

Srinivas

Read only

0 Likes
815

You can use the field separator as 'I' pipe symbol.

Reward if it is useful.

Thanks,

Srinivas

Read only

Former Member
0 Likes
815

Hi, Hiren

you can define another internal table IT_LINE which contain only one record, like CHAR300, and convert the records in original internal into the IT_LINE, convert one record into one line.

Then use the below function to transferyour data to FTP.

c_dest LIKE rfcdes-rfcdest VALUE 'SAPFTP',

c_key TYPE i VALUE 26101957.

1. Convert the password

data: g_ftp_pwd(20).

g_ftp_pwd = 'tx02ut'.

g_slen = STRLEN( g_ftp_pwd ).

CALL FUNCTION 'HTTP_SCRAMBLE'

EXPORTING

SOURCE = g_ftp_pwd

sourcelen = g_slen

key = g_key

IMPORTING

destination = g_ftp_pwd.

2. Connect FTP

data: g_rfcdes_rfcdest LIKE rfcdes-rfcdest VALUE 'SAPFTP'.

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

user = 'whqtr'

password = g_ftp_pwd

host = g_ip

rfc_destination = g_rfcdes_rfcdest

IMPORTING

handle = g_hdl

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.

3. Transfer file

CALL FUNCTION 'FTP_R3_TO_SERVER'

EXPORTING

handle = g_handle

fname = g_filename_tmp

blob_length = c_blob

character_mode = 'X'

TABLES

text = pt_contents

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

p_retcd = 3. "Put file fail

RETURN.

ENDIF.

4. Close FTP Connect

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = g_hdl.

CALL FUNCTION 'RFC_CONNECTION_CLOSE'

EXPORTING

destination = g_rfcdes_rfcdest

EXCEPTIONS

OTHERS = 1.

Hope this helpful

Regards.