Skip to Content

Error while reading a xml file from the file server - Ironically gui_upload works fine

Hello everyone,

I have a problem with the import of a xml file and I hope that you can help me.

My program has two options to import the xml file. The first option is via the prasentation server and works absolutely fine.

But when I want to read the file from the file server I always get an error.

For using a file from the prasentation server I use the standard "gui_upload" method. To read the file from the file server I use open, read and close dataset.

Open dataset works fine, but during the read dataset it will crash with the return code 4. The crash is at sy-tabix 180, so the the problem is not starting with the first line. Unfortunately the raw xml file can not be analyzed because all the content is in one line. But there can`t be an error in the file itself, because the other method works fine and the result ist correct.

Do you have any hints why there can be an error?

I already tried to change the input mode in the open dataset statement but with no other result.

Thanks in advance!

My code:

OPEN DATASET g_filename FOR INPUT IN BINARY MODE.

IF sy-subrc <> 0.

MESSAGE text-009 TYPE 'E' DISPLAY LIKE 'I'.

ENDIF.

DO.

READ DATASET g_filename INTO l_xml_line.

IF sy-subrc EQ 0.

APPEND l_xml_line TO l_xml_table.

ELSE.

MESSAGE 'Error while reading the file'(017) TYPE 'E' DISPLAY LIKE 'I'.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET g_filename. IF sy-subrc <> 0. MESSAGE 'Error while closing the file'(018) TYPE 'E' DISPLAY LIKE 'I'. ENDIF.

Kind regards

Kai Schluesener

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Jul 20, 2016 at 12:42 PM

    It's not an error, it's just the end of file. Just use sy-subrc <> 0 to leave the loop, not to send an error message!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 20, 2016 at 10:10 AM

    Hi

    But which kind of crash have you?

    And how have you defined l_xml_line?

    Max

    Add a comment
    10|10000 characters needed characters exceeded

    • l_xml_line is defined like this:

      TYPES: BEGIN OF t_xml_line,

      data(256) TYPE x,

      END OF _xml_line.

      The definition is from the SAP document "iXML ABAP Objects Jumpstart"

      iXML ABAP Objects Jumpstart - XML- Library - SAP Library



      Well, maybe crash is not the right expression.

      I`ll get the return code 4 which means "Data was read and the end of the file was reached or there was an attempt to read after the end of the file."

      Later in my program, when I am parsing the imported xml stream, the data can not be processed.

      While parsing the first line the method directly returns the error "unexpected end-of-file".

      With the file from the gui_upload everything is fine.

  • Posted on Jul 20, 2016 at 11:04 AM

    Try to

    • Use a DESCRIBE FIELD l_xml_line LENGTH len IN BYTE MODE
    • Add MAXIMUM LENGTH len option to your READ DATASET statement.


    Regards,

    Raymond

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 20, 2016 at 12:13 PM

    Hi

    It seems the structure you're using to upload the data is too short, try to use type XSTRING instead of X:

    TYPES: BEGIN OF t_xml_line,

    data(256) TYPE x,

    data type xtring,

    END OF _xml_line.

    Max

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.