REPORT ZTRANSFERDATA.
* Data declarations for later use
PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat'
LOWER CASE.
TABLES CUSTOMERS.
DATA MSG_TEXT(50).
* Get data for file transfer
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
WITH HEADER LINE.
SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.
SORT ALL_CUSTOMERS BY CITY.
LOOP AT ALL_CUSTOMERS.
WRITE: / ALL_CUSTOMERS-CITY,
ALL_CUSTOMERS-NAME.
ENDLOOP.
* Opening the File
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
MESSAGE MSG_TEXT.
IF SY-SUBRC NE 0.
WRITE: 'File cannot be opened. Reason:', MSG_TEXT.
EXIT.
ENDIF.
* Transferring Data
LOOP AT ALL_CUSTOMERS.
TRANSFER ALL_CUSTOMERS-NAME TO FILENAME.
ENDLOOP.
* Closing the File
CLOSE DATASET FILENAME.
Is there a function or method to get the folder directory for a screen field?
ReplyDeleteThe function "OCS_FILENAME_GET" can return the file name and directory. But a file must be selected or it can not return the directory.
Now only the directory is needed, is there a simple way to do it?
Thanks.
U can use the following code.
ReplyDeleteDATA : l_title TYPE string, " Window Title
l_string TYPE string. "File path string
l_title = 'Search for Download Path'(t04).
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = l_title
initial_folder = 'C:\'
CHANGING
selected_folder = l_string
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
p_path = l_string.
Hi all
ReplyDeletecan u tel me how to create directory in local pc using ABAP?
Deleteplz, see this link---
http://sapabap-tutorial.blogspot.com/2013/06/create-local-directory-on-your-pc-via.html
hi Rahul,
ReplyDeleteplz, see this link---
http://sapabap-utorial.blogspot.com/2013/06/create-local-directory-on-your-pc-via.html
SAP ABAP training is provided in CHENNAI.
ReplyDeleteTHE CREATING EXPERTS is one of the leading trainer in SAP who provides real time training
http://thecreatingexperts.com/sap-abap-training-in-chennai/
contact 8122241286