Date & Calendar table

Hi
I have a table with entries that have a date attribute i want to know which dates were not entered for a specific period
Is there a predefined calendar table?
Thanks

Here's an example of the sort of thing you can do...
SQL> ed
Wrote file afiedt.buf
  1  with cal as (select min_hiredate+rn-1 as dt
  2               from (select min(hiredate) min_hiredate from emp2), (select rownum rn from dual
  3                                                       connect by rownum <= (select max(hiredate)-min(hiredate)+1 from emp2))
  4              )
  5  -- end of calendar
  6  select cal.dt as cal_date
  7        ,emp2.*
  8  from cal left outer join emp2 on (cal.dt = emp2.hiredate)
  9* order by 1
SQL> /
CAL_DATE         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
23-JAN-2008       7934 MILLER     CLERK           7782 23-JAN-2008       1300                    10
24-JAN-2008
25-JAN-2008
26-JAN-2008
27-JAN-2008
28-JAN-2008
29-JAN-2008
30-JAN-2008
31-JAN-2008
01-FEB-2008
02-FEB-2008
03-FEB-2008
04-FEB-2008
05-FEB-2008
06-FEB-2008
07-FEB-2008
08-FEB-2008
09-FEB-2008
10-FEB-2008
11-FEB-2008
12-FEB-2008
13-FEB-2008
14-FEB-2008
15-FEB-2008
16-FEB-2008
17-FEB-2008
18-FEB-2008
19-FEB-2008
20-FEB-2008       7499 ALLEN      SALESMAN        7698 20-FEB-2008       1600        300         30
21-FEB-2008
22-FEB-2008       7521 WARD       SALESMAN        7698 22-FEB-2008       1250        500         30
23-FEB-2008
24-FEB-2008
25-FEB-2008
26-FEB-2008
27-FEB-2008
28-FEB-2008
29-FEB-2008
01-MAR-2008
02-MAR-2008
03-MAR-2008
04-MAR-2008
05-MAR-2008
06-MAR-2008
07-MAR-2008
08-MAR-2008
09-MAR-2008
10-MAR-2008
11-MAR-2008
12-MAR-2008
13-MAR-2008
14-MAR-2008
15-MAR-2008
16-MAR-2008
17-MAR-2008
18-MAR-2008
19-MAR-2008
20-MAR-2008
21-MAR-2008
22-MAR-2008
23-MAR-2008
24-MAR-2008
25-MAR-2008
26-MAR-2008
27-MAR-2008
28-MAR-2008
29-MAR-2008
30-MAR-2008
31-MAR-2008
01-APR-2008
02-APR-2008       7566 JONES      MANAGER         7839 02-APR-2008       2975                    20
03-APR-2008
04-APR-2008
05-APR-2008
06-APR-2008
07-APR-2008
08-APR-2008
09-APR-2008
10-APR-2008
11-APR-2008
12-APR-2008
13-APR-2008
14-APR-2008
15-APR-2008
16-APR-2008
17-APR-2008
18-APR-2008
19-APR-2008       7788 SCOTT      ANALYST         7566 19-APR-2008       3000                    20
20-APR-2008
21-APR-2008
22-APR-2008
23-APR-2008
24-APR-2008
25-APR-2008
26-APR-2008
27-APR-2008
28-APR-2008
29-APR-2008
30-APR-2008
01-MAY-2008       7698 BLAKE      MANAGER         7839 01-MAY-2008       2850                    30
02-MAY-2008
03-MAY-2008
04-MAY-2008
05-MAY-2008
06-MAY-2008
07-MAY-2008
08-MAY-2008
09-MAY-2008
10-MAY-2008
11-MAY-2008
12-MAY-2008
13-MAY-2008
14-MAY-2008
15-MAY-2008
16-MAY-2008
17-MAY-2008
18-MAY-2008
19-MAY-2008
20-MAY-2008
21-MAY-2008
22-MAY-2008
23-MAY-2008       7876 ADAMS      CLERK           7788 23-MAY-2008       1100                    20
24-MAY-2008
25-MAY-2008
26-MAY-2008
27-MAY-2008
28-MAY-2008
29-MAY-2008
30-MAY-2008
31-MAY-2008
01-JUN-2008
02-JUN-2008
03-JUN-2008
04-JUN-2008
05-JUN-2008
06-JUN-2008
07-JUN-2008
08-JUN-2008
09-JUN-2008       7782 CLARK      MANAGER         7839 09-JUN-2008       2450                    10
10-JUN-2008
11-JUN-2008
12-JUN-2008
13-JUN-2008
14-JUN-2008
15-JUN-2008
16-JUN-2008
17-JUN-2008
18-JUN-2008
19-JUN-2008
20-JUN-2008
21-JUN-2008
22-JUN-2008
23-JUN-2008
24-JUN-2008
25-JUN-2008
26-JUN-2008
27-JUN-2008
28-JUN-2008
29-JUN-2008
30-JUN-2008
01-JUL-2008
02-JUL-2008
03-JUL-2008
04-JUL-2008
05-JUL-2008
06-JUL-2008
07-JUL-2008
08-JUL-2008
09-JUL-2008
10-JUL-2008
11-JUL-2008
12-JUL-2008
13-JUL-2008
14-JUL-2008
15-JUL-2008
16-JUL-2008
17-JUL-2008
18-JUL-2008
19-JUL-2008
20-JUL-2008
21-JUL-2008
22-JUL-2008
23-JUL-2008
24-JUL-2008
25-JUL-2008
26-JUL-2008
27-JUL-2008
28-JUL-2008
29-JUL-2008
30-JUL-2008
31-JUL-2008
01-AUG-2008
02-AUG-2008
03-AUG-2008
04-AUG-2008
05-AUG-2008
06-AUG-2008
07-AUG-2008
08-AUG-2008
09-AUG-2008
10-AUG-2008
11-AUG-2008
12-AUG-2008
13-AUG-2008
14-AUG-2008
15-AUG-2008
16-AUG-2008
17-AUG-2008
18-AUG-2008
19-AUG-2008
20-AUG-2008
21-AUG-2008
22-AUG-2008
23-AUG-2008
24-AUG-2008
25-AUG-2008
26-AUG-2008
27-AUG-2008
28-AUG-2008
29-AUG-2008
30-AUG-2008
31-AUG-2008
01-SEP-2008
02-SEP-2008
03-SEP-2008
04-SEP-2008
05-SEP-2008
06-SEP-2008
07-SEP-2008
08-SEP-2008       7844 TURNER     SALESMAN        7698 08-SEP-2008       1500          0         30
09-SEP-2008
10-SEP-2008
11-SEP-2008
12-SEP-2008
13-SEP-2008
14-SEP-2008
15-SEP-2008
16-SEP-2008
17-SEP-2008
18-SEP-2008
19-SEP-2008
20-SEP-2008
21-SEP-2008
22-SEP-2008
23-SEP-2008
24-SEP-2008
25-SEP-2008
26-SEP-2008
27-SEP-2008
28-SEP-2008       7654 MARTIN     SALESMAN        7698 28-SEP-2008       1250       1400         30
29-SEP-2008
30-SEP-2008
01-OCT-2008
02-OCT-2008
03-OCT-2008
04-OCT-2008
05-OCT-2008
06-OCT-2008
07-OCT-2008
08-OCT-2008
09-OCT-2008
10-OCT-2008
11-OCT-2008
12-OCT-2008
13-OCT-2008
14-OCT-2008
15-OCT-2008
16-OCT-2008
17-OCT-2008
18-OCT-2008
19-OCT-2008
20-OCT-2008
21-OCT-2008
22-OCT-2008
23-OCT-2008
24-OCT-2008
25-OCT-2008
26-OCT-2008
27-OCT-2008
28-OCT-2008
29-OCT-2008
30-OCT-2008
31-OCT-2008
01-NOV-2008
02-NOV-2008
03-NOV-2008
04-NOV-2008
05-NOV-2008
06-NOV-2008
07-NOV-2008
08-NOV-2008
09-NOV-2008
10-NOV-2008
11-NOV-2008
12-NOV-2008
13-NOV-2008
14-NOV-2008
15-NOV-2008
16-NOV-2008
17-NOV-2008       7839 KING       PRESIDENT            17-NOV-2008       5000                    10
18-NOV-2008
19-NOV-2008
20-NOV-2008
21-NOV-2008
22-NOV-2008
23-NOV-2008
24-NOV-2008
25-NOV-2008
26-NOV-2008
27-NOV-2008
28-NOV-2008
29-NOV-2008
30-NOV-2008
01-DEC-2008
02-DEC-2008
03-DEC-2008       7900 JAMES      CLERK           7698 03-DEC-2008        950                    30
03-DEC-2008       7902 FORD       ANALYST         7566 03-DEC-2008       3000                    20
04-DEC-2008
05-DEC-2008
06-DEC-2008
07-DEC-2008
08-DEC-2008
09-DEC-2008
10-DEC-2008
11-DEC-2008
12-DEC-2008
13-DEC-2008
14-DEC-2008
15-DEC-2008
16-DEC-2008
17-DEC-2008       7369 SMITH      CLERK           7902 17-DEC-2008        800                    20
331 rows selected.
SQL>

Similar Messages

  • Split date range without Calendar table

    Hi guys!
    Is there any way to split date ranges (to days / hours / minutes) in one table without using Calendar table (without joining 2 tables)?
    Reason I'm asking this is because we have a huge Fact table (500+ million records) and joining small Calendar table and this huge Fact table takes considerable amount of time.
    So far we tried:
    Join 2 tables (Fact and Calendar)
    Cross Applying Calendar and table-valued function (that returns necessary measures from Fact table)
    and both approaches took few minutes for 1 day to complete.
    Most successful test we had so far was using CLR and executing table-valued functions in parallel for different 15 minute periods. This way we were able to get the results in 3-4 seconds.
    Anyway, is there any effective pure T-SQL way to accomplish this?
    Thanks in advance,
    Miljan

    Try using a temporary table rather than table variable.. You can have a CI on the date column.
    or
    declare @PeriodStart datetime2(0) = '2013-01-05 00:00:00'
    declare @PeriodEnd datetime2(0) = '2013-01-05 02:00:00'
    select T.PeriodStart, T.PeriodEnd, count(Column1)as count1, sum(Column2)as sum1
    from Fact F with(nolock)WHERE F.[Start]>= '19000101' AND <=@PeriodStartand F.[End] >= @PeriodEnd and F.[End] <='20200101'
    group by T.PeriodStart, T.PeriodEnd
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • SQL Query to calculate on-time dispatch with a calendar table

    Hi Guys,
    I have a query (view) to calculate orders' fulfillment leadtimes.
    The current criteria exclude week-ends but not bank holidays therefore I have created a calendar table with a column name
    isBusinessDay but I don't know how to best use this table to calculate the On-Time metric. I have been looking everywhere but so far I have been unable to solve my problem.
    Please find below the current calculation for the On-Time Column:
    SELECT
    Week#
    , ClntGroup
    , CORD_DocumentCode
    , DESP_DocumentCode
    , Cord_Lines --#lines ordered
    , CORD_Qty --total units orderd
    , DESP_Lines --#lines dispatched
    , DESP_Qty --total units dispatched
    , Status
    , d_status
    , OpenDate --order open date
    , DateDue
    , DESP_PostedDate --order dispatched date
    , DocType
    , [Lead times1]
    , [Lead times2]
    , InFxO
    , OnTime
    , InFxO + OnTime AS InFullAndOneTime
    , SLADue
    FROM (
    SELECT
    DATEPART(WEEK, d.DateOpn) AS Week#
    , Clients.CustCateg
    , Clients.ClntGroup
    , d.DocumentCode AS CORD_DocumentCode
    , CDSPDocs.DocumentCode AS DESP_DocumentCode
    , COUNT(CORDLines.Qnty) AS Cord_Lines
    , SUM(CORDLines.Qnty) AS CORD_Qty
    , COUNT(CDSPLines.Qnty) AS DESP_Lines
    , SUM(CDSPLines.Qnty) AS DESP_Qty
    , CDSPLines.Status
    , d.Status AS d_status
    , d.OpenDate
    , d.DateDue
    , CDSPDocs.PostDate AS DESP_PostedDate
    , d.DocType
    , DATEDIFF(DAY, d.OpenDate, d.DateDue) AS [Lead times1]
    , DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) AS [Lead times2]
    , CASE WHEN SUM(CORDLines.Qnty) = SUM(CDSPLines.Qnty) THEN 1 ELSE 0 END AS InFxO --in-full
    --On-Time by order according to Despatch SLAs
    , CASE
    WHEN Clients.ClntGroup IN ('Local Market', 'Web Sales', 'Mail Order')
    AND (DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) - (DATEDIFF(WEEK, d.OpenDate, CDSPDocs.PostDate) * 2 ) <= 2)
    THEN 1
    WHEN Clients.ClntGroup IN ('Export Market', 'Export Market - USA')
    AND (DATEDIFF(DAY, d.OpenDate, CDSPDocs.PostDate) - (DATEDIFF(WEEK, d.OpenDate, CDSPDocs.PostDate) * 2) <= 14)
    THEN 1
    WHEN Clients.ClntGroup = 'Export Market' OR Clients.CustCateg = 'UK Transfer'
    AND d.DateDue >= CDSPDocs.PostDate
    THEN 1
    ELSE 0
    END AS OnTime
    --SLA Due (as a control)
    , CASE
    WHEN Clients.ClntGroup IN ('Local Market', 'Web Sales','Mail Order') AND CDSPDocs.PostDate is Null
    THEN DATEADD(DAY, 2 , d.OpenDate)
    WHEN Clients.ClntGroup IN ('Export Market', 'Export Market - UK', 'Export Market - USA') OR (Clients.CustCateg = 'UK Transfer')
    AND CDSPDocs.PostDate IS NULL
    THEN DATEADD (DAY, 14 , d.OpenDate)
    ELSE CDSPDocs.PostDate
    END AS SLADue
    FROM dbo.Documents AS d
    INNER JOIN dbo.Clients
    ON d.ObjectID = dbo.Clients.ClntID
    AND Clients.ClientName NOT in ('Samples - Free / Give-aways')
    LEFT OUTER JOIN dbo.DocumentsLines AS CORDLines
    ON d.DocID = CORDLines.DocID
    AND CORDLines.TrnType = 'L'
    LEFT OUTER JOIN dbo.DocumentsLines AS CDSPLines
    ON CORDLines.TranID = CDSPLines.SourceID
    AND CDSPLines.TrnType = 'L'
    AND (CDSPLines.Status = 'Posted' OR CDSPLines.Status = 'Closed')
    LEFT OUTER JOIN dbo.Documents AS CDSPDocs
    ON CDSPLines.DocID = CDSPDocs.DocID
    LEFT OUTER JOIN DimDate
    ON dimdate.[Date] = d.OpenDate
    WHERE
    d.DocType IN ('CASW', 'CORD', 'MORD')
    AND CORDLines.LneType NOT IN ('Fght', 'MANF', 'Stor','PACK', 'EXPS')
    AND CORDLines.LneType IS NOT NULL
    AND d.DateDue <= CONVERT(date, GETDATE(), 101)
    GROUP BY
    d.DateOpn
    ,d.DocumentCode
    ,Clients.CustCateg
    ,CDSPDocs.DocumentCode
    ,d.Status
    ,d.DocType
    ,d.OpenDate
    ,d.DateReq
    ,CDSPDocs.PostDate
    ,CDSPLines.Status
    ,Clients.ClntGroup
    ,d.DocumentName
    ,d.DateDue
    ,d.DateOpn
    ) AS derived_table
    Please find below the DimDate table
    FullDateNZ HolidayNZ IsHolidayNZ IsBusinessDay
    24/12/2014 NULL 0 1
    25/12/2014 Christmas Day 1 0
    26/12/2014 Boxing Day 1 0
    27/12/2014 NULL 0 0
    28/12/2014 NULL 0 0
    29/12/2014 NULL 0 1
    30/12/2014 NULL 0 1
    31/12/2014 NULL 0 1
    1/01/2015 New Year's Day 1 0
    2/01/2015 Day after New Year's 1 0
    3/01/2015 NULL 0 0
    4/01/2015 NULL 0 0
    5/01/2015 NULL 0 1
    6/01/2015 NULL 0 1
    This is what I get from the query:
    Week# ClntGroup CORD_DocumentCode OpenDate DESP_PostedDate OnTime
    52 Web Sales 123456 24/12/2014 29/12/2014 0
    52 Web Sales 123457 24/12/2014 30/12/2014 0
    52 Web Sales 123458 24/12/2014 29/12/2014 0
    52 Local Market 123459 24/12/2014 29/12/2014 0
    1 Web Sale 123460 31/12/2014 5/01/2015 0
    1 Local Market 123461 31/12/2014 6/01/2015 0
    As the difference between the dispatched and open date is 2 business days or less, the result I expect is this:
    Week# ClntGroup CORD_DocumentCode OpenDate DESP_PostedDate OnTime
    52 Web Sales 123456 24/12/2014 29/12/2014 1
    52 Web Sales 123457 24/12/2014 30/12/2014 1
    52 Web Sales 123458 24/12/2014 29/12/2014 1
    52 Local Market 123459 24/12/2014 29/12/2014 1
    1 Web Sale 123460 31/12/2014 5/01/2015 1
    1 Local Market 123461 31/12/2014 6/01/2015 1
    I am using SQL Server 2012
    Thanks
    Eric

    >> The current criteria exclude week-ends but not bank holidays therefore I have created a calendar table with a column name “isBusinessDay” but I don't know how to best use this table to calculate the On-Time metric. <<
    The Julian business day is a good trick. Number the days from whenever your calendar starts and repeat a number for a weekend or company holiday.
    CREATE TABLE Calendar
    (cal__date date NOT NULL PRIMARY KEY, 
     julian_business_nbr INTEGER NOT NULL, 
    INSERT INTO Calendar 
    VALUES ('2007-04-05', 42), 
     ('2007-04-06', 43), -- good Friday 
     ('2007-04-07', 43), 
     ('2007-04-08', 43), -- Easter Sunday 
     ('2007-04-09', 44), 
     ('2007-04-10', 45); --Tuesday
    To compute the business days from Thursday of this week to next
     Tuesdays:
    SELECT (C2.julian_business_nbr - C1.julian_business_nbr)
     FROM Calendar AS C1, Calendar AS C2
     WHERE C1.cal__date = '2007-04-05',
     AND C2.cal__date = '2007-04-10'; 
    We do not use flags in SQL; that was assembly language. I see from your code that you are still in a 1960's mindset. You used camelCase for a column name! It makes the eyes jump and screws up maintaining code; read the literature. 
    The “#” is illegal in ANSI/ISO Standard SQL and most other ISO Standards. You are writing 1970's Sybase dialect SQL! The rest of the code is a mess. 
    The one column per line, flush left and leading comma layout tells me you used punch cards when you were learning programming; me too! We did wrote that crap because a card had only 80 columns and uppercase only IBM 027 character sets. STOP IT, it make you
    look stupid in 2015. 
    You should follow ISO-11179 rules for naming data elements. You failed. You believe that “status” is a precise, context independent data element name! NO! 
    You should follow ISO-8601 rules for displaying temporal data. But you used a horrible local dialect. WHY?? The “yyyy-mm-dd” is the only format in ANSI/ISO Standard SQL. And it is one of the most common standards embedded in ISO standards. Then you used crap
    like “6/01/2015” which is varying length and ambiguous that might be “2015-06-01” or “2015-01-06” as well as not using dashes. 
    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/
    >> Please find below the current calculation for the On-Time Column: <<
    “No matter how far you have gone down the wrong road, turn around”
     -- Turkish proverb
    Can you throw out this mess and start over? If you do not, then be ready to have performance got to hell? You will have no maintainable code that has to be kludged like you are doing now? In a good schema an OUTER JOIN is rare, but you have more of them in
    ONE statement than I have seen in entire major corporation databases.
    --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

  • Creating Fiscal/Calendar Table

    Hello,
    Please, help to create a Fiscal and Calendar table with the following conditions:
    The table and the first fiscal year start from 01/31/2011
    The end date could be 12/31/2020 (not that important as it could be a smaller date)
    All the next fiscal years should start 52 weeks after on the following Monday.
    I’m trying to modify the following code that is calculating the beginning of the fiscal year with 52 weeks ahead but with following Monday only for the first next Fiscal Year.
    Thanks
    DECLARE
    @StartDate smalldatetime
    = '01/31/2011'
    --First Calendar date to include in table
    DECLARE
    @EndDate smalldatetime
    = '12/31/2020'
    --Last calendar date to include in the table
    declare
    @FiscalYearBegin_First smalldatetime
    = '1/31/2011'
    DECLARE
    @Cycle INT
    = 52
    SET
    DATEFIRST 7
     ;WITH
    --This secton generates the number table
    E00(N)
    AS (SELECT 1
    UNION ALL
    SELECT 1),
    E02(N)
    AS (SELECT 1
    FROM E00
    a, E00
    b),
    E04(N)
    AS (SELECT 1
    FROM E02
    a, E02
    b),
    E08(N)
    AS (SELECT 1
    FROM E04
    a, E04
    b),
    E16(N)
    AS (SELECT 1
    FROM E08
    a, E08
    b),
    E32(N)
    AS (SELECT 1
    FROM E16
    a, E16
    b),
    cteTally(N)
    AS (SELECT
    ROW_NUMBER()
    OVER (ORDER
    BY N)
    FROM E32),
    --This CTE generates a list of calendar dates
    CalendarBase
    as (
     SELECT
    DateKey =
    n
    , CalendarDate
    = DATEADD(day,
    n -1,
    @StartDate )
    case when n
    = 1 then
    @FiscalYearBegin_First 
    else
    case when
    datepart(dw,DATEADD(DAY,
    n -1
    , @StartDate ))
    = 2 then 
    dateadd(week,CAST(ABS(DATEDIFF(WEEK,DATEADD(day,
    n -1
    , @StartDate ),@StartDate))/@Cycle
    AS INT)
    * @Cycle,@FiscalYearBegin_First)
    else
    dateadd(week,
    datediff(week, 0,
    dateadd(week,CAST(ABS(DATEDIFF(WEEK,DATEADD(day,
    n - 1,
    @StartDate ),@StartDate))/@Cycle
    AS INT)
    * @Cycle,@FiscalYearBegin_First)), 7)
    end
    end FiscalYearBegin
    FROM cteTally
      WHERE
    N <=
    DATEDIFF(day,
    @StartDate ,
    @EndDate +1)
    --Finally, use the list of calendar dates to fill the date dimension
    SELECT
    DateKey
    , IsoDate      
    = CONVERT(char(8),
    CalendarDate, 112)
    , CalendarDate
    , CalendarYear 
    = YEAR(CalendarDate)
    , CalendarQuarter
    =  (DATEPART(QUARTER,CalendarDate)
    , CalendarMonth
    = MONTH(CalendarDate)
    , CalendarDay  
    = DATEPART(DAY,
    CalendarDate)
    , DayofWk      
    = DATEPART(Dw,
    CalendarDate)
    , CalendarWeekOfMonth
    = DATEDIFF(week,
    DATEADD(day,1,
    CalendarDate-DAY(CalendarDate)
    + 1)
    -1, CalendarDate)
    +1
    , WeekofYr     
    = DATEPART(WEEK,
    CalendarDate)
    , DayofYr      
    = DATEPART(DAYOFYEAR,
    CalendarDate)
    , NameMonth    
    = DATENAME(Month,
    CalendarDate)
    , NameDay      
    = DATENAME
    (Weekday,CalendarDate
    , FiscalYear   
    = YEAR(FiscalYearBegin)
    , FiscalMonth   
    = DATEDIFF(
    MONTH,
    FiscalYearBegin,
    CalendarDate) + 1
    , FiscalQuarter  
    = DATEDIFF(
    QUARTER,
    FiscalYearBegin,
    CalendarDate) + 1
    , FiscalWeek    
    = DATEDIFF(
    WEEK,
    FiscalYearBegin,
    CalendarDate) + 1
    , FiscalDay     
    = DATEDIFF(
    day,
    FiscalYearBegin,
    CalendarDate) + 1
    FROM
    CalendarBase

    Try the below code if this meets your requirement.
    DECLARE @StartDate DATETIME = '01-31-2011'
    ,@EndDate DATETIME = '12-31-2020'
    ;WITH cteCalendar (CurrentDate,WeekDay,DayNum,WeekNum)
    AS
    (SELECT @StartDate AS CurrentDate, DATENAME(WEEKDAY,@StartDate) AS WeekDay, 1 AS MonthCode, 1 AS WeekNum
    UNION ALL
    SELECT DATEADD(DD,1,cte.CurrentDate) AS CurrentDate, DATENAME(WEEKDAY,DATEADD(DD,1,cte.CurrentDate)) AS WeekDay, cte.DayNum + 1 AS DayNum
    , cte.DayNum / 7 + 1 as WeekNum
    FROM cteCalendar cte
    WHERE cte.CurrentDate + 1 <= @EndDate
    SELECT CurrentDate,WeekDay
    ,CASE WHEN WeekNum%52 = 0 THEN 52
    ELSE WeekNum%52 END AS WeekNumber
    ,DATEPART(YY,@StartDate) + (WeekNum - 1)/52 AS FiscalYear
    FROM cteCalendar
    OPTION (MAXRECURSION 0)
    Only year condition was mentioned and you didn't mention about month, so i did not consider month in the result set. If month is also required, share the condition (30Days in a month or 4Weeks in month?)
    Let me know if i got you wrong.

  • Calendar Table Population

    Hi
    I need to populate a calendar table with two fields date(for 10 yrs) and Holiday Flag.Holiday flag will be Y if its saturday and Sunday and N for weekdays.
    Can anyone please provide me with the script to populate the table.
    Thanks

    Hi Jameel,
    Well, when I said version dependant, the result can differ :
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.7.0 - Production
    SQL> select sysdate+rownum,
      2  decode(to_char(sysdate+rownum,'Dy'),'Sat','Y','Sun','Y','N')
      3  from dual connect by level<=10;
    SYSDATE+ D
    11/06/06 Y
    =================================================
      1  select sysdate+rownum,
      2  decode(to_char(sysdate+rownum,'Dy'),'Sat','Y','Sun','Y','N')
      3* from dual connect by level<=10
    SCOTT@demo102> /
    SYSDATE+ D
    11/06/06 Y
    12/06/06 N
    13/06/06 N
    14/06/06 N
    15/06/06 N
    16/06/06 N
    17/06/06 Y
    18/06/06 Y
    19/06/06 N
    20/06/06 N
    10 rows selected.
    SCOTT@demo102> select * from v$version where rownum=1;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
    SCOTT@demo102> Without said about 10.1.0.2 (which I don't have) which give 11 rows with the same query above (see Re: Cube Function
    All these facts said me that we have to use others ways like pipelined (as showed the link I gave above) or dimension...
    Nicolas.

  • MTD,YTD,PTD without calendar table

              QTY
          Month
          Year
    QTY_YTD
    QTY_MTD
    QTY_PTD
    10
    1
    2010
    20
    2
    2010
    20
    1
    2012
    30
    3
    2012
    Above is how my table looks like and  all are having integer datatypes
    I dont have a calendar table to join hence without calendar table can I compute YTD,MTD,PTD?
    If so what will be the case queries
    Mudassar

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Something_Report_Periods
    (something_report_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (something_report_name LIKE <pattern>),
     something_report_start_date DATE NOT NULL,
     something_report_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (something_report_start_date <= something_report_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    --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

  • Calendar Table

    Does anyone know the best way to set up a calendar table? We will need a way to account for weekends and holidays when determining work days. I have been searching for some pl/sql code to do this. We are currently not using any other calendaring or using with forms. Needed mainly for reporting issues.
    Please let me know if you have any ideas for me.
    thanks,
    Toni

    Here is an an example using the holiday table combined with the this_year view in the previous example.
    SQL> create table holiday (holiday date,
      2    country varchar2(2), description varchar2(30));
    Table created.
    SQL> insert into holiday values (date '2006-01-23', 'NL',
      2    'National Cheese Day');
    1 row created.
    SQL> select day, weekend, description holiday,
      2    case when weekend = 'N' and holiday is null then
      3      'Y' else 'N' end business_day
      4  from this_year, holiday
      5  where day between sysdate - 5 and sysdate + 5
      6    and day = holiday (+)
      7  order by day;
    DAY       WEEKEND HOLIDAY                        BUSINESS_DAY
    19-JAN-06 N                                      Y
    20-JAN-06 N                                      Y
    21-JAN-06 Y                                      N
    22-JAN-06 Y                                      N
    23-JAN-06 N       National Cheese Day            N
    24-JAN-06 N                                      Y
    25-JAN-06 N                                      Y
    26-JAN-06 N                                      Y
    27-JAN-06 N                                      Y
    28-JAN-06 Y                                      N
    10 rows selected.
    SQL>

  • How to make column headers in table in PDF report appear bold while datas in table appear regular from c# windows forms with sql server2008 using iTextSharp

    Hi my name is vishal
    For past 10 days i have been breaking my head on how to make column headers in table appear bold while datas in table appear regular from c# windows forms with sql server2008 using iTextSharp.
    Given below is my code in c# on how i export datas from different tables in sql server to PDF report using iTextSharp:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using System.Diagnostics;
    using System.IO;
    namespace DRRS_CSharp
    public partial class frmPDF : Form
    public frmPDF()
    InitializeComponent();
    private void button1_Click(object sender, EventArgs e)
    Document doc = new Document(PageSize.A4.Rotate());
    var writer = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
    doc.SetMargins(50, 50, 50, 50);
    doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
    doc.Open();
    PdfPTable table = new PdfPTable(6);
    table.TotalWidth =530f;
    table.LockedWidth = true;
    PdfPCell cell = new PdfPCell(new Phrase("Institute/Hospital:AIIMS,NEW DELHI", FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK)));
    cell.Colspan = 6;
    cell.HorizontalAlignment = 0;
    table.AddCell(cell);
    Paragraph para=new Paragraph("DCS Clinical Record-Assigned Dialyzer",FontFactory.GetFont("Arial",16,iTextSharp.text.Font.BOLD,BaseColor.BLACK));
    para.Alignment = Element.ALIGN_CENTER;
    iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("logo5.png");
    png.ScaleToFit(105f, 105f);
    png.Alignment = Element.ALIGN_RIGHT;
    SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
    SqlCommand cmd = new SqlCommand("Select d.dialyserID,r.errorCode,r.dialysis_date,pn.patient_first_name,pn.patient_last_name,d.manufacturer,d.dialyzer_size,r.start_date,r.end_date,d.packed_volume,r.bundle_vol,r.disinfectant,t.Technician_first_name,t.Technician_last_name from dialyser d,patient_name pn,reprocessor r,Techniciandetail t where pn.patient_id=d.patient_id and r.dialyzer_id=d.dialyserID and t.technician_id=r.technician_id and d.deleted_status=0 and d.closed_status=0 and pn.status=1 and r.errorCode<106 and r.reprocessor_id in (Select max(reprocessor_id) from reprocessor where dialyzer_id=d.dialyserID) order by pn.patient_first_name,pn.patient_last_name", conn);
    conn.Open();
    SqlDataReader dr;
    dr = cmd.ExecuteReader();
    table.AddCell("Reprocessing Date");
    table.AddCell("Patient Name");
    table.AddCell("Dialyzer(Manufacturer,Size)");
    table.AddCell("No.of Reuse");
    table.AddCell("Verification");
    table.AddCell("DialyzerID");
    while (dr.Read())
    table.AddCell(dr[2].ToString());
    table.AddCell(dr[3].ToString() +"_"+ dr[4].ToString());
    table.AddCell(dr[5].ToString() + "-" + dr[6].ToString());
    table.AddCell("@count".ToString());
    table.AddCell(dr[12].ToString() + "-" + dr[13].ToString());
    table.AddCell(dr[0].ToString());
    dr.Close();
    table.SpacingBefore = 15f;
    doc.Add(para);
    doc.Add(png);
    doc.Add(table);
    doc.Close();
    System.Diagnostics.Process.Start("AssignedDialyzer.pdf");
    if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.Yes)
    var writer2 = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
    else if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.No)
    this.Close();
    The above code executes well with no problem at all!
    As you can see the file to which i create and save and open my pdf report is
    AssignedDialyzer.pdf.
    The column headers of table in pdf report from c# windows forms using iTextSharp are
    "Reprocessing Date","Patient Name","Dialyzer(Manufacturer,Size)","No.of Reuse","Verification" and
    "DialyzerID".
    However the problem i am facing is after execution and opening of document is my
    column headers in table in pdf report from
    c# and datas in it all appear in bold.
    I have browsed through net regarding to solve this problem but with no success.
    What i want is my pdf report from c# should be similar to following format which i was able to accomplish in vb6,adodb with MS access using iTextSharp.:
    Given below is report which i have achieved from vb6,adodb with MS access using iTextSharp
    I know that there has to be another way to solve my problem.I have browsed many articles in net regarding exporting sql datas to above format but with no success!
    Is there is any another way to solve to my problem on exporting sql datas from c# windows forms using iTextSharp to above format given in the picture/image above?!
    If so Then Can anyone tell me what modifications must i do in my c# code given above so that my pdf report from c# windows forms using iTextSharp will look similar to image/picture(pdf report) which i was able to accomplish from
    vb6,adodb with ms access using iTextSharp?
    I have approached Sound Forge.Net for help but with no success.
    I hope anyone/someone truly understands what i am trying to ask!
    I know i have to do lot of modifications in my c# code to achieve this level of perfection but i dont know how to do it.
    Can anyone help me please! Any help/guidance in solving this problem would be greatly appreciated.
    I hope i get a reply in terms of solving this problem.
    vishal

    Hi,
    About iTextSharp component issue , I think this case is off-topic in here.
    I suggest you consulting to compenent provider.
    http://sourceforge.net/projects/itextsharp/
    Regards,
    Marvin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I am using the big date calendar template and when I submit it to apple for printing I lose the name of two months. These names are not text boxes. I see the names when I send it in but something happens during the transmission to apple. It was suggested

    I am using the big date calendar template in iPhoto. I am on Lion 10.7.2, macbook air. The names of the months are on each calendar page but something happens when I send the data to Apple. The names are part of the template. They are not text boxes. I lose two names on the calendar after it is sent to Apple. Apple suggested I make a pdf file of my calendar before sending it in and check to make sure every name shows. I did this with a calendar I just sent in. The calendar was correct. All names of the months were showing. After sending the data two month names disappeard because when it arrived by mail, it was incorrect. Apple looked at my calendar via a pdf file and it was incorrect.  This is second time this has happened. I called Apple and they had me delete several folders in the Library folder, some preferences and do a complete reinstall of iPhoto.  I have not yet remade the defective calendar. I am wondering if anyone else has had this problem?
    kathy

    Control-click on the background of the view all pages window and select "Preview Calendar" from the contextual menu.
    You can also save the pdf as a file to compare to the printed calendar.  If the two names are visible in the pdf file then the printed copy should show them.  Contact Apple for a refund.  Apple Print Products - Apple Store (U.S.)

  • How to populate data in table control  .

    hi all,
    i put matnr no. in screen no. 103
    validation is done at that screen only.
    now when i want to modify dat record
    when i put matnr no. at screen 103
    so how i will get all  data of dat number to table control screen.

    Hi Darshan,
       Here is a detailed description of how to update data in table controll.
      Updating data in table control
    The ABAP language provides two mechanisms for loading the table control with data from the internal table and then storing the altered rows of the table control back to the internal table.
    Method 1: Read the internal table into the Table Control in the screenu2019s flow logic.  Used when the names of the Table Control fields are based on fields of the internal table.
    Method 2: Read the internal table into the Table Control in the module pool code. Used when the names of the Table Control fields are based on fields of the database table.
    Method 1 (table control fields = itab fields)
    In the flow logic we can read an internal table using the LOOP statement. Define the reference to the relevant able control by specifying WITH CONTROL <ctrl>
    Determine which table entry is to be read by specifying CURSOR <ctrl>-CURRENT_LINE.
    After the read operation the field contents are placed in the header line of the internal table. If the fields in the table control have the same name as the internal they will be filled automatically. Otherwise we need to write a module to transfer the internal table fields to the screen fields.
    We must reflect any changes the user makes to the fields of the table control in the internal table otherwise they will not appear when the screen is redisplayed after PBO processing, (eg, after the user presses Enter or scrolls) However, this processing should be performed only if changes have actually been made to the screen fields of the table control (hence the use of the ON REQUEST)
    PROCESS BEFORE OUTPUT.
    LOOP AT ITAB_REG WITH CONTROL TCREG
    CURSOR TCREG-CURRENT_LINE.
    ENDLOOP.
    PROCESS AFTER INPUT.
    LOOP AT ITAB_REG.
    MODULE MODIFY_ITAB_REG.
    ENDLOOP.
    MODULE MODIFY_ITAB_REG INPUT.
    MODIFY ITAB_REG INDEX TCREG-CURRENT_LINE.
    ENDMODULE.
    Method 2 (table control fields = dict. fields)
    If using a LOOP statement without an internal table in the flow logic, we must read the data in a PBO module which is called each time the loop is processed.
    Since, in this case, the system cannot determine the number of internal table entries itself, we must use the EXIT FROM STEP-LOOP statement to ensure that no blank lines are displayed in the table control if there are no more corresponding entries in the internal table.
    PROCESS BEFORE OUTPUT.
    LOOP WITH CONTROL TCREG.
    MODULE READ_ITAB_REG.
    ENDLOOP.
    PROCESS AFTER INPUT.
    LOOP WITH CONTROL TCREG.
    CHAIN.
    FIELD: ITAB_REG-REG,
    ITAB_REG-DESC.
    MODULE MODIFY_ITAB_REG
    ON CHAIN-REQUEST.
    ENDCHAIN.
    ENDLOOP.
    MODULE READ_ITAB_REG OUTPUT.
    READ TABLE ITAB_REG INDEX TCREG-CURRENT_LINE.
    IF SY-SUBRC EQ 0.
    MOVE-CORRESPONDING ITAB_REREG TO TCREG.
    ELSE.
    EXIT FROM STEP-LOOP.
    ENDIF.
    ENDMODULE.
    MODULE MODIFY_ITAB_REG INPUT.
    MOVE-CORRESPONDING TCREG TO ITAB_REG.
    MODIFY ITAB_REG INDEX
    TCREG-CURRENT_LINE.
    ENDMODULE.
    Updating the internal table
    Method 1
    PROCESS AFTER INPUT.
    LOOP AT ITAB_REG.
    CHAIN.
    FIELD: ITAB_REG-REG,
    ITAB_REG-DESC.
    MODULE MODIFY_ITAB_REG ON CHAIN-REQUEST.
    ENDCHAIN.
    ENDLOOP.
    MODULE MODIFY_ITAB_REG INPUT.
    ITAB_REG-MARK = u2018Xu2019.
    MODIFY ITAB_REG INDEX TCREG-CURRENT_LINE.
    ENDMODULE.
    Method 2
    PROCESS AFTER INPUT.
    LOOP WITH CONTROL TCREG.
    CHAIN.
    FIELD: TCREG-REG,
    TCREG-DESC.
    MODULE MODIFY_ITAB_REG ON CHAIN-REQUEST.
    ENDCHAIN.
    ENDLOOP.
    MODULE MODIFY_ITAB_REG INPUT.
    MOVE-CORRESPONDING TCREG TO ITAB_REG.
    ITAB_REG-MARK = u2018Xu2019.
    MODIFY ITAB_REG INDEX TCREG-CURRENT_LINE.
    ENDMODULE.
    Updating the database
    MODULE USER_COMMAND_100.
    CASE OK_CODE.
    WHEN u2018SAVEu2019.
    LOOP AT ITAB-REG.
    CHECK ITAB_REG-MARK = u2018Xu2019.
    MOVE-CORRESPONDING ITAB_REG TO TCREG.
    UPDATE TCREG.
    ENDLOOP.
    WHEN u2026
    u2026
    ENDCASE.
    ENDMODULE.
    Hope this will solve your problem.
    Regards,
    Pavan.
    Edited by: PAVAN CHANDRASEKHAR GANTI on Aug 3, 2009 12:48 PM

  • Open HUB ( SAP BW ) to SAP HANA through DB Connection data loading , Delete data from table option is not working Please help any one from this forum

    Issue:
    I have SAP BW system and SAP HANA System
    SAP BW to SAP HANA connecting through a DB Connection (named HANA)
    Whenever I created any Open Hub as Destination like DB Table with the help of DB Connection, table will be created at HANA Schema level ( L_F50800_D )
    Executed the Open Hub service without checking DELETING Data from table option
    Data loaded with 16 Records from BW to HANA same
    Second time again executed from BW to HANA now 32 records came ( it is going to append )
    Executed the Open Hub service with checking DELETING Data from table option
    Now am getting short Dump DBIF_RSQL_TABLE_KNOWN getting
    If checking in SAP BW system tio SAP BW system it is working fine ..
    will this option supports through DB Connection or not ?
    Please follow the attachemnet along with this discussion and help me to resolve how ?
    From
    Santhosh Kumar

    Hi Ramanjaneyulu ,
    First of all thanks for the reply ,
    Here the issue is At OH level ( Definition Level - DESTINATION TAB and FIELD DEFINITION )
    in that there is check box i have selected already that is what my issue even though selected also
    not performing the deletion from target level .
    SAP BW - to SAP HANA via DBC connection
    1. first time from BW suppose 16 records - Dtp Executed -loaded up to HANA - 16 same
    2. second time again executed from BW - now hana side appaended means 16+16 = 32
    3. so that i used to select the check box at OH level like Deleting data from table
    4. Now excuted the DTP it throws an Short Dump - DBIF_RSQL_TABLE_KNOWN
    Now please tell me how to resolve this ? will this option is applicable for HANA mean to say like , deleting data from table option ...
    Thanks
    Santhosh Kumar

  • Unable to see data in Table in smartform

    Hi all,
    I need to create a smartform where I have to print the header details at the start and then below that details for all line items for a particular document.
    so i have data ;ike :
    Header data :
    field 1 : field 2:
    Field3 : field4:
    field5: field6:
    Item data :
    field1 field2 field3 field4 --> Item 1
    field1 field2 field3 field4 -->Item 2
    field 1 field2 field3 field4 -->Item3
    For the Header data,Im planning to use a template in a secondary window.
    However for the item data,i need to use a table (As i know the no of records only at runtime).Also another reason for usng table would be that I dont need the header on each flloowing page but only the Line item details on the following pages.
    Now my ques is :
    1.I hav ecreated the form and put some constant /texts to just test the form.I am able to see the texts/data in the header data.However  Im unable to see the data for the Item i.e. in the TABLE.
    I have used template for Header details which I can see.
    I dont know what Im doing wrong.Is it because in the DATA tab under TABLES,I have given an interna table but there is no data in the table?
    I have defined only 1 line type in  my table an dthat has 4 cells (as I need to print 4 item fields under the Item data)
    PLease let me know what I am doig wrong because of which Im unable to see the item data in table form.
    Thanks!

    Hi,
    Have you used any exists?
    in exists is there any system date kind?
    Can you try to run your report thru RSRT and use debug option there.
    before reporting please check your all connected targets have data for reporting.
    mean at targets-->request tab, reporting symbol was there or not.
    Any master data objects included in multi provider?
    if yes then please check those, if any ACR was running then it may cause you.
    if possible try to develop simple query with as per needs(mean to see 2015 data only).
    As my guess selections/filters migth be hidden, please check those.
    Thanks

  • No data in table TRFCQDATA  when update IM in ECC after EWM PGR

    Hi Experts,
    In our client system, when Inbound delivery (Customer Return) has been completed PGR in EWM, ECC system cannot be updated in IM stock and  occurs an error :No data in Table TRFCQDATA(Internal) via SMQ2 query it.
    Who can advise how to solve it?
    Many thanks!
    Julia

    Thanks Sathish!
    Yes, after re-regisiering manually, the queue will be processing.
    However we need all qRFC queue can be automatically processed immediately, not manally.
    Who can advise what setting we are missing ?
    Thanks & Best regards,
    Julia

  • No Data in Table

    I Drag and drop a view node into UIX page from Data Control Palette. Run, But I get empty table in html. Why no data in table?

    or even if you execute it from struts it may still now show the data. The reason is unknown.
    Bugs in JDev/UIX

  • How to stored data after clicking checkbox in data base table

    REPORT  ZT                                      .
    TYPE-pools: slis.
    tables:mkpf,mseg,mard,COWB_COMP,ZTABLE.
    Types:BEGIN OF tp_data,
         mblnr LIKE mseg-mblnr,
         matnr LIKE mseg-matnr,
         werks LIKE mard-werks,
         lgort LIKE mard-lgort,
         lgpbe LIKE mard-lgpbe,
         charg LIKE mseg-charg,
         bwart LIKE mseg-bwart,
         budat LIKE mkpf-budat,
         menge LIKE mseg-menge,
         meins LIKE mseg-meins,
         kostl LIKE mseg-kostl,
         aufnr LIKE mseg-aufnr,
         rsnum LIKE mseg-rsnum,
         endkz like COWB_COMP-endkz,
    END OF tp_data,
    tp_tbl_data TYPE STANDARD TABLE OF tp_data.
    MODIFIED*******************
    DATA: WA TYPE TP_DATA.
    MODIFIED*******************
    *data: t_data like Y00_MM_ISSUE_DAT occurs 0 with header line.
    Constants
    Data objects (variable declarations and definitions)
    Report data to be shown.
    DATA: it_data TYPE STANDARD TABLE OF tp_data.
    MODIFIED*******************
    DATA : V_REPID LIKE SY-REPID.
    MODIFIED*******************
    Heading of the report.
    DATA: t_heading TYPE slis_t_listheader.
    *========================== Selection Screen
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS:smblnr FOR mseg-mblnr MODIF ID m1,
                  smatnr FOR mseg-matnr MODIF ID m2,
                  swerks FOR mard-werks MODIF ID m3,
                  slgort FOR mard-lgort MODIF ID m4,
                  slgpbe FOR mard-lgpbe MODIF ID m5,
                  scharg FOR mseg-charg MODIF ID m6,
                  sbwart FOR mseg-bwart MODIF ID m7,
                  skostl FOR mseg-kostl MODIF ID m8,
                  saufnr FOR mseg-aufnr MODIF ID m9,
                  srsnum FOR mseg-rsnum MODIF ID m10.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS:pre RADIOBUTTON GROUP radi USER-COMMAND ucomm DEFAULT 'X',
              pse RADIOBUTTON GROUP radi,
              bps RADIOBUTTON GROUP radi.
    SELECTION-SCREEN END OF BLOCK b2.
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
    PARAMETER:layout TYPE i.
    SELECTION-SCREEN END OF BLOCK b3.
    MODIFIED*******************
    INITIALIZATION.
    V_REPID = sy-repid.
    MODIFIED*******************
    *=========================== Event Blocks
    AT selection-SCREEN.
    start-OF-selection.
    PERFORM get_data USING it_data.
    END-OF-selection.
    PERFORM build_alv USING it_data t_heading.
    *=========================== Subroutines
    *&      Form  get_data
          Gets the information to be shown in the report.
    FORM get_data USING t_data TYPE tp_tbl_data.
    SELECT msegmblnr msegmatnr mardwerks mardlgort mard~lgpbe
    msegcharg msegbwart mkpf~budat
       msegmenge  msegmeins msegkostl msegaufnr mseg~rsnum
    INTO CORRESPONDING FIELDS OF TABLE t_data
    FROM mseg
    JOIN mard ON mardmatnr EQ msegmatnr
                  JOIN mkpf ON msegmblnr EQ mkpfmblnr
                  WHERE mseg~matnr IN smatnr.
    ENDFORM.                    " get_data
    *&      Form  build_alv
          Builds and display the ALV Grid.
    FORM build_alv USING t_data TYPE tp_tbl_data
         t_heading  TYPE slis_t_listheader.
    ALV required data objects.
    DATA: w_title   TYPE lvc_title,
           w_comm    TYPE slis_formname,
           w_status  TYPE slis_formname,
           x_layout  TYPE slis_layout_alv,
           t_event    TYPE slis_t_event,
           t_fieldcat TYPE slis_t_fieldcat_alv,
           t_sort     TYPE slis_t_sortinfo_alv.
    REFRESH t_fieldcat.
    REFRESH t_event.
    REFRESH t_sort.
    CLEAR x_layout.
    CLEAR w_title.
    Field Catalog
    PERFORM set_fieldcat2 USING:
           1 'MBLNR' 'MBLNR' 'MSEG' space space space space space space
    space space space space space space t_fieldcat ,
           2 'MATNR' 'MATNR' 'MSEG' space space space space space space
    space space space space space space  t_fieldcat ,
           3 'WERKS' 'WERKS' 'MARD' space space space space space space
    space space space space space space  t_fieldcat,
           4 'LGORT' 'LGORT' 'MARD' space space space space space space
    space space space space space space t_fieldcat ,
           5 'LGPBE' 'LGPBE' 'MARD' space space space space space space
    space space space space space space t_fieldcat ,
           6 'CHARG' 'CHARG' 'MSEG' space space space space space space
    space space space space space space t_fieldcat ,
           7 'BWART' 'BWART' 'MSEG' space  space space space space space
    space space space space space space t_fieldcat,
           8 'BUDAT' 'BUDAT' 'MKPF' space  space space space space space
    space space space space space space t_fieldcat,
           9 'MENGE' 'MENGE' 'MSEG' space  space space space space space
    space space space space space space t_fieldcat,
           10 'MEINS' 'MEINS' 'MSEG' space  space space space space space
    space space space space space space t_fieldcat,
           11 'KOSTL' 'KOSTL' 'MSEG' space  space space space space space
    space space space space space space t_fieldcat,
           12 'AUFNR' 'AUFNR' 'MSEG' space  space space space space space
    space space space space space space t_fieldcat,
           13 'RSNUM' 'RSNUM' 'MSEG' space  space space space space space
    space space space space space space t_fieldcat,
       14 'ENDKZ' 'ENDKZ' 'COWB_COMP' space space 'select' 'Select this row' 'Sel' 'Select this row' space space space 'X' 'X' space t_fieldcat.
    Layout
    x_layout-zebra = 'X'.
    Top of page heading
    PERFORM set_top_page_heading USING t_heading t_event.
    Events
    PERFORM set_events USING t_event.
    GUI Status
    w_status = ''.
    User commands
    w_comm   = 'USER_COMMAND'.
    Order
    Example
    PERFORM set_order USING '<field>' 'IT_DATA' 'X' space space t_sort.
    PERFORM set_order USING 'MBLNR' 'IT_DATA' 'X' space 'X' t_sort.
    PERFORM set_order USING 'EBELN' 'IT_DATA' 'X' space 'X' t_sort.
    PERFORM set_order USING 'EBELP' 'IT_DATA' 'X' space space t_sort.
    Displays the ALV grid
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       i_callback_program       = V_REPID
       it_fieldcat              = t_fieldcat
       is_layout                = x_layout
       it_sort                  = t_sort
       i_callback_pf_status_set = w_status
       i_callback_user_command  = w_comm
       i_save                   = 'X'
       it_events                = t_event
       i_grid_title             = w_title
    TABLES
       t_outtab                 = t_data
    EXCEPTIONS
       program_error            = 1
       OTHERS                   = 2.
    IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ENDFORM.                    " build_alv.
    *&      Form  set_top_page_heading
          Creates the report headings.
    FORM set_top_page_heading USING t_heading TYPE slis_t_listheader
         t_events  TYPE slis_t_event.
    DATA: x_heading TYPE slis_listheader,
           x_event   TYPE LINE OF slis_t_event.
    Report title
    CLEAR t_heading[].
    CLEAR x_heading.
    x_heading-typ = 'H'.
    x_heading-info = 'Reporte Prueba'(001).
    APPEND x_heading TO t_heading.
    Program name
    CLEAR x_heading.
    x_heading-typ = 'S'.
    x_heading-KEY = 'Program: '.
    x_heading-info = sy-repid.
    APPEND x_heading TO t_heading.
    User who is running the report
    CLEAR x_heading.
    x_heading-typ = 'S'.
    x_heading-KEY = 'User: '.
    x_heading-info = sy-uname.
    APPEND x_heading TO t_heading.
    Date of execution
    CLEAR x_heading.
    x_heading-typ = 'S'.
    x_heading-KEY = 'Date: '.
    WRITE sy-datum TO x_heading-info.
    APPEND x_heading TO t_heading.
    Time of execution
    CLEAR x_heading.
    x_heading-typ = 'S'.
    x_heading-KEY = 'Time: '.
    WRITE sy-uzeit TO x_heading-info.
    APPEND x_heading TO t_heading.
    Top of page event
    x_event-name = slis_ev_top_of_page.
    x_event-FORM = 'TOP_OF_PAGE'.
    APPEND x_event TO t_events.
    ENDFORM.
    *&      Form  set_events
          Sets the events for ALV.
          The TOP_OF_PAGE event is alredy being registered in
          the set_top_page_heading subroutine.
    FORM set_events USING t_events TYPE slis_t_event.
    DATA: x_event   TYPE LINE OF slis_t_event.
    Example
    clear x_event.
    x_event-name = .
    x_event-form = .
    append x_event to t_event.
    ENDFORM.
    *&      Form  set_order
          Adds an entry to the order table.
    FORM set_order USING p_fieldname p_tabname p_up p_down p_subtot
         t_sort TYPE slis_t_sortinfo_alv.
    DATA: x_sort TYPE slis_sortinfo_alv.
    CLEAR x_sort.
    x_sort-fieldname = p_fieldname.
    x_sort-tabname   = p_tabname.
    x_sort-UP = p_up.
    x_sort-down = p_down.
    x_sort-subtot = p_subtot.
    APPEND x_sort TO t_sort.
    ENDFORM.                    "set_order
    *&      Form  set_fieldcat2
          Adds an entry to the field catalog.
    FORM set_fieldcat2 USING p_colpos p_fieldname p_ref_fieldname
    p_ref_tabname
         p_outputlen p_noout
         p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt
         p_hotspot p_showasicon p_checkbox p_edit
         p_dosum
         t_fieldcat TYPE slis_t_fieldcat_alv.
    DATA: wa_fieldcat TYPE slis_fieldcat_alv.
    CLEAR wa_fieldcat.
    General settings
    wa_fieldcat-fieldname = p_fieldname.
    wa_fieldcat-col_pos = p_colpos.
    wa_fieldcat-no_out = p_noout.
    wa_fieldcat-HOTSPOT = p_hotspot.
    wa_fieldcat-CHECKBOX = p_checkbox.
    wa_fieldcat-ICON = p_showasicon.
    wa_fieldcat-do_sum = p_dosum.
    Set reference fieldname, tablenam and rollname.
    If p_ref_tabname is not given, the ref_fieldname given is a data
    *element.
    If p_ref_tabname is given, the ref_fieldname given is a field of a
    *table. In case ref_fieldname is not given, it is copied from the
    *fieldname.
    IF p_ref_tabname IS INITIAL.
       wa_fieldcat-rollname =   p_ref_fieldname.
    ELSE.
       wa_fieldcat-ref_tabname = p_ref_tabname.
       IF p_ref_fieldname EQ space.
         wa_fieldcat-ref_fieldname =   wa_fieldcat-fieldname.
       ELSE.
         wa_fieldcat-ref_fieldname =   p_ref_fieldname.
       ENDIF.
    ENDIF.
    Set output length.
    IF NOT p_outputlen IS INITIAL.
       wa_fieldcat-outputlen = p_outputlen.
    ENDIF.
    Set text headers.
    IF NOT p_seltext_m IS INITIAL.
       wa_fieldcat-seltext_m = p_seltext_m.
    ENDIF.
    IF NOT p_seltext_l IS INITIAL.
       wa_fieldcat-seltext_l = p_seltext_l.
    ENDIF.
    IF NOT p_seltext_s IS INITIAL.
       wa_fieldcat-seltext_s = p_seltext_s.
    ENDIF.
    IF NOT p_reptext_ddic IS INITIAL.
       wa_fieldcat-reptext_ddic = p_reptext_ddic.
    ENDIF.
    IF NOT p_ddictxt IS INITIAL.
       wa_fieldcat-ddictxt = p_ddictxt.
    ENDIF.
    Set as editable or not.
    IF NOT p_edit IS  INITIAL.
       wa_fieldcat-INPUT     = 'X'.
       wa_fieldcat-EDIT     = 'X'.
    ENDIF.
    APPEND wa_fieldcat TO t_fieldcat.
    ENDFORM.                   "set_fieldcat2
    *&      Form  top_of_page
          Called on top_of_page ALV event.
          Prints the heading.
    FORM top_of_page.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
         i_logo             = 'TRVPICTURE04'
       it_list_commentary = t_heading.
    ENDFORM.                    " alv_top_of_page
    *&      Form  user_command
          Called on user_command ALV event.
          Executes custom commands.
    FORM user_command USING r_ucomm     LIKE sy-ucomm
         rs_selfield TYPE slis_selfield.
    case sy-ucomm.
    WHEN '&DATA_SAVE'.
    LOOP AT IT_DATA INTO WA WHERE ENDKZ = 'X'.
       IF WA-ENDKZ = 'X'.
    *******MODIFIED*********************************
    U DELETE THIS CODE N USER UR INSERT CODE TO CHECK
    SY-MSGV1 = WA-MBLNR.                              " U CAN DELETE
    SY-MSGV2 = WA-MATNR.                              " U CAN DELETE
    MESSAGE ID 'BC_BOR' TYPE 'I' NUMBER '888'          " U CAN DELETE
            WITH SY-MSGV1 SY-MSGV2. " U CAN DELETE
    *******MODIFIED*********************************
       INSERT ZTABLE.
       ENDIF.
    endloop.
    ENDCASE.
    ENDFORM.                    "user_command
    this is my code, database will stored in fields only.data is empty,
    how to slove that one,send any sugestion.

    Hi Lakshmi,
           Can u explain briefly what is ur requirement. U mean to say that after clicking the checkbox in data base table or Screen?
    Regards,
      Jayaram...

Maybe you are looking for

  • Bi Publisher Enterprise 11.11 Parameters.

    I am building a report and i have couple of parameters. the user will enter the values for the parameter in a text field. now, i want to make that text field optional. how can i do that? i do not want to set a default value, i want it load blank but

  • Is it possible to add music from the music downloader app to the original music app?

    I have a bunch of music downloaded on the music downloader app, and i want to play it on the airmusic app, but the airmusic app only shows music from the original music app, and not the music downloader. Is there any way to move my music from the mus

  • How do I get SWF files to open in Flash Player?

    Currently they have no program associated to the extension. When I try 'Open With...' I cannot find Flash Player at all and opening in IE causes a loop between opening an IE window and the 'Open File, Save File, ect' window. I'm currently running Win

  • How to enhance Standard View in Webdynpro

    Hi Techies, I AM NEW TO WEBDYNPRO CONCEPTS. I have requirement that, I need incorporate a new UI element "THRESHOLD SLIDER" instead of Radio Button Group, These Radio Button Group represents "Profieciency Scale of Candidate". this is dynamic, i.e, so

  • Instruct Firefox to use more RAM

    I'd like to know if there is a way to disable some of the optimizations that Firefox has made for low end systems? I have 24GB of RAM and I'd like Firefox to not page out memory when I'm working with many tabs (some with large images). Additionally I