Search code examples
abaps4hanasap-r3

How to programmatically tell if system is R/3 or S/4


Is it possible to determine via code if the current system is R/3 or S/4?

I need it because I have a method that returns the software component of Human Resources related data, but this component should be different to R/3 and S/4 systems.

    DATA(lv_software_component) = mo_configuration->get_software_component( ).

    SELECT * FROM tadir INTO TABLE @DATA(lt_inftype_tables)
            WHERE pgmid  = 'R3TR'
              AND object = 'TABL'
              AND devclass IN ( SELECT devclass FROM tdevc
                                               WHERE dlvunit = @lv_software_component
                                                  OR dlvunit = 'SAP_HRGXX'
                                                  OR dlvunit = 'SAP_HRRXX' )

On R/3, lv_software_component should be 'SAP_HRCMX', for example, while on S/4 it should be 'S4HCMCMX'. Currently, I have no idea on how to tell the difference between the releases, programmatically speaking.

The best I've come up with is hardcoding SY-SYSID, since I know which systems are S/4 and which aren't, but that shouldn't be ideal.

I appreciate any help, thanks!


Solution

  • You can use below class method for determining it. On the other hand is_s4h method only exists on S4 system. You need to check method exits before calling it.

    cl_cos_utilities=>is_s4h( )
    

    Working full example:

    REPORT ZMKY_ISS4.
    CLASS cl_oo_include_naming DEFINITION LOAD.
    
    DATA oref TYPE REF TO if_oo_class_incl_naming.
    DATA: lt_methods TYPE seop_methods_w_include,
          lv_clskey  TYPE seoclskey,
          ls_cpdkey  TYPE seocpdkey,
          lv_iss4    TYPE abap_bool,
          lt_params  TYPE abap_parmbind_tab.
    
    lv_clskey = 'CL_COS_UTILITIES'.
    oref ?= cl_oo_include_naming=>get_instance_by_cifkey( lv_clskey ).
    lt_methods = oref->get_all_method_includes( ).
    ls_cpdkey-clsname = lv_clskey.
    ls_cpdkey-cpdname = 'IS_S4H'.
    READ TABLE lt_methods WITH KEY cpdkey = ls_cpdkey TRANSPORTING NO FIELDS.
    IF sy-subrc EQ 0.
      lt_params = VALUE #( ( name  = 'RV_IS_S4H'
                      kind  = cl_abap_objectdescr=>returning
                      value = REF #( lv_iss4 ) ) ).
      CALL METHOD CL_COS_UTILITIES=>('IS_S4H')
        PARAMETER-TABLE
          lt_params.
    ELSE.
      lv_iss4 = abap_false.
    ENDIF.