12-09-2005 12:41 PM
Dear SAP Gurus;
I had developed a <b><u>HR Data Extract Report</u></b> to export data in CSV format, but one of our vender application needs data in XML format - any assistance in writing code will be highly <b>appreciated</b> and reward points are <b><i>assured</i></b>.
Best Regards,
Aslam Riaz
12-09-2005 12:44 PM
12-09-2005 12:43 PM
Hi Aslam,
Try using SPRX_XML_DOWNLOAD Function module.
Regards,
Ravi
12-09-2005 12:52 PM
Thanks Ravi,
SPRX_XML_DOWNLOAD FM doesnt exists in our system... we are using SAP 4.7 x200
Best Regards,
Aslam Riaz
12-09-2005 12:54 PM
Hi Aslam,
In the fm i've mentioned, the method
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = rawtable_size
filename = l_fullpath
filetype = 'BIN'
CHANGING
data_tab = raw_table
is used.
If you have the internal table ready with the xml data, then you can use the above method.
Regards,
Ravi
12-09-2005 12:44 PM
12-09-2005 12:55 PM
Thanks Vijay,
I am getting a short dump when tried this with test data. Any sample code?
Best Regards,
Aslam Riaz
12-09-2005 1:12 PM
Check this documentation...
may be it will help you...
see the below sap documentation
CALL TRANSFORMATION
check this weblog...
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
12-09-2005 1:15 PM
Hi Try Using Call Transformation
check the documentation..
check this weblog...
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
regards
vijay
12-09-2005 9:07 PM
12-09-2005 9:10 PM
12-09-2005 9:21 PM
12-09-2005 12:45 PM
u have written code to download int'table data to frontend in CSV format. At the same location attach a condition.if this vendor...instead of CSV use XML extension.
12-09-2005 12:51 PM
Hi Aslam,
Try this out.
<SAP_BW_URL DATA_PROVIDER='View1' CMD='EXPORT' FORMAT='XLS'>
Try changing the format to the desired one.
Hope this helps u,
Regards,
Nagarajan.
12-10-2005 1:54 AM
Hi We are also in version 4.7.
Use the code below as refefence. It works. Please close the issue with appropriate points if helps. Good luck.
************************************************************************
Selection Screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK selscr WITH FRAME TITLE text-s01.
PARAMETER:p_file TYPE rlgrap-filename MODIF ID fil." Output File Name
SELECTION-SCREEN END OF BLOCK selscr.
************************************************************************
Data Declaratiion
************************************************************************
TYPES: BEGIN OF address,
street(20) TYPE c,
apt(10) TYPE c,
city(20) TYPE c,
state(2) TYPE c,
zip(10) TYPE c,
END OF address.
TYPES: BEGIN OF person,
name(20) TYPE c,
ssn(11) TYPE c,
dob(12) TYPE c,
address TYPE address,
END OF person.
DATA: BEGIN OF employee OCCURS 0,
person TYPE person,
END OF employee.
***********************************************************************
Data for xml conversion
***********************************************************************
DATA: l_dom TYPE REF TO if_ixml_element,
m_document TYPE REF TO if_ixml_document,
g_ixml TYPE REF TO if_ixml,
w_string TYPE xstring,
w_size TYPE i,
w_result TYPE i,
w_line TYPE string,
it_xml TYPE dcxmllines,
s_xml LIKE LINE OF it_xml,
w_rc LIKE sy-subrc.
DATA: xml TYPE dcxmllines.
DATA: rc TYPE sy-subrc,
BEGIN OF xml_tab OCCURS 0,
d LIKE LINE OF xml,
END OF xml_tab.
************************************************************************
Initialization
************************************************************************
INITIALIZATION.
************************************************************************
At Selection-Screen On Value Request
************************************************************************
AT SELECTION-SCREEN.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Validating file
PERFORM get_local_file_name USING p_file.
***********************************************************************
Start-of-selection
***********************************************************************
START-OF-SELECTION.
Populate the internal table
PERFORM populate_data.
Create xml file
PERFORM create_xml.
END-OF-SELECTION.
Down load the xml file
PERFORM download_xml.
&----
*& Form populate_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM populate_data .
REFRESH employee.
CLEAR employee.
MOVE: 'Venu Test One' TO employee-person-name,
'111-11-1111' TO employee-person-ssn,
'01/01/1900' TO employee-person-dob,
'1111 Sanzo road' TO employee-person-address-street,
'111 A1' TO employee-person-address-apt,
'BALTIMORE' TO employee-person-address-city,
'MD' TO employee-person-address-state,
'21209' TO employee-person-address-zip.
APPEND employee.
CLEAR employee.
MOVE: 'John Smith' TO employee-person-name,
'222-22-2222' TO employee-person-ssn,
'02/02/1888' TO employee-person-dob,
'2222 John Smith road' TO employee-person-address-street,
'222 B2' TO employee-person-address-apt,
'SANFRANSISCO' TO employee-person-address-city,
'CA' TO employee-person-address-state,
'99999' TO employee-person-address-zip.
APPEND employee.
ENDFORM. " populate_data
&----
*& Form create_xml
&----
text
----
--> p1 text
<-- p2 text
----
FORM create_xml .
CLASS cl_ixml DEFINITION LOAD.
g_ixml = cl_ixml=>create( ).
CHECK NOT g_ixml IS INITIAL.
m_document = g_ixml->create_document( ).
CHECK NOT m_document IS INITIAL.
WRITE: / 'Converting DATA TO DOM 1:'.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
name = 'EMPLOYEE'
dataobject = employee[]
IMPORTING
data_as_dom = l_dom
CHANGING
document = m_document
EXCEPTIONS
illegal_name = 1
OTHERS = 2.
IF sy-subrc = 0.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
sy-subrc.
ENDIF.
CHECK NOT l_dom IS INITIAL.
w_rc = m_document->append_child( new_child = l_dom ).
IF w_rc IS INITIAL.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
w_rc.
ENDIF.
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
document = m_document
IMPORTING
xml_as_string = w_string
size = w_size
TABLES
xml_as_table = it_xml
EXCEPTIONS
no_document = 1
OTHERS = 2.
IF sy-subrc = 0.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
sy-subrc.
ENDIF.
LOOP AT it_xml INTO xml_tab-d.
APPEND xml_tab.
ENDLOOP.
ENDFORM. " create_xml
&----
*& Form get_local_file_name
&----
text
----
-->P_P_FILE text
----
FORM get_local_file_name USING p_p_file.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = p_p_file
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE i007(zu). " 'Error in getting filename'.
ENDIF.
ENDFORM. " get_local_file_name
&----
*& Form download_xml
&----
text
----
--> p1 text
<-- p2 text
----
FORM download_xml .
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
bin_filesize = w_size
filename = p_file
filetype = 'BIN'
TABLES
data_tab = xml_tab
EXCEPTIONS
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
SKIP 5.
WRITE:(15) 'The ', p_file , 'is created successfully'.
*
ENDIF.
ENDFORM. " download_xml
12-10-2005 5:33 AM
the mentioned weblog uses DOM approach which is required if you are below 4.7
since you are already on 4.7 its very simple.
use the following statement to convert the internal table content to XML
data: xml_out type string .
CALL TRANSFORMATION (`ID`)
SOURCE output = your_itab[]
RESULT XML xml_out.
Regards
Raja
12-10-2005 8:12 AM
Thanks Raja,
This has done the job...
CALL TRANSFORMATION (`ID`)
SOURCE output = your_itab[]
RESULT XML xml_out.
Now the question is how to <b>download</b> this to PC
Ex: C:\HRXML
Quick response is highly appreciated.
Best Regards,
Aslam Riaz
12-10-2005 8:30 AM
hi aslam,
please see my post also...
i mentioned that in my post..
vijay..
12-10-2005 8:49 AM
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = rawtable_size
filename = l_fullpath
filetype = 'BIN'
CHANGING
data_tab = xmltable
using the above method you can download ..
12-10-2005 9:28 AM
to convert the xml_out (which is a string) to itab so that you can use it with gui_download.
data: xmltable type standard table of string .
append xml_out to xmltable .
Regards
Raja
08-08-2006 11:30 PM
Hi ,
I need to know how to create specific XML schema output. i tried with FM available and classes available but i need the output in the following format.
<?xml version="1.0" encoding="UTF-8" ?>
- <ps:ProcessSet xmlns:ps="http://schemas.ariba.com/IS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xtc="http://schemas/ariba/xt/core" xmlns:xtd="http://schemas/ariba/xt/datatypes" xmlns:dts="http://schemas/ariba/xt/database" msgid="yw890-hplw47j-904gk4n-s3n4mzq2">
- <ProcessSetProperties null_representation="indirect" process_scope="Entity">
<DateTimeFormats dateTimeFormat="YYYY-MM-DD HH24:MI:SS" />
<Source>SG</Source>
<Message_Version>1.0.0</Message_Version>
I need ABAP code for the above format.
Thanks in Advance
Anney
02-15-2010 10:27 AM
12-10-2005 11:35 AM
Dear All, <b><i><u>Thanks a million</u></i></b>;
It was great help from all of you, thanks God finally managed to get the data in XML format.
<u>SAMPLE of Final Code:</u>
REPORT zpax_extract
NO STANDARD PAGE HEADING
LINE-SIZE 132
LINE-COUNT 60
MESSAGE-ID z1.
* Tables
* Infotypes
* Record
* Internal Tables
* Constants
* Variables
**
TYPES: BEGIN OF ttab,
record(50000) TYPE c,
END OF ttab.
DATA: xmltable TYPE TABLE OF ttab.
* Parameters
PARAMETERS: p_file(128) OBLIGATORY,
p_csv AS CHECKBOX,
p_xml AS CHECKBOX.
* Include programs
*
*
* Main Program
*
*
START-OF-SELECTION.
*INITIALIZATION.
GET pernr.
END-OF-SELECTION.
PERFORM download.
*&---------------------------------------------------------------------*
*& Form download
*&---------------------------------------------------------------------*
FORM download.
DATA: BEGIN OF l_iout OCCURS 0,
rec(1000) TYPE c,
END OF l_iout.
LOOP AT it_pernr.
CONCATENATE it_pernr-pernr
it_pernr-vorna
it_pernr-nach2
it_pernr-nachn
INTO l_iout-rec
SEPARATED BY ';'.
CONDENSE l_iout-rec.
APPEND l_iout.
ENDLOOP.
IF p_csv = 'X'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = fullpath
filetype = 'ASC'
* APPEND = ' '
* write_field_separator = ';'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
* FILELENGTH =
TABLES
data_tab = l_iout
* FIELDNAMES =
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ELSEIF p_xml = 'X'.
DATA: xml_out TYPE string,
length LIKE sy-tabix.
CALL TRANSFORMATION id
SOURCE output = it_pernr[]
RESULT XML xml_out.
APPEND xml_out TO xmltable .
*-----------
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = length
filename = fullpath
filetype = 'BIN'
* APPEND = ' '
* write_field_separator = ';'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
filelength = length
TABLES
data_tab = xmltable
* FIELDNAMES =
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*
**-----------
ENDIF.
ENDFORM. " download
*&---------------------------------------------------------------------*
*& END REPORT
*&---------------------------------------------------------------------*
Thanks once more,
Aslam Riaz
12-10-2005 12:39 PM
Hi Aslam Riaz
Thanks for sharing the code.
If everybody follows what you have done here, this (SDN) will be even more better place for all SAP developers.
Regards
Raja
06-19-2008 10:54 AM
Does your way also work when a person tries to convert the standard report output to XML file?
06-25-2008 8:06 AM
Hi Aslam,
This is really useful.Thanks a lot.
But I have following issues over here:
1) From where does it take encoding value.In my case it is always UTF-16(Ours in Unicode system) and when I try to open this file in IE,it gives encoding error.
2)I need to have this :
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
while the generated XML has :
<asx:abap xmlns:asx="http://www.sap.com/abapxml"
3) I need to define this parameter too:
xsi:noNamespaceSchemaLocation
which doesnt appear in the generated file.
Could you please help, as this is quite urgent for us.
Thanks again.
Best Regards,
Shweta