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

upload mass data from file during testing the function module

Former Member
0 Likes
856

hi everyone,

i need to upload the data in XML format during testing of my customer(z) functin module,

please anyone help me out in solving this problem ASAP as this is a very urgent requirement .

Thanks in Advance!!

Munish

1 REPLY 1
Read only

Former Member
0 Likes
493

hi Munish,

the following code is used to get the large records from XML file, and print the collected data on to a list.. (a test program!!!) .

hope this would be helpful...

TYPE-POOLS: ixml.

START-OF-SELECTION.

CLASS cl_ixml DEFINITION LOAD.

*-- Folder selection Declarations

PARAMETER: ofile TYPE file_table-filename OBLIGATORY.

DATA: directory TYPE string.

DATA: window_title TYPE string.

DATA: sel_folder TYPE string.

DATA: file_path LIKE rlgrap-filename.

DATA: wa_file_name TYPE file_name.

DATA: file_table TYPE STANDARD TABLE OF file_name.

DATA: count_files TYPE i.

*-- iXML Declarations

DATA: element TYPE REF TO if_ixml_element.

*----


*

  • selection-screen - value reques for filename

*----


*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR ofile.

MOVE 'Destination Data File'(002) TO window_title.

CALL METHOD cl_gui_frontend_services=>directory_browse

EXPORTING

window_title = window_title

  • INITIAL_FOLDER =

CHANGING

selected_folder = sel_folder

  • EXCEPTIONS

  • CNTL_ERROR = 1

  • ERROR_NO_GUI = 2

  • others = 3 .

directory = sel_folder.

ofile = sel_folder.

END-OF-SELECTION.

directory = ofile.

IF sy-subrc = 0.

CALL METHOD cl_gui_frontend_services=>directory_list_files

EXPORTING

directory = directory

filter = '*.xml'

files_only = 'X'

  • DIRECTORIES_ONLY =

CHANGING

file_table = file_table

count = count_files .

ENDIF.

IF sy-subrc = 0.

LOOP AT file_table INTO wa_file_name.

CONCATENATE directory '' wa_file_name INTO file_path.

PERFORM upload_parse USING file_path.

ENDLOOP.

ENDIF.

*&----


*

*& Form upload_parse

*&----


*

  • text

*----


*

  • -->P_FILE_PATH text

*----


*

FORM upload_parse USING p_file_path LIKE rlgrap-filename.

DATA: g_ixml TYPE REF TO if_ixml.

DATA: streamfactory TYPE REF TO if_ixml_stream_factory.

DATA: document TYPE REF TO if_ixml_document.

DATA: pnode TYPE REF TO if_ixml_node.

DATA: parser TYPE REF TO if_ixml_parser.

DATA: xml_doc TYPE string.

TYPES : BEGIN OF xml_line,

data(256) TYPE x,

END OF xml_line.

DATA: xml_table TYPE TABLE OF xml_line,

istream TYPE REF TO if_ixml_istream,

xml_table_size TYPE i.

DATA: parseerror TYPE REF TO if_ixml_parse_error,

str TYPE string,

position TYPE i,

count TYPE i,

index TYPE i.

*----

-


DATA: event TYPE REF TO if_ixml_event,

type TYPE i,

node TYPE REF TO if_ixml_node,

value TYPE string,

name TYPE string,

indent TYPE i.

*----

-


*-- upload a file from the client's workstation

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p_file_path

filetype = 'BIN'

IMPORTING

filelength = xml_table_size

TABLES

data_tab = xml_table

EXCEPTIONS

OTHERS = 11.

*-- create the main factory

g_ixml = cl_ixml=>create( ).

*-- create the initial document

document = g_ixml->create_document( ).

*-- create the stream factory

streamfactory = g_ixml->create_stream_factory( ).

*-- create an input stream for the table

istream = streamfactory->create_istream_itable(

table = xml_table

size = xml_table_size ).

*-- create the parser

parser = g_ixml->create_parser( stream_factory = streamfactory

istream = istream

document = document ).

*!! subscribe events

*!!

DATA: events TYPE i.

ADD if_ixml_event=>co_event_element_pre TO events.

ADD if_ixml_event=>co_event_attribute_post TO events.

ADD if_ixml_event=>co_event_text_post TO events.

  • ... other events

  • parser->set_event_subscription( events = events ).

CALL METHOD parser->set_event_subscription

EXPORTING

events = events

.

ULINE.

WRITE: /.

WRITE: /' EVENTS'.

WRITE: /.

*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

*!! event based parsing

DO.

*! read next event

event = parser->parse_event( ).

IF event IS INITIAL. EXIT. ENDIF.

*! get event type

type = event->get_type( ).

node = event->get_node( ).

indent = node->get_height( ) * 2.

indent = indent + 20.

*! evaluate event type

CASE type.

WHEN if_ixml_event=>co_event_element_pre.

  • element event

name = node->get_name( ).

CASE name.

WHEN 'Title' OR 'TargetAudience' OR 'Prerequisites' OR

'RequiredKnowledge' OR 'Goals' OR 'KTPContent' OR 'Notes'.

WRITE: / 'ELEMENT PRE :'.

WRITE: AT indent name COLOR COL_POSITIVE INVERSE.

ENDCASE.

WHEN if_ixml_event=>co_event_attribute_post.

  • attr event

name = node->get_name( ).

value = node->get_value( ).

WRITE: / 'ATTR POST:'.

WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',

value COLOR COL_TOTAL INVERSE.

WHEN if_ixml_event=>co_event_text_post OR

if_ixml_event=>co_event_cdata_section_post.

  • text event

value = node->get_value( ).

WRITE: / 'TEXT POST:'.

WRITE: AT indent value COLOR COL_GROUP INVERSE.

WHEN OTHERS.

  • other event

WRITE: / 'EVENT-TYPE :'.

WRITE: AT indent type COLOR COL_NORMAL INVERSE.

ENDCASE.

ENDDO.

*-- parse the stream

  • IF parser->parse( ) NE 0.

IF parser->num_errors( ) NE 0.

count = parser->num_errors( ).

WRITE: count, ' parse errors have occured:'.

index = 0.

WHILE index < count.

parseerror = parser->get_error( index = index ).

position = parseerror->get_line( ).

WRITE: 'line: ', position.

position = parseerror->get_column( ).

WRITE: 'column: ', position.

str = parseerror->get_reason( ).

WRITE: str.

index = index + 1.

ENDWHILE.

ENDIF.

  • ENDIF.

*-- just clear the stream

CALL METHOD istream->close( ).

CLEAR istream.

element = document->get_root_element( ).

  • pnode = document.

  • PERFORM print_node USING pnode.

  • WRITE:/ sy-uline.

ENDFORM. " upload_parse

*----


*

  • FORM print_node *

*----


*

  • ........ *

*----


*

FORM print_node USING value(pnode) TYPE REF TO if_ixml_node.

DATA: indent TYPE i.

DATA: ptext TYPE REF TO if_ixml_text,

attributes TYPE REF TO if_ixml_named_node_map.

DATA: node_string TYPE string,

child TYPE REF TO if_ixml_node,

att_count TYPE i,

att_name TYPE string,

att_value TYPE string,

att_index TYPE i.

indent = pnode->get_height( ) * 2.

CASE pnode->get_type( ).

WHEN if_ixml_node=>co_node_element.

*-- get the node name

node_string = pnode->get_name( ).

CASE node_string.

WHEN 'Title' OR 'TargetAudience' OR 'Prerequisites' OR

'RequiredKnowledge' OR 'Goals' OR 'KTPContent' OR 'Notes'.

WRITE: AT /indent node_string, ':'.

*-- Get the KTPDescription attribute names and values..

WHEN 'KTPDescription'.

attributes = element->get_attributes( ).

IF NOT attributes IS INITIAL.

att_count = attributes->get_length( ).

DO att_count TIMES.

att_index = sy-index - 1.

child = attributes->get_item( att_index ).

att_name = child->get_name( ).

att_value = child->get_value( ).

WRITE: / att_name,':', att_value.

IF sy-subrc = 0.

ENDIF.

ENDDO.

ENDIF.

ENDCASE.

*-- Get node values

WHEN if_ixml_node=>co_node_text.

ptext ?= pnode->query_interface( ixml_iid_text ).

IF ptext->ws_only( ) IS INITIAL.

node_string = pnode->get_value( ).

REPLACE '-Auml-' WITH 'Ä' INTO node_string.

REPLACE '-auml-' WITH 'ä' INTO node_string.

REPLACE '-Ouml-' WITH 'Ö' INTO node_string.

REPLACE '-ouml-' WITH 'ö' INTO node_string.

REPLACE '-Uuml-' WITH 'Ü' INTO node_string.

REPLACE '-uuml-' WITH 'ü' INTO node_string.

REPLACE '-szlig-' WITH 'ß' INTO node_string.

WRITE: AT /indent node_string.

ENDIF.

ENDCASE.

pnode = pnode->get_first_child( ).

WHILE NOT pnode IS INITIAL.

  • PERFORM print_node USING pnode.

  • pnode = pnode->get_next( ).

ENDWHILE.

ENDFORM. "print_node