OSSincorp - Quest4SAP Market
Innovation and Knowledge
SAP Implementors
Total Tips
Total Articles
Total Members
Total Reads (since 2002)
Total Visits

SEP 2009 Launch

( NEWS )

More Content
Jobs & Resourcing
Prog Jul 15/2001 Overview of Functions
Preamble: SAP has built the core of their system through the use of Functions. BAPIs and Objects follow a similar nomenclature. This article addresses some concepts and key elements of Functions. 
Discussed will be:

Note 1: The Four Components of Functions
Note 2: The creation/Editing of Functions through the Work Bench 
Note 3: Interface Tabs of the Function
Note 4: Details surrounding Import and Export Parameters
Note 5: An explanation of Data Scope and Data Visibility
Note 6: An overview on Function Types
Note 7: An explanation of Exception Handling
Note 8: A Watch Out For
Note 9: Search Trick
Note 1

The Four Components of Functions





Conceptually there are four components to an SAP Function. 

Four Components
1. One Function Group that contains one or more Function Modules.
2. Global Data defines the Table and Data that has the scope across all the Function modules and FORMs within the Main Program.



Function Modules that contain the source code. Usually the code contains conditional branching with Perform Calls to the FORM subroutines contained in the Main Program.
4. The Main Program that contains all the Form subroutines. These FORMs have the scope visibility to all Function Modules
Note 2

Creation and Editing of Functions 



Enter transaction /nSE80 in the command field to get to the Object Navigator. By double clicking on ZSAP as it does not exist results in the dialog Create Object popping up.
SE37 Or enter transaction /nSE37 to get to the Function Builder and select the menu path from Goto, choose "Function groups" and then "Create"


To create a Function Module, click the Right Mouse Button with the Function Module Line highlighted. The Create dialog pops up and asks for details.
Note 3

Interface Tabs of the Function




The TAB screen shows Attributes, Interface In/Out settings, Exception Handling and the Source Code for the Function Module created.

Normal function module:
- The function we have created here is set with default Processing Types , "Normal function module" and to Start immediately. Two other more advanced Function types are explained for now as:

Remote-enabled module:- Allow logging in to an external system. To run this function requires a Destination Parameter to be supplied and the Login in details have to be maintained as a separate configuration step.

Update module:- If the function module is involved with Table Updates, then this option will identify this Function Module to be considered in the LUW (Logical Unit of Work) from the calling program.

Note 4

Import and Export Parameters



Note: One concept to realize involves the matching of Import and Export Parameters between the calling ABAP program and the Function Module. The ABAP call exports data into the Function and the Function receives the data from the ABAP. Further the Function exports the results out to the ABAP which is received under the Importing.

TIP: When adding a Function to your ABAP use the Pattern reference.
  EDIT -> PATTERN -> radio button the Function module
Note 5

Data Scope and Data Visibility



Globalize Parameters: The point to be discussed here addresses Scope and Visibility of the Data. From "Note 3" above you can see the Global check box is not checked. This is the default taken for all new Function Modules. The point around this is Import and Export parameters are not visible to ABAP FORM definitions seen in the MAIN program. When do you know you have this problem? If the syntax checker Fails to resolve the parameter called and gives the message Parameter not Found. 


There are two solutions to this. One way the Parameters could be visible in this circumstance is by passing them via the Perform Call.


The second way is to set the "Globalize Parameters". The outcome of this is the Function Import and Export Parameters now have the Scope of Visibility across the code segments making up  the Function.

Now the call could be   PERFORM DOSOMETHING.

Unless you have a reason to hide the Scope of the Parameters then set the Globalize Parameters on as it makes for cleaner code.

Note 6

Overview on Function Types



Explanation:  There are four entries possible "Type of Parameter" when adding Import or Export Parameters. 

They are,





Will accept any Data Type and has no validation type checking
LIKE:-  Is in reference to a Data Dictionary field, a Table or Structure
TYPE:-  Allows reference to a Data Dictionary field, a Table or Structure      and an explicit Table Type  declaration 
TYPE REF TO:-  allows reference to Classes


 Using TYPE references allow the usage of compound               structures. SAP refers to these as Deep Structures. 
Note 7




Exception Handling: When a function exits from a Raised Exception a Number value goes back to the Calling Program. As seen above in Note 3 the Return Value will be 1,2 or 3. This becomes the SY-SUBRC value.

Raising Exceptions: The code here shows how exceptions are managed with the Operator "RAISE". The parameter values available to the "RAISE" call are given against the "Exceptions" Tab seen below. Once an Exception is triggered the code Flow becomes, "Stop, Set all EXPORT and TABLE parameters in the Function Interface to Initial values, Exit and return a Number" back to the Calling Program as a System Exception.

Note 8





Keep in mind that any FORM reference in the MAIN Program can be called from all the Function Modules. Therefore if you are fixing the call "Perform Parse_BKPF_data" in the Function Module "Z_TEST_CALL_MODULE1".

Any code changes you put in will also affect module "Z_TEST_CALC_MODULE2" should this module contain the same Perform call.

Note 9

Search Trick





Say you want to find the Functions that exist say against a "Z" Table.

Why, to avoid reinventing some code. Go to transaction SE11, enter the Table, Display, then do a "where used" search. The resulting hit list could contain program references that contain SAPLxxxx.

You have found the Functions. Then you can go to transaction SE84 and select Program > Function Modules and put in xxxx into the Function Group, hit F8 and see the resulting Hit List which contains the list of all Function Modules
Copyright: Osberg Software Services Inc.
WEB: www.ossincorp.com
Email: k_osberg@yahoo.com

    copyright: Quest4 Market Strategies Inc, July 2009