Skip to Content

Looping a SAPscript

Hello!

I'm using a Excel macro with a connection to SAP with the purpose to, in VA02, set system status RREC on sales order items. As the amount of item lines are unknown in each case, I want a macro that goes backwards from the last item and sets the status from the last item all the way up to item 100 which is always the first line item.

This is the idea,

It enters transaction va02

Enters the sales order

Click the button that scrolls the list all the way down

Up arrow to get to the actual last item

Goto, Item, Status

Object status

Check RREC status

Back

And now I want to loop it so it does this until the last (which is the actual first, line item 100).

session.findById("wnd[0]").resizeWorkingPane 150,25,false
session.findById("wnd[0]/tbar[0]/okcd").text = "va02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = "3405192"
session.findById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 7
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[83]").press
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,3]").setFocus
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,3]").caretPosition = 0
session.findById("wnd[0]/mbar/menu[2]/menu[2]/menu[13]").select
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\12/ssubSUBSCREEN_BODY:SAPMV45A:4456/btnBT_PSTC").press
session.findById("wnd[0]/usr/tabsTABSTRIP_0300/tabpANWS/ssubSUBSCREEN:SAPLBSVA:0302/sub:SAPLBSVA:0302[2]/chkJ_STMAINT-ANWSO[0,0]").selected = true
session.findById("wnd[0]/usr/tabsTABSTRIP_0300/tabpANWS/ssubSUBSCREEN:SAPLBSVA:0302/sub:SAPLBSVA:0302[2]/chkJ_STMAINT-ANWSO[0,0]").setFocus
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[1]/btn[18]").press
session.findById("wnd[0]/tbar[0]/btn[11]").press

I don't know if this loop is supposed to be in the Excel code or in this SAPscript code.

Anyone?

BR Mattias

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Nov 22, 2011 at 06:21 PM

    Hi Matthias,

    the part you need to "Loop" is this:

    for i = 1 to 100    'Simple for - next !
    'session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = "3405192" 
    'replace with :
    session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = sht.cells(i,1).value  '<-- Necessary (Cell A1) for example
    session.findById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 7
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[1]").sendVKey 0
    session.findById("wnd[0]/tbar[0]/btn[83]").press
    session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,3]").setFocus
    session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,3]").caretPosition = 0
    session.findById("wnd[0]/mbar/menu[2]/menu[2]/menu[13]").select
    session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\12/ssubSUBSCREEN_BODY:SAPMV45A:4456/btnBT_PSTC").press
    session.findById("wnd[0]/usr/tabsTABSTRIP_0300/tabpANWS/ssubSUBSCREEN:SAPLBSVA:0302/sub:SAPLBSVA:0302[2]/chkJ_STMAINT-ANWSO[0,0]").selected = true
    session.findById("wnd[0]/usr/tabsTABSTRIP_0300/tabpANWS/ssubSUBSCREEN:SAPLBSVA:0302/sub:SAPLBSVA:0302[2]/chkJ_STMAINT-ANWSO[0,0]").setFocus
    session.findById("wnd[0]/tbar[0]/btn[3]").press
    session.findById("wnd[0]/tbar[1]/btn[18]").press
    session.findById("wnd[0]/tbar[0]/btn[11]").press
    next 
    

    To Refer the Sheet and Cells you should have this:

    if youre Working with excel this should com in First

    set sht = Application.ActiveWorkbook.Sheets("Tabelle1") 'or else
    

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello!

      Thanks for your answer, it actually worked. Had to do some editing in my script too.

      But now there is another "problem". As I said the number of item lines on each sales order differs. So with this example sales order of 13 item lines, the macro is trying on and on to set the status on the "next" item line (up to a 100 i guess?), when there is only 13 items. Is there a solution for it to automatically detect when it is on the last item line and then to move on to the next sales order? That would save alot of time.

      This is how the macro looks now (there is a lot of excel stuff in it which is not posted).

      SONumber = ActiveCell.Offset(0, 1).Value
      SOItem = ActiveCell.Offset(0, 2).Value
      
      session.findById("wnd[0]").maximize
      session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = SONumber
      session.findById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 7
      session.findById("wnd[0]").sendVKey 0
      session.findById("wnd[1]").sendVKey 0
      session.findById("wnd[0]/tbar[0]/btn[83]").press
      
      For i = 1 To 100    'Simple for - next !
      
      session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,12]").SetFocus
      session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,12]").caretPosition = 0
      session.findById("wnd[0]/mbar/menu[2]/menu[2]/menu[13]").Select
      session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\12/ssubSUBSCREEN_BODY:SAPMV45A:4456/btnBT_PSTC").press
      session.findById("wnd[0]/usr/tabsTABSTRIP_0300/tabpANWS/ssubSUBSCREEN:SAPLBSVA:0302/sub:SAPLBSVA:0302[2]/chkJ_STMAINT-ANWSO[0,0]").Selected = True
      session.findById("wnd[0]/usr/tabsTABSTRIP_0300/tabpANWS/ssubSUBSCREEN:SAPLBSVA:0302/sub:SAPLBSVA:0302[2]/chkJ_STMAINT-ANWSO[0,0]").SetFocus
      session.findById("wnd[0]/tbar[0]/btn[3]").press
      session.findById("wnd[0]/tbar[1]/btn[18]").press
      
      Next
      
      session.findById("wnd[0]/tbar[0]/btn[11]").press

      Points awarded.

      Thanks, Mattias

  • Posted on Nov 23, 2011 at 02:14 PM

    Main problem was answered while another similar problem occured.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.