Using QSNRTVMOD to find the last displayed screen size 

 October 31, 2017

By  NickLitten

While I was writing that previous blog about handling wide fat screens I stumbled across another useful API (QSNRTVMOD) for retrieving the current screen mode that we are displaying. This means we could find our screen width programmatically. Why isnt that a word?

I’m not too sure why anyone would want to do this but… in the spirit of sharing stuff on the same theme as the widescreen gubbins I was mumbling about earlier…

We can find out if we are displaying a 24×80 or a 27×132 screen with this little gem:


The QueueueuSinnerTeevumMod API will return a code and tell us what screen format we are using in our 5250 session.

We can add some error handling to the RPG program without changing any DDS in our *DSPF..

Procedure – Retrieve the Screen Mode

// +------------------------------------------------------------------+
// | Procedure to retrieve current screen mode ('3'=24x80 '4'=27x132) |
// +------------------------------------------------------------------+
QSNRTVMODdcl-proc #RtvScrnMode export;
  dcl-pi #RtvScrnMode char(1) end-pi;

dcl-s currentScrnSize char(1) inz('0');

dcl-ds myApiError inz qualified;
  Bytes int(10) inz( %size( myApierror ));
  BytesAvailable int(10) inz;
  ErrorID char(7) inz;
  Reserved char(1) inz( x'00' );
  MessageData char(128) inz;

dcl-pr QsnRtvMod extproc( 'QsnRtvMod' );
  *n char(1); // DspMode
  *n int(10) options( *omit ); // Handle
  *n options( *omit: *varsize ) like( myApierror ); // ErrorDS

QsnRtvMod ( currentScrnSize
          : *Omit
          : *Omit 

// Too lazy to add error handling for 'myApiError' but you could do that here

Return currentScrnSize;


(obviously this code should be in a service program to make it reusable but for code readability in this blog I’ve copy/pasted it separately)

Mainline – Check screen size before doing something

So, now we just need to check our screen size before doing something.

I’m not too sure if this is ever helpful technique really… I mean I have never had to use it in anger… but that doesnt mean that somebody out there might be looking for exactly this solution šŸ™‚

// Procedure to retrieve current screen mode (3=24x80; 4=27x132)
If RtvScreenMode() = '3';
  // do some stuff for 24x80 screens
If RtvScreenMode() = '4';
 // do some stuff for 27x132 screens
  // do some error handling stuff or perhaps handle totally weird screen sizes

*inlr = *on;

NOTE: This API is telling you the last screen size displayed not the screen size that the 2520 terminal is capable of. In other words – if you are logged into a 27×132 terminal but displaying a 24×80 screen and run this code it will tell you its 24×80. Go to a main IBM i menu like (GO MAIN) and it will say it’s 24×80 but call it from a widescreen format (like SEU-WIDE for example) and it will tell you it’s 27×132



IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

Iā€™m always looking for awesome input, feedback and critique!