hexagon logo

SAP Scripting

Hey I need some non PC-DMIS Scripting help....

Do any of you guys have any experience with scripting in SAP?

What I'm trying to do is write a script that runs a report for me. I have it reporting the data and saving it but I cant figure out how to set the dates to the previous week. currently it is just running the report for the days I selected. I can post the code if that helps.
  • Code below. Bold section is what I need help with.

    session.findById("wnd[0]").resizeWorkingPane 130,37,false
    session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00021"
    session.findById("wnd[1]/usr/lbl[15,4]").setFocus
    session.findById("wnd[1]/usr/lbl[15,4]").caretPosition = 12
    session.findById("wnd[1]").sendVKey 2
    session.findById("wnd[0]/usr/btn%_SL_0009_%_APP_%-VALU_PUSH").press
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]").text = ""
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpNOSV").select
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL_255-SLOW_E[1,0]").text = "Repack"
    session.findById("wnd[1]/usr/tabsTAB_STRIP/tabpNOSV/ssubSCREEN_HEADER:SAPLALDB:3030/tblSAPLALDBSINGLE_E/ctxtRSCSEL_255-SLOW_E[1,0]").caretPosition = 6
    session.findById("wnd[1]/tbar[0]/btn[8]").press
    session.findById("wnd[0]/usr/ctxtSL_SPTAG-LOW").setFocus
    session.findById("wnd[0]/usr/ctxtSL_SPTAG-LOW").caretPosition = 5
    session.findById("wnd[0]").sendVKey 4
    session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = "20210913"
    session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").selectionInterval = "20210913,20210913"
    session.findById("wnd[0]/usr/ctxtSL_SPTAG-HIGH").setFocus
    session.findById("wnd[0]/usr/ctxtSL_SPTAG-HIGH").caretPosition = 4
    session.findById("wnd[0]").sendVKey 4
    session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = "20210919"
    session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").selectionInterval = "20210919,20210919"

    session.findById("wnd[0]/tbar[1]/btn[8]").press
    session.findById("wnd[0]/tbar[1]/btn[20]").press
    session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").select
    session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").setFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "test.xls"
    session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 8
    session.findById("wnd[1]/tbar[0]/btn[11]").press
  • I used to record mouse and key presses/clicks and slightly edit them to suit. The code to search up is VBScript or VBS. Used this way back like 6-7yrs ago. I don't remember enough to be of some help but does changing the date on some of the highlighted lines do anything for you?

    Again search up VBS you can do neat stuff with it like input/message boxes similar to Pc-Dmis.
  • I used to record mouse and key presses/clicks and slightly edit them to suit. The code to search up is VBScript or VBS. Used this way back like 6-7yrs ago. I don't remember enough to be of some help but does changing the date on some of the highlighted lines do anything for you?

    Again search up VBS you can do neat stuff with it like input/message boxes similar to Pc-Dmis.


    Yeah i could physically change the date in the code if i needed to but i want it to be automatic. I have it set up so that it opens the calendar to the correct week but it wont actually filter the search. here is the code for that

    Set Calendar = session.findById("wnd[0]/usr/cntlC_V_NAVIGATOR/shellcont/shell")
    varMonth = Calendar.GetMonth(Calendar.Today)
    varDay = Calendar.GetDay(Calendar.Today)
    varWeek = Calendar.GetWeekNumber(Calendar.Today)
    If varMonth = 1 and varDay <= 7 Then
    If varWeek = 1 Then
    varWeek = 52 - 1 'The index starts with 0
    End If
    varYear = Calendar.GetYear(Calendar.Today) - 1
    Else
    varYear = Calendar.GetYear(Calendar.Today)
    End If
    Calendar.SelectWeek varWeek, varYear
  • Update.... IT saw that I was scripting and blocked access to scripting for the entire plant. So there goes that haha.
  • that is not only insane, it is STUPIDLY insane. Yeah, take away your tool box, then expect you to do your job efficiently.
  • That's what I'm saying. They didn't even notify me when it happened. I just found out once I was going to test my code. However... If they wont let me do it ill tell them to write me the code. I have already proven it to work. It normally takes about 3-4 hours a week to run these reports and format them in excel. I wrote a script to do it in 48 seconds. That includes saving the files under a new name and sending the data out in an email.

    That is a 99.64% time savings for the year. It wont be very hard to argue my side. 181 hours and 29 mins saved annually. or 22.6 work days. or 4.5 work weeks. I believe I will win this battle haha.
  • nice lean savings! i worked for a place (Corning) that would give you 1% of any hard cost savings that could save over $1,000/yr.
    Some dude suggested a on-site gold reclamation plant, instead of using a third party, which they knew were skimming the returns. They determined it saved the company >3 million a year, so he got a $30k award for the idea. It had to be hard cost savings.

    Labor/burden rates are soft-cost, until you can lose a headcount as a result of the savings (byebye coworker though).
  • The military did something very similar to that for the longest time. I believe it was 1% or something like that. Up until a guy suggested that the pilots should stop doing touch and go's when training in air craft. (basically just touch the runway and take off again) Since this would rapidly deteriorate the tires on the aircraft. This saved a stupidly ridiculous amount of money.

    Conveniently after that they put in a $15,000 cap for payouts.
  • Update.... IT saw that I was scripting and blocked access to scripting for the entire plant. So there goes that haha.


    Owner tried pulling that one on me but I defended the idea of scripting due to the fact that it only automates what a logged on user can do and has access to on SAP. If you wanted to do damage then you could skip the automation and manually click away.... dumb. Though, I did manage to clock in/out with scripting and Outlook VBA LOL! So, then again I don't blame them.