Using XSLT
I created an XSLT transformation called "ZSIMPLEXSLT" and wrote the following code to try and transform some data on a web server. When the code gets to the CALL TRANSFORMATION line it bombs saying that I've tried to invoke a method on an object reference that's null. It's talking about <b>istream</b> because in the Globals list I can see this dataobject is still INITIAL. Does anybody know why the call to create_istream_uri( ) is failing to return an istream?
TYPE-POOLS: abap.
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA g_ixml TYPE REF TO if_ixml.
DATA streamfactory TYPE REF TO if_ixml_stream_factory.
DATA istream TYPE REF TO if_ixml_istream.
DATA xmlstr TYPE string.
DATA ex TYPE REF TO CX_SY_REF_IS_INITIAL.
DATA imsg TYPE REF TO IF_MESSAGE.
DATA smsg TYPE string.
START-OF-SELECTION.
g_ixml = cl_ixml=>create( ).
streamfactory = g_ixml->create_stream_factory( ).
istream = streamfactory->create_istream_uri( 'http://www.somewhere.com/data.xml' ).
TRY.
CALL TRANSFORMATION zsimplexslt
SOURCE XML istream
RESULT XML xmlstr.
CATCH CX_SY_REF_IS_INITIAL INTO ex.
imsg = ex.
WRITE / 'EXCEPTION THROWN:'.
smsg = imsg->GET_LONGTEXT( ).
smsg = imsg->GET_TEXT( ).
WRITE / smsg.
ENDTRY.
Hello Steve
I am not sure whether method
streamfactory->create_istream_uri is able to make a HTTP connection to a web site. All the sample reports in package SIXML_TEST (ECC 5.0) deal with files located either on the local PC or the application server.
However, as a workaround you could use interface IF_HTTP_CLIENT in order to establish a HTTP connection and retrieve the data from the web site. The following sample report ZUS_SDN_SIMPLE_XSLT is a mélange of your coding and pieces out of report RSHTTP02 (HTTP client test, package SHTTP).
*& Report ZUS_SDN_SIMPLE_XSLT
REPORT zus_sdn_simple_xslt.
TYPE-POOLS: abap.
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA g_ixml TYPE REF TO if_ixml.
DATA streamfactory TYPE REF TO if_ixml_stream_factory.
DATA istream TYPE REF TO if_ixml_istream.
DATA xmlstr TYPE string.
DATA x_string TYPE xstring.
DATA ex TYPE REF TO cx_sy_ref_is_initial.
DATA imsg TYPE REF TO if_message.
DATA smsg TYPE string.
DATA:
go_client TYPE REF TO if_http_client.
START-OF-SELECTION.
g_ixml = cl_ixml=>create( ).
streamfactory = g_ixml->create_stream_factory( ).
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'http://www.w3schools.com/xsl/cdcatalog.xml'
* PROXY_HOST =
* PROXY_SERVICE =
* SSL_ID =
* SAP_USERNAME =
* SAP_CLIENT =
IMPORTING
client = go_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
go_client->request->set_method( 'GET' ).
go_client->request->set_version(
if_http_request=>co_protocol_version_1_0 ).
cl_http_utility=>set_request_uri( request = go_client->request
uri = 'GET' ).
CALL METHOD go_client->send( ).
CALL METHOD go_client->receive( ).
x_string = go_client->response->if_http_entity~get_data( ).
istream = streamfactory->create_istream_xstring( x_string ).
** CALL METHOD streamfactory->create_istream_uri
** EXPORTING
*** public_id = 'http://www.w3schools.com/xsl/cdcatalog.xml'
** system_id = 'http://www.w3schools.com/xsl/cdcatalog.xml'
** RECEIVING
** rval = istream.
CHECK ( istream IS BOUND ).
** istream = streamfactory->create_istream_uri(
** 'http://www.w3schools.com/xsl/cdcatalog.xml' ).
TRY.
CALL TRANSFORMATION zsimplexslt
SOURCE XML istream
RESULT XML xmlstr.
CATCH cx_sy_ref_is_initial INTO ex.
imsg = ex.
WRITE / 'EXCEPTION THROWN:'.
smsg = imsg->get_longtext( ).
smsg = imsg->get_text( ).
WRITE / smsg.
ENDTRY.
Regards
Uwe
PS: Please forgive that I have renamed your report but it makes tracking of "my" sample reports in the SDN easier...
Similar Messages
-
How to Count schedule lines in IDoc ORDERS05 using XSLT Mapping
Hi Experts,
In a Scenario where we are sending Purchase order (ORDERS05) to SAP SNC using XSLT Mapping,
where in we need to count the no. of schedule lines against the Purchase Order line.
As in Schedule line segment there is no such provision, so it needs to be handle in XSLT mapping to count the schedule lines.
Can you all please guide me how to go about the same.
Regards,
Nitin PHi Satish,
Thank you very much for the reply,
as there is only Quantity and other information is maintained against schedule lines how we can count the schedule line repeatation against PO line ? Is that very simple as you suggested or some other consideration also needs to be taken.
Please clarify the same and let me also know if there are some standard documents also for the same.
Regards,
Nitin P -
How to feed data to generate a html file using XSLT?
I need to implement email content generation in the hmtl format using XSLT. The document information is stored in a xsl file and the data is generated dynmically in the application. How to feed the data to have the file?
Thanks,
v.Thanks for your information. I, however, already thought about using string stream instand of a XML file to pass in data. I am looking for a more intelligent method. It doesn't seem to have one so far.
-
ERROR WHILE USING XSLT MAPPING IN INTERFACE MAPPING
Hi,
We are using an xslt mapping in our scenario but while i load the XSLT mapping in the interface mapping i get a message :
Transformer configuration exception occurred when loading XSLT
sorce interface :outbound and asyncronous.
mapping : XSLT mapping (imported as a zip file)
target interface: abstract,asyncronous.
The xslt runs well in standalone and its well formed and there is no name space issue.
please help if any one has faced such a situation while using XSLT mapping.
regards,
Anirban.Hi Anirban
When you say it runs well <i>standalone</i> what exactly do you mean? Which XSLT processor are you using to run it? There are subtle difference between XSTL processors that can sometimes result in incompatibilities. For instance, I have seen XSLTs run correctly in XMLSpy but incorrectly (or at least slightly differently) in XI.
Regards,
Thorsten -
XML to Internal table using XSLT by CALL TRANSFORMATION error
Dear experts,
I have to fetch the data from an XML file using XSLT into internal tables. The XML file is very big as following:-
<?xml version="1.0" standalone="yes" ?>
- <Shipment>
<shipmentID>25091203S000778</shipmentID>
<manifestDateTime>2009-12-03T20:16:52.00</manifestDateTime>
<shipmentFacilityNumber>025</shipmentFacilityNumber>
<shipmentFacilityAbbreviation>CHI</shipmentFacilityAbbreviation>
<shipmentFacilityAddress1>810 KIMBERLY DRIVE</shipmentFacilityAddress1>
<shipmentFacilityAddress2 />
<shipmentFacilityCity>CAROL STREAM</shipmentFacilityCity>
<shipmentFacilityState>IL</shipmentFacilityState>
<shipmentFacilityPostalCode>601880000</shipmentFacilityPostalCode>
<shipmentTruckCarrierCode>X150</shipmentTruckCarrierCode>
<shipmentSourceCode>T</shipmentSourceCode>
<userID>CAMPOSG</userID>
- <Delivery>
<primaryCustomerNumber>954371</primaryCustomerNumber>
<primaryCustomerName>MIDWEST OFFICE SUPPLY</primaryCustomerName>
<primaryCustomerAddress1 />
<primaryCustomerAddress2>4765 INDUSTRIAL DR</primaryCustomerAddress2>
<primaryCustomerCity>SPRINGFIELD</primaryCustomerCity>
<primaryCustomerState>IL</primaryCustomerState>
<primaryCustomerPostalCode>627030000</primaryCustomerPostalCode>
<primaryCustomerPhoneNumber>2177535555</primaryCustomerPhoneNumber>
<shuttleStopFacilityNumber />
<billOfLadingNumber>25HZK99</billOfLadingNumber>
<carrierProNumber />
<shipmentTotalCartonCount>6</shipmentTotalCartonCount>
<shipmentTotalWeight>266</shipmentTotalWeight>
- <order>
<orderNumber>25HZK99</orderNumber>
<subOrderNumber />
<dateProcessed>2009-12-03</dateProcessed>
<primaryOrderNumber />
<shipTruckCode>X150</shipTruckCode>
<shipTruckDescription>UDS - ADDISON</shipTruckDescription>
<shipTruckPriorityCode>01</shipTruckPriorityCode>
<shipTruckGroupCode>01</shipTruckGroupCode>
<shipTruckDepartureTime>20.00.00</shipTruckDepartureTime>
<shipTruckDockID>07</shipTruckDockID>
<ldpFacilityAbbreviation />
<shuttleAvailableIndicator>N</shuttleAvailableIndicator>
<shuttleMessageText />
<crossDockFacilityCode />
<crossDockTruckCode />
<crossDockID />
<subsidizedFreightTruckID />
<customerPurchaseOrderNumber>623559</customerPurchaseOrderNumber>
<headerTypeCode>P</headerTypeCode>
<orderTypeID>RG</orderTypeID>
<deliveryTypeID>DS</deliveryTypeID>
<deliveryMethodCode />
<customerBarCode />
<customerReferenceData>25HZK99</customerReferenceData>
<customerReferenceText />
<customerRouteData>ZNED UNTED</customerRouteData>
<customerRouteText>ROUTE</customerRouteText>
<endConsumerPurchaseOrderNumber />
<endConsumerPurchaseOrderText />
<endConsumerName>CHARLESTON TRANS. FACILITY</endConsumerName>
<endConsumerAddress1>HOMEWOOD DT PROGRAM DEPT. 3</endConsumerAddress1>
<endConsumerAddress2>17341 PALMER BLVD.</endConsumerAddress2>
<endConsumerAddress3 />
<endConsumerCity>HOMEWOOD</endConsumerCity>
<endConsumerState>IL</endConsumerState>
<endConsumerPostalCode>60430</endConsumerPostalCode>
<endConsumerCountryCode />
<fillFacilityNumber>025</fillFacilityNumber>
<shpFacilityNumber>025</shpFacilityNumber>
<homeFacilityAbbrCode>STL</homeFacilityAbbrCode>
<homeFacilityNumber>015</homeFacilityNumber>
<multiCartonIndicator>Y</multiCartonIndicator>
<primaryCustomerIndicator>Y</primaryCustomerIndicator>
<shipToCustomerNumber>954371001</shipToCustomerNumber>
<customerCompanyID>01</customerCompanyID>
<customerTruckID>U888</customerTruckID>
<customerTruckDescription>UDS - ADDISON</customerTruckDescription>
<customerTruckDockID>13</customerTruckDockID>
<thirdPartyBillCarrier />
<thirdPartyBillID />
<thirdPartyBillType />
<qualityCheckIndicator>N</qualityCheckIndicator>
<warehouseLaydownID />
<packListPosition>I</packListPosition>
<preferredPackingType>CTN</preferredPackingType>
<preferredPackingMaterial>PAPER</preferredPackingMaterial>
<preferedPackingInstructions />
<totalOrderCartonQty>6</totalOrderCartonQty>
<convertAddressIndicator>N</convertAddressIndicator>
<dealerInstructionIndicator>Y</dealerInstructionIndicator>
<dealerinstructions1>CPO#: 623559</dealerinstructions1>
<dealerinstructions2>ATTN: DANA GRIFFIN</dealerinstructions2>
<dealerinstructions3>INFO: 612</dealerinstructions3>
<dealerinstructions4>ROUTE: ZNED UNTED</dealerinstructions4>
<dealerinstructions5 />
<dealerinstructions6 />
<shippingInstructionsIndicator>N</shippingInstructionsIndicator>
<shippingInstructions1 />
<shippingInstructions2 />
<shippingInstructions3 />
<shippingInstructions4 />
<shippingInstructions5 />
<shippingInstructions6 />
<specialInstructionsIndicator>N</specialInstructionsIndicator>
<specialInstructions1 />
<specialInstructions2 />
<customeContainerDesc />
- <carton>
<deliveryCartonID>253370905995</deliveryCartonID>
<shipIndicator>Y</shipIndicator>
<deliveryPalletID>X150</deliveryPalletID>
<consolidatedDeliveryCartonID />
<scanDateTime>2009-12-03T19:36:12.00</scanDateTime>
<cartonWeight>52</cartonWeight>
<dropShipFlag>1</dropShipFlag>
<carrierTrackingNumber />
<carrierZoneID>0</carrierZoneID>
<codAmount />
<customerPackageAmount />
<declaredValue />
<residentialDeliveryIndicator />
<serviceTypeCode>00</serviceTypeCode>
<ssccCode>006860244400829393</ssccCode>
- <Item>
<shipPrefix>UNV</shipPrefix>
<shipStockNumber>21200</shipStockNumber>
<itemDescription>PAPER XERO/DUP WE LTR 20#</itemDescription>
<orderQuantity>1</orderQuantity>
<originalShipQuantity>1</originalShipQuantity>
<shipQuantity>1</shipQuantity>
<inventoryUnitCode>CT</inventoryUnitCode>
<inventoryWeightQuantity>52.000</inventoryWeightQuantity>
<upcNumber>00000000000000</upcNumber>
<upcRetailCode>087547212004</upcRetailCode>
<hazmatIndicator>N</hazmatIndicator>
<serialRequiredIndicator>N</serialRequiredIndicator>
<dealerMemoPO>S</dealerMemoPO>
<cartonLineNumber>1</cartonLineNumber>
<orderLineNumber>11</orderLineNumber>
<originalOrderPrefix>UNV</originalOrderPrefix>
<originalOrderStockNumber>21200</originalOrderStockNumber>
<reasonCode />
- <Item_Serial>
<serialNumber />
</Item_Serial>
</Item>
</carton>
</order>
</Delivery>
</Shipment>
This is not the complete XML file as it exceeds the 15000 characters and then I cann't post here. So I have deleted much part of it.
The hierarchy is as following: Shipment->Delivery->Order->Carton->Item.
I have created a XSLT for it which is working fine.
But when I execute my report program it gives CX_SY_XSLT_FORMAT_ERROR saying that
Transformation error: Non-canonical structure of element name XML_OUTPUT.Dear experts,
My report program is as following:-
*& Report Z_ASNTRNS
REPORT Z_ASNTRNS.
*& Report Z_ASNTRNS
TYPE-POOLS: abap, ixml.
TABLES: ZASN_SHIPMENT,ZASN_DELIVERY,ZASN_ORDER,ZASN_CARTON,ZASN_ITEM.
*CONSTANTS gs_file TYPE string VALUE 'C:Documents and SettingsC5134126DesktopRajesh_kandakatlaSampleASNFile.xml'.
This is the structure for the data from the XML file
TYPES: BEGIN OF ts_item,
ZSHIPMENT LIKE ZASN_ITEM-ZSHIPMENT,
VBELN LIKE ZASN_ITEM-VBELN,
ORDER_NUMBER LIKE ZASN_ITEM-ORDER_NUMBER,
CARTON_ID LIKE ZASN_ITEM-CARTON_ID,
ITEM LIKE ZASN_ITEM-ITEM,
CARTON_LINE_NUM LIKE ZASN_ITEM-CARTON_LINE_NUM,
CARTON_LINE_NUMBER LIKE ZASN_ITEM-CARTON_LINE_NUM,
AEDAT(8),
AEZET(6),
ITEM_DESCRIPTION LIKE ZASN_ITEM-ITEM_DESCRIPTION,
ORD_QTY(16),
ORIGINAL_SHIP(16),
SHIP_QTY(16),
UPC_NUMBER LIKE ZASN_ITEM-UPC_NUMBER,
DEALER_MEMO_PO(5),
ORDER_LINE_NUM LIKE ZASN_ITEM-ORDER_LINE_NUM,
STATUS LIKE ZASN_ITEM-STATUS,
END OF ts_item.
TYPES: BEGIN OF ts_carton,
ZSHIPMENT LIKE ZASN_CARTON-ZSHIPMENT,
VBELN LIKE ZASN_CARTON-VBELN,
ORDER_NUMBER LIKE ZASN_CARTON-ORDER_NUMBER,
CARTON_ID LIKE ZASN_CARTON-CARTON_ID,
AEDAT(8),
AEZET(6),
SHIP_INDICATOR LIKE ZASN_CARTON-SHIP_INDICATOR,
TRACKING_NUMBER LIKE ZASN_CARTON-TRACKING_NUMBER,
ZZCARTON_WGT(18),
Item type ts_item,
END OF ts_carton.
TYPES: BEGIN OF ts_order,
ZSHIPMENT LIKE ZASN_ORDER-ZSHIPMENT,
VBELN LIKE ZASN_ORDER-VBELN,
ORDER_NUMBER LIKE ZASN_ORDER-ORDER_NUMBER,
AEDAT(8),
AEZET(6),
SUB_ORDER LIKE ZASN_ORDER-SUB_ORDER,
ORDER_DATE(8),
PRIMARY_ORDER LIKE ZASN_ORDER-PRIMARY_ORDER,
CUSTOMER_PO LIKE ZASN_ORDER-CUSTOMER_PO,
PRIMARY_ID LIKE ZASN_ORDER-PRIMARY_ID,
SHIP_TO LIKE ZASN_ORDER-SHIP_TO,
ANZPK(5),
carton type ts_carton,
END OF ts_order.
TYPES: BEGIN OF ts_delivery,
ZSHIPMENT LIKE ZASN_DELIVERY-ZSHIPMENT,
VBELN LIKE ZASN_DELIVERY-VBELN,
AEDAT(8) TYPE C,
AEZET(6) TYPE C,
PRIMARY_CUSTOMER LIKE ZASN_DELIVERY-PRIMARY_CUSTOMER,
BILL_OF_LADING LIKE ZASN_DELIVERY-BILL_OF_LADING,
CARTON_COUNT(5),
TOTAL_WEIGHT(18),
order type ts_order,
END OF ts_delivery.
TYPES: BEGIN OF ts_shipment,
ZSHIPMENT LIKE ZASN_SHIPMENT-ZSHIPMENT,
MANIFEST_DATE_TIME(25),
AEDAT(8) TYPE C,
AEZET(6) TYPE C,
SDATE(8) TYPE C,
STIME(6) TYPE C,
SFACILITY_NUMBER LIKE ZASN_SHIPMENT-SFACILITY_NUMBER,
ZZCARRIERCODE LIKE ZASN_SHIPMENT-ZZCARRIERCODE,
Delivery type ts_delivery,
END OF ts_shipment.
TYPES: BEGIN OF ts_shipment1,
ZSHIPMENT LIKE ZASN_SHIPMENT-ZSHIPMENT,
MANIFEST_DATE_TIME(25),
SFACILITY_NUMBER LIKE ZASN_SHIPMENT-SFACILITY_NUMBER,
ZZCARRIERCODE LIKE ZASN_SHIPMENT-ZZCARRIERCODE,
PRIMARY_CUSTOMER LIKE ZASN_DELIVERY-PRIMARY_CUSTOMER,
BILL_OF_LADING LIKE ZASN_DELIVERY-BILL_OF_LADING,
CARTON_COUNT(5),
TOTAL_WEIGHT(18),
ORDER_NUMBER LIKE ZASN_ORDER-ORDER_NUMBER,
SUB_ORDER LIKE ZASN_ORDER-SUB_ORDER,
ORDER_DATE(8),
PRIMARY_ORDER LIKE ZASN_ORDER-PRIMARY_ORDER,
CUSTOMER_PO LIKE ZASN_ORDER-CUSTOMER_PO,
PRIMARY_ID LIKE ZASN_ORDER-PRIMARY_ID,
SHIP_TO LIKE ZASN_ORDER-SHIP_TO,
CARTON_ID LIKE ZASN_CARTON-CARTON_ID,
SHIP_INDICATOR LIKE ZASN_CARTON-SHIP_INDICATOR,
TRACKING_NUMBER LIKE ZASN_CARTON-TRACKING_NUMBER,
ZZCARTON_WGT(18),
ITEM LIKE ZASN_ITEM-ITEM,
CARTON_LINE_NUM LIKE ZASN_ITEM-CARTON_LINE_NUM,
CARTON_LINE_NUMBER LIKE ZASN_ITEM-CARTON_LINE_NUM,
ITEM_DESCRIPTION LIKE ZASN_ITEM-ITEM_DESCRIPTION,
ORD_QTY(16),
ORIGINAL_SHIP(16),
SHIP_QTY(16),
UPC_NUMBER LIKE ZASN_ITEM-UPC_NUMBER,
DEALER_MEMO_PO(5),
ORDER_LINE_NUM LIKE ZASN_ITEM-ORDER_LINE_NUM,
END OF ts_shipment1.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
*Typdefinition für Airplus
*READ THE DOCUMENTATION "LASG_XML_INVOICE_BTM"!!!
VARs beginning with "a_" are ATTRIBUTES
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_parser TYPE REF TO if_ixml_parser,
l_istream TYPE REF TO if_ixml_istream,
l_ostream TYPE REF TO if_ixml_ostream,
l_document TYPE REF TO if_ixml_document,
l_node TYPE REF TO if_ixml_node,
l_xml TYPE REF TO cl_xml_document,
l_xmldata TYPE string.
DATA: l_xml_table TYPE TABLE OF t_xml_line,
l_xml_line TYPE t_xml_line,
l_xml_table_size TYPE i.
DATA: l_filename TYPE string.
DATA: xml_out TYPE string ,
size type i.
DATA: l_xml_x1 TYPE xstring.
DATA: l_len TYPE i,
l_len2 TYPE i,
l_tab TYPE tsfixml,
l_content TYPE string,
l_str1 TYPE string,
c_conv TYPE REF TO cl_abap_conv_in_ce.
l_itab TYPE TABLE OF string.
DATA: BEGIN OF l_itab occurs 0,
data(256) type c,
end of l_itab.
TYPES : BEGIN OF TY_TEXT,
data(255) type C,
END OF TY_TEXT.
DATA: F_XML TYPE STRING.
DATA : LT_TEXT_OUT type table of TY_TEXT with header line.
tables
DATA: it_shipment TYPE STANDARD TABLE OF ts_shipment,
wa_shipment TYPE ts_shipment.
*Errorvariables
DATA: xslt_err TYPE REF TO cx_xslt_exception,
err_string TYPE string.
PARAMETERS: pa_file TYPE localfile OBLIGATORY
DEFAULT 'C:Documents and SettingsC5134126DesktopRajesh_kandakatlaSampleASNFile.xml'.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.
here we use the CALL TRANSFORMATION method which calls
the XSLT program "z_asnfile"
TRY.
CALL TRANSFORMATION ('Z_ASNFILE')
SOURCE xml LT_TEXT_OUT[]
RESULT xml_output = it_shipment
catch any error, very helpful if the XSLT isn't correct
CATCH cx_xslt_exception INTO xslt_err.
err_string = xslt_err->get_text( ).
WRITE: / 'Transformation error: ', err_string.
EXIT.
ENDTRY." setting a breakpoint to watch the workarea
by the internal table "it_airplus"
break-point.
LOOP AT it_shipment INTO wa_shipment.
ENDLOOP.
*& Form get_xml_table
FORM get_xml_table CHANGING l_xml_table_size TYPE i
l_xml_table TYPE STANDARD TABLE.
l_filename = pa_file.
upload a file from the client's workstation
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_xml_table_size
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Convert binary to text.
CALL FUNCTION 'SCMS_BINARY_TO_TEXT'
EXPORTING
INPUT_LENGTH = 70000
FIRST_LINE = 0
LAST_LINE = 0
APPEND_TO_TABLE = ' '
MIMETYPE = ' '
WRAP_LINES = 'X'
IMPORTING
OUTPUT_LENGTH =
TABLES
BINARY_TAB = l_xml_table
TEXT_TAB = LT_TEXT_OUT
EXCEPTIONS
FAILED = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "get_xml_table -
String to XML using XSLT..
Hey folks
Am having a XML in a single string in ma request and wanna convert that into a XML. Tried that using XSLT but seems am missing out on some point...It works fine with Stylus but fails within PI
Following code am using :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://www.sdn.com/xslt">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:for-each select="//*:string">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The name of the element in which i get the whole XML is "string".
My request string is something liek this :
<xml version="1.0" encoding="UTF-8"?><ProductDefinition><RefNo>23232323</RefNo><Description>dfdfdfdfdf</Description></ProductDefinition>
Now am trying to generate a XML using the XSL but its failing in PI...
Kindly point out where am i going wrong?Thanks, but graphical mapping does not expose <![CDATAhttp:// ... ] to be removed. Surely this must be done with XSLT?+
Don't worry about <![CDATA ... pass your whole string in source message like this : <![CDATAhttp://<?xml version=\"1.0\" encoding=\"UTF-8\"?><ProductDefinition><RefNo>12345</RefNo><Description>Test</Description></ProductDefinition>]>
1st the graphical mapping where you use replace string will replace <?xml version=\"1.0\" encoding=\"UTF-8\"?> and then the XSLT mapping would get a input like this : <![CDATAhttp://<ProductDefinition><RefNo>12345</RefNo><Description>Test</Description></ProductDefinition>]> which would eventually form your target structure...
I tried it myself few days back so its a sure shot method ... just try it
Cheers!!!
Soumen -
String to XML conversion using XSLT
Hi all,
I have a scenario when my source input XML is in the form of a string which needs to be transformed into an XML target fields.
I am using XSLT mapping to do that and its working but unfortunately, input XML contain xml declaration <?xml version='1.0'?>. Because of which it fails.
I need to remove this. Can any body please suggest how to do this?
Any help will be appriciated.
Regards
-KulwantHi,
Refer these links
XI/PI: Convert Flat File to Deeply Nested XML Structures Using Only Graphical Mapping
Regards,
Surya -
How to update XML file using XSLT
Hi there,
I have a "small" issue with exporting data to an XML file using XSLT.
A two steps process is needed to import data from a non-hierarchical XML file into ABAP, change the data, and then update the XML file with new values. The problem is not trivial, since the format of the XML file is a complex one: there are many interdependent elements on the same level, pointing to each other by using id and ref attributes. Based on these values the data can be read and written into an internal table. I use XSLT and XPath for that. So the inbound process is done and seems to work correctly. I have to mention that the file contains much more data than I need. I am working only with a small part of it.
Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT? I can pass only the internal table to the transformation, so how do I access the XML file in order to update it? I have tried to use the <B>xsl:document()</B> function to access the content of the file store locally on my PC, but it fails each time by throwing and URI exception. I have tried the absolute path without any addition and the path with the file:/// addition. Same result. Please advise.
Many thanks,
Ferenc
P.S. Please provide me with links only if they are relevant for this very matter. I will not give points for irrelevant postings...Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
XSLT approach: check these online tutorial
http://www.xml.com/pub/a/2000/08/02/xslt/index.html
http://www.xml.com/pub/a/2000/06/07/transforming/index.html
ABAP approach:
for example you have the xml (original) in a string called say xml_out .
data: l_xml type ref to cl_xml_document ,
node type ref to if_ixml_node .
create object l_xml.
call method l_xml->parse_string
exporting
stream = xml_out.
node = l_xml->find_node(
name = 'IDENTITY'
ROOT = ROOT
l_xml->set_attribute(
name = 'Name'
value = 'Charles'
node = node
(the above example reads the element IDENTITY and sets attribute name/value to the same)
like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
so how do I access the XML file in order to update it?
you have already read this XML into a ABAP variable right?
Sorry couldnt understand your whole process, why do you need to read local XML file?
Raja -
Multi Mapping using condition & Dynamic Receiver determination – Used XSLT Mapping
Dear Experts,
I am struggling to identify an error on the Technical Routing. Firstly according to my scenario, I receive an XML file with multiple PO's and I have to split the file to 2 different target messages. and also according to the source payload I have to send the file to 2 different receivers. first receiver is ABAP Proxy to the back end system and the 2nd one is to a file location. I have used XSLT to split the message into 2 target message type and I have used a XSLT mapping for receiver determination. Does any one have any idea of what I am doing wrong.
Note: some time I will only be able to fill in on target message.
I have attached my XSLT message split mapping with this post, please let me know if you have further question.
Your help is more appreciated.
Advance Thanks,
Pradeep
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:variable name="vFlag"/>
<xsl:variable name="vPONUM" select="POTRACKING/Lines[1]/PONumber"/>
<xsl:template match="/">
<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
<ns0:Message1>
<ns1:MT_Tracking xmlns:ns1="http://www.findel-education.co.uk/axapta">
<xsl:for-each select="POTRACKING/Lines">
<sap:call-external class="ZCL_VNAP_OBJECTS" method="CHECK_PO_EXIST">
<sap:callvalue param="IP_EBELN" select="string(PONumber)"/>
<sap:callvariable name="vFlag" param="EP_BOLEAN" type="string"/>
</sap:call-external>
<xsl:if test="$vFlag = 0">
<Lines>
<DDate>
<xsl:value-of select="DespatchDate"/>
</DDate>
<PONumber>
<xsl:value-of select="PONumber"/>
</PONumber>
<POLine>
<xsl:value-of select="POLine"/>
</POLine>
<QTY>
<xsl:value-of select="Quantity"/>
</QTY>
<VendorMaterial>
<xsl:value-of select="VendorMaterialNumber"/>
</VendorMaterial>
<AccountRef>
<xsl:value-of select="AccountReference"/>
</AccountRef>
<ConsignNumber>
<xsl:value-of select="ConsignmentNumber"/>
</ConsignNumber>
<CarrierURL>
<xsl:value-of select="CarrierURL"/>
</CarrierURL>
<ConsignURL>
<xsl:value-of select="ConsignmentURL"/>
</ConsignURL>
</Lines>
</xsl:if>
</xsl:for-each>
</ns1:MT_Tracking>
</ns0:Message1>
<ns0:Message2>
<ns2:MT_Tracking xmlns:ns2="http://www.findel-education.co.uk/ecc/ax/po/ftp">
<xsl:for-each select="POTRACKING/Lines">
<sap:call-external class="ZCL_VNAP_OBJECTS" method="CHECK_PO_EXIST">
<sap:callvalue param="IP_EBELN" select="string(PONumber)"/>
<sap:callvariable name="vFlag" param="EP_BOLEAN" type="string"/>
</sap:call-external>
<xsl:if test="$vFlag = 1">
<Lines>
<DDate>
<xsl:value-of select="DespatchDate"/>
</DDate>
<PONumber>
<xsl:value-of select="PONumber"/>
</PONumber>
<POLine>
<xsl:value-of select="POLine"/>
</POLine>
<QTY>
<xsl:value-of select="Quantity"/>
</QTY>
<VendorMaterial>
<xsl:value-of select="VendorMaterialNumber"/>
</VendorMaterial>
<AccountRef>
<xsl:value-of select="AccountReference"/>
</AccountRef>
<ConsignNumber>
<xsl:value-of select="ConsignmentNumber"/>
</ConsignNumber>
<CarrierURL>
<xsl:value-of select="CarrierURL"/>
</CarrierURL>
<ConsignURL>
<xsl:value-of select="ConsignmentURL"/>
</ConsignURL>
</Lines>
</xsl:if>
</xsl:for-each>
</ns2:MT_Tracking>
</ns0:Message2>
</ns0:Messages>
</xsl:template>
</xsl:stylesheet>Hi Hareesh,
Please find my determination in the XSLT below, I am using enhanced receiver determination.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:p1="http://sap.com/xi/XI/System" xmlns:ns="urn:sap-com:document:sap:idoc:messages" version="1.0">
<xsl:variable name="vFlag"/>
<xsl:variable name="vAX" select="0"/>
<xsl:variable name="vSAP" select="0"/>
<xsl:variable name="vBoth" select="0"/>
<!-- <xsl:variable name="vPONUM" select="POTRACKING/Lines[1]/PONumber"/>-->
<xsl:template match="/">
<xsl:for-each select="POTRACKING/Lines">
<sap:call-external class="ZCL_VNAP_OBJECTS" method="CHECK_PO_EXIST">
<sap:callvalue param="IP_EBELN" select="string(PONumber)"/>
<sap:callvariable name="vFlag" param="EP_BOLEAN" type="string"/>
</sap:call-external>
<xsl:choose>
<xsl:when test="$vFlag = 0">
<!-- <p1:Receivers>
<Receiver>
<Service>
<xsl:text>BS_AXAPTA_TST</xsl:text>
</Service>
</Receiver>
</p1:Receivers>-->
<xsl:variable name="vAX" select="$vAX + 1"/>
</xsl:when>
<xsl:when test="$vFlag = 1">
<!-- <p1:Receivers>
<Receiver>
<Service>
<xsl:text>BS_ECQCLNT300</xsl:text>
</Service>
</Receiver>
</p1:Receivers>-->
<xsl:variable name="vSAP" select="$vSAP + 1"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:if test="$vSAP > 0">
<xsl:if test="$vAX > 0">
<xsl:variable name="vBoth" select="$vBoth + 1"/>
<xsl:variable name="vSAP" select="0"/>
<xsl:variable name="vAX" select="0"/>
</xsl:if>
</xsl:if>
<xsl:if test="$vBoth > 0">
<p1:Receivers>
<Receiver>
<Service>
<xsl:text>BS_AXAPTA_TST</xsl:text>
</Service>
</Receiver>
<Receiver>
<Service>
<xsl:text>BS_ECQCLNT300</xsl:text>
</Service>
</Receiver>
</p1:Receivers>
</xsl:if>
<xsl:if test="$vAX > 0">
<p1:Receivers>
<Receiver>
<Service>
<xsl:text>BS_AXAPTA_TST</xsl:text>
</Service>
</Receiver>
</p1:Receivers>
</xsl:if>
<xsl:if test="$vSAP > 0">
<p1:Receivers>
<Receiver>
<Service>
<xsl:text>BS_ECQCLNT300</xsl:text>
</Service>
</Receiver>
</p1:Receivers>
</xsl:if>
</xsl:template>
</xsl:transform> -
** How to use XSLT Stylesheet Ver 2.0 functions in XI 7.0?
Hi friends,
There are numerous built-in functions in SALT ver 2.0. Functions like upper-case, index-of, etc. They are very useful when use XSLT Mapping. But, unfortunately we are not able to use this functions in XSLT Mapping in XI. i.e XI throws an error like 'Transformation Configuration Error Occured'.
Friends your experience, kindly share your idea how do we to do in XSLT? Is any other alternate way there ?
Thanking you.
Yours friendly,
Jeg P.You could of course try to import your own Java XSLT 2.0 processor in a .jar file and in the same or another .jar, you could import the .xslt files.
Regards,
Henrique. -
Advantages of using XSLT mapping
Can any one explain me the advantages of using XSLT mapping compare to graphical.java and abap mappings
Hi
Please go through the below links for details on XSLT Mappings..
XSLT Mapping
/people/udo.martens/blog/2006/04/26/xslt-recursive-templates
Thread:
Sample XSLT mapping required
XSLT Mapping Links::->
/people/prasadbabu.nemalikanti3/blog/2006/03/30/xpath-functions-in-xslt-mapping
/people/sreekanth.babu2/blog/2005/01/05/design-time-value-mappings-in-xslt
/people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping
XSLT Mapping with java enhancement
/people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners
XSLT - ABAP.
/people/r.eijpe/blog/2005/11/04/using-abap-xslt-extensions-for-xi-mapping
exception handling errors in respect with XSLT mapping
http://help.sap.com/saphelp_nw2004s/helpdata/en/8a/7672f7d7e444439fd7024f806221a4/content.htm
Hope this will help
Regards
Piyush
**reward points if found useful. -
Using XSLT mapping to avoid File content conversion
Hi all,
Can we avoid FCC by using XSLT mapping? I have a scenario in which I have to avoid FCC in the adapter and save the file in a excel/csv format. I have been through the different blogs and forums in SDN.
I have been through Michal Krawczyk's Blog https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2803. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
Got a bit confused whether that blog serves my purpose. Expecting your valid inputs.
Thanks and regards,
Harikumar. SHi,
There are multiple ways in which you can avoid Content Conversion in the Sender / Receiver File adapters.
I think there was a heated discussion already regarding this in one of your earlier threads,
Read/Write csv files without file converter
Basically, if you want to avoid content conversion on the sender file adapter,
1. Write an Adapter Module. or,
2. Use a Java Mapping.
If you want to avoid content conversion on the receiver File adapter,
1,. Use a Adapter Modules or,
2. Use Java Or XSLTmapping ( XSLT can be used if the input to the mapping is XML and output needs to be say a Excel File etc).
Regards
Bhavesh -
Change Filename using XSLT mapping without variable subtitution
Hi,
My scenario is IDOC to file...i am using XSLT mapping, i want to change the filename format to OUT_<Purchase Number>_<DDMMYYYYhhmmss>_KKKK.txt, i cannot use UDF function as i do XSLT mapping i also i cannot use variable substitution as the target structure doesn't have PO and timestamp as tag elements. Can i acheive using writing a adapter module? I appreciate if anyone could help me with this..
Many thanks>
Ravibabu Adari wrote:
> Hi,
> If i go with Option1: what changes i need to do in the file adapter to tell the adapter to pick the filename from XSLT ?
> If i go with Option2: To which element to the target structure should i map the filename using UDF ? do i have to add additional element to the target structure? what changes i need to do in the file adapter to tell the adapter to pick the filename from Message mapping ?
>
> Many thanks
Hi,
in both cases you need to enable file adapter specific properties and enable the file name...
for this you need to use the dynamic configuration properties for the same...
usage of this option using udf in message mapping is rather easy than to use in XSLT...for this you dont need to change the structure in the message mapping...message mapping is just needed for execution of the udf.. thats it..
HTH
Rajesh -
How to skip first TWO Lines of .txt file using XSLT Mapping
Hi Friends ,
I have an .txt file in has the format as
<TEST>
4564564545
56456444566
56465
How can i skip the first two Lines when i am writing the XSLT Mapping ?
That <TEST> and empty line shouldn't go the rfc .
How can i skip and sent to rfc using XSLT Mapping ?
Best Regards .,
V.Rangarajanyou can avoid the empty lines in your File Content Conversion by defining offset.
<i>Under Document Offset, specify the number of lines that are to be ignored at the beginning of the document.
This enables you to skip comment lines or column names during processing. If you do not make an entry, the default value is zero lines.</i>
ref: http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm
then the generated XML after FCC will not have the empty lines. -
Sorting on specific field using XSLT Mapping
Hi All,
I am trying to sort the records on specific field using XSLT mapping.But I'm unable get the proper output for the following code.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://xxxxxxxx">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<a:T1>
<Row>
<xsl:for-each select="a:S1/Record">
<xsl:sort select="EmpID" />
<EMPID>
<xsl:value-of select="EmpID"/>
</EMPID>
<ENAME>
<xsl:value-of select="EmpName"/>
</ENAME>
</xsl:for-each>
</Row>
</a:T1>
</xsl:template>
</xsl:stylesheet>>
Currently getting following output :
http://www.flickr.com/photos/21390012@N04/2074799747/
Expected output should be like below :
http://www.flickr.com/photos/21390012@N04/2074807393/
Kindly send me suggestion to achieve this.
Regards
PullaraoHi ,
I donno much about srting in XSLT but i can give you one example on that.
Example :
This is how to sort numbers in xslt.
Try this :
<xsl:for-each select="learn[@kind='done']">
<xsl:sort select="number(@rank)" data-type="number"/>
<table border="00" cellpadding="3" width="100%">
<tr>
<td width="100" valign="top" align="right"><input type="checkbox" checked="checked" readonly="readonly"/></td>
<td width="10" valign="top" align="right"><xsl:value-of select="position()"/>. </td>
<td valign="top">
[<xsl:value-of select="@rank"/>] <xsl:value-of select="@title"/>
</td>
</tr>
</table>
<table border="00" cellpadding="3" width="100%">
<tr>
<td width="100"> </td>
<td valign="top">
<xsl:apply-templates/>
</td>
</tr>
</table>
</xsl:for-each>
Regards
Aashish Sinha
PS : reward points if helpful -
File TO File-Using XSLT mapping (for Beginners) --- Error in XSLT
Hi,
I am following this wiki (TO File-Using XSLT mapping (for Beginners))
https://wiki.sdn.sap.com/wiki/display/XI/FileTOFile-UsingXSLTmapping%28forBeginners%29
When creating Xslt from the MapForce, when I click on the XSLT Tab I am getting the following error
http://www.flickr.com/photo_zoom.gne?id=1216715484&size=o
How to correct this error ?.....
Thanks
srini
Message was edited by:
srinivasHello,
The XSD you are using is from Data Type and you are using it for mapping.
Instead export XSD for Message Type and also pass the XML schema for source that will solve the issue and your XSLT will be generated.
Regards,
Maybe you are looking for
-
How to update apps in a ZTE Open (with FFOS 2.0 custom build)?
I have a ZTE Open I regularly update trough custom builds. In particular, I updated it to the 2.0 version by: BRANCH=v2.0 VARIANT=user ./config.sh inari BRANCH=v2.0 VARIANT=user ./build.sh The operation has apparently been successful, and by the test
-
Apple TV needs reboot for every use
My second-gen ATV is connected to a Sony TV via HDMI. Every time I try to use the ATV it requires a hard restart by unplugging/replugging its power cord. How can I avoid this?
-
How do I get a firefox page to scroll down while trying to copy content
Previously, when using Google (via Mozilla) I was able to copy something from say ...Wikipedia, by highlighting and scrolling down through a few pages to gather the content I needed. Now it only scrolls to the bottom of the first page as far as my ta
-
SQL Server Standard Edition with Sharepoint 2013 Enterprise
Hi there, I need some help figuring out what will be the ideal SQL Server Standard Edition that can run all features for SharePoint 2013 Enterprise Edition. I ordered CAL licenses for a Sharepoint 2013 Enterprise Server (Supports 500 users). Now I ne
-
Programmatically use distributed caching in SharePoint 2013?
As per below TechNet article, developers are not allowed to use the AppFabric instance that comes with SharePoint 2013. The expectation is to deploy a seperate AppFabric cluster for custom applications. http://technet.microsoft.com/en-us/library/jj21