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 to ABAP Conversion

Former Member
0 Likes
842

Hi Experts,

I am using SFP transaction.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

CHANGING

file_table = lt_file_table

rc = lv_rc

USER_ACTION =

FILE_ENCODING =

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4

OTHERS = 5.

READ TABLE lt_file_table

INTO lv_filename

INDEX 1.

cl_gui_frontend_services=>gui_upload(

EXPORTING

filename = lv_filename

filetype = 'BIN' "Binary

IMPORTING

filelength = lv_filelength

CHANGING

data_tab = lt_rawtab

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

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19 ).

Get FP reference

DATA: lo_fp TYPE REF TO if_fp VALUE IS INITIAL.

lo_fp = cl_fp=>get_reference( ).

For handling exceptions

DATA: lo_fpex TYPE REF TO cx_fp_runtime VALUE IS INITIAL.

TRY.

Create PDF Object using destination 'ADS' (<-- this is how it is

defined in SM59)

DATA: lo_pdfobj TYPE REF TO if_fp_pdf_object VALUE IS INITIAL.

lo_pdfobj = lo_fp->create_pdf_object( connection = 'ADS' ).

FIELD-SYMBOLS: <ls_rawtab> LIKE LINE OF lt_rawtab.

Move to XSTRING

LOOP AT lt_rawtab ASSIGNING <ls_rawtab>.

CONCATENATE pdf_data <ls_rawtab>-data INTO pdf_data IN BYTE MODE.

ENDLOOP.

Set document

lo_pdfobj->set_document(

EXPORTING

pdfdata = PDF_DATA).

CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'

EXPORTING

IM_XSTRING = XML_DATA

IMPORTING

EX_STRING = LV_XML_DATA_STRING.

  • Remove NEW-LINE character from XML data in STRING format

CLASS cl_abap_char_utilities DEFINITION LOAD.

REPLACE ALL OCCURrENCES OF cl_abap_char_utilities=>newline IN

lv_xml_data_string WITH ''.

  • Make the XML envelope compliant with identity transform

REPLACE '<?xml version="1.0" encoding="UTF-8"?><data>'

IN lv_xml_data_string

WITH '<?xml version="1.0" encoding="iso-8859-1"?><asx:abap xmlns :asx="http://www.sap.com/abapxml" version="1.0"><asx:values>'.

REPLACE '</data>' IN lv_xml_data_string WITH '</asx:values></asx:abap>'.

  • Apply the identity transform and convert XML into ABAP in one step

CALL TRANSFORMATION ('ID')

SOURCE XML lv_xml_data_string

RESULT out = out.

But getting error

Short text

XSLT: No valid XML source

Runtime Errors XSLT_BAD_SOURCE_CONTEXT

Except. CX_XSLT_RUNTIME_ERROR

How i call -->call transforamtion...Can any one please tell me how to convert XML to abap internal table?...

Thanks

Hi Experts,

I am using SFP transaction.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

CHANGING

file_table = lt_file_table

rc = lv_rc

USER_ACTION =

FILE_ENCODING =

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4

OTHERS = 5.

READ TABLE lt_file_table

INTO lv_filename

INDEX 1.

cl_gui_frontend_services=>gui_upload(

EXPORTING

filename = lv_filename

filetype = 'BIN' "Binary

IMPORTING

filelength = lv_filelength

CHANGING

data_tab = lt_rawtab

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

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19 ).

Get FP reference

DATA: lo_fp TYPE REF TO if_fp VALUE IS INITIAL.

lo_fp = cl_fp=>get_reference( ).

For handling exceptions

DATA: lo_fpex TYPE REF TO cx_fp_runtime VALUE IS INITIAL.

TRY.

Create PDF Object using destination 'ADS' (<-- this is how it is

defined in SM59)

DATA: lo_pdfobj TYPE REF TO if_fp_pdf_object VALUE IS INITIAL.

lo_pdfobj = lo_fp->create_pdf_object( connection = 'ADS' ).

FIELD-SYMBOLS: <ls_rawtab> LIKE LINE OF lt_rawtab.

Move to XSTRING

LOOP AT lt_rawtab ASSIGNING <ls_rawtab>.

CONCATENATE pdf_data <ls_rawtab>-data INTO pdf_data IN BYTE MODE.

ENDLOOP.

Set document

lo_pdfobj->set_document(

EXPORTING

pdfdata = PDF_DATA).

CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'

EXPORTING

IM_XSTRING = XML_DATA

IMPORTING

EX_STRING = LV_XML_DATA_STRING.

  • Remove NEW-LINE character from XML data in STRING format

CLASS cl_abap_char_utilities DEFINITION LOAD.

REPLACE ALL OCCURrENCES OF cl_abap_char_utilities=>newline IN

lv_xml_data_string WITH ''.

  • Make the XML envelope compliant with identity transform

REPLACE '<?xml version="1.0" encoding="UTF-8"?><data>'

IN lv_xml_data_string

WITH '<?xml version="1.0" encoding="iso-8859-1"?><asx:abap xmlns :asx="http://www.sap.com/abapxml" version="1.0"><asx:values>'.

REPLACE '</data>' IN lv_xml_data_string WITH '</asx:values></asx:abap>'.

  • Apply the identity transform and convert XML into ABAP in one step

CALL TRANSFORMATION ('ID')

SOURCE XML lv_xml_data_string

RESULT out = out.

But getting error

Short text

XSLT: No valid XML source

Runtime Errors XSLT_BAD_SOURCE_CONTEXT

Except. CX_XSLT_RUNTIME_ERROR

How i call -->call transforamtion...Can any one please tell me how to convert XML to abap internal table?...

Thanks

3 REPLIES 3
Read only

Former Member
0 Likes
621

Solved

Read only

0 Likes
621

Hi, How did you solve it? I have same problem and no idea what I can do. Thanks. Jarda

Read only

0 Likes
621

Hi,

I just catch the exception.

Regards,

Mathi