Search code examples
inputwaitibm-midrangerpgle

as400 RPGLE wait for input


I have an RPG program which prints data with the command DSPLY.

When I call the program,

I can see the printings which appears for a couple of milliseconds, but it closes right away.

Is there a way in native RPG to make the program wait for input other than using a display file?


Solution

  • Yes, you need to add a response parameter to your DSPLY operation:

    /free
    dou (response = 'Q');
       // dsply 'Q = Quit' '*EXT' response;
       // Better to let the RPG runtime determine
       // whether to use *EXT (for interactive jobs)
       // or QSYSOPR (for batch jobs).
       dsply 'Q = Quit' '' response;
       if (response <> 'Q');
          // your code here
          dsply yourvar;
       endif;
    enddo;
    *inlr = *on;
    /end-free
    

    Please note - I'm currently unable to test this, I'm just typing the code here straight out of my head.

    *Edited to incorporate Barbara's excellent point.