Transformation XML(TCODE-STRANS)

news/2024/7/16 6:23:23

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

一个简单小例子,将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.

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

http://www.niftyadmin.cn/n/3653916.html

相关文章

基于NetBeans的Java EE客户端应用程序(一)

文档当前处于草稿状态本教程将展示如何在 NetBeans 平台上方便地创建应用程序客户端。将以 Database Reader 为例进行演示说明。 目录l 要求 l 安装和配置l 项目创建 l 企业应用程序开发 l 修改构建脚本l 从数据库生成实体类 l …

几种内表更新方式的性能比较

分享一下我老师大神的人工智能教程&#xff01;零基础&#xff0c;通俗易懂&#xff01;http://blog.csdn.net/jiangjunshow也欢迎大家转载本篇文章。分享知识&#xff0c;造福人民&#xff0c;实现我们中华民族伟大复兴&#xff01;ABAP程序中&#xff0c;内表更新主要有以下程…

基于NetBeans的Java EE客户端应用程序(二)

创建会话 Bean我们需要创建无状态的会话 bean&#xff0c;它带有与持久单元进行通信的远程接口。创建一个这样的会话 bean&#xff0c;并将其命名为 DataBean。 向所创建的会话 bean 添加名为 getData 的业务方法。可以通过右键单击 editor 窗体&#xff08;在已打开的 DataBea…

记Redis那坑人的HGETALL

分享一下我老师大神的人工智能教程&#xff01;零基础&#xff0c;通俗易懂&#xff01;http://blog.csdn.net/jiangjunshow也欢迎大家转载本篇文章。分享知识&#xff0c;造福人民&#xff0c;实现我们中华民族伟大复兴&#xff01;世上本没有坑&#xff0c;摔的人多了&#x…

将NetBeans Profiler集成到Sun Java System Web Server 7.0

尽管分析简单的应用程序通常是一项简单的任务&#xff0c;但将分析器设置为在 Web 服务器或应用服务器上运行需要一些额外的步骤。然而&#xff0c;在 NetBeans IDE 中配置 Profiler&#xff08;以下称为 NetBeans Profiler&#xff09;通常一次即可轻松完成。NetBeans Profile…

ABAP从数据库中删除行

分享一下我老师大神的人工智能教程&#xff01;零基础&#xff0c;通俗易懂&#xff01;http://blog.csdn.net/jiangjunshow也欢迎大家转载本篇文章。分享知识&#xff0c;造福人民&#xff0c;实现我们中华民族伟大复兴&#xff01;删除单行&#xff1a;DELETE <dbtab> …

使用NetBeans将GUI连接到Derby数据库

本教程指导您如何将名为 ContactEditor 的应用程序的 GUI 连接到 Derby 数据库。在此过程中&#xff0c;您将向 GUI 添加数据敏感的 JDBC 组件&#xff0c;使该程序能够与雇员数据库交互。在本教程中&#xff0c;您将学会如何&#xff1a;l 使用 GUI Builder 界面 l …

SAP批量修改物料标准成本

分享一下我老师大神的人工智能教程&#xff01;零基础&#xff0c;通俗易懂&#xff01;http://blog.csdn.net/jiangjunshow也欢迎大家转载本篇文章。分享知识&#xff0c;造福人民&#xff0c;实现我们中华民族伟大复兴&#xff01;批量修改物料标准成本&#xff0c;其步骤也分…