Pages

Saturday, 29 August 2015

How to read SAP locks using Excel

How to read SAP locks using Excel

In previous documents we saw how to login and call function modules using excel. In this document we will apply the logic to reading SM12 locks entries. We have a function module "Enqueue_Report", which can can used for our purpose. We need to pass Client number, username if needed. The output is a table just like in SM12. and we draw it in excel


Sample Code
 Sub readSM12(R3 As Object)
' calling next func
Set myFuncMTE = R3.Add("ENQUEUE_REPORT")

' loading SAP functions input parameters
Dim ZCLIENT, ZNAME, ZTARG, ZUNAME As Object
    Set ZCLIENT = myFuncMTE.exports("GCLIENT")
           ZCLIENT.Value = Sheets("Main").Cells(8, 3)
    Set ZNAME = myFuncMTE.exports("GNAME")
           ZNAME.Value = ""
    Set ZTARG = myFuncMTE.exports("GTARG")
           ZTARG.Value = ""
    Set ZUNAME = myFuncMTE.exports("GUNAME")
           ZUNAME.Value = ""
' calling SAP Func
    If myFuncMTE.call = False Then
           MsgBox myFuncMTE.Exception
    End If
' Passing SAP output to Excel variables    
    Set ENQ = myFuncMTE.Tables("ENQ")
    Set Number = myFuncMTE.imports("NUMBER")
    
    For j = 1 To Number
              Sheets("SM12").Cells(j + 1, 1) = ENQ.Value(j, "GCLIENT")
              Sheets("SM12").Cells(j + 1, 2) = ENQ.Value(j, "GUNAME")
              Sheets("SM12").Cells(j + 1, 3) = ENQ.Value(j, "GTDATE")
              Sheets("SM12").Cells(j + 1, 4) = ENQ.Value(j, "GTTIME")
              Sheets("SM12").Cells(j + 1, 5) = ENQ.Value(j, "GMODE")
              Sheets("SM12").Cells(j + 1, 6) = ENQ.Value(j, "GNAME")
              Sheets("SM12").Cells(j + 1, 7) = ENQ.Value(j, "GARG")
              Sheets("SM12").Cells(j + 1, 8) = ENQ.Value(j, "GUSE")
              Sheets("SM12").Cells(j + 1, 9) = ENQ.Value(j, "GUSEVB")
    Next
    
    Set myFuncMTE = Nothing
    Sheets("Main").Cells(14, 5) = Number

End Sub



No comments:

Post a Comment