Function MIdule
Function MIdule
com/in/mickaelquesnot/
1. In the Object Navigator (transaction SE80), choose Function Group as the object type.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 1 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
2. Enter the name of the new function group and choose Enter.
If the object does not exist in the system, the Create Object dialog box appears.
Note
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 2 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Function group names can be up to 26 alphanumeric characters long. You should observe the
naming conventions for the first character: A to X for SAP developments, Y and Z for customers.
3. Choose Yes.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 3 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
4. In the Short Text field, enter a description for the new function group and choose Save.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 4 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
5. In the Package field, enter a name of a package or choose the Local Object pushbutton to save the
Note
When you create a new function group, the system automatically creates a main program with two
includes. The name of the main program is assigned by the system and consists of the
prefix SAPL followed by the function group name. For example, the main program for the function
group SXXX is called SAPLSXXX. The names of the include files begin with L followed by the
name of the function group, and end in -UXX (or -TOP for the TOP include). The name of the main
program can also be preceded by a namespace. The TOP include contains global data
declarations that are used by all function modules in the function group. The other include file
within the main program is used to hold the function modules within the group.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 5 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 6 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
You use this procedure to create function modules in the Function Builder.
1. In the Object Navigator (transaction SE80), choose Function Group as the object type.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 7 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 8 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 9 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
3. In the context menu of the function group, choose Create → Function Module.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 10 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
4. In the Function Module field, enter a name for the new function module and in the Short Text field,
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 11 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Attribute Description
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 12 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Attribute Description
Process Specifies the function type. Choose Normal unless your function is to be run on remote systems or during
data
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 13 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
6. Choose Save.
The system automatically creates an include file for your function module. For example, the include file for
the first function module in the function group FGRP is called LFGRPU01. The next function modules have
For more information about include programs, see Understanding Function Module Code.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 14 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
You use this procedure to set parameters and exceptions for your function module. They constitute its
interface. The Function Builder has a tab page for each of the following interface components: tables,
Procedure
1. In the Object Navigator (transaction SE80), open the function module you want to edit.
2. Enter the required information for each of the parameters (import, changing, export, or table).
Field Description
Name
Type spec. A database field, component of an ABAP Dictionary structure, or an entire ABAP Dictionary structure.
This is the same as the ABAP Dictionary field name in the Reference field/reference structure column.
Use this field to create a field based on an ABAP Dictionary field. You should always use a reference
structure if the data in the parameter must have the same structure as the reference field (for example,
Associated You can enter any system type, either generic or fully typed. For more information, see the Data Types
Default Default value of the parameter. Applies to import and changing parameters only. The system transfers
this value to the function module if the caller sets its own value for that parameter.
Reference The parameter reference. Specify this if you want the parameter to be called by reference instead of by
value. When a parameter is called by reference, the system points to the original parameter without
making a copy of it. The function module works with and, if necessary, alters the original parameter and
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 15 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 16 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 17 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
The exceptions screen only allows you to enter a text with which the exception can be triggered in
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 18 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
On the Documentation screen, you can enter short descriptions of the parameters and exceptions
or write full documentation of the entire function module.For more information, see Documenting
Source code :
FUNCTION Z_BAPI_TWLAD_ADRC_UPDATE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(PV_WERKS) TYPE ZBAPITWLAD-WERKS OPTIONAL
*" VALUE(PV_LGORT) TYPE ZBAPITWLAD-LGORT OPTIONAL
*" VALUE(PV_LFDNR) TYPE ZBAPITWLAD-LFDNR DEFAULT '10'
*" VALUE(PV_TITLE) TYPE ZBAPITWLAD-TITLE OPTIONAL
*" VALUE(PV_NAME1) TYPE ZBAPITWLAD-NAME1 OPTIONAL
*" VALUE(PV_SORT1) TYPE ZBAPITWLAD-SORT1 OPTIONAL
*" VALUE(PV_SORT2) TYPE ZBAPITWLAD-SORT2 OPTIONAL
*" VALUE(PV_STREET) TYPE ZBAPITWLAD-STREET OPTIONAL
*" VALUE(PV_HOUSE_NUM1) TYPE ZBAPITWLAD-HOUSE_NUM1 OPTIONAL
*" VALUE(PV_POST_CODE1) TYPE ZBAPITWLAD-POST_CODE1 OPTIONAL
*" VALUE(PV_CITY1) TYPE ZBAPITWLAD-CITY1 OPTIONAL
*" VALUE(PV_COUNTRY) TYPE ZBAPITWLAD-COUNTRY OPTIONAL
*" VALUE(PV_REGION) TYPE ZBAPITWLAD-REGION OPTIONAL
*" VALUE(PV_TIME_ZONE) TYPE ZBAPITWLAD-TIME_ZONE OPTIONAL
*" VALUE(PV_LANGU_CREA) TYPE ZBAPITWLAD-LANGU_CREA OPTIONAL
*" TABLES
*" ZBAPITWLAD STRUCTURE ZBAPITWLAD
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 19 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
CLEAR GV_ADRNR.
CALL FUNCTION 'MM_DELIVERY_ADDRESS_PROPOSE'
EXPORTING
I_WERKS = PV_WERKS
I_LGORT = PV_LGORT
IMPORTING
E_ADRNR = GV_ADRNR.
IF SY-SUBRC = 0.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 20 | P a g e
https://www.linkedin.com/in/mickaelquesnot/
ENDIF.
IF NOT PV_COUNTRY IS INITIAL.
GS_ADRC-COUNTRY = PV_COUNTRY.
ENDIF.
IF NOT PV_REGION IS INITIAL.
GS_ADRC-REGION = PV_REGION .
ENDIF.
IF NOT PV_TIME_ZONE IS INITIAL.
GS_ADRC-TIME_ZONE = PV_TIME_ZONE.
ENDIF.
IF NOT PV_LANGU_CREA IS INITIAL.
GS_ADRC-LANGU_CREA = PV_LANGU_CREA .
ENDIF.
*update ADRC
IF NOT GS_ADRC IS INITIAL.
UPDATE ADRC FROM GS_ADRC.
IF SY-SUBRC NE 0.
* abort: error during update
MESSAGE A017(KC) WITH 'UPDATE ADRC' SY-SUBRC INTO ZRETURN-
MESSAGE.
APPEND ZRETURN.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.
Mickaël QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/ 21 | P a g e