Delete internal table lines where field contains the "+"? - abap

I want to delete entries from an internal table, which has not a "+" in one column. Now, if I want to delete it like this:
DELETE internal_table where field1 <> '+'.
it doesn't work. This means, it takes the "+" as a regex and just selects any character with length 1.
Now I've tried several things:
DELETE internal_table where field1 <> '\+'.
DELETE internal_table where field1 <> |\+|.
DELETE internal_table where field1 <> `\+`.
Nothing of this works. With the String template |\+| I get the error "Unmasked symbol '\' in string template.
Field 1 is a character field with length 1. How can I escape the "+" that only the lines, which have a "+" in field1?

You can do it without regex:
DELETE internal_table
WHERE field CA '+'.
CA stands for contains any and it will delete all lines where the field contains a '+' character (independent of the lenght of the field or what other characters are in). You can add more characters if you wish, for example CA '+-' which means the string contains a '+' or a '-' etc.
If you want to delete a line, which does NOT contain a '+' you can use:
DELETE internal_table
WHERE field NA '+'.
Here is a link to the direct SAPHelp:
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenlogexp_op.htm

Related

Delete specific pattern between commas in text file

I have thousand of SQL queries written over notepad++ line by line.Single line contain single SQL query.Every SQL query contain list of columns to be selected from database as comma separated values.Now we want certain columns not to be part of that list which follow a specific pattern/regular expression.The SQL query follows a specific pattern :
A trimmed column has been selected as alias 'PK'
Every query has got a 'dated'where condition at the end of it.
Sometimes the pattern which we wish to remove exist in either PK/where or both.we don't want to remove that column/pattern from those places.Just from the column selection list.
Below is the example of a SQL query :
select (TRIM(TAE_TSP_REC_UPDATE)) as PK,TAE_AMT_FAIR_MV,TAE_TXT_ACCT_NUM,TAE_CDE_OWNER_TYPE,TAE_DTE_AQA_ABA,TAE_RID_OWNER,TAE_FID_OWNER,TAE_CID_OWNER,TAE_TSP_REC_UPDATE from TABLE_TAX_REP where DATE(TAE_TSP_REC_UPDATE)>='03/31/2018'
After removal of columns/patterns query should look like below :
select (TRIM(TAE_TSP_REC_UPDATE)) as PK,TAE_AMT_FAIR_MV,TAE_TXT_ACCT_NUM,TAE_CDE_OWNER_TYPE,TAE_DTE_AQA_ABA from TABLE_TAX_REP where DATE(TAE_TSP_REC_UPDATE)>='03/31/2018'
want to remove below patterns from each and every query between the commas :
.FID.
.RID.
.CID.
.TSP.
If the pattern exist within TRIM/DATE function it should not be touched.It should only be removed from column selection list.
Could somebody please help me regarding above.Thanks in advance
You may use
(?:\G(?!^)|\sas\s(?=.*'\d{2}/\d{2}/\d{4}'$))(?:(?!\sfrom\s).)*?\K,?\s*[A-Z_]+_(?:[FRC]ID|TSP)_[A-Z_]+
Details
(?:\G(?!^)|\sas\s(?=.*'\d{2}/\d{2}/\d{4}'$)) - two alternatives:
\G(?!^) - the end of the previous location, not a position at the start of the line
| - or
\sas\s(?=.*'\d{2}/\d{2}/\d{4}'$) - an as surrounded with single whitespaces that is followed with any 0+ chars other than line break chars and then ', 2 digits, /, 2 digits, /, 4 digits and ' at the end of the line
(?:(?!\sfrom\s).)*? - consumes any char other than a linebreak char, 0 or more repetitions, as few as possible, that does not start whitespace, from, whitespace sequence
\K - a match reset operator discarding all text matched so far
,?\s* - an optional comma followed with 0+ whitespaces
[A-Z_]+_(?:[FRC]ID|TSP)_[A-Z_]+ - ASCII letters or/and _, 1 or more occurrences, followed with _, then F, R or C followed with ID or TSP, then _, and again 1 or more occurrences of ASCII letters or/and _.
See the regex demo.

SQL : Confused with WildCard operators

what is difference between these two sql statements
1- select * from tblperson where name not like '[^AKG]%';
2- select * from tblperson where name like '[AKG]%';
showing same results: letter starting from a,k,g
like '[^AKG]% -- This gets you rows where the first character of name is not A,K or G. ^ matches any single character not in the specified set or a specified range of characters. There is one more negation not. So when you say name not like '[^AKG]%' you get rows where the first character of name is A,K or G.
name like '[AKG]% -- you get rows where the first character of name is A,K or G.
The wildcard character [] matches any character in a specified range or a set of characters. In your case it is a set of characters.
So both the conditions are equivalent.
You are using a double 'NOT'. The carrot '^' in your first character match is shorthand for 'not', so you are evaluating 'not like [not' AKG]% IE not like '[^AKG]%'.
1)In the first query you are using 'Not' and '^' basically it is Not twice so it cancels outs
therefore your query is 'Not Like [^AKG]' ==> 'Like [AKG]'
^ a.k.a caret or up arrow.
The purpose of this symbol is to provide a match for any characters not listed within the brackets [] , meaning that normally it wouldn't provide a result for anything that starts with AKG, but since you added the word NOT to the query , you are basically cancelling the operator, just as if you were doing in math :
(- 1) * (- 1)

Using wildcards

Can anyone help me out with this-
There is a column in the database as "TEXT".
This column hold some string value.
I want to search any row that is having '%' in this column .
For eg how will i search for a row having value 'Vivek%123' in the column TEXT
In sql there is something known as an escape character, basically if you use this character it will be ignored and the character right behind it will be used as a literal instead of a wildcard in the case of %
WHERE Text LIKE '%!%%'
ESCAPE '!'
The above sql statement will allow you to search for any string containing a percentage character '%' so it could find anything in the format of
string%string
You must escape the % character
WHERE COL1 LIKE 'Vivek#%123' ESCAPE '#' ;

drop characters from end of string

In SQL Server 2008, I need to drop the last two characters from a series of item numbers in our database. not all the numbers are the same format and i only need to drop characters from certain ones. the numbers i need to truncate look like this DOR-12345_X where _X is a revision letter. i tried this
SELECT LEFT(IV00103.VNDITNUM,(LEN(IV00103.VNDITNUM)-2)
FROM IV00103
WHERE LEFT STR = 'DOR'
but it doesn't like the syntax near FROM or the STR = 'DOR'
Can anyone assist? Do you need more info? I'm really a newb at SQL =) THANKS!
-jon
I think the correct syntax is:
SELECT LEFT(IV00103.VNDITNUM, LEN(IV00103.VNDITNUM)-2)
FROM IV00103
WHERE LEFT(IV00103.VNDITNUM, 3) = 'DOR'
Or:
WHERE IV00103.VNDITNUM like 'DOR%'
It doesn't like the syntax near FROM because you're missing a closing bracket on the LEFT. I suspect what you want is something like this:
SELECT CASE WHEN IV00103.VNDITNUM LIKE 'DOR%' THEN LEFT(IV00103.VNDITNUM,(LEN(IV00103.VNDITNUM)-2)) ELSE IV00103.VNDITNUM END AS VNDITNUM
FROM IV00103
That selects absolutely everything from the IV00103 table, removing those last two characters only from those that have a value in the VNDITNUM column beginning with DOR.
EDIT: If you want to actually update the contents of the table, you could do it this way using a WHERE:
UPDATE IV00103
SET VNDITNUM = LEFT(IV00103.VNDITNUM,(LEN(IV00103.VNDITNUM)-2))
WHERE VNDITNUM LIKE 'DOR%'
If you only need the ones that match the pattern DOR-somecharacters_asinglecharacter then you should probably do:
UPDATE IV00103
SET VNDITNUM = LEFT(IV00103.VNDITNUM,(LEN(IV00103.VNDITNUM)-2))
WHERE VNDITNUM LIKE 'DOR-%\__' ESCAPE '\'
The \_ is an escaped underscore, which will be treated as an actual underscore. The ESCAPE '\' part tells SQL that the \ character is being used to escape special characters in the pattern. The second _ is the special character, and matches a single character.

copy part of one column to another column in the same table

I need to copy part of one column into another column. The delimiter is "-". I don't want to remove that part from the first column.
Example:
ItemDesc Part#
Glowear_black-1234
So it needs to look like this:
ItemDesc Part#
Glowear_black-1234 1234
The only SQL query I can find cuts the information from the ItemDesc column and pastes it into Part#. I still need the "1234" in the first column. Also not all of the ItemDesc have a "-" (which is fine).
In Access SQL, you can use InStr() to find the position of "-" within your field. Then you can use Mid() to return the substring which starts one character after that position.
Note you must bracket Part# in your SQL statement because of the # character in its name.
UPDATE tblIOT1
SET [Part#] =
Mid(ItemDesc, InStr(1, ItemDesc, "-") + 1)
If ItemDesc could be Null or contain a string without a "-", add a WHERE clause to ignore those rows in the UPDATE.
WHERE ItemDesc ALike '%-%'
It is not explicitly clear what to do for the case where ItemDesc lacks the hyphen symbol as a delimiter, but here is my suggestion. Use the substring function to grab everything to the right of the hyphen, where everything to the right is bound by the index of the hyphen character plus one, and the length of the string:
update user.table
set Part# = substring(ItemDesc, (CHARINDEX('-', ItemDesc)+1), LEN(ItemDesc) )
Taking your statement from the comments:
UPDATE tblIOT1
SET Part#= Trim(Mid(ItemDesc, InStr(ItemDesc, '-') +1))
where ItemDesc like "*-*"
Note that I am using the star character and the other respondent uses the percent character, either appear to be valid to MS Access as specified here