cancel
Showing results for 
Search instead for 
Did you mean: 

File Location of Uploaded File

Former Member
0 Kudos

Hello Everyone,

I am planning to use BSP application to upload a XML file.I tried that with htmlb:fileUpload component which works fine. But where the file gets uploaded?

What I am planning to do is uploading a XML file to the server and then onInputProcessing parse and transform a XML.

For the test I created JavaScript function and tried to access the uploaded XML file from that but I guess it was not retrieving the same.

e.g.I used this function

xmlDoc.load('./../emp.xml');

Thanks in advance.

Thanks And Regards

Rajeev Patkie

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

When you use the fileUpload, you must handle the event and capture the uploaded data from within the event. You can then put it where you want. You will want some code like the following in your event handler:


DATA: event            TYPE REF TO if_htmlb_data,
  fileUpload_event TYPE REF TO CL_HTMLB_FILEUPLOAD.
  event = cl_htmlb_manager=>get_event_ex( request ).
  IF event IS NOT INITIAL AND event->event_name = 'fileUpload'.
  fileUpload_event ?= event.

You then have a binary string attribute in fileUpload_event called FILE_CONTENT.

You shouldn't need any JavaScript to work on the XML file. ABAP has XML process and Transformations built in. Look at the key word <b>Call Transformation</b> in the online help. You can work directly with the binary string that was returned from the fileUpload event.

Former Member
0 Kudos

Hello Thomas,

Thanks for your reply. Actually I had used JavaScript to just test whether file is uploaded successfully or not (also want to confirm whether this function creates a file in some directory of server or passes the contents of the file to server).

According to you do I need to create a custom transformation which will take input as byte stream and return required XML output?

I checked the SAP help which gives information about that transformation 'id'.Also I tried to included that code as

data ?= CL_HTMLB_MANAGER=>GET_DATA(

request = runtime->server->request

name = 'fileUpload'

id = 'myfileupload1'

).

IF data IS NOT INITIAL.

f_content = data->file_content.

call transformation id

source SOURCE = f_content

result xml XML_STRING.

endif.

and then on view <htmlb:textView><%=XML_STRING%> but still it prints binary string itself.

Regards

Rajeev Patkie

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The problem is your call transformation. The way you have it written, it thinks your source is ABAP data and your destination is XML. You actually want to transform XML->XML. You would want the following code:


    CALL TRANSFORMATION id
    SOURCE XML f_content
    RESULT XML xml_string.

In this example both your source and destination are XML. f_content is binary string and xml_string is just string. The id transformation works ok - I can see it in the debugger, but it isn't great for output in the textView. Might I suggest you try the XMLHTML transformation. It displayed quite nicely.

Former Member
0 Kudos

Hello Thomas,

Thanks for the reply. Now its parsing the XML string.

Actually I have to transform the input XML file to our format.I had gone through the ABAP documentation to create XSLT programs.One thing to ask is if we create our custom XSLT program in some package then can it be called by CALL TRANSFORMATION myXSLTProgram or do we have to refer it with package name?

Also one question is unanswered whether the htmlb:fileUpload component creates physical file on the server?

Regards

Rajeev

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

No you shouldn't have to refer to the XSLT by package. They are all global, just like an ABAP program. Just follow the same naming conventions.

I don't believe that fileUpload creates a physical file on the server. There may be some caching or temporary files written by the ICM, but it shouldn't be anything to worry about. Someone with more intimate knowledge of the inner workings of the ICM (some from SAP perhaps) would probably have to answer that question.

Former Member
0 Kudos

Hello Thomas,

Thanks once more for the same.I am planning to use CALL TRANSFORMATION for transforming my incoming XML. I can transform XML node values and nodes but how we can access XML attributes.

e.g.while accessing XML node value of Customer tag

<KUNNR>0000058974</KUNNR> in XSLT we can have

<xsl:value-of select="KUNNR"/>.But if we have material tag like <MATNR unit="kgs">00001221212</MATNR> how we can access unit value from XSLT.In my program I want to transform this value into another tag.

I went through tutorials of ABAP and XML and also of general XSLT programming. But nowhere I found values fetching of attributes.

Thanks in advance.

Thanks And Regards

Rajeev Patkie

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You are getting a little bit out of the area where I can help you. I don't have a ton of experience creating my own XSLT programs so let's see if we can struggle through this together. I believe that attributes can be accessed with the prefix @. Therefore you would refer to the unit in this example by MATNR/@unit. You should be able to do a <xsl:value-of select="MATNR/@unit"/>.

I did find some documentation that says you should be able to access all attributes with the following code:

<xsl:for-each select="@*">

You might have a look at the following links:

http://www.cafeconleche.org/books/bible2/chapters/ch17.html

http://www.w3.org/TR/xslt

Former Member
0 Kudos

Hello Thomas,

Thats perfect.

Actually came to know from SAP Std XSLT Program example of SXSLTDEMO_CONNECTIONS_FLIGHT..

anyway thanks for the same...

regards

rajeev

Answers (0)