博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Transformation XML(TCODE-STRANS)
阅读量:2034 次
发布时间:2019-04-28

本文共 3843 字,大约阅读时间需要 12 分钟。

一个简单小例子,将excel模板用STRANS生成XML格式,abap调用使用。

步骤如下:

我的数据源

 e59bbee5838f-8

相应的excel模板为:

 e59bbee5838f-1

将excel模板另存为XML文档,记事本打开,查看。

用t-code STRANS生成XML:

 e59bbee5838f-3

e59bbee5838f-4

 

将excel模板生成的xml文档上传,其实我自己通常是保存一个模板,只要修改一下红色代码的地方,改为你sap数据的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>

接下来程序调用:

程序界面,获得文件路径:

 e59bbee5838f-5

最后结果如下:

 e59bbee5838f-6

调用的程序代码如下:

*&———————————————————————*

*& 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.

转载地址:http://uyhaf.baihongyu.com/

你可能感兴趣的文章
RocketMQ初步应用架构理论(主从切换/异/同步刷盘)
查看>>
eclipse 修改 项目的git地址
查看>>
Spring gateway使用一个lambda例子的说明
查看>>
Bug: Return value of putIfAbsent is ignored, but list is reused
查看>>
理解WEB API网关
查看>>
maven-jar-plugin 排除不想打包的目录文件内容
查看>>
feign.FeignException: status 404 reading xxService#xxmethod(Integer)
查看>>
唯品会后端架构部分内容分享(一) ( 20180613 by flyer)
查看>>
Spring Cloud Zuul实现动态路由
查看>>
zuul动态路由支持的路径格式及扩展性测试
查看>>
linux服务器校对时间方法
查看>>
rocketMQ 消息查询(id,key) 运维命令以及java API的用法
查看>>
RocketMQ学习(五):Pull和Push (important)
查看>>
Linux下查看系统启动时间和运行时间
查看>>
数据处理过慢的问题分析(涉及插入查询)
查看>>
JVM线程状态,park, wait, sleep, interrupt, yeild 对比
查看>>
java.lang.Thread.State:WAITING(parking)
查看>>
Dubbo 和 Spring Cloud 微服务架构到底孰优孰劣?
查看>>
swagger默认访问地址
查看>>
redis-desktop-manager 的简单使用
查看>>