Skip to main content

ABAP Bugs and peculiarities


Some of the design decisions in the ABAP language are a leap backwards when the intention was to leap at best sideways to thrust us into the meaningless paradigm of the now-defunct world of 4GL languages.

ABAP is a horrible language on all counts. Syntax-wise and how it is implemented, but here are just some of the succinct little tidbits I have found and ways to try and circumvent them.

1. Divide by zero is OK! sometimes...

So X / 0 in my opinion is never OK. When X != 0, the result is +-Infinity and for X = 0 the result is undefined. Both should result in an error. Well, for some reason ABAP decided 0 / 0 = 0. Without blinking an eyelid. Well done.

To fix this, and create an exception in all cases of X and Y in expression X / Y, re-write it as:

X / Y -> ( X * ( 1 / Y ) )

The same problem happens with modulus, however the solution is not as elegant:

X mod Y -> ( ( 1 mod Y ) * 0 + X / Y ) )

2. float parsing on older system fail when assigned to a non-F variable!

On pre-702 systems (where there are no DECFLOATS either) the following results in an error:

l_packed = '1e-1'.

The problem is that it expects a simple decimal numeric representation, but instead finds a character 'e' in the text. The solution is to assign it to a simple temporary float variable, and then assign it to the packed. For this purpose one can just create a global static float someplace since it is very temporary (unless two floats need to be parsed at the same time. However this can be slow and cumbersome, and then also has the problem of working with multiple values in a single expression.

A better solution is to also use a R/O global float and assign it the value of 1. And then to rewrite the literal float values as:

l_packed = ( cl_global_class=>s_float_unity * '1e-1' ).

3. Unary negation and implied whitespace-imposed precedence.

Take care, in ABAP:

-1 * 3 ** 2 = -9 , and
-3 ** 2 = 9 , BUT

- 3 ** 2 = -9

Almost (but not quite) as bad an idea as spacing in Python that changes meaning. Wow.

4. Problems with CHANGING any via a char1


On older unpatched systems the following program dumps:
REPORT zerror_test.
*-------------------------------------------------------*
CLASS cl_test DEFINITION.
  PUBLIC SECTION.
    METHODS method_true RETURNING value(r_val) TYPE flag.
    METHODS execute CHANGING c_result TYPE any.
ENDCLASS.
*
CLASS cl_test IMPLEMENTATION.
  METHOD method_true.
    " This only dumps with returning C1
 (int + strings are OK) 
    " Thus it could be a unicode/utf-8 underlying string issue?
    r_val = 'X'.
  ENDMETHOD.
  METHOD execute.
    " Assigning here to 'X' instead works in all cases:
    c_result = method_true( ).
  ENDMETHOD.
ENDCLASS.
 
START-OF-SELECTION.
DATA: lcl_test TYPE REF TO cl_test.
CREATE OBJECT lcl_test.

" this works:
DATA: lr_result TYPE REF TO data.
FIELD-SYMBOLS: <l_result> TYPE any.
CREATE DATA lr_result TYPE string.
ASSIGN lr_result->* TO <l_result>.
lcl_test->execute( CHANGING c_result = <l_result> ).
WRITE :/ <l_result>.

" this works as well
DATA: l_result TYPE string.
l_result = lcl_test->method_true( ).
WRITE :/ l_result.

" this does not work:
ASSIGN l_result TO <l_result>.
lcl_test->execute( CHANGING c_result = <l_result> ).
WRITE :/ <l_result>.

" this does not work:
lcl_test->execute( CHANGING c_result = l_result ).
WRITE :/ l_result.

In summary:

1) and 3) above are fundamental flaws and will not and cannot be fixed lest almost all applications start dumping and/or give different results. But 2) and 4) can (and has) been fixed in newer releases.


Post a Comment

Popular posts from this blog

My Custom DIY 60% Keyboard

My Custom DIY 60% Keyboard
All the parts

1x GH60 (Satan) board - $35 61x Cherry Clear switches - $35 2x Cherry Blue switches - $3 10x Cherry Red switches - $10 1x PCB Stabilizer set (6.25 space) - $6 1x Royal Oak Glam 60% case (Black Walnut) - $78 1x Aluminium 60% plate - $19 1x SA profile Choclatier keycaps - $102 (base, modifiers, and novelties)
1x Braided Nylon USB cable - $15 Solder, Tools, Risers, Labor, etc.
Total: ± $300
(Other single switch types added as needed)
Testing the board I had my helper do the work here. We needed to test the board before applying any solder.
Assembling Add the stabilizers first Add the plate (using a few switches as spacers) Then add the rest
Solder solder solder...

And test again:


The casing The casing I received did to have built-in risers:

So I added my own:



Then Assemble (using temporary spare DSA Carbon Cherry profile keycaps):


Hmm... pretty.

And finally received my Chocolatier SA-profile keycap set!


Programming the GH60 The board is controlle…

Garage door opener using Arduino + SmartThings

I wired up and controlled my garage (two main doors controlling and one side door sensor only) with the following customizable source code running on an Arduino and the SmartThings platform (via a Z Wave shield. (The .groovy file you load on the web, and the .ino file you compile for the Arduino)

These are the materials I used:

$35 Smarthings Arduino Z Wave shield
$25 Arduino Uno
$10 Power supply for Arduino
$10 Wire
$20 Magnetic switches
$8   Relay

It was pretty easy, I developed all the source and did the installation in a single day (tweaked it a little the rest of the weekend) and it has been running stable for about 1.5 years now.

The garage doors are toggles that I wired into my garage controller button wires, and they only show if the garage doors are ajar. (It does not indicate whether they are closing or opening... that was troublesome to detect with just a magnetic switch and the way garage doors open and close.)

No express or implied warranty are attached to this guide... …

The story of my Amiga A1200's new lease on life.

Ok, so I rummaged through my storage in South Africa and found my old Amiga once again. This was not the original one I used to have, this is an Amiga A1200, where I used to have the Amiga A500 back in 1986.

A bit of history, I started out with a Atari 2600 back in 1983 (was 10 years old at the time), then saw an advertisement for a cartridge that could do programming... this concept fascinated me, but we could never find it anywhere (it was hard finding the good stuff in South Africa). I settled for a VIC-20 soon afterwards (I sold my Atari), then upgraded to a Commodore C64 soon thereafter.







This lasted until 1986 (age 13) when, after countless months of pouring over Commodore User magazines, I decided I wanted an Amiga.


I had the choice between an IBM compatible XT (with two floppy disc drives but no graphics) or an Amiga. Both seemingly the same price, but due to the then apartheid-era restrictions and taxes, the Amiga turned out to be very troublesome to get to South Africa. My f…