Hi Sreedhara,
Q1: I propose to create first the material and then the configuration. If you do not use BAPI_TRANSACTION_COMMIT then you can rollback with BAPI_TRANSACTION_ROLLBACK if any errors.
Q2: You can use the BAPI_MATERIAL_SAVEREPLICA
For configuration:
you need to set the instance data first (just an example)
* Set Instance data
ls_cuins-inst_id = lv_idx.
ls_cuins-obj_type = 'MARA'.
ls_cuins-class_type = '300'.
ls_cuins-obj_key = iv_kmat.
ls_cuins-complete = 'T'.
ls_cuins-consistent = 'T'.
ls_cuins-quantity_unit = <ls_matcn>-base_uom.
APPEND ls_cuins TO lt_cuins.
Then call the MATERIAL_SAVE_CONFIGURATION (just an example)
CALL FUNCTION 'MATERIAL_SAVE_CONFIGURATION'
EXPORTING
material = iv_matnr
conf_matl = iv_kmat
plant = <ls_matpl>-plant
conf_matl_plant = iv_kmat
IMPORTING
return = ls_return
TABLES
e1cucfg = lt_cucfg
e1cuins = lt_cuins
e1cuval = lt_cuval
e1cucom = lt_cucom
e1cucfg_w = lt_cucfg
e1cuins_w = lt_cuins
e1cuval_w = lt_cuval
e1cucom_w = lt_cucom
returnmessages = lt_return.
Parameters ending with "_w" are relevant for the plant views (e.g. MRP3 configuration) other parameters are relevant for Basic Data 2 view configuration.
Best regards
Tamas