Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
marianoc
Active Contributor

In the previous document Script Recording & Playback for Dummies we learnt how to create a simple script in order to execute steps automatically in SAP.

Now, let´s introduce two new concepts to make this tool more powerful.

1- Collect ion of SAP Message

Let´s suppose that you create a script to create documents in SAP. In this case you probably need to get the document number generated by the system when Save button is pressed.

In this case, we need to add the following sentence:

     objExcel.Cells(i, 6).Value = session.findById("wnd[0]/sbar").Text

     where 6 is the number of the column where the message will be collected.

For example, suppose that we create a script to create planner orders, where the information that we introduce is:

Column1 = Order Type = LA

Column2 = Material

Column3 = MRP Area or Plant

Column4 = Quantity

Column5 = End Basic Date

The script will be the following:

If Not IsObject(application) Then

   Set SapGuiAuto  = GetObject("SAPGUI")

   Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

   Set connection = application.Children(0)

End If

If Not IsObject(session) Then

   Set session    = connection.Children(0)

End If

If IsObject(WScript) Then

   WScript.ConnectObject session,     "on"

   WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").maximize

REM CONEXAO COM O EXCEL ***********************

Dim objExcel

Dim objSheet, intRow, i

Set objExcel = GetObject(,"Excel.Application")

Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

REM OJO SIEMPRE LOS TITULOS DEL EXCEL TIENEN QUE ESTAR EN EL RENGLON 2 Y SOLO TENES QUE TENER UN SOLO EXCEL ACTIVO AL MOMENTO DE LANZAR EL JOB.

For i = 2 to objSheet.UsedRange.Rows.Count

cOL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Ordertype

cOL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Material

cOL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'MRP Area

cOL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) 'Quntity

cOL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) 'Date

REM CONEXAO COM O EXCEL ***********************

session.findById("wnd[0]/tbar[0]/okcd").text = "/nmd11"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtRM61P-PASCH").text = cOL1

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtPLAF-MATNR").text = cOL2

session.findById("wnd[0]/usr/ctxtPLAF-BERID").text = cOL3

session.findById("wnd[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/txtPLAF-GSMNG").text = cOL4

session.findById("wnd[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/ctxtPLAF-PEDTR").text = cOL5

session.findById("wnd[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/ctxtPLAF-PEDTR").setFocus

session.findById("wnd[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/ctxtPLAF-PEDTR").caretPosition = 8

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/tbar[0]/btn[11]").press

objExcel.Cells(i, 6).Value = session.findById("wnd[0]/sbar").Text

NEXT




2- Add IF logic in the script


Suppose that we need to execute some steps only if we achieve certain condition. In this case, we can add if logic in the script.

For example, we can enter in one column an X to indicate that the condition was achieved. Then in the script we have to add the IF and END IF:

IF COL10 = "X" THEN

END IF

where 6 is the number of the column where the message will be collected.

As an example, here you can see a script that createnew BINs in WM (LS01N) and execute the stock transfer (LT10) from the old to the new BIN only if there was stock in the old BIN:

If Not IsObject(application) Then

   Set SapGuiAuto  = GetObject("SAPGUI")

   Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

   Set connection = application.Children(0)

End If

If Not IsObject(session) Then

   Set session    = connection.Children(0)

End If

If IsObject(WScript) Then

   WScript.ConnectObject session,     "on"

   WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").maximize

REM --> Conexion con Excel**************************************

Dim objExcel

Dim objSheet, intRow, i

Set objExcel = GetObject(, "Excel.Application")

Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

For i = 2 to objSheet.UsedRange.Rows.Count

COL1    = Trim(CStr(objSheet.Cells(i, 1).Value))  'Warehouse

COL2   = Trim(CStr(objSheet.Cells(i, 2).Value))  'Storage Type

COL3    = Trim(CStr(objSheet.Cells(i, 3).Value))  'Bin

COL4    = Trim(CStr(objSheet.Cells(i, 4).Value))  'Storage Section

COL5    = Trim(CStr(objSheet.Cells(i, 5).Value))  'Verification ID

COL6    = Trim(CStr(objSheet.Cells(i, 6).Value))  'Picking Area

COL7    = Trim(CStr(objSheet.Cells(i, 7).Value))  'Storage Bin Type

COL8    = Trim(CStr(objSheet.Cells(i, 8).Value))  'Maximum Weight

COL9    = Trim(CStr(objSheet.Cells(i, 9).Value))  'Total Capacity

COL10   = Trim(CStr(objSheet.Cells(i, 10).Value)) 'Execute LT10? If we need it populate an X in Column 10.

COL11   = Trim(CStr(objSheet.Cells(i, 11).Value)) 'Old Storage Type

REM **************************************

session.findById("wnd[0]/tbar[0]/okcd").text = "/NLS01N"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtLAGP-LGNUM").text = COL1

session.findById("wnd[0]/usr/ctxtLAGP-LGTYP").text = COL2

session.findById("wnd[0]/usr/ctxtLAGP-LGPLA").text = COL3

session.findById("wnd[0]/usr/ctxtLAGP-LGPLA").setFocus

session.findById("wnd[0]/usr/ctxtLAGP-LGPLA").caretPosition = 6

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/ctxtLAGP-LGBER").text = COL4

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/txtLAGP-VERIF").text = COL5

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/ctxtLAGP-KOBER").text = COL6

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/ctxtLAGP-LPTYP").text = COL7

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/txtLAGP-LGEWI").text = COL8

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/txtLAGP-LKAPV").text = COL9

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/txtLAGP-LKAPV").setFocus

session.findById("wnd[0]/usr/tabsFUNC_TABSTRIP/tabpALLG/ssubD0400_S:SAPML01S:4001/txtLAGP-LKAPV").caretPosition = 8

session.findById("wnd[0]/tbar[0]/btn[11]").press

IF COL10 = "X" THEN

session.findById("wnd[0]/tbar[0]/okcd").text = "/NLT10"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtS1_LGNUM").text = COL1

session.findById("wnd[0]/usr/ctxtS1_LGTYP-LOW").text = COL11

session.findById("wnd[0]/usr/ctxtS1_LGPLA-LOW").text = COL3

session.findById("wnd[0]/usr/ctxtBWLVS-LOW").text = "999"

session.findById("wnd[0]/usr/radP_QUANT").select

session.findById("wnd[0]/usr/ctxtS1_LGPLA-LOW").setFocus

session.findById("wnd[0]/usr/ctxtS1_LGPLA-LOW").caretPosition = 6

session.findById("wnd[0]/tbar[1]/btn[8]").press

session.findById("wnd[0]/tbar[1]/btn[45]").press

session.findById("wnd[0]/tbar[1]/btn[48]").press

session.findById("wnd[1]/usr/chkRL03T-SQUIT").selected = true

session.findById("wnd[1]/usr/ctxtLAGP-LGTYP").text = COL2

session.findById("wnd[1]/usr/ctxtLAGP-LGPLA").text = COL3

session.findById("wnd[1]/usr/ctxtLTAK-BWLVS").text = "999"

session.findById("wnd[1]/usr/chkRL03T-SQUIT").setFocus

session.findById("wnd[1]/tbar[0]/btn[0]").press

END IF

session.findById("wnd[0]/tbar[0]/okcd").text = "/NLS02N"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtLAGP-LGNUM").text = COL1

session.findById("wnd[0]/usr/ctxtLAGP-LGTYP").text = COL11

session.findById("wnd[0]/usr/ctxtLAGP-LGPLA").text = COL3

session.findById("wnd[0]/usr/ctxtLAGP-LGPLA").caretPosition = 6

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/tbar[1]/btn[14]").press

session.findById("wnd[1]/usr/btnSPOP-OPTION1").press


NEXT

Good luck with both new concepts!!

11 Comments
Labels in this area