0% found this document useful (0 votes)
11 views21 pages

Function MIdule

The document provides a step-by-step guide on creating function groups and function modules in SAP S/4HANA using the Function Builder. It details the procedures for defining parameters, exceptions, and documentation for function modules, along with example code for a specific function. Key points include naming conventions, the structure of generated programs, and the importance of parameter specifications.

Uploaded by

fateme.soroush92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views21 pages

Function MIdule

The document provides a step-by-step guide on creating function groups and function modules in SAP S/4HANA using the Function Builder. It details the procedures for defining parameters, exceptions, and documentation for function modules, along with example code for a specific function. Key points include naming conventions, the structure of generated programs, and the importance of parameter specifications.

Uploaded by

fateme.soroush92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

https://www.linkedin.

com/in/mickaelquesnot/

Creating a Function Module in SAP

Creating a Function Group in SAP


S/4HANA
You use this procedure to create function groups 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/ 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.

The Create Function Group screen appears.

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.

The Create Object Directory Entry screen appears.

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

new function group locally.

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/

2. Enter the name of the function group and choose Enter.

The tree structure of the function group appears.

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/

The Create Function Module screen appears.

4. In the Function Module field, enter a name for the new function module and in the Short Text field,

enter a description for the new function group.

Mickaël QUESNOT ©

https://www.linkedin.com/in/mickaelquesnot/ 11 | P a g e
https://www.linkedin.com/in/mickaelquesnot/

5. Specify the following attributes

Attribute Description

Short text Describes the function module.

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

type update tasks.

General General administration information.

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

include files called LFGRPU02, LFGRPU03, LFGRPU04, and so on.

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/

Specifying Parameters and


Exceptions
Use

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,

exceptions, import, export, and changing parameters.

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

Parameter Name of the parameter for identification purposes.

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,

when you want to add new entries to the database).

Associated You can enter any system type, either generic or fully typed. For more information, see the Data Types

Type section of the ABAP User Guide.

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

not a copy. Table parameters are always passed by reference.

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/

3. Enter the exceptions.

The exceptions screen only allows you to enter a text with which the exception can be triggered in

the function module.

4. Document the interface on this screen.

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

and Releasing Function Modules

5. Save your entries.

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/

*" ZRETURN STRUCTURE BAPIRET2


*"----------------------------------------------------------------------

DATA GV_ADRNR TYPE TWLAD-ADRNR.


DATA GS_ADRC TYPE ADRC.

*Determination of Address from Plant and Storage Location

CLEAR GV_ADRNR.
CALL FUNCTION 'MM_DELIVERY_ADDRESS_PROPOSE'
EXPORTING
I_WERKS = PV_WERKS
I_LGORT = PV_LGORT
IMPORTING
E_ADRNR = GV_ADRNR.

IF NOT GV_ADRNR IS INITIAL.

*Reads from DB-table adrc


CALL FUNCTION 'RTP_US_DB_ADRC_READ'
EXPORTING
I_ADDRESS_NUMBER = GV_ADRNR
* I_NATION = ' '
* I_READ_DB=
IMPORTING
E_ADRC = GS_ADRC
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.

IF SY-SUBRC = 0.

IF NOT PV_TITLE IS INITIAL.


GS_ADRC-TITLE = PV_TITLE.
ENDIF.
IF NOT PV_NAME1 IS INITIAL.
GS_ADRC-NAME1 = PV_NAME1.
ENDIF.
IF NOT PV_SORT1 IS INITIAL.
GS_ADRC-SORT1 = PV_SORT1.
ENDIF.
IF NOT PV_SORT2 IS INITIAL.
GS_ADRC-SORT2 = PV_SORT2.
ENDIF.
IF NOT PV_STREET IS INITIAL.
GS_ADRC-STREET = PV_STREET .
ENDIF.
IF NOT PV_HOUSE_NUM1 IS INITIAL.
GS_ADRC-HOUSE_NUM1 = PV_HOUSE_NUM1 .
ENDIF.
IF NOT PV_POST_CODE1 IS INITIAL.
GS_ADRC-POST_CODE1 = PV_POST_CODE1 .
ENDIF.
IF NOT PV_CITY1 IS INITIAL.
GS_ADRC-CITY1 = PV_CITY1.

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

You might also like