Transformation XML(TCODE-STRANS)
一個(gè)簡(jiǎn)單小例子,將excel模板用STRANS生成XML格式,abap調(diào)用使用。
步驟如下:
我的數(shù)據(jù)源
?
相應(yīng)的excel模板為:
?
將excel模板另存為XML文檔,記事本打開,查看。
用t-code STRANS生成XML:
?
?
將excel模板生成的xml文檔上傳,其實(shí)我自己通常是保存一個(gè)模板,只要修改一下紅色代碼的地方,改為你sap數(shù)據(jù)的element,如下:
<?sap.transform simple?>
<?mso-application progid=”Excel.Sheet”?>
<tt:transform xmlns:tt=”http://www.sap.com/transformation-templates”>
<tt:root name=”table”/>
<tt:template>?
<Workbook xmlns=”urn:schemas-microsoft-com:office:spreadsheet”
?xmlns:o=”urn:schemas-microsoft-com:office:office”
?xmlns:x=”urn:schemas-microsoft-com:office:excel”
?xmlns:ss=”urn:schemas-microsoft-com:office:spreadsheet”
?xmlns:html=”http://www.w3.org/TR/REC-html40″>
?<ExcelWorkbook xmlns=”urn:schemas-microsoft-com:office:excel”>
?</ExcelWorkbook>
?<Styles>
? <Style ss:ID=”Default” ss:Name=”Normal”>
?? <Alignment ss:Vertical=”Bottom”/>
?? <Borders/>
?? <Font ss:FontName=”Arial” x:Family=”Swiss”/>
?? <Interior/>
?? <NumberFormat/>
?? <Protection/>
? </Style>
? <Style ss:ID=”s62″>
?? <Alignment ss:Horizontal=”Left” ss:Vertical=”Bottom”/>
? </Style>
? <Style ss:ID=”s63″>
?? <Borders>
??? <Border ss:Position=”Bottom” ss:LineStyle=”Continuous” ss:Weight=”1″/>
??? <Border ss:Position=”Left” ss:LineStyle=”Continuous” ss:Weight=”1″/>
??? <Border ss:Position=”Right” ss:LineStyle=”Continuous” ss:Weight=”1″/>
??? <Border ss:Position=”Top” ss:LineStyle=”Continuous” ss:Weight=”1″/>
?? </Borders>
?? <Interior ss:Color=”#00CCFF” ss:Pattern=”Solid”/>
? </Style>
?</Styles>
????? <Worksheet ss:Name=”Sheet1″>
??????? <Table? x:FullColumns=”1″ x:FullRows=”1″>
????????? <tt:loop ref=”.table”>
??????????? <Row>
??????????? ???????? <Cell><Data ss:Type=”String”><tt:value ref=”STUID”/></Data></Cell>
????????????? <Cell><Data ss:Type=”String”><tt:value ref=”STUNM”/></Data></Cell>
????????????? <Cell><Data ss:Type=”String”><tt:value ref=”STUSX”/></Data></Cell>
????????????? <Cell><Data ss:Type=”String”><tt:value ref=”STUTP”/></Data></Cell>
????????????? <Cell><Data ss:Type=”String”><tt:value ref=”STUAD”/></Data></Cell>
??????????? </Row>
????????? </tt:loop>
??????? </Table>
????? </Worksheet>
??? </Workbook>
? </tt:template>
</tt:transform>
接下來(lái)程序調(diào)用:
程序界面,獲得文件路徑:
?
最后結(jié)果如下:
?
調(diào)用的程序代碼如下:
*&———————————————————————*
*&?Report??YY_ELCT
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT??YY_ELCT.
types:begin?of?ty_out,
??????stuid?type?string,
??????stunm?type?string,
??????stusx?type?string,
??????stutp?type?string,
??????stuad?type?string,
?????end?of?ty_out.
data:gt_out?type?table?of?ty_out,
?????gw_out?type?ty_out.
data:gt_student?type?table?of?yyt_student,
?????gw_student?type?yyt_student.
data:g_xmlstr?type?string,
?????gt_xml?type?standard?table?of?string,
?????gw_xml?like?line?of?gt_xml.
data?g_filename?type?string.
selection-screen?begin?of?block?blk1?with?frame?title?text-001.
parameters:?p_down??like?rlgrap-filename?default?‘D:\’.
selection-screen?end?of?block?blk1.
initialization.
*&———————————————————————*
*?AT?SELECTION-SCREEN
*&———————————————————————*
at?selection-screen?on?value-request?for?p_down.
??call?function?‘WS_FILENAME_GET’
????exporting
??????def_path?????????=?p_down
??????title????????????=?‘Choose?your?file’(120)
??????mode?????????????=?‘S’
????importing
??????filename?????????=?p_down
????exceptions
??????inv_winsys???????=?1
??????no_batch?????????=?2
??????selection_cancel?=?3
??????selection_error??=?4
??????others???????????=?5.
??check?sy-subrc?=?0?and?not?p_down?is?initial.
start-of-selection.
“get?data
select?*?into?table?gt_student
??from?yyt_student.
“down?file
clear?gw_out.
gw_out-stuid?=?‘Student?Id’.
gw_out-stunm?=?‘Student?Name’.
gw_out-stusx?=?‘Student?Sex’.
gw_out-stutp?=?‘Student?Telphone’.
gw_out-stuad?=?‘Student?Address’.
append?gw_out?to?gt_out.
clear?gw_out.
loop?at?gt_student?into?gw_student.
??move-corresponding?gw_student?to?gw_out.
??append?gw_out?to?gt_out.
??clear?gw_out.
endloop.
call?transformation?ystu_excel
??source?table?=?gt_out
??result?xml?g_xmlstr.
replace?first?occurrence?of?‘encoding=”utf-16″‘?in?g_xmlstr?with?‘encoding=”gbk”‘.
append?g_xmlstr?to?gt_xml.
g_filename?=?p_down.
call?function?‘GUI_DOWNLOAD’
??exporting
????filename?=?g_filename
????codepage?=?‘8400′
????filetype?=?‘ASC’
??tables
????data_tab?=?gt_xml.
if?sy-subrc?eq?0.
???message?‘Success’?type?‘S’.
else.
???message?‘Download?file?fail’?type?‘I’.
endif.
總結(jié)
以上是生活随笔為你收集整理的Transformation XML(TCODE-STRANS)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: smartform 打印预览时转PDF查
- 下一篇: sap abap好用的函数