04-04-2006 1:29 PM
Hi all,
I need to put some data into the file which i am getting the file name dynamically. after getting the file name. so can any one suggest me how can i do that.
i came to know that i can do this with open dataset command is this right way to do?.If its wrong!. can any one tell me how to do that.
Regards,
Lisa.
Message was edited by: Lisa Roy
04-04-2006 1:35 PM
data: TheFileName(120).
data: theStr(500).
move the dynamic file that you have to TheFileName
open dataset TheFileName for input in text mode.
if sy-subrc <> 0.
*message here about an OPEN error
endif.
do.
read dataset TheFileName into theStr.
if sy-subrc <> 0.
EOF reached.
exit.
endif.
Do your business logic here
enddo.
close dataset TheFileName.
Don't forget those reward points.
04-04-2006 1:43 PM
hi,
<b> OPEN DATASET <file name> FOR {OUTPUT/INPUT/APPENDING}
IN {TEXT/BINARY} MODE</b>
OPEN DATASET P_UNAME FOR INPUT IN TEXT MODE.
IF SY-SUBRC = 0.
CLOSE DATASET P_UNAME.
DELETE DATASET P_UNAME.
ENDIF.
OPEN DATASET P_UNAME FOR OUTPUT IN TEXT MODE.
IF SY-SUBRC <> 0.
MESSAGE E039 WITH
'Message'.
ENDIF.
LOOP AT ITAB_OUT.
PERFORM ZYIR008_TRANSFER_DATASET USING 'C'
P_UNAME
ITAB_OUT SY-INDEX.
ENDLOOP.
CLOSE DATASET P_UNAME.
Regards,
Santosh
04-04-2006 1:49 PM
Hi all,
Thank you for your reply and forgot to inform you that i have two fields in selection screen
1)file name and
2)file format.
if it is csv i will save in csv if its is xml i will save in xml.
based on the second field i will save the file.
So is it still possible to use the open dataset command.
Regards,
Lisa.
Message was edited by: Lisa Roy
04-04-2006 1:54 PM
data: TheFileName(120).
data: theStr(500).
concatenate Field1 '.' Field2 into TheFileName.
open dataset TheFileName for OUTPUT in text mode.
if sy-subrc <> 0.
*message here about an OPEN error
endif.
loop at SomeTable.
Do any business logic here
transfer YourData to TheFileName.
endloop.
close dataset TheFileName.
Don't forget those reward points.
04-04-2006 1:39 PM
Hai Lisa,
I think it is possible with Open dataset..
Here is something abt open dataset.
Syntax
OPEN DATASET dset FOR access IN mode [position]
[ os_addition]
[error_handling].
Effect
This statement opens the file specified in dset for the access specified in access in a storage mode specified in mode. For dset, a character-type data object is expected, which contains the platform-specific name of the file.
Use additions position, os_addition and error_handling to determine the position at which to open the file, to specify platform-specific additions and to influence error handling.
In Unicode programs, the access and storage modes access and mode must be specified explicitly. If the additions are missing in non-Unicode programs, the file is opened implicitly as a binary file for read access.
In Unicode programs, the file must not yet be open in the current program; otherwise a treatable exception occurs. In non-Unicode programs, the file may already be open. The statement OPEN DATASET then does not reopen the file but moves the read or write position depending on the access mode. In this case, you should not change the access or storage mode.
Note
You can open up to 100 files per internal session. The actual maximum number of simultaneously open files may be less, depending on the platform.
Return Value
sy-subrc Description
0 File was opened.
8 Operating system could not open file.
Exceptions
Catchable Exceptions
CX_SY_FILE_OPEN
Cause: File is already open (only in Unicode programs)
Runtime Error: DATASET_REOPEN
CX_SY_CODEPAGE_CONVERTER_INIT
Cause: The desired conversion is not supported. (Due to specification of invalid code page or of language not supported in the conversion, with SET LOCALE LANGUAGE.)
Runtime Error: CONVT_CODEPAGE_INIT (catchable)
CX_SY_CONVERSION_CODEPAGE
Cause: Internal error in the conversion.
Runtime Error: CONVT_CODEPAGE (catchable)
CX_SY_FILE_AUTHORITY
Cause: No authorization for access to file
Runtime Error: OPEN_DATASET_NO_AUTHORITY (catchable)
Cause: Authorization for access to this file is missing in OPEN DATASET with addition FILTER.
Runtime Error: OPEN_PIPE_NO_AUTHORITY (catchable)
CX_SY_PIPES_NOT_SUPPORTED
CX_SY_TOO_MANY_FILES
Cause: Maximum number of open files exceeded.
Runtime Error: DATASET_TOO_MANY_FILES (catchable)
Non-Catchable Exceptions
Cause: You tried to open a pipe that is already open.
Runtime Error: DATASET_PIPE_POSITION
regards,
Srikanth.
04-04-2006 1:40 PM
Get the fielname into a variable.
Use the statement,
Open dataset <YOur file name> for output in text mode.
if sy-subrc = 0.
TRANSFER f TO dsn.
endif.
close dataset.
04-04-2006 1:40 PM
Hi
use the following statement for uploading from file.
OPEN DATASET file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
DO.
READ DATASET file INTO line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE: / line.
ENDDO.
04-04-2006 1:40 PM
Hi,
PARAMETERS p_afile TYPE rlgrap-filename.
TYPES : BEGIN OF ty_output,
field(500) TYPE c,
END OF ty_output.
Internal Table Declaration
DATA: t_output TYPE STANDARD TABLE OF ty_output,"Holding Output Details
Work Area Declaration
w_output TYPE ty_output,"Holding Output Details
OPEN DATASET p_afile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
"Error in opening file for output
LEAVE LIST-PROCESSING.
ENDIF.
LOOP AT t_output INTO w_output.
TRANSFER w_output TO p_afile.
ENDLOOP.
Closing the file
CLOSE DATASET p_afile.
IF sy-subrc NE 0.
"Error in closing file
LEAVE LIST-PROCESSING.
ENDIF.
04-06-2006 10:35 AM
Hi Jayaraman,
While i am transfering the data th weay which u have specified iam getting an error message that in unicode programe it's not covertable.
Can you please tell me what i have to do.
Regards,
Lisa
Message was edited by: Lisa Roy
04-06-2006 1:41 PM
Lisa,
The code provided by Jayaraman is very similar to first code example that I provided to you. It does not meet your CSV and XML requirements.
Are you having problems with the later example that I provided to you? That will generate CSV and XML output when coded correctly.
04-04-2006 1:43 PM
Hi Lisa,
Open dataset <datasetname> for input/output/appending in text/binary mode.
if sy-subrc ne 0.
message .....
endif.
*******transferring data from file to app server.
do.
read dataset file into itab.
if sy-subrc = 0.
append itab.
clear itab.
else.
exit.
endif.
enddo.
*******transferring data from itab to file
loop at itab.
transfer itab to file.
endloop.
*******closing dataset
close dataset file.
hope this helps,
priya
04-04-2006 2:08 PM
Hi,
You can use method to create a file and save the data with download..
follow the below method and FM GUI_DOWNLOAD. Hope it is useful to you.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
CHANGING
FILENAME = LDF_FILENAME
PATH = LDF_PATH
FULLPATH = LDF_FULLPATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 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.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = LDF_FULLPATH
FILETYPE = 'DAT'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = ''
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = ''
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR =
REPLACEMENT = ''
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = ''
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = GDT_DL
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
regards
-Rakesh
04-04-2006 2:29 PM
Lisa,
If your question has been answered, please reward points accordingly and close the thread.
If not, please provide more detail.
Thanks in advance.
04-04-2006 2:51 PM
Hi John,
Can you please look into my above message so that you can understand my requirement.
Regards,
Lisa
04-04-2006 3:04 PM
Lisa,
Sorry... I see it now.
Use something like this and my code to LOOP thru I_OUT to create the output file.
REPORT Zsandbox_prog .
type-pools: truxs .
data: begin of i_in occurs 0,
Field1(20),
Field2(20),
Field3(20),
Field4(20),
Field5(20),
end of i_in.
data: i_out type TRUXS_T_TEXT_DATA.
move 'Line 1 - Field 1' to i_in-Field1.
move 'Line 1 - Field 2' to i_in-Field2.
move 'Line 1 - Field 3' to i_in-Field3.
move 'Line 1 - Field 4' to i_in-Field4.
move 'Line 1 - Field 5' to i_in-Field5.
append i_in.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = ','
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
TABLES
I_TAB_SAP_DATA = i_in
CHANGING
I_TAB_CONVERTED_DATA = i_out
EXCEPTIONS
CONVERSION_FAILED = 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.
04-04-2006 3:06 PM
And for your XML output, use similar logic with Func Mode - SAP_CONVERT_TO_XML_FORMAT
04-04-2006 3:17 PM
Nothing more than the idea of John,
SAP_CONVERT_TO_CSV_FORMAT
SAP_CONVERT_TO_TEX_FORMAT
SAP_CONVERT_TO_TXT_FORMAT
SAP_CONVERT_TO_XLS_FORMAT
SAP_CONVERT_TO_XML_FORMAT
Rgd
Frédéric
04-04-2006 3:23 PM