Should Not Use: You Might Have To Use The Commit Work in Some Cases As of Ur Need

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Commit Work in BADI :

To give you a very specific answer, the COMMIT WORK statement triggers following reactions.
1. SAP LUW ends
2. All Buffers are refreshed i.e cleared.
The implication can be that your code may go into dump or the data updated might be missed as in
between the process you are clearing all buffer memories.

You should not use the COMMIT WORK inside the BADI or USER EXIT as it will lead to
inconsistancies in data.
Note : Commit and Roll back shold be avoided ( You Might have to use the Commit Work in some
cases as of ur need )in User exit and BADIs Because while executing its not always sure that all the
values needed for database updations are present or not.
Example.
Suppose steps 1,2,3,4 have to be completed before the transaction completes its Logical Unit of
Work and calls the internal Commit Work.
Now you are adding some piece of code through a User exit between step 2 and 3.
If you use a commit work, All the data manipulated in Step 1 and 2 will be saved.
however if somehow step 3 gets failed.(Which means LUW brakes and there should not be any
database commit)
Evrythng should ROLLBACK at that time,including the data in step 1 and 2.
But it will not happen, as you have already used a Commit Work inside ur exit.

if you are not allowed to use COMMIT WORK in your user-exit, I recommend
>you to use the function module 'BAPI_TRANSACTION_COMMIT'.
This is an incorrect thing to do! The function BAPI_TRANSACTION_COMMIT is just a wrapper
around the COMMIT WORK statement so that it can be called as part of a remote transaction via
RFC. This will have the exact same bad effects as already documented by others in this thread as
calling COMMIT WORK.
Within your user-exit you have the option of:
- Doing DB update, but don't commit them and when the overall transaction is commited by the
standard transaction then your updates will also be commited.
- Putting your updates into an Update Task function module and calling this during the user-exit. It
won't actually be executed until the main transaction calls the COMMIT WORK and then at that time
it will be executed in an update process along with the other standard update fucntions as part of the
transaction.
Key thing, don't call COMMIT WORK or call BAPI_TRANSACTION_COMMIT.
Now that I've said that, here is a scenario that I've had in the past. During user-exit I need to do
updates to custom tables or call APIs that do updates to the DB and I need them to be commited
immediatly as a seaperate DB transaction from the main calling program (Note, this is a very specific
requirment becuase there is no roll-back possible). The way to accomplish this is to put the updates
and your COMMIT WORK into a function module and mark the function module as RFC enabled
(note, does not need to be Update enabled because this isn't an update task). In the User-Exit call
the new function with the addition "Starting New Task"
>CALL FUNCTION func STARTING NEW TASK task
> [DESTINATION {dest|{IN GROUP {group|DEFAULT}}}]
> parameter_list
> [{PERFORMING subr}|{CALLING meth} ON END OF TASK].
By doing this function call in a new task it is actaully making an RFC to another process on one of
the application servers and will be handled as a seperate DB transaction from the main program.
So final note on this one, don't call COMMIT WORK or call BAPI_TRANSACTION_COMMIT but if
you have a specific need to create a seperate DB transaction you can use this method that I've
described but remember that there is no way to roll back the changes of the seperate transaction.

Logo in ALV Grid :

Logo should be uploaded into application server using transaction 'OAER'.

1. Go to Transaction OAER,
2. Give Class Name as PICTURES
3. Class type as OT
4. Object Key as the name of the Object u want to specify
5. Upon execution you would be prompted to give the file path details. Just upload which ever logo u want
to display
6. Now you can use the same name in your ALV FM

In your ALV program, you need to have event for TOP_OF_PAGE, and also this works only in case of Grid not
in ALV LIST.

Look at the sample code to display LOGO.

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

call function 'REUSE_ALV_GRID_DISPLAY'


exporting
i_callback_program = i_repid
it_fieldcat = header
is_layout = gt_layout
i_callback_top_of_page = 'TOP-OF-PAGE1'
i_grid_title = xyz
it_sort = gt_sort[]
i_default = 'X'
i_save = 'U'
is_variant = gt_variant
it_events = gt_events
tables
t_outtab = t_output.

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

*-------------------------------------------------------------------*
* Form TOP-OF-PAGE1

*-------------------------------------------------------------------*

form top-of-page1.

data: header type slis_t_listheader,


wa type slis_listheader.

* TITLE AREA

wa-typ = 'S'.
wa-info = text-h04.
append wa to header.

wa-typ = 'S'.
write sy-datum to wa-info mm/dd/yyyy.

concatenate text-h03 wa-info into wa-info separated by space.


append wa to header.

wa-typ = 'S'.
concatenate text-h02 sy-uname into wa-info separated by space.
append wa to header.

wa-typ = 'S'.
concatenate text-h01 sy-repid into wa-info separated by space.
append wa to header.

********" LOGO

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = header

i_logo = 'ENJOYSAP_LOGO'.

*********" LOGO

endform.

Here in TOP-OF-PAGE form it will show you the Prog name,Date, User Name.

You might also like