Application Development and Automation 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: 
Read only

issue with uploading XML file from application server into internal table

durgaprasanth_vemula
Participant
0 Likes
6,840

i Need to fetch the XML file from the application server and place into internal table and i am getting error message while using the functional module   SMUM_XML_PARSE and the error message is "line   1 col   1-unexpected symbol; expected '<', '</', entity reference, character data, CDATA section, processing instruction or comment" and could you please let me know how to resolve this issue?  

    TYPES: BEGIN OF T_XML,
             raw(2000) TYPE C,
           END OF T_XML.
DATA:GW_XML_TAB TYPE  T_XML.
DATAGI_XML_TAB TYPE TABLE OF T_XML INITIAL SIZE 0.
DATA:GI_STR TYPE STRING.
dataGV_XML_STRING TYPE XSTRING.
DATA: GI_XML_DATA TYPE  TABLE OF SMUM_XMLTB INITIAL SIZE 0.
data:GI_RETURN TYPE STANDARD TABLE OF BAPIRET2.

    OPEN DATASET LV_FILE1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.


    IF SY-SUBRC NE 0.

      MESSAGE 'File does not exist' TYPE 'E'.
    ELSE.

      DO.
* Transfer the contents from the file to the work area of the internal table
        READ DATASET LV_FILE1 INTO GW_XML_TAB.
        IF SY-SUBRC EQ 0.
          CONDENSE GW_XML_TAB.
*       Append the contents of the work area to the internal table
          APPEND GW_XML_TAB TO GI_XML_TAB.

        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
    ENDIF.

* Close the file after reading the data
    CLOSE DATASET LV_FILE1.



   


    IF NOT GI_XML_TAB IS INITIAL.
      CONCATENATE LINES OF GI_XML_TAB INTO GI_STR SEPARATED BY SPACE.
    ENDIF.

* The function module is used to convert string to xstring
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        TEXT   = GI_STR
      IMPORTING
        BUFFER = GV_XML_STRING
      EXCEPTIONS
        FAILED = 1
        OTHERS = 2.

    IF SY-SUBRC <> 0.

      MESSAGE 'Error in the XML file' TYPE 'E'.
    ENDIF.


  ENDIF.



*
  IF GV_SUBRC = 0.
* Convert XML to internal table
    CALL FUNCTION 'SMUM_XML_PARSE'
      EXPORTING
        XML_INPUT = GV_XML_STRING
      TABLES
        XML_TABLE = GI_XML_DATA
        RETURN    = GI_RETURN.
  ENDIF.

  READ TABLE GI_RETURN TRANSPORTING NO FIELDS WITH KEY TYPE = 'E'.
  IF SY-SUBRC EQ 0.
    MESSAGE 'Error converting the input XML file' TYPE 'E'.
  ELSE.
    DELETE GI_XML_DATA WHERE TYPE <> 'V'.
    REFRESH GI_RETURN.
  ENDIF.

17 REPLIES 17
Read only

rosenberg_eitan
Active Contributor
0 Likes
5,013

Hi,

This one is working just fine.

Regards.

I am on windows network using unc file name \\folder\file.xml

PARAMETERS: p_file_i TYPE pathextern MODIF ID gr2 .

FORM get_data_1 .

  IF p_file_i IS INITIAL .
    MESSAGE e668(vl).
  ENDIF .

  DATA: mess TYPE string .

  OPEN DATASET p_file_i FOR INPUT IN LEGACY BINARY MODE MESSAGE mess.

  DATA: response_string_1 TYPE string .
  DATA: response_string_2 TYPE xstring .

  READ DATASET p_file_i INTO response_string_1 .

  CALL METHOD cl_bcs_convert=>string_to_xstring
    EXPORTING
      iv_string  = response_string_1
    RECEIVING
      ev_xstring = response_string_2.

  DATA: it_xml_table TYPE TABLE OF smum_xmltb .

  DATA: it_bapiret  TYPE bapirettab .

  CALL FUNCTION 'SMUM_XML_PARSE'
    EXPORTING
      xml_input = response_string_2
    TABLES
      xml_table = it_xml_table
      return    = it_bapiret.

  BREAK-POINT .

* Check  it_xml_table ,  it_bapiret

ENDFORM .                                                   "get_data_1
*----------------------------------------------------------------------*

Read only

0 Likes
5,013

still i am getting the same error i.e
"line   1 col   1-unexpected symbol; expected '<', '</', entity reference, character data, CDATA section, processing instruction or comment"

Actually the requirment is that the XML file is in application server and it is uploaded from the presenation server to application server using the tcode /nCG3Z

And from the application server i need to upload into the internal table

Read only

0 Likes
5,013

Hi,

Can you up load your XML file so I can test it here ?

Regards.

Read only

0 Likes
5,013

how i can upload file  in SCN and could you please tell me or can u give me  your email id and i will send the file to you or please send me your emailid  to <Removed by Moderator> and i will send the file to you.

Message was edited by: Marcelo Ramos:

If you want people to contact you, you can choose to make your email visible in your profile, but we ask you not to post it elsewhere on the site.

Please check the The SCN Rules of Engagement for more information.

Read only

0 Likes
5,013

Hi,

- You can update your original message and add a file.

Read only

0 Likes
5,013

i had added it.please find it

Read only

0 Likes
5,013

Hi,

Or post it as a message.

it is a text file after all...

Regards.

Read only

durgaprasanth_vemula
Participant
0 Likes
5,013


I had added the file.Please find it

Read only

0 Likes
5,013

Testing.....

Read only

rosenberg_eitan
Active Contributor
0 Likes
5,013

Debug:

Hi,

It seems that the xml is not well formed .

I remove some parts and then it works just fine.

It is showing in the browser as well.

Regards.

Read only

0 Likes
5,013

thanks for the help and i am able to upload it and  could you please let me know what you had removed the some part in the XML file

Read only

0 Likes
5,013

You can learn how to do file comparison using any tool (Notepad++ for example).

One comparing 2 files, it can be seen that first 8 lines were removed, till <Soap:Body>.. And <?xml ..?> line was added in beginning.

Read only

0 Likes
5,013

Hi,

Thanks !!!

You are my time saver !!!!! (And more then once...)

Regards.

Read only

0 Likes
5,013

One more thing. If you don't want to install software just to compare text, you can do it via online text comparison website. One such website is DiffNow

Read only

0 Likes
5,013

Could you please tel me  why the first 8 lines were removed, till <Soap:Body and also added the line <?xml version="1.0" encoding="UTF-8"?> in the beggining .

Becuase there will be lot of  XML files will be coming from the Vendor daily and that should be uploaded in the application server and should update in the SAP tables based on the data in the XML file.

what information i need to give to vendor that do not add the first 8 lines in the XML file and add the line in the beggining <?xml version="1.0" encoding="UTF-8"?>   ??????

Is there any other way we can do with out removing the lines?

Read only

0 Likes
5,013

Hi,

Ask the vendor to create a well formed file.

I do not know how he generate those but if he is doing it by "hand" this problen can occours.

If the vendor is using SAP he can use cl_ixml to generate the file for you.

Example: http://scn.sap.com/servlet/JiveServlet/download/38-233479/Y_R_EITAN_TEST_40_02.txt.zip

See http://scn.sap.com/community/abap/blog/2013/12/15/creating-excel-the-java-way

Regards.

Read only

0 Likes
5,013

You should try to understand the XML structure.

It starts with header, and then every opening tag has matching ending tag at same hierarchy level.

Deleting lines to make it work was one option. Another option is to add missing ending tags.

After adding the ending tags, it is opening in internet explorer even without the <?xml header.

See this attachment.