Problem solve Get help with specific problems with your technologies, process and projects.

Simple screen capture

Here is a simple technique for capturing the information on a screen and using it in a program.

Here is a simple technique for capturing the information on a screen and using it in a program.

My motivation for developing the program below was to save typing when using the STRSRVJOB command. I have recently had to debug many batch jobs. After having issued WRKJOB and typed "STRSRVJOB 123456/USERNAME/JOBNAME" a hundred times, I thought there must be some time-saving technique.

The program below is designed to be invoked from the WRKJOB screen. This screen displays the job number, user, and job name; all required by many job-related commands, such as STRSRVJOB. The program works by capturing the screen image (using the Dynamic Screen Manager APIs), extracting the required job details, and invoking the appropriate command.

The actual command string to be invoked is passed to the program by one of a number of commands. Command SRV passes the string 'STRSRVJOB'. Command PRTLOG passes the string 'DSPJOBLOG OPTION(*OUTPUT)'. The range of job-related commands could easily be extended. Indeed, almost any command could be invoked, given an appropriate screen to capture.

Program GETSCR:

H Dftactgrp(*NO)
H BndDir('QSNAPI')

 * Dynamic Screen Manager prototypes...
 * Create input buffer:
D CrtInpBuf       pr            10i 0 Extproc('QsnCrtInpBuf')
D  InitSize                     10i 0 Const
D  Increment                    10i 0 Const Options(*OMIT)
D  Maximum                      10i 0 Const Options(*OMIT)
D  InpBufHnd                    10i 0 Const Options(*OMIT)
D  ErrorCode                   272    Options(*OMIT)
 * Read screen without requiring AID key:
D ReadScreen      pr            10i 0 Extproc('QsnReadScr')
D  NoBytes                      10i 0 Options(*OMIT)
D  InpBufHnd                    10i 0 Const Options(*OMIT)
D  CmdBufHnd                    10i 0 Const Options(*OMIT)
D  EnvHnd                       10i 0 Const Options(*OMIT)
D  ErrorCode                   272    Options(*OMIT)
 * Retrieve pointer to buffer data:
D RtvDtaPtr       pr              *   Extproc('QsnRtvDta')
D  InpBufHnd                    10i 0
D  Data                           *   Options(*OMIT)
D  ErrorCode                   272    Options(*OMIT)
 * Delete buffer:
D DltBuf          pr            10i 0 Extproc('QsnDltBuf')
D  BufHnd                       10i 0
D  ErrorCode                   272    Options(*OMIT)

D JobCommand      s             32
D BufHnd          s             10i 0
D NoBytes         s             10i 0
D ReturnCode      s             10i 0
D Screen          ds                  Based(BufPtr)
D  JobName              169    178
D  JobUser              192    201
D  JobNo                217    222
D SelName         s                   Like(JobName)
D SelUser         s                   Like(JobUser)
D CmdStr          s             66
D CmdLen          s             15  5 Inz(%Size(CmdStr))

C     *Entry        Plist
C                   Parm                    JobCommand

 * Create input buffer.
C                   Eval      BufHnd = CrtInpBuf (%Size(Screen) : *OMIT :
C                                                 *OMIT : *OMIT : *OMIT)
 * Read screen.
C                   Eval      NoBytes = ReadScreen (*OMIT : BufHnd :
C                                                   *OMIT : *OMIT : *OMIT)
 * Retrieve pointer to buffer data.
C                   Eval      BufPtr = RtvDtaPtr (BufHnd : *OMIT : *OMIT)
 * Build Command string.
C     x'00':' '     Xlate     JobName       SelName
C     x'00':' '     Xlate     JobUser       SelUser
C                   Eval      CmdStr = JobCommand + ' JOB(' +
C                                      JobNo + '/' +
C                                      %Trimr(SelUser) + '/' +
C                                      %Trimr(SelName) + ')'
 * Delete buffer.
C                   Eval      ReturnCode = DltBuf (BufHnd : *OMIT)
 * Execute command against job.
C                   Call      'QCMDEXC'
C                   Parm                    CmdStr
C                   Parm                    CmdLen

C                   Return 

The commands below should be created to invoke the program above:

Command SRV:

CMD PROMPT('Start Service Job')

Command PRTLOG:

CMD PROMPT('Print Job Log')


The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

This was last published in April 2002

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.