Function module vs loacal subroutines
Hi all,
I have created some six function modules for data migration.all are working fine.
but if i utillized local subroutine for the same logic
it creates performance issue.actually performance for the local subroutine is far better than (1/12) than function module.i checked all coding in both routines .everything is correct.
then what could be the problem.if u know the answer please let me know.
regards,
raja
Hi,
Whenever a function module is called there is a process called context switch happens in micro-processor.
In this process all the registers(local memory of microprocessor ), program counter and memory(here cache and RAM) is refreshed and reloaded and previous content is saved in memory location. This whole process takes time. Thats why we have performance issue here.
So direct line of code is faster that local sub-routine . and local sub-routine is faster than function module.
Regards,
Sumit.
Similar Messages
-
Can we call functional module in a subroutine? Any example?
Can we call functional module in a subroutine? Any example?
sample code....
REPORT ZPL_BDC_PA30.
TABLES : PA0022.
DATA : V_PERNR LIKE PA0022-PERNR,
V_SLABS LIKE PA0022-SLABS.
DATA : FILENAME TYPE STRING.
DATA : BEGIN OF IT_DATA OCCURS 0,
PERNR LIKE PA0022-PERNR, "Personnel Number
SLABS LIKE PA0022-SLABS, "Certificate code
SLABS1 LIKE PA0022-SLABS, "Certificate code new
END OF IT_DATA.
DATA : IT_BDCDATA LIKE BDCDATA OCCURS 1 WITH HEADER LINE.
DATA : BEGIN OF IT_ERROR OCCURS 0,
POS LIKE SY-TABIX,
TEXT(40),
END OF IT_ERROR.
PARAMETERS : P_FNAME TYPE DXFIELDS-LONGPATH.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
I_LOCATION_FLAG = ' '
I_SERVER = '?'
I_PATH = I_PATH
FILEMASK = '.'
FILEOPERATION = 'R'
IMPORTING
O_LOCATION_FLAG = O_LOCATION_FLAG
O_SERVER = O_SERVER
O_PATH = P_FNAME
ABEND_FLAG = ABEND_FLAG
EXCEPTIONS
RFC_ERROR = 1
ERROR_WITH_GUI = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
START-OF-SELECTION.
FILENAME = P_FNAME.
PERFORM UPLOAD. "Uploading inputfile to internal table.
PERFORM VALIDATE. "validating the values
PERFORM POPULATE_BDC. "Populating bdc internal table
PERFORM ERROR_RECORDS
TABLES IT_ERROR. "Error records
*& Form bdc_fdata
FORM BDC_FDATA USING FNAM FVAL.
CLEAR IT_BDCDATA.
IT_BDCDATA-FNAM = FNAM.
IT_BDCDATA-FVAL = FVAL.
APPEND IT_BDCDATA.
ENDFORM. " bdc_fdata
*& Form bdc_hdata
FORM BDC_HDATA USING PROGRAM SCRNO DYNBEGIN.
CLEAR IT_BDCDATA.
IT_BDCDATA-PROGRAM = PROGRAM.
IT_BDCDATA-DYNPRO = SCRNO.
IT_BDCDATA-DYNBEGIN = DYNBEGIN.
APPEND IT_BDCDATA.
ENDFORM. " bdc_hdata
*& Form upload
FORM UPLOAD .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE = VIRUS_SCAN_PROFILE
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH = FILELENGTH
HEADER = HEADER
TABLES
DATA_TAB = IT_DATA
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
MESSAGE I000(BCTRAIN) WITH 'FILE NOT UPLOADED'.
ELSE.
MESSAGE I000(BCTRAIN) WITH 'FILE UPLOADED'.
ENDIF.
ENDFORM. " upload
*& Form populate_bdc
FORM POPULATE_BDC .
LOOP AT IT_DATA .
PERFORM BDC_HDATA USING 'SAPMP50A'
'1000'
'X'.
PERFORM BDC_FDATA USING 'RP50G-PERNR'
IT_DATA-PERNR.
PERFORM BDC_FDATA USING 'RP50G-CHOIC'
'0022'.
PERFORM BDC_FDATA USING 'BDC_OKCODE'
'=MOD'.
PERFORM BDC_HDATA USING 'MP002200'
'2000'
'X'.
PERFORM BDC_FDATA USING 'P0022-SLABS'
IT_DATA-SLABS1.
PERFORM BDC_FDATA USING 'BDC_OKCODE'
'=UPD'.
CALL TRANSACTION 'PA30' USING IT_BDCDATA.
REFRESH IT_BDCDATA.
ENDLOOP.
ENDFORM. " populate_bdc
*& Form validate
FORM VALIDATE .
data : num like sy-tabix,
num1 like sy-tabix.
LOOP AT IT_DATA.
num = num + 1.
num1 = sy-tabix.
SELECT PERNR
FROM PA0022
INTO V_PERNR WHERE
PERNR EQ IT_DATA-PERNR.
ENDSELECT.
IF SY-SUBRC <> 0.
MOVE num TO IT_ERROR-POS.
MOVE 'Invalid Pernr' TO IT_ERROR-TEXT.
APPEND IT_ERROR.
DELETE IT_DATA .
ELSE.
IF IT_DATA-SLABS IS INITIAL.
MOVE num TO IT_ERROR-POS.
MOVE 'Certificate code is initial' TO IT_ERROR-TEXT.
APPEND IT_ERROR.
DELETE IT_DATA.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " validate
*& Form error_records
FORM ERROR_RECORDS TABLES IT_ERRORS.
FORMAT COLOR COL_GROUP.
WRITE : / 'Error in the following records : ' .
FORMAT COLOR COL_NEGATIVE.
LOOP AT IT_ERROR.
WRITE : / IT_ERROR-POS,
IT_ERROR-TEXT.
ENDLOOP.
ENDFORM. " error_records -
How to use a function module in a subroutine
Hi,
I am working on a report where i have to create list boxes for 5 fields.Instead of using the function module VRM_SET_VALUES for each field can i use subroutine?
If so, can anyone tell me the procedure for that?Its very urgent.
Thanks and Regards,
HemaHi,
I have written the code like this.
FORM VALUE USING V_NAME.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING id = v_name
values = v_list.
ENDFORM.
AT SELECTION-SCREEN OUTPUT.
REFRESH V_LIST.
v_name = 'P_COMMER'.
v_value-key = 'C'.
v_value-text = 'Commercial'.
APPEND v_value TO v_list.
v_value-key = 'N'.
v_value-text = 'Non-Commercial'.
APPEND v_value TO v_list.
v_value-key = ' ' .
v_value-text = 'Both'.
APPEND v_value to v_list.
PERFORM VALUE USING V_NAME.
REFRESH V_LIST1.
v_name1 = 'P_DIRECT'.
v_value1-key = 'D'.
v_value1-text = 'Direct'.
APPEND v_value1 to v_list1.
v_value1-key = 'I'.
v_value1-text = 'Indirect'.
APPEND v_value1 to v_list1.
PERFORM VALUE USING V_NAME1.
REFRESH V_LIST2.
v_name2 = 'P_DIR'.
v_value2-key = 'D'.
v_value2-text = 'D'.
APPEND v_value2 TO v_list2.
v_value2-key = 'C'.
v_value2-text = 'C'.
APPEND v_value2 TO v_list2.
v_value2-key = ' ' .
v_value2-text = ' '.
APPEND v_value2 to v_list2.
PERFORM VALUE USING V_NAME2.
REFRESH V_LIST3.
v_name3 = 'P_LOW'.
v_value3-key = 'Y'.
v_value3-text = 'Yes'.
APPEND v_value3 TO v_list3.
v_value3-key = 'N'.
v_value3-text = 'No'.
APPEND v_value3 TO v_list3.
v_value3-key = ' ' .
v_value3-text = ''.
APPEND v_value3 to v_list3.
PERFORM VALUE USING V_NAME3.
REFRESH V_LIST4.
v_name4 = 'P_PARENT'.
v_value4-key = 'P'.
v_value4-text = 'Parent'.
APPEND v_value4 TO v_list4.
v_value4-key = 'C'.
v_value4-text = 'Child'.
APPEND v_value4 TO v_list4.
v_value4-key = ' ' .
v_value4-text = ''.
APPEND v_value4 to v_list4.
PERFORM VALUE USING V_NAME4.
REFRESH V_LIST5.
v_name5 = 'P_PREF'.
v_value5-key = 'P'.
v_value5-text = 'Preferred'.
APPEND v_value5 TO v_list5.
v_value5-key = 'N'.
v_value5-text = 'NotPreferred'.
APPEND v_value5 TO v_list5.
v_value5-key = ' ' .
v_value5-text = ''.
APPEND v_value5 to v_list5.
PERFORM VALUE USING V_NAME5.
Now I am getting the same set of values in all the fields.How can I solve this?
Thanks and Regards,
Hema -
Difference between Function module and a subroutine
hi
In the case of subroutine i can access the global workarea values.
I want to know whether in the case of function module
whether
i can follow the same procedure to access the workarea values
or
i have to pass this workarea values as an import or tables parameter to the function module and then use it
(in first case whether that workarea to make global whether i have to place it in function pool please check this but which is better one)
Thx in advance for any replies.Yes
You would have to pass the values as import parameters to access the global variables of the program otherwise you will not be able to get the values of the global variable from inside the program.
Another solution would be to export to SAP memory but the entire concept of modularization of using the FM would be lost. -
Brefely explain function module
hi
this is ramireddy.hi ram,
Function modules are procedures that are defined in function groups (special ABAP programs with type F) and can be called from any ABAP program. Function groups act as containers for function modules that logically belong together,Function modules allow you to encapsulate and reuse global functions in the R/3 System. They are stored in a central library,Unlike subroutines, you do not define function modules in the source code of your program.
3 types.
1)normal function module
2)remote function module
Difference between FM and subroutines
difference between function module and subroutines
function module vs loacal subroutines
3)update function module
reward points if helpful. -
Using subroutines in Function Module
Hi , experts ,
I want to know how to use performs in function module,
If created subroutine must be used in all FM in Func.Group ?
if you have articles about this or any information , I will be glad .
Please help.
Regards,
Tatiana.If i am not mistaken you want to use forms in function module.
To enable forms in function module you have to follow these steps:
Create a Z include in your function module.
INCLUDE ZTEST_INCLUDE.
Inside this include you need to write your form routine which will be accessable from your function module.
Now you can use perform statement in your funtion module.
Thnaks & Regards,
Lalit Mohan Gupta -
hi,
One of the main difference between Function module and the subroutine is that Function module can return values but subroutine cannot.I could not understand this point.
can anybody tell me how i can see the difference between fm and subroutine with an example?
Thanks in advance.Hi
As mentioned, both forms and FMs are <i>reusable modularization units</i>. To distinguish we generally say that forms are used for <b>internal modularization</b> and FMs are used for <b>external modularization</b>.
To decide on which to implement, consider whether you need the content to be used just for a limited program or wheteher it can be called from many independent programs. For the first purpose it is better to implement a form whereas for the second we implement an FM.
However, ABAP does not isolate the usage context. That is; you can call a form from another program within whose code the form is not actually implemented. However, this requires attention since the form may utilize global variables.
The same issue holds for FMs. FMs are encapsulated in <i>function groups</i> and function groups may have global variables that can be globally used by all FMs inside it.
Regards
*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a> -
Using a function module in a search help.
People,
I make a function module for a search help. Into the function module I call a function 'K_GROUP_SELECT' that show me a screen to make another search but I don't know how can I put the value that this function return me in the field that the user click the button of the search help in my program.
This is the code that I put in the function module.
Thanks!
FUNCTION Z_GROUP_SELECT_ZFINCOKOH1_B.
*"*"Local Interface:
*" TABLES
*" SHLP_TAB TYPE SHLP_DESCT
*" RECORD_TAB STRUCTURE SEAHLPRES
*" CHANGING
*" VALUE(CALLCONTROL) LIKE DDSHF4CTRL STRUCTURE DDSHF4CTRL
*" VALUE(SHLP) TYPE SHLP_DESCR
tables: setheader.
data: setname type setheader-setname.
CONSTANTS:
CLASS TYPE SETCLASS VALUE '0103',
FIELD_NAME TYPE RGSBS-FIELD VALUE '*',
KOKRS TYPE TKA01-KOKRS VALUE 'BPPR',
KTOPL TYPE TKA01-Ktopl VALUE 'CAPI'.
IF callcontrol-step = 'SELECT'.
*PERFORM k_group_select USING: CLASS, FIELD_NAME, KOKRS, KTOPL.
CALL FUNCTION 'K_GROUP_SELECT'
EXPORTING
BUTTONS = 'X'
CLASS = CLASS
CRUSER = '*'
field_name = FIELD_NAME
SEARCHFLD = ' '
SEARCHFLD_INPUT = 'X'
SEARCHFLD_REQUIRED = 'X'
SET = '*'
START_COLUMN = 10
START_ROW = 5
TABLE = 'CCSS'
TYPELIST = 'BS'
UPDUSER = '*'
KOKRS = KOKRS
KTOPL = KTOPL
IMPORTING
SET_NAME = setname
EXCEPTIONS
NO_SET_PICKED = 1
OTHERS = 2
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif.
ENDFUNCTION.Carlos, Please see the following program. It is working well in my system. The only difference is that I've implemented you function module as a subroutine instead of in a FM. You can see that it will return the selected value back to the screen field.
report zrich_0002 .
data: setname type setheader-setname.
parameters: p_val type setheader-setname.
data: dynfields type table of dynpread with header line.
data: return type table of ddshretval with header line.
at selection-screen on value-request for p_val.
perform f4_help.
p_val = setname.
start-of-selection.
* FORM f4_help *
form f4_help.
constants: class type setclass value '0103',
field_name type rgsbs-field value '*',
kokrs type tka01-kokrs value 'BPPR',
ktopl type tka01-ktopl value 'CAPI'.
call function 'K_GROUP_SELECT'
exporting
buttons = 'X'
class = class
cruser = '*'
field_name = field_name
searchfld = ' '
searchfld_input = 'X'
searchfld_required = 'X'
set = '*'
start_column = 10
start_row = 5
table = 'CCSS'
typelist = 'BS'
upduser = '*'
kokrs = kokrs
ktopl = ktopl
importing
set_name = setname
exceptions
no_set_picked = 1
others = 2.
endform.
REgards,
Rich HEilman -
Function Groups and Function Modules
Hi,
Can anyone give me the detail steps for creating Function Group and then from that function group creation of function module with example?
Regards,
ChandruHi,
Function Group creation -
A function group is a program that contains function modules. With each R/3 system, SAP supplies more than 5,000 pre-existing function groups.
In total, they contain more than 30,000 function modules. If the functionality you require is not already covered by these SAP-supplied function modules, you can also create your own function groups and function modules.
We can put all the relevant function modules under one function group and all the global variables can be declared in this FG.
FG Creation:
1) Function group can be created in SE80. There choose the 'Function Group' from the list of objects.
2) Then give a name for ur function group (starts with Y or Z) and press ENTER.
3) The click 'YES' in the create object dialog box and give a short desc. for this FG and save.
Function Module:
A function module is the last of the four main ABAP/4 modularization units. It is very similar to an external subroutine in these ways:
Both exist within an external program.
Both enable parameters to be passed and returned.
Parameters can be passed by value, by value and result, or by reference.
The major differences between function modules and external subroutines are the following:
Function modules have a special screen used for defining parameters-parameters are not defined via ABAP/4 statements.
tables work areas are not shared between the function module and the calling program.
Different syntax is used to call a function module than to call a subroutine.
Leaving a function module is accomplished via the raise statement instead of check, exit, or stop.
A function module name has a practical minimum length of three characters and a maximum length of 30 characters. Customer function modules must begin with Y_ or Z_. The name of each function module is unique within the entire R/3 system.
Defining Data within a Function Module
Data definitions within function modules are similar to those of subroutines.
Within a function module, use the data statement to define local variables that are reinitialized each time the function module is called. Use the statics statement to define local variables that are allocated the first time the function module is called. The value of a static variable is remembered between calls.
Define parameters within the function module interface to create local definitions of variables that are passed into the function module and returned from it (see the next section).
You cannot use the local statement within a function module. Instead, globalized interface parameters serve the same purpose. See the following section on defining global data to learn about local and global interface parameters.
Defining the Function Module Interface
To pass parameters to a function module, you must define a function module interface. The function module interface is the description of the parameters that are passed to and received from the function module. It is also simply known as the interface. In the remainder of this chapter, I will refer to the function module interface simply as the interface.
To define parameters, you must go to one of two parameter definition screens:
1) Import/Export Parameter Interface
2) Table Parameters/Exceptions Interface
Then in the FM interface screen, give the following
1) Import parameters
2) Export parameters
3) Changing parameters
Then give
1) Define internal table parameters
2) Document exceptions
You enter the name of the parameter in the first column and the attributes of the parameter in the remaining columns. Enter one parameter per row.
Import parameters are variables or field strings that contain values passed into the function module from the calling program. These values originate outside of the function module and they are imported into it.
Export parameters are variables or field strings that contain values returned from the function module. These values originate within the function module and they are exported out of it.
Changing parameters are variables or field strings that contain values that are passed into the function module, changed by the code within the function module, and then returned. These values originate outside the function module. They are passed into it, changed, and passed back.
Table parameters are internal tables that are passed to the function module, changed within it, and returned. The internal tables must be defined in the calling program.
An exception is a name for an error that occurs within a function module. Exceptions are described in detail in the following section.
Syntax for the call function Statement
The following is the syntax for the call function statement.
call function 'F'
[exporting p1 = v1 ... ]
[importing p2 = v2 ... ]
[changing p3 = v3 ... ]
[tables p4 = it ... ]
[exceptions x1 = n [others = n]].
where:
F is the function module name.
p1 through p4 are parameter names defined in the function module interface.
v1 through v3 are variable or field string names defined within the calling program.
it is an internal table defined within the calling program.
n is any integer literal; n cannot be a variable.
x1 is an exception name raised within the function module.
The following points apply:
All additions are optional.
call function is a single statement. Do not place periods or commas after parameters or exception names.
The function module name must be coded in uppercase. If it is coded in lowercase, the function will not be found and a short dump will result.
Use the call function statement to transfer control to a function module and specify parameters. Figure 19.9 illustrates how parameters are passed to and received from the function module.
sample FM
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = ' '
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT =
IT_FIELDCAT =
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP = 0
I_HTML_HEIGHT_END = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab =
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Example
1 report ztx1905.
2 parameters: op1 type i default 2, "operand 1
3 op2 type i default 3. "operand 2
4 data rslt type p decimals 2. "result
5
6 call function 'Z_TX_DIV'
7 exporting
8 p1 = op1
9 p2 = op2
10 importing
11 p3 = rslt.
12
13 write: / op1, '/', op2, '=', rslt.
Regards,
Shanthi.P
Reward points if useful ****
Edited by: shanthi ps on Jan 26, 2008 12:03 PM -
Exceptions in Function Modules
Hi
How can I create an Exception in a Function Module and Raise that based on some condition? Plz helpHi Santo,,,,
Look into this link ,, where u will get a clear information on exceptions,,,,,
http://help.sap.com/saphelp_nw70/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm
http://abapprogramming.blogspot.com/2007/06/lesson-24-function-groups-and-function.html
In the function module, you can create your own local types and data objects, and call subroutines or other function modules.
You can make a function module trigger exceptions .
To do this, you must first declare the exceptions in the interface definition, that is, assign each one a different name.
In the source code of your function module, you program the statements that trigger an exception under the required condition. At runtime, the function module is terminated when an exception is triggered.
The changes to exporting and changing parameters are the same as in subroutines. There are two statements that you can use to trigger an exception. In the forms given below, stands for the name of an exception that you declared in the interface. The system reacts differently according to whether or not the exception was listed in the function module call:
RAISE .
If the exception is listed in the calling program, the system returns control to it directly. If the exception is not listed, a runtime error occurs.
MESSAGE () RAISING .
If the exception is listed in the calling program, the statement has the same effect as RAISE . If it is not listed, the system sends message from message class with type , and no runtime error occurs.
Function modules differ from subroutines in that you must assume that they will be used by other programmers. For this reason, you should ensure that you complete the steps listed here.
Documentation (can be translated)
You should document both your parameters and exceptions with short texts (and long texts if necessary) and your entire function module. The system provides a text editor for you to do this, containing predefined sections for Functionality, Example Call, Hints, and Further Information.
Work list
When you change an active function module, it acquires the status active (revised). When you save it, another version is created with the status inactive . When you are working on a function module, you can switch between the inactive version and the last version that you activated. When you activate the inactive version, the previous active version is overwritten.
Function test
Once you have activated your function module, you can test it using the built-in test environment in the Function Builder. If an exception is triggered, the test environment displays it, along with any message that you may have specified for it. You can also switch into the Debugger and the Runtime Analysis tool. You can save test data and compare sets of results.
When you insert a function module call in your program, you should use the Pattern function. Then, you only need to enter the name of the function module (input help is available). The system then inserts the call and the exception handling (MESSAGE statement) into your program.
You assign parameters by name. The formal parameters are always on the left-hand side of the expressions:
Exporting parameters are passed by the program. If a parameter is optional, you do not need to pass it. Default values are displayed if they exist.
Importing parameters are received by the program. All importing parameters are optional.
Changing parameters are both passed and received. You do not have to list optional parameters.
Default values are displayed if they exist.
The system assigns a value to each exception, beginning at one, and continuing to number them sequentially in the order they are declared in the function module definition. You can assign a value to all other exceptions that you have not specifically listed using the special exception OTHERS.
If you list the exceptions and one is triggered in the function module, the corresponding value is placed in the return code field sy-subrc. If you did not list the exception in the function call, a runtime error or a message occurs, depending on the statement you used in the function module to trigger the exception.
When you create a function module, you must assign it to a function group. The function group is the main program in which a function module is embedded.
A function group is a program with type F, and is not executable . The entire function group is loaded in a program the first time that you call a function module that belongs to it.
The system also triggers the LOAD-OF-PROGRAM event for the function group.
The function group remains active in the background until the end of the calling program. It is therefore a suitable means of retaining data objects for the entire duration of a program. All of the function modules in a group can access the group's global data.
Please reward if found helpful,,,,,,,,,,,,,,,,
Thanks And Regards ,,,,
Sreekar.Kadiri. -
A sample coding for fun. module ' MRM_DBTAB_RSEG_READ' using subroutine
i need to have this function module within the subroutine. something like this
perform item_detail using p_belnr p_gjahr changing i_irseg
loop at i_irseg.
write:/ i_irseg-belnr.
endloop.
form item_detail using p_belnr p_gjahr changing i_irseg
CALL FUNCTION 'MRM_DBTAB_RSEG_READ'
EXPORTING
I_BELNR = P_BELNR
I_GJAHR = P_GJAHR
I_BUFFER_ON = X
IMPORTING
TE_RSEG = I_IRSEG
EXCEPTIONS
ENTRY_NOT_FOUND = 1
OTHERS = 2.
this is not correct. Pls do provide the exact coding.
promise to reward points.Sample code.
report zrich_0004 .
type-pools: mrm.
data: i_irseg type mrm_tab_rseg.
data: x_irseg like line of i_irseg.
parameters: p_belnr type rseg-belnr,
p_gjahr type rseg-gjahr.
start-of-selection.
perform item_detail using p_belnr p_gjahr changing i_irseg.
<b> loop at i_irseg into x_irseg.
write:/ x_irseg-belnr.
endloop.</b>
* FORM item_detail *
form item_detail using p_belnr p_gjahr changing i_irseg.
call function 'MRM_DBTAB_RSEG_READ'
exporting
i_belnr = p_belnr
i_gjahr = p_gjahr
* I_BUFFER_ON = X
importing
te_rseg = i_irseg
exceptions
entry_not_found = 1
others = 2.
endform.
Regards,
Rich Heilman -
How to organize function modules & subroutines in a function group?
Hi,
There are several function modules and subroutines in a function group. And the subroutines will be called by severel modules.
Originally:
1. I put subroutine forms in an Include.
2. and in the function modules which will use the forms, I include the Include before the function definition.
3. While when activating the functin modules, it's reported that the forms had already been defined. Only if one function module includes the Include, it's OK.
How should the forms and function modules be organized?
Thanks!
SayidHi Atish
Yes, you are right.
It works.
Thank you.
Regards,
Sayid -
What is the difference between subroutine and function module?
What is the difference between subroutine and function module?
Hi,
they can both return values.
FMs are mainly used when a routine is to be performed by many programs.
Subroutines (forms) are generally only executed within one program.
You can perform routines from other programs, but it's not often done.
both forms and FMs are reusable modularization units.
To distinguish we generally say that forms are used for internal modularization and
FMs are used for external modularization.
To decide on which to implement, consider whether you need the content to be used just for a limited program
or wheteher it can be called from many independent programs.
For the first purpose it is better to implement a form whereas for the second we implement an FM.
However, ABAP does not isolate the usage context.
That is; you can call a form from another program within whose code the form is not actually implemented.
However, this requires attention since the form may utilize global variables.
The same issue holds for FMs.
FMs are encapsulated in function groups and function groups may have global variables that can be globally
used by all FMs inside it.
Thanks,
Reward If Helpful. -
Function Module IMPORT structures not recognized in form subroutines
Hello everyone,
Did some searching on SDN and didn't find the answer, so I apologize if this has been covered before.
Just finished my first Function Module. It's a remote-enabled (RFC) function that will be called by XI to do some processing. I have two components declared on the IMPORT tab, which we'll call "A" and "B". Both "A" and "B" are defined with a user type, each of which is a simple structure of 4-5 fields each. My Function Module also has two tables, and these are defined on the TABLES tab.
Here's my problem: When I do a syntax check, I get an error telling me that "A" and "B" are unknown. However, I only get this error where I reference "A" or "B" in the FORM subroutines I have declared at the end of my function.
I have my other data declarations defined globally in the "LZ...TOP" Include for my Function Module, so those don't pose a problem. But these are my Function Module parameters, so I can't go "declare" those as I already have them defined on the appropriate tabs.
Is there a way for me to get around this error and have them recognized globally, or do I have to resort to moving the values to some globally-declared "hold" field? I'm hesitant to have to add them as parameters passed into the FORM routines because I pretty much reference each of the fields within the structures for "A" and "B".
Thanks everyone. Points definitely awarded for helpful answers.Dave,
The parameters are visible only in the main program of the function module. So, if the subroutines are directly in the main function, they you should not have a issue. But if you subroutines in an include and you are calling them in the main function, then the paramters are not visible in the subroutines. In that case you will have to hold the values in a globally declared tables.
Or you will have to pass them as parameters to Sub routines as well.
Regards,
Ravi
note : please mark the helpful answers
Message was edited by: Ravikumar Allampallam -
Macros, Function modules and subroutines
Hi Experts,
In performance wise which one is best macro or subroutine or Function module?
Thanks.Hi Nandini,
Each and every one has its importance in certain situations..
Macros
If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.
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.
Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.
Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.
Best regards,
raam
Maybe you are looking for
-
Hello. On my MacBook Air late 2013 model I am having a problem with Microsoft office word for Mac where the window for the document becomes all gray and I can not see anything that I have typed or any menus for it and also windows will sometimes diss
-
How to "completely" reinstall FF, and recover ONLY cookies & Bookmarks?
I installed FF 3.6.10, and made the mistake of importing IE8 Settings (hooks...!), along with Bookmarks & cookies! FF has been my primary browser for quite awhile, and I have added Many new bookmarks/cookies. Now I want to "completely" uninstall 3.6.
-
About bapi with help of example
about bapi with help of example plz dont give links.
-
Can some one post any good books or links on oracle content management to maintain images/xml files, etc.,Thanks
-
I really need help i am so ****** :(
Well so my sister yesterday updated her ipod touch to version 4.0 and everything went perfectly , I tried to do it after her but i had an error ( i will show later ) Then i tried today still no luck same error and that happened 5 times already and st