aganm
aganm

Reputation: 1369

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?

Upvotes: 0

Views: 3534

Answers (3)

Benny Hill
Benny Hill

Reputation: 6240

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.

Upvotes: 3

CRPence
CRPence

Reputation: 1259

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.

Upvotes: 1

Charles
Charles

Reputation: 23783

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.

Upvotes: 3

Related Questions