Control Flow

From Abap2Java

Jump to: navigation, search

Contents

Image:Dotright.JPG ABAP

Unconditional loops with DO

DO 100 TIMES.
  WRITE: 'No.' , sy-tabix , '.' .
ENDDO.

Conditional loops with WHILE

WHILE i < 100. 
   i = i + 1.
ENDWHILE.

Looping over internal tables with LOOP

LOOP AT lt_my_table ASSIGNING <fs_line>.
  <fs_line>-my_change_date = sy-datum.
ENDLOOP.

Conditional branches with CASE

CASE n.
   WHEN 1.
     "code block
   WHEN 2.
     "code block
   WHEN OTHERS.
     "code block
ENDCASE.

Image:Dotleft.JPG Java

Conditional or unconditional loops with for

for (int i = 0; i < 100; i++) {
  System.out.print( "No." +  i + "." );
}

Conditional loops with do ... while

do {
   i++;
}
while ( i < 100 );

Conditional loops with while

List<MyClass> c = new List<MyClass>();
Iterator i = c.iterator();
while ( i.hasNext() ) {
   MyClass m = (MyClass) i.next();
}

Looping over iterable collections with for

List<MyClass> c = new List<MyClass>();
for (MyClass m: c) {
   System.out.print(m);
}

Conditional branches with if

if ( a == b ) {
   // codeblock 
} else if ( a > b ) {
   // codeblock
} else {
   // codeblock
}

Conditional branches with switch

switch(n) {
   case 1:
      // Code
   break;
   case 2:
      // Code
   break;
   default:
      // Code
   break;
}

Fast Assignment with ? ... :

String answer (a == b) ? "yes" : "no";
Personal tools