How to execute Transaction with mass data without ABAP coding using SAP Script Recording, 코딩없이 대량 데이타를 SAP 업로드 할 수 있나요?

In the realm of SAP, there exists a menu that holds significant value for both SAP users and consultants. Allow me to acquaint you with this menu, a gateway to executing transactions involving substantial data volumes, all without the need for intricate ABAP coding. Intrigued? Imagine a scenario where you effortlessly transfer vast data sets from Excel to SAP transactions, all facilitated by a bit of VBA coding.

This menu, known as "Script Recording and Playback" in SAP, is the key to this endeavor. To embark on this journey, simply copy the provided source code and paste it into the Visual Basic Editor. You can access this editor by launching Excel and pressing ALT+F11. The possibilities that unfold are truly captivating.

Absolutely, I'm here to help you through the process. Let's break it down step by step: 1. Review the SAP VBS File: First, let's thoroughly review the SAP VBS file I've provided below which will help you understand its content and identify the relevant portions to copy into the Excel VBA editor.




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]").resizeWorkingPane 130,29,false
session.findById("wnd[0]/tbar[0]/okcd").text = "/NLT01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtLTAK-BWLVS").text = "MvT" 'Change it accordingly
session.findById("wnd[0]/usr/ctxtLTAP-MATNR").text = "Material No" 'Change it accordingly 
session.findById("wnd[0]/usr/txtRL03T-ANFME").text = "1"
session.findById("wnd[0]/usr/ctxtLTAP-WERKS").text = "Plant" 'Change it accordingly 
session.findById("wnd[0]/usr/ctxtLTAP-LGORT").text = "SLoc" 'Change it accordingly 
session.findById("wnd[0]/usr/ctxtLTAP-LGORT").setFocus
session.findById("wnd[0]/usr/ctxtLTAP-LGORT").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtLTAP-LETYP").text = "00"
session.findById("wnd[0]/usr/ctxtLTAP-VLTYP").text = "SSty" 'Change it accordingly
session.findById("wnd[0]/usr/ctxtLTAP-NLTYP").text = "DSty" 'Change it accordingly
session.findById("wnd[0]/usr/txtLTAP-NLPLA").text = "BIN_NO" 'Change it accordingly 
session.findById("wnd[0]/usr/txtLTAP-NLPLA").setFocus
session.findById("wnd[0]/usr/txtLTAP-NLPLA").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/okcd").text = "/n"
session.findById("wnd[0]").sendVKey 0


2. Copy Relevant Sentences: Identify the specific sentences or code blocks within the SAP VBS file that you want to integrate into your Excel VBA script. Copy these sections. 3. Open Excel and Access VBA Editor: Launch Microsoft Excel and press `ALT+F11` to open the Visual Basic for Applications (VBA) editor.

4. Insert a Button: Go to the "Developer" tab in Excel, which you can enable in Excel options if it's not visible. From the "Insert" menu, select the button or form control box that you'd like to use as your macro trigger. 5. Assign the Macro: After inserting the button, you can assign the macro you're creating (the VBA script) to this button. Right-click the button, choose "Assign Macro," and select the appropriate macro from the list. 6. Paste and Modify the Code: In the VBA editor, create a new module if you haven't already. Paste the code you copied from the SAP VBS file. Make any necessary modifications to adapt the code for Excel VBA.
Sub CreateTO_LT01() 'LT01

' Keyboard Shortcut: Ctrl+a
'
    Dim SapGui
    Dim Application
    Dim connection
    Dim session
    Dim WSHShell
    Dim ObjR3
    Dim Grid
    Dim sap_message
    Dim lastRow As Long
    Dim i As Long
        
    ' Assuming you want to write the sap_message to cell A2 in "Sheet1"
    Dim DestinationSheet As Worksheet
    
    Set SheetName = ThisWorkbook.Sheets("Sheet1")
        
    lastRow = ThisWorkbook.Sheets("Sheet1").Cells(ThisWorkbook.Sheets("Sheet1").Rows.Count, "A").End(xlUp).Row
    
    Set WSHShell = Nothing
    Set SapGui = GetObject("SAPGUI")
    Set Application = SapGui.GetScriptingEngine
    
    Set connection = Application.Children(0)
    Set session = connection.Children(0)


    ' Loop through each row in the Excel sheet
    For i = 2 To lastRow
        ' Start of LT01
        session.findById("wnd[0]").resizeWorkingPane 130, 29, False
        session.findById("wnd[0]/tbar[0]/okcd").Text = "/NLT01"
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/usr/ctxtLTAK-BWLVS").Text = "999"
        session.findById("wnd[0]/usr/ctxtLTAP-MATNR").Text = ThisWorkbook.Sheets("Sheet1").Cells(i, 1).Value
        session.findById("wnd[0]/usr/txtRL03T-ANFME").Text = ThisWorkbook.Sheets("Sheet1").Cells(i, 2).Value
        session.findById("wnd[0]/usr/ctxtLTAP-WERKS").Text = "Plant" 'Change it accordingly
        session.findById("wnd[0]/usr/ctxtLTAP-LGORT").Text = "SLoc" 'Change it accordingly
        session.findById("wnd[0]/usr/ctxtLTAP-LGORT").SetFocus
        session.findById("wnd[0]/usr/ctxtLTAP-LGORT").caretPosition = 4
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/usr/ctxtLTAP-LETYP").Text = "00"
        session.findById("wnd[0]/usr/ctxtLTAP-VLTYP").Text = ThisWorkbook.Sheets("Sheet1").Cells(i, 3).Value 'Source S.type
        session.findById("wnd[0]/usr/ctxtLTAP-NLTYP").Text = ThisWorkbook.Sheets("Sheet1").Cells(i, 4).Value ''Dest.S.type
        session.findById("wnd[0]/usr/txtLTAP-NLPLA").Text = ThisWorkbook.Sheets("Sheet1").Cells(i, 5).Value 'Dest.Bin
        session.findById("wnd[0]/usr/txtLTAP-NLPLA").SetFocus
        session.findById("wnd[0]/usr/txtLTAP-NLPLA").caretPosition = 9
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]").sendVKey 0

        
        ' Your existing code to perform LT01 transaction
        
        sap_message = session.findById("wnd[0]/sbar").Text ' Transfer order No
        SheetName.Cells(i, 6).Value = sap_message

        ' You can use sap_message or perform any other actions with it
        
        ' Insert code here to handle the next row of data or perform any other necessary actions
    Next i

    session.findById("wnd[0]/tbar[0]/okcd").Text = "/n"
    session.findById("wnd[0]").sendVKey 0
        
        ' End of LT01

End Sub
7. Test the Macro: Save your Excel file, exit the VBA editor, and click the button you inserted. This should execute the macro and perform the desired action based on the code you integrated.
Material         Qty Dest.S.type Message Material No1 1 204         Transfer order 0000028491 created Material No2 2 204         Transfer order 0000028492 created Material No3 3 204         Transfer order 0000028493 created

8. Learn and Refine: If you encounter any errors or issues, don't worry; it's all part of the learning process. Review the error messages, make adjustments, and continue refining your macro until it works as intended. Remember, the journey of learning and experimenting with VBA can be both exciting and rewarding. If you encounter specific issues or have questions along the way, feel free to ask, and I'll be here to assist you. Happy coding!

Comments

Popular posts from this blog

How to automate how to process mass transaction without ABAP code (SAP ABAP coding 하지 않고 엑셀 매크로 VBA로 SAP 생산오더 만들기)

Material Label as a industry standard on traceability along the whole supply chain.