cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload XML file into the internal table in Webdynpro ABAP ?

Former Member
0 Kudos

Hi Friends,

I am not able to upload the XML file into ABAP,can you please help me in solving this issue with the help of source code.

Regards

Dinesh

Accepted Solutions (0)

Answers (5)

Answers (5)

Lukas_Weigelt
Active Contributor
0 Kudos

Hi there,

I would use a different approach... but that set aside. What exactly do you want to do:

1. Read an XML Document into a string table?

2. Read an XML Document in Binary into an xstring table?

3. Or do you want to convert your xml document into an equivalent abap internal table, i.e. having the table like with the concrete columns and data as per the XML document describes?

First of all, for getting your XML document into the system, you should use the UI-Element 'FileUpload' make an Xstring attribute in Context and bind it to that UI-Element. That way you can easily Upload from presentation into runtime.

Now, that you have the Xstring in Context, you can read it, convert it to string, use an XSLT transformation; depends what you actually need.

cheers, Lukas

uday_gubbala2
Active Contributor
0 Kudos

Hi Dinesh,

You can also have a look at Robert Eijpe's [blog |https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2702] [original link is broken] [original link is broken] [original link is broken];where he makes use of DOM processing to achieve the same result. You then even check Thomas Jung's [approach |https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/1651] [original link is broken] [original link is broken] [original link is broken];here. Check out "Unit 10" .

Regards,

Uday

Former Member
0 Kudos

Hi,

U can try with the FM 'TEXT_CONVERT_XML_TO_SAP' while trying to upload a XML file into SAP.

Thanks,

Kishor.

uday_gubbala2
Active Contributor
0 Kudos
START-OF-SELECTION.
" Move the file path to a string variable to pass to GUI_UPLOAD FM
  I_FILE_PATH = P_PATH.

  perform upload_xml_to_binary.
  perform conv_binary_xstring.
  perform parse_xstring_variable.
  perform display_parsed_data.


" Upload XML file in binary mode to internal table

FORM UPLOAD_XML_TO_BINARY .
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME   = I_FILE_PATH
      fILETYPE   = 'BIN'
    IMPORTING
      FILELENGTH = I_LENGTH
    TABLES
      DATA_TAB   = IT_XML.
ENDFORM.                    " UPLOAD_XML_TO_BINARY


" Move the XML file in binary format to an XSTRING variable

FORM CONV_BINARY_XSTRING .
  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      INPUT_LENGTH = I_LENGTH
    IMPORTING
      BUFFER       = I_XSTRING
    TABLES
      BINARY_TAB   = IT_XML.
ENDFORM.                    " CONV_BINARY_XSTRING


"  Perform XML parsing on the XSTRING variable

FORM PARSE_XSTRING_VARIABLE .
  CALL FUNCTION 'SMUM_XML_PARSE'
    EXPORTING
      XML_INPUT = I_XSTRING
    TABLES
      XML_TABLE = it_SMUM_XMLTB
      RETURN    = it_bapiret2.
ENDFORM.                    " PARSE_XSTRING_VARIABLE


" Display the parsed XML in name & value pairs

FORM DISPLAY_PARSED_DATA .
  loop at it_SMUM_XMLTB.
    write:/10 it_SMUM_XMLTB-cname color 2 inverse on,
           40 it_SMUM_XMLTB-cvalue color 4 inverse on.
    skip 1.
    write:/10 sy-uline(70).
  endloop.
ENDFORM.                    " DISPLAY_PARSED_DATA
SatyaGade
Explorer
0 Kudos

If I use this code the result is dump...I think we should not use GUI_UPLOAD function module in Webdynpro ABAP.you please advise me how to solve this.

uday_gubbala2
Active Contributor
0 Kudos

Hi Dinesh,

Try go through this program which I had developed earlier. It takes as input an XML file and then breaks it down into name-value pairs of an intrnal table. You need to pass an XML file as input to this program. (I had hard coded the path for my XML file in it. You need to replace it with 1 of your own or you can just delete it and use the browse button to selet the file on your PC)

Regards,

Uday

REPORT  ZUDAY_XML no standard page heading.


" Internal table to store the XML file in binary mode
data: begin of it_xml occurs 1, 
        c(255) type x,
      end of it_xml,
" Name-value pairs table rturned by FM SMUM_XML_PARSE
      it_SMUM_XMLTB type SMUM_XMLTB occurs 0 with header line, 
" Table returned by FM SMUM_XML_PARSE for error handling
      it_bapiret2 type bapiret2 occurs 0 with header line.


" XSTRING variable to be used by FM SCMS_BINARY_TO_XSTRING to hold the XML file in XSTRING format
data: I_xstring type xstring,  
" String variable to hold XML file path to pass to GUI_UPLOAD
      I_file_path type string, 
" Variable to store the size of the uploaded binary XML file
      I_LENGTH TYPE I VALUE 0. 



parameters: P_path type IBIPPARMS-PATH default 'C:\Documents and Settings\c5104398\Desktop\flights.xml'.


" Get the XML file path from the user

at selection-screen on value-request for P_path.

  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      FILE_NAME = P_PATH.

SatyaGade
Explorer
0 Kudos

When I tested after using this code I am getting an error like this Access via 'NULL' object reference not possible.

could you please resolve this

■The following error text was processed in the system PRA : Access via 'NULL' object reference not possible.

■The error occurred on the application server pwpra_PRA_01 and in the work process 0 .

■The termination type was: RABAX_STATE

■The ABAP call stack was:

Function: DP_CONTROL_ASSIGN_TABLE of program SAPLCNDP

Method: DIRECTORY_LIST_FILES of program CL_GUI_FRONTEND_SERVICES======CP

Method: FILE_EXIST of program CL_GUI_FRONTEND_SERVICES======CP

Function: GUI_UPLOAD of program SAPLSFES

Function: ZPW_XCARRIER_DHL of program SAPLZSRFG

Method: EXECUTEMD1 of program /1BCWDY/AGX7RYVYLDJHZ7FKZ6SW==CP

Method: IF_COMPONENTCONTROLLER~EXECUTEMD1 of program /1BCWDY/AGX7RYVYLDJHZ7FKZ6SW==CP

Method: ONACTIONPSHIPMENT of program /1BCWDY/AGX7RYVYLDJHZ7FKZ6SW==CP

Method: IF_WDR_VIEW_DELEGATE~WD_INVOKE_EVENT_HANDLER of program /1BCWDY/AGX7RYVYLDJHZ7FKZ6SW==CP

Method: INVOKE_EVENTHANDLER of program CL_WDR_DELEGATING_VIEW========CP

Former Member
0 Kudos

Could you please provide some more detail on how & from where are you reading this XML data.

You have to make use of methods of these classes / interfaces

if_ixml

if_ixml_stream_factory

if_ixml_istream

if_ixml_document

if_ixml_parser

cl_abap_conv_in_ce

if_ixml_node

Thanks,

Abhishek

Former Member
0 Kudos

Hi Abhishek,

I am uploading the XML file from my desktop.My actual requirement is to upload the XML file into the internal table from the desktop using in Webdynpro.

Regards

Dinesh