Google Search - Blog...........

ABAP - Sample Program For Creating XML File On Presentation Server.

*&---------------------------------------------------------------------*
*& report : zdownload_to_xml
*& description : this is the simple example for creating xml
* file to the presentation server
*&---------------------------------------------------------------------*
* for executing the report you should create a varient with name 'test'

Report zdownload_to_xml message-id zmsg.

*&---------------------------------------------------------------------*
* database table used
*&---------------------------------------------------------------------*
Tables : mara,
Makt .
*&---------------------------------------------------------------------*
* types and internal tables for the data
*&---------------------------------------------------------------------*

*--types for the final fields for data
Types : begin of ty_tab ,
Matnr like mara-matnr,
Maktx like makt-maktx,
Mbrsh like mara-mbrsh,
Mtart like mara-mtart,
Meins like mara-meins,
End of ty_tab,

*--types to hold the xml contents.
Begin of ty_xml ,
Line(255) type c,
End of ty_xml.

Types: begin of t_varinfo,
flag type c,
olength type x,
line like raldb-infoline,
End of t_varinfo.

*---internal tables for the types
Data: itab type standard table of ty_tab with header line ,
It_xml type standard table of ty_xml with header line ,
Tables type trdir-name occurs 0 with header line ,
Infotab type t_varinfo occurs 0 with header line.

*&---------------------------------------------------------------------*
* selection screen design
*&---------------------------------------------------------------------*
Selection-screen begin of block b1 with frame title text-001.
Select-options : s_matnr for mara-matnr.
Selection-screen skip 2.
Parameters:filename like rlgrap-filename.
Selection-screen end of block b1 .
*----------------------------------------------------------------------*
* at selection-screen on value-request
*----------------------------------------------------------------------*
At selection-screen on value-request for filename.

Call function 'F4_FILENAME'
Exporting
Program_name = syst-cprog
Dynpro_number = syst-dynnr
Importing
File_name = filename.

*&---------------------------------------------------------------------*
* start-of-selection.
*&---------------------------------------------------------------------*

Start-of-selection.
*---get the data from tables for output
Perform get_data.
If not itab[] is initial.
*--build the xml file data
Perform build_xml.
Endif.
End-of-selection.
*--- download the xml file to the presentaion server
Perform download_xml.
*&---------------------------------------------------------------------*
*& form get_data
*&---------------------------------------------------------------------*
Form get_data .

Clear : itab.
Refresh : itab.
Select a~matnr
B~maktx
A~mbrsh
A~mtart
A~meins
Into table itab
From mara as a
Inner join makt as b
On b~matnr = a~matnr
Where a~matnr in s_matnr and
B~spras = sy-langu.

Endform. " get_data
*&---------------------------------------------------------------------*
*& form build_xml
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
Form build_xml .

Sort itab by matnr.

*--this logic interprets the xml code behaviour hardcoded
*--to build the xml content.
Loop at itab.
At first.
It_xml-line = ''.
Append it_xml.
Clear it_xml.
Endat.
At new matnr.
Read table itab index sy-tabix.
Concatenate '' into it_xml-line.
Append it_xml.
Clear it_xml.
Endat.
Concatenate '' itab-maktx '' into it_xml-line.
Append it_xml.

Concatenate '' itab-mbrsh '' into it_xml-line.
Append it_xml.

Concatenate '' itab-mtart '' into it_xml-line.
Append it_xml.

Concatenate '' itab-meins '' into it_xml-line.
Append it_xml.
At end of matnr.
It_xml-line = '
'.
Append it_xml.
Clear it_xml.
Endat.
Endloop.
It_xml-line = '
'.
Append it_xml.
Clear it_xml.

Endform. " build_xml
*&---------------------------------------------------------------------*
*& form download_xml
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
Form download_xml .

Data:v_file type string .

V_file = filename .

Call function 'gui_download'
Exporting
Filename = v_file
Filetype = 'asc'
Tables
Data_tab = it_xml.

Call function 'print_selections'
Exporting
Mode = tables
Rname = sy-repid "program name
Rvariante = 'TEST' "varient name
Tables
Infotab = infotab
.

Loop at infotab.
Write / infotab-line.
Endloop.

Skip 3 .
Write:/ 'file downloaded with location:', v_file .


Endform. " download_xml

No comments:

Post a Comment