Jump to content

SAP UDF - "session attach" problem.


Recommended Posts

I've got alittle tricky problem that I can't seem to figure out with the SAP UDF.

What I'm trying to do is builda simple script that will copy a network using the CN21 transaction.

The details are, go into CN21 fill out the network profile/type/plant/mrp controller.

Enter the network# to copy from. Click the "more" button and select the additional checkboxes to copy the WBS elements and settlement rules.

My code is hanging and I'm not too sure why.

I can get into the CN21 transaction but autoit shows an error on line 446 of the SAP UDF.

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id).text = $object_value

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id)^ ERROR

Can someone point me in the right direction? Is it failing because it can't find the box to enter the text, or that it can't find the sap session?

CODE
#include <SAP.au3>

; Prompt the user to run the script - use a Yes/No prompt

$question = MsgBox(4, "SAP Network Creator", "This Program will copy SAP networks using the CN21 transaction.")

; Check the user's answer to the prompt

; If "No" was clicked (7) then exit the script

If $question = 7 Then

MsgBox(4096, "SAP Network Creator", "Bye!")

Exit

EndIf

; Present user with a textbox to enter Numbers.

$answer = InputBox("SAP Network Exporter", "How many Networks do you want to Create? Hit CTRL + ALT + X at any time to stop the script.", "Enter Number of Networks to create.", " M3")

If @error = 1 Then

MsgBox(4096, "Error", "Goodbye!")

Exit

$networkqty = 0 ;Start count variable.

$networkqtyend = $answer ;Specify end variable that is user defined.

ElseIf @error = 0 Then

Do ; Start Executing SAP export Command Lines.

Opt("WinWaitDelay", 100)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

WinWait("[CLASS:SAP_FRONTEND_SESSION]", "")

If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]", "") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]", "")

WinWaitActive("[CLASS:SAP_FRONTEND_SESSION]", "")

; Before running this script, ensure the "SAP Easy Access" window is open.

; Attach to the session with the window titled "SAP Easy Access"

_SAPSessAttach("SAP Easy Access")

; Put the value "/ncn21" into the command field.

_SAPObjValueSet("tbar[0]/okcd", "/ncn21")

Sleep(250)

;Go into CN21 Transaction

_SAPVKeysSend("Enter")

Sleep(250)

; Attach to the session with the window titled "Create: Network: Initial Screen"

_SAPSessAttach("Create: Network: Initial Screen")

Sleep(250)

;Script stops running here....

_SAPObjValueSet("/usr/ctxtCAUFVD-PROFID", "XXXXX")

Sleep(250)

_SAPObjValueSet("/usr/ctxtAUFPAR-PS_AUFART", "XXXX")

Sleep(250)

_SAPObjValueSet("/usr/ctxtCAUFVD-WERKS", "1101")

Sleep(250)

_SAPObjValueSet("/usr/ctxtCAUFVD-DISPO", "001")

Sleep(250)

_SAPObjValueSet("/usr/ctxtRC62C-REFNR", "2290300")

Sleep(250)

_SAPObjSelect("/usr/btn%_AUTOTEXT002")

; Attach to the session with the window titled "Copy From..." and select WBS element and Settlement Rule checkboxes.

_SAPSessAttach("Copy from...")

Sleep(250)

_SAPObjPropertySet("/usr/chkRC62C-COPY_ASSG", "WBS elem./Sales ord.", True)

Sleep(250)

_SAPObjPropertySet("/usr/chkRC62C-COPY_SM", "Settlement Rule", True)

Sleep(250)

_SAPObjSelect("/tbar[0]/btn[0]")

Sleep(250)

; Attach to the session with the window titled "Network Create: Header Data" and change the Network Header

_SAPSessAttach("Network Create: Header Data")

;Exit back to the SAP Easy Access Screen

_SAPVKeysSend("F12")

;Go to Excel and copy the next network#

; Source code for exporting SAP Network is done.

$networkqty = $networkqty + 1

Sleep(150)

;Stop Looping until User Value is met.

Until $networkqty = $networkqtyend

; Display Print Message Because you're all done.

MsgBox(0, "SAP Network Creator", "Finished!")

Exit

EndIf

Link to comment
Share on other sites

I've got alittle tricky problem that I can't seem to figure out with the SAP UDF.

What I'm trying to do is builda simple script that will copy a network using the CN21 transaction.

The details are, go into CN21 fill out the network profile/type/plant/mrp controller.

Enter the network# to copy from. Click the "more" button and select the additional checkboxes to copy the WBS elements and settlement rules.

My code is hanging and I'm not too sure why.

I can get into the CN21 transaction but autoit shows an error on line 446 of the SAP UDF.

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id).text = $object_value

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id)^ ERROR

Can someone point me in the right direction? Is it failing because it can't find the box to enter the text, or that it can't find the sap session?

CODE
#include <SAP.au3>

; Prompt the user to run the script - use a Yes/No prompt

$question = MsgBox(4, "SAP Network Creator", "This Program will copy SAP networks using the CN21 transaction.")

; Check the user's answer to the prompt

; If "No" was clicked (7) then exit the script

If $question = 7 Then

MsgBox(4096, "SAP Network Creator", "Bye!")

Exit

EndIf

; Present user with a textbox to enter Numbers.

$answer = InputBox("SAP Network Exporter", "How many Networks do you want to Create? Hit CTRL + ALT + X at any time to stop the script.", "Enter Number of Networks to create.", " M3")

If @error = 1 Then

MsgBox(4096, "Error", "Goodbye!")

Exit

$networkqty = 0 ;Start count variable.

$networkqtyend = $answer ;Specify end variable that is user defined.

ElseIf @error = 0 Then

Do ; Start Executing SAP export Command Lines.

Opt("WinWaitDelay", 100)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

WinWait("[CLASS:SAP_FRONTEND_SESSION]", "")

If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]", "") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]", "")

WinWaitActive("[CLASS:SAP_FRONTEND_SESSION]", "")

; Before running this script, ensure the "SAP Easy Access" window is open.

; Attach to the session with the window titled "SAP Easy Access"

_SAPSessAttach("SAP Easy Access")

; Put the value "/ncn21" into the command field.

_SAPObjValueSet("tbar[0]/okcd", "/ncn21")

Sleep(250)

;Go into CN21 Transaction

_SAPVKeysSend("Enter")

Sleep(250)

; Attach to the session with the window titled "Create: Network: Initial Screen"

_SAPSessAttach("Create: Network: Initial Screen")

Sleep(250)

;Script stops running here....

_SAPObjValueSet("/usr/ctxtCAUFVD-PROFID", "XXXXX")

Sleep(250)

_SAPObjValueSet("/usr/ctxtAUFPAR-PS_AUFART", "XXXX")

Sleep(250)

_SAPObjValueSet("/usr/ctxtCAUFVD-WERKS", "1101")

Sleep(250)

_SAPObjValueSet("/usr/ctxtCAUFVD-DISPO", "001")

Sleep(250)

_SAPObjValueSet("/usr/ctxtRC62C-REFNR", "2290300")

Sleep(250)

_SAPObjSelect("/usr/btn%_AUTOTEXT002")

; Attach to the session with the window titled "Copy From..." and select WBS element and Settlement Rule checkboxes.

_SAPSessAttach("Copy from...")

Sleep(250)

_SAPObjPropertySet("/usr/chkRC62C-COPY_ASSG", "WBS elem./Sales ord.", True)

Sleep(250)

_SAPObjPropertySet("/usr/chkRC62C-COPY_SM", "Settlement Rule", True)

Sleep(250)

_SAPObjSelect("/tbar[0]/btn[0]")

Sleep(250)

; Attach to the session with the window titled "Network Create: Header Data" and change the Network Header

_SAPSessAttach("Network Create: Header Data")

;Exit back to the SAP Easy Access Screen

_SAPVKeysSend("F12")

;Go to Excel and copy the next network#

; Source code for exporting SAP Network is done.

$networkqty = $networkqty + 1

Sleep(150)

;Stop Looping until User Value is met.

Until $networkqty = $networkqtyend

; Display Print Message Because you're all done.

MsgBox(0, "SAP Network Creator", "Finished!")

Exit

EndIf

The SAP UDF was written by Sean Griffin, and you will heve more luck if you post this question in the appropiate threat.......Search the forum for SAP and you will find it.

(I think that Sean will receive an emial when a new comment is placed in that forum).

Best regards,

Jeweetwel.

Link to comment
Share on other sites

The SAP UDF was written by Sean Griffin, and you will heve more luck if you post this question in the appropiate threat.......Search the forum for SAP and you will find it.

(I think that Sean will receive an emial when a new comment is placed in that forum).

Best regards,

Jeweetwel.

Also, Sean will presumably start by asking about the details of the COM error (at least I would). So add a COM error handler to your script and report the exact error received.

This is a fundamental step to take in any script that uses COM objects.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks!

I'll try posting to the alternative thread.

Any good Com Error Handlers you suggest?

I read through the forum and am hijacking the one included as part of the IE UDF... any better ideas?

#include <IE.au3>

_IEErrorHandlerRegister()

Link to comment
Share on other sites

Thanks!

I'll try posting to the alternative thread.

Any good Com Error Handlers you suggest?

I read through the forum and am hijacking the one included as part of the IE UDF... any better ideas?

#include <IE.au3>

_IEErrorHandlerRegister()

Dale's handler in IE.au3 is a good one, there is also a working example in the help file under OBJ\COM Reference.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 3 weeks later...

Dale's handler in IE.au3 is a good one, there is also a working example in the help file under OBJ\COM Reference.

:D

Hi Guys,

Just for the record, the SAP UDF v0.4 has an error handler built-in. Just put the following code at the top of your script:

_SAPErrorHandlerRegister()

If a COM error occurs, you should get a detailed message in the console of AutoIT.

Yes I based my error handler on the one in IE.au3.

I'll answer the rest of this topic over at my SAP UDF topic.

Edited by seangriffin

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...