Hi Sanjana,
Below code will help to save or rollback based on condition .
lr_transaction ?= lr_customer->get_transaction( ).
if lr_transaction is bound.
if lr_transaction->check_save_possible( ) eq abap_true.
if lr_transaction->save( ) eq abap_true.
lr_transaction->commit( ).
endif.
endif.
endif.
Regards
Alok