Skip to Content
Technical Articles
Author's profile photo Enno Wulff

Funny (?) glitch in ABAP development {riddle}

Today I ran through a problem with macros.

I wanted to use 2 parameters in a macro but the second parameter should also be initial.

DEFINE _where_cond.
  APPEND |&2 field&1 = var&1| TO dynamic_where.
END-OF-DEFINITION.

START-OF-SELECTION.
  _where_cond 1.
  _where_cond 2 AND.

The editor shows up the following error:

Call macro _WHERE_COND without 2. Actual parameters.

Solutions

First I wanted to add an IF statement to add the AND command but I found it not “nice”.

The next idea was to define 2 macros what I also discarded as the macro was some more lines longer and I wanted to have the macro as short as possible,

The third – and final – solution was:

IF dynamic_where IS NOT INITIAL.
  APPEND 'AND' TO dynamic_where.
ENDIF.

Riddle

In the meantime I encountered another solution, which was very, very bad.

Can you guess which?

 

Please no discussion about not using macros anyway. thanks.

Assigned Tags

      16 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jacques Nomssi Nzali
      Jacques Nomssi Nzali

      won’t this work?

        _where_cond 1 ''.
      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      No. ?

      Author's profile photo Suhas Saha
      Suhas Saha
      data DYNAMIC_WHERE type standard table of STRING with empty key.
      
      define _WHERE_COND.
        insert CONDENSE( |{ &2 } field&1 = var&1| ) into table DYNAMIC_WHERE.
      END-OF-DEFINITION.
      
      start-of-selection.
        _WHERE_COND 1 SPACE.
        _WHERE_COND 2 'AND'.
      
        CL_DEMO_OUTPUT=>DISPLAY( DATA = DYNAMIC_WHERE ).

      Shouldn’t the 2nd macro placeholder &2 be defined as a variable in the string template?

      Tbh, i was not aware of this behavior in macros 🙂 Cf. Placeholders in macros

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      Hey Suhas Saha , this is a good solution!!

      But not what I thought about...

      Author's profile photo Lars Hvam
      Lars Hvam

      a macro that calls a macro? worse than a macro...

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      worse than everything Lars Hvam 🙂

      My "solution" is quite evil.

       

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      I will show you the "evil solution":

        _WHERE_COND 1  .
        _WHERE_COND 2 AND.
      Author's profile photo Shai Sinai
      Shai Sinai

      ?

      What do I miss?

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      you can’t see the evil, but it's there… ?

      http://www.fileformat.info/info/unicode/char/00a0/index.htm

      Author's profile photo Shai Sinai
      Shai Sinai

      Neither do I nor the browser ?

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      but the editor does...

      Author's profile photo Shai Sinai
      Shai Sinai

      Indeed.

      ABAP editor does,

      but when I copied your code from here it didn't include the "forbidden" character.

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      The blog seems to eliminate the ALT-255 character (or I made a mistake when copying it).

      Author's profile photo Suhas Saha
      Suhas Saha

      To "space" or not to "space" is the question ?

      Author's profile photo Suhas Saha
      Suhas Saha

      This is pure evil, did you attend the "Obfuscation 101" course?

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      I created it 😀