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

subroutines

Former Member
0 Likes
2,357

"Like any other processing block, subroutines cannot be nested. You should therefore place your subroutine definitions at the end of the program, especially for executable programs (type 1). In this way, you eliminate the risk of accidentally ending an event block in the wrong place by inserting a FORM...ENDFORM block."

I have read this in some documentation.. but i didnt get that point.? sub routines can be nested as i know.. but in this it wa mentioned as it cant be nested. what does that mean??

"Like any other processing block, subroutines cannot be nested. You should therefore place your subroutine definitions at the end of the program, especially for executable programs (type 1). In this way, you eliminate the risk of accidentally ending an event block in the wrong place by inserting a FORM...ENDFORM block."

I have read this in some documentation.. but i didnt get that point.? sub routines can be nested as i know.. but in this it wa mentioned as it cant be nested. what does that mean??

14 REPLIES 14
Read only

Former Member
0 Likes
2,324

I think it means that you can't do this...


FORM TEST.
  FORM TEST_ME.
  ENDFORM.
ENDFORM.

Greetings,

Blag.

Read only

Former Member
0 Likes
2,324

Yes we can nested the sub routines.

Perform <sub_name1>

form <sub_name1>

..............

..............

Perform <sub_name2>

..............

endform.

form <sub_name2>

...................

....................

endform.

Read only

Former Member
0 Likes
2,324

Hi Sandeep,

In addition to to what Blag said, if you write the FORM..... ENDFORM before completing the event block, that event maybe terminated and the statements after the endform will be inaccessible. This throws up an error in unicode programs.

hence they should always be written at the end of the code.

Cheers

~goldie.

Read only

0 Likes
2,324

Hi goldie I didnt get your point.. can you explain it more clear !

Read only

0 Likes
2,324

I will give you an example



START-OF-SELECTION.

perform func1.
perform func2.

FORM func1.
.
ENDFORM.

perform func3.

FORM func2.
.
.
write:/ 'something'.
ENDFORM.

FORM func3.
ENDFORM.

In the above case the perform func3 is never called, because we are writing the output in func2.

As a result that statement will become inaccessible and throws up an error in unicode programs.

In older versions we would only get a warning.

Think this explains it. If not I will send you a real live example.

~goldie.

Read only

0 Likes
2,324

ya goldie,

I got your point to some extent but still kind of vague actually what do you mean by event block ..form.. endform is one event block right

...if i write code like this..

START-OF-SELECTION.

perform func1.

perform func2.

perform func3.

FORM func1.

write 'sandeep'.

ENDFORM.

FORM func2.

write:/ 'something'.

ENDFORM.

perform func3.

FORM func3.

write 'san'.

ENDFORM.

then also it is not calling FUN3..?? i was thinking after executing fun1 fun2 it should go for next statemnt that is perform fun3 right?

Edited by: Sandeep Manukonda on Feb 19, 2008 4:19 PM

Read only

0 Likes
2,324

Hi sandeep,

The first time you call func3, it will be executed.

but the second perform func3 will throw an error, because that is the statement which is not accessible.

If you remove it from the current place and write it under perform func3, you wont have any problem.

You will see 'SAN' 2 times in the output (that is what your code is suppposed to do now right??).

goldie.

Read only

0 Likes
2,324

no goldie its not executing the program.. it is showing an error..like statement(second perform fun3) is not accessible...

Read only

0 Likes
2,324

thats what I told you.

take the second perform func3, and write it under first perform func3.



perform func1.
perform func2.
perform func3.
perform func3.

FORM func1.
ENDFROM.
.......
.
..

This is how it should be.

Read only

0 Likes
2,324

as you said why second perform fun3 throws an error..?? why it is not accessible?

after end form of fun2 it should execute perform fun3 which calls form .. endform ..isnt it taht way?

Read only

0 Likes
2,324

ya its correct .. but i was wondering why it wot work in other way ...like writing perform fun3 after endform of fun2..

why it wont call perform in the sequence..

i have got confusion goldie.. from this i came to know you are the right person to solve my q..

can you please calrify me?

i didnt get taht point ?? what do you mean by statement is not accessible if it is betwwen events..

Read only

0 Likes
2,324

Sandeep,

You have to understand that your problem was only with the second perform func3.

The first was correct.

I guess it is like this.

After the endform, the ABAP editor looks for the next perform. there will be no problem if they are in sequence like func1, func2 and first func3.

but if it encounters a FORM, it stops looking or terminates the event (here Start-of-selection).

Thats why the second perform func3 was not even encountered and hence inaccessible.

but if you want to make it accessible, you have to write in a sequence in the same event block or make it accessible using another event like END-OF-SELECTION.

I havent tried the other option, so if you try it out and find my hypothesis true... let me know

This is the only explanation I can come up with. I am new to SAP, its been only 3 months now.

So sorry if I cant explain better.

Cheers,

~goldie.

Read only

0 Likes
2,324

Thats awesome... im almost clarified ...ya i too know that probrlem is only with the second func3..

so if it encounters first form it wont look for anter perform..right?

before you said you can give me one real time example what abt that?

Read only

0 Likes
2,324

perform func1.

perform func2.

perform func3.

FORM func1.

write 'sandeep'.

ENDFORM.

FORM func2.

write:/ 'something'.

ENDFORM.

FORM func3.

write 'san'.

ENDFORM.

Then it works fine, because the form---endform statements should be the last statements.

So after the form statement we can't use the perform statement.