sap 內錶轉xml,類的使用if_ixml_element
*&---------------------------------------------------------------------*
*& Report YTESTXML002
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ytestxml002
.
types
:
begin
of ty_item
,
ebelp
like ekpo
-ebelp
,
menge
like ekpo
-menge
,
end
of ty_item
.
types tt_item
type
standard
table
of ty_item
with
default
key
.
data
: itab_item
type
standard
table
of ty_item
with
header
line
,
wa_item
like
line
of itab_item
.
types
:
begin
of ty_po
,
ebeln
like ekko
-ebeln
,
aedat
like ekko
-aedat
,
item
type tt_item
,
end
of ty_po
.
data
: itab_po
type
standard
table
of ty_po
with
header
line
.
data
:
begin
of itab_all
occurs
0
,
ebeln
like ekko
-ebeln
,
aedat
like ekko
-aedat
,
ebelp
like ekpo
-ebelp
,
menge
like ekpo
-menge
,
end
of itab_all
.
data
: tmpebeln
like ekko
-ebeln
.
data
: l_ixml
type
ref
to if_ixml
,
l_encoding
type
ref
to if_ixml_encoding
,
l_comment
type
ref
to if_ixml_comment
,
l_doc
type
ref
to if_ixml_document
,
l_root
type
ref
to if_ixml_element
,
l_po
type
ref
to if_ixml_element
,
l_pohead
type
ref
to if_ixml_element
,
l_item
type
ref
to if_ixml_element
,
l_element
type
ref
to if_ixml_element
,
l_attribute
type
ref
to if_ixml_attribute
,
l_ostream
type
ref
to if_ixml_ostream
,
l_factory
type
ref
to if_ixml_stream_factory
.
types
:
begin
of xml_line
,
data
(
256
)
type
x
,
end
of xml_line
.
data
: xml_table
type
table
of xml_line
,
xml_size
type
i
.
data
: l_rval
type
i
.
data
: str
type string
.
select-options
: s_ebeln
for itab_all
-ebeln
.
start-of-selection
.
perform getdata
.
perform create_xml
.
perform download
.
*---------------------------------------------------------------------*
* FORM getdata *
*---------------------------------------------------------------------*
form getdata
.
select ekko
~ebeln ekko
~aedat ekpo
~ebelp ekpo
~menge
up
to
10
rows
into
table itab_all
from ekko inner
join ekpo
on ekko
~ebeln
= ekpo
~ebeln
where ekko
~ebeln
in s_ebeln
.
sort itab_all
by ebeln ebelp
.
loop
at itab_all
.
on
change
of itab_all
-ebeln
.
clear itab_po
-item
.
clear tmpebeln
.
tmpebeln
= itab_all
-ebeln
.
loop
at itab_all
where ebeln
= tmpebeln
.
wa_item
-ebelp
= itab_all
-ebelp
.
wa_item
-menge
= itab_all
-menge
.
append wa_item
to itab_po
-item
.
endloop
.
sort itab_po
-item
by ebelp
.
itab_po
-ebeln
= itab_all
-ebeln
.
itab_po
-aedat
= itab_all
-aedat
.
append itab_po
.
endon
.
endloop
.
endform
.
"getdata
*---------------------------------------------------------------------*
* FORM create_xml *
*---------------------------------------------------------------------*
form create_xml
.
class cl_ixml
definition
load
.
l_ixml
= cl_ixml
=>
create
(
)
.
call
method l_ixml
->create_encoding
exporting
byte_order
=
0
character_set
=
'gb2312'
receiving
rval
= l_encoding
.
call
method l_ixml
->create_document
receiving
rval
= l_doc
.
call
method l_doc
->set_encoding
exporting
encoding
= l_encoding
.
call
method l_doc
->create_simple_element
exporting
name
=
'Root'
parent
= l_doc
receiving
rval
= l_root
.
call
method l_root
->set_attribute
exporting
name
=
'ATTRIBUTE'
value
=
'sample'
receiving
rval
= l_rval
.
call
method l_doc
->create_comment
exporting
comment
=
''
'上面ATTRIBUTE為屬性示例'
''
receiving
rval
= l_comment
.
call
method l_root
->append_child
exporting
new_child
= l_comment
receiving
rval
= l_rval
.
loop
at itab_po
.
call
method l_doc
->create_simple_element
exporting
name
=
'po'
parent
= l_root
receiving
rval
= l_po
.
call
method l_doc
->create_simple_element
exporting
name
=
'pohead'
parent
= l_po
receiving
rval
= l_pohead
.
str
= itab_po
-ebeln
.
call
method l_doc
->create_simple_element
exporting
name
=
'ponumber'
parent
= l_pohead
value
= str
receiving
rval
= l_element
.
str
= itab_po
-aedat
.
call
method l_doc
->create_simple_element
exporting
name
=
'podate'
parent
= l_pohead
value
= str
receiving
rval
= l_element
.
perform fill_itab2xml
tables itab_po
-item
using
'pobody'
'poitem'
l_po
.
endloop
.
call
method l_ixml
->create_stream_factory
receiving
rval
= l_factory
.
call
method l_factory
->create_ostream_itable
exporting
table
= xml_table
receiving
rval
= l_ostream
.
call
method l_doc
->render
exporting
ostream
= l_ostream
.
* recursive = 'X'.
call
method l_ostream
->get_num_written_raw
receiving
rval
= xml_size
.
endform
.
"create_xml
*---------------------------------------------------------------------*
* FORM fill_itab *
*---------------------------------------------------------------------*
form fill_itab2xml
tables intab
using node1name
type string
node2name
type string
l_parent
type
ref
to if_ixml_element
.
data
:
begin
of headtab
occurs
0
,
length
type
i
,
decimals
type
i
,
type_kind
type
c
,
name
(
30
)
type
c
,
end
of headtab
.
data descr_ref
type
ref
to cl_abap_structdescr
.
field-symbols
: <comp_wa>
type abap_compdescr
,
<f_field>
,
<f_intab>
type
any
.
data
: n
type
i
,
str
type string
,
itemname
type string
,
text1
type
c
,
l_node
type
ref
to if_ixml_element
,
l_item
type
ref
to if_ixml_element
.
descr_ref ?= cl_abap_typedescr
=>describe_by_data
( intab
)
.
loop
at descr_ref
->components
assigning <comp_wa>
.
move-corresponding <comp_wa>
to headtab
.
append headtab
.
endloop
.
call
method l_doc
->create_simple_element
exporting
name
= node1name
parent
= l_parent
receiving
rval
= l_node
.
describe
table headtab
lines n
.
loop
at intab
assigning <f_intab>
.
call
method l_doc
->create_simple_element
exporting
name
= node2name
parent
= l_node
receiving
rval
= l_item
.
do n
times
.
assign
component sy
-
index
of
structure <f_intab>
to <f_field>
.
str
= <f_field>
.
read
table headtab
index sy
-
index
.
if headtab
-type_kind
=
'I'
or headtab
-type_kind
=
'P'
or headtab
-type_kind
=
'F'
.
search str
for
'-'
.
if sy
-subrc
=
0
and sy
-fdpos <>
0
.
split str
at
'-'
into str text1
.
condense str
.
concatenate
'-' str
into str
.
else
.
condense str
.
endif
.
else
.
* SHIFT str LEFT DELETING LEADING '0' .
endif
.
itemname
= headtab
-name
.
call
method l_doc
->create_simple_element
exporting
name
= itemname
parent
= l_item
value
= str
receiving
rval
= l_element
.
enddo
.
endloop
.
endform
.
"fill_itab2xml
*---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form DOWNLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form download
.
data
: pickedfolder
type string
.
data
: initialfolder
type string
.
data
:
: filepath
like rlgrap
-filename
.
call
method cl_gui_frontend_services
=>directory_browse
exporting
initial_folder
= initialfolder
changing
selected_folder
= pickedfolder
exceptions
cntl_error
=
1
error_no_gui
=
2
not_supported_by_gui
=
3
.
concatenate pickedfolder
'\' sy
-uzeit
'testpo2.xml'
into pickedfolder
.
**--將xml資料匯出到本地
call
method cl_gui_frontend_services
=>gui_download
exporting
bin_filesize
= xml_size
filename
= pickedfolder
filetype
=
'BIN'
changing
data_tab
= xml_table[]
.
endform
.
" DOWNLOAD
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9522162/viewspace-2999368/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- XML轉化為json工具類XMLJSON
- 匿名內部類的使用
- PHP xml 轉陣列 陣列轉 xml 操作PHPXML陣列
- java使用jaxb解析XML(含根據xml自動生成實體類)JavaXML
- 關係錶轉dooris 的java 指令碼Java指令碼
- xml字串轉JSON字串XML字串JSON
- C# 操作xml(轉)C#XML
- SAP系統中的內碼和外碼轉換 (WBS號)
- 基於 DOM 的 XML 檔案解析類XML
- 使用程式碼給 SAP UI5 XML 檢視新增自定義 CSSUIXMLCSS
- SSM整合之使用配置類替換xml配置檔案(2)SSMXML
- Java 內部類使用詳解Java
- 剛需,jackjsonjson轉化內部類問題JSON
- 使用FOR XML AUTO控制XML輸出KHXML
- xml與陣列的相互轉換——phpXML陣列PHP
- SAP Fiori Elements 本地專案的 annotations.xml 檔案XML
- Java 將HTML轉為XMLJavaHTMLXML
- [xmlbeans]自動生成讀寫xml的java類XMLBeanJava
- 修改所有xml檔案中的某些內容XML
- 元件使用總結:使用 JAXB 實現 XML檔案和java物件互轉元件XMLJava物件
- 內部類中的成員的定義和使用
- mapper.xml基礎內容APPXML
- 第11章 使用類——型別轉換(二)將自定義型別轉換為內建型別型別
- Spring基於XML方式的使用SpringXML
- 關於SAP的故事(轉)
- 快速將log4j.xml轉換為logback.xmlXML
- 學習 XSLT:XML文件轉換的關鍵XML
- php陣列如何轉換為xml的形式?PHP陣列XML
- java內部類,區域性內部類,靜態內部類,匿名內部類Java
- C# 將HTML轉為XMLC#HTMLXML
- C# 將Excel轉為XMLC#ExcelXML
- java 物件與xml相互轉換Java物件XML
- Java中的匿名內部類及內部類的二三事Java
- 在 Excel 內使用 ODBC 消費 SAP ABAP CDS viewExcelView
- 使用 XML 時儘量避免使用的技術XML
- 【ASK_ORACLE】使用insert語句將普通錶轉換成分割槽表Oracle
- php獲取xml檔案內容PHPXML
- 10-Java內部類——成員內部類、區域性內部類、匿名內部類Java