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

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!

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.

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.

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.

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.

Related

How to find all enhancements in SAP system?

I need to prepare a document which includes all enhancements implemented in the SAP system of the company, what are all steps that I have to go through?
Another more comprehensive way to find all the enhancements is to (re)use the best practices.
A wonderful tool called ABAP Exit Ray Eye was developed yet in 2009 and though it is a bit forgotten now, it is still does the job.
Having different criteria
it can show you currently implemented enhancements in a very nifty and user-friendly way:
The source code of this tool can be grabbed in archive from Github repo and is installable by SAPLink.
Try running SAP Standard program SNIF in se38. It might help. For more information refer to this blog post. https://blogs.sap.com/2012/04/16/lets-find-enhancements/
All the enhancements reside in ENHINCINX table and can be searched by package like this:
PARAMETERS p_pack TYPE devclass.
"Accept wildcards for package
p_pack = COND #( WHEN p_pack IS INITIAL THEN '%' ELSE replace( val = p_pack sub = `*` with = `%` occ = 0 ) ).
SELECT e~*
FROM enhincinx AS e
INNER JOIN tadir AS t
ON 'R3TR' = t~pgmid
AND 'ENHO' = t~object
AND e~enhname = t~obj_name
WHERE t~devclass LIKE #p_pack
INTO TABLE #DATA(lt_enhincinx).
LOOP AT lt_enhincinx ASSIGNING FIELD-SYMBOL(<ls_enhincinx>).
WRITE: / |{ <ls_enhincinx>-programname } / { <ls_enhincinx>-enhname }:|.
ENDLOOP.

Notification: BTPLN vs TPLNR

I have this data type to hold the information to create a notification.
DATA: LS_NOTIFHEADER LIKE BAPI2080_NOTHDRI.
I want to create a notification with a functional location and an affected functional location. I know I can add the functional location with
LS_NOTIFHEADER-TPLNR = '1010-XXXXXXXXXXXXXX'.
Is there also a field to add the affected functional location (BTPLN)?
This is the code I use to create the notification.
CALL FUNCTION 'BAPI_ALM_NOTIF_CREATE'
EXPORTING
NOTIF_TYPE = 'M1'
NOTIFHEADER = LS_NOTIFHEADER
IMPORTING
NOTIFHEADER_EXPORT = LS_NOTIF
TABLES
RETURN = LT_RETURN.
There is no possibility to specify affected location in BAPI.
But user-exit EXIT_SAPLIQS0_017 (enhancement QQMA0025) may be helpful for you. It is called by BAPI and there you can modify BTPLN.

Sap odata: Export a single Variable with abap

I have got a function module that counts some variables in sap system and export it as single INT4. But when I try to use this in gateway service, it says me
"no output table mapped" How can i overcome it, I tried to put this variable in a table and export then but I couldnt.
DATA: EV_ENQ TYPE STANDARD TABLE OF seqg3.
CALL FUNCTION 'ENQUEUE_READ'
EXPORTING
guname = '*'
IMPORTING
number = EV_TABLESIZE
TABLES
enq = EV_ENQ.
Ev_Tablesize is the variable that I want to export. It holds the total lock count.
Your parameter should be mapped under your service implementation in SEGW. If it is not, then you should map them again and be sure that the parameter is being displayed.

Sap Code Inspector - Generating a table of all PCodes linked to the classes

I have problems to read the error codes and corresponding messages of SCI message classes.
Is there an way to easy access those?
I'm using "Praxishandbuch SAP Code Inspector" as a reference, but in that regard it is of no help.
I looked in Se11 but the information to the messages isn't helpful.
Has someone an approch to build such a table?
You can try this, perhaps it will work for you. I use the code below to get the access to all the errors found by Code Inspector for particular user(s):
data: ref_inspec_a type ref to cl_ci_inspection.
ref_inspec_a = cl_ci_inspection=>get_ref(
p_user = pa_iuser
p_name = pa_inam
p_vers = pa_ivers ).
data: ls_resp type scir_resp,
lt_resp type scit_resp.
clear: ls_resp, lt_resp.
ls_resp-sign = 'I'.
ls_resp-option = 'EQ'.
ls_resp-low = pa_fuser.
insert ls_resp into table lt_resp.
call method ref_inspec_a->get_results
exporting
p_responsibl = lt_resp
exceptions
insp_not_yet_executed = 1
overflow = 2
others = 3.
Playing around with LT_RESP you can get results for more users at the same time.
After you execute the code above, you can check the attributes SCIRESTPS and SCIRESTHD of the object REF_INSPEC_A. These are the large tables, which contain the result data of the SCI check. You can either work with them on your own, or you can simply pass the object REF_INSPEC_A into the function module SCI_SHOW_RESULTS to get regular SCI user interface.
I found out that you can get all the changeable messages (found in SCI GoTo/Management Of/ Message Priorities) can be read from the scimessages attribute of the test classes.
With this help you can get about 60% of all errors.

Equivalent BAPI for a MB01 transaction?

I'm trying to replace some un-reliable sap scripting we have in place to do an MB01 from a custom goods receipt application. I have come across the .NET connector and it looks like it could do a job for me.
Research has churned up the BAPI called BAPI_GOODSMVT_CREATE but can anyone tell me what parameters might be required to perform this transaction?
I have access to a SAP test environment.
BAPI_GOODSMVT_CREATE accepts a table of values called GOODSMVT_ITEM which contains 121 fields. I'm sure that not all of these fields are required.
Ultimately I guess my question is, what how can I work out which ones are required?
Do you have access to a SAP system? I have recently used this BAPI, and it has quite detailed documentation. To view the documentation, use transaction SE37, and enter the BAPI name. Unfortunately I don't currently have access to a system.
You will have to ask one of your MM/Logistics people to tell you what the movement type (BWART) is, and depending on the config you will need details like material number (MATNR), plant (WERKS), storage location etc.
MB01 is a Post GR for PO transaction, it is an equivalent of GM_Code 01 in MIGO or BAPI_GOODSMVT_CREATE. MIGO transaction is a modern successor for obsolete MB01.
So, as per the BAPI_GOODSMVT_CREATE documentation for GM_Code 01 the following fields are mandatory:
Purchase order
Purchase order item
Movement type
Movement indicator
Quantity in unit of entry
ISO code unit of measurement for unit of entry or
quantity proposal
Here is the sample:
gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '01'.
loop at pcitab.
itab-move_type = pcitab-mvt_type.
itab-mvt_ind = 'B'.
itab-plant = pcitab-plant.
itab-material = pcitab-material.
itab-entry_qnt = pcitab-qty.
itab-move_stloc = pcitab-recv_loc.
itab-stge_loc = pcitab-issue_loc.
itab-po_number = pcitab-pur_doc.
itab-po_item = pcitab-po_item.
concatenate pcitab-del_no pcitab-del_item into itab-item_text.
itab-move_reas = pcitab-scrap_reason.
append itab.
endloop.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gmhead
goodsmvt_code = gmcode
IMPORTING
goodsmvt_headret = mthead
tables
goodsmvt_item = itab
return = errmsg