SAP创建XML 文件
TYPES: BEGIN OF xml_line_type,
data(256) TYPE x,
END OF xml_line_type,
xml_tab_type TYPE TABLE OF xml_line_type,
xml_element TYPE REF TO if_ixml_element. DATA:unicodelg LIKE x030l-unicodelg,
temp_fore_filename TYPE string,
curr_object_type TYPE i,
percentage TYPE p DECIMALS 2,
obj_perc TYPE p DECIMALS 2,
temp_back_filename LIKE rlgrap-filename,
g_iref_root_elem TYPE REF TO if_ixml_element,
g_iref_pixml TYPE REF TO if_ixml,
g_iref_pdocument TYPE REF TO if_ixml_document,
g_iref_pstreamfactory TYPE REF TO if_ixml_stream_factory,
gt_converted_data TYPE xml_tab_type,
g_ostream TYPE REF TO if_ixml_ostream,
g_buffer_itab TYPE xml_tab_type,
g_strx TYPE xstring,
gv_tabix TYPE sy-tabix,
g_file_append_mode TYPE char01 VALUE space. DATA:p_fore TYPE char128 VALUE 'C:\Users\wangz94\Desktop\xml\xml.xml',
p_back TYPE rlgrap-filename,
r_fore TYPE c VALUE 'X',
r_back TYPE c VALUE '',
no_usage TYPE c,
popup_ok TYPE c VALUE 'X',
new_line TYPE string. CONSTANTS: encoding(10) TYPE c VALUE 'UTF-8',
num_object_types TYPE i VALUE 48,
* Test mode definiton - do not change
panaya_test_mode TYPE c VALUE space,
show_servers_name TYPE c VALUE 'X',
skip_empty_tags TYPE c VALUE 'X',
buffer_max_size TYPE i VALUE 10000000,
general_part_ver(15) TYPE c VALUE '2.36',
rel_specific_ver(15) TYPE c VALUE '10_2005',
root_element_name(30) TYPE c VALUE 'ROOT_ELEMENT'. temp_fore_filename = p_fore.
* Create the main factory and the initial document
PERFORM create_xml_document.
* Create the root element of the XML
PERFORM xml_header USING g_iref_pdocument root_element_name
CHANGING g_iref_root_elem. PERFORM open_xml_file.
* Add data to the XML
PERFORM add_data_to_xml. PERFORM close_xml_file. FORM add_data_to_xml.
PERFORM add_document_header.
ENDFORM.
*---------------------------------------------------------------------*
* FORM create_xml_document 创建XML文件 *
*---------------------------------------------------------------------*
FORM create_xml_document. DATA: l_encoding TYPE string,
i_encoding TYPE REF TO if_ixml_encoding. * create the main factory
g_iref_pixml = cl_ixml=>create( ). * create the initial document
g_iref_pdocument = g_iref_pixml->create_document( ). l_encoding = encoding.
i_encoding = g_iref_pixml->create_encoding( character_set = l_encoding
byte_order = '0' ).
CALL METHOD g_iref_pdocument->set_encoding( encoding = i_encoding ). ENDFORM. " create_xml_document *---------------------------------------------------------------------*
* FORM xml_header(XML 头部信息) *
*---------------------------------------------------------------------*
FORM xml_header USING VALUE(pi_pdocument) TYPE REF TO if_ixml_document
VALUE(pi_xml_root) TYPE c
CHANGING VALUE(pc_elem) TYPE REF TO if_ixml_element. DATA:
l_simple_elem TYPE REF TO if_ixml_element,
l_elem TYPE REF TO if_ixml_element,
l_result TYPE i,
l_name TYPE string. l_name = pi_xml_root .
l_elem = pi_pdocument->create_element( name = l_name ).
l_result = pi_pdocument->append_child( l_elem ).
pc_elem = l_elem. ENDFORM. " xml_header *---------------------------------------------------------------------*
* FORM add_attribute_to_node (XML节点属性) *
*---------------------------------------------------------------------*
FORM add_attribute_to_node USING
VALUE(pi_elem) TYPE REF TO if_ixml_element
VALUE(pi_attr_name) TYPE string
VALUE(pi_value) TYPE any. DATA: l_value TYPE string. l_value = pi_value. IF l_value IS INITIAL AND NOT skip_empty_tags IS INITIAL.
EXIT.
ENDIF. CALL METHOD pi_elem->set_attribute
EXPORTING
name = pi_attr_name
value = l_value. ENDFORM. "add_attribute_to_node *&---------------------------------------------------------------------*
*& Form add_document_header
*&---------------------------------------------------------------------*
FORM add_document_header. DATA: header_node TYPE xml_element.
DATA: code_version(15) TYPE c. DATA: lv_text TYPE char10,
lv_license TYPE char10,
lv_mode TYPE char10,
lv_logsys TYPE logsys,
lv_rfc_sysid TYPE sy-sysid,
lv_rfc_mandt TYPE sy-mandt. DATA: k_release TYPE sysaprl,
k_patch TYPE sychar05.
DATA: host TYPE string. * Create a child node for the Header node
PERFORM create_xml_node USING g_iref_pdocument g_iref_root_elem 'HEADER'
CHANGING header_node.
* Set Date
lv_text = sy-datum.
PERFORM add_attribute_to_node USING header_node 'DATE' lv_text.
* Set Time
lv_text = sy-uzeit.
PERFORM add_attribute_to_node USING header_node 'TIME' lv_text.
* Set Application Server
IF show_servers_name IS INITIAL.
host = 'XXX'.
ELSE.
host = sy-host.
ENDIF.
PERFORM add_attribute_to_node USING header_node 'APPLICATION_SERVER' host.
* Set System ID name
PERFORM add_attribute_to_node USING header_node 'SYSTEM_ID' sy-sysid.
* Set Client number
PERFORM add_attribute_to_node USING header_node 'CLIENT' sy-mandt.
* Set Operating System
PERFORM add_attribute_to_node USING header_node 'OPERATING_SYSTEM' sy-opsys.
* Set SAP System Release
PERFORM add_attribute_to_node USING header_node 'SYSTEM_RELEASE' sy-saprl.
* Set Installation number
CALL FUNCTION 'SLIC_GET_LICENCE_NUMBER'
IMPORTING
license_number = lv_license.
PERFORM add_attribute_to_node USING header_node 'INSTALLATION_NUMBER' lv_license.
* Set User name
PERFORM add_attribute_to_node USING header_node 'USER_NAME' sy-uname.
* Set Export Tool Version
CONCATENATE general_part_ver rel_specific_ver INTO code_version SEPARATED BY '.'.
PERFORM add_attribute_to_node USING header_node 'EXPORT_TOOL_VERSION' code_version.
* Set Target System
PERFORM add_attribute_to_node USING header_node 'TARGET_SYSTEM' 'DR1'.
* Set Target System Id ( production system id )
PERFORM add_attribute_to_node USING header_node 'TARGET_SYSTEM_ID' 'rfc_sysid'.
* Set Target system release
PERFORM add_attribute_to_node USING header_node 'TARGET_SYSTEM_REL' 'rfc_saprl'.
* Set ETL vanilla extraction flag
PERFORM add_attribute_to_node USING header_node 'VANILLA_EXTRACTION' 'X'.
* Set SM Target System
PERFORM add_attribute_to_node USING header_node 'SM_SYSTEM' 'p_sm_rfc'.
* Set SM System Id
PERFORM add_attribute_to_node USING header_node 'SM_SYSTEM_ID' 'sm_sysid'.
* Set SM system release
PERFORM add_attribute_to_node USING header_node 'SM_SYSTEM_REL' 'sm_saprl'.
* Set execution mode
IF r_back IS INITIAL.
lv_mode = 'FOREGROUND'.
ELSE.
lv_mode = 'BACKGROUND'.
ENDIF.
PERFORM add_attribute_to_node USING header_node 'MODE' lv_mode. PERFORM add_attribute_to_node USING header_node 'PRD_LOGSYS' 'gv_logsys'. CALL FUNCTION 'PARTNER_LOGICAL_SYSTEM_GET'
IMPORTING
p_logsys = lv_logsys
EXCEPTIONS
own_logical_system_not_defined = 1
OTHERS = 2.
IF sy-subrc <> 0.
lv_logsys = 'UNDEFINED'.
ENDIF.
PERFORM add_attribute_to_node USING header_node 'LOCAL_LOGSYS' lv_logsys. * Add unicode length of the current system
PERFORM add_attribute_to_node USING header_node 'UCLEN' unicodelg.
* Add active industry solution when applicable
PERFORM add_attribute_to_node USING header_node 'ACTIVE_INDUSTRY_SOLUTION' 'active_industry_solution'.
* Add usage only
PERFORM add_attribute_to_node USING header_node 'USAGE_ONLY' 'usageonl'.
PERFORM add_attribute_to_node USING header_node 'IA_DATA_ONLY' 'ia_data_only'.
PERFORM add_attribute_to_node USING header_node 'REQUIRE_SOLMAN_RFC' 'require_solman_rfc'.
PERFORM add_attribute_to_node USING header_node 'TESTING_DATA_ONLY' 'testing_data_only'.
PERFORM add_attribute_to_node USING header_node 'NO_SUET_DATA' 'no_suet_data'.
PERFORM add_attribute_to_node USING header_node 'EXTRACT_DEBUG' 'extract_debug'.
PERFORM add_attribute_to_node USING header_node 'EXTRACT_FULL_USAGE' 'extract_full_usage'.
PERFORM add_attribute_to_node USING header_node 'EXTRACT_WORKFLOW_DATA' 'extract_workflow_data'.
PERFORM add_attribute_to_node USING header_node 'GET_AGR_USERS' 'get_agr_users'. * Add version specific header attributes
* PERFORM version_specific_header_attrib USING header_node.
PERFORM add_attribute_to_node USING header_node 'MINI_VERSION' 'HEADER_MINI_VERSION'.
* Add kernel data
PERFORM get_kernel_data CHANGING k_release k_patch.
PERFORM add_attribute_to_node USING header_node 'KERNEL_RELEASE' k_release.
PERFORM add_attribute_to_node USING header_node 'KERNEL_PATCH' k_patch.
PERFORM add_attribute_to_node USING header_node 'EXTRACT_USER_DATA' 'extract_user_data'.
PERFORM add_attribute_to_node USING header_node 'SM_SYSTEM' 'p_sm_rfc'.
* Set SM System Id
PERFORM add_attribute_to_node USING header_node 'SM_SYSTEM_ID' 'sm_sysid'.
* Set SM system release
PERFORM add_attribute_to_node USING header_node 'SM_SYSTEM_REL' 'sm_saprl'.
* Set bw extraction system data
* BW system
PERFORM add_attribute_to_node USING header_node 'BW_DESTINATION' 'p_bw_rfc'. * CALL FUNCTION 'SCT2_GET_T000_ENTRY_RFC' DESTINATION p_bw_rfc
* IMPORTING
* ev_sysid = lv_rfc_sysid
* ev_mandt = lv_rfc_mandt
* EXCEPTIONS
* system_failure = 1
* communication_failure = 2. * Set BW System ID
PERFORM add_attribute_to_node USING header_node 'BW_SYSID' 'lv_rfc_sysid'.
* Set BW Client
PERFORM add_attribute_to_node USING header_node 'BW_CLIENT' 'lv_rfc_mandt'.
* Set the local system and target system's types
PERFORM add_system_types_to_header USING header_node.
PERFORM append_xml_element_to_file USING header_node 'X'.
ENDFORM. " add_document_header *&---------------------------------------------------------------------*
*& Form ADD_SYSTEM_TYPES_TO_HEADER
*&---------------------------------------------------------------------*
* ........ *
*----------------------------------------------------------------------*
FORM add_system_types_to_header
USING iv_header_node TYPE REF TO if_ixml_element. DATA: ls_local_system TYPE t000,
ls_target_system TYPE t000,
ls_rfcdes TYPE rfcdes,
ls_rfcdisplay TYPE rfcdisplay. DATA: lv_prefix TYPE string,
lv_suffix TYPE string,
lv_target_mandt TYPE mandt. DATA: options TYPE TABLE OF rfc_db_opt,
fields TYPE TABLE OF rfc_db_fld,
t000_itab TYPE TABLE OF t000. * Local system's type
SELECT SINGLE *
FROM t000
INTO CORRESPONDING FIELDS OF ls_local_system
WHERE mandt EQ sy-mandt. IF sy-subrc IS INITIAL.
PERFORM add_attribute_to_node USING iv_header_node
'LOCAL_SYSTEM_TYPE' ls_local_system-cccategory.
MESSAGE s000(conv) WITH 'LOCAL_SYSTEM_TYPE ='
ls_local_system-cccategory.
ENDIF. * Target system's type
SELECT SINGLE *
FROM rfcdes BYPASSING BUFFER
INTO CORRESPONDING FIELDS OF ls_rfcdes
WHERE rfcdest EQ 'DR1'. IF sy-subrc IS INITIAL.
SPLIT ls_rfcdes-rfcoptions AT ',M=' INTO lv_prefix lv_suffix.
IF sy-subrc IS INITIAL AND NOT lv_suffix IS INITIAL.
lv_target_mandt = lv_suffix(3).
ENDIF.
ENDIF. * Get target system T000 table
CALL FUNCTION 'RFC_READ_TABLE' DESTINATION 'DR1'
EXPORTING
query_table = 'T000'
delimiter = space
no_data = space
rowskips = 0
rowcount = 0
TABLES
options = options
fields = fields
data = t000_itab
EXCEPTIONS
table_not_available = 1
table_without_data = 2
option_not_valid = 3
field_not_valid = 4
not_authorized = 5
data_buffer_exceeded = 6
OTHERS = 7. IF sy-subrc IS INITIAL AND NOT t000_itab IS INITIAL.
IF NOT lv_target_mandt IS INITIAL.
* Read target T000 with mandt
READ TABLE t000_itab INTO ls_target_system
WITH KEY mandt = lv_target_mandt.
IF NOT sy-subrc IS INITIAL.
* Fallback: Mandt not found Read target T000 with cccategory = 'P'
* CONCATENATE
* 'No results in target system T000 table'
* 'for target MANDT found:' lv_target_mandt
* 'Reading T000 with cccategory = P'
* INTO gt_etl_message-message SEPARATED BY space. * PERFORM add_message USING gt_etl_message-message abap_false. READ TABLE t000_itab INTO ls_target_system
WITH KEY cccategory = 'P'.
ENDIF.
ELSE.
* Fallback: No mandt: Read target T000 with cccategory = 'P'
* CONCATENATE
* 'Failed to get MANDT, Reading target system T000'
* 'table with cccategory = P'
* INTO gt_etl_message-message SEPARATED BY space. * PERFORM add_message USING gt_etl_message-message abap_false. READ TABLE t000_itab INTO ls_target_system
WITH KEY cccategory = 'P'.
ENDIF.
ENDIF. IF NOT ls_target_system IS INITIAL.
PERFORM add_attribute_to_node USING iv_header_node
'TARGET_SYSTEM_TYPE' ls_target_system-cccategory.
ENDIF. ENDFORM. " ADD_SYSTEM_TYPES_TO_HEADER *---------------------------------------------------------------------*
* FORM GET_KERNEL_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> EV_KRELEASE *
* --> EV_KLEVEL *
*---------------------------------------------------------------------*
FORM get_kernel_data CHANGING ev_krelease
ev_klevel. TYPES: BEGIN OF t_kernel_version,
key(21) TYPE c,
data(69) TYPE c,
END OF t_kernel_version. DATA: lt_kernel_version TYPE TABLE OF t_kernel_version
WITH HEADER LINE,
ls_kernel_version TYPE t_kernel_version. CALL 'SAPCORE' ID 'ID' FIELD 'VERSION'
ID 'TABLE' FIELD lt_kernel_version-*sys*. READ TABLE lt_kernel_version INTO ls_kernel_version INDEX 12.
ev_krelease = ls_kernel_version-data.
READ TABLE lt_kernel_version INTO ls_kernel_version INDEX 15.
ev_klevel = ls_kernel_version-data. ENDFORM. "GET_KERNEL_DATA
*---------------------------------------------------------------------*
* FORM create_xml_node(创建XML 节点) *
*---------------------------------------------------------------------*
FORM create_xml_node USING
VALUE(pi_pdocument) TYPE REF TO if_ixml_document
VALUE(parent_element) TYPE REF TO if_ixml_element
VALUE(pi_xml_node) TYPE string
CHANGING VALUE(pc_elem) TYPE REF TO if_ixml_element. pc_elem = pi_pdocument->create_simple_element(
name = pi_xml_node
parent = parent_element ). ENDFORM. " create_xml_node *---------------------------------------------------------------------*
* FORM create_xml_node_value_cdata *
*---------------------------------------------------------------------*
FORM create_xml_node_value_cdata USING
VALUE(pi_pdocument) TYPE REF TO if_ixml_document
VALUE(parent_element) TYPE REF TO if_ixml_element
VALUE(pi_xml_node) TYPE string
VALUE(pi_value) TYPE any
VALUE(pi_with_cdata) TYPE c
CHANGING
VALUE(pc_elem) TYPE REF TO if_ixml_element. DATA: l_value TYPE string. IF pi_with_cdata = 'X'. DATA: rval TYPE REF TO if_ixml_cdata_section.
l_value = pi_value.
CALL METHOD pi_pdocument->create_cdata_section
EXPORTING
cdata = l_value
RECEIVING
rval = rval. pc_elem = pi_pdocument->create_simple_element(
name = pi_xml_node
* value = l_value
parent = parent_element ). CALL METHOD pc_elem->append_child
EXPORTING
new_child = rval. ELSE.
l_value = pi_value.
pc_elem = pi_pdocument->create_simple_element(
name = pi_xml_node
value = l_value
parent = parent_element ).
ENDIF. ENDFORM. " create_xml_node_value *---------------------------------------------------------------------*
* FORM close_xml_file *
*---------------------------------------------------------------------*
FORM close_xml_file. DATA: stream_size TYPE i,
msg_line1(70) TYPE c,
msg_line2(70) TYPE c,
msg_line3(70) TYPE c. PERFORM append_string_to_file USING '</ROOT_ELEMENT>'. * flush the buffered data to the file - last time
stream_size = g_ostream->get_num_written_raw( ).
PERFORM append_itab_to_file USING stream_size g_buffer_itab. * Write the file to original location
PERFORM move_file USING temp_fore_filename
temp_back_filename
p_fore
p_back
r_fore. * Display finish message
IF panaya_test_mode IS INITIAL.
msg_line1 = 'The data extraction was finished successfully.'.
IF no_usage = 'X'.
msg_line2 = 'Please note: No usage statistics were found.'.
msg_line3 = 'Contact Panaya support for assistance.'.
IF popup_ok = 'X'.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT_LO'
EXPORTING
titel = 'Panaya'
textline1 = msg_line1
textline2 = msg_line2
textline3 = msg_line3
start_column = 15
start_row = 6.
ELSE.
WRITE:/ msg_line1.
WRITE:/ msg_line2.
WRITE:/ msg_line3.
ENDIF.
ELSE.
IF popup_ok = 'X'. CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT_LO'
EXPORTING
titel = 'Panaya'
textline1 = msg_line1
start_column = 15
start_row = 6.
ELSE.
WRITE:/ msg_line1.
WRITE:/ msg_line2.
WRITE:/ msg_line3.
ENDIF. ENDIF.
ENDIF. ENDFORM. "close_xml_file *---------------------------------------------------------------------*
* FORM append_string_to_file *
*---------------------------------------------------------------------*
FORM append_string_to_file USING str TYPE string. CALL METHOD g_ostream->write_string
EXPORTING
string = new_line.
CALL METHOD g_ostream->write_string
EXPORTING
string = str.
CALL METHOD g_ostream->write_string
EXPORTING
string = new_line. ENDFORM. "append_string_to_file *---------------------------------------------------------------------*
* FORM append_itab_to_file *
*---------------------------------------------------------------------*
FORM append_itab_to_file USING i_stream_size TYPE i
i_tab_converted_data TYPE xml_tab_type. DATA: l_oref TYPE REF TO cx_root,
text TYPE string.
DATA: l_file TYPE string.
DATA: ls_file TYPE xml_line_type.
DATA: l_remaining_size TYPE i.
DATA: l_recsize TYPE i. IF NOT r_fore IS INITIAL.
l_file = temp_fore_filename.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = i_stream_size
filename = l_file
filetype = 'BIN'
append = g_file_append_mode
CHANGING
data_tab = i_tab_converted_data
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24. IF sy-subrc <> 0.
DATA: explan TYPE string.
IF sy-subrc = 17.
explan = 'Disk is full'.
ELSE.
explan = sy-subrc.
ENDIF.
MESSAGE e000(conv) WITH 'Problem writing to file: ' explan.
ENDIF.
ENDIF. * Server file
IF NOT r_back IS INITIAL.
* Open file
IF g_file_append_mode IS INITIAL.
OPEN DATASET temp_back_filename FOR OUTPUT IN BINARY MODE.
ELSE.
OPEN DATASET temp_back_filename FOR APPENDING IN BINARY MODE.
ENDIF.
* Write file
l_remaining_size = i_stream_size.
LOOP AT i_tab_converted_data INTO ls_file.
IF l_remaining_size < 256.
l_recsize = l_remaining_size.
ELSE.
l_recsize = 256.
ENDIF. TRANSFER ls_file TO temp_back_filename LENGTH l_recsize.
SUBTRACT l_recsize FROM l_remaining_size.
ENDLOOP.
* Close file
CLOSE DATASET temp_back_filename .
IF sy-subrc IS INITIAL.
* MESSAGE s171(26) WITH p_back.
* File & created
ELSE.
* MESSAGE e005(ps).
* Cannot close output file
ENDIF.
ENDIF. * The first time we write the file in overwrite mode, then we switch
* to append mode
IF g_file_append_mode IS INITIAL.
g_file_append_mode = 'X'.
ENDIF. ENDFORM. "append_itab_to_file *&---------------------------------------------------------------------*
*& Form MOVE_FILE
*&---------------------------------------------------------------------*
* Move file from initial location to the location specified by
* user
*----------------------------------------------------------------------*
FORM move_file USING p_temp_fore_file
p_temp_back_file
p_orig_fore_file
p_orig_back_file
p_is_fore. DATA: explan TYPE string,
error_msg TYPE string,
curr_line_len TYPE i,
data(256) TYPE c,
filename1 TYPE string,
filename2 TYPE string.
DATA: l_oref TYPE REF TO cx_root,
text TYPE string,
text_len TYPE i,
param1(50) TYPE c,
param2(50) TYPE c,
param3(50) TYPE c,
param4(50) TYPE c. IF NOT p_is_fore IS INITIAL. * Copy the file to original location
filename1 = p_temp_fore_file.
filename2 = p_orig_fore_file.
CALL METHOD cl_gui_frontend_services=>file_copy
EXPORTING
source = filename1
destination = filename2
overwrite = 'X'
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
disk_full = 4
access_denied = 5
file_not_found = 6
destination_exists = 7
unknown_error = 8
path_not_found = 9
disk_write_protect = 10
drive_not_ready = 11
OTHERS = 12. IF sy-subrc <> 0.
IF sy-subrc = 4.
explan = 'Disk is full'.
ELSE.
explan = sy-subrc.
ENDIF.
MESSAGE e001(00) WITH 'Problem writing to file: '
p_orig_fore_file
explan.
ENDIF. * Delete the temporary file
* DATA: rc TYPE i.
* CALL METHOD cl_gui_frontend_services=>file_delete
* EXPORTING
* filename = p_temp_fore_file
* CHANGING
* rc = rc
* EXCEPTIONS
* file_delete_failed = 1
* cntl_error = 2
* error_no_gui = 3
* file_not_found = 4
* access_denied = 5
* unknown_error = 6
* OTHERS = 7.
* IF sy-subrc <> 0.
* explan = sy-subrc.
* MESSAGE e001(00) WITH 'Problem deleting file: ' p_temp_fore_file
* ' return code (RC) = ' rc.
* ENDIF. ELSE.
* Open the temp file
OPEN DATASET p_temp_back_file FOR INPUT IN BINARY
MODE MESSAGE error_msg. OPEN DATASET p_orig_back_file FOR OUTPUT IN BINARY MODE
MESSAGE error_msg. * Transfer the data to destination file
DO.
READ DATASET p_temp_back_file INTO data LENGTH curr_line_len.
IF sy-subrc <> 0.
TRANSFER data TO p_orig_back_file
LENGTH curr_line_len.
EXIT.
ENDIF.
TRANSFER data TO p_orig_back_file LENGTH curr_line_len.
ENDDO. * Close both files
CLOSE DATASET p_temp_back_file.
CLOSE DATASET p_orig_back_file. * Delete the file from current directory
DELETE DATASET p_temp_back_file. IF sy-subrc <> 0.
MESSAGE e001(00) WITH 'Problem deleting file: ' p_temp_back_file
' SUBC: ' sy-subrc.
EXIT.
ENDIF.
ENDIF.
ENDFORM. " MOVE_FILE *---------------------------------------------------------------------*
* FORM append_xml_element_to_file *
*---------------------------------------------------------------------*
FORM append_xml_element_to_file USING i_element TYPE REF TO if_ixml_element
i_remove_node TYPE c. DATA: stream_size TYPE i. stream_size = g_ostream->get_num_written_raw( ). IF ( stream_size > buffer_max_size ).
PERFORM append_itab_to_file USING stream_size g_buffer_itab.
g_ostream = g_iref_pstreamfactory->create_ostream_itable(
table = g_buffer_itab ).
CALL METHOD g_ostream->set_pretty_print
EXPORTING
pretty_print = 'X'.
CLEAR g_buffer_itab.
ENDIF. CALL METHOD g_ostream->write_string
EXPORTING
string = new_line.
CALL METHOD i_element->render( ostream = g_ostream ). IF i_remove_node = 'X'.
CALL METHOD i_element->remove_node.
CLEAR i_element.
ENDIF. ENDFORM. "append_xml_element_to_file *---------------------------------------------------------------------*
* FORM open_xml_file *
*---------------------------------------------------------------------*
FORM open_xml_file. DATA: header_string TYPE string. * Initialize stream factory
g_iref_pstreamfactory = g_iref_pixml->create_stream_factory( ).
g_ostream = g_iref_pstreamfactory->create_ostream_itable(
table = g_buffer_itab ).
CALL METHOD g_ostream->set_pretty_print
EXPORTING
pretty_print = 'X'. CONCATENATE '<?xml version="1.0" encoding="' encoding '"?>'
INTO header_string. CALL METHOD g_ostream->write_string
EXPORTING
string = header_string.
PERFORM append_string_to_file USING '<ROOT_ELEMENT>'. ENDFORM. "open_xml_file *&---------------------------------------------------------------------*
*& Form add_used_memory_to_log
*&---------------------------------------------------------------------*
FORM add_used_memory_to_log. DATA: mem_size TYPE abap_msize,
mem(25) TYPE c,
mem_text(50) TYPE c. IF sy-batch = 'X'.
* Used memory log message
CALL METHOD cl_abap_memory_utilities=>get_total_used_size
IMPORTING
size = mem_size.
mem = mem_size.
CONCATENATE 'Used memory:' mem INTO mem_text SEPARATED BY space.
* MESSAGE s000(conv) WITH mem_text.
* PERFORM add_message USING mem_text abap_true.
ENDIF. ENDFORM. " add_used_memory_to_log *---------------------------------------------------------------------*
* FORM update_progress *
*---------------------------------------------------------------------*
FORM update_progress USING text. DATA: batch_text(50) TYPE c,
curr_step(2) TYPE c,
total_steps(2) TYPE c,
steps_text(50) TYPE c,
progress_text(512) TYPE c. curr_object_type = curr_object_type + 1.
percentage = percentage + obj_perc.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = percentage
text = text. IF sy-batch = 'X'.
curr_step = curr_object_type.
total_steps = num_object_types.
CONCATENATE '(' curr_step '/' total_steps ')' INTO steps_text.
CONCATENATE text steps_text INTO progress_text SEPARATED BY space.
* PERFORM ADD_MESSAGE USING PROGRESS_TEXT ABAP_TRUE. PERFORM add_used_memory_to_log.
ENDIF. ENDFORM. "update_progress
SAP创建XML 文件的更多相关文章
- .net中创建xml文件的两种方法
.net中创建xml文件的两种方法 方法1:根据xml结构一步一步构建xml文档,保存文件(动态方式) 方法2:直接加载xml结构,保存文件(固定方式) 方法1:动态创建xml文档 根据传递的值,构建 ...
- C#操作XML学习之创建XML文件的同时新建根节点和子节点(多级子节点)
最近工作中遇到一个问题,要求创建一个XML文件,在创建的时候要初始化该XML文档,同时该文档打开后是XML形式,但是后缀名不是.在网上找了好些资料没找到,只能自己试着弄了一下,没想到成功了,把它记下来 ...
- Java 创建xml文件和操作xml数据
java中的代码 import java.io.File; import java.io.StringWriter; import javax.xml.parsers.DocumentBuilder; ...
- TinyXML2读取和创建XML文件 分类: C/C++ 2015-03-14 13:29 94人阅读 评论(0) 收藏
TinyXML2是simple.small.efficient C++ XML文件解析库!方便易于使用,是对TinyXML的升级改写!源码见本人上传到CSDN的TinyXML2.rar资源:http: ...
- XML文件操作类--创建XML文件
这个类是在微软XML操作类库上进行的封装,只是为了更加简单使用,包括XML类创建节点的示例. using System; using System.Collections; using System. ...
- asp.net创建XML文件方法
方法一:按照XML的结构一步一步的构建XML文档. 通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法一:按照XML的结 ...
- C#创建XML文件并保存
随着XML的普及以及在动态WEB应用程序中大量应用,如何通过.NET创建,删除,修改XML文件变的也来也重要了.一个简单的概念是,XML文件跟大的文本文件并没有什么区别,同时它是先于.NET出现,很多 ...
- Dom4j解析Xml文件,Dom4j创建Xml文件
Dom4j解析Xml文件,Dom4j创建Xml文件 >>>>>>>>>>>>>>>>>>&g ...
- 创建XML文件
//创建XML文件 XmlDocument xmldoc = new XmlDocument(); XmlText xmltext; ...
随机推荐
- (2020行人再识别综述)Person Re-Identification using Deep Learning Networks: A Systematic Review
目录 1.引言 2.研究方法 2.1本次综述的贡献 2.2综述方法 2.3与现有综述的比较 3.行人再识别基准数据集 3.1基于图像的再识别数据集 3.2基于视频的再识别数据集 4.基于图像的深度再识 ...
- PostgreSQL 锁 之 关系级锁
1.关于锁的基本信息 PostgreSQL 有各种各样的技术来锁定某些东西(或者至少是这样称呼的).因此,我将首先用最笼统的术语解释为什么需要锁,可用的锁类型以及它们之间的区别.然后我们将弄清楚 Po ...
- springmvc04-数据处理
数据处理 我们把它分为三种情况来分析,这样我们对于数据处理会有更好的理解 1.提交的域名称和处理方法的参数名一致 提交数据 : http://localhost:8080/hello?name=xi ...
- macOS 安装 Nebula Graph 看这篇就够了
本文首发于 Nebula Graph Community 公众号 背景 刚学习图数据的内容,当前网上充斥大量的安装文档,参差不齐,部署起来令人十分头疼. 现整理一份比较完整的安装文档,供大家学习参考, ...
- 【学习笔记】CDQ分治(等待填坑)
因为我对CDQ分治理解不深,所以这篇博客只是我现在的浅显理解有任何不对的,希望大佬指出. 首先就是CDQ分治适用的题型: (1)带修改,但修改互相独立 (2)必须允许离线 (3)解决数据结构的题,能把 ...
- navicat软件、 python操作MySQL
查询关键字之having过滤 having与where的功能是一模一样的 都是对数据进行筛选 where用在分组之前的筛选 havng用在分组之后的筛选 为了更好的区分 所以将where说成筛选 ha ...
- windows 文件hash校验,字符串加密,base64转换工具
对下载的文件使用hash校验验证文件完整性 1 import hashlib 2 def md5(): 3 md5_value = hashlib.md5() 4 with open('C:\Inte ...
- OpenStack 安装 Keystone
OpenStack 安装 Keystone 本篇主要记录一下 如何安装 openstack的 第一个组件 keystone 认证授权组件 openstack 版本 我选的是queens 版本 1.Op ...
- 软件项目管理 ——1.2.PMBOK与软件项目管理知识体系
软件项目管理 --1.2.PMBOK与软件项目管理知识体系 归档于软件项目管理初级学习路线 第一章 软件项目管理基本概念 <初级学习路线合集 > @ 目录 软件项目管理 --1.2.PMB ...
- 行为参数化与lambda表达式 - 读《Java 8实战》
零. 概述 第一部分:1~3章 主要讲了行为参数化和Lambda表达式 第二部分:4~7章 主要讲了流的应用,包括流与集合差异,流的操作,收集器,注的并行执行 第三部分:8~12章 主要讲了怎样用Ja ...