0

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?

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
aganm
  • 1,245
  • 1
  • 11
  • 30

3 Answers3

3

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.

Benny Hill
  • 6,191
  • 4
  • 39
  • 59
  • What if I just want the program to wait for the user to press enter? Do you think that's possible? – aganm Oct 17 '16 at 00:29
  • 3
    I would not hardcode '*EXT'. Just code '' and let the RPG runtime decide whether to use '*EXT' for an interactive job or 'QSYSOPR' for a batch job. – Barbara Morris Oct 17 '16 at 14:05
3

Benny is on the right track, but he left off the response parm.

All you need is:

dsply wMessage *EXT wResponse;

The program will wait till a response is entered. Technically, since any reponse requires enter to be pressed. The user could respond with just enter.

Charles
  • 21,637
  • 1
  • 20
  • 44
1

A CL procedure using the Send User Message (SNDUSRMSG) with a default value supplied [Default Reply Value (DFT)] can enable an Inquiry allowing for a pause and just Enter to be pressed to continue. IIRC, even without a default specified, the character string value *N is returned for lack of any input by the user, for which of course a return value of less than two-characters would return only the asterisk; though depending on other setup, that may not be the effect with just Enter, and may instead be seen only with either F11=Delete of the inquiry by the user [or F13=Clear]. Or doing the same code, using whatever message-feature API effects similar; deciding on where to send the message when running as batch vs interactive, might be required by the code using the API vs coding to use SNDUSRMSG for which that feature is built-in.
Note: This usage is of course influenced by the Inquiry Message Reply Handling (INQMSGRPY) setup of the job; e.g. the job could be set auto-reply with the default, such that the inquiry never presents, but that is probably a good thing for consistency/expectation.

CRPence
  • 1,259
  • 7
  • 12