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

Update function module

Former Member
0 Likes
2,681

Hi All,

i have read threads in SDN regarding update function module for updating the database, Could any one send an example for it !

Is there any standard function module which is provided by SAP ?

Regards,

Azee.

8 REPLIES 8
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,333

Not one standard function module, but many can be called in an update task. In the function module, you specify that you can call it in update task, then when calling the function module, you add the extension IN UPDATE TASK.

F1 Help

<i>

CALL FUNCTION

Variant 3

CALL FUNCTION func IN UPDATE TASK.

Additions:

1. ... EXPORTING p1 = f1 ... pn = fn

2. ... TABLES p1 = itab1 ... pn = itabn

Effect

Flags the function module func for execution in the update task. It is not executed at once, but the data passed with EXPORTING or TABLES is placed in a database table and a subsequent COMMIT WORK then causes the function module to be executed by the update task. Update function modules must be flagged as such in the Function Builder

The return value is not set.

Addition 1

... EXPORTING p1 = f1 ... pn = fn

Effect

Values of fields and field strings specified under EXPORTING are passed from the calling program to the function module. In the function module, the formal parameters are defined as import parameters. In the interface definition, default values must be assigned to all import parameters of the update function module.

Addition 2

... TABLES p1 = itab1 ... pn = itabn

Effect

TABLES passes references to internal tables. All table parameters of the function module must have values.

Note

With update function modules, both import parameters and exceptions are ignored when the call is made.

</i>

Call function 'ZTEST'
        IN UPDATE TASK.
Commit work.

Regards,

Rich Heilman

Read only

0 Likes
1,333

Hi Rich,

I expected ur reply,Thanks..

Well i have not written any Update FM before so i take baby steps,

Firstly the record that needs to be inserted should be send to my Update FM

Secondly how should my FM luk like ?

do i just need to put an insert command for that record ?

And give an Commit Work ?

If any standard Example then plz forward.

Regards,

Azee

Read only

0 Likes
1,333

Are you updating a custom table?

Regards,

Rich Heilman

Read only

0 Likes
1,333

i am updating ztable .

Read only

0 Likes
1,333

Hi

Your fm should have an export parameter (if you want to store only one record) or table (if you wan to save several records) structurated as your table and and export parameter to indicate which action has to be made.

In your program you should pass the record(s) you want to insert/update and the action type.

CALL FUNCTION 'Z_UPDATE_TABLE' IN UPDATE TASK

EXPORT

RECORD = ZTABLE

ACTION = 'I'

EXCEPTION

FAIL = 1

OTHERS = 2.

FUNCTION Z_UPDATE_TABLE.

CASE ACTION.

WHEN 'D'. DELETE ZTABLE FROM RECORD.

WHEN 'I'. INSERT ZTABLE FROM RECORD.

WHEN 'U'. UPDATE ZTABLE FROM RECORD.

ENDCASE.

IF SY-SUBRC <> 0. RAISE FAIL. ENDIF.

ENDFUNCTION.

Max

Message was edited by: max bianchi

Read only

0 Likes
1,333

First Create your function module in SE80.

In the attributes tab, under processing type, choose Update Module, Start Immeditatly. Define your import parameters, enter the source code, All validations should have been done prior to the call to this function module, so all you need in the source, is the updating of the database, INSERT, MODIFY, UPDATE, whatever.

When you call you function module, use IN UPDATE TASK, after the call, COMMIT WORK. The commit work will trigger the db update.

Regards,

Rich Heilman

Read only

0 Likes
1,333

Hi ,

Can I pass Memory ID values in update function module.

Any restrictions in using the Export / Import....???

Because I am facing problem in importing the values from memory ID, while exporting I can see the value in my variable , but after import no values are coming.

Could you please help.

Read only

Former Member
0 Likes
1,333

I think you are talking about updating database tables. There are some FM's available but remember SAP doesn't suggest to update standard table directly. You can use COC2_TABLE_INSERT_DB to insert records into a table.

Cheers,

Satya