首页 > 其他分享 >ABAP STRANS转换XML到EXCLE

ABAP STRANS转换XML到EXCLE

时间:2023-07-27 11:25:11浏览次数:40  
标签:XML count STRANS data lv ABAP path filename TYPE

*&---------------------------------------------------------------------*
*& Report ZTEST00001
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest00001.

"使用xml的下载方式
DATA: lv_path TYPE rlgrap-filename.
DATA: lt_xml_table TYPE STANDARD TABLE OF string,
      lv_xmlstr    TYPE string.
DATA: lv_count TYPE n LENGTH 10.
FIELD-SYMBOLS: <fs_value> TYPE any.
"弹出窗口选择保存路径
PERFORM frm_save_path CHANGING lv_path.
TYPES:BEGIN OF ty_data,

        psttr TYPE  string,

      END OF ty_data.

DATA:gt_data    TYPE TABLE OF ty_data,

     gs_alv_out TYPE ty_data.
DO 1000000 TIMES.
  gs_alv_out-psttr = 'SFDFSFS'.
  APPEND gs_alv_out TO gt_data.
ENDDO.

********关键代码部分*****************************************
DESCRIBE TABLE gt_data LINES lv_count.
lv_count = lv_count + 3.

CALL TRANSFORMATION zfir045_1
SOURCE root = gt_data[]
RESULT XML lv_xmlstr.

REPLACE FIRST OCCURRENCE OF 'encoding="utf-16"' IN lv_xmlstr WITH 'encoding="gbk"'."显示中文
REPLACE FIRST OCCURRENCE OF 'cs_count' IN lv_xmlstr WITH lv_count."行数,替代xml文件里的cs_count
APPEND lv_xmlstr TO lt_xml_table.

********关键代码部分*****************************************

DATA: lv_file TYPE string.
lv_file = lv_path.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename                = lv_file
    filetype                = 'ASC'
  TABLES
    data_tab                = lt_xml_table
  EXCEPTIONS
    file_write_error        = 1
    no_batch                = 2
    gui_refuse_filetransfer = 3
    invalid_type            = 4
    OTHERS                  = 5.

MESSAGE '数据下载成功!' TYPE 'S'.

FORM frm_save_path CHANGING pv_path TYPE rlgrap-filename.
  DATA:lv_filename TYPE string,
       lv_path     TYPE string.
  "名字指定
  CONCATENATE '进耗存报表_明细_' sy-datum '.XLS' INTO lv_filename.

  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      def_filename     = lv_filename
      def_path         = 'D:W'
      mask             = '.XLS'
      mode             = 'S'
      title            = 'DOWNLOAD'
    IMPORTING
      filename         = pv_path
*     RC               =
    EXCEPTIONS
      inv_winsys       = 1
      no_batch         = 2
      selection_cancel = 3
      selection_error  = 4
      OTHERS           = 5.
  IF pv_path IS INITIAL.   "选择取消的情况
    MESSAGE e000(su) WITH '已取消操作!'.
  ENDIF.
ENDFORM.

 

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">

  <tt:root name="ROOT"/>

  <tt:template>
    <?mso-application progid="Excel.Sheet"?>
    <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">
      <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
        <Author>马宇</Author>
        <LastAuthor>马宇</LastAuthor>
        <Created>2019-07-29T09:17:10Z</Created>
        <LastSaved>2019-07-29T09:41:41Z</LastSaved>
        <Version>16.00</Version>
      </DocumentProperties>
      <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
        <AllowPNG/>
      </OfficeDocumentSettings>
      <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
        <WindowHeight>7500</WindowHeight>
        <WindowWidth>20490</WindowWidth>
        <WindowTopX>32767</WindowTopX>
        <WindowTopY>32767</WindowTopY>
        <ProtectStructure>False</ProtectStructure>
        <ProtectWindows>False</ProtectWindows>
      </ExcelWorkbook>
      <Styles>
        <Style ss:ID="Default" ss:Name="Normal">
          <Alignment ss:Vertical="Center"/>
          <Borders/>
          <Font ss:Color="#000000" ss:FontName="等线" ss:Size="11" x:CharSet="134"/>
          <Interior/>
          <NumberFormat/>
          <Protection/>
        </Style>
        <Style ss:ID="s62">
          <Alignment ss:Vertical="Top"/>
        </Style>
        <Style ss:ID="s63">
          <Alignment ss:Vertical="Top"/>
          <NumberFormat ss:Format="@"/>
        </Style>
        <Style ss:ID="s64">
          <Alignment ss:Horizontal="Right" ss:Vertical="Top"/>
          <NumberFormat ss:Format="#,##0.000"/>
        </Style>
        <Style ss:ID="s65">
          <Alignment ss:Horizontal="Right" ss:Vertical="Top"/>
          <NumberFormat ss:Format="[$-F400]h:mm:ss\ AM/PM"/>
        </Style>
        <Style ss:ID="s66">
          <Alignment ss:Horizontal="Right" ss:Vertical="Top"/>
          <NumberFormat ss:Format="Short Date"/>
        </Style>
        <Style ss:ID="s67">
          <Alignment ss:Vertical="Top"/>
          <Borders>
            <Border ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Right" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="1"/>
          </Borders>
          <Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/>
        </Style>
      </Styles>
      <Worksheet ss:Name="Sheet1">
        <Table ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25" ss:ExpandedColumnCount="29" ss:ExpandedRowCount="cs_count" x:FullColumns="1" x:FullRows="1">
          <Row>
            <Cell ss:StyleID="s67">
              <Data ss:Type="String">计划日期</Data>
            </Cell>
          </Row>
          <tt:loop ref=".ROOT">
            <Row>
              <Cell ss:StyleID="s66">
                <Data ss:Type="String">
                  <tt:value ref="PSTTR"/>
                </Data>
              </Cell>
            </Row>
          </tt:loop>
        </Table>
        <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
          <PageSetup>
            <Header x:Margin="0.3"/>
            <Footer x:Margin="0.3"/>
            <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
          </PageSetup>
          <Selected/>
          <Panes>
            <Pane>
              <Number>3</Number>
              <ActiveRow>4</ActiveRow>
              <ActiveCol>1</ActiveCol>
            </Pane>
          </Panes>
          <ProtectObjects>False</ProtectObjects>
          <ProtectScenarios>False</ProtectScenarios>
        </WorksheetOptions>
      </Worksheet>
    </Workbook>
  </tt:template>
</tt:transform>

 

标签:XML,count,STRANS,data,lv,ABAP,path,filename,TYPE
From: https://www.cnblogs.com/ZJY-1314/p/17584434.html

相关文章

  • Python win11 安装lxml 失败
    如果你有一个项目执行了requirements后,一直提示lxml失败,解决步骤如下1、尝试升级pippython.exe-mpipinstall--upgradepip2、尝试下载包手动安装下载网址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml选择:lxml‑4.9.0‑cp311‑cp311‑win_amd64.whl3、python第三方......
  • PHP 中优雅的将JSON/XML/YAML 等数据反序列化成指定的类对象
    这个小事情何以需要记上一笔?实在是因为当用了各种编程语言以后,发现系统I/O处,尤其对外的接口Interface最重要,它或许可以被称为Specification,规约。PHP是混合型编程风格的语言,不强求完全的OOP。但是代码不OOP化的话,又得不到更多的开发工具的支持。尤其在PHP中如果只是用数组结......
  • xml声明式事务控制
    1、applicationContext.xml配置<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:contex......
  • Android开发笔记[2]-传统XML方式界面布局
    摘要使用传统的XML方式对Androidapp界面进行布局.平台信息AndroidStudio:ElectricEel|2022.1.1Patch2Gradle:distributionUrl=https://services.gradle.org/distributions/gradle-7.5-bin.zipjvmTarget='1.8'minSdk24targetSdk34compileSdk34开发语言:Kotl......
  • Converting between XML and JSON
    1ConvertionbetweenXMLandJSONhttp://www.json.org/java/index.html  API:http://www.json.org/javadoc/org/json/XML.htmlpublicclassXMLextendsjava.lang.Object ThisprovidesstaticmethodstoconvertanXMLtextintoaJSONObject,andt......
  • android packages.xml 与pms启动
    实现"androidpackages.xml与pms启动"的步骤为了实现"androidpackages.xml与pms启动",我们需要按照以下步骤进行操作:步骤操作步骤1获取PackageManagerService(PMS)实例步骤2加载packages.xml文件步骤3初始化PackageManagerService(PMS)实例步骤4启动P......
  • 转!XML文件和DOM Document、String字符串三种类型之间的相互转换
    转自:https://www.cnblogs.com/fightingdeng1998/p/16047075.html用的包是org.w3c.dom.Document下的/***@Authordengzp*@Date2022/3/22*@Version1.0*@Description*/publicclassOperateXMLByDOM{/***将给定文件的内容或者给定URI的内容解析......
  • SAP ABAP 系统里和传输请求读写相关的 Function Module
    在SAPABAP系统中,有一系列的函数模块以TRINT开头,被用来与TransportRequest交互。这里的"TRINT"并不是一个标准的缩写,它主要被用来表明这个函数模块与TransportRequest有关。在"TRINT"中,"TR"很明显的指的是"TransportRequest",而"INT"可能是"Interface"或&qu......
  • SAP ABAP 传输请求背后的读取函数和存储数据库表讲解试读版
    本教程前一篇文章,我们介绍了SAPABAP系统传输请求的基本知识:106.什么是SAPABAP系统里的传输请求(TransportRequest)有朋友提问:你好,有个问题请教下,在开发系统通过SM30维护会产生传输请求的配置表,这个传输请求对应的本次修改的内容存在哪里的呢?SE09相关CR里只有配置表......
  • 什么是 SAP ABAP 服务器的 Addon
    SAPABAP服务器的附加组件(Add-Ons)是专门设计用于扩展SAP基本系统功能的软件组件。它们是由SAP或其他第三方供应商开发的,可以提供针对特定行业或业务需求的特殊功能。附加组件是预先编程好的,可以直接安装在SAP系统中,从而大大提高了系统定制和扩展的便利性。举个例子,SAP提供了一个......