Lesson 18 – Example of CASE and DO LOOP in SAP ABAP

Lesson 18 – Example of CASE and DO LOOP in SAP ABAP

 

Example of CASE statement in SAP ABAP

 

Parameters : p_num1 type i.

 

Case p_num1 .
when ‘1’.
write : / ‘You have entered ‘, p_num1.
when ‘2’.
write : / ‘You have entered ‘, p_num1.
when ‘3’.
write : / ‘You have entered ‘, p_num1.
when others.
write : / ‘You have entered other than 1,2,3. You have entered’, p_num1.
Endcase.

 

 

Example of DO-LOOP statement in SAP ABAP

 

Example 1 –

 

Parameters ; p_num1 type i obligatory.

 

Do 3 times.
write : / ‘Index is ‘, sy-index.
write : / ‘Tabix is ‘, sy-tabix.
write : / ‘——————–‘.
Enddo.

 

Example 2 –

 

Parameters : p-num1 type i obligatory.

 

Do.
If sy-index = 3.

Continue.
Else.
Write : / Sy-index.
If sy-index = 5.
Exit.
Endif.
Endif.
Enddo.

 

Note : – CONTINUE statement will terminates the loop pass unconditionally.

Add a Comment

Your email address will not be published. Required fields are marked *