Home > AS/400 Tips > iSeries administrator tips > How to take advantage of DSM -- even in a non-ILE shop
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES ADMINISTRATOR TIPS

How to take advantage of DSM -- even in a non-ILE shop


Ron Turull
12.08.2004
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



Ron Turull

In the last two installments (DSM lets you build screens and windows on the fly and How to save, restore the screen -- the quick and easy way) we explored the use of Dynamic Screen Manager (DSM), which comprises a large set of APIs. Specifically, in the last installment, we saw how quick and simple it is to save and restore the screen using two DSM APIs, QsnSavScr and QsnPutBuf. The only drawback was that it required your application to be written in an ILE language. Here, we will introduce a "helper" program you can put to use immediately to accomplish the same thing from a non-ILE program.

The helper program takes care of the calls to the DSM APIs. The key to making this work is to write the helper program in an ILE language.

The program shown below, SAVE_RST, is a short ILE CL program. It can be called from any program, be it ILE or non-ILE. The program is easily translated to ILE COBOL or ILE RPG, either of which will increase the performance considerably. Below that is the RPG version, SAVE_RST.RPG.

SAV_RST.CLE

pgm  parm(&Buffer &SaveOrRst)

             DCL        VAR(&Buffer) TYPE(*char) LEN(4)
             DCL        VAR(&SaveOrRst) TYPE(*char) LEN(1)


             IF         (&SaveOrRst = 'R') +
               /*  Restore screen. */ +
               CALLPRC PRC('QsnPutBuf') PARM(&Buffer *OMIT *OMIT)

             ELSE +
               /*  Save screen. */ +
               CALLPRC  PRC('QsnSavScr') PARM(&Buffer *OMIT *OMIT *OMIT)


  return

SAVE_RST.RPG

      *
     c     *entry        plist
     c                   parm                    Buffer            4
     c                   parm                    SaveOrRst         1
      *
      *
     c     SaveOrRst     ifeq      'R'
      *
      *      Restore screen
     c                   call      'QsnPutBuf'
     c                   parm                    Buffer
      *
     c                   else
      *
      *      Save screen
     c                   call      'QsnSavScr'
     c                   parm                    Buffer
      *
     c                   endif
      *
      *
      *  Return without LR on.
     c                   return
      *

The program parameters

The program accepts two parameters, Buffer and SaveOrRst. The Buffer parameter is just a 4-byte space DSM uses to store the address of the internal buffer where it stores the screen information. Simply declare a 4-byte field in the calling program for this parameter; the calling program should not manipulate the contents of this field in any way.

The SaveOrRst parameter controls the operation of the helper program; if it is an 'R' the program restores the screen, otherwise the screen is saved. This may seem a bit backward but it helps guard against accidental restore operations which may generate an escape message (while they may still be incorrect, accidental save operations generally will not cause an escape message).

How to use the program

Using this helper program is easier than using the DSM APIs themselves. Simply call it once to save the screen (by setting the SaveOrRst parameter to something other than 'R', such as 'S'). Then call it again with the SaveOrRst parameter set to 'R' to restore the screen. It can be called any number times to restore the saved screen.

Below is a sample RPG program, T_SAVRST.RPG, that shows how to use this helper program. After calling SAVE_RST to save the screen, the program writes a display file record to the screen. Before going into a long processing loop, the programmer wishes to restore the original screen, which is accomplished by calling SAVE_RST again with the SaveOrRst parameter set to 'R'.

T_SAVRST.RPG

      *
     FTEST    CF  E                    WORKSTN
      *
      *
      *   Save screen.
     C                     CALL 'SAVE_RST'
     C                     PARM           BUFFER  4
     C                     PARM 'S'       SORR    1
      *
      *
      *  ----------------------------------------------
      *   Call to screen-altering program here.
      *   Test with WRITE OF TEST DSPF.
      *
     C                     WRITEREC
     C           '1'       IFEQ '0'
     C                     READ REC                      99
     C                     ENDIF
      *  ----------------------------------------------
      *
      *
      *   Restore screen.
     C                     CALL 'SAVE_RST'
     C                     PARM           BUFFER  4
     C                     PARM 'R'       SORR    1
      *
      *  -----------------------
      *   Long processing here.
      *  -----------------------
      *
     C           1         DO   300       I       70
     C                     Z-ADD3456      Z2      50
     C                     SQRT Z2        Z       50
     C                     ENDDO
      *
      *
      *  -------------
      *   EXFMT here.
      *  -------------
      *
      *
      *
     C                     RETRN
      *

Restrictions

The only thing you have to be careful about is calling other programs that use DSM in between calls to SAVE_RST. These programs can cause the DSM environment to change, thereby destroying the previous contents of DSM's internal buffers.

To get around that, create the SAVE_RST program to run in a named activation group. This is done by specifying DFTACTGRP(*NO) and ACTGRP(name) on the CRTBNDCL command (or the CRTBNDCBL command for COBOL or the CRTBNDRPG command for RPG).

DFTACTGRP(*NO) specifies that the program is not to run in the default activation group -- the activation group that supports OPM (Original/Old Program Model) programs. Instead, the program will run in its own activation group identified with whatever name you provide on the ACTGRP parameter. As long as the helper program does not execute an operation that causes the activation group to end (e.g., *INLR = 1 in RPG) -- and none of the programs discussed here do -- the activation group will remain active until the job ends or it is deleted using the Reclaim Activation Group (RCLACTGRP) command.

-----------------------------------
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries system performance and monitoring
Translating Linux for IBM i admins: Working with jobs and networking
Database performance comparisons on IBM i
How to: Monitoring job activity on the AS/400
Performance tuning for IBM i: The basics and beyond
How to: Reduce the percentage of ASP used on the AS/400
Detecting system changes made by outside IP address
AS/400 system values quiz
Checking on System i disk space requires creating a new command: XRTVSYSSTS
Drive space management commands
Viewing netstat information

Integrated File System (IFS)
How to view source files in the library
User being locked out by Windows share on iSeries
Incorrect CCSID on FTP connection from AS/400 to Windows
Trouble accessing IFS path from Win2k3 server
How to use an API for adding users to EIM SSO implemenation
Transfer files from one environment to another without closing all other AS/400 sessions
Securing the integrated file system on IBM System i
Generically send a text file from the IFS via FTP
Setting ILE and C+++ compilers to runtime
Use a virtual directory to move a .bmp file from the IFS to a remote server to run a software package

iSeries administrator tips
Translating Linux for IBM i admins: Using GUI to make it easy
Translating Linux for IBM i admins: Working with jobs and networking
OpenOffice: What to know before making the transition from Microsoft Office
OpenOffice: An enterprise open source solution
Database performance comparisons on IBM i
Translating Linux for IBM i admins: User profile commands
Modern System i reports using Client Access
Tips for installing Lotus Domino server on a System i partition
The iSeries Blog has a new home on IT Knowledge Exchange
Virtualization for IBM i: Backups

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
CIW  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts