You are on page 1of 25

RAJESH

FUNTION MODULE

FUNCTION MODULE
In order to create a function module go to T-CODE SE37. In order to
create a function module a function group is necessary. Function group
is just act as a folder to store function modules.
STEPS:
-> Go to GOTO menu -> Function Group -> Create Group

-> Give function group name and description. Function group name is
starts with either Z or Y, and then click on SAVE.

7/26/2015

RAJESH

FUNTION MODULE

-> After saving your FUNCTION GROUP create FUNCTION MODULE.


This is also start with either Z or Y and click on CREATE.

7/26/2015

RAJESH

FUNTION MODULE

-> Then give Function group, Short text and click on SAVE.

-> Now
there.
-

it shows the following screen. There are mainly 7 tabs are


ATTRIBUTE
IMPORT
EXPORT
CHANGING
TABLES
EXCEPTIONS
SOURCE CODE
Attribute contains the function group name and the
package name under which we are saved.
Import tab contains all the input fields.
Export tab contains all output fields.
Tables tab contains all the information regarding tables.
Source code contains the code for which we are
generating the output.

Let see the example for getting values from parameters. So in order
to get the values from a parameters declare the input values in the
import tab, output fields in export tab and then write the code in
source code tab like the following.
3

7/26/2015

RAJESH

FUNTION MODULE

IMPORT
A
B

TYPE
TYPE

I
I

EXPORT
C

TYPE

SOURCE CODE
C

B.

7/26/2015

RAJESH

FUNTION MODULE

7/26/2015

RAJESH

FUNTION MODULE

-> SAVE, CHECK and ACTIVATE. Then click on TEXT/EXECUTE.


-> Give values for the parameters A and B and again click in EXECUTE.

****This is the process of retrieving the values from parameters****

7/26/2015

RAJESH

FUNTION MODULE

%% Now see hoe to retrieve the values from a tables. %%


-> In order to retrieve the values from tables we must declare internal
table. What is INTERNAL TABLE?
INTERNAL TABLES are nothing but a temporary storage area.
It is just like table, but it contains the data at the time of execution
only. Actually we didnt get the values directly from the tables, views,
structures etc. So in order to retrieve the values we can go for creating
INTERNAL TABLES. We can create the INTERNAL TABLES in 2 ways.
1. With header line
2. Without header line
Now see the declaration of with header line and without header line.

1. WITH HEADER LINE


DATA : ITAB LIKE VBAK OCCURS 0 WITH HEADER LINE.
(That means in this case it takes all the fields from VBAK table
and stored in internal table ITAB)
2. WITHOUT HEADER LINE
DATA : BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
ERDAT LIKE VBAK-ERDAT,
NETWR LIKE VBAK-NETWR,
WEARK LIKE VBAK-WEARK,
END OF ITAB.
(In this case we can select the specified number of fields from
VBAK and stored in internal table ITAB)
-> Now declare internal table in Tables tab and write the code in
source code tab.
TABLES
ITAB LIKE VBAK
SOURCE CODE
SELECT * FROM VBAK INTO TABLE ITAB.
7

7/26/2015

RAJESH

FUNTION MODULE

7/26/2015

RAJESH

FUNTION MODULE

-> SAVE, CHECK, ACTIVATE and click on EXECUTE. Before executing


the internal table contains 0 entries and then click on execute. It
shows all the records from VBAK table into internal table.

7/26/2015

RAJESH

FUNTION MODULE
FUNTION MODULE RELATED TO BW

In order to create function module, which is related to BW, it takes lot


of steps. See the steps below.
1. First of all decide from table we want extract the data using
function module.
2. Go to SE11 and open that table. For Ex: select DATABASE TABLE
and give table name as VBAK and click on DISPLAY.
3. Open another screen for SE11 and select DATA TYPE, which is
starting with either Z or Y. Then click on CREATE tab. Select
STRUCTURE and click on continue.
4. Copy some fields from VBAK table and paste in newly created
STRUCTURE along with the DATA ELEMENT.
5. SAVE, CHECK and ACTIVATE your newly created STRUCTURE.
6. Then again open SE11 screen and give DATABASE TABLE name
as ROOSOURCE (it contains all the datasource) and click on
DISPLAY. Click on CONTENTS, give OLTP name as
2LIS_01_S260, click on EXECUTE, double click on your
datasource and copy EXTROCTER name and paste in SE37
screen and click on DISPLAY.
7. Open another screen for SE37, then create FUNCTION GROUP.
GOTO menu bar -> FUNCTION GROUP -> CREATE -> Give
function group name and description.
8. Again go to created function group as GOTO menu bar ->
FUNCTION GROUP -> CHANGE -> give function group name and
click on continue -> click in MAIN PROGRAM -> double click on
INCLUDE and write declaration here as follows.
TYPE-POOLS : SRSC, SBIWA.

9. After creating function group, create FUNCTION MODULE. Give


function module name and click on CREATE.
10.
Give function group name, short text and click on SAVE.
11.
Copy all the fields from the EXTRACTOR, which open in
previous screen into this function module, which we are creating.
12.
IMPORT -> IMPORT
TABLES -> TABLES
13.
Go to TABLES tab and declare as follows and write the
code in source code tab.

10
7/26/2015

RAJESH

FUNTION MODULE

TABLES
E_T_DATA LIKE ZSTRUCTURE (Structure name)
SOURCE CODE
SELECT VBELN ERDAT NETWR WEARK FROM VBAK INTO
TABLE E_T_DATA.

14.
SAVE, CHECK, ACTIVATE and EXECUTE.
15.
Go to RSO2 and give this FUNCTION MODULE name along
with the structure.

11
7/26/2015

RAJESH

12
7/26/2015

FUNTION MODULE

RAJESH

13
7/26/2015

FUNTION MODULE

RAJESH

14
7/26/2015

FUNTION MODULE

RAJESH

15
7/26/2015

FUNTION MODULE

RAJESH

16
7/26/2015

FUNTION MODULE

RAJESH

17
7/26/2015

FUNTION MODULE

RAJESH

18
7/26/2015

FUNTION MODULE

RAJESH

19
7/26/2015

FUNTION MODULE

RAJESH

20
7/26/2015

FUNTION MODULE

RAJESH

21
7/26/2015

FUNTION MODULE

RAJESH

22
7/26/2015

FUNTION MODULE

RAJESH

23
7/26/2015

FUNTION MODULE

RAJESH

24
7/26/2015

FUNTION MODULE

RAJESH

FUNTION MODULE

***** FUNCTION MODULE RELATED TO BW *****

25
7/26/2015

You might also like