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,
Chandru

Hi,
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

Similar Messages

  • Function Group and Module Transport

    Hi All,
    I have created a new Function group and is part of transport request. Created new function modules and assigned to the same function group. When i see object list in SE09 for the transport request i see only function group, all the FM are part of same transportable package of Function group. Do i need to assign them manually in object list through SE09 as pseudo changes to FM is not capturing in the request.
    Thanks in advance.
    Regards
    Kunal.

    There is no need to manually assign fm to fg. If you transport the fg , objects under the fg get transported automatically.
    Next time if you changing only function module then your se09 entry will be
    LIMU              FUNC

  • What is the difference between function groups and Object Orientation

    Hello all
    I have read about this on the help.sap.com site, I still do not understand it completely, can some one explain me with  a simple example please ? (Not the increment counter example please !).
    Thanks a ton.
    Rgds
    Sameer

    Hello Sameer
    When you call a module of a function group for the first time in your program then the entire function group is loaded. However, this can happen only once within your report and all global variables within the function group will have the same values all the time (except they are manipulated via fm's).
    In contrast, you can create as many instances of the same class as you want and all of them can have different global attributes. And all these instances are independent of each other.
    On the other hand, if fm_A changes global attributes of the function group and fm_B reads these attributes then fm_B read the changed values.
    Or in other words:
    Function Group = can be instantiated only ONCE
    Class = can be instantiated unlimited
    Regards
      Uwe

  • Export Function Group or Funtion Module

    Dear all,
      I'm new in ABAP development.  I had a set of function module inside the same function group and i want to test it in another sandbox system.  Since, there is no transport routing between the development and sandbox server.  Is there any faster way to export the whole function group content to another system??
    Regards,
    Kit

    Hi Chun..
    you can do One thing to achieve this :
    In the Dev system :
    Tcode SE37: Open the Source code of The Function Group.
    Copy the Souce code of the Main program and also Each include in this Function group to Notepad files.
    Note: Function modules are stored as includes in a Function group.
    In the Sandbox system:
    Tcode SE37: Create a  function Group with the Same name.
    Copy all the includes and source code in this system.
    Activate them.
    <b>reward if Helpful.</b>

  • Function Group and Subroutines

    Hi all,
    I have two Function Groups.
    I have a subroutine defined in one Function Group and want to use same subroutine in another Function Group.
    Is there any way to do it, <u><b>without redefining same Subroutine in another Function Group?</b></u>

    Hi,
        either define subroutines in include
        and inlude in function group
         include ztest.
          perform abc .
          perfrom add.
    Function group ZFG
         include ztest.
    Function group ZFG1
         include ztest.
    <b>    or</b>   
    perform test(prog1).
    Regards
    amole

  • Are Classes better than Function groups and Modules

    Hi,
    Are classes better than Function groups? For example if you want to execute something is back ground or use parallel processing you can't do it using classes. Even inside classes most of the places we use Function modules.
    Then how classes are beneficial?
    Regards,
    Deepak Bhalla

    Yes they are compared in the sense that the class and function group are the containers, and the methods and function modules are the interfaces in which you interact with the encapsulated data. 
    Again if you are developing an application in which you are not forced to push the processing to differenet work processes,  then using classes/methods is preferrable. The reason I say this, is because anything coming from SAP will most likely be implemented as a class as opposed to a function group.  This is not to say that SAP will not create new function modules, because of course there still is a use for them.
    Regards,
    Rich Heilman

  • Function group and transaction hav same name.

    Is  it   possible to re-name a function group name which is accidently nameed same as a transaction code.
    Thanks in advance,
    Rupesh.

    You can't rename a function group, but you can copy it. Go to SE80, put in your function group, right click on the function group name and click COPY. You can now choose a new name for the function group. After confirming you'll get another popup, where you can select the function modules you want to copy. Don't forget to rename them as well.
    Hope that helps,
    Michael

  • Changing function group of function module

    Hi
    I assigned my function module to function group of different person, which has been transported to quality server. Now whenever I make some changes in my function module, it creates problem to his application.
    As it has been released, system is not allowing me to change the function group of my function module. is there any way out so that I can assign my function module to my own function group.
    Regards
    Vishal Kapoor

    Vishal,
    if your application is different from the other users application, then you better remove it from the Function group. Create new one and make a copy of it. and then Proceed. Make sure you activated the existing fucntion group. Activate the main program properly.
    Regards
    Vijay

  • Can we move SAP standard Function Group and Table defintion to BW

    Dear Forum,
    We are in a ‘pilot’ process of migrating SAP R/3 Custom development objects to our BW client and we have a few questions that we would like to know if possible.
    We are currently in the ‘To Be’ Blueprint Phase of migrating SAP 45B to ERP2005 as a Ramp-Up customer and we need to determine as soon as possible the feasibility of moving one particular Custom application
    from our SAP R/3 environment to BW.  This application primarily performs computational processing and does reporting of the results at the
    conclusion
    We have selected one Custom R/3 ABAP program to do a ‘pilot’ to determine the feasibility of migrating it to the BW platform. This Custom program utilizes objects from standard SAP Function Groups which are non existent in BW.  In this particular case Function groups KMS0
    (Cost Center Selection) and KAB2 (CO Reporting: General).
    Questions:
    Are we allowed to move these 2 standard SAP Function Groups to BW ? Would it alter the BW environment integrity as intended and designed by SAP?
    If we move the Function Group KMS0 and KAB2 will
    SAP support our BW environment if we decide to move them?
    Would it be considered a ‘SAP Best Practice’ to move standard SAP R/3
    objects to BW?
    Thank you in advance for your help,
    Paulo Silveira
    [email protected]

    Hi Paulo and welcome on board !
    Please don't post twice the same question...(look in the other one...)
    ..and don't forget to rewards the answers...it's THE way to say thanks here !
    Anyway, I'd suggest to close this thread to avoid to receive answers in both threads...
    Cheers,
    Roberto

  • About function groups and includes?

    I ahve created 1 function groupa nd module
    then id int keep any thing in function module like tables,impot..exportsourcecode
    i dint fill ..when im checking for errors its showing nothing but when activating its saying "report stmt is missing"
    y this happening?
    about includes..
    I wanted to include one in other include
    when im im wriitng select stmt in second include the error is
    "stmt is not accessble"
    pls clarify my doubts as soon as possible

    Hi,
    When ever you execute or check it will give "report stmt is missing" so you need to use this includes in report program only.
    For include in which select is there also need to keep in report program.
    You cannot execute include/module pool pragram
    regards,
    Sreevani

  • 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.

  • Transporting Function Module & Function group

    Hello All,
    I want some clarification in transporting a FM, FG, Extract Structure.
    First I collected Function Group in a Transport Request (R3TRFUGR********) and collected Function Module in the same request and also the extract structure.
    This Function Group have only one Function Module and 4 Includes (LRSALK01, LRSAXD01, LZ_BI_DS_DATATOP, LZ_BI_DS_DATAUXX, RSAUMAC).
    Do I need to collect these includes separately in the same request or is it enough if i collect only function group and function module and move the request.
    Please let me know.
    Thank you.

    Hi Saptrain,
    the best is always to let the system handle it: As soon as you assign an object (function group, function module, include or whatever) to a package, it will ask for a transport. Create the transport and the transport management system will include in the transport what has to be transported.
    As far as I know (but I never have the question), a function group (R3TR FUGR) will transport everything that is in the function group: All functions, all modules, all includes, screens, texts, status and...I think even test cases
    You will find FUGR in the transport after creating the function group.
    If you change something after releasing the transport, it will transport only the changed objects (i.e. includes)
    Regards,
    Clemens

  • Function group / Function modules approvals

    Hi,
    We have couple of function modules related to RFC / BAPI in QA we need to give approvals before we move them to production.
    What precautions do we need to take before approving?
    How to segregate Function groups / Function modules?
    Thanks,
    Ram

    Well you should test function groups and function module coding as per your normal procedures. They are widely used.
    Whether they are accessible depends on your roles, right?
    Which release are you on?
    Prior release 7.01 you can only control at function group level with object S_RFC.
    Subsequently you can use RFC_TYPE 'FUNC' to control at module name level if FUGR fails.
    Luckily, this check is central and to my knowledge only one developer ever hardcoded it for list outputs, so you should be okay to convert for manual authorizations.
    For standard ones from the menu, you will need to deactivate S_RFC (there is not option to un-merge, unfortunately..........). Easiest is to get the names from the menu and paste them into the manual authorization, or use a Su24 "dummy" for the role or scenario.
    Dummy's are usefull workarounds and protect you against upgrades as well... (when SAP adds a load of stuff because GRC needs it, and then toasts your roles, sets active auths to inactive and adds new ones which are merged automatically...)
    Cheers,
    Julius

  • Transport Function Group

    Hi,
    I created a new function group and assigned a function module to it. I transported the function group and function module (available in 1 request) from Dev to QA with no warnings/errors. In QA, i went to SE37, typed my FM name and tried to goto function group using the goto menu option, it says function group does not exist. It prompts for creating a function group.
    In dev, when i tried to save the function group to a request, this entrry was saved in the request/task.
    Function Group Texts -  LIMU  -  FUGT - ZSLS_FGRP
    I don't have any specific entry for function group in the request. Is there a way to capture function group entry in the request.
    Thanks

    Hi,
    When u create a new function group and assign the function module for the first time, you can see only the function group name in Transport Request but the function module name will not get displayed.
    Check the entries of object in to ensure the function group has been assigned to the request in Transport Request.
    If you are creating other Function modules after first transport you can find the function modules names also in transport request.
    Cheers,
    Rema.

  • Function pool relation to Function group

    Hi friends,
    Could you please clarify for me how the 2 are related? I can understand function group but not sure what is function pool and how it relates to function group and function module.
    I have searched the online help but its not clear to me. Please give me simpler explanations.
    Thanks
    Sri

    Hi Sri - When you interact with a function group you are using an interface which uses the ABAP code contained in a function pool. A function group will always be in only one function pool and a function pool will always have only one function group. The function pool is the parent program of the function group. Each function module is an ABAP include in the parent program. Likewise when you interact with the function module you are using an interface that uses the ABAP include.
    When you debug into a function module you will always see the main program as the function pool and the source code is the ABAP include of the function module because that is the code that is being executed. Usually SAPL prefixes the function group to create the name of the function pool.
    Hope this helps.
    Andy

Maybe you are looking for

  • How do I turn on closed caption on my apple tv for netflix

    How do I turn on closed caption on my apple tv for netflx? I was able before I updated 2 days ago all I had to do was press the silver button in the middle of the circle with the arrows and it will bring me to audio/closed caption menu now I get noti

  • Marketing attribute not assignable with language PL

    Hi *, I have detected a strange behaviour when maintaining "some/special" marketing attributes for BP in logon language PL. The affected attributes are configured as follows. Format                   No. Chars      Dec.Places      Meas. unit      Sin

  • Selected Items

    I tried using UIManager.put("Menu.highlight", Color.ORANGE);but the color of my JMenu when selected is still purple. What should I do??? Thanks!!!

  • How to apply metadata to sharepoint site collection

    Hello, We have almost 1000 teamsite and we are working to arrange those according to department and site admins. So requirement is Let say if the HR department has 10 team sites, those 10 team site's department should be marked as "HR". Now how can w

  • Round off to two decimal places

    hi i have a filed in it values are there i want to round off to two decimal places which is the function module for it please suggest regards Arora