7

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!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Pedro Accorsi
  • 765
  • 1
  • 8
  • 21

4 Answers4

8

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.
mkysoft
  • 5,392
  • 1
  • 21
  • 30
  • 2
    Why call the method if it only exists in S/4? Once you know if it exists or not, calling it seems unnecessary. – Gert Beukema Aug 25 '20 at 19:42
  • That method making some controls. Also determining cloud and on promise option. May be it will come to non s4 system in future as snote or patch. So I think we need to call it. – mkysoft Aug 25 '20 at 20:02
  • worked perfectly! ```rv_result = switch #( cl_cos_utilities=>is_s4h( ) when abap_true then 'S4HCMCMX' else 'SAP_HRCMX' ).``` thanks! – Pedro Accorsi Aug 25 '20 at 20:43
  • 6
    There's an easier way to determine if a method exists. Just call it in a TRY and CATCH CX_SY_DYN_CALL_ILLEGAL_METHOD. – Gert Beukema Aug 25 '20 at 20:48
6

Using the method cl_cos_utilities=>is_s4h is a rather unclean solution, because that method does not exist on older releases.

A cleaner method is to use the function module SFW_IS_BFUNC_SWITCHED_ON. This function module checks if a business function in the switch framework is enabled.

To check for the S4HANA on premise business function:

CALL FUNCTION 'SFW_IS_BFUNC_SWITCHED_ON'
  EXPORTING
    bfunc_name     = 'SIMPLIFY_ON_PREMISE'
  IMPORTING
    is_switched_on = is_s4.

To check for the S4HANA on cloud business function:

CALL FUNCTION 'SFW_IS_BFUNC_SWITCHED_ON'
  EXPORTING
    bfunc_name     = 'SIMPLIFY_PUBLIC_CLOUD'
  IMPORTING
    is_switched_on = is_s4.

By the way: The method cl_cos_utilities=>is_s4h actually uses this function module internally.

You might also want to check if it might be more appropriate in your use-case to use that function module to actually detect which HR business functions are active instead of deriving that information indirectly from whether or not the system has S/4 activated.

Philipp
  • 67,764
  • 9
  • 118
  • 153
2

There's the function module OCS_GET_INSTALLED_COMPS which returns all software components installed. Note that it's not released by SAP. It used to work in old systems and still works in S/4HANA.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
0

You can use function module DELIVERY_CHCK_ACTIVE_COMPONENT to check which of the two components is active.

I am also pretty sure only S/4 systems will have the S4CORE component active if you really need to check if it's S/4 or R/3.

Gert Beukema
  • 2,510
  • 1
  • 17
  • 18
  • 1
    How to call the function module? It seems obsolete in S/4HANA because it's based on the table `CVERS_ACT` which is empty. – Sandra Rossi Aug 25 '20 at 19:55