Bad data added in Open Dataset for output in Binary mode
Hello,
I am getting random bad data being added to the end of the file that is created on the file server when I run the Open Dataset for output in Binary mode. This data sometimes looks like information about the Unix file server. If I do the Open Dataset in Text mode, it does not add the extra bad data.
** transfer file to Unix File server
DATA: LIN TYPE P.
OPEN DATASET P_APPFIL FOR OUTPUT IN BINARY MODE.
DESCRIBE TABLE XML_TAB LINES LIN.
IF LIN EQ 0.
EXIT.
ELSE.
LOOP AT XML_TAB.
TRANSFER XML_TAB TO P_APPFIL.
ENDLOOP.
ENDIF.
CLOSE DATASET P_APPFIL.
Running the program 2 times with the same variant will give different results.
For example, the data in file should end with </cPedigreeXML> but it added data as shown below:
</cPedigreeXML>8 I X-UNKNOWN 9 I X-UNKNOWN 10
C X-UNKNOWN
Then, when the program was run again with the same selections, it did not add the erroneous data at the end.
This is a real problem because the bad data that gets added causes the file to error in the application. Any help would be greatly appreciated.
Thanks,
Bob
Hi Bob,
Use CLEAR statement after TRANSFER statement and check once.
IF LIN EQ 0.
EXIT.
ELSE.
LOOP AT XML_TAB.
TRANSFER XML_TAB TO P_APPFIL.
<b>CLEAR XML_TAB.</b>
ENDLOOP.
ENDIF.
Thanks,
Vinay
Similar Messages
-
Problem writing file ANSI to UTF-8. OPEN DATASET FOR OUTPUT IN TEXT MODE
Hello everybody,
My report needs to create a file in ANSI so I am using this sentence: * "OPEN DATASET p_dir_a FOR OUTPUT IN TEXT MODE ENCODING DEFAULT."* almost all charters in the file are well generating excepting for this two: ( Á ) & ( Í ) because SAP assigns the same code to both characters ( Ã? ) = 'xC3' which is not correct, the right code should be ( Á ) = 'xC1' ( Í ) = 'xCD' respectively
from this string = ( ÁÉÍÓÚáéíóúàèìòùÀÈÌÒÙ ) only those two characters are wrong converted.
Also I tray to catch a conversion error with this sentence:
TRY.
TRANSFER <field> TO p_dir_a NO END OF LINE.
CATCH cx_sy_conversion_codepage.
MESSAGE 'error' type 'I'.
ENDTRY.
but never enters in it.
Does anyone know where I can configure SAP to SET this value correctly?
Thanks for your help.was a server problem, not SAP
-
Open Dataset for input in BINARY MODE not working after ECC 6.0 upgrade
Hi All,
Our requirement is to download an XML file from the application server and there is a customized program to download these files.
This program uses the statement, Open dataset ...for input in BINARY MODE
and it works perfect for 4.7. There were no issues. But, after the upgrade to ECC 6.0 this does not work.
When the data is read in ECC 6.0 , it is shown in some special characters and it could not be opened with XML editor and the file is not completely downloaded. I read through the forum and tried the following statement as well,
Open dataset....for input in LEGACY BINARY MODE.
After this statement, there were no special characters, but there is a blank space introduced before every character.
Example : TEST(actual)
T E S T (After the legacy binary mode)
Could you please let me know if there is any solution to rectify this problem. Appreciate your help.
Thanks a million.
Edited by: Manikd on May 12, 2011 3:52 PMBut this program was already using BINARY MODE and after upgrade this is not working. I know, it may work in TEXT MODE. However, I cannot change the whole program to TEXT mode now.
-
Hi,
When I create a file from R3 using open dataset for output, the file is created at the OS Level with rights coming from R3. Is there a way to control the properties of those rights.
Regards,Hi,
you can use authorization object S_DATASET & S_PATH to control user & program access to the file system . Then in your program use FM AUTHORITY_CHECK_DATASET to check the authority before opening to avoid a dump.
Cheers
Allan -
OPEN DATASET FOR INPUT IN TEXT MODE - linesize issue
Hi,
I faced a problem when opened ANSI file with CYRILLIC in ECC 6.0 Unicode system - the system cuts the line to 250 characters. Below is snip of code:
REPORT Z_TEST_01 LINE-SIZE 1023.
DATA:
file TYPE char40 VALUE 'ansi_file.txt',
line TYPE char1024, len TYPE i.
OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
WHILE sy-subrc = 0.
READ DATASET file INTO line ACTUAL LENGTH len.
WRITE: / len, line.
ENDWHILE.
CLOSE DATASET file.
In this case, variable LEN always get value 250. File-content is correctly converted from ANSI and all CYRILLIC is displayed to the screen. I changed type for LINE - initialy the type was STRING, actially.
Further, tried to open it in BINARY - like this:
DATA:
file TYPE char40 VALUE 'ansi_file.txt',
line TYPE char1024, len TYPE i.
FIELD-SYMBOLS <hex_container> TYPE x.
OPEN DATASET file FOR INPUT IN BINARY MODE.
ASSIGN line TO <hex_container> CASTING.
DO.
READ DATASET file INTO <hex_container>.
IF sy-subrc = 0.
WRITE: / line.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET file.
WRITE: / line.
In this case I got bigger linesize (obviously 1024), but faced conversion issues - the file contains some CYRILLIC and it is messed. Played for few hours with conversions - using additions: IN LEGACY BINARY MODE... BIG/LITTLE ENDIAN, CODE PAGE... without success. So decided to ask...
Well, I searched SDN for a similar issue, but didn't found, except this one:
Re: OPEN DATASET STRING Problem
Could someone points me what am I doing wrong? How can I read my ANSI file with line-size more than 250 chars? Actually, in my case line size may vary up to 1800 chars. Further, afrer conversion and some validation, I should save it back to the AS.
Many thans in advance.
Regards,
Ivaylo MutafchievSorry for the noise - it is not an issue anymore.
-
OPEN DATASET FOR OUTPUT IN LEGACY TEXT MODE not working!
Hi All,
I need your expertise to help me with my problem.
The program passed through the code OPEN DATASET ... FOR OUTPUT IN LEGACY TEXT MODE. Then it gave an error message "Error Accessing File /home/sap/sample.txt".
I would like to know what are the causes of this error. Please explain to me further why the program gives an error message specified above because I'm not familiar in OPEN DATASET.
Please reply asap since the issue need to be resolved immediately.
Thanks in advance,
CarinaHi Carmey,
The Problem will u need toi get Open Dataset Authorisation from ur Basis Team from the Specified Path.
Regards,
Morris Bond.
Reward Points if Helpful. -
CG3Z working not open dataset for output
Hi,
I am trying to upload data into the application server for which m using the OPEN DATASET statement. My file name is as follows in lowercase.
p_file = '/usr/upi/out/test_20100220.dat'. TYPE c.
While trying to execute this i am getting a short dump 'DATASET_NOT OPEN'.
I tried to upload a file through tcode CG3Z with the same file path and its working fine whereas through the below code its not working at all.
open DATASET w_filename_unix for INPUT in TEXT MODE ENCODING DEFAULT.
LOOP AT i_fieldnames INTO wa_fieldnames.
TRANSFER wa_fieldnames TO w_filename_unix.
ENDLOOP.
LOOP AT i_output INTO wa_output.
TRANSFER wa_output TO w_filename_unix.
ENDLOOP.
if sy-subrc NE 0.
WRITE: 'Error'.
ENDIF.
CLOSE DATASET w_filename_unix.
Please help.
Regards herwin..hii,
Why is it W_filename...??? it should be p_file ...... after opendataset... -
Open dataset for input don't work after upgrade from 46C to 47
We did an upgrade from 46C to 47, after that all the Z programs that have the sentence "open dataset for input" alwas send a sy-subrc = 8, the curios things is that the sentece "open dataset for output" works ok.
Please I need help to solve this?
En example of code.
PARAMETERS: P_ARCHF(60) OBLIGATORY DEFAULT
'C:\20050900.txt' LOWER CASE.
OPEN DATASET P_ARCHF FOR INPUT IN TEXT MODE.
IF SY-SUBRC <> 0. MESSAGE i001 WITH ARCHIVO. stop. endif.Well, it's telling you that the datset doesn't exist. From the help in 4.7:
OPEN DATASET
Addition 1a
... FOR INPUT
Effect
OPEN ... FOR INPUT opens the file in read mode.
If the file does not exist, OPEN ... FOR INPUT fails with Return Code SY-SUBRC = 8.
Note
If OPEN DATASET is not executed in a Unicode program and if the user has write authorization for the file, the file is opened in read and write mode. Otherwise, it is only opened in read mode.
Rob -
OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE
Hi There,
I also have the similar issue. I am able to write the data into appliaction server in Chinese Characters using :OPEN DATASET datei FOR OUTPUT IN TEXT MODE ENCODING DEFAULT or OPEN DATASET datei FOR OUTPUT IN TEXT MODE ENCODING UTF-8. But when i save that file into my presentation server manually, all the chinese characters are showing as Junk.
When i use OPEN DATASET datei FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE, giving runtime error and when i use OPEN DATASET datei FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE IGNORING CONVERSION ERRORS, No error but application server output itself showing as Junk characters.
Could you please suggest me what you have done?
Regards,
Chaitanya AHi,
Use this
OPEN DATASET File_path FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE
WITH SMART LINEFEED
it will definitely work.
Regards,
Manesh. R -
Open dataset for file output does not work
I have the following code
OPEN DATASET MY_FILE FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
MY_FILE is a selection parameter for the filename but when I put any file name, say C:\tmp\test.txt, the code does not create the file for writing. If I create the file manually from windows so that I am sure it exists (Right click-> New -> Text File -> test.txt), SAP still does not open the file for writing.
Am I doing something wrong?
I have searched the net and the forums but I can't seem to get a useful answer...
Thanks in advance!
KyleHey Prabhu,
Thanks. I kinda missed this from the documentation:
The file must be accessible from the application server. You cannot use OPEN DATASET to process files on the current presentation server (whether PC or workstation). The function modules WS_DOWNLOAD and WS_UPLOAD exist for this purpose.
[http://help.sap.com/saphelp_40b/helpdata/en/34/55cad198482bc0e10000009b38f91f/content.htm]
Points have been awarded. Thank you.
Kyle -
Open Dataset for XML not reading the XML file, Returning Code 8.
Dear all,
Im trying to open an XML file using Open Dataset, since i have to execute this report in background and GUI_upload doesnt work in background.
The XML file is available in my C:\, say, C:\xmlfile.xml.
But the open dataset is not reading any value into the g_xml_line . it is returning sy-subrc = 8.
Below is my code for that, can anybody help me out to resolve.
DATA : lv_filename LIKE rlgrap-filename.
CLEAR: lv_filename.
lv_filename = p_input.
OPEN DATASET lv_filename FOR INPUT IN BINARY MODE.
IF sy-subrc ne 0.
WRITE:/ 'invalid file'.
else.
DO.
READ DATASET lv_filename INTO g_xml_line.
IF sy-subrc EQ 0.
APPEND g_xml_line TO g_xml_table.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_filename.
ENDIF.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
DATA: g_xml_table TYPE TABLE OF t_xml_line,
g_xml_line TYPE t_xml_line,
g_xml_table_size TYPE i.
GET REFERENCE OF gt_person INTO gs_result_xml-value.
gs_result_xml-name = 'IPIX'.
APPEND gs_result_xml TO gt_result_xml.
Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION zaum_manh_sync_rpt
SOURCE XML g_xml_table
RESULT (gt_result_xml).
CATCH cx_root INTO gs_rif_ex.
gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.
ENDTRY.
Kindly suggest me a solution. Points assured
regs,
rajaAfter saving the file , below is the code i wrote, but it gives a runtime error with message
No roll storage space of length 3788808 available for internal storage.
***Coding****
PARAMETERS: p_file TYPE pathintern LOWER CASE DEFAULT '/usr/sap/DEV/SYS/global/XMLABAP2.XML'.
DATA : lv_filename LIKE rlgrap-filename.
CLEAR: lv_filename.
lv_filename = p_file.
DATA: l_fname TYPE filename-fileintern. " File name
*GET THE FILENAME FROM THE APPLICATION SERVER
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = p_file
filemask = '*'
IMPORTING
serverfile = l_fname
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*/usr/sap/DEV/SYS/global/substanc
lv_filename = l_fname.
OPEN DATASET lv_filename FOR INPUT IN BINARY MODE.
IF sy-subrc NE 0.
WRITE:/ 'invalid file'.
ELSE.
DO.
READ DATASET lv_filename INTO g_xml_line.
IF sy-subrc EQ 0.
APPEND g_xml_line TO g_xml_table.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_filename.
ENDIF. -
Data transfer error open dataset files
hi,
When i try to create a excel or text in my application server using open dataset.
i.e
l_filename type rlgrap-filename value '/tmp/down.txt'.
I got a short dump during the run time
i got the output and put into an internal table.
the following code has been used.
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
if r_ucomm = 'confirm' .
OPEN DATASET l_fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT it_out INTO wa_out.
IF sy-subrc = 0.
TRANSFER wa_out TO l_filename.
ENDIF.
ENDLOOP.
endform.
during the execution i hv a button alv grid outpu. when i click the button the file should be transferred.
but NO authorization to open the file "/tmp/down.txt".
and the error is pointed in the opendataset line.
Please tell me where i am wrong . and help me in resoving this.Try this..instead of moving field by field into the file 1st convert all he fields to a character stream..and then move that steam to file. Ex:
loop at internal table into l_h_tbl_file.
concatenate l_h_tbl_file-f1 l_h_tbl_file-f2 l_h_tbl_file-f3
l_h_tbl_file-f4 l_h_tbl_file-f5 into g_string.
TRANSFER g_string TO fu_wk_get_file.
endloop. -
Open dataset filename for output in text mode encoding default
Hi,
When I excute this command I get a sy-subrc = 0, but no file is created. This happens in an ECC 6.0 system. In 4.6C works ok.
filename has the following structure '
server\directory\filename'
What am I doing wrong??
Thank you very much for your your help.
Regards.Hi,
Can u tell what syntax u have written for open statement.
In programs with active Unicode check, you must specify the access type (such as ... FOR INPUT, ... FOR OUTPUT, and so on) and the mode (such as ... IN TEXT MODE, ... IN BINARY MODE, and so on). If the file is opened using ... IN TEXT MODE, you must still use the addition ... ENCODING. If the Unicode check is enabled, it is possible to use file names containing blanks.
Regards,
Sruthi -
Hello,
I need to read data from SAP 710 and save it in the server as a XML utf-8 file. Then this file is going to be read in a non SAP system.
I am reading data in a simple transformation to a STRING, but it come as UTF-16.
Then I call method CL_RSWAD_CONVERT=>STRING_TO_TABLE where I Import a binary table TYPE STANDARD TABLE OF char255.
So when I do 'OPEN DATASET lv_temp_unix_filen in BINARY MODE for OUTPUT.' the file is in UTF-16 format.
I tried to replace UTF-16 for UTF-8 (using: REPLACE FIRST OCCURRENCE OF 'utf-16' in lv_xml_string with 'utf-8'.)
but then the NON SAP system doesn't recognize the file.
I also tried to read the simple transformation data into a XSTRING.
Then I used CL_RSWAD_CONVERT=>XSTRING_TO_TABLE where I get the content in a binary table TYPE SOLIX_TAB.
If I use method cl_gui_frontend_services=>gui_download this works fine, but for the server, the file shows an error:
"The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Invalid at the top level of the document. Error processing resource 'file:///C:/test.xml'. "
Can anyone help me?
Thanks and Kind regards!Sorry for taking so long to answer.
I am using Abap 710.
What do you mean with valid XML?
I can have a valid one in my pc (frontend) using method "CALL METHOD cl_gui_frontend_services=>gui_download",
but if I try to download it to the server using "OPEN DATASET lv_temp_unix_filen in BINARY MODE for OUTPUT." it gives me the error I described on my first post.
Is it possible to add in the simple transformation the enconding? Then I could load that transformed data to a STRING as UTF-8. Because right now from the simple transformation I get it as UTF-16. That's why I am reading it to a XSTRING to be UTF-8 (I read it in another topic from this forum).
Does anyone have a solution?
Thanks for helping me.
Kind regards. -
Open dataset deleting file in application server
Hi All,
Im reading a text file from application server .However the below statement is failing(sy-subrc = 8)
and deleting my file
OPEN DATASET gv_file FOR INPUT IN TEXT MODE ENCODING UTF-8.
Please let me know what is causing the issue.
REgards,
FaizThat seems very unlikely, you should try to get more information:
* Try the messages statement:
DATA mess TYPE string.
OPEN DATASET `` FOR INPUT IN BINARY MODE MESSAGE mess.
IF sy-subrc = 8.
MESSAGE mess TYPE 'I'.
ENDIF.
Maybe you are looking for
-
Flash player won't play on home pages
My flash player won't play on my browser's home pages. My OS is : windows 7 64 bit ultimate and my browsers are : Mozilla,Chrome, and IE. I have owned this machine since laborday 2012 and all of them worked in the begining. This has been going on
-
If I turn off my iCloud in my iPad for my phone, will that delete the iCloud I have on my phone? (Or vise versa) I want to have iCloud in both my iPad and my phone, but I don't want my information synching with one another.
-
This is an Adobe Illustrator File that was saved without PDF Content.
Hi everybody, I'm working in illustrator CS6 and I am trying to save my file as PDF. However I can't seem to do it. I save the file as an ai. file and click the "Create PDF Compatible File" option. Then when I click >save as >and opt for the PDF vers
-
Has anybody experience a lag when swiping through apps?
Has anybody experience when swiping through your apps, the screen theme to freeze or a few seconds and then it responds?
-
My 500gb mac mini disk space is being used by something called "backup" (451gb). I have nothing left to work with. I can't find where this file(s) is so I can delete it.