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

Incorrect nesting

Former Member
0 Likes
1,049

Hi,

This is my program.

PARAMETERS:

P_NUM1 TYPE I,

P_NUM2 TYPE I,

P_OPER TYPE C.

DATA:

W_RESULT TYPE I.

CALL FUNCTION 'ZAC_CALCULATE'

EXPORTING

IM_NUM1 = P_NUM1

IM_NUM2 = P_NUM2

IM_OPER = P_OPER

  • IMPORTING

  • EX_RESULT =

  • EXCEPTIONS

  • INVALID_OPERATOR1 = 1

  • ZERO_DIVIDE1 = 2

  • OTHERS = 3

.

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

IF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

IF SY-SUBRC EQ 1.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

Iam getting the following error.

Incorrect nesting: Before the end of the program, the structure

introduced by "IF" must be concluded by "ENDIF" . . . . . .

1 ACCEPTED SOLUTION
Read only

amit_khare
Active Contributor
0 Likes
944

USe this -

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

IF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

<b><i>ELSEIF</i></b> SY-SUBRC EQ 1.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

Regards,

Amit

Reward all helpful replies.

8 REPLIES 8
Read only

Former Member
0 Likes
944

Hi,

THE STRUCTURE SHOULD FOLLOW THIS

IF <condition1>.

<statement block>

ELSEIF <condition2>

<statement block>.

ELSEIF <condition3>.

<statement block>

.....

ELSE.

<statement block>

ENDIF.

SO MAKE SOME CHANGES IN YOUR CODE

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

ELSEIF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

ELSEIF SY-SUBRC EQ 1.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

************PLEASE REWARD POINTS IF THE INFORMATION IS HELPFUL TO YOU************

Read only

amit_khare
Active Contributor
0 Likes
945

USe this -

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

IF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

<b><i>ELSEIF</i></b> SY-SUBRC EQ 1.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
944

Hi,

PARAMETERS:
P_NUM1 TYPE I,
P_NUM2 TYPE I,
P_OPER TYPE C.

DATA:
W_RESULT TYPE I.


CALL FUNCTION 'ZAC_CALCULATE'
EXPORTING
IM_NUM1 = P_NUM1
IM_NUM2 = P_NUM2
IM_OPER = P_OPER
* IMPORTING
* EX_RESULT =
* EXCEPTIONS
* INVALID_OPERATOR1 = 1
* ZERO_DIVIDE1 = 2
* OTHERS = 3
.
IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

IF SY-SUBRC EQ 1.
WRITE:/ 'INVALID OPERATION'.

IF SY-SUBRC EQ 1.
WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.
WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.
ENDIF.   " Add this
ENDIF.   " Add this

Regards

Sudheer

Read only

Former Member
0 Likes
944

Try This

Incorrect nesting

Posted: Jul 10, 2007 1:17 PM Reply E-mail this post

Hi,

This is my program.

PARAMETERS:

P_NUM1 TYPE I,

P_NUM2 TYPE I,

P_OPER TYPE C.

DATA:

W_RESULT TYPE I.

CALL FUNCTION 'ZAC_CALCULATE'

EXPORTING

IM_NUM1 = P_NUM1

IM_NUM2 = P_NUM2

IM_OPER = P_OPER

  • IMPORTING

  • EX_RESULT =

  • EXCEPTIONS

  • INVALID_OPERATOR1 = 1

  • ZERO_DIVIDE1 = 2

  • OTHERS = 3

.

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

ElSEIF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

ELSEIF SY-SUBRC EQ 1.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

Read only

Former Member
0 Likes
944

Hi,

Try this,

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

ELSEIF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

ELSEIF SY-SUBRC EQ 1.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

Thanks,

Reward If Helpful.

Read only

Former Member
0 Likes
944

Hi,

write like this:

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

ELSEIF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

ELSEIF SY-SUBRC EQ *. <- here, appropriate sybrc check.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

Regards,

Siddhesh Sanghvi.

Read only

Former Member
0 Likes
944

hi ,

Write like this way.

PARAMETERS:

P_NUM1 TYPE I,

P_NUM2 TYPE I,

P_OPER TYPE C.

DATA:

W_RESULT TYPE I.

CALL FUNCTION 'ZAC_CALCULATE'

EXPORTING

IM_NUM1 = P_NUM1

IM_NUM2 = P_NUM2

IM_OPER = P_OPER

  • IMPORTING

  • EX_RESULT =

  • EXCEPTIONS

  • INVALID_OPERATOR1 = 1

  • ZERO_DIVIDE1 = 2

  • OTHERS = 3

.

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

IF SY-SUBRC EQ 1.

WRITE:/ 'INVALID OPERATION'.

endif.

IF SY-SUBRC EQ 1.

WRITE:/ 'CANNOT DIVIDE BY ZERO'.

endif.

ELSE.

WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.

thanks,

CS Reddy.

Read only

Former Member
0 Likes
944

change to this

IF SY-SUBRC EQ 0.

WRITE:/ 'RESULT IS', W_RESULT.

elseIF SY-SUBRC EQ 1.
WRITE:/ 'INVALID OPERATION'.

elseIF SY-SUBRC EQ 2.         " SY-SUBRC changed to 2
WRITE:/ 'CANNOT DIVIDE BY ZERO'.

ELSE.
WRITE:/ 'UNKNOWN EXCEPTION'.

ENDIF.