Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Function Module how to create / call

Former Member
0 Likes
1,233

Hello ABAP Experts,

I need to create a function module which will take a line wa_itab1 of a internal table itab1 and returns the same line after changing couple of values in it.

I have the logic already working in a zprogram. wondering how to call this zprogram as function module. so that it could be useful in other programs.

how to pass the wa_itab and how to receive it in other programs.

sequence:

zprogram needs to be converted to zfm

zprogram1 will call zfm

zprogram1 will export wa_itab

zfm will change couple of values in wa_itab

zprogram1 will receive the changed wa_itab.

any suggestions appreciated.

Thanks,

BWer

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
728

First, go to SE80, select from the listbox, "Function Group", enter the name of your function group, Hit enter. SYstem will ask if you want to create it, say yes. Once the function group is created, then righ-click on the node in the tree structure and select create->function module. Name it and give description.

Add your IMPORT and EXPORT parameters in the appropriate tab, add the source code in the appropriate tab. SAve and activate.

Here is some addtional reading.

http://help.sap.com/saphelp_470/helpdata/en/d1/801ee8454211d189710000e8322d00/frameset.htm

Regards,

Rich Heilman

Read only

Manohar2u
Active Contributor
0 Likes
728

1. To convert zprogram to function module, You need to create a function module with one import i_line and one export with o_line.

Then in this function module you change i_line to o_line.

2. Now you need to call the above created function module in a program by export and import parameter.

program zprogram1
data : wa_input like ztable,
       wa_output like ztable.

Call function 'ZFM'
export
i_input = wa_input
import 
o_input = wa_output.

write wa_output.

********************

function zfm.

o_output-date = i_input-date + 2.

endfunction.

Read only

Former Member
0 Likes
728

If you envision several programs using this function module, then first create a structure like your wa_itab1. Create a function module in SE37, using this structure as the changing parameter type.

Read only

Puneet_Gupta
Contributor
0 Likes
728

Hi,

here are the steps:

1. Create a dictionary structure with the same strucure as your interal table say (ZSTRUC).

2. Create a function module with 1 import parameter say WA_LINEIN LIKE ZSTRUC and one EXPORT parameter say WA_LINEOUT LIKE ZSTRUC

function zfunction.

wa_lineout = wa_linein.

wa_linout-a = 'XX'.

WA_LINEOUT-b = 'YY'

endfunction.

3.In your prog

loop at itab.

call function ZFUNCTION

exporting

WA_LINEIN = ITAB

importing

WA_LINEOUT = ITAB

modify itab.

endloop.

This will modify your itab with the new values and you can use the same.

Hope this helps

Thanks,

Puneet

Read only

Former Member
0 Likes
728

Hi,

Create a structure in SE11 corresponding to your wa_itab line type.

Create a Function Module SE37 (Function Builder : Initial Screen- Goto>Function Groups>Create Groups)

In the  <b>IMPORT</b> parameters 
WA_ITAB1 <b>LIKE</b> <b>Structure Name</b>
       
        <b>EXPORT</b> parameters 
WA_ITAB2 <b>LIKE</b> <b>Structure Name</b>

        
In the Source Code Part.

FUNCTION ZFM.

"Here calling program will pass the values in
"WA_ITAB1 . Process and assign the values to 
"WA_ITAB2 to get the changed values in the Calling 
"Program
ENDFUNCTION.

In your report program.

REPORT zprogram1.

DATA: wa_itab1 TYPE <i>structure name</i>,
      wa_itab2 TYPE <i>structure name</i>.

*-Use the PATTERN push button in the Application toolbar *-to call the function. 

CALL FUNCTION 'ZFM'
 EXPORTING
    WA_ITAB1 = wa_itab1  " Program passes the wa_itab1
 IMPORTING
    WA_ITAB2 = wa_itab2. " Changed values passed to program in wa_itab2.

Regards,

Arun Sambargi.