as I mentioned in Interact with mainframe screen, I am using the OLE interface of IBM Personal Communications 3270 emulator to perform automated tasks on a mainframe. However, some sessions get stuck when 3 or 4 sessions are used in parallel. So I tried to find another way...and I found it. Starting at version 4.1 or 4.3 (don't know exactly), a DLL EHLAPI.dll is provided with PCOMM to interface C or Java applications with the emulator, and I also found Win32::API.

Once everything is put together, I managed to have some interaction between Perl script and the 3270 emulator with the following code.It is a just a simple one, but works, and shows an increase speed execution(and hopefully less buggy).

here are the pages I found of interest to help me interface my Perl script with the EHLLAPI of the PCOMM:

A quick benchmark, only with the seconds elapsed, shows that for the same queries, the OLE version took around 60 seconds to execute, were the EHLLAPI version tooks only 15 seconds ! Until now I thought that the cause of the 'slow' execution time was due to the execution time of the query on the mainframe, or to the communication between the emulator and the mainframe, but most of the time was spent on the OLE interface.

use strict; use Win32::API; print "Getting API function\n"; my $hllapi = new Win32::API('D:/PC3270W/EHLAPI32.dll', 'hllapi', ['P', +'P','P','P'], 'N'); die("oups not created") unless(defined($hllapi)); print "Connecting to session A"; my $fct=pack('L', 1); my $connBuffer="A"."\0" x 3; my $connBufferLen = pack('L', 4); my $returnCode=pack('L',13); $hllapi->Call($fct,$connBuffer,$connBufferLen,$returnCode); my $ret=unpack('L',$returnCode); print "return code -$ret-\n"; die("oups") if($ret != 0); print "Trying sendkeys - JD\n"; $fct=pack('L', 3); my $keys='JD@E'; my $keysLengh=pack('L', 4); $hllapi->Call($fct,$keys,$keysLengh,$returnCode); print "Waiting for command to be finished\n"; $fct=pack('L',4); my $a="\0"; my $b=pack('L',0); my $rc=pack('L',0); $hllapi->Call($fct,$a,$b,$rc); print "Reading screen\n"; $fct=pack('L',8); my $readBuf= "\0" x 3000; my $lenToRead=pack('L',1920); my $offset=pack('L',1); $hllapi->Call($fct,$readBuf,$lenToRead,$offset); for(my $k=0;$k<24;$k++){ my $offset=$k*80; print substr($readBuf,$offset,80)."\n"; } print "\n"; exit(0);

In reply to mainframe screen - PCOMM - EHLLAPI by jeepj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.