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

XML -> ABAP

Former Member
0 Likes
5,319

Can anybody give me an idea as to how to read xml from an ABAP Program?

Thanks and Regards,

Thiru

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,196

The type was BIN and p_file is of type c, still i get the same error.

Can anybody give me an idea as to how to read xml from an ABAP Program?

Thanks and Regards,

Thiru

16 REPLIES 16
Read only

athavanraja
Active Contributor
0 Likes
5,196

do you want to read the XML file stored in the frontend to ABAP program,

use GUI_UPLOAD

what do you want to do with the loaded XML? if you could explain this then we can come up with suggestions.

Regards

Raja

Read only

Former Member
0 Likes
5,196

Hello Durai,

I would like to know how to store the xml into an internal table.

I have created a dot net application where we download data from SAP and then send mails. We display the data within a HTML table. We found type out all the code(to create the table and display data) in ABAP store it in a string and then use SO_OBJECT_SEND to send email. Instead if we can store the file and read it into an internal table, then populate the SAP data and send the email, we thought it could be useful.

Kindly advise.

Thanks and Regards,

Thiru

Read only

0 Likes
5,196

<i>I would like to know how to store the xml into an internal table.</i>

you want to store the XML as just a string then just use GUI_UPLOAD

if you want to transform the loaded XML into a internal table of rows and columns the you need to use

CALL TRANSFORMATION key word. (search the forum there were solutions).

the second part of your explantaion is not clear to me.

Regards

Raja

Read only

Former Member
0 Likes
5,196

hi , you can parse the XML using DOM, DOM is also supported in ABAP, there is a class CL_IXML, and other associated class. you can achieve your target by using them.

reference link:

http://help.sap.com/saphelp_nw04/helpdata/en/86/8280d212d511d5991b00508b6b8b11/frameset.htm

The other way is through XLST. it is supported in ABAP from 4.7. you can create a XSLT, and read you XML, then CALL TRANSFORMATION to convert a XML into ABAP data structure.

reference link:

http://help.sap.com/saphelp_nw04/helpdata/en/fd/9d7348389211d596a200a0c94260a5/frameset.htm

Hope it will be helpful

thanks

Read only

Former Member
0 Likes
5,196

hi, if you want to restore content of XML into a internal table, read following link:

The last reply of mine in this link will work fine.

Thanks

Read only

Former Member
0 Likes
5,196

Hello Durai, Zhenglin,

Your inputs have been useful. I will explore this and get back.

Regards,

Thiru

Read only

Former Member
0 Likes
5,196

Whil I use GUI_UPLOAD, I get the following error 'Type conflict when calling a function module.

'

I have tried the following-

1. FILETYPE = 'ASC'

2. FILETYPE = 'BIN'

3. FILETYPE = 'XML'

None seem to work. I used WS_FILENAME_GET to select the file, at selection-screen(using f4 help, I select the file and the path is stored in p_file).

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = p_file

FILETYPE = 'BIN'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = itab

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Kindly advice.

Read only

0 Likes
5,196

for xml files better use BIN

and your variable p_file has to be of type string,

Regards

Raja

if you find the answers helpful, reward them by clicking the radio button and if you feel the question is answered mark it answered.

Read only

Former Member
0 Likes
5,197

The type was BIN and p_file is of type c, still i get the same error.

Read only

0 Likes
5,196

p_file has to be type string.

data: p_file type string.

Regards

Raja

Read only

Former Member
0 Likes
5,196

Hi Durai,

That problem got sorted out, and i have assigned the points. thanks, but i am getting an error in the standard program saying 'Error in ASSIGN statement in program "SAPLSFES ".

'

Read only

0 Likes
5,196

there is something wrong with your itab declaration.

how did you declare the itab?

Regards

Raja

Read only

Former Member
0 Likes
5,196

DATA: BEGIN OF ITAB OCCURS 0,

CODE TYPE STRING,

END OF ITAB.

Read only

0 Likes
5,196

DATA: BEGIN OF ITAB OCCURS 0,

CODE TYPE <b>xSTRING</b>,

END OF ITAB.

Regards

Raja

Read only

Former Member
0 Likes
5,196

I tried it Durai, still I get the same thing.

&----


*& Report ZVTN_XML_READ *

*& *

&----


*& *

*& *

&----


REPORT ZVTN_XML_READ.

DATA: BEGIN OF ITAB OCCURS 0,

CODE TYPE xSTRING,

END OF ITAB,

itabtemp like itab occurs 0 with header line.

DATA param type string.

selection-screen begin of block b1 with frame title text-001.

*parameter p_file like param obligatory.

parameter p_file like RLGRAP-FILENAME.

selection-screen end of block b1.

at selection-screen on value-request for p_file.

perform read_file using p_file.

start-of-selection.

perform Uploadfile.

perform Displaydata.

form read_file using p_p_file.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = SPACE

DEF_PATH = p_file

MASK = ',.,..'

MODE = '0'

TITLE = 'Choose File '

IMPORTING

FILENAME = p_p_file

  • RC =

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endform.

form uploadfile.

param = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = param

FILETYPE = 'BIN'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = itab

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endform.

form Displaydata.

write itab-code.

endform.

Read only

0 Likes
5,196

couldnt figureout the issue. but i guess you dont have any problem if the uploaded content is in binary format or ASC format.

make the following changes. (sorry for the inconvenience)

change the itab to string

and file type to 'ASC'

if you still want to have it in BIN format,

check out the program SXSLTDEMO_FLIGHTS

search for the code "<i>perform load_file using i_path changing srctab</i>"

you can see how the itab is built.

Regards

Raja