
ABAP中的IF语句怎么用?
4个回答
展开全部
语法:
IF <condition1>.
<statement block>
ELSEIF <condition2>.
<statement block>
ELSEIF <condition3>.
<statement block>
.....
ELSE.
<statement block>
ENDIF.
范例:
DATA: TEXT1(30) VALUE 'This is the first text',
TEXT2(30) VALUE 'This is the second text',
TEXT3(30) VALUE 'This is the third text',
STRING(5) VALUE 'eco'.
IF TEXT1 CS STRING.
WRITE / 'Condition 1 is fulfilled'.
ELSEIF TEXT2 CS STRING.
WRITE / 'Condition 2 is fulfilled'.
ELSEIF TEXT3 CS STRING.
WRITE / 'Condition 3 is fulfilled'.
ELSE.
WRITE / 'No condition is fulfilled'.
ENDIF.
产生如下输 出:
Condition 2 is fulfilled.
这里,第二 个逻辑表达 式 TEXT2 CS STRING 是真,因为 字符串“eco” 存在于 TEXT2 中。
IF <condition1>.
<statement block>
ELSEIF <condition2>.
<statement block>
ELSEIF <condition3>.
<statement block>
.....
ELSE.
<statement block>
ENDIF.
范例:
DATA: TEXT1(30) VALUE 'This is the first text',
TEXT2(30) VALUE 'This is the second text',
TEXT3(30) VALUE 'This is the third text',
STRING(5) VALUE 'eco'.
IF TEXT1 CS STRING.
WRITE / 'Condition 1 is fulfilled'.
ELSEIF TEXT2 CS STRING.
WRITE / 'Condition 2 is fulfilled'.
ELSEIF TEXT3 CS STRING.
WRITE / 'Condition 3 is fulfilled'.
ELSE.
WRITE / 'No condition is fulfilled'.
ENDIF.
产生如下输 出:
Condition 2 is fulfilled.
这里,第二 个逻辑表达 式 TEXT2 CS STRING 是真,因为 字符串“eco” 存在于 TEXT2 中。
展开全部
举个简单的例子:
C = 1+2 = 3,
这个时候判断C是不是等于3,等于3就出正确,不等于3就告诉用户,错了
IF C = 3.
正确。
ELSE.
错了。
ENDIF.
C = 1+2 = 3,
这个时候判断C是不是等于3,等于3就出正确,不等于3就告诉用户,错了
IF C = 3.
正确。
ELSE.
错了。
ENDIF.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就一个逻辑判断而以, 请参考
IF log_exp1.
[statement_block1]
[ELSEIF log_exp2.
[statement_block2]]
...
[ELSE.
[statement_blockn]]
ENDIF.
Effect
These statements define a control structure which can contain multiple statement blocks statement_block of which a maximum of one will be executed in conjunction with logical expressions log_exp.
After IF and ELSEIF any logical expressions log_exp can be executed while the expressions statement_block stand for any statement blocks.
The logical expressions, beginning with the IFstatement, are checked from top to bottom and the statement block after the first is executed during the logical expression. If none of the logical expressions are true, the statement block after the ELSE statement is executed.
When the end of the statement block is reached or if no statement block is to be executed, the processing is continued after ENDIF.
Example
Converting a time output into the 12-hour format (see also country-specific formats).
DATA time TYPE t.
fltime = sy-time.
IF time < '120000'.
WRITE: / time, 'AM' .
ELSEIF time > '120000' AND
time < '240000'.
time = time - 12 * 3600.
WRITE: / time, 'PM' .
ELSE.
WRITE / 'High Noon'.
ENDIF.
IF log_exp1.
[statement_block1]
[ELSEIF log_exp2.
[statement_block2]]
...
[ELSE.
[statement_blockn]]
ENDIF.
Effect
These statements define a control structure which can contain multiple statement blocks statement_block of which a maximum of one will be executed in conjunction with logical expressions log_exp.
After IF and ELSEIF any logical expressions log_exp can be executed while the expressions statement_block stand for any statement blocks.
The logical expressions, beginning with the IFstatement, are checked from top to bottom and the statement block after the first is executed during the logical expression. If none of the logical expressions are true, the statement block after the ELSE statement is executed.
When the end of the statement block is reached or if no statement block is to be executed, the processing is continued after ENDIF.
Example
Converting a time output into the 12-hour format (see also country-specific formats).
DATA time TYPE t.
fltime = sy-time.
IF time < '120000'.
WRITE: / time, 'AM' .
ELSEIF time > '120000' AND
time < '240000'.
time = time - 12 * 3600.
WRITE: / time, 'PM' .
ELSE.
WRITE / 'High Noon'.
ENDIF.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单的语法就是:
if xxx.
else.(有时候会用到elseif xxx.)
ednif.
具体的可以参照sap help.
if xxx.
else.(有时候会用到elseif xxx.)
ednif.
具体的可以参照sap help.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询