Convert Date Time field to Date & Time

Post Author: Smita
CA Forum: Crystal Reports
I am new to Crystal XI  . I need to convert DateTime ("2007/04/04/04 09:49:05:00") format to Date and Time and then group a months data first by date and then by Time ( per Hour ).
If someone can help ?
Thanks

Post Author: newcruser
CA Forum: Crystal Reports
Thanks
This is easy...second group based on the second formula 'for each hour'.
How you group by 15 minutes?.
i want to group by every 15 minutes starting from 9 AM to 5 PM.
First i need to create a time range and then use that time range to group?.  Or any other simple and best way to solve this?. Please help
How to create time range from 9 AM to 5 PM?

Similar Messages

  • [Forum FAQ] How to convert data of date time's type stored in database to display Time Zone based on different territories?

    Introduction:
    There is a date’s type field in the database. When using the field in the report, clients want to convert the field’s values based on own Time Zone to show the date field.
    Workaround:
    Currently, Reporting Services doesn’t provide the function that can get the Time Zone of a client machine. To work around the issue, you need to add a custom code in the report to convert Time Zone and create a parameter through which the client users can
    select his/her Time Zone, and then pass the parameter value to the custom function. Please see the details as follows:
    1. Click the Report, select Report Properties and add the custom code as the screenshot shown:
    Custom code:
    Shared Function FromUTC (ByVal d As Date, ByVal tz As String) As Date
    Return (TimeZoneInfo.ConvertTimeBySystemTimeZoneId(d, TimeZoneInfo.Utc.Id, tz))
    End Function
    2. Create a parameter named TimeZone (you can name the parameter according to your requirement), select Available value and click Specify values.
    Label                                                               
    Value
    China Standard Time                                        
    China Standard Time
    Central European Time Zone                              Central European Time Zone
    India Time Zone                                               
    India Time Zone
    United States of America Time zones                   United States of America Time zones
    3. Call the custom code and type the expression to convert the Time Zone as follows:
    =Code.FromUTC(Fields!UTCDateFromDatabase.Value,Parameters!TimeZone.Value)
    Note: If you use the expression “=Code.FromUTC(Fields!UTCDateFromDatabase.Value,TimeZone.CurrentTimeZone.StandardName)”, it cannot achieve the goal because TimeZone.CurrentTimeZone.StandardName gets the TimeZone of Report Server side rather than Client side.
    More information:
    TimeZone Class
    http://msdn.microsoft.com/en-us/library/system.timezone(v=vs.110).aspx
    Applies to
    Microsoft SQL Server 2005
    Microsoft SQL Server 2008
    Microsoft SQL Server 2008 R2
    Microsoft SQL Server 2012

    Hello,
    Please read the answer provided by Kalman on the following thread:
    http://social.technet.microsoft.com/Forums/es-ES/446df85a-7ad8-4891-8748-478a26350c5c/how-to-compare-tables-in-two-different-servers-while-one-of-the-server-name-has-a-?forum=transactsql
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • How convert date/time from xml in xdp(Designer)?

    Hi, i want to convert date/time format from xml in Designer, date/time value in xml is NOT in common format YYYY-MM-DD (if is in a common format i can do this with pattern)
    I have a "DateTime" Field in Xdp can get from Xml date and time:
    In XML <DateTime>DD-MM-YYYY</DateTime> i want to convert in XDP in DateTime Field in "DD-April-YYYY"
    Can i do this?

    You can do this way..
    Bind the date field to your XML tag.
    Set the display pattern for the date field.
    In the initialize event of the date field place the following code.
    Set JavaScript as language.
    var dtStr = this.rawValue;
    var pos1=dtStr.indexOf("-");
    var pos2=dtStr.indexOf("-",pos1+1);
    var strMonth=dtStr.substring(0,pos1);
    var strDay=dtStr.substring(pos1+1,pos2);
    var strYear=dtStr.substring(pos2+1);
    //Assign the formatted value to the Date field.
    this.rawValue = strYear + "-" + strMonth + "-" + strDay;
    Thanks
    Srini

  • Conversion failed when converting date and/or time from character string

    Hi experts,
    I'm trying running a query in Microsoft Query but it gives the following error message:
    "conversion failed when converting date and/or time from character string"
    when asks me the data I'm inserting 31-01-2014
    i've copy the query form the forum:
    SELECT T1.CardCode, T1.CardName, T1.CreditLine, T0.RefDate, T0.Ref1 'Document Number',
         CASE  WHEN T0.TransType=13 THEN 'Invoice'
              WHEN T0.TransType=14 THEN 'Credit Note'
              WHEN T0.TransType=30 THEN 'Journal'
              WHEN T0.TransType=24 THEN 'Receipt'
              END AS 'Document Type',
         T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')<=-1),0) 'Future'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=0 and DateDiff(day, T0.DueDate,'[%1]')<=30),0) 'Current'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>30 and DateDiff(day, T0.DueDate,'[%1]')<=60),0) '31-60 Days'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>60 and DateDiff(day, T0.DueDate,'[%1]')<=90),0) '61-90 Days'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>90 and DateDiff(day, T0.DueDate,'[%1]')<=120),0) '91-120 Days'
         ,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=121),0) '121+ Days'
    FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    WHERE (T0.MthDate IS NULL OR T0.MthDate > ?) AND T0.RefDate <= ? AND T1.CardType = 'C'
    ORDER BY T1.CardCode, T0.DueDate, T0.Ref1

    Hi,
    The above error appears due to date format is differnt from SAP query generator and SQL server.
    So you need convert all date in above query to SQL server required format.
    Try to convert..let me know if not possible.
    Thanks & Regards,
    Nagarajan

  • Error "Conversion failed when converting date and/or time from character string" to execute one query in sql 2008 r2, run ok in 2005.

    I have  a table-valued function that run in sql 2005 and when try to execute in sql 2008 r2, return the next "Conversion failed when converting date and/or time from character string".
    USE [Runtime]
    GO
    /****** Object:  UserDefinedFunction [dbo].[f_Pinto_Graf_P_Opt]    Script Date: 06/11/2013 08:47:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE   FUNCTION [dbo].[f_Pinto_Graf_P_Opt] (@fechaInicio datetime, @fechaFin datetime)  
    -- Declaramos la tabla "@Produc_Opt" que será devuelta por la funcion
    RETURNS @Produc_Opt table ( Hora datetime,NSACOS int, NSACOS_opt int)
    AS  
    BEGIN 
    -- Crea el Cursor
    DECLARE cursorHora CURSOR
    READ_ONLY
    FOR SELECT DateTime, Value FROM f_PP_Graficas ('Pinto_CON_SACOS',@fechaInicio, @fechaFin,'Pinto_PRODUCTO')
    -- Declaracion de variables locales
    DECLARE @produc_opt_hora int
    DECLARE @produc_opt_parc int
    DECLARE @nsacos int
    DECLARE @time_parc datetime
    -- Inicializamos VARIABLES
    SET @produc_opt_hora = (SELECT * FROM f_Valor (@fechaFin,'Pinto_PRODUC_OPT'))
    -- Abre y se crea el conjunto del cursor
    OPEN cursorHora
    -- Comenzamos los calculos 
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    /************  BUCLE WHILE QUE SE VA A MOVER A TRAVES DEL CURSOR  ************/
    WHILE (@@fetch_status <> -1)
    BEGIN
    IF (@@fetch_status = -2)
    BEGIN
    -- Terminamos la ejecucion 
    BREAK
    END
    -- REALIZAMOS CÁLCULOS
    SET @produc_opt_parc = (SELECT dbo.f_P_Opt_Parc (@fechaInicio,@time_parc,@produc_opt_hora))
    -- INSERTAMOS VALORES EN LA TABLA
    INSERT @Produc_Opt VALUES (@time_parc,@nsacos, @produc_opt_parc)
    -- Avanzamos el cursor
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    END
    /************  FIN DEL BUCLE QUE SE MUEVE A TRAVES DEL CURSOR  ***************/
    -- Cerramos el cursor
    CLOSE cursorHora
    -- Liberamos  los cursores
    DEALLOCATE cursorHora
    RETURN 
    END

    You can search the forums for that error message and find previous discussions - they all boil down to the same problem.  Somewhere in your query that calls this function, the code invoked implicitly converts from string to date/datetime.  In general,
    this works in any version of sql server if the runtime settings are correct for the format of the string data.  The fact that it works in one server and not in another server suggests that the query executes with different settings - and I'll assume for
    the moment that the format of the data involved in this conversion is consistent within the database/resultset and consistent between the 2 servers. 
    I suggest you read Tibor's guide to the datetime datatype (via the link to his site below) first - then go find the actual code that performs this conversion.  It may not be in the function you posted, since that function also executes other functions. 
    You also did not post the query that calls this function, so this function may not, in fact, be the source of the problem at all. 
    Tibor's site

  • SAP query error - 1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string.  'Received Alerts' (OAIB)

    SAP query error - 1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting date and/or time from character string.  'Received Alerts' (OAIB)
    SELECT    
    CASE WHEN T0.DocStatus = 'O' THEN 'OPEN'
    WHEN T0.DocStatus = 'C' THEN 'CLOSED'  END  AS 'Document Status',
    T0.DocDate AS 'Posting Date',
    T0.DocNum AS 'Doc.No',
    T0.NumAtCard,
    T0.TransId AS 'Trans. No.',
    T0.Comments AS 'Remarks',
    T0.CardCode AS 'Offset Acct',
    T0.CardName AS 'Offset Acct Name',
    sum(T0.DocTotal) + (T0.WTSum) as 'DocTotal',
    T3.DueDate AS 'Cheque Date',
    T3.CheckSum AS 'Amount'
    FROM         ODPO AS T0 LEFT OUTER JOIN
                          VPM2 AS T1 ON T0.ObjType = T1.InvType AND T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
         OVPM AS T2 ON T2.DocEntry = T1.DocNum LEFT OUTER JOIN
                          VPM1 AS T3 ON T2.DocEntry = T3.DocNum
    where T0.DocDate>='[%0]' and T0.DocDate<='[%1]'

    Hi,
    Try this:
    SELECT   
    CASE WHEN T0.DocStatus = 'O' THEN 'OPEN'
    WHEN T0.DocStatus = 'C' THEN 'CLOSED'  END  AS 'Document Status',
    T0.DocDate AS 'Posting Date',
    T0.DocNum AS 'Doc.No',
    T0.NumAtCard,
    T0.TransId AS 'Trans. No.',
    T0.Comments AS 'Remarks',
    T0.CardCode AS 'Offset Acct',
    T0.CardName AS 'Offset Acct Name',
    sum(T0.DocTotal) + (T0.WTSum) as 'DocTotal',
    T3.DueDate AS 'Cheque Date',
    T3.CheckSum AS 'Amount'
    FROM         ODPO  T0 LEFT OUTER JOIN
                          VPM2  T1 ON T0.ObjType = T1.InvType AND T0.DocEntry = T1.DocEntry
    LEFT OUTER JOIN
         OVPM  T2 ON T2.DocEntry = T1.DocNum LEFT OUTER JOIN
                          VPM1  T3 ON T2.DocEntry = T3.DocNum
    where T0.DocDate >= '[%0]' and T0.DocDate <='[%1]'
    group by T0.DocStatus,T0.DocDate ,
    T0.DocNum ,
    T0.NumAtCard,
    T0.TransId ,
    T0.Comments ,
    T0.CardCode,
    T0.CardName ,
    T0.WTSum ,
    T3.DueDate ,
    T3.CheckSum
    Thanks & Regards,
    Nagarajan

  • Can I convert Facebook time Text to Project Siena's Date value ?

    Can I convert Facebook time Text to Project Siena's Date value ?
    I want to show create_time on screen by my Localtime formatted text.
    Facebook time Text = 2014-07-14T11:22+0000
    I want to show = 2014/07/14 18:22
    My Time Zone is +09:00, Osaka/Japan.
    Currently I try it by Text/Replace/Replace/Replace/Left/DateValue/+ , etc.
    And I ask more simple way.
    Regards,
    Yoshihiro Kawabata

    Thank you Andy , and Robin, I can.
    Text(TimeValue(Substitute(ThisItem!created_time,"+0000",".000Z")),"yyyy/mm/dd hh:mm")
    At Facebook Albums's Gallary, I can convert from Facebook created_time to Localtime Text DateTime.
    and I hope more easy way like Excel Power Query's one.
    Regards,
    Yoshihiro Kawabata

  • Can I convert Twitter time Text to Project Siena's Date Value ?

    Can I convert Twitter time Text to Project Siena's Date Value ?
    I want to show localtime of Twitter created_at.
    Twitter time text = ThisItem!created_at , ex: Tue Jul 15 17:19:00 +0000 2014
    I want to show 2014/07/16 02:19 by Japan localtime.
    Regards,
    Yoshihiro Kawabata

    Siena uses JavaScript to parse date/times, via the TimeValue function. A good specification regarding what is acceptable can be found here:
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
    The example above is truly bizarre: I thought I had seen it all. You will need to turn that form into one of those listed on the above site, using string functions to chop it up and reassemble it into a saner form.

  • Convert Data time stamp to Local Time

    Hello,
    I want to convert this input to local time EST.
    Input:12/8/2006 10:23:00.000000000 PM -06:00
    o/p: EST.Local Time

    Is the input a string? A timestamp? If so, which flavor of timestamp? Something else?
    Normally, you'd want to use a TIMESTAMP WITH LOCAL TIME ZONE data type for this sort of requirement, since it automatically converts data to the client's time zone. Assuming the input is a string and that the client's time zone is set to EST
      1  select cast(to_timestamp_tz( '12/8/2006 10:23:00.000000000 -06:00',
      2                               'MM/DD/YYYY HH24:MI:SS.FF TZH:TZM' )
      3                AS TIMESTAMP WITH LOCAL TIME ZONE)
      4*   from dual
    SCOTT @ nx102 JCAVE9420> /
    CAST(TO_TIMESTAMP_TZ('12/8/200610:23:00.000000000-06:00','MM/DD/YYYYHH24:MI
    08-DEC-06 11.23.00.000000 AM
    Elapsed: 00:00:00.01
    SCOTT @ nx102 JCAVE9420> Justin

  • FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.

    HI EXPERTS,
         FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.
    PLS DO HELP.....

    Hiii gita
    we have another FM SPELL_AMOUNT
    regards
    Jaipal

  • Convert date time local Timezone  to GMT

    I need to get GMT time...
    How to convert local time to GMT ?
         public static long getGMTNow()
             Calendar local = new GregorianCalendar();
             local.set(Calendar.HOUR_OF_DAY, 0);              
             local.set(Calendar.MINUTE, 0);
             local.set(Calendar.SECOND, 0);
             System.out.println(local.getTime());
             System.out.println(local.getTimeInMillis());
             Calendar gmtC = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
             gmtC.setTimeInMillis(local.getTimeInMillis());
             System.out.println(gmtC.getTime());
             return gmtC.getTimeInMillis();
         }Result :
    Thu Feb 12 00:00:00 EST 2009
    1234414800034
    Thu Feb 12 00:00:00 EST 2009
    1234414800034

    Calendar gpsTime = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
             gpsTime.set(Calendar.HOUR_OF_DAY, 10);              
             gpsTime.set(Calendar.MINUTE, 0);
             gpsTime.set(Calendar.SECOND, 0);
             System.out.println("gpsTime: "+gpsTime.getTime());
             Calendar realtime= new GregorianCalendar();
             realtime.set(Calendar.HOUR_OF_DAY, 5);              
             realtime.set(Calendar.MINUTE, 0);
             realtime.set(Calendar.SECOND, 0);
             System.out.println("realtime: "+realtime.getTime());
             System.out.println("COMPARETO : "+ realtime.compareTo(gpsTime));
             long timediff = realtime.getTimeInMillis() - gpsTime.getTimeInMillis();
             System.out.println(timediff/1000 + " sec");RESULT :
    gpsTime: Mon Feb 16 05:00:00 EST 2009
    realtime: Mon Feb 16 05:00:00 EST 2009
    COMPARETO : 1
    0 secOk, I done my homework. getTime() will allways return local time so I need to set the GPS time to a GMT Calendar to get the right result.
    Funny thing, look at the compareTo result....

  • GRR2- 4FM-RepPaint(put ABAP code for convert data in field)

    Hi,
    If somebody know how possible add ABAP code for convert data in some column-field of report (by RepWriter,UserExit,BADI)?
    Thanks a lot.

    Elaborate your question. Not clear ??

  • ALE, use bd79 (converting data from sender to receiver to blank out fields)

    Hi, I am trying to blank four fields out in our FI IDOC for a certain business reason.  These fields must be blank (it is the FIDCC1 message type).   I am trying to use transaction bd79 (converting data from sender to receiver) maintain rules.  Is there a way to blank out these fields using a conversion rule?  I can change data fine but I cannot find a way to blank or null a field out.  Thanks in advance.

    You should have a look at the inbound function module (linked to your inbound process code). sometimes there are checks that if fields are initial that nothing will be changed.

  • How to convert epoch time to datetime in sql*loader Oracle

    Hello,
    I wan't to question how to convert epoch time to datetime in sql*loader Oracle. I try this script for convert epoch time to datetime in sql*loader, but error:
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    This is my loader:
    LOAD DATA INFILE 'C:\Documents and Settings\Administrator\My Documents\XL_EXTRACT_211\load.csv'
    into table TEMP_TEST_LANGY append
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    DATADATA CHAR "TO_DATE('01-JAN-1970','DD-MON-YYYY')+:datadata/86400"
    This is my csv file:
    79314313.7066667
    79314336.2933333
    79314214.3466667
    This is my table:
    CREATE TABLE TEMP_TEST_LANGY
    DATADATA DATE
    Thanks
    Edited by: xoops on Sep 21, 2011 8:56 AM
    Edited by: xoops on Sep 21, 2011 8:58 AM

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

  • Convert data to MSWORD, MSEXCEL or PDF

    Hi,
    I have a requirement of sending SAP std report output as an attachment via email. I am thinking of using SUBMIT TO MEMORY or SPOOL and then get the data from there and convert and send as file attachment using SO_DOCUMENT_SEND_API1 or class CL_BCS. The file is required to be sent as MSWORD or MSEXCEL or PDF which can be decided by having a parameter on selection screen..
    But I am not sure on how to convert data after retrieving it back from Memory or spool. There are a few function modules to convert. Can anyone give me the names please in each case like
    For Spool to PDF function CONVERT_ABAPSPOOLJOB_2_PDF can be used
    For Spool to Excel ?
    For Spool to Word ?
    For memory to PDF ?
    For memory to Word ?
    For memory to Excel ?
    Regards,
    Vin

    Hi,
    I just had the same reuirement and i did it few days back . here is the code ...juz modify it accordingly.
    The program will send my ABAP report as a PDF attachment to the USER>
    REPORT  ZRMM0055  NO STANDARD PAGE HEADING
                      MESSAGE-ID ZZ
                      LINE-SIZE 255
                      LINE-COUNT 65.
                        TABLES DECLARATION                               *
    TABLES : MARD,          " Storage Location Data for Material
             MARC,          " Plant Data for Material
             MSEG,
             SSCRFIELDS.    " Fields on selection screens
                       Internal Tables declaration.                      *
    *---Internal Table to hold the MARD table data
    DATA : BEGIN OF IT_MARD OCCURS 0,
           MATNR LIKE MARD-MATNR,          " Material Number
           WERKS LIKE MARD-WERKS,          " Plant
           LGORT LIKE MARD-LGORT,          " Storage Location
           LMINB LIKE MARD-LMINB,          " Reorder Point
           LABST LIKE MARD-LABST,          " Stock at storage loc
           END OF IT_MARD.
    *---Internal table to hold data from MSEG, MKPF, MAKT
    DATA : BEGIN OF IT_MSEG OCCURS 0,
           MATNR LIKE MARD-MATNR,          " Material Number
           WERKS LIKE MARD-WERKS,          " Plant
           LGORT LIKE MARD-LGORT,          " Storage Location
           MENGE LIKE MSEG-MENGE,          " Quantity
           MEINS LIKE MSEG-MEINS,          " UOM
           LIFNR LIKE MSEG-LIFNR,          " Account Number of Vendor
           SHKZG LIKE MSEG-SHKZG,          " Credit/Debit Indicator
           EBELN LIKE EKPO-EBELN,
           MENGE1 LIKE EKPO-MENGE,         " Open PO qty
           EINDT LIKE EKET-EINDT,
           DISPO LIKE MARC-DISPO,          " MRP controller
           EKGRP LIKE MARC-EKGRP,          " Purchasing Group
           MAKTX LIKE MAKT-MAKTX,
           END OF IT_MSEG.
    *----Internal table to hold the data from EKPO and EKET table
    DATA : BEGIN OF IT_EKPO OCCURS 0,
           EBELN LIKE EKPO-EBELN,          " PO document
           EBELP LIKE EKPO-EBELP,          " Item
           MATNR LIKE MARD-MATNR,          " Material Number
           WERKS LIKE MARD-WERKS,          " Plant
           LGORT LIKE MARD-LGORT,          " Storage Location
           MENGE LIKE EKPO-MENGE,          " Quantity
           EINDT LIKE EKET-EINDT,          " Delivery Date
           END OF IT_EKPO.
    *--Internal Table to hold the final data
    DATA : BEGIN OF IT_FINAL OCCURS 0,
           MATNR LIKE MARD-MATNR,          " Material Number
           MAKTX LIKE MAKT-MAKTX,          " Material Description
           LMINB LIKE MARD-LMINB,          " Reorder Point
           MEINS LIKE MSEG-MEINS,          " UOM
           LABST LIKE MARD-LABST,          " On hand inventory at storageloc
           TOT_LABST LIKE MARD-LABST,      " Total On hand at plant
           ISSUE LIKE MSEG-MENGE,          " YTD issue
           RECEIPT LIKE MSEG-MENGE,        " YTD receipts
           DISPO LIKE MARC-DISPO,          " MRP controller
           EKGRP LIKE MARC-EKGRP,          " Purchasing Group
           MENGE LIKE EKPO-MENGE,          " Open PO Quantity
           EINDT LIKE EKET-EINDT,          " Next Delivery Date
           LIFNR LIKE MSEG-LIFNR,          " Vendor
           EBELN LIKE MSEG-EBELN,          " PO number
           END OF IT_FINAL.
    *----Internal table to hold YTD data
    DATA : BEGIN OF IT_YTD OCCURS 0,
           MENGE LIKE MSEG-MENGE,
           MEINS LIKE MSEG-MEINS,
           SHKZG LIKE MSEG-SHKZG,
           END OF IT_YTD.
    DATA : BEGIN OF X_MSEG,
           MBLNR LIKE MSEG-MBLNR,
           MJAHR LIKE MSEG-MJAHR,
           MATNR LIKE MARD-MATNR,          " Material Number
           WERKS LIKE MARD-WERKS,          " Plant
           LGORT LIKE MARD-LGORT,          " Storage Location
           MENGE LIKE MSEG-MENGE,          " Quantity
           MEINS LIKE MSEG-MEINS,          " UOM
           LIFNR LIKE MSEG-LIFNR,          " Account Number of Vendor
           SHKZG LIKE MSEG-SHKZG,          " Credit/Debit Indicator
           EBELN LIKE EKPO-EBELN,
           MENGE1 LIKE EKPO-MENGE,         " Open PO Qty
           EINDT LIKE EKET-EINDT,
           DISPO LIKE MARC-DISPO,          " MRP controller
           EKGRP LIKE MARC-EKGRP,          " Purchasing Group
           MAKTX LIKE MAKT-MAKTX,
           END OF X_MSEG.
    DATA: V_LMINB(16) TYPE C,
          S_LABST(16) TYPE C,
          V_TOT_LABST(16) TYPE C,
          S_ISSUE(16) TYPE C,
          S_RECEIPT(16) TYPE C,
          V_MENGE(16) TYPE C,
          V_EINDT(8) TYPE C.
    DATA: T_PDF LIKE TLINE OCCURS 100 WITH HEADER LINE.
                    VARIABLES DECLARATION                                *
    DATA : V_SUM TYPE MSEG-MENGE,      " Variable for adding GI's to Stock
           V_TEMP TYPE MSEG-MENGE,      " Variable for adding GI's to Stock
           V_TABIX TYPE SY-TABIX,      " Loop count
           V_ISSUE LIKE MSEG-MENGE,    " Variable for calculating YTD issues
           V_RECEIPT LIKE MSEG-MENGE,  " Var for Calculating YTD Receipts
           V_LABST LIKE MARD-LABST,    " Var for Total On hand inv at plant
           V_MJAHR LIKE MSEG-MJAHR,    " Variable for holding the Year
           f_color.
    *----Declaration to send Email
    DATA: IT_PDF          LIKE TLINE      OCCURS 10 WITH HEADER LINE,
          IT_XI_PDF       LIKE TLINE      OCCURS 0  WITH HEADER LINE,
          IT_HTML         LIKE SOLISTI1   OCCURS 0  WITH HEADER LINE,
          IT_XI_TEMP      LIKE BAPIQCMIME OCCURS 0  WITH HEADER LINE,
          IT_XI_MIME(255) TYPE C          OCCURS 0  WITH HEADER LINE.
    DATA:
       LS_DOCDATA    TYPE SODOCCHGI1,
       LT_OBJPACK    TYPE TABLE OF SOPCKLSTI1 WITH HEADER LINE,
       LT_OBJHEAD    TYPE TABLE OF SOLISTI1   WITH HEADER LINE,
       LT_OBJTXT     TYPE TABLE OF SOLISTI1   WITH HEADER LINE,
       LT_OBJBIN     TYPE TABLE OF SOLISTI1   WITH HEADER LINE,
       LT_RECLIST    TYPE TABLE OF SOMLRECI1  WITH HEADER LINE,
       LT_LISTOBJECT TYPE TABLE OF ABAPLIST   WITH HEADER LINE,
       LT_LISTOBJECTLN(1000) TYPE C,
       L_TAB_LINES TYPE I,
       L_ATT_TYPE  LIKE SOODK-OBJTP.
    DATA: IT_OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
    Internal table for Single List with Column Length 255
    DATA : IT_OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    Internal table for Single List with Column Length 255
    DATA : IT_OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    Internal table for Structure of the API Recipient List
    DATA : IT_RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
    Structure of the API Recipient List
    DATA: X_DOC_CHNG LIKE SODOCCHGI1.
                            SELECTION-SCREEN                             *
    SELECTION-SCREEN BEGIN OF BLOCK S1 WITH FRAME TITLE TEXT-001.
    PARAMETERS:
    P_WERKS  LIKE MARD-WERKS OBLIGATORY.     " Plant
    SELECT-OPTIONS:
    S_BUKRS  for mseg-bukrs,                 " Company  code
    S_LGORT  FOR MARD-LGORT OBLIGATORY,      " Storage Location
    S_MATNR  FOR MARD-MATNR,                 " Material Number
    S_DISPO  FOR MARC-DISPO,                 " MRP Controller
    S_DATE   FOR SY-DATUM DEFAULT SY-DATUM OBLIGATORY.  " Date Range
    SELECTION-SCREEN END OF BLOCK S1.
    SELECTION-SCREEN BEGIN OF BLOCK S2 WITH FRAME TITLE TEXT-002.
    PARAMETERS:
    P_MAIL  TYPE C AS CHECKBOX.                " Mail to user Group
    SELECT-OPTIONS:
    S_UNAME FOR SY-UNAME NO INTERVALS.         " Usergroup id
    SELECTION-SCREEN END OF BLOCK S2.
                         Initialization
    INITIALIZATION.
    AT S E L E C T I O N - S C R E E N
    AT SELECTION-SCREEN.
      CHECK SSCRFIELDS-UCOMM EQ 'ONLI'.
      PERFORM VALIDATE_MAIL.
      PERFORM VALIDATE_DATA.
                        START-OF-SELECTION                               *
    START-OF-SELECTION.
      PERFORM FETCH_DATA.
                         END-OF-SELECTION                                *
    END-OF-SELECTION.
      IF NOT IT_FINAL[] IS INITIAL.
        PERFORM DOWNLOAD_DISPLAY_REPORT.
      ENDIF.
                         TOP-OF-PAGE                                *
    TOP-OF-PAGE.
    PERFORM PAGE_HEADER.
    *&      Form  Fetch_DATA
          Pick data
    FORM FETCH_DATA .
      DATA : V_EBELN LIKE EKPO-EBELN,
             V_EBELP LIKE EKPO-EBELP,
             V_MENGE LIKE EKPO-MENGE,
             V_EINDT LIKE EKET-EINDT,
             V_DISPO LIKE MARC-DISPO,
             V_EKGRP LIKE MARC-EKGRP,
             V_MAKTX LIKE MAKT-MAKTX.
    *----Select data from MARD Table
      SELECT MATNR                  " Material Number
             WERKS                  " Plant
             LGORT                  " Storage Location
             LMINB                  " Reorder Point Level
             LABST                  " Stock with unrestricted use
             INTO TABLE IT_MARD
             FROM MARD
             WHERE MATNR  IN S_MATNR AND
                   WERKS  = P_WERKS . "AND
                  LGORT  IN S_LGORT.
                   D~LMINB <> SPACE .
      IF SY-SUBRC = 0.
        LOOP AT IT_MARD.
          CLEAR : V_EBELN, V_EBELP, V_MENGE, V_EINDT.
    *---select data from EKPO table
          SELECT EBELN
                 EBELP
                 MENGE
                 UP TO 1 ROWS
                 FROM EKPO
                 INTO (V_EBELN, V_EBELP, V_MENGE)
                 WHERE MATNR = IT_MARD-MATNR AND
                       WERKS = IT_MARD-WERKS AND
                       LGORT = IT_MARD-LGORT AND
                       BUKRS IN S_BUKRS AND
                       ELIKZ = SPACE.
          ENDSELECT.
          IF SY-SUBRC = 0.
            X_MSEG-EBELN = V_EBELN.
            X_MSEG-MENGE1 = V_MENGE.
            SELECT EINDT
                   UP TO 1 ROWS
                   FROM EKET
                   INTO V_EINDT
                   WHERE EBELN = V_EBELN AND
                         EBELP = V_EBELP.
            ENDSELECT.
            IF SY-SUBRC = 0.
              X_MSEG-EINDT = V_EINDT.
            ENDIF.
          ENDIF.
    *---Select Data from MARC table.
          CLEAR : V_DISPO, V_EKGRP.
          SELECT DISPO
                 EKGRP
                 UP TO 1 ROWS
                 FROM MARC
                 INTO (V_DISPO, V_EKGRP)
                 WHERE MATNR = IT_MARD-MATNR AND
                       WERKS = IT_MARD-WERKS AND
                       DISPO IN S_DISPO.
          ENDSELECT.
          IF SY-SUBRC = 0.
            X_MSEG-DISPO = V_DISPO.
            X_MSEG-EKGRP = V_EKGRP.
          else.
          continue.
          ENDIF.
    *---select Material Description from MAKT
          CLEAR V_MAKTX.
          SELECT SINGLE MAKTX
                 FROM MAKT
                 INTO V_MAKTX
                 WHERE MATNR = IT_MARD-MATNR AND
                       SPRAS = SY-LANGU.
          IF SY-SUBRC = 0.
            X_MSEG-MAKTX = V_MAKTX.
          ENDIF.
    *----Select data from MSEG Table
          SELECT MBLNR
                 MJAHR
                 MATNR                  " Material Number
                 WERKS                  " Plant
                 LGORT                  " Storage Location
                 MENGE                  " Quantity
                 MEINS                  " UOM
                 LIFNR                  " Account No of Vendor
                 SHKZG                  " Credit/Debit Indicator
                 FROM MSEG
                 INTO X_MSEG
                 WHERE MATNR = IT_MARD-MATNR AND
                       WERKS = IT_MARD-WERKS AND
                       LGORT = IT_MARD-LGORT AND
                       BUKRS IN S_BUKRS.
    *---Subroutine to check whether the document is in the given date range
            PERFORM CHECK_DATE.
          ENDSELECT.
        ENDLOOP.
      ELSE.
        STOP.
      ENDIF.
    *----Select YTD receipts and Issues to date from MSEG
      CLEAR : V_MJAHR, V_ISSUE, V_RECEIPT.
      IF S_DATE[] IS NOT INITIAL.
        V_MJAHR = S_DATE+3(4).
      ELSE.
        V_MJAHR = SY-DATUM+0(4).
      ENDIF.
      SELECT MENGE
             MEINS
             SHKZG
             FROM MSEG
             INTO TABLE IT_YTD
             WHERE WERKS = P_WERKS AND
                   MJAHR = V_MJAHR.
    *--Calculating YTD receipts and Issues
      IF SY-SUBRC = 0.
        LOOP AT IT_YTD.
          IF IT_YTD-SHKZG = 'S'.
            V_ISSUE = V_ISSUE + IT_YTD-MENGE.
          ELSE.
            V_RECEIPT = V_RECEIPT + IT_YTD-MENGE.
          ENDIF.
        ENDLOOP.
        IT_FINAL-ISSUE = V_ISSUE.
        IT_FINAL-RECEIPT = V_RECEIPT.
      ENDIF.
    *-----Logic for printing the material
      LOOP AT IT_MSEG.
        V_TABIX = SY-TABIX.
        AT NEW MATNR.
    *----Logic for calculation of Total On hand inv at plant.
    *---Sum of all MARD-LABST.
          CLEAR V_LABST.
          LOOP AT IT_MARD WHERE MATNR = IT_MSEG-MATNR.
            V_LABST = V_LABST + IT_MARD-LABST.
          ENDLOOP.
          IT_FINAL-TOT_LABST = V_LABST.
        ENDAT.
        AT NEW LGORT.
          CLEAR : V_SUM.
        ENDAT.
        READ TABLE IT_MARD WITH KEY MATNR = IT_MSEG-MATNR
                                    WERKS = IT_MSEG-WERKS
                                    LGORT = IT_MSEG-LGORT.
        IF SY-SUBRC = 0 AND IT_MARD-LMINB > 0.
    *---Logic for adding/Subtracting GR/GI
          IF V_TABIX = 1.
            IF IT_MSEG-SHKZG = 'S'.
              V_TEMP = IT_MARD-LABST + IT_MSEG-MENGE.
            ELSE.
              V_TEMP = IT_MARD-LABST - IT_MSEG-MENGE.
            ENDIF.
          ENDIF.
          IF IT_MARD-LABST < IT_MARD-LMINB.  "Stock < Reorder Point
    *---Check for any goods receipts on the given day. SHKZG = 'S'
            IF IT_MSEG-SHKZG = 'S' .
              IF V_TABIX = 1.
                V_SUM = V_TEMP.
              ELSE.
                V_SUM = V_SUM + IT_MSEG-MENGE.
              ENDIF.
              IF V_SUM < IT_MARD-LMINB.
                IT_FINAL-MATNR = IT_MARD-MATNR.
                IT_FINAL-MAKTX = IT_MSEG-MAKTX.
                IT_FINAL-LMINB = IT_MARD-LMINB.
                IT_FINAL-MEINS = IT_MSEG-MEINS.
                IT_FINAL-LABST = IT_MARD-LABST.
                IT_FINAL-DISPO = IT_MSEG-DISPO.
                IT_FINAL-EKGRP = IT_MSEG-EKGRP.
                IT_FINAL-LIFNR = IT_MSEG-LIFNR.
                IT_FINAL-ISSUE = V_ISSUE.
                IT_FINAL-RECEIPT = V_RECEIPT.
                IT_FINAL-TOT_LABST = V_LABST.
                IT_FINAL-EBELN = IT_MSEG-EBELN.
                IT_FINAL-MENGE = IT_MSEG-MENGE1.
                IT_FINAL-EINDT = IT_MSEG-EINDT.
                APPEND IT_FINAL.
                CLEAR IT_FINAL.
              ENDIF.
            ELSE.
    *--- If there is no Goods receipt mov't type on the given day, then
    *---add all the goods issues to the storage location stock.
    *---Goos Receipt = 'S' , Goods Issue = 'H'.
              IF V_TABIX = 1.
                V_SUM = V_TEMP.
              ELSE.
                V_SUM = V_SUM - IT_MSEG-MENGE.
              ENDIF.
              IF V_SUM < IT_MARD-LMINB.
                IT_FINAL-MATNR = IT_MARD-MATNR.
                IT_FINAL-MAKTX = IT_MSEG-MAKTX.
                IT_FINAL-LMINB = IT_MARD-LMINB.
                IT_FINAL-MEINS = IT_MSEG-MEINS.
                IT_FINAL-LABST = IT_MARD-LABST.
                IT_FINAL-DISPO = IT_MSEG-DISPO.
                IT_FINAL-EKGRP = IT_MSEG-EKGRP.
                IT_FINAL-LIFNR = IT_MSEG-LIFNR.
                IT_FINAL-ISSUE = V_ISSUE.
                IT_FINAL-RECEIPT = V_RECEIPT.
                IT_FINAL-TOT_LABST = V_LABST.
                IT_FINAL-EBELN = IT_MSEG-EBELN.
                IT_FINAL-MENGE = IT_MSEG-MENGE1.
                IT_FINAL-EINDT = IT_MSEG-EINDT.
                APPEND IT_FINAL.
                CLEAR IT_FINAL.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " Fetch_DATA
    *&      Form  check_date
          text
    FORM CHECK_DATE .
      DATA: LV_BLDAT LIKE MKPF-BLDAT.
      SELECT SINGLE BLDAT
             FROM MKPF
             INTO LV_BLDAT
             WHERE MBLNR = X_MSEG-MBLNR AND
                   MJAHR = X_MSEG-MJAHR AND
                   BLDAT IN S_DATE.
      IF SY-SUBRC = 0.
        MOVE : X_MSEG-MATNR TO IT_MSEG-MATNR,
               X_MSEG-WERKS TO IT_MSEG-WERKS,
               X_MSEG-LGORT TO IT_MSEG-LGORT,
               X_MSEG-MENGE TO IT_MSEG-MENGE,
               X_MSEG-MEINS TO IT_MSEG-MEINS,
               X_MSEG-LIFNR TO IT_MSEG-LIFNR,
               X_MSEG-SHKZG TO IT_MSEG-SHKZG,
               X_MSEG-EBELN TO IT_MSEG-EBELN,
               X_MSEG-MENGE1 TO IT_MSEG-MENGE1,
               X_MSEG-EINDT TO IT_MSEG-EINDT,
               X_MSEG-DISPO TO IT_MSEG-DISPO,
               X_MSEG-EKGRP TO IT_MSEG-EKGRP,
               X_MSEG-MAKTX TO IT_MSEG-MAKTX.
        APPEND IT_MSEG.
        CLEAR IT_MSEG.
      ENDIF.
    ENDFORM.                    " check_date
    *&      Form  PAGE_HEADER
         To Print page header and other details
    FORM PAGE_HEADER .                                          "#EC CALLED
    *---Page header
      ULINE AT /1(150).
      FORMAT COLOR COL_BACKGROUND INTENSIFIED ON .
      WRITE:/ 'Run Date:'(t08), SY-DATUM, 50 'Stanley Works'(t07),
             110 'Page No:'(t09), SY-PAGNO LEFT-JUSTIFIED.
      WRITE:/ 'Run Time:'(t10), SY-UZEIT, 47 SY-TITLE, 110 SY-UNAME.
      WRITE:/ 'Source  :'(t11), SY-SYSID, 110 SY-CPROG .
      ULINE AT /1(150).
      WRITE :/1 'Safety Stock Report for Plant :'(t13),P_WERKS.
    ENDFORM.                    "PAGE_HEADER
    *&      Form  VALIDATE_DATA
          Subroutine to Validate selection screen data
    FORM VALIDATE_DATA .
      DATA V_TEMP(20) TYPE C.                                   "#EC NEEDED
    *--Validation for Plant.
      CLEAR V_TEMP.
      SELECT SINGLE WERKS
             INTO V_TEMP
             FROM T001W
             WHERE WERKS = P_WERKS.
      IF SY-SUBRC NE 0.
        MESSAGE E001(ZZ) WITH 'Invalid Plant'(t03).             "#EC *
      ENDIF.
    *--Validation for Storage Location.
      CLEAR V_TEMP.
      IF NOT S_LGORT[] IS INITIAL.
        SELECT LGORT INTO V_TEMP UP TO 1 ROWS
               FROM T001L
               WHERE LGORT IN  S_LGORT.
        ENDSELECT.
        IF SY-SUBRC NE 0.
          MESSAGE E001(ZZ) WITH 'Invalid Storage Location'(t04).
        ENDIF.
      ENDIF.
    *--Validation for Material Number.
      CLEAR V_TEMP.
      IF NOT S_MATNR[] IS INITIAL.
        SELECT MATNR
               INTO V_TEMP
               UP TO 1 ROWS
               FROM MARA
               WHERE MATNR IN S_MATNR.
        ENDSELECT.
        IF SY-SUBRC NE 0.
          MESSAGE E001(ZZ) WITH 'Invalid Material Number'(t05).
        ENDIF.
      ENDIF.
    *--Validation for MRP controller.
      CLEAR V_TEMP.
      IF NOT S_DISPO[] IS INITIAL.
        SELECT  DISPO INTO V_TEMP UP TO 1 ROWS
                FROM T024D
                WHERE DISPO IN S_DISPO.
        ENDSELECT.
        IF SY-SUBRC NE 0.
          MESSAGE E001(ZZ) WITH 'Invalid MRP Controller'(t06).
        ENDIF.
      ENDIF.
    ENDFORM.                    " VALIDATE_DATA
    *&      Form  validate_mail
          Validate user id
    FORM VALIDATE_MAIL .
      IF P_MAIL = 'X' AND S_UNAME[] IS INITIAL.
        MESSAGE E001(ZZ) WITH 'Enter User Mail id'(t01).
      ENDIF.
    ENDFORM.                    " validate_mail
    *&      Form  SEND_MAIL
         Send email to SAP inbox
    FORM SEND_MAIL .
    Structures and internal tables for the send data
      DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2  WITH HEADER LINE,
            OBJHEAD LIKE SOLISTI1   OCCURS 1  WITH HEADER LINE,
            OBJBIN  LIKE SOLISTI1   OCCURS 0  WITH HEADER LINE,
            OBJTXT  LIKE SOLISTI1   OCCURS 10 WITH HEADER LINE,
            RECLIST LIKE SOMLRECI1  OCCURS 5  WITH HEADER LINE.
      DATA: DOC_CHNG LIKE SODOCCHGI1,
            TAB_LINES LIKE SY-TABIX.
    Data for the status output after sending
      DATA: SENT_TO_ALL LIKE SONV-FLAG.
      CLEAR: IT_RECLIST, IT_RECLIST[],
             IT_OBJTXT , IT_OBJTXT[],
             IT_OBJPACK, IT_OBJPACK[],
             IT_OBJBIN , IT_OBJBIN[],X_DOC_CHNG.
      LOOP AT IT_HTML.
        OBJBIN-LINE = IT_HTML-LINE.
        APPEND OBJBIN.
        CLEAR OBJBIN.
      ENDLOOP.
    Create the document which is to be sent
      DOC_CHNG-OBJ_NAME  = 'List'(012).
      DOC_CHNG-OBJ_DESCR = 'Mail'(m05).
    Heading
      OBJTXT-LINE = 'Safety Stock Report attached'(014).
      APPEND OBJTXT.
      CLEAR OBJTXT.
    Size
      DESCRIBE TABLE OBJTXT LINES TAB_LINES.
      READ TABLE OBJTXT INDEX TAB_LINES.
      DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
    Fill the fields of the packing_list for the main document:
      CLEAR OBJPACK-TRANSF_BIN.
    The document needs no header (head_num = 0)
      OBJPACK-HEAD_START = 1.
      OBJPACK-HEAD_NUM = 0.
    Body
      OBJPACK-BODY_START = 1.
      OBJPACK-BODY_NUM = TAB_LINES.
      OBJPACK-DOC_TYPE = 'RAW'(m02).
      APPEND OBJPACK.
    Create the attachment (the list itself)
      DESCRIBE TABLE OBJBIN LINES TAB_LINES.
    Fill the fields of the packing_list for the attachment:
      OBJPACK-TRANSF_BIN = 'X'.
    Header
      OBJPACK-HEAD_START = 1.
      OBJPACK-HEAD_NUM = 0.
    Body
      OBJPACK-BODY_START = 1.
      OBJPACK-BODY_NUM = TAB_LINES.
      OBJPACK-DOC_TYPE = 'PDF'(m01).
      OBJPACK-OBJ_NAME = 'Attachment'(m03).
      OBJPACK-OBJ_DESCR = 'Mail with pdf Attachment'(018).
      OBJPACK-DOC_SIZE = TAB_LINES * 255.
      APPEND OBJPACK.
    *-Fill the mail recipient list
      LOOP AT S_UNAME.
        RECLIST-RECEIVER = S_UNAME-LOW.
        RECLIST-REC_TYPE = 'B'.
        APPEND RECLIST.
        CLEAR: RECLIST.
      ENDLOOP.
    *-Send the document by calling the SAPoffice API1 module for sending
    *-documents with attachments
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          DOCUMENT_DATA              = DOC_CHNG
          PUT_IN_OUTBOX              = 'X'
          COMMIT_WORK                = 'X'
        IMPORTING
          SENT_TO_ALL                = SENT_TO_ALL
        TABLES
          PACKING_LIST               = OBJPACK
          OBJECT_HEADER              = OBJHEAD
          CONTENTS_BIN               = OBJBIN
          CONTENTS_TXT               = OBJTXT
          RECEIVERS                  = RECLIST
        EXCEPTIONS
          TOO_MANY_RECEIVERS         = 1
          DOCUMENT_NOT_SENT          = 2
          OPERATION_NO_AUTHORIZATION = 4
          OTHERS                     = 99.
      CASE SY-SUBRC .
        WHEN 0.
          MESSAGE s001 WITH 'Mail has been sent successfully'(003).
        WHEN OTHERS.
          MESSAGE s001 WITH 'Problem in sending the mail'(004).
      ENDCASE.
    ENDFORM.                    " SEND_MAIL
    *&      Form  download_display_report
          Download and dispaly report
    FORM DOWNLOAD_DISPLAY_REPORT .
      DATA: X_PARAMS TYPE PRI_PARAMS,
            V_VALID.
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          IMMEDIATELY    = ' '
          LAYOUT         = 'X_65_255'
          NO_DIALOG      = 'X'
        IMPORTING
          OUT_PARAMETERS = X_PARAMS
          VALID          = V_VALID.
      IF V_VALID <> SPACE.
        NEW-PAGE PRINT ON PARAMETERS X_PARAMS NO DIALOG.
        PERFORM DISPLAY_REPORT.
        NEW-PAGE PRINT OFF.
        PERFORM CONV_TO_PDF_DOWNLOAD.
      ENDIF.
      PERFORM DISPLAY_REPORT.
    ENDFORM.                    " download_display_report
    *&      Form  DISPLAY_REPORT
          Display the report
    FORM DISPLAY_REPORT .
    ULINE AT /0(204).
      write:/1 sy-vline no-gap, (10)'Material'(032),
             sy-vline no-gap, (40)'Description'(031),
             sy-vline no-gap, (15)'Reorder pt'(030),
             sy-vline no-gap, (03)'BUn'(029),
             sy-vline no-gap, (13)'OnHandQty'(023),
             sy-vline no-gap, (13)'OnHandPlnt'(024),
             sy-vline no-gap, (13)'YTD issues'(025),
             sy-vline no-gap, (13)'YTD Receipts'(026),
             sy-vline no-gap, (08)'MRPcntrl'(027),
             sy-vline no-gap, (04)'POgrp'(028),
             sy-vline no-gap, (13)'POqty'(019),
             sy-vline no-gap, (10)'NextDelvDt'(020),
             sy-vline no-gap, (10)'Vendor'(021),
             sy-vline no-gap, (10)'PO#'(022),
             sy-vline no-gap.
    ULINE AT /0(204).
    loop at it_final.
      PERFORM COLOR_SWAP.
      write:/1 sy-vline no-gap, (10)it_final-matnr,
             sy-vline no-gap, (40)it_final-maktx,
             sy-vline no-gap, (15)it_final-lminb,     "#EC UOM_IN_MES
             sy-vline no-gap, (03)it_final-meins,
             sy-vline no-gap, (13)it_final-labst,     "#EC UOM_IN_MES
             sy-vline no-gap, (13)it_final-tot_labst, "#EC UOM_IN_MES
             sy-vline no-gap, (13)it_final-issue,     "#EC UOM_IN_MES
             sy-vline no-gap, (13)it_final-receipt,   "#EC UOM_IN_MES
             sy-vline no-gap, (08)it_final-dispo,
             sy-vline no-gap, (04)it_final-ekgrp,
             sy-vline no-gap, (13)it_final-menge,     "#EC UOM_IN_MES
             sy-vline no-gap, (10)it_final-eindt,
             sy-vline no-gap, (10)it_final-lifnr,
             sy-vline no-gap, (10)it_final-ebeln,
             sy-vline no-gap.
    endloop.
    ULINE AT /0(204).
    skip 2.
    WRITE:/ '******End of Report*******'.
    ENDFORM.                    " DISPLAY_REPORT
    *&      Form  CONV_TO_PDF_DOWNLOAD
          Convert to PDF
    FORM CONV_TO_PDF_DOWNLOAD .
      DATA: V_NUMBYTES TYPE I,
            V_SPOOLNO TYPE TSP01-RQIDENT.
      CLEAR   IT_PDF.
      REFRESH IT_PDF.
      WAIT UP TO 2 SECONDS.
      V_SPOOLNO = SY-SPONO.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          SRC_SPOOLID   = V_SPOOLNO
          NO_DIALOG     = ' '
        IMPORTING
          PDF_BYTECOUNT = V_NUMBYTES
        TABLES
          PDF           = IT_PDF.
      IF SY-SUBRC = 0.    "#EC *
        PERFORM PAGE_FORMAT.
      ENDIF.
    ENDFORM.                    " CONV_TO_PDF_DOWNLOAD
    *&      Form  page_format
       Format the page
    FORM PAGE_FORMAT .
      DATA : L_LINES       TYPE I,
             L_TEMP(500)   TYPE C,
             L_OFFSET      TYPE P,
             L_LINESLEN(2) TYPE P,
             L_MIMELEN(2)  TYPE P,
             L_TABIX       LIKE SY-TABIX.
      CLEAR : IT_XI_PDF,
              IT_XI_TEMP.
      REFRESH : IT_XI_PDF,
                IT_XI_TEMP.
      IT_XI_PDF[] = IT_PDF[].
    Reformat the line to 255 characters wide (code from SAP)
      CLEAR: L_TEMP, L_OFFSET, IT_XI_TEMP.
      DESCRIBE TABLE IT_XI_PDF   LINES  L_LINES.
      DESCRIBE FIELD IT_XI_PDF   LENGTH L_LINESLEN IN CHARACTER MODE.
      DESCRIBE FIELD IT_XI_TEMP  LENGTH L_MIMELEN IN CHARACTER MODE.
      LOOP AT IT_XI_PDF.
        L_TABIX = SY-TABIX.
        MOVE IT_XI_PDF TO L_TEMP+L_OFFSET.
        IF L_TABIX = L_LINES.
          L_LINESLEN = STRLEN( IT_XI_PDF ).
        ENDIF.
        L_OFFSET = L_OFFSET + L_LINESLEN.
        IF L_OFFSET GE L_MIMELEN.
          CLEAR IT_XI_TEMP.
          IT_XI_TEMP = L_TEMP(L_MIMELEN).
          APPEND IT_XI_TEMP.
          SHIFT L_TEMP BY L_MIMELEN PLACES.
          L_OFFSET = L_OFFSET - L_MIMELEN.
        ENDIF.
        IF L_TABIX = L_LINES.
          IF L_OFFSET GT 0.
            CLEAR IT_XI_TEMP.
            IT_XI_TEMP = L_TEMP(L_OFFSET).
            APPEND IT_XI_TEMP.
          ENDIF.
        ENDIF.
      ENDLOOP.
      CLEAR : IT_XI_MIME,
              IT_XI_MIME[].
      LOOP AT IT_XI_TEMP.
        IT_XI_MIME(255) = IT_XI_TEMP-LINE.
        APPEND IT_XI_MIME.
        CLEAR  IT_XI_MIME.
      ENDLOOP.
    Final Data
      CLEAR : IT_HTML,
              IT_HTML[].
      IT_HTML[] = IT_XI_MIME[].
    For sending mail
      PERFORM SEND_MAIL .
    ENDFORM.                    " page_format
    Form        : color_swap
    Description : Subroutine for color
    form color_swap.
    if flag is set
      if f_color eq 'X'.
        clear f_color.
    switch off the intensity
        format color col_normal intensified off.
      else.
    if flag is not set.
        f_color = 'X'.
    switch on the intensity
        format color col_normal intensified on.
      endif.
    endform.                    " color_swap

  • How to convert date format into sap standard format?

    Hi All,
    In SAPUI5 screen i have one simple form in form i have date field which is format  (MM/DD/YYYY). but i am getting POST error while inserting the data in to sap table.
    I want convert date format in sap format (YYYY/MM/DD).
    One more issue, when i am fetching the data from sap table,but  the date display with time and time zone.
    eg. Sat Aug 02 2014 05:30:00 GMT+0530 (India Standard Time)
    I want to display only date.
    Thanks,
    Prashant.

    Now i am using <DatePicker id="Emp_fsdate" displayFormat="yyyy-MM-dd"/>
    I checked in console, but date is display like mm/dd/yy
    In my controller.js file i have written code
    OData.request
               requestUri: "http:sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata", 
               method: "GET",
               headers:
               "X-Requested-With": "XMLHttpRequest",
               "Content-Type": "application/atom+xml",
               "DataServiceVersion": "2.0",       
               "X-CSRF-Token":"Fetch"
           function (data, response){
            var header_xcsrf_token = response.headers['x-csrf-token'];
                       OData.request
                            requestUri:
                             "http://sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata", 
                            method: "POST",
                            headers:
                          "X-Requested-With": "XMLHttpRequest",                     
                            "Content-Type": "application/atom+xml",
                            "DataServiceVersion": "2.0",
                            "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
                            "X-CSRF-Token": header_xcsrf_token
                            data:
                                   Empid:Emp_id,
                                   Empname:Emp_name,
                                   Start_Date:Emp_sdate,
    //                              End_Date:Emp_edate,
                                   Status:Emp_status,
                                   City:Emp_city,
                                   Location:Emp_location,
    and in my CREATE_ENTITY method
    method ES_SODATA_CREATE_ENTITY.
         DATA: ls_request_input_data TYPE zcl_zservice_final_mpc=>ts_et_sodata,
             ls_userinfo TYPE zsodata.
       DATA ls_temp TYPE sy-datum.
    * Read Request Data
       io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data ).
    * Fill workarea to be inserted
       ls_userinfo-Empid   = ls_request_input_data-Empid.
       ls_userinfo-Empname   = ls_request_input_data-Empname.
       ls_userinfo-Start_Date   = ls_request_input_data-Start_Date.
       ls_userinfo-End_Date   = ls_request_input_data-End_Date.
       ls_userinfo-Status   = ls_request_input_data-Status.
       ls_userinfo-City   = ls_request_input_data-City.
       ls_userinfo-Location   = ls_request_input_data-Location.
    * Insert Data in table ZUSERINFO
       INSERT zsodata FROM ls_userinfo.
       IF sy-subrc = 0.
         er_entity = ls_request_input_data. "Fill Exporting parameter ER_ENTITY
       ENDIF.
       endmethod.
    But still i am getting an error
    POST http://sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata 500 (Internal Server Error)
    I am able to insert all field except date field. How to insert date field in sap table.

Maybe you are looking for

  • X-FI ExtremeMusic and old Live Drive

    Hi, I have purchased an X-FI ExtremeMusic card. I have an old front bay Li've Dri've II?connection box from my old SoundBlaster Li've! PlatinumI know the pin-outs are different. If you look at the following links, they show the pin-outs for the X-Fi?

  • (Un)Managed Wrapper calling LabView-Dll

    Hello, I am focused with a strange behaviour which i could not explain. I had to extend the NI272x in my C++ unmanaged environment for a StepType http://sine.ni.com/cs/app/doc/p/id/cs-11443/lang/de/pdf/yes/pdf that descripes a functional testsystem.

  • Excel File downloaded from application server is also opening in notepad

    Hi Friends, While downlaoding an excel file from the application server,we are able to open in notepad also.But this does not conatin the excel properties and hence happening.File should only oopen with excel and no other file type Can any open help

  • 10.5.2 Erased all Calendar Entries

    What happened to all my iCal entries after updating to 10.5.2???

  • Replacing tables wih Views

    Hi, I used to work on OLTP reports i.e reports 6i/10g etc.I was asked to work on disco now.We've couple of reports moved from Oracle apps 11i to R12.All those reports are based on tables and now I was asked to replace those tables with views by addin