Jump to content

Recommended Posts

  • 2 weeks later...

This is great -  It's cool to see someone else interested in AS400 automation!

A few years ago I developed an application for my employer that automated iSeries and wrote a massive library to operate on these PCOMM classes. I found that using the AutScreenDesc class was a very reliable way of waiting for a screen by first describing it then calling the WaitForScreen() method. Alternatively, the WaitForString() and WaitForStringInRect() methods work just as well.

I also found the SetConnectionByHandle() method was a bit more reliable when dealing with multiple sessions.

I wish I could share the lib, but unfortunately it technically doesn't belong to me :(

Though IBM provides a wealth of knowledge on these classes here and even provide VB example code which makes it super easy to translate into AU3.

Link to post
Share on other sites
  • 2 months later...

Welcome to the AS400 world :D

PTFs are the windows updates of AS400, so IBM are providing them ;)

Fyi all moderns AS400 are virtual and run on an IBM hypervisior (the same way a VM runs on ESXi), so I recommend you backup your virtual AS400 image before trying anything ;) 

Link to post
Share on other sites
5 hours ago, Neutro said:

Welcome to the AS400 world :D

PTFs are the windows updates of AS400, so IBM are providing them ;)

Fyi all moderns AS400 are virtual and run on an IBM hypervisior (the same way a VM runs on ESXi), so I recommend you backup your virtual AS400 image before trying anything ;) 

Not ours.  Not one but 2 physical machines :)

and we have a TON of other servers and services that interface it.

Some of those might be virtual, not sure yet.

Edited by ViciousXUSMC
Link to post
Share on other sites
13 hours ago, ViciousXUSMC said:

Not ours.  Not one but 2 physical machines :)

and we have a TON of other servers and services that interface it.

Some of those might be virtual, not sure yet.

When you have 2 physical machines, 1 is usually dedicated to business operations and the other one to backup/test.

I find it unlikely that your 2 physical machines are not hypervisors. If they are not then your hardware is most likely kinda old ^^

As i told you by PM you should try to contact IBM support :)

Edited by Neutro
Link to post
Share on other sites
  • 6 months later...

Thanks for the information, that is very helpful.

I almost succeed to do what I try to do.

I tried to get screen content using  GetScreen function but I always got errors.

Is it my syntaxe or it's not possible to use that function ?


My code.

global $oOIA = ObjCreate("PCOMM.autECLOIA")
$oOIA.SetconnectionByName("A")

global $oPS = ObjCreate("PCOMM.autECLPS")
$oPS.SetConnectionByName("A")

Global $actualKw

$oPs.GetScreen($actualKw, 51, 9, 18, 50);

MsgBox($MB_SYSTEMMODAL,"Actual Web Keyword", _ArrayDisplay($actualKw))

 

Link to post
Share on other sites
  • 2 years later...

Hi Guys, im new on this and i'm trying to automate an AS400 console, im following the example of Neutro but when trying to declare the variables im having the following error:

"C:\Windows_x86-64\TestScript.au3" (4) : ==> Variable must be of type "Object".:
$oOIA.SetconnectionByName("TESTENV")
$oOIA^ ERROR

Following the code:

global $oOIA = ObjCreate("PCOMM.autECLOIA")
$oOIA.SetconnectionByName("TESTENV")

global $oPS = ObjCreate("PCOMM.autECLPS")
$oPS.SetConnectionByName("TESTENV")

RunWait("acslaunch_win-64.exe")

Sleep(5000)

 

If you can give me a light on how to get around of this error or do the SetCursorPos on the window it will be appreciated.

 

Thanks.

Link to post
Share on other sites
  • 3 weeks later...

Hey,

Sorry to answer a bit late but better late than never ;)

For this to work you need to have the IBM iseries software installed on your computer and check that you can effectively use it to connect to interface with your AS400 with the 5250 emulator as displayed in my screenshots in my first post.

If you do not have the iseries software and the 5250 interface emulator installed the object creation will fail in autoIT and you will get the error message that you had.

Also in your code you used SetconnectionByName("TESTENV") but "TESTENV" here is wrong. Please read again my first post, instead of "TESTENV" this should be the letter of the session that is displayed when you open the 5250 interface emulator as shown in my screenshots (letter A and B in my examples).

If you set anything else than the right letter in SetconnectionByName the code will fail.

Also if i recall correctly, when i did this post back in 2017 it was on windows 7. If my memory is right i've tried using the same on Windows 10 and it also worked, but i'm not 100% sure.

Also i just checked and saw that the "IBM i Access for Windows" software that includes the iseries software that i'm referring to has been discontinued if i'm not wrong:

https://www.ibm.com/support/pages/ibm-i-access-windows

and replaced by the new version called "IBM i Access Client Solutions". 

I stopped working on AS400 for a while now so i dont know if the code in my first post still work with this version, but even if IBM say in their article that the first version of I Access for Windows has been discontinued and does not support Windows 10, it might still work properly as i tested it back then when i was working on migrating our IT from windows 7 to win10 and had no problems.

Link to post
Share on other sites
  • 1 month later...

Hi ,

Error message “unknown function name” is thrown when trying to create objects for autECLOIA or autECLPS. Do we have to include any libraries before hand. If so how to include them. 
I have gone threw different posts but unable to find the libraries or how to include them.

Thanks in advance.

@water: could you provide me an advice on the above issue.

Edited by Ravali
Link to post
Share on other sites

I have never worked with AS400, just with IBM mainframes.
You have to make sure that the correct software and the correct version is installed (as Neutro describes above).
How to do this and how to set up the computer for automation is described in the docu of the software.

Sorry for not being more specific but that's all I can do based on the information you provide.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2021-04-13 - Version 1.6.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

@water/ @Neutro : Sorry for the less information provided. I am just trying to connect and automate ibm as400 database using autoit.Do i have to include or download any libraries for auto it to recognize the below statements. Unknown function name is thrown when trying to create object for autECLOIA or autECLPS.

global $oOIA = ObjCreate("PCOMM.autECLOIA")
$oOIA.SetconnectionByName("A")

global $oPS = ObjCreate("PCOMM.autECLPS")
$oPS.SetConnectionByName("A")
Link to post
Share on other sites

@Ravali :welcome: to logo_autoit_210x72.svg forum.

Please make a small reproducer just how you create object and connect, of course do not forget to anonymize your security related data.

 

Signature beginning:
Please remember: "AutoIt".....  Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) *

PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-03-17

Link to post
Share on other sites

But please first answer Danp2' s questions.

  • Which software do you use?
  • Which version do you use?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2021-04-13 - Version 1.6.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Hi,

I am able to access the AS400 Ibm sessions manually. But facing the issue when trying to automate through autoit.

As am able to access the application without any issue , I dnt think this might be the download problem of the software.

I am using IBM Personal Communications iseries as neutro mentioned in his first post.

Session manager version 6.0 for windows is used.

The code in autoit is

Global $oOI=ObjCreate(“PCOMM.autECLOIA”)

Global $oPS=ObjCreate(“PCOMM.autECLPS”)

 

this might be a silly mistake but am unable to figure it out as am new to autoit.

Thanks in advance.

 

Link to post
Share on other sites

Maybe when installing PComm the libraries needed by AutoIt haven't been selected and hence are now missing?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2021-04-13 - Version 1.6.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites
14 hours ago, mLipok said:

Please make a small reproducer just how you create object and connect, of course do not forget to anonymize your security related data.

Again please post small reproducer to this

2 hours ago, Ravali said:

Global $oOI=ObjCreate(“PCOMM.autECLOIA”)

Global $oPS=ObjCreate(“PCOMM.autECLPS”)

Complete I mean which you run to check....

Edited by mLipok

Signature beginning:
Please remember: "AutoIt".....  Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) *

PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-03-17

Link to post
Share on other sites

According to this post you need to create objects for the connection manager and a session and then you call autECLOIA and autECLPS.
Could you please give this code a try?

Edit: You need HACL (Host Access Class Library) objects as described here to automate a PCOMM session.
A good overview can be found here.
My understanding is that at least you have to create a connection.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2021-04-13 - Version 1.6.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By chrweav86
      Here is an existing AS400 PCOM script that I have: 
      #include-once
      #cs ----------------------------------------------------------------------------
       UDF Header Title: _PCOMM
       UDF Header Version: 0.1.0
       AutoIt Version: 3.3.8.1
       Author:         Jason S. - Jewelry Supply, Inc.
       Script Function: PCOMM UDF Header
                          For use with IBM AS/400 - IBM OS/400 - IBM System i - IBM i application system.
                          This PCOMM UDF Header targets ASW - an ERP application suite written in IBM's RPG language (yuck!),
                          although it will work for any AS/400 system and is not ASW specific.
                          PCOMM allows injection of keystrokes into the datastream of
                          a running terminal/console application ("Green Screen" Console Emulator).
                              - Assumes Session 'A' but can be overriden using the aswConnect() function.
                          PCOMM allows observing of characters in the datastream of a running
                          terminal/console application ("Green Screen" Console Emulator).
                              - Assumes Session 'A' but can be overriden using the aswConnect() function.
      #ce ----------------------------------------------------------------------------
      Global $Session = "A"
      Global $Ps
      Global $Oia
      ; Specify session to connect to
      Func aswSetSession($nSession)
          $Session = $nSession
      EndFunc
      ; Connect to ASW
      ; @param $nSession - Specify session to connect to. Ex: "A"
      Func aswConnect($nSession = $Session)
          $Obj_ConnMgr = ObjCreate("PCOMM.autECLConnMgr")
          $OBJ_EmulSession = ObjCreate("PCOMM.autECLSession")
          $OBJ_EmulSession.SetConnectionByName($nSession)
          $Ps = $OBJ_EmulSession.autECLPS
          $Oia = $OBJ_EmulSession.autECLOIA
      EndFunc
      ; Send Data to ASW
      ; if $rownum and $colnum are not specified, defaults to the cmd line
      Func aswSend($keys, $rownum = 20, $colnum = 7, $inhibit = 1)
          $Ps.SendKeys($keys, $rownum, $colnum)
          if $inhibit = 1 Then
              While $Oia.InputInhibited <> 0
              WEnd
          EndIf
          $Oia.WaitForInputReady()
      EndFunc
      ; Get Data from ASW
      Func aswGet($row, $col, $length)
          $info = $Ps.GetText($row,$col,$length)
          return $info
      Endfunc
      ; Check which page we are on
      ; @param $page - Page to see if we are on. Ex: "DMR30101" == Sales Order Maintenance page
      Func checkScreen($page, $rownum = 1, $colnum = 72, $length = 8)
          If StringInStr(aswGet($rownum, $colnum, $length), $page) Then
              Return 1
          Else
              Return 0
          EndIf
      EndFunc
      I would like to use it launch a connection to the AS400. I have an executable that I run with an hod file. Do I just need to run the exe and hod file then run the session connect function and send keys function to pass credentials?
       
    • By Rhidlor
      So I'm trying to do some as400 automation and hit a wall when trying to get a COM object. The code on line 8 is failing, the as400.ws file opens with PCSWS.exe so I tried using that as the file path too but that didn't work either. Any and all help is greatly appreciated! 
       
      $file = "C:\Users\Rhidlor\Desktop\as400.ws" If Not FileExists($file) Then MsgBox(0, "Error", "Error finding file") Exit EndIf $object = ObjGet($file) If @error Then MsgBox(0, "Error", "Error getting object") Exit EndIf $object.SendKeys("05")  
    • By CarlFerrer
      Hello folks!
      I am trying to open a as400 session but no luck. Here is my code.
       
      Example()
      Func Example()
          ; Run Notepad with the window maximized.
         Run("C:\Program Files\IBM\Client Access\Emulator\Private\iSynergy.ws", "", @SW_SHOWMAXIMIZED)
          ; Wait for 4 seconds.
          Sleep(4000)
      EndFunc   ;==>Example
       
    • By Radiance
      Hi all,

      this is very specific. I'm an administrator for several IBM i Power mainframe servers that run i5/OS and people use the Client Access Software.
      For now I've been using the Host Access Class Lib in my AutoIt Scripts on Client Access to automate most of my tasks.
      The essential code lines are this:

      After this you can use the methods listed here to remote-control your Client Access session. Much like a macro.

      This worked fine for the Client Access software. Now IBM released their new IBM i Access Client Solutions and I can't get it to work with it.
      Does anyone have any experience with this already by chance?
    • By Bennet
      I'm actually really proud of myself today. I'm always keen on using AutoIT wherever I can, as I've been developing in it since the age of 14 and whenever I meet any new technical staff or developers at the different clients I visit it always gets a mention and a demonstration. So we had a minor problem today at one of our clients, whereby they had an existing Windows Service implemented with a config file but the source-code was missing, which limited the ability of our company to enhance the interface in any way.

      Now considering the fact that I was paid to develop this I will refrain from divulging any company names or "secrets" as, of course, there are clauses in my contract that state that my work belongs to them. I am however a SAP ABAP developer by trade so anything that falls outside of the defined limits of this trade I can technically share, but regardless I'll keep the information limited.

      So the requirement was to pull data from IBM Websphere, write it out to a file and post it into SAP through a custom built RFC. It turned out to be much less complicated than I imagined and through the research on these forums, I had discovered that similar things had been attempted but that nothing concrete had been written for AutoIT specifically (The MQ part, not the SAP part). So without further adieu I present my thinking.

      I started out with the IBM Websphere dll using DllOpen and DllCall. After a few frustrating attempts at creating COM objects through the DLL Call. I finally discovered that there was another dll that I could register using regsrv32. It was called MQAX200.dll

      Once this dll was registered on the system I could access the following piece of code;



      EnvSet("MQSERVER", $iniServer) ;MQ Server Environment Variable $MQSess = ObjCreate("MQAX200.MQSession") $QMgr = ObjCreate("MQAX200.MQQueueManager") $QMgr = $MQSess.AccessQueueManager($iniQM) ;Queue Manager ConsoleWrite("Connected" & @CRLF)
      After this was complete and I successfully tested my connection I added the following to read from MQ;


      $Queue = $QMgr.AccessQueue($iniQueue, 2) ;Queue (2=MQOO_INPUT, 16=MQOO_OUTPUT) While 1 $GetMsg = $MQSess.AccessMessage $GetOptions = $MQSess.AccessGetMessageOptions $Queue.Get($GetMsg, $GetOptions) If $Queue.ReasonCode = 2033 Then ;When there aren't any new messages sleep for 2 seconds. Sleep(2000) Else #EndRegion Accessing MQ #Region Write File $MsgData = $GetMsg.MessageData ....
      I then wrote this out to a file and attempted my SAP connection using the following code;


      Dim $LoggedIn = False $oConnection = $LogonControl.NewConnection $oConnection.System = $System $oConnection.ApplicationServer = $AppServer $oConnection.SystemNumber = $SysNumb $oConnection.User = $User $oConnection.Password = $Password $oConnection.Client = $Client $oConnection.Language = $Language $LoggedIn = $oConnection.Logon(0, True) Return $LoggedIn
      which resulted in failure as the SAP COM object wasn't registered on the system. After attempting to register the correct object without installing SAP GUI, I ended up with a slightly different solution for an executable supplied by SAP called startrfc.exe;


      $foo = Run(@ComSpec & " /c " & $RFCExec & " -3 -h " & $AppServer & " -s " & $SysNumber & " -F " & $RFC & " -u " & $User & " -p " & $Password & " -c " & $Client & " -l " & $Language & " -E FNAME=" & $FilePath & " -E PNAME=" & $Program, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo) If @error Then ExitLoop ConsoleWrite($line) $LogFile = FileOpen(StringReplace($FilePath, "\In\","\Logs\"), 2) FileWrite($LogFile, $Line) FileClose($LogFile) FileMove($FilePath, StringReplace($FilePath, "\In\","\Out\")) WEnd While 1 $line = StderrRead($foo) If @error Then ExitLoop ConsoleWrite($line) $ErrFile = FileOpen(StringReplace($FilePath, "\In\","\Errors\E"), 2) FileWrite($ErrFile, $Line) FileClose($ErrFile) FileMove($FilePath, StringReplace($FilePath, "\In\","\Errors\")) WEnd

      One last piece of code that you should keep in mind if you attempt this so that your program doesn't stop when a COM error is returned (MQ returns an error that indicates there is no data available on the queue as you see with the reason code check earlier);


      Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ;Catch COM errors
      In conclusion, I really enjoyed implementing something that'll be used for the foreseeable future at a powerful company and writing it in my favorite language. I hope you find some use in these snippets.

      This will be running as a Windows Service from now on using srvany.exe.
×
×
  • Create New...