SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

DCOM object to create and translate XML Files in 4.6C



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Mon Oct 08, 2007 4:18 pm    Post subject: DCOM object to create and translate XML Files in 4.6C Reply with quote

Here is two programs with DCOM objects.
You have to apply the OSS note 675637 to fix the function MOVE_TABLE in CL_XML_DOCUMENT object.

Code:
============================================
= EXPORT PROGRAM.
============================================
REPORT ZXXX.

type-pools truxs.

DATA: m_xmldoc TYPE REF TO CL_XML_DOCUMENT.
DATA: w_subrc LIKE sy-subrc.
DATA: g_ixml TYPE REF TO IF_IXML.
DATA: node_h TYPE REF TO IF_IXML_NODE,
node_d TYPE REF TO IF_IXML_NODE.
DATA: nodes TYPE REF TO IF_IXML_NODE_LIST,
child TYPE REF TO IF_IXML_NODE,
index TYPE i.
DATA: l_hea TYPE REF TO IF_IXML_ELEMENT,
l_det TYPE REF TO IF_IXML_ELEMENT,
l_lot TYPE REF TO IF_IXML_ELEMENT,
l_dets TYPE REF TO IF_IXML_ELEMENT,
l_doc TYPE REF TO IF_IXML_DOCUMENT.
DATA: ws_corh LIKE zstcorh,
ws_cord LIKE zstcord,
it_cord LIKE zstcord OCCURS 0 WITH HEADER LINE.

* --------------------------------------
* Generaciуn de data de pruebas
* --------------------------------------
ws_corh-TIPO_REGISTRO = 'C'.
ws_corh-CODIGO_CLIENTE = '12932'.
ws_corh-RUC = '000010096587533'.
ws_corh-NRO_LOTE = '000002'.
ws_corh-ANO = '2004'.
ws_corh-MES = '12'.
ws_corh-DIA = '14'.
ws_corh-HORA = '161350'.
ws_corh-USUARIO_ENVIO = 'WONG'.
ws_corh-NRO_DETALLES = '00002'.
ws_corh-RELLENO = '----------'.

it_cord-TIPO_REGISTRO = 'D'.
it_cord-CODIGO_CLIENTE = '12932'.
it_cord-RUC_CLIENTE = '000010096587533'.
it_cord-RUC_PROVEEDOR = '000001009869944'.
it_cord-TIPO_DOCUMENTO = '01'.
it_cord-NRO_DOCUMENTO = '000000000003863'.
it_cord-ANO_EMISION = '2004'.
it_cord-MES_EMISION = '12'.
it_cord-DIA_EMISION = '11'.
it_cord-MONEDA_PAGO = '02'.
it_cord-SUB_TOTAL = '00000001273059'.
it_cord-IMPUESTOS = '00000000241881'.
it_cord-TOTAL_PAGO = '00000001514940'.
it_cord-PENDIENTE_PAGO = '00000001514940'.
it_cord-DOCUMENTO_REFERE = '01-00012-0012345'.
it_cord-ANO_VENCIMIENTO = '2004'.
it_cord-MES_VENCIMIENTO = '12'.
it_cord-DIA_VENCIMIENTO = '18'.
it_cord-ANO_PROGPAGO = '2004'.
it_cord-MES_PROGPAGO = '12'.
it_cord-DIA_PROGPAGO = '18'.
it_cord-FORMA_PAGO = '02'.
it_cord-NRO_LOTE = '000002'.
it_cord-ANO_ENVIO = '2004'.
it_cord-MES_ENVIO = '12'.
it_cord-DIA_ENVIO = '14'.
it_cord-HORA_ENVIO = '161350'.
it_cord-NOMBRE_PROVEEDOR = 'AML'.
it_cord-AFECTO_DETRACCIO = 0.
it_cord-AFECTO_RETENCION = 0.
it_cord-AFECTO_DESCUENTO = 0.
it_cord-IMPORTE_AFECTO = '00000000000000'.
it_cord-OBSERVACIONES = 'xxxxxxxxxx'.
append it_cord.

it_cord-TIPO_REGISTRO = 'D'.
it_cord-CODIGO_CLIENTE = '12932'.
it_cord-RUC_CLIENTE = '000010096587533'.
it_cord-RUC_PROVEEDOR = '000001009869944'.
it_cord-TIPO_DOCUMENTO = '01'.
it_cord-NRO_DOCUMENTO = '000000000003864'.
it_cord-ANO_EMISION = '2004'.
it_cord-MES_EMISION = '12'.
it_cord-DIA_EMISION = '11'.
it_cord-MONEDA_PAGO = '02'.
it_cord-SUB_TOTAL = '00000001273059'.
it_cord-IMPUESTOS = '00000000241881'.
it_cord-TOTAL_PAGO = '00000001514940'.
it_cord-PENDIENTE_PAGO = '00000001514940'.
it_cord-DOCUMENTO_REFERE = '01-00011-0088888'.
it_cord-ANO_VENCIMIENTO = '2004'.
it_cord-MES_VENCIMIENTO = '12'.
it_cord-DIA_VENCIMIENTO = '15'.
it_cord-ANO_PROGPAGO = '2004'.
it_cord-MES_PROGPAGO = '12'.
it_cord-DIA_PROGPAGO = '18'.
it_cord-FORMA_PAGO = '02'.
it_cord-NRO_LOTE = '000002'.
it_cord-ANO_ENVIO = '2004'.
it_cord-MES_ENVIO = '12'.
it_cord-DIA_ENVIO = '14'.
it_cord-HORA_ENVIO = '161350'.
it_cord-NOMBRE_PROVEEDOR = 'AML'.
it_cord-AFECTO_DETRACCIO = 0.
it_cord-AFECTO_RETENCION = 0.
it_cord-AFECTO_DESCUENTO = 0.
it_cord-IMPORTE_AFECTO = '00000000000000'.
it_cord-OBSERVACIONES = 'xxxxxxxxxx'.
append it_cord.

* --------------------------------------
* Inicializa Framework
* --------------------------------------
CLASS cl_ixml DEFINITION LOAD.
g_ixml = cl_ixml=>CREATE( ).

l_doc = g_ixml->CREATE_DOCUMENT( ).
l_lot = l_doc->CREATE_ELEMENT( name = 'LOTE' ).
CALL METHOD l_doc->APPEND_CHILD
EXPORTING NEW_CHILD = l_lot.

* --------------------------------------
* Generaciуn de HEADER
* --------------------------------------
* Convierto la data a un DOM
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING NAME = 'HEADER'
DATAOBJECT = ws_corh
IMPORTING DATA_AS_DOM = l_hea.

CALL METHOD l_lot->APPEND_CHILD
EXPORTING NEW_CHILD = l_hea.

* --------------------------------------
* Generaciуn de DETALLES
* --------------------------------------
l_dets = l_doc->CREATE_ELEMENT( NAME = 'DETALLES' ).
CALL METHOD l_lot->APPEND_CHILD
EXPORTING NEW_CHILD = l_dets.

* loop a la tabla de detalles
LOOP AT it_cord INTO ws_cord.
* Convierto la data a un DOM
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING NAME = 'DETALLE'
DATAOBJECT = ws_cord
IMPORTING DATA_AS_DOM = l_det.
*
CALL METHOD l_dets->APPEND_CHILD
EXPORTING NEW_CHILD = l_det.
ENDLOOP.

* --------------------------------------
* creo y exporto el documento
* --------------------------------------
CREATE OBJECT m_xmldoc.
CALL METHOD m_xmldoc->CREATE_WITH_DOM
EXPORTING DOCUMENT = l_doc.

CALL METHOD m_xmldoc->EXPORT_TO_FILE
EXPORTING FILENAME = 'c:\xml\cesar.xml'.


Code:
=============================================
= IMPORT PROGRAM.
=============================================
REPORT ZXX5.

*type-pools truxs.

DATA: s_FILENAME(128) TYPE c.
s_FILENAME = 'c:\backup\abap\export.xml'.

DATA: xmldoc TYPE REF TO CL_XML_DOCUMENT,
xmldo2 TYPE REF TO CL_XML_DOCUMENT.
DATA: w_subrc LIKE sy-subrc.
DATA: g_ixml TYPE REF TO IF_IXML.
DATA: node_h TYPE REF TO IF_IXML_NODE,
node_d TYPE REF TO IF_IXML_NODE,
item TYPE REF TO IF_IXML_NODE,
n_tab TYPE REF TO IF_IXML_NODE,
child TYPE REF TO IF_IXML_NODE,
grandson TYPE REF TO IF_IXML_NODE,
new TYPE REF TO IF_IXML_NODE.
DATA: index TYPE i.
DATA: l_tabl TYPE REF TO IF_IXML_ELEMENT,
l_item TYPE REF TO IF_IXML_ELEMENT.
DATA: l_doc TYPE REF TO IF_IXML_DOCUMENT.
DATA: it_corh LIKE zstcorh OCCURS 0 WITH HEADER LINE,
it_cord LIKE zstcord OCCURS 0 WITH HEADER LINE.

* ----------------------------------------------
* PROCESOS INICIALES
* ----------------------------------------------
* Inicializa Framework
CLASS cl_ixml DEFINITION LOAD.
g_ixml = cl_ixml=>CREATE( ).

* Creo el objeto xmldoc
CREATE OBJECT xmldoc.
* importo el documento
CALL METHOD xmldoc->CREATE_WITH_FILE( FILENAME = s_FILENAME ).

* ----------------------------------------------
* CONVERSION DEL NODO HEADER
* ----------------------------------------------
CALL METHOD xmldoc->FIND_NODE
EXPORTING NAME = 'HEADER'
RECEIVING NODE = node_h.

* Creo documento de detalles y le paso contenido de HEADER
l_doc = g_ixml->CREATE_DOCUMENT( ).
l_tabl = l_doc->CREATE_ELEMENT( NAME = 'PT_TABNAME' ).
CALL METHOD l_doc->APPEND_CHILD( NEW_CHILD = l_tabl ).
l_item = l_doc->CREATE_ELEMENT( NAME = 'item' ).
CALL METHOD l_tabl->APPEND_CHILD( NEW_CHILD = l_item ).

* Agrego los nodos a documento creado
child = node_h->GET_FIRST_CHILD( ).
WHILE not child is initial.
new = child->CLONE( ).
CALL METHOD l_item->APPEND_CHILD( NEW_CHILD = new ).
child = child->GET_NEXT( ).
endwhile.

* Creo el objeto xmldo2
CREATE OBJECT xmldo2.

* Convierto a documento y luego a tabla
CALL METHOD xmldo2->CREATE_WITH_DOM( DOCUMENT = l_doc ).
CALL METHOD xmldo2->GET_DATA
CHANGING DATAOBJECT = it_corh[].

* ----------------------------------------------
* CONVERSION DEL NODO DETALLES
* ----------------------------------------------
CALL METHOD xmldoc->find_node
EXPORTING NAME = 'DETALLES'
RECEIVING NODE = node_d.

* Creo documento de detalles y le paso contenido de DETALLES
l_doc = g_ixml->CREATE_DOCUMENT( ).
l_tabl = l_doc->CREATE_ELEMENT( NAME = 'PT_TABNAME' ).
CALL METHOD l_doc->APPEND_CHILD( NEW_CHILD = l_tabl ).

* Agrego los nodos a documento creado
child = node_d->GET_FIRST_CHILD( ).
WHILE not child is initial.
l_item = l_doc->CREATE_ELEMENT( NAME = 'item' ).
CALL METHOD l_tabl->APPEND_CHILD( NEW_CHILD = l_item ).
grandson = child->GET_FIRST_CHILD( ).
WHILE not grandson is initial.
new = grandson->CLONE( ).
CALL METHOD l_item->APPEND_CHILD( NEW_CHILD = new ).
grandson = grandson->GET_NEXT( ).
endwhile.
child = child->GET_NEXT( ).
endwhile.

* Convierto a documento y luego a tabla
CALL METHOD xmldo2->DELETE( ).
CALL METHOD xmldo2->CREATE_WITH_DOM( DOCUMENT = l_doc ).
CALL METHOD xmldo2->GET_DATA
CHANGING DATAOBJECT = it_cord[].
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.