Exception "A condition specified dynamically has an unexpected format" with RFC_READ_TABLE - sap-dotnet-connector

I'm using .Net Sap Connector 3 and function "RFC_READ_TABLE" to read PA0001 table data.
Where condition I'm using seem stupid, but it's only to explain that my problem is the length of this expression.
If I use:
MANDT = '100' OR MANDT = '100' OR MANDT = '100' OR MANDT = '100'
it work. But if I use
MANDT = '100' OR MANDT = '100' OR MANDT = '100' OR MANDT = '100' OR MANDT = '100'
I have this exception: "A condition specified dynamically has an unexpected format".
I tried to break the string with the character ~ and specify this character as a separator
function.SetValue ("DELIMITER", "~")
but the problem persists
Help me!

Adding OP's comment as an answer to help future visitors:
OPTIONS line has a 72 char limitation, so if one has a long condition the solution would be to split it into several lines:
inputTableOptions = function.GetTable("OPTIONS");
string[] aWhere = sWhereExpression.Split("~".ToCharArray()); foreach (string cond in aWhere) { inputTableOptions.Append();
inputTableOptions.SetValue("TEXT", cond);

Related

"SQL Error (1292): Truncated incorrect DOUBLE value: 'unknown'" upon INSERT but not when only SELECTing

Can someone please help me understand why below INSERT query
INSERT INTO ha_archive.pond(last_updated, water)
SELECT DATE(s.last_updated) 'last_updated',
SUM(s.state) 'water'
FROM home_assistant.states s
WHERE s.entity_id = 'sensor.pond_last_refill' AND s.state > 0
GROUP BY DATE(s.last_updated)
ON DUPLICATE KEY update
water = VALUES(water);
triggers
SQL Error (1292): Truncated incorrect DOUBLE value: 'unknown'
While the SELECT query below does not?
SELECT DATE(s.last_updated) 'last_updated',
SUM(s.state) 'water'
FROM home_assistant.states s
WHERE s.entity_id = 'sensor.pond_last_refill' AND s.state > 0
GROUP BY DATE(s.last_updated)
There are occasional 'unknown' strings among float values, and I've tried casting as float, but that doesn't avoid the error.

u-sql script can not obtain scalar value from dataset

In u-sql script I must extract a variable from file to a dataset and then use it to form a name of output file. How can I get the variable from the dataset?
In details.
I have 2 input files: csv file with a set of fields and a dictionary file. The 1st file has file name like ****ClintCode*****.csv. The 2nd file-dictionary has 2 fields with mapping: ClientCode - ClintCode2. My task is extract ClientCode value from the file name, get ClientCode2 from the dictionary, insert it as a field to output file (implemented), and, moreover, form the name of output file as ****ClientCode2****.csv.
Dictionary csv file has the content:
OldCode NewCode
6HAA Alfa
CCVV Beta
CVXX gamma
? Davis
The question is how to get ClientCode2 into scalar variable to write an expression for the output file?
DECLARE #inputFile string = "D:/DFS_SSC_Automation/Tasks/FundInfo/ESP_FAD_GL_6HAA_20170930.txt"; // '6HAA' is ClientCode here that mapped to other code in ClientCode_KVP.csv
DECLARE #outputFile string = "D:/DFS_SSC_Automation/Tasks/FundInfo/ClientCode_sftp_" + // 'ClientCode' should be replaced with ClientCode from mapping in ClientCode_KVP.csv
DateTime.Now.ToString("yyyymmdd") + "_" +
DateTime.Now.ToString("HHmmss") + ".csv";
DECLARE #dictionaryFile string = "D:/DFS_SSC_Automation/ClientCode_KVP.csv";
#dict =
EXTRACT [OldCode] string,
[NewCode] string
FROM #dictionaryFile
USING Extractors.Text(skipFirstNRows : 1, delimiter : ',');
#theCode =
SELECT Path.GetFileNameWithoutExtension(#inputFile).IndexOf([OldCode]) >= 0 ? 1 : 3 AS [CodeExists],
[NewCode]
FROM #dict
UNION
SELECT *
FROM(
VALUES
(
2,
""
)) AS t([CodeExists],[NewCode]);
#code =
SELECT [NewCode]
FROM #theCode
ORDER BY [CodeExists]
FETCH 1 ROWS;
#GLdata =
EXTRACT [ASAT] string,
[ASOF] string,
[BASIS_INDICATOR] string,
[CALENDAR_DATE] string,
[CR_EOP_AMOUNT] string,
[DR_EOP_AMOUNT] string,
[FUND_ID] string,
[GL_ACCT_TYPE_IND] string,
[TRANS_CLIENT_FUND_NUM] string
FROM #inputFile
USING Extractors.Text(delimiter : '|', skipFirstNRows : 1);
// Prepare output dataset
#FundInfoGL =
SELECT "" AS [AccountPeriodEnd],
"" AS [ClientCode],
[FUND_ID] AS [FundCode],
SUM(GL_ACCT_TYPE_IND == "A"? System.Convert.ToDecimal(DR_EOP_AMOUNT) : 0) AS [NetValueOtherAssets],
SUM(GL_ACCT_TYPE_IND == "L"? System.Convert.ToDecimal(CR_EOP_AMOUNT) : 0) AS [NetValueOtherLiabilities],
0.0000 AS [NetAssetsOfSeries]
FROM #GLdata
GROUP BY FUND_ID;
// NetAssetsOfSeries calculation
#FundInfoGLOut =
SELECT [AccountPeriodEnd],
[NewCode] AS [ClientCode],
[FundCode],
Convert.ToString([NetValueOtherAssets]) AS [NetValueOtherAssets],
Convert.ToString([NetValueOtherLiabilities]) AS [NetValueOtherLiabilities],
Convert.ToString([NetValueOtherAssets] - [NetValueOtherLiabilities]) AS [NetAssetsOfSeries]
FROM #FundInfoGL
CROSS JOIN #code;
// Output
OUTPUT #FundInfoGLOut
TO #outputFile
USING Outputters.Text(outputHeader : true, delimiter : '|', quoting : false);
As David points out: You cannot assign query results to scalar variables.
However, we have a dynamic partitioned output feature in private preview right now that will give you the ability to generate file names based on column values. Please contact me if you want to try it out.
You can't. Please see Convert Rowset variables to scalar value.
You may still be able to achieve your ultimate goal in a different manner. Please consider re-writing your post with clear & concise language, small dataset, expected output, and a very minimal amount of code needed to repro - remove all details and nuances that aren't necessary to create a test case.

I would like to create UDF alternative of INDIRECT()

As indirect() is volatile and there is no other way than using indirect in my files, I need to create a UDF equivalent/alternative to indirect.
As far as I have been is :
INDIRECTVBA(ref_text As String, Optional active_A1 As Boolean) As String
If active_A1 = False Then
ref_text = "=" & ref_text
ref_text = Application.ConvertFormula(Formula:=ref_text, fromReferenceStyle:=xlR1C1, toReferenceStyle:=xlA1)
INDIRECTVBA = Range(ref_text)
Else
INDIRECTVBA = Range(ref_text)
End If
End Function
At this point, I'm able to manage :
A1 and R1C1 input with A1 format as default,
In the same sheet or not,
With and without the name of sheet.
I have been googleing for hours, to go there ...
My final need is to handle range such as :
A1:B2 as ref_text => INDIRECTVBA("A1:B2") should return a range as A1:B2
R1C1:R2C3 as ref_text
Thanks for time,

Simple Procedure raise ORA-06502

There's the simplified version of my code who keep raise me ORA-06502:
declare
p_filter varchar2(300) := '2012';
p_value varchar2(300) := '12345.000';
w_new_value number(13,3) := null ;
w_count number(4) := null ;
BEGIN
SELECT count(*)
INTO w_count
FROM dual
where p_filter = p_filter;
--- more filters
if w_count != 0 then
w_new_value := p_value / w_count;
else
w_new_value := p_value;
end if;
-- do something
end;
/
Someone can give me a help?
DataBase Details
nls_language = italian
nls_territory = italy
nls_currency = �
nls_iso_currency = italy
nls_numeric_characters = ,.
nls_calendar = gregorian
nls_date_format = dd-mon-rr
nls_date_language = italian
nls_characterset = we8iso8859p15
nls_sort = west_european
nls_time_format = hh24:mi:ssxff
nls_timestamp_format = dd-mon-rr hh24:mi:ssxff
nls_time_tz_format = hh24:mi:ssxff tzr
nls_timestamp_tz_format = dd-mon-rr hh24:mi:ssxff tzr
nls_dual_currency = �
nls_nchar_characterset = al16utf16
nls_comp = binary
nls_length_semantics = byte
nls_nchar_conv_excp = false
First, this is always going return a value of 1.
SELECT count(*)
INTO w_count
FROM dual
It doesn't matter what the qualifier is.
Lastly, I just ran your simplified code example in Oracle 11R2 and it didn't throw an exception.
I added the following statement in place of your "do something" comment:
dbms_output.put_line('w_new_value: ' || w_new_value || '. w_count: ' || w_count);
The result was:
w_new_value: 12345. w_count: 1
So, I think you've simplified your example into oblivion. You need to provide something that actually shows the error.
Good luck.
I found myself the ansewer and i think is useful for other know.
The real problem of the script for my DB is the language.
The italian "version" of Oracle accept , instead of the . for translate the VARCHAR2 into NUMBER unlike the most of other country.
For make the code running well the solution is
w_new_value := replace(p_value,'.',',') / w_count;
This trick finally allows the DB use my VARCHAR2 param like a NUMBER

Problems with Recordset Filter

I'm having trouble with a filter on an ADO Recordset in legacy ASP Classic code, and I'm trying to understand if what I'm trying to do is not supported, or if I'm just doing it wrong.
I have a recordset of Items, and they have a Status of 1 (active) or 0 (inactive), and an optional End_Date. In my administrative user interface, I have a control to show all items or only those that should be displayed to end-users: Status = 1 AND ( End_Date is null OR End_Date > Date() )
To implement that logic, I tried:
rs.Filter = "Status = 1 AND ( End_Date = null OR End_Date > #" & Date() & "# )"
but I get
ADODB.Recordset (0x800A0BB9)
Unknown runtime error
After much fooling around, it seems that ADO doesn't like the grouping parens around the End_Date conditions in combination with the AND condition. If I take the parens out, this works:
rs.Filter = "Status = 1 AND End_Date = null OR End_Date > #" & Date() & "#"
But that's just an accident -- it looks like the filter conditions are evaluated in order, and so I get the results I want. If I change the AND to OR, the parens work:
rs.Filter = "Status = 1 OR ( End_Date = null OR End_Date > #" & Date() & "# )"
But of course that logic is wrong -- it shows Active but expired items.
Strangely, if I move the conditions around, it breaks again:
rs.Filter = "End_Date = null OR Status = 1 AND End_Date > #" & Date() & "# "
crashes with the same ADODB error.
I can't seem to predict what will and won't work, and the docs I've read are very sketchy on the syntax expected (it's not pure T-SQL!), the limitations, etc. and all the examples I've seen have at most two conditions. I don't think my conditions are all that complex. Can anyone tell me if what I'm trying to do is supported, if there's a better way to do it, or point me to comprehensive docs and samples that match this kind of logic?
Thanks!
ADO Recordset Object Filter Property:
There is no precedence between AND and OR. Clauses can be grouped within parentheses. However, you cannot group clauses joined by an OR and then join the group to another clause with an AND, like this:
(LastName = 'Smith' OR LastName =
'Jones') AND FirstName = 'John'
Instead, you would construct this
filter as:
(LastName = 'Smith' AND FirstName =
'John') OR
(LastName = 'Jones' AND FirstName =
'John')
So you would have to construct your filter like this:
rs.Filter = "( Status = 1 AND End_Date = null ) OR ( Status = 1 AND End_Date > #" & Date() & "# )"
I know that you are working with legacy code and probably other things are working, but how do you open the recordset in this specific page? Are you using some constant defined in adovbs.inc?
For example:
rs.Open "SELECT * FROM table1", db, adOpenStatic, adLockPessimistic
What happens when you try this...
Dim strToday
strToday = Now()
rs.Filter = "Status=1 AND (End_Date = null OR End_Date > """ & strToday & """)"

Resources