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: 

XML to internal table

Former Member
0 Kudos
300

Hi guys,

I've searched around on SDN and found out that this blog actually has some example

But what if my XML is in the application server? How do I modify the code?

My requirement is to read the XML file from Apps server and save it in an internal table so that I can compare header and stuff.

Please advice.

Thanks

9 REPLIES 9

former_member589029
Active Contributor
0 Kudos
214

Just use read dataset instead of gui_upload. lv_name should contain the file name including the complete file path:


  OPEN DATASET lv_name FOR INPUT IN BINARY MODE.

    DO.
*     append the file line by line
      READ DATASET lv_name INTO ls_string.
      IF sy-subrc EQ 0.
*       determine the length
        y_filelength = y_filelength + STRLEN( ls_string ).
        APPEND ls_string TO yt_file_data.
      ELSE.
        EXIT .
      ENDIF.
    ENDDO.
*   now we need to close the file
    CLOSE DATASET lv_name.

Hope that helps,

Michael

0 Kudos
214

Hi there, thanks for the reply but that is not really the thing I'm looking for. i mean its not complete.

The problem i have now is that when i do READ DATASET lv_name INTO ls_string... I think its too long to be stored in ls_string.

I declared

ls_string type string.

how do you declare

y_filelength = y_filelength + STRLEN( ls_string ).
        APPEND ls_string TO yt_file_data.

Y_filelength and yt_file_data?.

Anyone can shed some light here?

The XML files are in the application server already. What are the steps required to read and store them into internal tables .

Many thanks

0 Kudos
214

y_filelength is of type i, but the only reason I have it here is for post processing where I need to know the total length of the imported file. So if you are not interested in the total length of the file you do not need that part.

A binary file is an unstructured sequence of bytes, therefore if you do not want to import the file in one single step (by using a ls_string TYPE XSTRING), you usually import it in smaller chunks. A lot of standard function modules accepting a binary file usually have the following structure:


TYPES: BEGIN OF ty_binary,
         line(256) type x,
       END OF ty_binary.

DATA: YT_FILE_DATA TYPE TABLE OF ty_binary.

The length of the field LINE of the structure determines how many bytes are read from the file in each step.

e.g. your file is 1000 bytes long - with the above declaration you would end up with four lines in your internal table because in every loop step you would read exactly (up to) 256 bytes.

Another thing is in the blog you referred to the data is read in binary format because it is passed into the DOM object - that's what we do as well - but if you want to compare header information or stuff like that binary format is not going to work.

If you would like to the the file in text format (to be able to compare tags etc.) you would need to open it in text mode instead of binary mode. In that case it would look something like this:


data: ls_string type string,
      lt_string type stringtab.

OPEN DATASET lv_name FOR INPUT IN TEXT MODE ENCODING DEFAULT.
 
    DO.
*     append the file line by line
      READ DATASET lv_name INTO ls_string.
      IF sy-subrc EQ 0.
*       determine the length
        y_filelength = y_filelength + STRLEN( ls_string ).
        APPEND ls_string TO lt_string.
      ELSE.
        EXIT .
      ENDIF.
    ENDDO.
*   now we need to close the file
    CLOSE DATASET lv_name.

That way you would see the contents of the XML file in text in your internal table lt_string enabling you to compare tags etc.

Hope that clarifies it,

Michael

0 Kudos
214

Hi Michael,

Thank you so much for your explanation. I manage to store the read XML into an internal table. No, I didnt need that file size...Anyway,

How I did it was

1. OPEN DATASET(text mode).

2. Convert into XSTRING using FM SCMS_STRING_TO_XSTRING

3. SMUM_XML_PARSE. The internal table has the fields( its the XML nodes right?) and values. which is what i need.

Once again, your coding example is useful if i need the filesize in the near future. many thanks.

Point awarded

Edited by: Slow ABAPer on Nov 20, 2008 10:59 AM

Former Member
0 Kudos
214

Manage to solve it as explained

Former Member
0 Kudos
214

Hi guys...

Sorry but I need to use Call Transformation for this requirement.

I'm currently using http://heidoc.net/joomla/content/view/15/1/

But how do I get the files from application server to use the Call Transformation

Please help.

0 Kudos
214

Read the file in and call the xslt in your report.

0 Kudos
214

Hi there.

Sorry for not giving much details. here is how my program flows

I'm reading all the xml files in the directory using FM RZL_READ_DIR_LOCAL

I will then loop through the return list of files. example file_table type table of salfldir.

My question is...from this loop, how do I read the xml and use the call transformation?

Any brief example?

0 Kudos
214

Call transactopn ABAPDOCU and search fpr keywords OPEN, CLOSE, READ and TRANSFER. There are examples in the online help.