You are currently viewing SAP-ABAP Executing Function Module

SAP-ABAP Executing Function Module

In previous article we have discussed about Function Module and steps to create a Function Module. In this article we will discuss about how to execute a function module. After creating a function module and after writing your source code, you can execute your function module to test it so that it gives desired result as per your requirement.

Steps to Execute a Function Module are: –

Step 1: –Press F8 Key and then Enter Import Parameters

Step 2: – Press F8 Key again, it will display export parameters or no. of records in the internal table.

Step 3: – Click on the table icon of the respective internal table to see records.

Let’s discuss with following example about function module with screenshots.

Lets first see the source code below

Source Code:

FUNCTION ZFM_BILL_DETAIL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(BILLDOCNO) TYPE  ZBILLDOCNO DEFAULT 0
*"  EXPORTING
*"     REFERENCE(BILLNO) TYPE  ZBILL-BILNO
*"  TABLES
*"      IBILL STRUCTURE  ZBILL OPTIONAL
*"      IBILLDETAIL STRUCTURE  ZBILL_DESC OPTIONAL
*"  EXCEPTIONS
*"      FLAG
*"----------------------------------------------------------------------
DATA: FLAG TYPE CHAR1.
IF BILLDOCNO IS NOT INITIAL .
SELECT SINGLE * INTO IBILL FROM ZBILL WHERE DOC_ID = BILLDOCNO.
BILLNO  =  IBILL-BILNO.
SELECT * INTO CORRESPONDING FIELDS OF TABLE IBILLDETAIL FROM ZBILL_DESC                     WHERE DOC_ID = BILLDOCNO.
APPEND IBILL.
ELSEIF BILLDOCNO IS INITIAL.
SELECT * INTO CORRESPONDING FIELDS OF TABLE IBILL FROM ZBILL.
ENDIF.
SORT IBILL BY DOC_ID.
IF IBILL[] IS INITIAL.
FLAG = 'X'.
ENDIF.
ENDFUNCTION.

In the above source code, I am fetching the bill records and the details of bill on two conditions if I will not pass any bill document number, it will display a list of bills which are in IBILL internal table and if I will pass bill document no., it will display record of that particular bill which is in IBILL internal table and its details which are in IBILLDETAIL internal table.

 

Case 1:- If BILLDOCNO is initial or 0.

Step 1: – Press F8 Key to execute the Function Module after writing source code. It will display following screen. Then Enter Import Parameter Value and then Press F8 key again.

Step 2: – On pressing F8 key again, it will display following screen which shows no. records in Internal Tables. As IBILL has 33 entries and IBILLDETAIL has no record.

Step 3: – Click on table icon of IBILL and you will get result as show below.

 

Case 2:- If BILLDOCNO is some other number for e.g. Here, I entered 19.

Step 1: – After doing 1st case, Go back to following screen by clicking on Back Button two times. Then Enter Import Parameter Value and then Press F8 key again.

Step 2: – On pressing F8 key again, it will display following screen which shows no. records in Internal Tables. As IBILL has 1 entry and IBILLDETAIL has 3 entries.

Step 3: – Click on table icon of IBILL and you get following result.

Step 4: – Now Go Back to previous screen, Click on table icon of IBILLDETAIL and you get following result.

 

Dinesh Kumar Bansal

Dinesh Kumar Bansal is an Indian Software Developer, who is working on ASP.Net, MS-SQL, SAP-ABAP technologies from last one year. His Basic Principle of developing software is, “You have to clear about, what do you want to do, how can it be done”. He always says that development can be done with a cool & fresh mind.

Leave a Reply