SAP ABAP supports two types of conditional expressions, IF/ELSIF/ELSE/ENDIF and CASE/WHEN/ENDCASE. Here is a sample IF condition:
IF my_variable IS NOT INITIAL.
(actions)
ELSEIF NOT (my_variable > 0).
(actions)
ELSE.
(actions)
ENDIF
And, here is a sample CASE statement:
CASE my_variable.
WHEN 'ONE'.
(actions)
WHEN 'TWO'.
(actions)
WHEN OTHERS.
(actions)
ENDCASE.
For looping, ABAP supports four different types. The first type is the DO/ENDDO, which has two variations. Notice that I use the sys-index variable in the IF condition, this is a system variable that counts how many times this loop has run.
DO
IF sy-index > 100. EXIT. ENDIF.
(actions)
ENDDO

DO n TIMES
(actions)
ENDDO
ABAP also supports conditional loops:
WHILE sy-index <>ENDWHILE
Finally, ABAP supports looping against database or internal tables:
SELECT (conditions) FROM (database_table).
(actions)
ENDSELECT.

LOOP AT (internal_table).
(actions)
ENDLOOP.
Along with sy-index, SAP has 170 other system fields (171 total). Some important or frequently used ones include: sy-mandt, sy-uname, sy-langu, sy-datum, sy-uzeit (time), and sy-subrc.

Another common task is producing dialog messages, in ABAP the followign syntax is used:
MESSAGE tnnn(message_class) WITH variable_one variable_two variable_n
The with statement is for including variables from you program into the message, and is optional. The 't' that proceeds the message number ('nnn') is the type of message to be displayed, below are the options.
  • i - An informative message that appears as a modal dialog, the program is continued after it is displayed.
  • s - A status bar message on the next screen.
  • w - A warning message that appears in the status bar
  • e - An error message that appears in the status bar
  • a - An abort message that appears as a modal dialog box, the program terminates after it is displayed (and the users confirms).
  • x - A short dump is generated as a runtime error, you probably don't want the user seeing these.

Tags: Blogger Programming SAP ABAP

Published: 2009-01-17