Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 256
Pedro Accorsi Avatar asked Aug 25 '20 16:08

Pedro Accorsi


2 Answers

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.
like image 195
mkysoft Avatar answered Nov 17 '22 02:11

mkysoft


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.

like image 6
Philipp Avatar answered Nov 17 '22 00:11

Philipp