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

FM PROBLEM

Former Member
0 Likes
548

DEAR ALL .

CAN I INCLUDE SUBROUTINE IN FUNCTION MODULE .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
517

Yes you can. Is your question the same or different.

4 REPLIES 4
Read only

vinod_gunaware2
Active Contributor
0 Likes
517

Yes U can add subroutine in FM.

<b>Calling Subroutines</b>

You use subroutines for local modularization. Function modules can also use this technique. The function module that they call are defined in the corresponding main program.

If you only want to call a subroutine from a single function module, it is best to define them in the same include program as the function module itself, directly after the ENDFUNCTION statement. These subroutines can be called from all function modules in the function group, but for clarity, they should only be called from the function module that precedes them.

If you want to define a subroutine that will be called from several different function modules, you can define a special include program for it with the name L<fgrp>F<xx>.

<b>Subroutines</b>

Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.

<b>Defining Subroutines</b>

A subroutine is a block of code introduced by FORM and concluded by ENDFORM.

FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]

[CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ].

...

ENDFORM.

<subr> is the name of the subroutine. The optional additions USING and CHANGING define the parameter interface. 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.

<b>Calling Subroutines</b>

You call subroutines using the statement

PERFORM... [USING ... <pi>... ]

[CHANGING... <pi>... ].

Subroutines can call other subroutines (nested calls) and may also call themselves (recursive calls). Once a subroutine has finished running, the calling program carries on processing after the PERFORM statement. You can use the USING and CHANGING additions to supply values to the parameter interface of the subroutine.

regards

vinod

Read only

Former Member
0 Likes
518

Yes you can. Is your question the same or different.

Read only

Former Member
0 Likes
517

hi,

yes you can do that, if you are creating it will ask you to include in the include ****F01 or you can do it in the same FM it self.

Regards

vijay

Read only

Former Member
0 Likes
517

I hope you are not asking for including the code for a routine within the function module code as follows.

This is not possible if that is what you are asking.


FUNCTION POPUP_TO_DISPLAY_VALUE.
*"-------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(COLBEG)
*"     VALUE(COLEND)
*"     VALUE(ITEMTXT)
*"     VALUE(TEXTLINE1)
*"     VALUE(TEXTLINE2)
*"     VALUE(TEXTLINE3)
*"     VALUE(TEXTLINE4)
*"     VALUE(TITLE)
*"-------------------------------------------------------

* Überschrift
  GLID-TITLE   = TITLE.
  GLID-ITEMTXT = ITEMTXT.

* Ausgabe
  GLID-TEXTLN1 = TEXTLINE1.
  GLID-TEXTLN2 = TEXTLINE2.
  GLID-TEXTLN3 = TEXTLINE3.
  GLID-TEXTLN4 = TEXTLINE4.

  CALL SCREEN 100 STARTING AT 40 COLBEG
                  ENDING   AT 75 COLEND.
<b>--> You can have a PERFORM statement between the
FUNCTION and ENDFUNCTION, but not the code of the FORM 
routine itself.<--</b>
ENDFUNCTION.

You can either write the routine after this ENDFUNCTION

statment or create a seperate include as others here

explained.

Please close the thread if answered.

Srinivas