Application Development 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: 

Open data set save an XML into file system incomplete

0 Kudos

Hello Guys,

I am traying to create and XML and save into file system, I get XML string by a web services and I pass this string to file system, the problem its that the xml are incomplete,I donwload file from AL11 and the file are incomplete

Original file looks like this

This is my code:

   DATA: ruta TYPE string,
         long TYPE integer.


      ruta = '/tmp/darwin.xml'.

       OPEN DATASET  ruta  FOR OUTPUT IN BINARY MODE .
     long = strlen( i_input-mt_ventas_emision_res-factura-ruta_xml ).

  TRANSFER i_input-mt_ventas_emision_res-factura-ruta_xml TO ruta LENGTH long.
    CLOSE DATASET ruta.
    BREAK-POINT.

Can anyone help me?

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

If you have RUTA_XML made of 5303 characters as you can see in debugger, which results into a UTF-8 file with 5123 bytes, I guess that the only possible reason is because of the "newline" character representation (character(s) for end of line). In the variable, you probably have sequences of 2 characters CRLF (UTF-8 bytes 0D0A, UTF-16LE 0D000A00), specific to Windows "newline", which are converted for Operating systems Unix/Linux 1 character LF (LineFeed). i.e. you have 180 or 181 lines in your file.

For information, in OPEN DATASET, you have the word WITH WINDOWS LINEFEED to force the newline representation CRLF. (but don't do it, it's just to help you analyzing the case)

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos

What is the objective symptom of the "incomplete" error? How do you open the file? Why do you say "incomplete"?

So your XML is stored in a string of characters. Why then do you open your file in BINARY mode?

Sandra_Rossi
Active Contributor
0 Kudos

Please use the COMMENT button for comments, questions, adding details, replying to OP comment, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

Sandra_Rossi
Active Contributor
0 Kudos

You said "original length file its 6909 but when I used Open Dataset to create the file on file system I only have 2568 of length".

So I guess you mean you see in the debugger that your STRING variable has length 6909 but you see in AL11 that the length is 2568.

Really surprising.

First of all, if your variable is text (string of characters), open your file IN TEXT MODE ENCODING DEFAULT, not binary. Try again.

0 Kudos

Hey Sandra Rossi many thanks for your comment, I do that you said me and now my file save more data but not all, now lengh saved its: 5123, but the original file has 5303. This xml its save well to billing document with fm SO_OBJECT_INSERT and I can see the xml complete in vf03 attached to bill document, I am triying to save this XML on file system, I do that you comment but sitll not save all data. My file code its follow:

    DATA: ruta TYPE string.

    ruta = '/tmp/darwin.xml'.

   OPEN DATASET  ruta FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

  TRANSFER i_input-mt_ventas_emision_res-factura-ruta_xml TO ruta.
  CLOSE DATASET ruta.

Any other idea?

Sandra_Rossi
Active Contributor
0 Kudos

If you have RUTA_XML made of 5303 characters as you can see in debugger, which results into a UTF-8 file with 5123 bytes, I guess that the only possible reason is because of the "newline" character representation (character(s) for end of line). In the variable, you probably have sequences of 2 characters CRLF (UTF-8 bytes 0D0A, UTF-16LE 0D000A00), specific to Windows "newline", which are converted for Operating systems Unix/Linux 1 character LF (LineFeed). i.e. you have 180 or 181 lines in your file.

For information, in OPEN DATASET, you have the word WITH WINDOWS LINEFEED to force the newline representation CRLF. (but don't do it, it's just to help you analyzing the case)

Sandra_Rossi
Active Contributor
0 Kudos

Thanks for clarifying. See my separate answer.