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

reading XML File from application server

Former Member
0 Likes
2,794

Hi experts,

My aim is to read a XML file from application server and extract the relevant data from it and process further.

When I am trying to read a XML file from application server it is reading success fully but the problem is that its not reading the last root structure of XML file why is so happening can any body help me?

I am using the following code:

TYPES: BEGIN OF xml_line,

text(256) type x,

END OF xml_line.

DATA: e_file LIKE rlgrap-filename VALUE 'applcatin server path'

OPEN DATASET e_file FOR INPUT IN BINARY MODE.

IF sy-subrc EQ 0.

DO.

READ DATASET e_file INTO wa_item1-text.

IF sy-subrc EQ 0.

APPEND wa_item1 TO gt_item1 .

CLEAR wa_item1.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET e_file.

after this i am passing this internal table to "cl_ixml" class to extract the data

but it returning the itab with required value except the last record.

The stream reading the file it self is i thought in complete thats why it is not converting the all values.

Please help me...

Thanks a ton in advance.

4 REPLIES 4
Read only

RahulKeshav
Active Contributor
0 Likes
1,248

Hi,

Try to debug and find out weather your internal table gt_item1 is populating with all the entries...

thnx

Rahul

Read only

Former Member
0 Likes
1,248

Hi,

1 Copy Report BCCIIXMLT1

2 (you can change the way of filling internal table xml_table if necessary)

3 you don't need the part between

*-- render the DOM back into an output stream/internal table

and

*-- print the whole DOM tree as a list...

Comment it out or simply delete it

4 Rename form print_node to your liking e.g. process_node

5 In your new form you need three extra variables:

data: attribs type ref to IF_IXML_NAMED_NODE_MAP,

attrib_node type ref to IF_IXML_NODE,

attrib_value type string.

6 After the lines:

when if_ixml_node=>co_node_element.

string = pNode->get_name( ).

Insert:

attribs = pNode->get_attributes( ).

clear attrib_value.

case string.

when ''. "put your XML tag name here

attrib_node = attribs->get_named_item(name = '' ). "put your XML attribute name here

attrib_value = attrib_node->get_value( ).

You can also refer link,

/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach

thanks & regards

shreemohan

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,248

>

> but it returning the itab with required value except the last record.

Before you use cl_ixml, did you check whether your itab contains this last record ? If it's missing, it means that the last record in your file doesn't end with a "line feed character". This is because READ DATASET sets sy-subrc = 4 though it reads something (the last line). You should either modify the source file (add a line feed character after the last character), or add LENGTH keyword to READ DATASET and test this length altogether with sy-subrc (IF sy-subrc EQ 0 OR length <> 0. (processing) ELSE. EXIT. ENDIF.)

Read only

Former Member
0 Likes
1,248

Nikhil,

Try using identical transformation that will convert XML string directly in ABAP data stored record wise in internal table.

It is simple and fast.

Thanks,

Augustin.