Updated: May 31, 2022
Controlling keywords are used to control the flow of the data execution.
There are 7 types of controlling keywords—>
LOOP——ENDLOOP (to be used in internal table concept)
Note—As an ABAPER we always create custom programs, and as per coding standards name of the program should always start with either ‘y’ or ‘z’.
All programs starting with alphabets other than ‘y’ and ‘z’ are known as standard programs, which are created and developed by SAP labs.
Transaction in SAP is a 4 digit short cut key to access he requested transaction. Transaction code provides direct access to the desired transaction from anywhere within the SAP system.
Transaction code or T-code for ABAP editor screen is “se38”.
Some more transaction codes in ABAP—>
When you are compiling the program try to follow the following steps—>
Click on SAVE.
Then Check (
Then Active it.
Click on Execute.
‘IF’ is a control statement used to specify one or more conditions. You may also nest the IF control structures in an ABAP program.
If the ‘IF’ CONDITION is true then only it will execute coding otherwise it will directly jump to ENDIF.
In case of IF….ELSE statements, if the expression evaluates to true then the IF block of code will be executed. Otherwise, ELSE block of code will be executed.
In case of IF….ELSEIF statements, the expression is checked at every condition. It will execute only when the condition is true.
The CASE control statement is used when you need to compare two or more fields.
The following rules apply to a CASE statement −
NO logical expressions can be used for <field> field.
The field strings uses in CASE statement are used as type C variables
The statement block following a WHEN clause is executed if the contents of the fields shown in the <field> is similar to one of the fields <abc>, <def>, <ghi> up to <xyz>.
After executing all the conditions specified in the WHEN statement, the program continues to process the remaining statements after the ENDCASE statement.
The WHEN OTHERS clause is executed in a program when the value of the <field> does not match with any value specified in the <abc> up to <xyz> fields of the WHEN clause.
If the WHEN OTHERS clause is omitted and the value of the <field> does not match with any value specified in the <abc> up to <xyz> fields of the WHEN clause, the program continues to process the remaining statements after the ENDCASE statement.
BASIC CONCEPT OF LOOPING
Loops are among the most basic and powerful of programming concepts. A loop in a computer program is an instruction that repeats until a specified condition is reached. In a loop structure, the loop asks a question. If the answer requires action, it is executed. The same question is asked again and again until no further action is required. Each time the question is asked is called an iteration.
A computer programmer who needs to use the same lines of code many times in a program can use a loop to save time.
Different types of looping techniques
DO—ENDDO is an unconditional loop. It does not have any condition to check whether it’s true or false. It will execute the exact of times as mentioned by the user.
The statements DO and ENDDO define a control structure, which can contain a closed statement block statement_block.
If the addition n TIMES is not specified, the loop has to be terminated by a statement; otherwise the loop is processed endlessly. The profile parameter rdisp/max_wprun_time limits the maximum execution time of an ABAP program. If this is exceeded, the program is ended by the runtime environment.
DO [n TIMES].
2. WHILE———ENDWHILE. (Conditional loop)
The statements WHILE and ENDWHILE define a control structure that can contain a closed statement block statement_block. After WHILE, any LOGICAL EXPRESSION (log_exp) can follow.
The statement block is repeated as long as the logical expression is true, or until it is exited with one of the statements to leave loops. In particular, the statement EXIT is ideal for exiting a loop completely. Within the statement block, the system field sy-index contains the number of previous loop passes, including the current pass. In nested loops, sy-index always refers to the current loop.
The condition should not exceed the maximum limit. If in case this happens the program is ended by the runtime environment
3. LOOP———ENDLOOP. (Used in internal tables)
Processes an internal table (DATA ) in a loop which begins with LOOP and ends with ENDLOOP . Each of the internal table entries is sent to the output area in turn.
When LOOP AT itab. is used, the header line of the internal table itab is used as output area. In the case of LOOP AT itab INTO wa , there is an explicitly specified work area wa .
If the internal table is empty, all the statements between LOOP and ENDLOOP are ignored.
LOOP AT INT_TABLE INTO WORK_AREA.
ISHNOOR SINGH SETHI