Date Difference in Months & Days using XSLT
Hi,
I have two dates and want to calculate how many months & days in between those using XSLT, do we have inbuilt functions to do the same?
E.g. Start Date: 05/25/2014
End Date: 12/31/2014
Desired Output: 7 Months & 7 days (end date included in calculation)
Thanks in advance.
Hi,
In XLST 2.0 (XPath 2.0) you can just use operator - to find difference between to dates, there's an example on link below...
http://stackoverflow.com/questions/5544762/finding-the-difference-between-2-dates-in-xslt
However, Oracle's implementation is not a full XSLT 2.0 (XPath 2.0), so it may not work... Please test it and let us know...
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="vDate1"
select="my:dateFromUsDate(/*/d1)"/>
<xsl:variable name="vDate2"
select="my:dateFromUsDate(/*/d2)"/>
<xsl:sequence select=
"($vDate1 - $vDate2) div xs:dayTimeDuration('P1D')"/>
</xsl:template>
<xsl:function name="my:dateFromUsDate" as="xs:date">
<xsl:param name="pUsDate" as="xs:string"/>
<xsl:sequence select=
"xs:date(concat(substring($pUsDate,7,4),
substring($pUsDate,1,2),
substring($pUsDate,4,2)
"/>
</xsl:function>
</xsl:stylesheet>
Cheers,
Vlad
Similar Messages
-
How can I find the difference between two dates in months?
I assume I can't do this:
Date firstDate = 4/1/2000;
Date secondDate = 6/1/2002;
int monDiff = secondDate - firstDate;
Also is it better to use java date or sql date?
thx.Here is a method that will compute the difference in years, months, and days. It's a bit more tricky that the previous post suggested when you take into account the day of the month. I'm not sure but I think that when you add a month to a date as in the suggested code you may have odd things happen when you go from Jan 31 to Feb to March since Feb may only have 28 days in it.
* Compute the difference between two dates in years, months, and days.
* The result is returned in a concatenated integer value of the form
* ymmdd. So the difference between Apr 20, 2003 and Apr 15, 2025 would
* be 211126 (21 years, 11 months, and 26 days) since 21 years and
* 11 months gets you to May 20 2025, there are 31 days in May of 2025,
* and it takes 25 days to go from May 20 2025 to April 15 2025! To split
* the values off,
* #years = return value / 10000,
* #months = return value % 10000 / 100
* #days = return value % 100.
* This method will return a negative value if the 'from' value is after the
* 'to' value (i.e. getDiff( from, to) = -getDiff( to, from )).
* @param pFrom The time to compute the difference from.
* @param pTo Date The time to compute the difference to.
* @return int The differenct in the two dates in the form ymmdd.
public static int getDiff( java.util.Date pFrom, java.util.Date pTo )
int lMultiplier = 1;
if ( pFrom.after( pTo ) );
lMultiplier = -1;
java.util.Date pTemp = pTo;
pTo = pFrom;
pFrom = pTemp;
Calendar lFrom = new GregorianCalendar();
lFrom.setTime( pFrom );
Calendar lTo = new GregorianCalendar();
lTo.setTime( pTo );
int lFromYear = lFrom.get( Calendar.YEAR );
int lFromMonth = lFrom.get( Calendar.MONTH );
int lFromDay = lFrom.get( Calendar.DAY_OF_MONTH );
int lToYear = lTo.get( Calendar.YEAR );
int lToMonth = lTo.get( Calendar.MONTH );
int lToDay = lTo.get( Calendar.DAY_OF_MONTH );
int lYearDiff = lToYear - lFromYear;
int lMonthDiff = lToMonth - lFromMonth;
int lDayDiff = lToDay - lFromDay;
if ( lDayDiff < 0 )
lMonthDiff--;
Calendar lTemp = new GregorianCalendar();
lTemp.setTime( pTo );
lTemp.add( lTemp.MONTH, -1 );
lDayDiff = lTemp.getActualMaximum( lTemp.DAY_OF_MONTH ) + lDayDiff;
if ( lMonthDiff < 0 )
lYearDiff--;
lMonthDiff = 12 + lMonthDiff;
return lMultiplier * ( lYearDiff * 10000 + lMonthDiff * 100 + lDayDiff );
} -
Date Calculate difference between 2 days using DateField
Hi,
I have 2 dateFields on stage. I hav2 a text box ,which I want
to display, the number of days difference, when I select datefield1
and then datefield2. The code I have is not working, can you please
point me in the right direction ?
I have done this successfully, with out the Datefield, but I
want to include the Datefield.
Thanks,
PaulYes, this helped - thank you very much. I converted the code to work with my table/column names and it worked, but only on the SQL/Object side, not on the app/item/form side. Again, I don't have a column in the table for this item, as I wanted to only do the calc on the app side. I just don't know how to pull this on the app side to make it display ok. I would like to see HH:MI as the item display.
I keep getting:
"ORA-06550: line 1, column 27: PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null continue avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe
ERR-1020 Error in PLSQL item processing (function)."
My code that fires ok in SQL Command is:
SELECT
TO_CHAR(sign_out, 'HH24:MI') sign_out,
TO_CHAR(signintime, 'HH24:MI') signintime,
(sign_out - signintime) * 24
FROM appointment
where appointment_id = 1
I even tried the following to make it simple, which fires ok as well:
SELECT sign_out-signintime from appointment where appointment_ID=1
Both of which provides a data response of:
SIGN_OUT-SIGNINTIME
+000000000 01:00:00.000000
....which is correct for record 1 (I'll remove the where ID=1 afterward so it's dynamic to the record being displayed of course)
Now to get this to function correctly on the app/item side? I can add the item, but don't know exactly how to define it, or any other necessary steps? Your help is greatly appreciated.
Thanks
Brad -
Hi there:
I've created a SSRS report based on OLAP cube. In this report, there is a date parameter which is used to filter out data.
Now , I want this report to be run and always retrieve data from previous day. I need to supply the date parameter with something
like SQL syntax: DATEADD(dd,-1,GETDATE()) . The question is how can I do that in the MDX world?
thanks
Hui
--Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --Hi Hui,
According to your description, you need to retrieve data from previous day, so you are looking for an expression in MDX which can achieve the requirement like SQL syntax: DATEADD(dd,-1,GETDATE()), right?
As per my understanding, it easy to achieve this requirement in report level ranther than in MDX query level. You can create another hidden parameter "Date2" using the expression below.
=DateAdd("d",-1,Parameters!Date.Value)
Then use Date2 parameter to filter in the query.
If don't want to create another parameter, you can use it like below.
Year =DatePart("yyyy",DateAdd("d",-1,Parameters!Date.Value))
Quarter =DatePart("qq",DateAdd("d",-1,Parameters!Date.Value))
Month =DatePart("mm",DateAdd("d",-1,Parameters!Date.Value))
Week =DatePart("ww",DateAdd("d",-1,Parameters!Date.Value))
Besides, DateAdd function is supported in MDX, please refer to the link below.
http://msdn.microsoft.com/en-us/library/hh510163.aspx
If I have anything miunderstand, please point it out.
Regards,
Charlie Liao
If you have any feedback on our support, please click
here.
Charlie Liao
TechNet Community Support -
Display 1 month day using connect by
Hi,
How can we display 1 month date say from 1 jan 2010 to 31 han 2010 using connect by function.Check this link http://www.orafaq.com/wiki/Oracle_Row_Generator_Techniques.
By
Vamsi -
Transforming XML data into SVG line charts using XSLT
Hi
I am trying to transform revenue data from an XML file into an SVG line chart. The problem is that I am quite new to XPath and XSLT and whereas I can draw the grid for my chart I struggle drawing the lines using the data from the XML doc.
The XML look something like the one below, and I would like to have one chart for each product and in each chart having the time on the x-axis and chart the revenue by regions.
Any help on this is much appreciated.
Thanks
Peter
<?xml version="1.0"?>
<revenue>
<caption>
<heading>My title</heading>
</caption>
<date name="01/01/2003">
<region name="Asia">
<product_a>30</product_a>
<product_b>12</product_b>
<product_c>301</product_c>
</region>
</date>
<date name="02/01/2003">
<region name="Asia">
<product_a>32</product_a>
<product_b>12</product_b>
<product_c>301</product_c>
</region>
<region name="America">
<product_a>57</product_a>
<product_b>31</product_b>
<product_c>457</product_c>
</region>
</date>
<date name="03/01/2003">
<region name="Asia">
<product_a>38</product_a>
<product_b>12</product_b>
<product_c>301</product_c>
</region>
<region name="America">
<product_a>31</product_a>
<product_b>9</product_b>
<product_c>357</product_c>
</region>
</date>
<date name="04/01/2003">
<region name="Asia">
<product_a>33</product_a>
<product_b>12</product_b>
<product_c>301</product_c>
</region>
<region name="America">
<product_a>43</product_a>
<product_b>16</product_b>
<product_c>430</product_c>
</region>
</date>
<date name="05/01/2003">
<region name="Asia">
<product_a>36</product_a>
<product_b>12</product_b>
<product_c>301</product_c>
</region>
<region name="America">
<product_a>54</product_a>
<product_b>1</product_b>
<product_c>561</product_c>
</region>
</date>
</revenue>You could try Jeni's XSLT utilities for SVG :
http://www.jenitennison.com/xslt/utilities/svg-utils.html
Specifically, the sample code provided, when a couple of SVG charts are being generated from XML data :
http://www.jenitennison.com/xslt/utilities/svg-example.html
Hope that helps. -
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 -
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 -
Hi,
I want to find the duration of stock in quality.
Is there any direct formula available to calculate the date difference.
Or I need to create a variable for this.
Thanks, JeetuHi,
You can also calculate date difference at query level using replacement path variables.
Check this link:-
http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
regards,
Pruthvi R -
Date difference in years,month,days should consider Leap Year
I would like to know how to compute the difference between two Date, and get the difference in years,months,days, PS. Should include New Year
Eg Date1 : 01/01/2000
Date2: 01/01/2005
Diff: years=5, months=0 days=1 for a leap year is included'2004'I would like to know how to compute the difference
between two Date, and get the difference in
years,months,days, PS. Should include New Year
Eg Date1 : 01/01/2000
Date2: 01/01/2005
Diff: years=5, months=0 days=1 for a leap year is
included'2004'If any program I was using gave me that result, I would consider it a bug. -
Convert two dates difference to number of years, months and days
Post Author: gigimonu
CA Forum: Formula
I wanted to write a formula (if there is a function I can use) that can convert a date difference to total number of years, months and days example
adate = 10/22/2006
?xdate = current date - adate (answer should be 1 years, 0 months and 0 days)
Please help
ThanksPost Author: V361
CA Forum: Formula
[Years, Months, Days]
DATEVAR FROMDATE := DATE(2000,01,01); // FROM DATE
DATEVAR TODATE := CURRENTDATE; // TO DATE
NUMBERVAR YEARS;
NUMBERVAR MONTHS;
NUMBERVAR DAYS;
STRINGVAR DIFF;
DATEVAR TEMP;
IF TODATE < FROMDATE THEN
(TEMP := TODATE;
TODATE := FROMDATE;
FROMDATE := TEMP);
YEARS := DATEDIFF('YYYY',FROMDATE,TODATE);
IF YEARS > 2 THEN
(YEARS := YEARS - 2;
TEMP := DATE(DATEADD("M",YEARS * 12,FROMDATE));)
ELSE
(YEARS := 0;
TEMP := FROMDATE);
WHILE TRUE DO
(TEMP := DATE(DATEADD('M',1,TEMP));
IF TEMP > TODATE THEN
EXIT WHILE;
MONTHS := MONTHS + 1);
DAYS := DATEDIFF('D',DATE(DATEADD('M',-1,TEMP)),TODATE);
IF MONTHS > 12 THEN
(YEARS := YEARS + INT(MONTHS/12);
MONTHS := MONTHS MOD 12);
DIFF := IIF(YEARS>0 ,TRIM(TOTEXT(YEARS,0)) & " YEARS " ,"0 YEARS ") &
IIF(MONTHS>0,TRIM(TOTEXT(MONTHS,0))& " MONTHS ","0 MONTHS ")&
IIF(DAYS>0 ,TRIM(TOTEXT(DAYS,0)) & " DAYS" ,"0 DAYS"); -
How to get the difference of two dates in years,months and days
Hi friends,
how to get the difference of two dates in years,months and days
for ex 2 years 3 months 13 days
select (sysdate-date_Start) from per_periods_of_service
thanksSomething like this...
SQL> ed
Wrote file afiedt.buf
1 with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
2 select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
3 select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
4 )
5 -- end of test data
6 select c_start_date, c_end_date
7 ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
8 ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
9 ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
10* from t
SQL> /
C_START_D C_END_DAT YRS MNTHS DYS
17-NOV-06 21-JAN-08 1 2 4
21-NOV-06 17-FEB-08 1 2 27
21-JUN-06 17-JUL-08 2 0 26
SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too. -
Find year,month & day between dates
Hi,
I need to find a number of years, months & day between a given dates. For example If a employee joined on 31.01.2003 and left on 01.06.2006, I need to find in between how many years, months & days he has worked. Is there any function module available .DATA: EDAYS LIKE VTBBEWE-ATAGE,
EMONTHS LIKE VTBBEWE-ATAGE,
EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
Call Function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = FROMDATE
i_date_to = TODATE
* I_FLG_SEPARATE = ' '
IMPORTING
E_DAYS = EDAYS
E_MONTHS = EMONTHS
E_YEARS = EYEARS.
WRITE:/ 'Difference in Days ', EDAYS.
WRITE:/ 'Difference in Months ', EMONTHS.
WRITE:/ 'Difference in Years ', EYEARS.
INITIALIZATION.
FROMDATE = SY-DATUM - 60.
Using teh abiove u can get difference but when u pass previous year u wont get the exact.
There is no seperate FM for this, u have to use three FM.
If possible using these three FM code u can create an FM.
<b>For years and months between two days:</b>
DATA: EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE PREL-BEGDA,
TODATE LIKE PREL-BEGDA DEFAULT SY-DATUM.
CALL FUNCTION 'COMPUTE_YEARS_BETWEEN_DATES'
EXPORTING
first_date = fromdate
* MODIFY_INTERVAL = ' '
second_date = todate
IMPORTING
YEARS_BETWEEN_DATES = EYEARS
* EXCEPTIONS
* SEQUENCE_OF_DATES_NOT_VALID = 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.
Write:/ eyears.
DATA: EMONTHS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE SY-DATUM,
TODATE LIKE SY-DATUM
DEFAULT SY-DATUM.
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = fromdate
i_datum_von = todate
* I_KZ_INCL_BIS = ' '
IMPORTING
E_MONATE = emonths
write:/ emonths
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = x_faede-zfbdt
I_DATUM_VON = p_fdat
I_KZ_EXCL_VON = '0'
I_KZ_INCL_BIS = '0'
I_KZ_ULT_BIS = ' '
I_KZ_ULT_VON = ' '
I_STGMETH = '0'
I_SZBMETH = '1'
IMPORTING
E_TAGE = dias_v.
IF SY-SUBRC <> 0.
ENDIF.
x_faede-zfbdt -> 20050915
p_fdat -> 20050811
dias_v = 4
try this and let me know.
Message was edited by:
Judith Jessie Selvi -
Display dates with zeros for month, day, year.
I have a date coming from a database as an int (20021215 means 12/15/2002). If the database gives me a "0", meaning no date value is assigned, then it should be displayed as "00/00/0000". The following code snippet works for the non-zero int database values ...
public static String formatDisplayDate(int date) {
String dateAsString = null;
if (date == 0) {
dateAsString = "00000000";
else {
dateAsString = Integer.toString(date);
String strYear = dateAsString.substring(0,4);
String strMonth = dateAsString.substring(4,6);
String strDay = dateAsString.substring(6);
int year = Integer.parseInt(strYear);
int month = (Integer.parseInt(strMonth)) - 1;
int day = Integer.parseInt(strDay);
DateFormat myFormat = DateFormat.getDateInstance(DateFormat.SHORT);
Calendar cal = myFormat.getCalendar();
cal.set(year, month, day);
Date myDate = cal.getTime();
String formattedDate = myFormat.format(myDate);
return formattedDate;
}Although I didn't really expect the zero values case to work, I am not sure how to implement it. How would I go about building a string using all zeros and still have it automatically display in the correct locale format?
Any help is appreciated.Thank you for your response. I agree a blank field would be better, but I think the "zeros" format is there to give the user an idea of expected date entry formatting, not that they'll necessarily follow it. I have made a few changes per your suggestions (shown below for the record, minus the exception handling), and it works perfectly.
public static String formatExternalDate8(int date) {
String dateAsString = null;
if (date == 0) {
dateAsString = "00010101";
else {
dateAsString = Integer.toString(date);
int year = Integer.parseInt(dateAsString.substring(0,4));
int month = (Integer.parseInt(dateAsString.substring(4,6))) - 1;
int day = Integer.parseInt(dateAsString.substring(6));
DateFormat myFormat = DateFormat.getDateInstance(DateFormat.SHORT);
Calendar cal = myFormat.getCalendar();
cal.set(year, month, day);
Date myDate = cal.getTime();
String formattedDate = myFormat.format(myDate);
if (date == 0) {
formattedDate = formattedDate.replace('1', '0');
return formattedDate;
}Thanks again for your assistance. -
When I view databases through Firefox, the date/day format is set at month, day, year (US style), whereas I need day, month, year, I work in the UK and the "wrong" format is VERY confusing and could lead to errors/mistakes. IE has that format but I don't want to revert to using that.
Gingerbread Man, thank you VERY much!! I followed your instructions and it works perfectly. I am a happy person :-))
Maybe you are looking for
-
Nokia c5-03 gallery & music player problem.
Hi... I've been using My c5-03 for a while now.. Yesterday after transferring songs from my pc a few problems have come up.. 1) the music player won't refresh but i can listen to songs though.. 2) the gallery dissent doesnt show any photos or videos
-
N96 V20 Update: Connection Lost during OTA update ...
Ok, I decided to update my N96 thru OTA this time. I chose "Check for New Updates" from the phone's menu but while checking if there was a new update, the phone told me "the connection was lost!" with the WLAN modem. I am now little concerned about u
-
My iPhone will connect with my Goodmans bluetooth speaker but my macbook pro will not, even though it will pair with it and 'sees' it
-
ALL-PHOTOS-VIDEOS buttons don't work in iOS app
Hi there! I just downloaded the Revel iOS app which I found amazing! The best memories cloud storage solution I've found so far! I found an issue with the app, when watching all the photos in a library, the ALL PHOTOS VIDEOS buttons don't work at all
-
Help with selecting chuncks of data from a table
Hi all, I need help with a query that should do the following. I have a table with vessel messages, and I need to get the last "NumMsgs" messages from a group of vessels. The problem I have is that if I order the table by Vessel_ID, MessageDate DESC,