Application Development 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: 

[IBASE] => EXAMPLE CODE : How to create an iBase (trx: IB51)

rachidroughi
Explorer
0 Kudos
339

Hi Guys,

please, find below an example of an ABAP code to create an iBase.

REPORT ztest_ibase.

DATA: lo_engine TYPE REF TO cl_ibase_engine,
lv_moment TYPE ibxx_ref-moment,
ls_ibib TYPE ibib1,
ls_ibibt TYPE ibibt1,
lt_inst TYPE ibco1_inst_tab1,
lt_stru TYPE ibco1_struc_tab1,

ls_process TYPE ibxx_process_rec,
lt_inst_cre TYPE ibco1_inst_tab1,
lt_stru_cre TYPE ibco1_struc_tab1,

lv_handle TYPE ibxx_ref-handle.

* Create new handle
CALL FUNCTION 'IB_COM_NEW'
IMPORTING
e_ibco_handle = lv_handle.

* Get moment
GET TIME STAMP FIELD lv_moment.

* Initialization of iBase
CALL FUNCTION 'IB_COM_CREATE_IBASE_INITIAL'
EXPORTING
i_ibco_handle = lv_handle
i_ibtyp = 'Z1'
IMPORTING
e_ibib1 = ls_ibib
e_ibibt1 = ls_ibibt
EXCEPTIONS
ib_handle_not_defined = 1
OTHERS = 2.

CHECK sy-subrc EQ 0.

ls_ibibt-descr = ls_ibib-extid = 'Test creation'.
CALL FUNCTION 'IB_COM1_CHANGE_IBASE_ONLY'
EXPORTING
i_ibco_handle = lv_handle
i_ibib1 = ls_ibib
i_ibibt1 = ls_ibibt
EXCEPTIONS
ib_handle_not_defined = 1
OTHERS = 2.

* Fill process
CHECK sy-subrc EQ 0.
ls_process = VALUE ibxx_process_rec( activity = ibxx_ac_create
ind_valfr = ibxx_true
ind_valto = ibxx_true
ind_sortf = ibxx_true
ind_amount = ibxx_true
ind_unit = ibxx_true
ind_objtyp = ibxx_true
ind_objid = ibxx_true
ind_serno = ibxx_true
ind_plant = ibxx_true
ind_batch = ibxx_true
ind_revlv = ibxx_true
ind_deviceid = ibxx_true
ind_posno = ibxx_true
).

INSERT VALUE ibco1_inst_rec1( val = VALUE #( valfr = lv_moment valto = '99991231235959' )
objtyp = ibxx_obj_0002
object = NEW cl_ibase_r3_material( i_matnr = '7300/1200A-001' )
) INTO TABLE lt_inst.
APPEND VALUE ibco1_struc_rec1( ) TO lt_stru.

* Buffering of the first component
CALL FUNCTION 'IB_COM1_PROCESS_INSTANCE'
EXPORTING
i_ibco_handle = lv_handle
i_ibase = ls_ibib-ibase
i_moment = lv_moment
i_process_rec = ls_process
CHANGING
c_instance_tab = lt_inst
c_structure_tab = lt_stru
EXCEPTIONS
ib_handle_not_defined = 1
ib_no_activity = 2
ib_nothing_processed = 3
ib_inconsistend_data = 4
OTHERS = 5.
CLEAR: lt_inst[], lt_stru[].

* New component without any parent
INSERT VALUE ibco1_inst_rec1( val = VALUE #( valfr = lv_moment valto = '99991231235959' )
objtyp = ibxx_obj_0002
object = NEW cl_ibase_r3_material( i_matnr = 'H900.2050.CAGT1' )
) INTO TABLE lt_inst.
APPEND VALUE ibco1_struc_rec1( ) TO lt_stru.

* Buffering of the component
CALL FUNCTION 'IB_COM1_PROCESS_INSTANCE'
EXPORTING
i_ibco_handle = lv_handle
i_ibase = ls_ibib-ibase
i_moment = lv_moment
i_process_rec = ls_process
CHANGING
c_instance_tab = lt_inst
c_structure_tab = lt_stru
EXCEPTIONS
ib_handle_not_defined = 1
ib_no_activity = 2
ib_nothing_processed = 3
ib_inconsistend_data = 4
OTHERS = 5.


*
* Here, creation of several components linked to their parent
*
IF sy-subrc EQ 0.

"Store first node ID
DATA: lv_recno TYPE ibxx_ref-recno.
LOOP AT lt_inst INTO DATA(ls_inst).
lv_recno = ls_inst-in_recno.
EXIT.
ENDLOOP.
CLEAR: lt_inst[], lt_stru[].

"ADD SUBNODES
INSERT VALUE ibco1_inst_rec1( val = VALUE #( valfr = lv_moment valto = '99991231235959' )
objtyp = ibxx_obj_0002
object = NEW cl_ibase_r3_material( i_matnr = 'H264.9649/3NJ3.B' )
) INTO TABLE lt_inst.
APPEND VALUE ibco1_struc_rec1( par_recno = lv_recno ) TO lt_stru.

* Buffering of the component
CALL FUNCTION 'IB_COM1_PROCESS_INSTANCE'
EXPORTING
i_ibco_handle = lv_handle
i_ibase = ls_ibib-ibase
i_moment = lv_moment
i_process_rec = ls_process
CHANGING
c_instance_tab = lt_inst
c_structure_tab = lt_stru
EXCEPTIONS
ib_handle_not_defined = 1
ib_no_activity = 2
ib_nothing_processed = 3
ib_inconsistend_data = 4
OTHERS = 5.
CLEAR: lt_inst[], lt_stru[].

* New component
INSERT VALUE ibco1_inst_rec1( val = VALUE #( valfr = lv_moment valto = '99991231235959' )
objtyp = ibxx_obj_0002
object = NEW cl_ibase_r3_material( i_matnr = 'H910.2539.GT1' )
) INTO TABLE lt_inst.
APPEND VALUE ibco1_struc_rec1( par_recno = lv_recno ) TO lt_stru.

* Buffering of the component

CALL FUNCTION 'IB_COM1_PROCESS_INSTANCE'
EXPORTING
i_ibco_handle = lv_handle
i_ibase = ls_ibib-ibase
i_moment = lv_moment
i_process_rec = ls_process
CHANGING
c_instance_tab = lt_inst
c_structure_tab = lt_stru
EXCEPTIONS
ib_handle_not_defined = 1
ib_no_activity = 2
ib_nothing_processed = 3
ib_inconsistend_data = 4
OTHERS = 5.

IF sy-subrc EQ 0.

"Store first node ID
LOOP AT lt_inst INTO ls_inst.
lv_recno = ls_inst-in_recno.
EXIT.
ENDLOOP.
CLEAR: lt_inst[], lt_stru[].

INSERT VALUE ibco1_inst_rec1( val = VALUE #( valfr = lv_moment valto = '99991231235959' )
objtyp = ibxx_obj_0002
object = NEW cl_ibase_r3_material( i_matnr = 'H950.109534.S0A' )
) INTO TABLE lt_inst.
APPEND VALUE ibco1_struc_rec1( par_recno = lv_recno ) TO lt_stru.

* Buffering of the component
CALL FUNCTION 'IB_COM1_PROCESS_INSTANCE'
EXPORTING
i_ibco_handle = lv_handle
i_ibase = ls_ibib-ibase
i_moment = lv_moment
i_process_rec = ls_process
CHANGING
c_instance_tab = lt_inst
c_structure_tab = lt_stru
EXCEPTIONS
ib_handle_not_defined = 1
ib_no_activity = 2
ib_nothing_processed = 3
ib_inconsistend_data = 4
OTHERS = 5.

INSERT VALUE ibco1_inst_rec1( val = VALUE #( valfr = lv_moment valto = '99991231235959' )
objtyp = ibxx_obj_0002
object = NEW cl_ibase_r3_material( i_matnr = 'H950.109534.S0A' )
) INTO TABLE lt_inst.
APPEND VALUE ibco1_struc_rec1( par_recno = lv_recno ) TO lt_stru.

* Buffering of the component
CALL FUNCTION 'IB_COM1_PROCESS_INSTANCE'
EXPORTING
i_ibco_handle = lv_handle
i_ibase = ls_ibib-ibase
i_moment = lv_moment
i_process_rec = ls_process
CHANGING
c_instance_tab = lt_inst
c_structure_tab = lt_stru
EXCEPTIONS
ib_handle_not_defined = 1
ib_no_activity = 2
ib_nothing_processed = 3
ib_inconsistend_data = 4
OTHERS = 5.


IF sy-subrc EQ 0.
* Save buffer
CALL FUNCTION 'IB_COM_SAVE_AND_FREE'
EXPORTING
i_ibco_handle = lv_handle.

COMMIT WORK AND WAIT.
WRITE :'Ibase number:', ls_ibib-ibase.

ENDIF.
ENDIF.

ENDIF.
1 REPLY 1

abo
Active Contributor
0 Kudos
307

Where is the question? Perhaps you wanted to post a technical article, right?