Skip to Content
0
Former Member
May 05, 2009 at 11:04 AM

Strange: blank in string. Anybody can explain this?

1188 Views

Hello!

Look at this. Until now I thougt, I had understood ABAP...

Output of the following programm:

1) Strange

2) Strange

3) Strange

4) Strange

5) Strange

6) Strange

Very strange, isn't it?

ABAPDOCU tells, that strings pay attention to blanks.

Can anybody explain this?

REPORT zstrange.

DATA: stringwithspace TYPE string VALUE 'A B',
      teststring TYPE string,
      blankstring TYPE string VALUE ' ',
      l type i.

START-OF-SELECTION.
  IF stringwithspace+1(1) = ' '.
    WRITE: / '1) My guess'.
  ELSE.
    WRITE: / '1) Strange'.
  ENDIF.

  IF stringwithspace+1(1) = blankstring.
    WRITE: / '2) guess'.
  ELSE.
    WRITE: / '2) Strange'.
  ENDIF.

  IF stringwithspace+1(1) = ''.
    WRITE: / '3) guess'.
  ELSE.
    WRITE: / '3) Strange'.
  ENDIF.

  teststring = stringwithspace+1(1).
  IF teststring = ' '.
    WRITE: / '4) Guess'.
  ELSE.
    WRITE: / '4) Strange'.
  ENDIF.

  IF teststring = blankstring.
    WRITE: / '5) Guess'.
  ELSE.
    WRITE: / '5) Strange'.
  ENDIF.

  IF teststring = ''.
    WRITE: / '6) guess'.
  ELSE.
    WRITE: / '6) Strange'.
  ENDIF.