Converting data to HH:mm:ss time

Post Author: tvuprestige
CA Forum: Formula
Hi, im new to crystal reports and I need to change output to HH:MM:SS.  Currently, data is in form of seconds only. Any help would be appreciated!

Post Author: SKodidine
CA Forum: Formula
I see the problem.  You said that you created a sum via the wizard.  When you right click on the summary field in the report and then click on Format Field and then in the Common tab, click on x-2 next to Display String, in the formula workshop window, expand the Report Fields.  Within it you should see your summary field with a SIGMA (that looks like a capital E).  It might say something like "E Report Area: Sum of  IWrkgrpQueueStats.tTalkAcd"
In your formula:
"totext(({Sum of IWrkgrpQueueStats.tTalkAcd}/60)/60,0,"","") & ":" & totext(truncate(remainder({Sum of IWrkgrpQueueStats.tTalkAcd}/60,60)),0) & ":" & totext(remainder({Sum of IWrkgrpQueueStats.tTalkAcd},60),0);
Replace the fields above with the field with the sigma.  Dont just type it in, double click on the field and it will be placed in the formula area.  If correctly placed, your formula should look similar to this:
"totext((Sum ({ IWrkgrpQueueStats.tTalkAcd})/60)/60,0,"","") & ":" & totext(truncate(remainder((Sum ({ IWrkgrpQueueStats.tTalkAcd})/60,60)),0) & ":" & totext(remainder((Sum ({ IWrkgrpQueueStats.tTalkAcd}),60),0);

Similar Messages

  • HELP - How to Convert Date in GMT to Local time in Applet

    Hi All
    Is there a way to convert a date from GMT format into a local time say IST in my Java applet, this GMT date is coming from a postgresql database.
    Thanks in advance
    Swaraj

    Try this with your customization:
    java.text.SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.text.SimpleDateFormat format1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    java.util.Calendar cal0 = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    java.util.Calendar cal1 = Calendar.getInstance(new SimpleTimeZone((int)(5.5*60*60*1000), "IST"));
    format0.setCalendar(cal0);
    format1.setCalendar(cal1);
    java.util.Date date = format0.parse("2003-01-25 00:15:30");
    java.lang.String formatted = format1.format(date);
    System.out.println(formatted);

  • 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

  • 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

  • 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

  • Internationalization  issue : convert date/time to GMT/UTC

    We have our webservices running in websphere /oracle.There is this requirement to internationalize the application ...like
    a) language .....
    d)Internatiolization of time :
    For this requirment I am planning to do the following.Service request with date will be converted to GMT before it is stored in database and the response back will be converted from GMT back to the time zone of the requester and have the application server/database server configured to UTC time.Is this a good strategy or is there a better one.
    Thanks
    m

    Manjit wrote:
    Sabre,to confirm again...you are suggesting that there is even no need to change the oracle Date field from Date type to Timestamp.The only thing I really have to do is for display purpose convert/format the response date to the zone the request is coming from.Please let me know if I missed anything.The above statement is indefinite.
    Are you starting with a java.util.Date or perhaps a java.sql.Timestamp?
    Then you do NOT convert them. You display them. You use SimpleDateFormat for that. You do not concern yourself at all with timezones exception in terms of creating a SimpleDateFormat. And that is ONLY an issue if you are creating the string (display value) on a server. If you are doing that you will need the client to provide you with a timezone. There is no magic way to get that from the client. If a client app is doing the display the the client is running in a client VM and that VM will already have a display format that might be suitable.
    Conversely if you are receiving a timestamp value as a text value (say read it from a file) then you must convert that into a java.util.Date. You do that via SimpleDateFormat. The specifics of how you do that depends on the form of the text value.

  • 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

  • Problem converting Date time vanishes

    Hi,
    I am doing the following
    String datstr = coform.getCourseDate();
    LamLog.log(this,LamLog.INFO,"Date in insertRow is " + datstr);
    LamLog.log(this,LamLog.INFO,"Date in insertRow sdf.parse(datstr) is " + sdf.parse(datstr));
    java.sql.Date dt = new java.sql.Date(sdf.parse(datstr).getTime());
    LamLog.log(this,LamLog.INFO,"Date after creating in insertRow is " + dt);
    dt.setTime(sdf.parse(datstr).getTime());
    LamLog.log(this,LamLog.INFO,"Date after conversion in insertRow is " + dt);
    but the result I am getting is
    Date in insertRow is 04/01/2003 09:30:00
    Date in insertRow sdf.parse(datstr) is Tue Apr 01 09:30:00 EST 2003
    Date after creating in insertRow is 2003-04-01
    Date after conversion in insertRow is 2003-04-01
    if you see after converting to sql.Date the time portion of the date vanishes. What is wrong??
    Kindly help.
    Regards
    Rajesh J

    But I need sql date to use in my entity beanjava.sql.Date doesn't have a time component. java.sql.Timestamp does. If your bean has been written to use java.sql.Date then obviously it doesn't need the time component.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to Convert Date to Month in Database which is pointing to EBS, Not DWH.

    Hi Friends,
    We are planning to create reports in OBIEE and the Source is EBS. That means, we don’t want to depends on Datawarehouse and Informatica and OBIApps. We just create some reports and they are pointing to EBS database.
    For testing purpose, we have taken one HR Report and it containsthe below columns:
    Month (Dim)
    Revenue Per Employee Headcount (Fact)
    Average Cost per Active Workforce Headcount (Fact)
    In my little investigation, we found that Revenue column is coming from EBS: GL_BALANCES. And we configured W_Day_D base table in DAC as there is no Month column in EBS (Not sure).
    *** Coming to my problem, how can I call Month column in my database pointed to EBS. How to convert Date to Month in my database.
    I could be wrong but anyone please look into this issue.. How can I create columns for that exact OBI report in EBS database instead of DwH.
    Thanks in Advance..
    Raghu Nagadasari

    Hi Veeresh,
    You are right. Here, no need of using W_DAY_D table, but, we need all the stuff from the table and to explain my problem i have taken that table as an example. Now, we ran scripts for W_MONTH_D and W_DAY_D tables with EBS columns. So, we are getting data for the tables. In the same manner we have to create scripts for the below tables.
    W_GL_ACCOUNT_D
    W_GL_OTHER_F
    W_STATUS_D
    W_MCAL_DAY_D
    W_EMPLOYMENT_STAT_CAT_D
    W_WRKFC_BAL_A
    W_DAY_D (Completed)
    W_MONTH_D (Completed)
    But, we are not aware of EBS Tables and their columns much. So, we are back tracing from RpD --> DAC --> Info --> EBS for each and every column and its taking much time.
    So, if anyone of you facing the same issue, please share the EBS tables for the corresponding OBI tables, which are mentioned above.

  • 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.

  • How to convert date which is coming from a file

    Hi All,
    I am reading the content from the file in which date is also one field, but i am while inserting into the database i'm getting an exception because it is not able
    to insert into the database because the database date format is different from the one which is coming from a file.
    The datatype value of the database is Date.
    Can anyone help me on this if anybody having an idea.
    Regards,
    CH

    Hi,
    Even if I'm using JavaEmbeddedActivity also i'm getting an error. Please have alook at the below code once
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class ConvertDateToStringExample {
    public static void main(String args[]){
    DateFormat dateFormat = new SimpleDateFormat("dd-nn-yyyy hh:mm:ss");
    //to convert Date to String, use format method of SimpleDateFormat class.
    String strDate = dateFormat.format(getVariableData('inputVariable','payload','/client:process/client:Date'));
    System.out.println("Date converted to String: " + strDate);
    Error Message:
    Error(21,33): Failed to compile bpel generated classes.
    failure to compile the generated BPEL classes for BPEL process "DateProcess" of composite "default/DateProcess!1.0"
    The class path setting is incorrect.
    Ensure that the class path is set correctly. If this happens on the server side, verify that the custom classes or jars which this BPEL process is depending on are deployed correctly. Also verify that the run time is using the same release/version.
    Well it's not at all allowing me to insert the format while passing the input arguments.
    Regards,
    CH

Maybe you are looking for