-3

I want to convert temperature from Fahrenheit to Celsius. At run time it should ask the temperature in Fahrenheit and then show the the equivalent temperature in celsius.

2 Answers2

2

Unlike other languages, RPG is built specifically for business programs. Thus it has no built in console IO like C or Java. Instead user interaction is traditionally via an object called a device file which mimics database IO. However, there is one op code that can be used to access the external message queue and can send a message and receive a reply. This op code is DSPLY. It is quite limited, you can only display a 52 character message, but will work for this purpose. A real solution where you want user IO would involve a display file. But to get something like what you are asking for in a way similar to other languages, you could write the following:

   ctl-opt Option(*SrcStmt : *NoDebugIo: *NoUnref)
           DftActGrp(*No) ActGrp(*New)
           Main(temprature);

   dcl-proc temprature;

     dcl-s degreesC       Char(15) Inz('');
     dcl-s degreesF       Char(15) Inz('');

     dsply 'Enter temprature in degrees F' '*EXT' degreesF;
     degreesC = %char(
       (%dec(degreesF:15:0) - 32) * 5 / 9
     );
     dsply ('Temprature in degrees C is: ' + degreesC);

     return;
   end-proc;

The first dsply has three parameters, the message, the message queue, and a variable for the reply (which must be a character variable). The second dsply just has the message which can be an expression if it is enclosed in parenthesis. There is no reply, and it sends to the *EXT message queue by default for interactive jobs.

NOTE: DSPLY is really useful only for testing and debug, and has only limited utility for that. A program that will face users would use a display file or some other way to interact with the user such as through a browser using the CGIDEV2 library.

jmarkmurphy
  • 11,030
  • 31
  • 59
0

A good start is to look at the RPG Manual then start researching DDS. There is TONS of documentation out there. Just search for "iseries" then your topic.

Mike Wills
  • 20,959
  • 28
  • 93
  • 149