2020 Jun 10 1:56 PM
OK, we know that if you have a numeric type and try to assign a string value to it, any non-numerals will be ignored. I.e.
DATA mynum TYPE n LENGTH 4.
DATA mystring TYPE string VALUE 'DI01'.mynum = mystring.
mynum will now contain the value 0001.
We also know that when you use READ on a internal table with a key, the supplied value is converted to the type of the key. I've an internal table (HASHED), keyed on a four length numeric field. It has a record for 0001. I was confused for some time that this code
READ TABLE mytable INTO DATA(record) WITH TABLE KEY numckey = mystring.
had sy-subrc = 0, and returned a record with record-numckey = '0001'.
2020 Jun 10 7:28 PM
If you perform an extended check (SLIN) you will get a warning like the following. Unfortunately only in extended check...
Syntax check warning.
This warning is only displayed in SLIN
The assignment "NUMCKEY" = ... is not usually the equivalent of a comparison. It is best to use the
same type for the c
Internal message code: MESSAGE GC6
Deactivatable using pragma ##WARN_OK. Message Code WRN 1305
2020 Jun 10 2:33 PM
Hi Matthew
Why is there a difference between these fields? Is it by design or some oversight?
Kind regards,2020 Jun 10 2:43 PM
It is more like opinion, than answer:
2020 Jun 10 4:36 PM
Opinions are good!
I did know it. But only in relation to the fact that in LOOP AT WHERE, type conversions are a performance hit.
DATA test TYPE string.
DATA itab TYPE ... (table that has a char key).
LOOP AT itab ... WHERE key = test.
is more expensive than
DATA test TYPE string.
DATA itab TYPE ... (table that has a char key).
DATA mykey TYPE key_type.
mykey = test.
LOOP AT itab ... WHERE key = mykey.
In this particular instance, it never occurred to me that the key of the table (which I didn't define!) wouldn't be C4 rather than N4.
It's not a bug - more a feature of the ABAP language. And far too late to change now!
But if you used CONV for example, you'd get the same issue. What we really need is a IF type(thing) IS NUMC. I know we can use RTTS or DESCRIBE, but it's not the same.
Just for info, I changed the code as follows.
IF blah CO |0123456789|.
2020 Jun 10 4:42 PM
Someone else's design. It was wrong from the start, but I've only been working here 15 years. That decision was taken 20 years ago!
2020 Jun 10 7:06 PM
I like your solution - (>>DELETED--although it may surprise people as blah is of type N--DELETED<< as per Matthew comment):
IF blah CO |0123456789|. " or '0123456789'
You can also do that (but I think it's worse than your solution):
TYPES : ty_n TYPE n LENGTH 4,
BEGIN OF ty,
key TYPE ty_n,
END OF ty,
tt TYPE HASHED TABLE OF ty WITH UNIQUE KEY key.
FIELD-SYMBOLS <c> TYPE c.
DATA: mykey TYPE ty_n,
mystring TYPE string.
DATA(mytable) = VALUE tt( ( key = '0001' ) ).
mystring = 'DI01'.
ASSIGN mykey TO <c> CASTING.
<c> = mystring. " <==== mykey of type N will contain the invalid value 'DI01'
READ TABLE mytable WITH TABLE KEY key = mykey TRANSPORTING NO FIELDS.
ASSERT sy-subrc <> 0.
2020 Jun 11 10:56 AM
2020 Jun 10 7:28 PM
If you perform an extended check (SLIN) you will get a warning like the following. Unfortunately only in extended check...
Syntax check warning.
This warning is only displayed in SLIN
The assignment "NUMCKEY" = ... is not usually the equivalent of a comparison. It is best to use the
same type for the c
Internal message code: MESSAGE GC6
Deactivatable using pragma ##WARN_OK. Message Code WRN 1305
2020 Jun 11 10:58 AM
Unfortunately, ATC is a bit ... broken thanks to a poor implementation of a 3rd party product. I don't think we've got SLIN directly in Eclipse - but if I'm wrong, please tell me!
I wonder if there's a way of getting SLIN warnings inside the editor?
2020 Jun 17 11:09 PM
There is no SE80-like integration, true.
What is possible (kind of crawling back through the window if entry via the entrance door is not possible) is to execute transaction SLIN in the Eclipse environment (Ctrl-Shift-A, type SLIN, pick transaction, then push test transaction button) as long as you have all the authorizations for these steps... You will need to pass a report name (so knowing the technical report names for function groups with SAPL or for classes with the ==CP style suffix is important) -- at least there is a value help for the report name.