From ff0fc728911a46eec9ed7826d40222c21776ff5b Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Wed, 11 May 2022 12:38:20 +0200 Subject: [PATCH] IOBJ/ODSO: Fix errors if objects exist already (#5551) Implementation worked only for new objects (argh) Co-authored-by: Lars Hvam --- src/objects/zcl_abapgit_object_iobj.clas.abap | 76 ++++++++++++------- src/objects/zcl_abapgit_object_odso.clas.abap | 42 +++++++--- 2 files changed, 80 insertions(+), 38 deletions(-) diff --git a/src/objects/zcl_abapgit_object_iobj.clas.abap b/src/objects/zcl_abapgit_object_iobj.clas.abap index 0273b80cb..74111f615 100644 --- a/src/objects/zcl_abapgit_object_iobj.clas.abap +++ b/src/objects/zcl_abapgit_object_iobj.clas.abap @@ -55,14 +55,20 @@ CLASS zcl_abapgit_object_iobj IMPLEMENTATION. CALL FUNCTION 'RSD_IOBJ_GET' EXPORTING - i_iobjnm = lv_objna - i_objvers = 'A' + i_iobjnm = lv_objna + i_objvers = 'A' IMPORTING - e_s_viobj = . - - ASSIGN COMPONENT 'TSTPNM' OF STRUCTURE TO . - - rv_user = . + e_s_viobj = + EXCEPTIONS + iobj_not_found = 1 + illegal_input = 2 + bct_comp_invalid = 3 + not_authorized = 4 + OTHERS = 5. + IF sy-subrc = 0. + ASSIGN COMPONENT 'TSTPNM' OF STRUCTURE TO . + rv_user = . + ENDIF. ENDMETHOD. @@ -208,31 +214,49 @@ CLASS zcl_abapgit_object_iobj IMPLEMENTATION. TRY. - CALL FUNCTION 'BAPI_IOBJ_CREATE' - EXPORTING - details = - IMPORTING - return = ls_return - TABLES - compounds = - attributes = - navigationattributes = - atrnavinfoprovider = - hierarchycharacteristics = - elimination = - hanafieldsmapping = - xxlattributes = . - - IF ls_return-type = 'E'. - zcx_abapgit_exception=>raise( |Error when creating iobj: { ls_return-message }| ). - ENDIF. - ASSIGN COMPONENT 'INFOOBJECT' OF STRUCTURE TO . ASSERT sy-subrc = 0. + IF zif_abapgit_object~exists( ) = abap_false. + CALL FUNCTION 'BAPI_IOBJ_CREATE' + EXPORTING + details = + IMPORTING + return = ls_return + TABLES + compounds = + attributes = + navigationattributes = + atrnavinfoprovider = + hierarchycharacteristics = + elimination = + hanafieldsmapping = + xxlattributes = . + ELSE. + CALL FUNCTION 'BAPI_IOBJ_CHANGE' + EXPORTING + infoobject = + details = + IMPORTING + return = ls_return + TABLES + compounds = + attributes = + navigationattributes = + atrnavinfoprovider = + hierarchycharacteristics = + elimination = + hanafieldsmapping = + xxlattributes = . + ENDIF. + + IF ls_return-type = 'E'. + zcx_abapgit_exception=>raise( |Error when creating iobj: { ls_return-message }| ). + ENDIF. + APPEND TO . CALL FUNCTION 'BAPI_IOBJ_ACTIVATE_MULTIPLE' diff --git a/src/objects/zcl_abapgit_object_odso.clas.abap b/src/objects/zcl_abapgit_object_odso.clas.abap index 1bebb72cf..5b78574b1 100644 --- a/src/objects/zcl_abapgit_object_odso.clas.abap +++ b/src/objects/zcl_abapgit_object_odso.clas.abap @@ -133,6 +133,7 @@ CLASS zcl_abapgit_object_odso IMPLEMENTATION. FIELD-SYMBOLS: TYPE any, + TYPE any, TYPE STANDARD TABLE, TYPE STANDARD TABLE, TYPE STANDARD TABLE, @@ -169,17 +170,34 @@ CLASS zcl_abapgit_object_odso IMPLEMENTATION. io_xml->read( EXPORTING iv_name = 'INDEX_IOBJ' CHANGING cg_data = ). TRY. - CALL FUNCTION 'BAPI_ODSO_CREATE' - EXPORTING - details = - IMPORTING - odsobject = lv_dsonam - TABLES - infoobjects = - navigationattributes = - indexes = - indexesinfoobjects = - return = lt_return. + + ASSIGN COMPONENT 'ODSOBJECT' OF STRUCTURE TO . + ASSERT sy-subrc = 0. + + IF zif_abapgit_object~exists( ) = abap_false. + CALL FUNCTION 'BAPI_ODSO_CREATE' + EXPORTING + details = + IMPORTING + odsobject = lv_dsonam + TABLES + infoobjects = + navigationattributes = + indexes = + indexesinfoobjects = + return = lt_return. + ELSE. + CALL FUNCTION 'BAPI_ODSO_CHANGE' + EXPORTING + odsobject = + details = + TABLES + infoobjects = + navigationattributes = + indexes = + indexesinfoobjects = + return = lt_return. + ENDIF. CATCH cx_sy_dyn_call_illegal_func. zcx_abapgit_exception=>raise( |Necessary BW function modules not found or object not supported| ). @@ -192,7 +210,7 @@ CLASS zcl_abapgit_object_odso IMPLEMENTATION. CALL FUNCTION 'BAPI_ODSO_ACTIVATE' EXPORTING - odsobject = lv_dsonam + odsobject = TABLES return = lt_return.