CONCATENATE 'XSLT' ls_xsltattr-xsltdesc INTO ls_xsltattr-xsltdesc.
CONCATENATE 'Z' ls_xsltattr-xsltdesc INTO ls_xsltattr-xsltdesc.
* Delete the transformation since it is not needed any more.
CALL FUNCTION 'XSLT_MAINTENANCE'
EXPORTING
i_operation = 'DELETE' "#EC NOTEXT
i_xslt_attributes = ls_xsltattr
i_gen_flag = abap_true
i_suppress_corr_insert = abap_true
i_suppress_tree_placement = abap_true
EXCEPTIONS
OTHERS = 1.
<?xml version="1.0" encoding="utf-8"?>
<data xmlns="http://www.sap.com/SAPForm/0.5">
<TABLE>
<DATA>
<NAME>%NAME%</NAME>
<LAST_NAME>%LAST_NAME%</LAST_NAME>
<DATE>%DATE%</DATE>
</DATA>
</TABLE>
</data>
*&---------------------------------------------------------------------*
*& Report ZCUSTOMXML_SAP
*&
*&---------------------------------------------------------------------*
*& Report demonstrates creation of custom xml file, then reading
*& document and using generated XSLT tramsformation to merge these files
*& Pavol Olejar 23.4.2017
*&---------------------------------------------------------------------*
REPORT zcustomxml_sap.
TYPES: BEGIN OF t_table,
name TYPE string,
last_name TYPE string,
birth_date TYPE string,
END OF t_table.
DATA: lt_table TYPE TABLE OF t_table,
ls_table TYPE t_table,
lv_length TYPE i,
lt_data_tab TYPE STANDARD TABLE OF x255,
lv_docx TYPE xstring,
lr_docx TYPE REF TO cl_docx_document,
lr_main TYPE REF TO cl_docx_maindocumentpart,
lr_custom TYPE REF TO cl_oxml_customxmlpart,
lv_table_string TYPE string,
lv_custom_xml TYPE xstring.
* 1ST PART - PREPARE DATA FOR MAPPING
ls_table-name = 'James'.
ls_table-last_name = 'Bond'.
ls_table-birth_date = '13.04.1968'.
APPEND ls_table TO lt_table.
ls_table-name = 'Pavol'.
ls_table-last_name = 'Olejar'.
ls_table-birth_date = '27.01.1985'.
APPEND ls_table TO lt_table.
LOOP AT lt_table INTO ls_table.
CONCATENATE lv_table_string
'<DATA>'
'<NAME>' ls_table-name '</NAME>'
'<LAST_NAME>' ls_table-last_name '</LAST_NAME>'
'<DATE>' ls_table-birth_date '</DATE>'
'</DATA>'
INTO lv_table_string.
ENDLOOP.
CONCATENATE '<?xml version="1.0" encoding="utf-8"?>'
'<data xmlns="http://www.sap.com/SAPForm/0.5">'
'<TABLE>'
lv_table_string
'</TABLE>'
'</data>'
INTO DATA(lv_custom).
* 2ND STEP - CREATE CUSTOM XML
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_custom
IMPORTING
buffer = lv_custom_xml.
* 3RD STEP - READ WORD DOCUMENT
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = 'C:\Table.docx'
filetype = 'BIN'
IMPORTING
filelength = lv_length
CHANGING
data_tab = lt_data_tab.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_length
IMPORTING
buffer = lv_docx
TABLES
binary_tab = lt_data_tab.
CALL METHOD cl_docx_document=>load_document
EXPORTING
iv_data = lv_docx
RECEIVING
rr_doc = lr_docx.
CHECK lr_docx IS BOUND.
lv_docx = lr_docx->get_package_data( ).
* 4TH STEP - MERGE CUSTOM XML FILE AND DOC
TRY.
CALL METHOD zcl_docx_form=>merge_data
EXPORTING
im_formtemplate_data = lv_docx
im_customxml_data = lv_custom_xml
im_delete_sdt_tags = 'Y'
RECEIVING
re_merged_data = lv_docx.
CATCH cx_root.
ENDTRY.
* 5TH STEp - SAVE RESULT
lv_length = xstrlen( lv_docx ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_docx
TABLES
binary_tab = lt_data_tab.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = lv_length
filename = 'C:\Table.docx'
filetype = 'BIN'
confirm_overwrite = 'X'
CHANGING
data_tab = lt_data_tab.
<a:extLst>
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
<a14:useLocalDpi
xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/>
</a:ext>
</a:extLst>
FROM
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
TO
<a:ext uri="{{28A0092B-C50C-407E-A947-70E740481C1C}}">
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |