Skip to content

Instantly share code, notes, and snippets.

@mbtools
Created September 4, 2023 18:25

Revisions

  1. mbtools created this gist Sep 4, 2023.
    157 changes: 157 additions & 0 deletions zrepair_oo_shorttexts.abap
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,157 @@
    *&---------------------------------------------------------------------*
    *& Report ZREPAIR_OO_SHORTTEXTS
    *&---------------------------------------------------------------------*
    *& Check and repair program to address inconsistencies caused by
    *& abapGit deserializing of classes and interfaces
    *&
    *& See https://github.com/abapGit/abapGit/issues/6442
    *&---------------------------------------------------------------------*
    REPORT zrepair_oo_shorttexts.

    TABLES seoclassdf.

    SELECT-OPTIONS so_clif FOR seoclassdf-clsname OBLIGATORY.
    PARAMETERS: p_test AS CHECKBOX DEFAULT 'X'.

    INITIALIZATION.

    %_so_clif_%_app_%-text = 'Class/Interface'.
    %_p_test_%_app_%-text = 'Test Run'.

    so_clif-sign = 'I'.
    so_clif-option = 'CP'.
    so_clif-low = 'Y*'.
    INSERT so_clif INTO TABLE so_clif.
    so_clif-low = 'Z*'.
    INSERT so_clif INTO TABLE so_clif.

    START-OF-SELECTION.

    DATA:
    clsnames TYPE STANDARD TABLE OF seoclsname WITH DEFAULT KEY,
    clsname TYPE seoclsname,
    langu TYPE tadir-masterlang,
    count TYPE i,
    count_txt TYPE i.

    SELECT clsname FROM seoclassdf INTO TABLE clsnames
    WHERE clsname IN so_clif AND version = seoc_version_active
    ORDER BY PRIMARY KEY.

    LOOP AT clsnames INTO clsname.
    SELECT SINGLE masterlang FROM tadir INTO langu
    WHERE pgmid = 'R3TR' AND ( object = 'CLAS' OR object = 'INTF' ) AND obj_name = clsname.
    IF sy-subrc <> 0.
    langu = sy-langu.
    ENDIF.

    WRITE: / clsname.

    SELECT COUNT(*) INTO count FROM seocompo WHERE clsname = clsname.

    SELECT COUNT(*) INTO count_txt FROM seocompotx WHERE clsname = clsname AND langu = langu.

    IF count = count_txt.
    WRITE: AT /5 'Component Texts OK' COLOR COL_POSITIVE.
    ELSE.
    WRITE: AT /5 'Component Texts inconsitent' COLOR COL_NEGATIVE.
    PERFORM repair_component.
    ENDIF.

    SELECT COUNT(*) INTO count FROM seosubco WHERE clsname = clsname.

    SELECT COUNT(*) INTO count_txt FROM seosubcotx WHERE clsname = clsname AND langu = langu.

    IF count = count_txt.
    WRITE: AT /5 'Sub-component Texts OK' COLOR COL_POSITIVE.
    ELSE.
    WRITE: AT /5 'Sub-component Texts inconsitent' COLOR COL_NEGATIVE.
    PERFORM repair_subcomponent.
    ENDIF.

    SKIP.
    ENDLOOP.

    FORM repair_component.

    DATA:
    lt_components TYPE seo_components,
    lt_descriptions TYPE HASHED TABLE OF seocompotx WITH UNIQUE KEY clsname cmpname langu,
    ls_description TYPE seocompotx.

    FIELD-SYMBOLS:
    <ls_description> TYPE seocompotx,
    <ls_component> TYPE LINE OF seo_components.

    SELECT * FROM seocompotx INTO TABLE lt_descriptions WHERE clsname = clsname.

    "WRITE: AT /5 'Texts (before):', lines( lt_descriptions ).

    SELECT * FROM vseocompdf INTO TABLE lt_components
    WHERE clsname = clsname AND version <> seoc_version_deleted.

    LOOP AT lt_components ASSIGNING <ls_component>.
    READ TABLE lt_descriptions TRANSPORTING NO FIELDS WITH KEY
    clsname = clsname
    cmpname = <ls_component>-cmpname.
    IF sy-subrc <> 0.
    ls_description-clsname = clsname.
    ls_description-cmpname = <ls_component>-cmpname.
    ls_description-langu = langu.
    ls_description-descript = space.
    INSERT ls_description INTO TABLE lt_descriptions.
    ENDIF.
    ENDLOOP.

    "WRITE: 'Texts (after):', lines( lt_descriptions ).

    IF p_test IS INITIAL.
    DELETE FROM seocompotx WHERE clsname = clsname. "#EC CI_SUBRC
    INSERT seocompotx FROM TABLE lt_descriptions. "#EC CI_SUBRC
    WRITE: 'Repaired' COLOR COL_TOTAL.
    ENDIF.

    ENDFORM.

    FORM repair_subcomponent.

    DATA:
    lt_subcomponents TYPE seo_subcomponents,
    lt_descriptions TYPE HASHED TABLE OF seosubcotx WITH UNIQUE KEY clsname cmpname sconame langu,
    ls_description TYPE seosubcotx.

    FIELD-SYMBOLS:
    <ls_description> TYPE seosubcotx,
    <ls_subcomponent> TYPE LINE OF seo_subcomponents.

    SELECT * FROM seosubcotx INTO TABLE lt_descriptions WHERE clsname = clsname.

    "WRITE: AT /5 'Texts (before):', lines( lt_descriptions ).

    SELECT * FROM vseosubcdf INTO TABLE lt_subcomponents
    WHERE clsname = clsname AND version <> seoc_version_deleted.

    LOOP AT lt_subcomponents ASSIGNING <ls_subcomponent>.
    READ TABLE lt_descriptions TRANSPORTING NO FIELDS WITH KEY
    clsname = clsname
    cmpname = <ls_subcomponent>-cmpname
    sconame = <ls_subcomponent>-sconame.
    IF sy-subrc <> 0.
    ls_description-clsname = clsname.
    ls_description-cmpname = <ls_subcomponent>-cmpname.
    ls_description-sconame = <ls_subcomponent>-sconame.
    ls_description-langu = langu.
    ls_description-descript = space.
    INSERT ls_description INTO TABLE lt_descriptions.
    ENDIF.
    ENDLOOP.

    "WRITE: 'Texts (after):', lines( lt_descriptions ).

    IF p_test IS INITIAL.
    DELETE FROM seosubcotx WHERE clsname = clsname. "#EC CI_SUBRC
    INSERT seosubcotx FROM TABLE lt_descriptions. "#EC CI_SUBRC
    WRITE: 'Repaired' COLOR COL_TOTAL.
    ENDIF.

    ENDFORM.