FLAGS column on SYS.AUX_STATS$
Trying to find documentation on the meaning of the FLAGS column in the SYS.AUX_STATS$ table, but a quick 10 minute search around Google has turned up nothing useful. Anyone have any pointers? Thanks.
Thanks for the reply -- the reason for my asking was because I was comparing the contents of SYS.AUX_STATS$ between two databases to verify that the statistics were the same. These contents were identical:
SNAME PNAME PVAL1 PVAL2
SYSSTATS_MAIN CPUSPEEDNW 1737.78664
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM 36.417
SYSSTATS_MAIN MREADTIM 4
SYSSTATS_MAIN CPUSPEED 2587
SYSSTATS_MAIN MBRC 3
SYSSTATS_MAIN MAXTHR 27071488
SYSSTATS_MAIN SLAVETHR 4532224...which I suppose means that the statistics are the same. The only value that was different was FLAGS:
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO FLAGS 128It had a value of 128 on one database but a value of 1 on the other. Does that make any difference at all between the two? It doesn't seem like it would, but...
Similar Messages
-
Obtaining comma-separated list of text values associated with bitwise flag column
In the table msdb.dbo.sysjobsteps, there is a [flags] column, which is a bit array with the following possible values:
0: Overwrite output file
2: Append to output file
4: Write Transact-SQL job step output to step history
8: Write log to table (overwrite existing history)
16: Write log to table (append to existing history)
32: Include step output in history
64: Create a Windows event to use as a signal for the Cmd jobstep to abort
I want to display a comma-separated list of the text values for a row. For example, if [flags] = 12, I want to display 'Write Transact-SQL job step output to step history, Write log to table (overwrite existing history)'.
What is the most efficient way to accomplish this?Here is a query that gives the pattern:
DECLARE @val int = 43
;WITH numbers AS (
SELECT power(2, n) AS exp2 FROM (VALUES(0), (1), (2), (3), (4), (5), (6)) AS n(n)
), list(list) AS (
SELECT
(SELECT CASE WHEN exp2 = 1 THEN 'First flag'
WHEN exp2 = 2 THEN 'Flag 2'
WHEN exp2 = 4 THEN 'Third flag'
WHEN exp2 = 8 THEN 'IV Flag'
WHEN exp2 = 16 THEN 'Flag #5'
WHEN exp2 = 32 THEN 'Another flag'
WHEN exp2 = 64 THEN 'My lucky flag'
END + ', '
FROM numbers
WHERE exp2 & @val = exp2
ORDER BY exp2
FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)')
SELECT substring(list, 1, len(list) - 1)
FROM list
Here I'm creating the numbers on the fly, but it is better to have a table of numbers in your database. It can be used in many places, see here for a short discussion:
http://www.sommarskog.se/arrays-in-sql-2005.html#numbersasconcept
(Only read down to the next header.)
For FOR XML PATH thing is the somewhat obscure way we create concatenated lists. There is not really any using trying to explain how it works; it just works. The one thing to keep in mind is that it adds an extra comma at the end and the final query strips
it off.
This query does not handle that 0 has a special meaning - that is left as an exercise to the reader.
Erland Sommarskog, SQL Server MVP, [email protected] -
Hi,
I have table called Employe. And the Columns are Emp_ID,EMP_NAME,SRC_SYS_CD,DOB
I have Query like
Select
COALESCE(MAX(CASE WHEN src_sys_cd='1' THEN Emp_id END), MAX(CASE WHEN src_sys_cd='2' THEN Emp_Id END))Emp_Id,
COALESCE(MAX(CASE WHEN src_sys_cd='1' THEN Emp_name END), MAX(CASE WHEN src_sys_cd='2' THEN Emp_Name END))Emp_name,
COALESCE(MAX(CASE WHEN src_sys_cd='1' THEN dob END), MAX(CASE WHEN src_sys_cd='2' THEN dob END))dob ,
from Employe
group by dob.
I want to generalize the query like get the columns from SYS.ALL_COLUMNS table for that table name and want to pass it to COALEACE() function. I tried with Cursor. But i didnt get the appropriate results.
Is there any way to achieve this? Please help me out in this regard.
Thanks,Is this the kinda thing you're after?
Add a filter to the queries to get just a single table/
WITH allCols AS (
SELECT s.name as sName, o.name AS oName, c.name AS cName, column_id,
CASE WHEN st.name in ('float','bigint','tinyint','int','smallint','bit','datetime','money','date','datetime2','uniqueidentifier','sysname','geography','geometry') THEN st.name
WHEN st.name in ('numeric','real') THEN st.name + '('+CAST(c.scale AS VARCHAR)+','+CAST(c.precision AS VARCHAR)+')'
WHEN st.name in ('varbinary','varchar','binary','char','nchar','nvarchar') THEN st.name + '(' + CAST(ABS(c.max_length) AS VARCHAR) + ')'
ELSE st.name + ' unknown '
END + ' '+
CASE WHEN c.is_identity = 1 THEN 'IDENTITY ' ELSE '' END +
CASE WHEN c.is_nullable = 0 THEN 'NOT ' ELSE '' END + 'NULL' AS bText,
f.name AS fileGroupName
FROM sys.columns c
INNER JOIN sys.objects o
ON c.object_id = o.object_id
AND o.type = 'U'
INNER JOIN sys.systypes st
ON c.user_type_id = st.xusertype
INNER JOIN sys.schemas s
ON o.schema_id = s.schema_id
INNER JOIN sys.indexes i
ON o.object_id = i.object_id
AND i.index_id = (SELECT MIN(index_id) FROM sys.indexes WHERE object_ID = o.object_id)
INNER JOIN sys.filegroups f
ON i.data_space_id = f.data_space_id
), rCTE AS (
SELECT sName, oName, cName, column_id, CAST(cName + ' ' + bText AS VARCHAR(MAX)) as bText, CAST(cName AS VARCHAR(MAX)) AS colList, fileGroupName
FROM allCols
WHERE column_id = 1
UNION ALL
SELECT r.sName, r.oName, r.cName, c.column_id, CAST(r.bText +', ' + c.cName + ' ' +c.bText AS VARCHAR(MAX)), CAST(r.colList+ ', ' +c.cName AS VARCHAR(MAX)), c.fileGroupName
FROM allCols c
INNER JOIN rCTE r
ON c.oName = r.oName
AND c.column_id - 1 = r.column_id
), allIndx AS (
SELECT 'CREATE '+CASE WHEN is_unique = 1 THEN ' UNIQUE ' ELSE '' END+i.type_desc+' INDEX ['+i.name+'] ON ['+CAST(s.name COLLATE DATABASE_DEFAULT AS NVARCHAR )+'].['+o.name+'] (' as prefix,
CASE WHEN is_included_column = 0 THEN '['+c.name+'] '+CASE WHEN ic.is_descending_key = 1 THEN 'DESC' ELSE 'ASC' END END As cols,
CASE WHEN is_included_column = 1 THEN '['+c.name+']'END As incCols,
') WITH ('+
CASE WHEN is_padded = 0 THEN 'PAD_INDEX = OFF,' ELSE 'PAD_INDEX = ON,' END+
CASE WHEN ignore_dup_key = 0 THEN 'IGNORE_DUP_KEY = OFF,' ELSE 'IGNORE_DUP_KEY = ON,' END+
CASE WHEN allow_row_locks = 0 THEN 'ALLOW_ROW_LOCKS = OFF,' ELSE 'ALLOW_ROW_LOCKS = ON,' END+
CASE WHEN allow_page_locks = 0 THEN 'ALLOW_PAGE_LOCKS = OFF' ELSE 'ALLOW_PAGE_LOCKS = ON' END+
')' as suffix, index_column_id, key_ordinal, f.name as fileGroupName
FROM sys.indexes i
LEFT OUTER JOIN sys.index_columns ic
ON i.object_id = ic.object_id
AND i.index_id = ic.index_id
LEFT OUTER JOIN sys.columns c
ON ic.object_id = c.object_id
AND ic.column_id = c.column_id
INNER JOIN sys.objects o
ON i.object_id = o.object_id
AND o.type = 'U'
AND i.type <> 0
INNER JOIN sys.schemas s
ON o.schema_id = s.schema_id
INNER JOIN sys.filegroups f
ON i.data_space_id = f.data_space_id
), idxrCTE AS (
SELECT r.prefix, CAST(r.cols AS NVARCHAR(MAX)) AS cols, CAST(r.incCols AS NVARCHAR(MAX)) AS incCols, r.suffix, r.index_column_id, r.key_ordinal, fileGroupName
FROM allIndx r
WHERE index_column_id = 1
UNION ALL
SELECT o.prefix, COALESCE(r.cols,'') + COALESCE(', '+o.cols,''), COALESCE(r.incCols+', ','') + o.incCols, o.suffix, o.index_column_id, o.key_ordinal, o.fileGroupName
FROM allIndx o
INNER JOIN idxrCTE r
ON o.prefix = r.prefix
AND o.index_column_id - 1 = r.index_column_id
SELECT 'CREATE TABLE ['+sName+'].[' + oName + '] ('+bText+') ON [' + fileGroupName +']'
FROM rCTE r
WHERE column_id = (SELECT MAX(column_id) FROM rCTE WHERE r.oName = oName)
UNION ALL
SELECT prefix + cols + CASE WHEN incCols IS NOT NULL THEN ') INCLUDE ('+incCols ELSE '' END + suffix+' ON [' + fileGroupName +']'
FROM idxrCTE x
WHERE index_column_id = (SELECT MAX(index_column_id) FROM idxrCTE WHERE x.prefix = prefix) -
Hi all,
Observing the below error in event logs once in every day at 3:30 AM on the on SQL Server Machine, it is being used for TFS 2010.
The transaction log for database 'WSS_Content' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
Kindly advice me here on what to do?
Thanks in advanceFirst thing to check is, what is happening at 3:30am to cause the log to fill up? Is there any maintenance tasks being run against the DB, such as index re-organizations or rebuilds? If so, take a look at what the job is doing, maybe it could
be tuned (ex: A Maintenance Plan with a rebuild indexes task will rebuild *every* index whether it needs it or not. Look at using something that checks how fragmented an index is, and then intelligently determines what, if anything, to do to that
index.)
Basically, the error is telling you that SQL is trying to do something in the DB, and has filled up the log (either because it's not getting backed up often enough, or the transaction in question is running *very* long, or your log is set to not auto-grow)
So, a couple possible solutions:
Increase the frequency of Transaction Log backups of WSS_Content (only works if the DB is in Full Recovery)
If you've got the disk space, turn on auto-growth for the TLog (or just manually grow it larger) {This will work for both Full and Simple Recovery}
It would be nice to know what's causing the space to not be re-used, but with this occuring at 3:30am, you'll either need to set up an Agent job to run around that time and record its results, or manually run something like "select log_reuse_wait_desc from
sys.databases where name = 'WSS_Content';" Me, I prefer to be soundly sleeping at 3:30am and would set up an Agent job to run from say about 3:00am to 3:45am once per minute (maybe even more frequently.)
DON'T shrink the log, though. SQL will idealy grow the log as large as it needs it (if autogrowth is enabled) and no more. If you shrink the file, SQL will just have to re-grow it later again, which can affect performance.
Jason A. -
Where can I find meaings of each column in sys.tables
Command> host ttversion
TimesTen Release 11.2.2.2.0 (64 bit Linux/x86_64) (tt1122:53396) 2011-12-23T09:26:28Z
Instance admin: tttest
Instance home directory: /timesten/TimesTen/tt1122
Group owner: tttest
Daemon home directory: /timesten/TimesTen/tt1122/info
PL/SQL enabled.
Command> desc sys.tables;
System table SYS.TABLES:
Columns:
SYS26 TT_BIGINT NOT NULL
*TBLNAME TT_CHAR (31) NOT NULL
*TBLOWNER TT_CHAR (31) NOT NULL
SYS2 TT_SMALLINT NOT NULL
SYS18 TT_BIGINT NOT NULL
SYS1 TT_BIGINT NOT NULL
OWNER TT_INTEGER NOT NULL
SYS3 TT_INTEGER NOT NULL
SYS33 TT_BIGINT NOT NULL
SYS8 TT_BIGINT NOT NULL
SYS4 TT_SMALLINT NOT NULL
NUMVARY TT_SMALLINT NOT NULL
NUMNULL TT_SMALLINT NOT NULL
NUMCOLS TT_SMALLINT NOT NULL
LENGTH TT_BIGINT NOT NULL
SYS19 TT_BIGINT NOT NULL
SYS20 BINARY (1) NOT NULL
SYS21 BINARY (1) NOT NULL
SYS5 TT_SMALLINT NOT NULL
NUMLOB TT_SMALLINT NOT NULL
SYS65 TT_SMALLINT NOT NULL
SYS6 TT_BIGINT NOT NULL
SYS31 TT_BIGINT NOT NULL
SYS40 TT_BIGINT NOT NULL
SYS41 TT_BIGINT NOT NULL
SYS43 TT_BIGINT NOT NULL
SYS39 BINARY (1) NOT NULL
NUMCOMPRESS TT_SMALLINT NOT NULL
SYS64 TT_INTEGER NOT NULL
SYS7 TT_BIGINT NOT NULL
TBLID TT_BIGINT NOT NULL
NUMTUPS TT_BIGINT NOT NULL
MAXTUPS TT_BIGINT NOT NULL
SYS9 TT_INTEGER NOT NULL
SYS10 TT_INTEGER NOT NULL
SYS29 BINARY (4000) NOT NULL
SYS32 TT_BIGINT NOT NULL
SYS11 TT_BIGINT NOT NULL
PRIMCNT TT_SMALLINT NOT NULL
PRIMCOLS BINARY (32) NOT NULL
SYS22 TT_BIGINT NOT NULL
SYS12 TT_BIGINT NOT NULL
CACHEFLAG BINARY (1) NOT NULL
XLAFLAG BINARY (1) NOT NULL
PXLAFLAG BINARY (1) NOT NULL
SYS16 TT_SMALLINT NOT NULL
CACHEGROUP TT_BIGINT NOT NULL
OCACHEGROUP TT_BIGINT NOT NULL
MVID TT_BIGINT NOT NULL
MVIDS TT_VARCHAR (1024) NOT INLINE
CGFKIDS TT_VARCHAR (8192) NOT INLINE
PERMLTBLID TT_BIGINT NOT NULL
SYS44 TT_INTEGER NOT NULL
CVVERSIONNUM TT_INTEGER NOT NULL
SYS24 TT_SMALLINT NOT NULL
SYS57 TT_SMALLINT NOT NULL
SYS25 TT_INTEGER NOT NULL
REPNUMKEYCOLS TT_SMALLINT NOT NULL
REPTSCOLNUM TT_SMALLINT NOT NULL
REPRETURNSERVICE TT_CHAR (1) NOT NULL
REPRETURNBYREQUEST BINARY (1) NOT NULL
REPUSERID TT_BIGINT NOT NULL
SYS34 TT_INTEGER NOT NULL
SYS35 TT_INTEGER NOT NULL
SYS36 TT_BIGINT NOT NULL
SYS37 TT_BIGINT NOT NULL
REPKEYCOLS BINARY (32) NOT NULL
SYS27 BINARY (240) NOT NULL
REPACCESS TT_CHAR (1) NOT NULL
REPTSUPDATERULE TT_CHAR (1) NOT NULL
SYS45 TT_SMALLINT NOT NULL
SYS46 TT_BIGINT NOT NULL
SYS47 TT_INTEGER NOT NULL
SYS48 TT_INTEGER NOT NULL
SYS49 TT_INTEGER NOT NULL
SYS50 TT_INTEGER NOT NULL
SYS51 TT_INTEGER NOT NULL
SYS52 TT_INTEGER NOT NULL
SYS53 TT_INTEGER NOT NULL
SYS54 TT_INTEGER NOT NULL
SYS55 TT_BIGINT NOT NULL
SYS56 TT_BIGINT NOT NULL
SYS28 BINARY (16) NOT NULL
CACHEDTBLPOS TT_INTEGER NOT NULL
SYS58 TT_SMALLINT NOT NULL
SYS59 TT_SMALLINT NOT NULL
SYS60 TT_BIGINT NOT NULL
SYS61 TT_BIGINT NOT NULL
SYS62 TT_BIGINT NOT NULL
VALTBLIDS VARBINARY (8000) NOT INLINE
SYS63 TT_INTEGER NOT NULL
SYS66 TT_INTEGER NOT NULL
SYS67 TT_BIGINT NOT NULL
SYS68 TT_BIGINT NOT NULL
SYS17 BINARY (32) NOT NULL
1 table found.
(primary key columns are indicated with *)
I searched white book of Timesten11.2, but the columns of sys.tables in it is different from above.
also, in http://docs.oracle.com/cd/E13085_01/doc/timesten.1121/e17114/systemtables.htm#TTSYS379, I can't find it.
Thanks a lot .Why do you need to know this? Is there some specific information you are trying to find?
Note the columns SYS[n] are not and never have been documented. Although they may contain values these are internal to Engineering and not generally made public. There is no guarantee that the use of a SYS[n] column will stay the same between releases as well. -
Difference between is_published and is_replicated columns of sys.tables
Hello,
Can someone please tell me the exact difference between is_published and is_replicated columns of sys.tables? I know is_published is inherited from sys.objects table , but purpose of both the columns are same. However sometimes for some replicated tables
i have seen is_published = 1 and is_replicated = 0 and for another published database tables value of both columns are 1.
It is bit confusing. Can you please explain?
Thanks in Advance.
-MalkeshIs published has a value of 1 for snapshot and transactional replication, and peer to peer.
Is_replicated has a value of 1 for transactional, p2p, and cdc.
The values will be 1 for both the pub and the subscriber in p2p, but are 0 for both for all other subscription types.
The values are always 0 for merge.
looking for a book on SQL Server 2008 Administration?
http://www.amazon.com/Microsoft-Server-2008-Management-Administration/dp/067233044X looking for a book on SQL Server 2008 Full-Text Search?
http://www.amazon.com/Pro-Full-Text-Search-Server-2008/dp/1430215941 -
!! (2 exclamation points) in Flag column
Does anyone know why I have !! (2 exclamation points) next to some of my messages in the "flag" column? I have a brand new iMac, Mail 4.2. I've been using Mail for years and this is the first time I'm seeing it. I've done "flag/unflag", etc, and nothing gets rid of them or explains why they're there.
Thanks!!babysnakes wrote:
Does anyone know why I have !! (2 exclamation points) next to some of my messages in the "flag" column? I have a brand new iMac, Mail 4.2. I've been using Mail for years and this is the first time I'm seeing it. I've done "flag/unflag", etc, and nothing gets rid of them or explains why they're there.
That means that the message is set to have "high priority". You can expose a priority field (at least for new messages) by pulling down the list to the left of the ""From" field and selecting "Priority Field". -
Decode of system FLAGS columns?
I'm looking for a resource/writeup that can tell me what the different values in the FLAGS columns mean. Specifically I'm looking at indpart$.flags and tabpart$.flags and seg$.spare1. If I'm looking in the wrong place please let me know.
I'm trying to write a (generic) procedure to compress partitions on tables that may or may not have already been compressed. If the table has not been compressed and it has valid bitmap indexes then any attempt to compress will fail with the following error:
SQL Error: ORA-14646: Specified alter table operation involving compression cannot be performed in the presence of usable bitmap indexes.
In most cases I can look at the partitions using dba_tab_partitions and check the COMPRESSION column value. However, it's possible to have that column tell you the partition is compressed (COMPRESSION = ENABLED) without the partition actually being compressed. This has been documented elsewhere and I won't go into it.
Within my procedure I would like to proactively verify the partition(s) to see if they really are compressed. If at least one partition is compressed then there is no need to disable all the bitmap indexes at the table level. I'll disable the bitmap indexes at the table level only if it is absolutely necessary.
Alternatively, my only other way to make this work is to try the MOVE command and if ORA-14646 is thrown then go back and disable the bitmap indexes an try again.Thanks Dan! I think I found some promising values. I'll have to play with them but you put me on the right track.
-
Best Practice for "flag" columns
Hello Experts!
This is more of a design/architecture/performance? question. Suggestions welcome, of course!
Oracle Server version 11.2.0.3
Scenario:
I plan to use one of my columns in the table as a "flag" field. Meaning, this field will have some type of static value. Our document management system leverages Oracle as the database and provides a front-end user interface for the user. When the user searches for their documents, the records will be displayed accordingly. If the user wants to "delete" the document, they would change the flag field from "No" to "Yes". The custom search that we would have already built for them would have a hidden where clause of "where column_flag = 'No'" to show the records that they searched and of course if they change the flag to "Yes" (to be deleted), it will no longer appear in their search results. The field would be a string datatype.
My Second Thought:
Same scenario above, except for 1 change. Instead of the "No" and "Yes" value, I would replace the value to a blank/null value and "Delete". Essentially, the drop-down value would change from "No" and "Yes" values to a blank value and "Delete". Visually, this would make more sense to our users when they see the data and for when they decide to choose to "delete" a document. At this point, the where clause would of course change to "where column_flag is null".
My Question:
From a performance perspective, which is a better practice?
Is it faster to query the database with "where column_flag = 'No'" / "where column_flag = 'Yes'" OR "where column_flag is null" / "where column_flag = 'Delete'"?
Should I even create an index on the column? (I would assume no because it would serve no benefit because of the static values).
Keep in mind that I will have millions and millions of records/rows in the table. I am striving for the best possible answer in terms of long-term performance. In the past, I have had users complain about "slow searches" and that is what I would like to help prevent from happening.
Thanks in advance for all your help and suggestions!rp0428 wrote:
When the user searches for their documents, the records will be displayed accordingly. If the user wants to "delete" the document, they would change the flag field from "No" to "Yes". The custom search that we would have already built for them would have a hidden where clause of "where column_flag = 'No'" to show the records that they searched and of course if they change the flag to "Yes" (to be deleted), it will no longer appear in their search results.
Why? If you user wants to delete the document just delete it. Then you don't need ANY of the mucking around.
What is it you aren't telling us? Why would you just mark it instead of actually delete it?
The reason is because of senior upper management policy, where they do not want to actually delete/remove the record from the system. They only want to "delete"/hide the record from the search result from the user if they choose to "delete" a document. Part of this is to help prevent a restore from happening. Lets say a user accidentally deletes (an actual real delete) of a document and the next day/week/month/year she says, "oops, I made a mistake can you undo it?" The answer is yes, but then we now lose more documents/data just to restore that 1 document because of all the other documents that were added to the system the previous day. Make sense? However, in this scenario, if they just mark it for "deletion" and they think that they are actually deleting it, but what it's really doing is hiding it from their search results, then if she comes and says, "oops, I made a mistake can you undo it?" We can simply change the flag/property from "Yes" to "No" (or from one to the other basically, and assuming she provides us with all the necessary information for the document for us to find it) and then we don't have to actually perform a system "restore" any thing.
rp0428 wrote:
Is it faster to query the database with "where column_flag = 'No'" / "where column_flag = 'Yes'" OR "where column_flag is null" / "where column_flag = 'Delete'"?
Not enough info to know. Query performance will depend on the query, all of the data needed for the query, indexes available and other things.
The query will always have this hidden where clause of "where column_flag = 'No'" in the front-end UI for the user. The UI for the user basically has pertinent information for them to search off of for a particular set of documents with the additional where clause to search for documents that are not marked for deletion. For instance, HR would have searchable fields, like FirstName, LastName, EmployeeID, SocialSecurityNumber, etc.. the user has the ability to search for any of these fields and when they populate any of these fields and clicks search, it goes out and retrieves all of the documents that are found based on the criteria entered. The additional where clause of "where column_flag = 'No'" will always be added somewhere in the where clause of the SQL query because we only want to display documents that are not marked for deletion. We have no reason nor should they have any reason to see documents that they "deleted" because to them they will think that they are actually deleting/removing the document from the system when they change the flag/property.
rp0428 wrote:
Should I even create an index on the column? (I would assume no because it would serve no benefit because of the static values).
Not enough info to know. If there are 5 million YES values and 5 million NO values what purpose would an index serve? As SB said if NULL means YES but nulls aren't indexed then what purpose would an index server?
The most likely case where an index on that one column would be used is if the mosts commonly queried value is rare. More likely the actual table row will need to be obtained from the table and the filter of Y/N can be applied then.
For a simple flag just use VARCHAR2(1). There is no need to store YES or NO; that just increase the amount of storage needed for no benefit.
The majority of the documents would not be marked for deletion or would not have "No". Lets say if I had 10 million records/rows in the database, I would probably say that less than 1%? would probably be marked for deletion by the users, which is 1 million documents or less. Realistically, I would probably even go further to say that out of 10 million, I could only imagine that maybe ~50,000 would only be marked for deletion? The number is not very high and would be uncommon for the users to consistently delete documents. -
Add a flag column in the Query based on Cancel date
hi Guys,
I have a Characterstic object 0canceldate and it gets the cancellation date of the sales order. Based on that date i need to add a column in the report like if 0canceldate has ahappened or populate then show Yes or No in the coumn like a flag.
Can anybody help me how i can do that?SELECT d.NAME
FROM
(SELECT jta.NAME
FROM apps.jtf_terr_values_all jtva,
apps.jtf_terr_qual_all jtqa,
apps.jtf_terr_all jta ,
apps.hz_party_sites ps,
apps.hz_locations hl
WHERE jtva.terr_qual_id = jtqa.terr_qual_id
AND jtqa.terr_id = jta.terr_id
AND jtva.low_value_char = hl.postal_code
AND jtqa.org_id = jtva.org_id
AND jta.org_id = jtqa.org_id
AND ps.location_id = hl.location_id
AND hl.country in( 'CA', 'US')) D;
UNION
SELECT jta.NAME
FROM apps.jtf_terr_values_all jtva,
apps.jtf_terr_qual_all jtqa,
apps.jtf_terr_all jta,
apps.hz_party_sites ps,
apps.hz_locations hl
WHERE jtva.terr_qual_id = jtqa.terr_qual_id
AND jtqa.terr_id = jta.terr_id
AND ps.location_id = hl.location_id
AND jtqa.org_id = jtva.org_id
AND jta.org_id = jtqa.org_id
AND hl.country = 'US'
AND hl.postal_code BETWEEN jtva.low_value_char AND jtva.high_value_char
)d; -
Need to maintain "Flag" column
Hello,
I am trying to maintain a "Flag" that identifies an address as the primary. The latest updated address for each member_id should be the primary with its primary_flag=Y and all the others for the member_id set to N. I have added a small sample of the data but my table has 2.3 million rows so performance is key. The records are updated and inserted using a MERGE query into my members table from an external table and this works very well.
I am on 11gR1
After my MERGE this is what I might see:
member_id address_id primary_flag last_updated
12 232 N 1/2/2011
12 324 Y 2/14/2011
12 376 N 2/29/2011
25 256 N 1/13/2011
28 278 N 1/20/2011
28 291 Y 1/25/2011
30 389 Y 3/1/2011What I would like to see:
member_id address_id primary_flag last_updated
12 232 N 1/2/2011
12 324 N 2/14/2011
12 376 Y 2/29/2011
25 256 Y 1/13/2011
28 278 N 1/20/2011
28 291 Y 1/25/2011
30 389 Y 3/1/2011I have come up with a few 2-Pass (SQL Updates) but I would like to do it in one (It would be real nice if I could do it in the MERGE statement).
Thanks for any help!Hi,
Thanks for posting the sample data. The results you said you wanted included only 4 columns; don't you want to set the other columns, in particular last_update_date, as well? I included all columns in the INSERT nad UPDATE; you can easily remove them if you don't want them.
This does what I think you want:
merge into
MEMBER_ADRESS MA
using (
WITH new_data AS
select
NULL AS address_id,
ML.MEMBER_ID,
SUBSTRB (ML.ADDRESS_1, 1, 30) AS address_1,
SUBSTRB (ML.ADDRESS_2, 1, 30) AS address_2,
SUBSTRB (ML.CITY, 1, 25) AS city,
ML.STATE,
ML.ZIP_CODE AS zipcode,
SYSDATE AS creation_date,
SYSDATE AS last_update_date,
NULL AS primary_flag,
ML.ADDITIONAL_COMPANY_INFO,
to_number ( regexp_replace ( ML.ADDITIONAL_COMPANY_INFO ||
SUBSTRB (ML.ADDRESS_1, 1, 30) ||
SUBSTRB (ML.ADDRESS_2, 1, 30) ||
SUBSTRB (ML.CITY, 1, 25) ||
ML.STATE ||
ML.ZIP_CODE
, '[^[:digit:]]'
) as MATCH_VALUE,
NULL AS match_cnt
from MEMBER_LOAD_V2 ML
, primary_flag_y AS
SELECT o.*
, COUNT ( CASE
WHEN o.match_value = n.match_value
THEN 1
END
) OVER ( PARTITION BY o.member_id
) AS match_cnt
FROM member_adress o
JOIN new_data n ON o.member_id = n.member_id
WHERE o.primary_flag = 'Y'
, combined_data AS
SELECT *
FROM primary_flag_y
WHERE match_cnt = 0
UNION
SELECT *
FROM new_data
SELECT address_id, member_id, address_1, address_2, city, state
, zipcode, creation_date, last_update_date
, CASE
WHEN ROW_NUMBER () OVER ( PARTITION BY member_id
ORDER BY last_update_date DESC
) = 1
THEN 'Y'
ELSE 'N'
END AS primary_flag
, additional_company_info, match_value
FROM combined_data
) L
on (MA.MEMBER_ID = L.MEMBER_ID and MA.MATCH_VALUE = L.MATCH_VALUE)
when matched then
update set
MA.ADDRESS_ID = L.ADDRESS_ID,
MA.ADDRESS_1 = L.ADDRESS_1,
MA.ADDRESS_2 = L.ADDRESS_2,
MA.CITY = L.CITY,
MA.STATE = L.STATE,
MA.ZIPCODE = L.ZIPCODE,
MA.CREATION_DATE = L.CREATION_DATE,
MA.LAST_UPDATE_DATE = L.LAST_UPDATE_DATE,
MA.PRIMARY_FLAG = L.PRIMARY_FLAG,
MA.ADDITIONAL_COMPANY_INFO = L.ADDITIONAL_COMPANY_INFO
when not matched then
insert (MA.ADDRESS_ID, MA.MEMBER_ID, MA.ADDRESS_1, MA.ADDRESS_2, MA.CITY, MA.STATE, MA.ZIPCODE,
MA.CREATION_DATE, MA.LAST_UPDATE_DATE, MA.PRIMARY_FLAG, MA.ADDITIONAL_COMPANY_INFO)
values (
MEMBER_CNTCT_SEQ.NEXTVAL,
L.MEMBER_ID,
L.ADDRESS_1,
L.ADDRESS_2,
L.CITY,
L.STATE,
L.ZIPCODE,
L.CREATION_DATE,
L.LAST_UPDATE_DATE,
L.PRIMARY_FLAG,
L.ADDITIONAL_COMPANY_INFO
);The cruical part is that, for each member_id in the source table, it finds the row with primary_flag='Y' that's already in the table (if a row with with the same member_id and match_value isn't already in the source table), and does a UNION to include those rows, so that an existing primary_flag may get changed from 'Y' to 'N'.
It looks like the address_1, address_2 and city columns are the same length in both tables, so I don't see why you're using SUBSTR. I left it in, in case you have some reason.
You might consider a user-defined function to caluculate match_value, and use that function bioth in the definition of the virtuyal column and in the MERGE. That way, you can be sure it is being computed the same in both places, and if, in the future, you change how match_value is computed, you only need to change it in one place. Match_value looks like just the kind of thing you might refine in the future, For example, you might decide that, on the rare occassions when city or state contains digits, it suits your needs better to ignore those digits. -
Display data from BLOB column.
Hi All,
I want to display data from blob datatype field, which contains HTML and GIF both files.
If I set it's property from file format IMAGE then i get data only gif.
if anybody have answer plz revert back...
awaiting...
JunedHi Juned
What I suggest is that you may have overlapping fields. One to show HTML and other to show GIF. You need to add one more column to your table in order identify if the BLOB is GIF or HTML.
In the Format Trigger of each of these two fields, inspect the value of flag column and hide one field if the datatype is not its type.
For instance, if flag field is 0 then hide Image field and show HTML field. If flag field is 1 then show Image field and hide HTML field.
Regards
Sripathy -
Problem :ALV:Deletion Flags not showing in output
hi all !
I have a alv program which displays customer data.there are three deletion flags columns in the output.
First deletion flag will be: KNA1-LOEVM
Second deletion flag will be: KNB1-LOEVM
Third deletion flag will be: KNVV-LOEVM
earlier all three were showing.but now no one is showing.i'm pasting my code here if any expert can have a look and find out the BUG.
CODE STARTS----
report zqsdcap_cust.
INCLUDE DECLARATIONS
include:
ziabapcapph_macros. "Holcim Useful Macros
TABLE DECLARATIONS
tables:
tvko, "Org. Unit: Sales Organizations
t001, "Company codes
kna1, "Customer Master
knvv, "Customer master sales
knvi, "Customer tax classificat'n
knb1, "Customer master company code
<<CR003-DEVK949538 start ins
adr6. "SMTP numbers
<<CR003-DEVK949538 end ins
TYPE DECLARATIONS
type-pools:
slis.
STRUCTURE DECLARATIONS
Define structure for keep data in ALV list
data: begin of gs_output_list,
vkorg like knvv-vkorg, "Sales organization
ktokd like kna1-ktokd, "Customer A/C grp
kunnr like kna1-kunnr, "Customer number
vtweg like knvv-vtweg, "Distribution channel
name1 like kna1-name1, "Name1
name3 like kna1-name3, "Name3
name4 like kna1-name4, "Name4
stras like kna1-stras, "Street
cityc like kna1-cityc, "City
bezei1 like t005h-bezei, "Sales office
land1 like kna1-land1, "Country
regio like kna1-regio, "Region
bezei2 like t005u-bezei, "Region decription
kdgrp like knvv-kdgrp, "Customer group
ktext like t151t-ktext, "Cust grp name
bzirk like knvv-bzirk, "Sales district
bztxt like t171t-bztxt, "Description
zterm like knvv-zterm, "Payment term
lzone like kna1-lzone, "Transport zone
vtext like tzont-vtext, "Description
erdat like kna1-erdat, "Creation date
end of gs_output_list.
Internal table for customer tax data
data: begin of gs_output_tax,
vkorg like knvv-vkorg, "Sales organization
kunnr like kna1-kunnr, "Customer number
vtweg like knvv-vtweg, "Distribution channel
name1 like kna1-name1, "Name1
name3 like kna1-name3, "Name3
name4 like kna1-name4, "Name4
ort01 like kna1-ort01, "City
stcd1 like kna1-stcd1, "STD code
spart like knvv-spart, "Division
taxkd like knvi-taxkd, "Tax classific'n
tatyp like knvi-tatyp, "Tax category
vtext like tskdt-vtext, "Tax description
end of gs_output_tax.
Internal table for HVL customer master
data: begin of gs_output_hvl,
kunnr like kna1-kunnr, "Customer number
stceg like kna1-stceg, "VAT registration no
telfx like kna1-telfx, "Fax number
telf1 like kna1-telf1, "First telephone number
stras like kna1-stras, "House number and stret
ort02 like kna1-ort02, "District
cityc like kna1-cityc, "City code
bezei like t005h-bezei, "City description
regio like kna1-regio, "Region
ort01 like kna1-ort01, "City
name2 like kna1-name2, "Name2
name1 like kna1-name1, "Name1
bzirk like knvv-bzirk, "Sales district
spart like knvv-spart, "Division
vtweg like knvv-vtweg, "Distribution channel
vkorg like knvv-vkorg, "Sales organization
end of gs_output_hvl.
Internal table for customer database CRM
data: begin of gs_output_crm,
vkorg like knvv-vkorg, "Sales organization
vtweg like knvv-vtweg, "Distribution channel
bzirk like knvv-bzirk, "Sales district
kunnr like kna1-kunnr, "Customer number
name1 like kna1-name1, "Name1
name2 like kna1-name2, "Name2
stras like kna1-stras, "House number street
ort01 like kna1-ort01, "City
ort02 like kna1-ort02, "District
pstlz like kna1-pstlz, "Postal code
cityc like kna1-cityc, "City code
telf1 like kna1-telf1, "First telephone number
telfx like kna1-telfx, "Fax number
vkbur like knvv-vkbur, "Sales office
regio like kna1-regio, "Region
vkgrp like knvv-vkgrp, "Sales group
kdgrp like knvv-kdgrp, "Customer group
kvgr3 like knvv-kvgr3, "Customer group 3
altkn like knb1-altkn, "Previous record number
erdat like knvv-erdat, "Creation date
found_dat like zcrm_bp_ext-found_dat, "Found date
<<CR000-DEVK943142 start del
versg like knvv-versg, "Customer statistic grp
bukrs like knb1-bukrs, "Company code
<<CR000-DEVK943142 end del
end of gs_output_crm.
Internal table for customer information
data: begin of gs_output_info,
kunnr like kna1-kunnr, "Customer number
vkorg like knvv-vkorg, "Sales organization
vtweg like knvv-vtweg, "Distribution channel
stcd2 like kna1-stcd2, "Tax code
name1 like kna1-name1, "Name1
name2 like kna1-name2, "Name2
<<CR002-DEVK944835 start ins
name3 like kna1-name3, "Name3
<<CR002-DEVK944835 end ins
stras like kna1-stras, "House number street
ort01 like kna1-ort01, "City
ort02 like kna1-ort02, "District
pstlz like kna1-pstlz, "Postal code
regio like kna1-regio, "Region
land1 like kna1-land1, "Country code
cityc like kna1-cityc, "City code
telf1 like kna1-telf1, "First telephone number
telfx like kna1-telfx, "Fax number
<<CR001-DEVK944239 start ins
bzirk like knvv-bzirk, "Sales District
vkbur like knvv-vkbur, "Sales Office
kdgrp like knvv-kdgrp, "Customer group
<<CR001-DEVK944239 end ins
vkgrp like knvv-vkgrp, "Sales group
kvgr3 like knvv-kvgr3, "Customer group 3
versg like knvv-versg, "Customer stat grp
kdkg2 like kna1-kdkg2, "Customer condition gp2
kdkg1 like kna1-kdkg1, "Customer condition gp1
<<CR001-DEVK944239 start del
kdgrp like knvv-kdgrp, "Customer group
<<CR001-DEVK944239 end del
altkn like knb1-altkn, "Previous record#
erdat like knvv-erdat, "Creation date
note_text(200) type c, "<<CR003-DEVK949538 ins
smtp_addr like adr6-smtp_addr, "<<CR003-DEVK949538 ins
loevm1 like kna1-loevm, "Deletion flag all
loevm2 like knb1-loevm, "Deletion flag Cd
loevm3 like knvv-loevm, "Deletion flag sal
end of gs_output_info.
ALV Grid Declaration
data:
gs_fieldcat type slis_fieldcat_alv,
gs_layout type slis_layout_alv,
gs_event type slis_t_event,
gs_variant like disvariant,
gs_sort_info type slis_sortinfo_alv,
gs_exit_caused_by_user type slis_exit_by_user,
gs_tabname type slis_tabname,
gs_header type slis_entry.
INTERNAL TABLE DECLARATIONS
Define internal table for keep data in ALV list
data:
gt_output_list like table of gs_output_list,
gt_output_tax like table of gs_output_tax,
gt_output_hvl like table of gs_output_hvl,
gt_output_crm like table of gs_output_crm,
gt_output_info like table of gs_output_info,
<<CR003-DEVK949538 start ins
gv_text like tline occurs 0 with header line,
<<CR003-DEVK949538 start ins
ALV Grid Declaration
gt_fieldcat type slis_t_fieldcat_alv,
gt_list_top_of_page type slis_t_listheader,
gt_list_top_of_page2 type slis_t_listheader,
gt_sort_info type slis_t_sortinfo_alv.
VARIABLE DECLARATIONS
data:
ALV Grid Declaration
gv_save,
gv_exit_caused_by_caller,
gv_repid type sy-repid,
gv_user_command type slis_formname value 'USER_COMMAND',
gv_top_of_page type slis_formname value 'TOP_OF_PAGE',
gv_top_of_list type slis_formname value 'TOP_OF_LIST',
gv_end_of_list type slis_formname value 'END_OF_LIST',
lv_store like thead-tdname, "<<CR003-DEVK949538 ins
lv_id like thead-tdid, "<<CR003-DEVK949538 ins
lv_lines type i. "<<CR003-DEVK949538 ins
SELECTION SCREEN DECLARATIONS
Define selection-screen of query
selection-screen: begin of block blk with frame title text-001.
select-options: s_vkorg for knvv-vkorg "Sales org
obligatory
memory id vko,
s_bzirk for knvv-bzirk, "Sales district
s_vtweg for knvv-vtweg, "Dist channel
s_spart for knvv-spart "Division
default 'CM',
s_taxkd for knvi-taxkd, "Tax classific'n
s_kunnr for kna1-kunnr, "Customer number
s_regio for kna1-regio, "Region
s_kdgrp for knvv-kdgrp, "Customer group
s_vkgrp for knvv-vkgrp, "Sales group
s_vkbur for knvv-vkbur, "Sales office
s_lzone for kna1-lzone, "Zone
s_erdat for kna1-erdat, "Creation date
s_zuawa for knb1-zuawa, "Key for sorting
s_ktokd for kna1-ktokd, "Customer A/C grp
s_altkn for knb1-altkn, "Previous rec no
s_bukrs for knb1-bukrs "Company code
obligatory
memory id buk,
s_loevm1 for kna1-loevm, "Deletion flag all
s_loevm2 for knb1-loevm, "Deletion flag Cd
s_loevm3 for knvv-loevm. "Deletion flag sal
selection-screen: end of block blk.
selection-screen: begin of block b2 with frame title text-002.
parameters: pr_cust1 radiobutton group a1
default 'X'
user-command bkg,
pr_cust2 radiobutton group a1,
pr_cust3 radiobutton group a1,
pr_cust4 radiobutton group a1,
pr_cust5 radiobutton group a1.
selection-screen: end of block b2.
AT SELECTION-SCREEN ON S_VKORG
at selection-screen on s_vkorg.
select vkorg
into tvko-vkorg
from tvko
where vkorg in s_vkorg.
authorization check for sales org.
authority-check object 'V_VBRK_VKO'
id 'VKORG' field tvko-vkorg
id 'ACTVT' field '03'.
check sy-subrc ne 0.
message e002(zgen) with 'No authorization for sales org.'
tvko-vkorg.
endselect.
AT SELECTION-SCREEN ON S_BUKRS
at selection-screen on s_bukrs.
if pr_cust4 eq 'X' or
pr_cust5 eq 'X'.
select bukrs
into t001-bukrs
from t001
where bukrs in s_bukrs.
authorization check for plant and company code
authority-check object 'A_S_WERK'
id 'BUKRS' field t001-bukrs
id 'WERKS' dummy.
check sy-subrc ne 0.
message e002(zgen) with 'No authorization for this company code.'
t001-bukrs.
endselect.
endif.
AT SELECTION-SCREEN OUTPUT
at selection-screen output.
loop at screen .
if pr_cust1 eq 'X'.
if screen-name = 'S_VTWEG-LOW' or
screen-name = 'S_VTWEG-HIGH' or
screen-name = 'S_SPART-LOW' or
screen-name = 'S_SPART-HIGH' or
screen-name = 'S_TAXKD-LOW' or
screen-name = 'S_TAXKD-HIGH' or
screen-name = 'S_BUKRS-LOW' or
screen-name = 'S_BUKRS-HIGH' or
screen-name = 'S_ERDAT-LOW' or
screen-name = 'S_ERDAT-HIGH' or
screen-name = 'S_ALTKN-LOW' or
screen-name = 'S_ALTKN-HIGH' or
screen-name = 'S_VKBUR-LOW' or
screen-name = 'S_VKBUR-HIGH' or
screen-name = 'S_LOEVM1-LOW' or
screen-name = 'S_LOEVM1-HIGH' or
screen-name = 'S_LOEVM2-LOW' or
screen-name = 'S_LOEVM2-HIGH' or
screen-name = 'S_LOEVM3-LOW' or
screen-name = 'S_LOEVM3-HIGH'.
screen-input = 0.
endif.
elseif pr_cust2 eq 'X'.
if screen-name = 'S_BZIRK-LOW' or
screen-name = 'S_BZIRK-HIGH' or
screen-name = 'S_KDGRP-LOW' or
screen-name = 'S_KDGRP-HIGH' or
screen-name = 'S_LZONE-LOW' or
screen-name = 'S_LZONE-HIGH' or
screen-name = 'S_KTOKD-LOW' or
screen-name = 'S_KTOKD-HIGH' or
screen-name = 'S_ERDAT-LOW' or
screen-name = 'S_ERDAT-HIGH' or
screen-name = 'S_KTOKD-LOW' or
screen-name = 'S_KTOKD-HIGH' or
screen-name = 'S_ALTKN-LOW' or
screen-name = 'S_ALTKN-HIGH' or
screen-name = 'S_VKBUR-LOW' or
screen-name = 'S_VKBUR-HIGH' or
screen-name = 'S_LOEVM1-LOW' or
screen-name = 'S_LOEVM1-HIGH' or
screen-name = 'S_LOEVM2-LOW' or
screen-name = 'S_LOEVM2-HIGH' or
screen-name = 'S_LOEVM3-LOW' or
screen-name = 'S_LOEVM3-HIGH' or
screen-name = 'S_BUKRS-LOW' or
screen-name = 'S_BUKRS-HIGH' or
screen-name = 'S_VKGRP-LOW' or
screen-name = 'S_VKGRP-HIGH'.
screen-input = 0.
endif.
elseif pr_cust3 eq 'X'.
if screen-name = 'S_BZIRK-LOW' or
screen-name = 'S_BZIRK-HIGH' or
screen-name = 'S_KDGRP-LOW' or
screen-name = 'S_KDGRP-HIGH' or
screen-name = 'S_LZONE-LOW' or
screen-name = 'S_LZONE-HIGH' or
screen-name = 'S_ERDAT-LOW' or
screen-name = 'S_ERDAT-HIGH' or
screen-name = 'S_KTOKD-LOW' or
screen-name = 'S_KTOKD-HIGH' or
screen-name = 'S_SPART-LOW' or
screen-name = 'S_SPART-HIGH' or
screen-name = 'S_TAXKD-LOW' or
screen-name = 'S_TAXKD-HIGH' or
screen-name = 'S_REGIO-LOW' or
screen-name = 'S_REGIO-HIGH' or
screen-name = 'S_ALTKN-LOW' or
screen-name = 'S_ALTKN-HIGH' or
screen-name = 'S_VKBUR-LOW' or
screen-name = 'S_VKBUR-HIGH' or
screen-name = 'S_LOEVM1-LOW' or
screen-name = 'S_LOEVM1-HIGH' or
screen-name = 'S_LOEVM2-LOW' or
screen-name = 'S_LOEVM2-HIGH' or
screen-name = 'S_LOEVM3-LOW' or
screen-name = 'S_LOEVM3-HIGH' or
screen-name = 'S_BUKRS-LOW' or
screen-name = 'S_BUKRS-HIGH' or
screen-name = 'S_VKGRP-LOW' or
screen-name = 'S_VKGRP-HIGH' or
screen-name = 'S_VTWEG-LOW' or
screen-name = 'S_VTWEG-HIGH'.
screen-input = 0.
endif.
elseif pr_cust4 eq 'X'.
if screen-name = 'S_LZONE-LOW' or
screen-name = 'S_LZONE-HIGH' or
screen-name = 'S_TAXKD-LOW' or
screen-name = 'S_TAXKD-HIGH' or
screen-name = 'S_REGIO-LOW' or
screen-name = 'S_REGIO-HIGH' or
screen-name = 'S_ZUAWA-LOW' or
screen-name = 'S_ZUAWA-HIGH'.
screen-input = 0.
endif.
else.
if screen-name = 'S_LZONE-LOW' or
screen-name = 'S_LZONE-HIGH' or
screen-name = 'S_TAXKD-LOW' or
screen-name = 'S_TAXKD-HIGH'.
screen-input = 0.
endif.
endif.
modify screen.
endloop.
INITIALIZATION
initialization.
perform deactivate_program using sy-cprog.
START OF SELECTION
start-of-selection.
Customized function to get data from database table
perform get_data.
<<CR003-DEVK949538 start ins
perform get_internal_note_text tables gt_output_info.
<<CR003-DEVK949538 end ins
Create sort of ALV list
perform build_sort.
Send data to ALV list to display
if pr_cust1 eq 'X'.
gs_tabname = text-003.
gs_header = text-004.
perform write_alv_report tables gt_output_list
gt_sort_info.
elseif pr_cust2 eq 'X'.
gs_tabname = text-005.
gs_header = text-006.
perform write_alv_report tables gt_output_tax
gt_sort_info.
elseif pr_cust3 eq 'X'.
gs_tabname = text-007.
gs_header = text-008.
perform write_alv_report tables gt_output_hvl
gt_sort_info.
elseif pr_cust4 eq 'X'.
gs_tabname = text-009.
gs_header = text-010.
perform write_alv_report tables gt_output_crm
gt_sort_info.
else.
gs_tabname = text-011.
gs_header = text-012.
perform write_alv_report tables gt_output_info
gt_sort_info .
endif.
FORM EVENTTAB_FIELD
Fill Event tab, for ALV Grid Display
form eventtab_field using gs_events type slis_t_event.
data:
ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gs_events.
read table gs_events with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move gv_top_of_page to ls_event-form.
append ls_event to gs_events.
endif.
endform. " eventtab_field
FORM TOP_OF_PAGE
Write at Top of Page of ALV grid
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = gt_list_top_of_page.
endform. "top_of_page
FORM COMMENT_BUILD
Write header of ALV grid
form comment_build using lt_top_of_page type slis_t_listheader
gs_header.
data:
lv_tdate(10),
lv_fdate(10),
ls_line type slis_listheader.
clear: ls_line.
ls_line-typ = 'H'.
ls_line-info = gs_header.
append ls_line to lt_top_of_page.
endform. "comment_build
FORM INIT_FIELDCAT
Fill Field Catalog for ALV Grid
form init_fieldcat using gs_tabname.
refresh: gt_fieldcat.
use this function to get the all fields in the structure.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = gv_repid
i_internal_tabname = gs_tabname
i_inclname = gv_repid
changing
ct_fieldcat = gt_fieldcat.
if sy-subrc eq 0.
clear mark for key field to set color of key column
gs_fieldcat-key = ''.
modify gt_fieldcat from gs_fieldcat transporting key
where fieldname ne space.
read table gt_fieldcat with key fieldname = 'FOUND_DAT'
into gs_fieldcat.
gs_fieldcat-seltext_l = text-013.
modify gt_fieldcat from gs_fieldcat
transporting seltext_l
where fieldname = 'FOUND_DAT'.
<<CR003-DEVK949538 start ins
read table gt_fieldcat with key fieldname = 'NOTE_TEXT'
into gs_fieldcat.
gs_fieldcat-seltext_l = text-014.
modify gt_fieldcat from gs_fieldcat
transporting seltext_l
where fieldname = 'NOTE_TEXT'.
<<CR003-DEVK949538 start ins
endif.
endform. "init_fieldcat
FORM INIT_LAYOUT
Layout initial
form init_layout using gs_layout type slis_layout_alv.
gs_layout-info_fieldname = 'LINECOLOR'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-zebra = 'X'.
endform. " init_layout
FORM WRITE_ALV_REPORT
form write_alv_report tables gt_output
gt_sort_info.
ALV Grid display
clear: gv_repid,
gv_save.
gv_repid = sy-repid.
gs_variant-report = gv_repid.
gv_save = 'A'.
Build fieldcatalog
perform init_fieldcat using gs_tabname.
Build list events
perform eventtab_field using gs_event.
Show in ALV Grid form
perform init_layout using gs_layout.
Build comments
perform comment_build using gt_list_top_of_page[]
gs_header.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_buffer_active = ' '
i_callback_program = gv_repid
is_layout = gs_layout
i_save = gv_save
is_variant = gs_variant
it_events = gs_event[]
it_sort = gt_sort_info[]
it_fieldcat = gt_fieldcat[]
importing
e_exit_caused_by_caller = gv_exit_caused_by_caller
es_exit_caused_by_user = gs_exit_caused_by_user
tables
t_outtab = gt_output
exceptions
program_error = 1
others = 2.
endform. "write_alv_report
FORM GET_DATA
form get_data.
Get customer list
if pr_cust1 eq 'X'.
select knvv~vkorg
kna1~ktokd
kna1~kunnr
knvv~vtweg
kna1~name1
kna1~name3
kna1~name4
kna1~stras
kna1~cityc
kna1~regio
kna1~land1
knvv~kdgrp
knvv~bzirk
knvv~zterm
kna1~lzone
kna1~erdat
from kna1 join knvv
on kna1kunnr = knvvkunnr
into corresponding fields of table gt_output_list
where kna1~kunnr in s_kunnr
and knvv~vkorg in s_vkorg
and knvv~bzirk in s_bzirk
and kna1~regio in s_regio
and knvv~kdgrp in s_kdgrp
and kna1~lzone in s_lzone
and kna1~erdat in s_erdat
and kna1~ktokd in s_ktokd.
loop at gt_output_list into gs_output_list.
Get City decsription
perform get_city_description using gs_output_list-cityc
changing gs_output_list-bezei1.
Get Region description
select single bezei
from t005u
into gs_output_list-bezei2
where bland = gs_output_list-regio
and land1 = gs_output_list-land1"<<CR000-DEVK942345 ins
and spras = sy-langu.
Get customer group description
select single ktext
from t151t
into gs_output_list-ktext
where kdgrp = gs_output_list-kdgrp
and spras = sy-langu.
Get sales district description
select single bztxt
from t171t
into gs_output_list-bztxt
where bzirk = gs_output_list-bzirk
and spras = sy-langu.
Get zone decription
select single vtext
from tzont
into gs_output_list-vtext
where zone1 = gs_output_list-lzone
and spras = sy-langu.
modify gt_output_list from gs_output_list index sy-tabix
transporting bezei1
bezei2
ktext
bztxt
vtext.
clear gs_output_list.
endloop.
Get customer tax data
elseif pr_cust2 eq 'X'.
select kna1~kunnr
kna1~name1
kna1~name3
kna1~name4
kna1~ort01
kna1~stcd1
knvv~vkorg
knvv~spart
knvv~vtweg
knvi~taxkd
knvi~tatyp
from kna1 join knvv
on kna1kunnr = knvvkunnr
join knvi
on kna1kunnr = knvikunnr
into corresponding fields of table gt_output_tax
where kna1~kunnr in s_kunnr
and knvv~vkorg in s_vkorg
and knvv~vtweg in s_vtweg
and knvv~spart in s_spart
and kna1~regio in s_regio
and knvi~taxkd in s_taxkd.
Get customer tax description
loop at gt_output_tax into gs_output_tax.
select single vtext
from tskdt
into gs_output_tax-vtext
where tatyp = gs_output_tax-tatyp
and taxkd = gs_output_tax-taxkd
and spras = sy-langu.
if sy-subrc eq 0.
modify gt_output_tax from gs_output_tax index sy-tabix
transporting vtext.
clear gs_output_tax.
endif.
endloop.
Get customer HVL data
elseif pr_cust3 eq 'X'.
select kna1~kunnr
kna1~stceg
kna1~telfx
kna1~telf1
kna1~stras
kna1~ort02
kna1~cityc
kna1~regio
kna1~ort01
kna1~name2
kna1~name1
knvv~bzirk
knvv~spart
knvv~vtweg
knvv~vkorg
from kna1 join knvv
on kna1kunnr = knvvkunnr
into corresponding fields of table gt_output_hvl
where kna1~kunnr in s_kunnr
and knvv~vkorg in s_vkorg.
loop at gt_output_hvl into gs_output_hvl.
Get city description.
perform get_city_description using gs_output_hvl-cityc
changing gs_output_hvl-bezei.
if sy-subrc eq 0.
modify gt_output_hvl from gs_output_hvl index sy-tabix
transporting bezei.
clear gs_output_hvl.
endif.
endloop.
Get cust CRM data
elseif pr_cust4 eq 'X'.
select kna1~kunnr
knvv~versg "<<CR000-DEVK943142 del
knvv~vkorg
knvv~vtweg
knvv~bzirk
knvv~vkgrp
knvv~kdgrp
knvv~vkbur
kna1~name1
kna1~name2
kna1~ort01
kna1~pstlz
kna1~regio
kna1~stras
kna1~telf1
kna1~telfx
kna1~ort02
kna1~cityc
knvv~kvgr3
knb1~altkn
knb1~bukrs "<<CR000-DEVK943142 del
knvv~erdat
zcrm_bp_ext~found_dat
from kna1 join knvv
on kna1kunnr = knvvkunnr
join knb1
on knvvkunnr = knb1kunnr
join zcrm_bp_ext
on knb1kunnr = zcrm_bp_extkunnr
into corresponding fields of table gt_output_crm
where kna1~kunnr in s_kunnr
and knvv~vkorg in s_vkorg
and knvv~vtweg in s_vtweg
and knvv~spart in s_spart
and knvv~bzirk in s_bzirk
and knvv~kdgrp in s_kdgrp
and knvv~vkgrp in s_vkgrp
and knvv~vkbur in s_vkbur
and knvv~erdat in s_erdat
and kna1~ktokd in s_ktokd
and kna1~loevm in s_loevm1
and knb1~loevm in s_loevm2
and knvv~loevm in s_loevm3
and knb1~bukrs in s_bukrs
and knb1~altkn in s_altkn.
else.
Get customer information
<<CR001-DEVK944342 start del
select kna1~kunnr
knvv~vkorg
knvv~vtweg
kna1~stcd2
kna1~name1
kna1~name2
kna1~ort01
kna1~land1
kna1~pstlz
kna1~regio
kna1~stras
kna1~telf1
kna1~telfx
knvv~bzirk "<<CR001-DEVK944239 ins
knvv~vkbur "<<CR001-DEVK944239 ins
kna1~ort02
kna1~cityc
knvv~vkgrp
knvv~kvgr3
knvv~versg
kna1~kdkg2
kna1~kdkg1
knvv~kdgrp
knb1~altkn
knvv~erdat
kna1~loevm
knb1~loevm
knvv~loevm
<<CR001-DEVK944342 end del
<<CR001-DEVK944342 start ins
select kna1~kunnr
knvv~vkorg
knvv~vtweg
kna1~stcd2
kna1~name1
kna1~name2
kna1~name3 "<<CR002-DEVK944835 ins
kna1~stras
kna1~ort01
kna1~ort02
kna1~pstlz
kna1~regio
kna1~land1
kna1~cityc
kna1~telf1
kna1~telfx
knvv~bzirk
knvv~vkbur
knvv~kdgrp
knvv~vkgrp
knvv~kvgr3
knvv~versg
kna1~kdkg2
kna1~kdkg1
knb1~altkn
knvv~erdat
kna1~loevm
knb1~loevm
knvv~loevm
<<CR001-DEVK944342 end ins
from kna1 join knvv
on kna1kunnr = knvvkunnr
join knb1
on kna1kunnr = knb1kunnr
<<CR001-DEVK944252 start del
into corresponding fields of table gt_output_info
<<CR001-DEVK944252 end del
<<CR003-DEVK949538 start del
into table gt_output_info "<<CR001-DEVK944342 ins
<<CR003-DEVK949538 end del
<<CR003-DEVK949538 start ins
into corresponding fields of table gt_output_info
<<CR003-DEVK949538 end ins
where kna1~kunnr in s_kunnr
and knvv~vkorg in s_vkorg
and knvv~vtweg in s_vtweg
and knvv~spart in s_spart
and knvv~bzirk in s_bzirk
and knvv~kdgrp in s_kdgrp
and knvv~vkgrp in s_vkgrp
and knvv~vkbur in s_vkbur
and knvv~erdat in s_erdat
and kna1~ktokd in s_ktokd
and kna1~regio in s_regio
<<CR001-DEVK944252 start del
and kna1~loevm in s_loevm1
and knb1~loevm in s_loevm2
and knvv~loevm in s_loevm3
<<CR001-DEVK944252 end del
<<CR001-DEVK944252 start ins
and ( kna1~loevm in s_loevm1
or knb1~loevm in s_loevm2
or knvv~loevm in s_loevm3 )
<<CR001-DEVK944252 end ins
and knb1~zuawa in s_zuawa
and knb1~bukrs in s_bukrs
and knb1~altkn in s_altkn.
<<CR003-DEVK949538 start ins
loop at gt_output_info into gs_output_info.
select single adrnr
into kna1-adrnr
from kna1
where kunnr = gs_output_info-kunnr.
check sy-subrc eq 0.
select single smtp_addr
into adr6-smtp_addr
from adr6
where addrnumber = kna1-adrnr.
check sy-subrc eq 0.
gs_output_info-smtp_addr = adr6-smtp_addr.
modify gt_output_info from gs_output_info.
endloop.
<<CR003-DEVK949538 end ins
endif.
<<CR003-DEVK949538 start ins
loop at gt_output_info into gs_output_info.
lv_store = gs_output_info-loevm1.
endloop.
<<CR003-DEVK949538 end ins
endform.
FORM BUILD_SORT
form build_sort.
if pr_cust1 eq 'X' or
pr_cust2 eq 'X'.
clear gs_sort_info.
gs_sort_info-fieldname = 'VKORG'.
gs_sort_info-spos = 1.
gs_sort_info-up = 'X'.
append gs_sort_info to gt_sort_info.
endif.
clear gs_sort_info.
gs_sort_info-fieldname = 'KUNNR'.
gs_sorhi shivaji!
thx for the reply.
can u chk whether there is any problem with the queries or not.
regards
sachin -
How to get same day of a month in every year in the DB ( To update a flag )
Hi,
I am trying to formulate an update query for a flag table in our database which contains dates, and flag columns. Currently the system have dates for the next ten years. The flags are updated with values 0 or 1 if a particular date falls under the required criteria.
I need to update flag column for the same day of the month in every year. e.g. 2nd Sunday of October. The value should be updated to all years in the table. Currently I am using the following query to update the current year.
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7;
and for next year Like
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = add_months(NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7,+12)-1;
This is not an excellent way to do it as it does not take care of leap years and it does not scan and update values in the whole table for all years correctly.
Can any one help me to resolve this please.Hi,
user10903866 wrote:
Hi,
I am trying to formulate an update query for a flag table in our database which contains dates, and flag columns. Currently the system have dates for the next ten years. The flags are updated with values 0 or 1 if a particular date falls under the required criteria.
I need to update flag column for the same day of the month in every year. e.g. 2nd Sunday of October. The value should be updated to all years in the table. Currently I am using the following query to update the current year.
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7;That's the 2nd Sunday after October 1; the 2nd Sunday of October is the 2nd Sunday after September 30, so you need to subtract 1 more day before calling NEXT_DAY.
I'd do it this way:
WHERE c_date = NEXT_DAY ( TO_DATE ( '01-OCT-2013', 'DD-MON-YYYY') - 8
, 'SUNDAY'
) + (7 * 2) -- Last number is week numberRemember, calling NEXT_DAY like this depends on your NLS_DATE_LANGUAGE.
and for next year Like
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = add_months(NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7,+12)-1;If you want the 2nd Sunday in October, 2014, then take the previous expression, and just change 2013 to 2014:
WHERE c_date = NEXT_DAY ( TO_DATE ( '01-OCT-2014' -- or any month and year you want
, 'DD-MON-YYYY'
) - 8
, 'SUNDAY'
) + (7 * 2) -- Last number is week number
This is not an excellent way to do it as it does not take care of leap years and it does not scan and update values in the whole table for all years correctly.
Can any one help me to resolve this please.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
See the forum FAQ {message:id=9360002} -
How to create Measures for count on Flag colums in FACT with a CONDITON
I have about 6 flag columns in my fact table and I would like to create measures in my report with count as aggregation on these flag columns with a group by on a condition.
I am able to do this very easily with SQL query but am really stuck with on how to achieve this in OBIEE.
Each of my measure should be to do an aggreagation of count on the flag column with a condition such as is flag true/false.
Eg:
Measure1 - Select count(INV_ID) from payments_f where Flag 1 = "TRUE" and Flag2 = "FALSE" GROUP_BY (COLUMN1)
Measure2 - Select count(INV_ID) from payments_f where Flag 2 = "TRUE" and Flag3 = "FALSE" GROUP_BY (COLUMN1)
similar conditions for all the flag columns.
I tried to write the where condition in the Content tab of the Logical table but unfortunately it does on the table level - which was not very helpful to me
I really appreciate if some one can help me on how to achieve this.
Thanks in AdvanceYou need to create a new logical column in your existing logical table. Then you need to set the physical mapping to:
CASE WHEN FLAG1 = "TRUE" AND FLAG2 = "FALSE" THEN 1 ELSE 0 END.
Set aggregation rule to Sum.
Regards,
Stijn
Maybe you are looking for
-
Self Assigned IP address – can't figure this out. Frustrated.
This is a long post but bear with me. It proposes a challenge for the mac connoisseur. Who knows? Might be fun? OK, here goes: Please help. I have been trying to fix this for about 7 months. I first noticed this issue when I started traveling around
-
How can I transfer albums from one of my accounts to another? My new account (Apple ID) email address is no longer available to me since I lost my job.
-
Errors when generating a adobe form in report
Hello, I have a problem with the solution of the errors to generate an adobe form. I put in a situation: - I need to create a form with several dinamic tables, each below the previous. For each dinamic table, apart from the header row (column titles)
-
Clear Project Cache option .cpd
Hi, I'm using RH8. When my project was taking forever to open up, from past experience I knew it was due to a large .cpd file. Sure enough, it was up to 11 MB and after deleting it, the new .cpd file is only about 1 MB now. Opens much faster now. Rob
-
PS CC keeps askink te (re-)activate
I have a licence for PS CC en LR5 since mid december and had to re-activate PS on average twice a week. I suspect that perhaps the software I use to keep my PC tidy (CCleaner, PC Health) accidentally deletes some hidden licence file? Can that be the