Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

difference b/w check and if statement

Former Member
0 Likes
3,491

difference b/w check and if statement

1 ACCEPTED SOLUTION

difference b/w check and if statement

8 REPLIES 8
Read only

Former Member
2,070

Learn to search.

Learn to use the on line help.

Read only

Former Member
0 Likes
2,070

Hi,

LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE

evaluates the specified condition internally.

As with any logical expressions, the performance is better if the

operands of a comparison share a common type.

The performance can be further enhanced if LOOP ... WHERE is combined

with FROM i1 and/or TO i2, if possible.

I would be helpful for you..

Rgds

Yogesh

Read only

Former Member
0 Likes
2,070

Hi

Check statement, checks the condition with in a loop and if it satisfies the condition, the control moves to next statement in the loop. Otherwise, it terminates the loop.

[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3571358411d1829f0000e829fbfe/content.htm]

Definitely useful

Reward helpful

Regards

Lakshman

Read only

Former Member
0 Likes
2,070

Hi!!

IF

Syntax

IF log_exp1.

[statement_block1]

[ELSEIF log_exp2.

[statement_block2]]

...

[ELSE.

[statement_blockn]]

ENDIF.

Effect

These statements define a control structure which can contain several statement_block statement blocks; depending on the logical expressions log_exp, maximally one of the blocks is executed.

After IF and ELSEIF, any number of logical expressions log_exp can be specified, while the expressions statement_block represent any kind of statement blocks.

The logical expressions are checked from top to bottom, starting

with the IF statement, and the statement block after the first true logical expression is executed. If none of the logical expressions is true, then the statement block after the ELSE statement is executed.

If the end of the executed statement block is reached or if no statement block was executed, then the processing is resumed after ENDIF.

Example

Converting a time output into Anglo American notation

DATA time TYPE t.

time = sy-uzeit.

IF time < '120000'.

WRITE: / time, 'AM' .

ELSEIF time > '120000' AND

time < '240000'.

time = time - 12 * 3600.

WRITE: / time, 'PM' .

ELSE.

WRITE / 'High Noon'.

ENDIF.

Syntax

CHECK log_exp.

Effect

If the statement CHECK is executed in a loop and log_exp is incorrect, the statement CHECK immediately terminates the current loop pass and the program continues with the next loop pass. For log_exp, you can specify any logical expression.

Note

Outside a loop, the statement CHECK exits the current processing block (see CHECK Processing Block).

Example

Termination of the loop pass using CHECK when the loop index sy-index is odd-numbered.

DATA remainder TYPE i.

DO 20 TIMES.

remainder = sy-index MOD 2.

CHECK remainder = 0.

WRITE / sy-index.

ENDDO.

Note:

if the condtion is true the if-endif block code is executed otherwise th ewhole block is ignored.

multiple conditions can be checked in if-else if-endif where as check can look after only onle conditon.

check statement

CHECK

This statement will apply if you want to check condition before go to next statement. If the result of checking is u2019TRUEu2019, system will go to next step as normally. If the result of checking is u2019FALSEu2019, system will operate look like CONTINUE statement.

Example

DO 4 TIMES.

WRITE:/ sy-index.

CHECK sy-index > 2.

WRITE: u2019Afteru2019.

ENDDO.

The output is

1

2

3 After

4 After

Hope this helps

Reward points if helpful.

Read only

Former Member
0 Likes
2,070

hi,

The check statement is coded within a loop. It can act very much like continue, passing control immediately to the terminating statement of the loop and bypassing the statements between. Unlike continue, it accepts a logical expression. If the expression is true, it does nothing. If it is false, it jumps to the end of the loop.

check behaves like a continue statement when the logical expression is false. When it is true, it does nothing.

Syntax for the check Statement

The following is the syntax for the check statement. It can be used within a do, while, select, or loop.

[do/while/select/loop]

---

check exp.

---

[enddo/endwhile/endselect/endloop]

where:

u2022exp is a logical expression.

u2022--- represents any number of lines of code.

The if statement in ABAP/4 has relational operators for equality and inequality and special relational operators for string comparisons and for bit masks.

The following is the syntax for the if statement.

if [not] exp [ and [not] exp ] [ or [not] exp ].

---

[elseif exp.

---]

[else.

---]

endif.

where:

u2022exp is a logical expression that evaluates to a true or false condition.

u2022--- represents any number of lines of code. Even zero lines are allowed.

The following points apply:

u2022Every if must have a matching endif.

u2022else and elseif are optional.

u2022Parentheses can be used. Each parentheses must be separated by a space. For example, if ( f1 = f2 ) or ( f1 = f3 ) is correct, and if (f1 = f2) or (f1 = f3) is incorrect.

u2022Variables can be compared with blanks or zeros using the addition is initial. For example, if f1 is initial will be true if f1 is type c and is blank. If f1 is any other data type, the statement is true if f1 contains zeros.

u2022To accomplish negation, not must precede the logical expression. For example, if not f1 is initial is correct. if f1 is not initial is incorrect.

u2022Variables can be compared with nulls using the addition is null. For example, if f1 is null.

pls reward if helpful.

Regards,

Rajyalakshmi

Edited by: Rajyalakshmi Attili on Jun 2, 2008 3:03 PM

Read only

0 Likes
2,070

Hi,

If :

if condition is true the block will execute otherwise i will skip block of code then execute the line after the line endif . You can give else condition in your program.

Check:

if condition is true then only it will enter to next line otherwise i will not execute bellow lines . check will not give else condition in your program.

Read only

2,070

The question was from 2008!....no need to bring it back from the dead.