Quantcast
Channel: SCN : Blog List - All Communities
Viewing all articles
Browse latest Browse all 2548

Download Workload Statistics as CSV via RFC and CCo

$
0
0

Hello community,

 

RFC connections offers a lot of possibilities. Here is an example how to download workload statistics as CSV file. Normally you get this information via the Workload Monitor - TAC ST03. On this way you have the possibility to download this kind of information from different systems automatically For this example I use COM connector (CCo) and VBScript. The information I get from the FM SWNC_GET_WORKLOAD_STATISTIC. I get the top response time of dialog steps and top DB accesses of dialog steps.

 

Enjoy it.

 

Cheers

Stefan

 

 

'-Begin-----------------------------------------------------------------

'-

'- To execute this script your user needs a role with the authorization

'- object S_RFC, the activity execute (16), the type Function group and

'- with the names RFC1, SCSM_GLOB_SYSTEM, SDIFRUNTIME and SYST

'-

'-----------------------------------------------------------------------

 

  '-Directives----------------------------------------------------------

    Option Explicit

 

  '-Constants-----------------------------------------------------------

    Const RFC_OK = 0

    Const Sep = ";"

 

  '-Sub getStat---------------------------------------------------------

    Sub getStat(strConn, SID, PeriodStart)

 

      '-Variables-------------------------------------------------------

        Dim SAP, hRFC, rc, hFuncDesc, hFunc, hTable, RowCount, i, hRow

        Dim charBuffer, Stat, fltBuffer, FSO, oFile

 

      Set SAP = CreateObject("COMNWRFC")

      If IsObject(SAP) Then

        SAP.UsePwdRequest = 0

        rc = SAP.RfcSetIniPath("C:\Dummy")

        hRFC = SAP.RfcOpenConnection(strConn)

        If hRFC Then

 

          hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, _

            "SWNC_GET_WORKLOAD_STATISTIC")

          If hFuncDesc Then

            hFunc = SAP.RfcCreateFunction(hFuncDesc)

            If hFunc Then

 

              rc = SAP.RfcSetChars(hFunc, "SYSTEMID", SID)

              rc = SAP.RfcSetChars(hFunc, "INSTANCE", "TOTAL")

              rc = SAP.RfcSetChars(hFunc, "PERIODTYPE", "M")

              rc = SAP.RfcSetDate(hFunc, "PERIODSTRT", PeriodStart)

 

              If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then

 

                '-Top Response Time of Dialog Steps (All data)----------

                If SAP.RfcGetTable(hFunc, "HITLIST_RESPTIME", hTable) = _

                  RFC_OK Then

 

                  rc = SAP.RfcGetRowCount(hTable, RowCount)

                  rc = SAP.RfcMoveToFirstRow(hTable)

 

                  Stat = ""

 

                  For i = 1 To RowCount

                    hRow = SAP.RfcGetCurrentRow(hTable)

 

                    rc = SAP.RfcGetChars(hRow, "ACCOUNT", charBuffer, 12)

                    Stat = Stat & charBuffer & Sep                 'User

                    rc = SAP.RfcGetChars(hRow, "TCODE", charBuffer, 20)

                    Stat = Stat & charBuffer & Sep 'Report / Transaction

                    rc = SAP.RfcGetChars(hRow, "REPORT", charBuffer, 40)

                    Stat = Stat & charBuffer & Sep 'Name of ABAP Program

                    rc = SAP.RfcGetFloat(hRow, "DBCALLS", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep           'Calls

                    rc = SAP.RfcGetFloat(hRow, "RESPTI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep      'Resp. Time

                    rc = SAP.RfcGetFloat(hRow, "PROCTI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep      'Proc. Time

                    rc = SAP.RfcGetFloat(hRow, "QUEUETI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep       'Wait Time

                    rc = SAP.RfcGetFloat(hRow, "CPUTI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & vbCrLf     'CPU Time

 

                    If i < RowCount Then

                      rc = SAP.RfcMoveToNextRow(hTable)

                    End If

                  Next

 

                  Set FSO = CreateObject("Scripting.FileSystemObject")

                  Set oFile = FSO.CreateTextFile("C:\Dummy\" & SID & _

                    "_" & PeriodStart & "_Hitlist_Resptime.csv", True)

                  oFile.Write "ACCOUNT" & Sep & "TCODE" & Sep & _

                    "REPORT" & Sep & "DBCALLS" & Sep & "RESPTI" & _

                    Sep & "PROCTI" & Sep & "QUEUETI" & Sep & _

                    "CPUTI" & vbCrLf

                  oFile.Write Stat

                  oFile.Close

                  Set FSO = Nothing

 

                End If

 

                '-Top DB Accesses of Dialog Steps (All data)------------

                If SAP.RfcGetTable(hFunc, "HITLIST_DATABASE", hTable) = _

                  RFC_OK Then

 

                  rc = SAP.RfcGetRowCount(hTable, RowCount)

                  rc = SAP.RfcMoveToFirstRow(hTable)

 

                  Stat = ""

 

                  For i = 1 To RowCount

                    hRow = SAP.RfcGetCurrentRow(hTable)

 

                    rc = SAP.RfcGetChars(hRow, "ACCOUNT", charBuffer, 12)

                    Stat = Stat & charBuffer & Sep                 'User

                    rc = SAP.RfcGetChars(hRow, "TCODE", charBuffer, 20)

                    Stat = Stat & charBuffer & Sep 'Report / Transaction

                    rc = SAP.RfcGetChars(hRow, "REPORT", charBuffer, 40)

                    Stat = Stat & charBuffer & Sep 'Name of ABAP Program

                    rc = SAP.RfcGetFloat(hRow, "DBCALLS", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep           'Calls

                    rc = SAP.RfcGetFloat(hRow, "RESPTI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep      'Resp. Time

                    rc = SAP.RfcGetFloat(hRow, "PROCTI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep      'Proc. Time

                    rc = SAP.RfcGetFloat(hRow, "QUEUETI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & Sep       'Wait Time

                    rc = SAP.RfcGetFloat(hRow, "CPUTI", fltBuffer)

                    Stat = Stat & CStr(fltBuffer) & vbCrLf     'CPU Time

 

                    If i < RowCount Then

                      rc = SAP.RfcMoveToNextRow(hTable)

                    End If

                  Next

 

                  Set FSO = CreateObject("Scripting.FileSystemObject")

                  Set oFile = FSO.CreateTextFile("C:\Dummy\" & SID & _

                    "_" & PeriodStart & "_Hitlist_Database.csv", True)

                  oFile.Write "ACCOUNT" & Sep & "TCODE" & Sep & _

                    "REPORT" & Sep & "DBCALLS" & Sep & "RESPTI" & _

                    Sep & "PROCTI" & Sep & "QUEUETI" & Sep & _

                    "CPUTI" & vbCrLf

                  oFile.Write Stat

                  oFile.Close

                  Set FSO = Nothing

 

                End If

              End If

              rc = SAP.RfcDestroyFunction(hFunc)

            End If

          End If

 

          rc = SAP.RfcCloseConnection(hRFC)

        End If

        Set SAP = Nothing

      End If

 

    End Sub

 

  '-Sub Main------------------------------------------------------------

    Sub Main()

 

      '-Variables-------------------------------------------------------

        Dim PeriodStart

 

      PeriodStart = "20151201"

 

      getStat "DEST=NSP", "NSP", PeriodStart

      getStat "DEST=NPL", "NPL", PeriodStart

 

      MsgBox "Ready"

 

    End Sub

 

 

  '-Main----------------------------------------------------------------

    Main()

 

'-End-------------------------------------------------------------------

 


Viewing all articles
Browse latest Browse all 2548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>