2009 Dec 03 11:57 AM
What's the FM for creating XML file in application server.
Like CL_GUI_FRONTEND_SERVICES=>gui_download
Thanks in advance
Hi Supriya,
Do you think my code is for creating an Excel??
Kindly read my post carefully, it is for creating an XML.
Regards
Abhii
2009 Dec 03 12:03 PM
Hi SIMO,
Use CALL TRANSFORMATION concept for the same.
PS : CALL TRANSFORMATION is only available in ECC.
A sample code snippet :-
REPORT ZUS_SDN_XML_XSTRING_APPLSERVER.
DATA:
gd_dsn type string,
gd_xstring type xstring,
gt_kna1 type STANDARD TABLE OF kna1.
start-of-selection.
select * from kna1 into table gt_kna1 up to 10 rows.
BREAK-POINT.
call TRANSFORMATION id
source itab = gt_kna1
result xml = gd_xstring.
gd_dsn = '/tmp/xml_as_xstring.file'.
open DATASET gd_dsn for OUTPUT in BINARY MODE.
check ( syst-subrc = 0 ).
TRANSFER gd_xstring to gd_dsn.
CLOSE DATASET gd_dsn.
end-of-SELECTION.
Regards
Abhii
2009 Dec 03 12:16 PM
Hi ,
There is no FM .
U have to use Open Dataset and create a .XML file for the same .
Thanks
2009 Dec 03 12:19 PM
Hi Supriya,
Read my code carefully, I am not using any Function Module, It is CALL TRANSFORMATION its not a function module, its exclusively used to create an excel file.
Regards
Abhii
2009 Dec 03 12:30 PM
Yes , agreed ..
But the requirement here is to create an XML and not an Excel ....
Thanks
2009 Dec 03 12:33 PM
Hi Supriya,
Do you think my code is for creating an Excel??
Kindly read my post carefully, it is for creating an XML.
Regards
Abhii
2009 Dec 03 12:39 PM
I think we are here to find out a solution and not to point out anyones errors .
Anyways , Call trans works only in ECC ...
So , Open Dataset is a much better option incase the solution needs to be put up in lower versions ...
n Open Dataset works for sure as i have used it N number of times .
Thanks .
2009 Dec 03 12:50 PM
Hi Supriya,
I am not finding any error. I am just replying to what has been pointed towards my post.
You wrote "Yes , agreed ...But the requirement here is to create an XML and not an Excel ...."
I had clearly written that it is for creating for an XML.
Even I had written that this works in only ECC versions. If you look at my code DATASET concept is also used.
However SIMO if you are working on a version other than ECC like 4.7 then , SIMO please refer below code.
REPORT z_down_xml LINE-SIZE 132 NO STANDARD PAGE HEADING.
**********************************************************************
* REPORT Z_DOWN_XML - Using an internal table (gt_marc)
* * and downloading the report data as an xml file
* * the xml indentation is hard coded into the file *
********************************************************************** *
* databases
TABLES: makt, "Mat description
marc, "Material / plant
t001w, "plant name
bhdgd. "Batch heading
* Internal tables
DATA: BEGIN OF gt_marc OCCURS 0,
werks LIKE marc-werks,
matnr LIKE marc-matnr,
END OF gt_marc,
* Table to be downloaded as xml. Each line stores start and end tags
* and the value
BEGIN OF gt_xml OCCURS 0,
line(120),
END OF gt_xml,
g_maktx(120).
* User-input
SELECT-OPTIONS: s_werks FOR marc-werks, s_matnr FOR marc-matnr.
**********************************************************************
START-OF-SELECTION.
* extract all required data
perform main_processing.
**********************************************************************
END-OF-SELECTION.
SORT gt_marc BY werks matnr.
LOOP AT gt_marc.
AT FIRST. "First tag must be root
CLEAR gt_xml.
gt_xml-line = ''.
APPEND gt_xml.
CLEAR gt_xml.
ENDAT.
AT NEW werks. "At new plant
PERFORM read_plant.
FORMAT COLOR 4 ON.
SKIP 1.
WRITE :/ gt_marc-werks,
t001w-name1.
FORMAT COLOR 4 OFF.
CLEAR gt_xml.
gt_xml-line = ' '.
APPEND gt_xml.
CLEAR gt_xml.
CONCATENATE ' ' gt_marc-werks '' INTO gt_xml-line.
APPEND gt_xml.
CLEAR gt_xml.
CONCATENATE ' ' t001w-name1 '' INTO gt_xml-line.
APPEND gt_xml.
CLEAR gt_xml.
gt_xml-line = ' '.
APPEND gt_xml.
CLEAR gt_xml.
ENDAT.
PERFORM read_description.
CLEAR gt_xml.
gt_xml-line = ' '.
APPEND gt_xml.
CLEAR gt_xml.
CONCATENATE ' ' g_maktx '' INTO gt_xml-line.
APPEND gt_xml.
CLEAR gt_xml.
CONCATENATE ' ' gt_marc-matnr '' INTO gt_xml-line.
APPEND gt_xml.
CLEAR gt_xml.
gt_xml-line = ' '.
APPEND gt_xml.
CLEAR gt_xml.
* display data
FORMAT COLOR 2 ON.
WRITE :/ gt_marc-matnr,
makt-maktx.
FORMAT COLOR 2 OFF.
ENDLOOP.
* The last tag must be the root closing tag --*
gt_xml-line = ''.
APPEND gt_xml.
CLEAR gt_xml.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = 'C:PLANT1.XML'
filetype = 'ASC'
TABLES
data_tab = gt_xml.
**********************************************************************
top-of-page.
MOVE sy-title TO bhdgd-line1.
MOVE sy-repid TO bhdgd-repid.
MOVE sy-uname TO bhdgd-uname.
MOVE sy-datum TO bhdgd-datum.
MOVE '0' TO bhdgd-inifl.
MOVE '132' TO bhdgd-lines.
FORMAT INTENSIFIED ON COLOR COL_HEADING.
PERFORM batch-heading(rsbtchh0). "report header
*---------------------------------------------------------------------*
* Form READ_PLANT
*---------------------------------------------------------------------*
FORM read_plant.
* Get plant name
CLEAR t001w.
SELECT SINGLE name1 INTO t001w-name1 FROM t001w WHERE werks EQ
gt_marc-werks.
ENDFORM. " READ_PLANT
*---------------------------------------------------------------------*
* Form MAIN_PROCESSING
*---------------------------------------------------------------------*
FORM main_processing.
* Material and plant basic data
SELECT werks matnr INTO TABLE gt_marc FROM marc WHERE werks IN s_werks
AND matnr IN s_matnr.
ENDFORM. " MAIN_PROCESSING
*---------------------------------------------------------------------*
* Form READ_DESCRIPTION
*---------------------------------------------------------------------*
FORM read_description.
* Material name
CLEAR g_maktx.
SELECT SINGLE maktx INTO g_maktx FROM makt WHERE matnr EQ gt_marc-matnr
AND spras EQ 'E'.
* Replace special character
DO.
REPLACE '&' WITH '*ù%;' INTO g_maktx.
IF NOT sy-subrc IS INITIAL.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '*ù%;' WITH '&' INTO g_maktx.
IF NOT sy-subrc IS INITIAL.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '/' WITH '/' INTO g_maktx.
IF NOT sy-subrc IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ENDFORM.Regards
Abhii
2009 Dec 03 1:12 PM
hi
What Abhil says is 100% right.
To get the XML file we have to use conept of Transformation.
sampath
2009 Dec 04 10:32 AM
Ok. Thanks for all your answers.
How can i do to add this tag in my XML file: create( ).
Creation the dom object model
l_document = l_ixml->create_document( ).
Création des noeuds et des valeurs
l_element_fichier = l_document->create_simple_element(
name = 'fichier_des'
parent = l_document ).
.......................
.....................
Thanks
2009 Dec 04 12:45 PM
Hello,
use code like this:
Make the XML envelope compliant with identity transform
REPLACE '<?xml version="1.0" encoding="UTF-8"?><data>'
IN lv_xml_data_string
WITH '<?xml version="1.0" encoding="iso-8859-1"?><asx:abap xmlns
:asx="http://www.sap.com/abapxml" version="1.0"><asx:values>'.
REPLACE '</data>'
IN lv_xml_data_string
WITH '</asx:values></asx:abap>'.
Otto
2009 Dec 04 1:33 PM
???
I don't understand your solution.
When i generat the xml file, the first tag is <?xml version="1.0"?>
i want replace it by <?xml version="1.0" encoding="UTF-8"?>
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |