Skip to content

Instantly share code, notes, and snippets.

@mbtools
Created March 14, 2024 10:10
Show Gist options
  • Save mbtools/c4387a30556ac637eb28c9770ac30ad0 to your computer and use it in GitHub Desktop.
Save mbtools/c4387a30556ac637eb28c9770ac30ad0 to your computer and use it in GitHub Desktop.
ABAP System Info
REPORT zsysinfo.
TYPES:
BEGIN OF ys_info,
attname TYPE string,
attvalue TYPE string,
END OF ys_info,
yt_info TYPE STANDARD TABLE OF ys_info.
START-OF-SELECTION.
DATA:
l_db_host TYPE sapdbhost,
l_as_host TYPE syhost,
l_release_os TYPE char100,
l_rel_os_major TYPE i,
l_rel_os_minor TYPE i,
l_list_count TYPE i,
ls_list TYPE msxxlist,
lt_list TYPE TABLE OF msxxlist,
ls_info TYPE ys_info,
lt_info TYPE TABLE OF ys_info,
l_opsys TYPE string,
l_opsys_bits TYPE i,
l_opsys_uname TYPE string,
l_opsys_major TYPE i,
l_opsys_minor TYPE i,
l_opsys_revision TYPE i,
l_opsys_changelst TYPE i,
l_opsys_rhel TYPE c,
l_kernel TYPE c LENGTH 80,
l_kernel_patch TYPE c LENGTH 80,
l_msg TYPE c LENGTH 250,
l_text TYPE string,
l_text2 TYPE string,
l_text3 TYPE string,
l_dummy TYPE string,
l_subrc TYPE sy-subrc.
* Get all application servers
CALL FUNCTION 'TH_SERVER_LIST'
TABLES
list = lt_list
EXCEPTIONS
no_server_list = 1
OTHERS = 2.
IF sy-subrc = 0.
l_list_count = lines( lt_list ).
LOOP AT lt_list INTO ls_list.
SKIP.
WRITE: / '>> Application Server:', ls_list-name.
SKIP.
* Get details via EWA RFC functions (requires ST-PI add-on)
IF l_list_count = 1.
PERFORM ewa_get_hardware_info
USING 'NONE' CHANGING l_subrc lt_info.
ELSE.
PERFORM ewa_get_hardware_info
USING ls_list-name CHANGING l_subrc lt_info.
ENDIF.
CHECK l_subrc = 0.
CLEAR l_msg.
CALL FUNCTION 'TH_SAPREL'
DESTINATION ls_list-name
IMPORTING
kern_rel = l_kernel
kern_patchlevel = l_kernel_patch
EXCEPTIONS
communication_failure = 1 MESSAGE l_msg
system_failure = 2 MESSAGE l_msg
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'connecting to application server:', l_msg.
CONTINUE.
ENDIF.
* Check Appl vs. DB server
l_as_host = ls_list-host.
TRANSLATE l_as_host TO UPPER CASE. "#EC SYNTCHAR
WRITE: / 'Host name:', AT 40 l_as_host.
* Check Operating System
READ TABLE lt_info INTO ls_info
WITH KEY attname = 'OpSysCategory'.
IF sy-subrc = 0.
l_opsys = ls_info-attvalue.
ELSE.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Get system information: OpSysCategory'.
CONTINUE.
ENDIF.
READ TABLE lt_info INTO ls_info
WITH KEY attname = 'OpSysBits'.
IF sy-subrc = 0.
l_opsys_bits = ls_info-attvalue.
ELSE.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Get system information: OpSysBits'.
CONTINUE.
ENDIF.
READ TABLE lt_info INTO ls_info
WITH KEY attname = 'OpSysRelease'.
IF sy-subrc = 0.
l_release_os = ls_info-attvalue.
ELSE.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Get system information: OpSysRelease'.
CONTINUE.
ENDIF.
CLEAR: l_text, l_text2, l_text3.
IF l_release_os(4) = 'SLES'.
SPLIT l_release_os+4(*) AT '.' INTO l_text l_text2 l_dummy.
ELSEIF l_release_os(4) = 'RHEL'.
SPLIT l_release_os+4(*) AT '.' INTO l_text l_text2 l_dummy.
ELSEIF l_release_os(2) = 'RH'.
SPLIT l_release_os+2(*) AT '.' INTO l_text l_text2 l_dummy.
ELSE.
SPLIT l_release_os AT '.' INTO l_text l_text2 l_dummy.
ENDIF.
TRY.
l_rel_os_major = l_text.
l_rel_os_minor = l_text2.
CATCH cx_sy_conversion_no_number.
WRITE: / 'Warning:', 'Cannot determine OS version'.
ENDTRY.
IF l_release_os CS 'SLES'.
READ TABLE lt_info INTO ls_info
WITH KEY attname = 'OpSysUname'.
IF sy-subrc = 0.
l_opsys_uname = ls_info-attvalue.
IF l_opsys_uname <> 'n/a'.
SPLIT l_opsys_uname AT '.'
INTO l_text l_text2 l_text3 l_dummy.
TRY.
l_opsys_major = l_text.
l_opsys_minor = l_text2.
SPLIT l_text3 AT '-' INTO l_text3 l_text.
l_opsys_revision = l_text3.
SPLIT l_dummy AT '-' INTO l_dummy l_text.
SPLIT l_dummy AT '.' INTO l_dummy l_text.
l_opsys_changelst = l_dummy.
CATCH cx_sy_conversion_no_number.
WRITE: / 'Warning:', 'Cannot determine operating system version'.
ENDTRY.
ENDIF.
ELSE.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Get system information OpSysUname'.
CONTINUE.
ENDIF.
ENDIF.
SKIP.
WRITE: / 'Operating system:', AT 40 l_opsys.
WRITE: / 'Operating system version:', AT 40 l_release_os.
IF l_opsys_bits = 64.
WRITE: / 'Operating platform:', AT 40 '64-bit'.
ELSEIF l_opsys_bits = 32.
WRITE: / 'Operating platform:', AT 40 '32-bit'.
ELSE.
WRITE: / 'Warning:' COLOR COL_TOTAL, 'Unknown operating platform: 32 or 64-bits'.
ENDIF.
SKIP.
WRITE: / 'SAP Kernel release:', AT 40 l_kernel.
WRITE: / 'SAP Kernel patch level:', AT 40 l_kernel_patch.
SKIP.
IF cl_abap_char_utilities=>charsize = 1.
WRITE: / 'Unicode:', AT 40 'No'.
ELSE.
WRITE: / 'Unicode:', AT 40 'Yes'.
ENDIF.
IF cl_abap_char_utilities=>endian = 'L'.
WRITE: / 'Endian:', AT 40 'Little'.
ELSEIF cl_abap_char_utilities=>endian = 'B'.
WRITE: / 'Endian:', AT 40 'Big'.
ELSE.
WRITE: / 'Warning:' COLOR COL_TOTAL, 'Unknown endian'.
ENDIF.
ENDLOOP.
ELSE.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Getting list of application servers'.
ENDIF.
FORM ewa_get_hardware_info
USING
i_destination TYPE msname2
CHANGING
e_subrc TYPE sy-subrc
et_info TYPE yt_info.
DATA:
ls_info TYPE ys_info,
l_xml TYPE shwodescr,
lt_xml TYPE TABLE OF shwodescr,
l_return TYPE i, "#EC NEEDED
l_length TYPE i,
l_start TYPE i,
l_end TYPE i,
lx_xslt TYPE REF TO cx_xslt_runtime_error,
l_xpath TYPE string,
l_msg TYPE c LENGTH 250,
l_msg2 TYPE c LENGTH 250,
l_dummy TYPE string,
lr_xpath_processor TYPE REF TO cl_xslt_processor,
lr_ixml_nodes TYPE REF TO if_ixml_node_collection,
lr_iterator TYPE REF TO if_ixml_node_iterator,
lr_node TYPE REF TO if_ixml_node,
lr_nodemap TYPE REF TO if_ixml_named_node_map,
lr_attr TYPE REF TO if_ixml_node.
CLEAR: e_subrc, et_info.
* Get information from host controller (try twice)
CALL FUNCTION '/SDF/EWA_SAPOSCOL_B' "ST-PI add-on
DESTINATION i_destination
TABLES
result = lt_xml
EXCEPTIONS
connection_error = 1
saposcol_error = 2
file_p_error = 3
file_g_error = 4
hwinfo_error = 5
communication_failure = 6 MESSAGE l_msg
system_failure = 7 MESSAGE l_msg
OTHERS = 8.
IF sy-subrc <> 0.
CALL FUNCTION 'RZL_SLEEP'
EXPORTING
seconds = 5
EXCEPTIONS
argument_error = 1
OTHERS = 2.
IF sy-subrc = 0.
CALL FUNCTION '/SDF/EWA_SAPOSCOL_B' "ST-PI add-on
DESTINATION i_destination
TABLES
result = lt_xml
EXCEPTIONS
connection_error = 1
saposcol_error = 2
file_p_error = 3
file_g_error = 4
hwinfo_error = 5
communication_failure = 6 MESSAGE l_msg
system_failure = 7 MESSAGE l_msg
OTHERS = 8.
ENDIF.
ENDIF.
IF sy-subrc <> 0.
IF sy-subrc = 6 OR sy-subrc = 7.
WRITE: / 'Warning' COLOR COL_TOTAL, 'Error reading HW/OS information:', l_msg.
ELSE.
WRITE: / 'Warning' COLOR COL_TOTAL, 'Error reading HW/OS information:', sy-subrc, '(SAPOSCOL)'.
ENDIF.
e_subrc = 4.
ELSEIF lt_xml IS INITIAL.
WRITE: / 'Warning' COLOR COL_TOTAL, 'Error reading HW/OS information: No XML (See SAP Note 2690964)'.
e_subrc = 4.
ENDIF.
IF e_subrc <> 0.
WRITE: / 'Warning' COLOR COL_TOTAL, 'Update to latest SAP Host Agent (See SAP Note 2130510)'.
* Try another way
PERFORM ewa_get_hardware_info_syscall
USING i_destination CHANGING e_subrc et_info.
RETURN.
ENDIF.
l_xpath = '/sldinfo/group/class/instance/property'. "#EC NOTEXT
* Delete some lines we don't need or are not complete
DELETE lt_xml WHERE table_line CS '<?xml version'.
DELETE lt_xml WHERE table_line CS '<!--' AND table_line CS '-->'.
* Remove some properties which sometime cause overflow errors
* but are not required anyway
FIND '<property name="LogicalHostnames">' IN TABLE lt_xml
MATCH LINE l_start.
IF sy-subrc = 0.
FIND '</property>' IN TABLE lt_xml FROM l_start MATCH LINE l_end.
IF sy-subrc = 0.
DELETE lt_xml FROM l_start TO l_end.
ENDIF.
ENDIF.
FIND '<property name="OpSysPatchDetails">' IN TABLE lt_xml
MATCH LINE l_start.
IF sy-subrc = 0.
FIND '</property>' IN TABLE lt_xml FROM l_start MATCH LINE l_end.
IF sy-subrc = 0.
DELETE lt_xml FROM l_start TO l_end.
ENDIF.
ENDIF.
FIND '<property name="OpSysPatchSummary">' IN TABLE lt_xml
MATCH LINE l_start.
IF sy-subrc = 0.
FIND '</property>' IN TABLE lt_xml FROM l_start MATCH LINE l_end.
IF sy-subrc = 0.
DELETE lt_xml FROM l_start TO l_end.
ENDIF.
ENDIF.
* Clean-up end of line
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf(1)
IN TABLE lt_xml WITH space.
* Retrieve initial information from XML
CREATE OBJECT lr_xpath_processor.
TRY.
CALL METHOD lr_xpath_processor->set_source_table
EXPORTING
table = lt_xml.
lr_xpath_processor->set_expression( l_xpath ).
l_return = lr_xpath_processor->run( progname = '' ).
lr_ixml_nodes = lr_xpath_processor->get_nodes( ).
CATCH cx_xslt_runtime_error INTO lx_xslt.
l_length = strlen( lx_xslt->s2 ).
IF l_length > 50.
l_msg = lx_xslt->s2(50).
l_msg2 = lx_xslt->s2+50(*).
ELSE.
l_msg = lx_xslt->s2.
l_msg2 = ''.
ENDIF.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Error parsing HW/OS information (XPATH):'.
WRITE: / 'Error' COLOR COL_NEGATIVE, l_msg, l_msg2.
e_subrc = 4.
RETURN.
CATCH cx_root.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Error parsing HW/OS information (XSLT)'.
e_subrc = 4.
RETURN.
ENDTRY.
IF NOT lr_ixml_nodes IS BOUND.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Error parsing HW/OS information (IXML)'.
e_subrc = 4.
RETURN.
ENDIF.
* Process all nodes defined in path (property attributes and values)
l_length = lr_ixml_nodes->get_length( ).
lr_iterator = lr_ixml_nodes->create_iterator( ).
DO l_length TIMES.
TRY.
lr_node = lr_iterator->get_next( ).
lr_nodemap = lr_node->get_attributes( ).
lr_attr = lr_nodemap->get_named_item( name = 'name' ). "#EC NOTEXT
CLEAR ls_info.
ls_info-attname = lr_attr->get_value( ).
ls_info-attvalue = lr_node->get_value( ).
SHIFT ls_info-attvalue LEFT DELETING LEADING space.
CONDENSE ls_info-attvalue.
APPEND ls_info TO et_info.
CATCH cx_sy_ref_is_initial.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Error reading HW/OS information (XML)'.
e_subrc = 4.
RETURN.
ENDTRY.
ENDDO.
ENDFORM.
FORM ewa_get_hardware_info_syscall
USING i_destination TYPE msname2
CHANGING e_subrc TYPE sy-subrc
et_info TYPE yt_info.
DATA:
l_msg TYPE c LENGTH 250,
ls_info TYPE ys_info,
ls_srv_info TYPE bdi_log,
lt_srv_info TYPE TABLE OF bdi_log.
CLEAR l_msg.
CALL FUNCTION '/SDF/ASR_GET_INSTANCE_INFO'
DESTINATION i_destination
EXPORTING
coreinfoonly = abap_true
TABLES
srv_info = lt_srv_info
EXCEPTIONS
no_authority = 1
communication_failure = 2 MESSAGE l_msg
system_failure = 3 MESSAGE l_msg
OTHERS = 4.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Not authorized to read HW/OS information (SYSCALL)'.
WHEN 2 OR 3.
WRITE: / 'Error' COLOR COL_NEGATIVE, 'Error getting instance information:', l_msg.
ENDCASE.
e_subrc = 4.
RETURN.
ENDIF.
READ TABLE lt_srv_info INTO ls_srv_info
WITH KEY tcode = 'operating system'.
IF sy-subrc = 0.
ls_info-attname = 'OpSysCategory'.
ls_info-attvalue = ls_srv_info-comm.
APPEND ls_info TO et_info.
ENDIF.
READ TABLE lt_srv_info INTO ls_srv_info
WITH KEY tcode = 'OP system release'.
IF sy-subrc = 0.
ls_info-attname = 'OpSysRelease'.
ls_info-attvalue = ls_srv_info-comm.
APPEND ls_info TO et_info.
ENDIF.
ls_info-attname = 'OpSysBits'.
ls_info-attvalue = '0'. " n/a
APPEND ls_info TO et_info.
ls_info-attname = 'OpSysUname'.
ls_info-attvalue = 'n/a'.
APPEND ls_info TO et_info.
ENDFORM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment