CASE: ABAP Keyword a day
CASE
Basic form
CASE f.
Effect Case distinction.
Depending on the current contents of a field, this statement executes one of several alternative processing branches. The field whose contents determine how the subsequent processing is specified after CASE ; the individual processing branches are introduced by WHEN , followed by the value to be tested. The entire block is concluded by ENDCASE . The structure of the CASE statement is as follows:
CASE f.
WHEN f1.
…
WHEN f2.
…
…
ENDCASE.
On reaching such a CASE statement, the processor compares f with f1 .
If f = f1 , it executes the processing block between ” WHEN f1. ” and the next WHEN statement. If there are no further WHEN statements, it executes the processing block up to the ENDCASE statement and then continues with any subsequent processing.
If f <> f1 , the processor compares the field f2 in the next WHEN statement with f and proceeds as with f1 and so on.
Although f should be a variable, f1 can be a variable or a literal. For the comparison ” f = f1 “, the rules are the same as for IF .
There is a second variant of the WHEN statement:
WHEN OTHERS.
No more than one such WHEN statement is allowed within a CASE block. The ” WHEN OTHERS ” processing block is always concluded by ENDCASE , i.e. no further WHEN statements can follow.
The ” WHEN OTHERS ” processing block is executed only if none of the preceding WHEN blocks have been executed, i.e. if all previous comparisons (” f = … ) have returned a negative result.
Example
DATA: ONE TYPE I VALUE 1,
THREE TYPE P VALUE 3.
DO 5 TIMES.
CASE SY-INDEX.
WHEN ONE.
WRITE / ‘That is’.
WHEN 2.
WRITE ‘a’.
WHEN THREE.
WRITE ‘good’.
WRITE ‘example’.
WHEN OTHERS.
WRITE ‘!’.
ENDCASE.
ENDDO.
Output: ” That is a good example ! ! “
Notes
You can nest several CASE statements and even combine them with IF statements.
The statement ” WHEN: f1, f2. ” does not make sense. The example below shows that the block belonging to ” WHEN f1 ” is empty:
WHEN f1.
WHEN f2.
Related
IF , ELSEIF
———————
ABAPer, mail: abap.community@gmail.com http://www.erpdb.info
If you like this post, you may as well like these too:
- AT : ABAP Keyword a day AT Events in lists- AT LINE-SELECTION.- AT USER-COMMAND.- AT PFn.Events on selection screens- AT SELECTION-SCREEN.Control break with extracts- AT NEW f.- AT END OF f.- AT FIRST.- AT LAST.- AT...
- GET: ABAP Keyword a day GET: Event keyword for defining event blocks for reporting events. GET <node> [FIELDS <fi> <f 2>...]. GET node LATE [FIELDS f1 f2 ...]. Only occurs in executable programs. When the...
- DO : ABAP Keyword a day DO Variants 1. DO. 2. DO n TIMES. Variant 1 DO. Addition … VARYING f FROM f1 NEXT f2 Effect Repeats the processing enclosed by the DO and ENDDO statements...
- ASSIGN: ABAP Keyword a day ASSIGN Variants:1. ASSIGN f TO .2. ASSIGN (f) TO .3. ASSIGN TABLE FIELD (f) TO .4. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .5. ASSIGN COMPONENT idx OF...
- FORM: ABAP Keyword a day FORM: Defines a subroutine. Syntax FORM [USING ... [VALUE(][)] [TYPE |LIKE ]„. ] [CHANGING... [VALUE(][)] [TYPE |LIKE ]„. ]. Introduces a subroutine. The USING and CHANGING additions define the subroutine’s...
- FETCH : ABAP Keyword a day FETCH Basic form FETCH NEXT CURSOR c target. Effect Uses the cursor c to read the next line or lines from the dataset of a database table determined by OPEN...
- EXPORT : ABAP Keyword a day EXPORT 1 2 3 4 *Export data - EXPORT obj1 ... objn TO MEMORY. - EXPORT obj1 ... objn TO DATABASE dbtab(ar) ID key. - EXPORT obj1 ... objn TO...
- DIVIDE : ABAP Keyword a day DIVIDE Basic form DIVIDE n1 BY n2. Effect Divides the contents of n1 by n2 and places the result in n1 . This is equivalent to: n1 = n1 /...
- DESCRIBE : ABAP Keyword a day DESCRIBE Return attributes of a field - DESCRIBE FIELD f. Return attributes of an internal table - DESCRIBE TABLE itab. Determine distance between two fields - DESCRIBE DISTANCE BETWEEN f1...
- DATA : ABAP Keyword a day DATA Variants1. DATA f.2. DATA f(len).3. DATA: BEGIN OF rec,…END OF rec.4. DATA: BEGIN OF itab OCCURS n,…END OF itab.5. DATA: BEGIN OF COMMON PART c,…END OF COMMON PART.EffectDefines global...
- CONTINUE: ABAP Keyword a day CONTINUE Basic formCONTINUE.EffectWithin loop structures like * DO … ENDDO* WHILE … ENDWHILE* LOOP … ENDLOOP* SELECT … ENDSELECTCONTINUE terminates the current loop pass, returns the processing to the beginning...
- CONCATENATE : ABAP Keyword a day CONCATENATE Basic form CONCATENATE f1 … fn INTO g. Addition … SEPARATED BY h Effect Places the fields f1 to fn after g . With the fields fi (1 <=...
- COMPUTE: ABAP Keyword a day COMPUTEBasic formCOMPUTE n = arithexp.EffectEvaluates the arithmetic expression arithexp and places the result in the field n .Allows use of the four basic calculation types + , – , *...
- CHECK : ABAP Keyword a day CHECK Within loops and events- CHECK logexp.Special for reports with logical databases- CHECK sel.- CHECK SELECT-OPTIONS. CHECK – within loops Basic formCHECK logexp.EffectCHECK evaluates the subsequent logical expression . If...
- GET PARAMETER: ABAP Keyword a day GET PARAMETER Gets an SPA/GPA parameters. Syntax GET PARAMETER ID <pid> FIELD <field_name>. Writes the value of the SPA/GPA parameter <pid> from the user-specific SAP memory into the variable <f>....



















Leave a Reply