[SAP ABAP] Get Physical Memory Information

*----------------------------------------------------------------------
* Created By : Albertus Reinandang
* Date       : 14.05.2018
* OS Support : Unix Base
*----------------------------------------------------------------------
REPORT yrun_get_memory LINE-SIZE 512 NO STANDARD PAGE HEADING.


TABLES : tab512.

TYPES : BEGIN OF ty_info,
          datum LIKE sy-datum,
          uzeit LIKE sy-uzeit,
          field01(20),
          field02(20),
          field03(20),
          field04(20),
          field05(20),
          field06(20),
          field07(20),
          field08(20),
          field09(20),
          field10(20),
          field11(20),
          field12(20),
          field13(20),
          field14(20),
          field15(20),
          field16(20),
          field17(20),
          field18(20),
          field19(20),
          field20(20),
        END OF ty_info.

DATA : gi_header TYPE STANDARD TABLE OF ty_info WITH HEADER LINE.

PARAMETERS : pa_time TYPE i DEFAULT 120.

START-OF-SELECTION.

  WRITE : /(10) 'Date' CENTERED COLOR COL_KEY, (8) 'Time' CENTERED COLOR COL_KEY,
           (20) 'total memory' CENTERED, (20) 'used memory' CENTERED, (20) 'active memory' CENTERED, (20) 'inactive memory' CENTERED,

(20) 'free memory' CENTERED,
           (20) 'buffer memory' CENTERED, (20) 'swap cache' CENTERED, (20) 'total swap' CENTERED, (20) 'used swap' CENTERED, (20)

'free swap' CENTERED.

  DO pa_time TIMES.
    WAIT UP TO 1 SECONDS.
    PERFORM fm_get_memory.
  ENDDO.

*&---------------------------------------------------------------------*
*&      Form  fm_get_memory
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM fm_get_memory.
  DATA : li_return LIKE STANDARD TABLE OF tab512 WITH HEADER LINE.
  DATA : lw_header LIKE gi_header.

  REFRESH : li_return[].

  CALL 'SYSTEM' ID 'COMMAND' FIELD 'vmstat -s'
                ID 'TAB'     FIELD li_return[].
  IF LINES( li_return ) > 0.
*    READ TABLE li_return INDEX 3.
*    IF sy-subrc = 0.
*      SPLIT li_return-wa AT space INTO lw_header-field01 lw_header-field02 lw_header-field03 lw_header-field04 lw_header-field05
*                                       lw_header-field06 lw_header-field07 lw_header-field08 lw_header-field09 lw_header-field10.
*      lw_header-datum = sy-datum.
*      lw_header-uzeit = sy-uzeit.
*      APPEND lw_header TO gi_header.
*    ENDIF.
    LOOP AT li_return.
      CASE sy-tabix.
        WHEN 1.
          lw_header-field01 = li_return-wa(13).
        WHEN 2.
          lw_header-field02 = li_return-wa(13).
        WHEN 3.
          lw_header-field03 = li_return-wa(13).
        WHEN 4.
          lw_header-field04 = li_return-wa(13).
        WHEN 5.
          lw_header-field05 = li_return-wa(13).
        WHEN 6.
          lw_header-field06 = li_return-wa(13).
        WHEN 7.
          lw_header-field07 = li_return-wa(13).
        WHEN 8.
          lw_header-field08 = li_return-wa(13).
        WHEN 9.
          lw_header-field09 = li_return-wa(13).
        WHEN 10.
          lw_header-field10 = li_return-wa(13).
        WHEN 11.
          lw_header-field11 = li_return-wa(13).
        WHEN 12.
          lw_header-field12 = li_return-wa(13).
        WHEN 13.
          lw_header-field13 = li_return-wa(13).
        WHEN 14.
          lw_header-field14 = li_return-wa(13).
        WHEN 15.
          lw_header-field15 = li_return-wa(13).
        WHEN OTHERS.
      ENDCASE.
    ENDLOOP.
    lw_header-datum = sy-datum.
    lw_header-uzeit = sy-uzeit.
    APPEND lw_header TO gi_header.

    WRITE : / lw_header-datum, lw_header-uzeit,
              lw_header-field01, lw_header-field02, lw_header-field03, lw_header-field04, lw_header-field05,
              lw_header-field06, lw_header-field07, lw_header-field08, lw_header-field09, lw_header-field10.
  ENDIF.

ENDFORM.                    "fm_get_memory

Comments