Controlling keywords are used to control the flow of the data execution.
There are 7 types of controlling keywords—>
IF——ENDIF.
IF——ELSE——ENDIF.
IF——ELSEIF——ENDIF.
CASE——WHEN——ENDCASE.
DO——ENDDO.
WHILE——ENDWHILE.
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 code—>
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—>
KNOWLEDGE CLOUD——>
When you are compiling the program try to follow the following steps—>
Click on SAVE.
Then Check (
Then Active it.
Click on Execute.
IF——ENDIF—>
‘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.
SYNTAX—>
IF (CONDITION).
CODING.
ENDIF.
Flow Diagram—>
CODING SCREEN—>
INPUT 1—>
OUTPUT 1—>
INPUT 2—>
OUTPUT 2—>
2. IF——ELSE——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.
SYNTAX—>
IF (CONDITION).
CODING.
ELSE.
CODING.
ENDIF.
Flow Diagram—->
CODING SCREEN—>
INPUT 1—>
OUTPUT 1—>
INPUT 2—>
OUTPUT 2—>
3. IF—ELSEIF—ENDIF—>
In case of IF….ELSEIF statements, the expression is checked at every condition. It will execute only when the condition is true.
SYNTAX—>
IF(CONDITION).
CODING.
ELSEIF(CONDITION).
CODING.
ELSEIF(CONDITION).
CODING.
ENDIF.
CODING SCRREN—>
INPUT 1—>
OUTPUT 1—>
INPUT 2—>
OUTPUT 2—>
4. CASE—WHEN—ENDCASE—>
The CASE control statement is used when you need to compare two or more fields.
SYNTAX—>
CASE <field>.
WHEN <abc>.
<statement block>.
WHEN <def>.
<statement block>.
WHEN <pqr>.
<statement block>.
......
......
......
WHEN <xyz>.
<statement block>.
WHEN OTHERS.
<statement block>.
ENDCASE.
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.
Flow Diagram—>
CODING SCREEN—>
INPUT—>
OUTPUT—>
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(unconditional loop)
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.
SYNTAX—>
DO [n TIMES].
[statement_block]
ENDDO.
CODING SCREEN—>
INPUT —>
OUTPUT—>
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
SYNTAX——>
WHILE log_exp
[statement_block]
ENDWHILE.
CODING SCREEN—>
INPUT—>
OUTPUT—>
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.
Syntax——>
LOOP AT INT_TABLE INTO WORK_AREA.
[STATEMENT]
ENDLOOP.
ISHNOOR SINGH SETHI
ความคิดเห็น