RPG 101 - Tweaking Hello World to make it a bit more fancy

RPG Code Sample

**free
// -----------------------------------------------------------
// SAMPLE COMPLEX BUT STYLISH HELLO WORLD PROGRAM
// -----------------------------------------------------------
//
// This program is a simple 'Hello World' style RPG program
// which has been fleshed out to match my preferred standard
// RPG style.
//
// The control options define runtime setup for this program
// including some notable options:
// * main(mainline) - tell RPG not to add all the usual RPG
// Cycle info but to execute the procedure
// called MAINLINE by default.
// * pgminfo(*pcml:*module) - this embeds the parameter
// information in the compiled object so
// that processes like the integrated
// webserver can see the expected parms
// * copyright - store version information against the program
// to show information using DSPPGM
// * Defined(*CRTBNDRPG) - add activation group defaults if
// this is created as a bound program versus
// a module and ILE
//
// The program expects three incoming parameters:
// * Environment - 3 character enviroment code
// * A success indicator which will return *ON/*OFF
// * A message which will contain error code or info message
//
// To call use: CALL PGM(HELLO7) PARM(('DEV') (' ') (' '))
//
// -----------------------------------------------------------
// Modification History:
// V.000 2024.03.14 NJL Created
// V.001 2024.03.14 NJL Added error code to DSPLY if invalid ENV
// V.002 2024.03.14 NJL minor change to success env code text
// -----------------------------------------------------------
ctl-opt
main(mainline)
optimize(*full)
option(*nodebugio:*srcstmt:*nounref)
pgminfo(*pcml:*module)
indent('| ')
copyright('HELLO7 | V.002 | Sample Stylised RPG Program')
/if Defined(*CRTBNDRPG)
dftactgrp(*no)
actgrp('NICKLITTEN')
/endIf
;
// -----------------------------------------------------------
// the mainline (default) runtime procedure
// -----------------------------------------------------------
dcl-proc mainline;
dcl-pi mainline;
p_env char(3) const;
p_success ind;
p_msg char(50);
end-pi;
dcl-s myResponse char(1);
// check if the incoming environment code is acceptable
if valid_environment(p_env);
// send the environment code message into the joblog
p_msg = 'Environment Code is:' + p_env;
dsply p_msg;
// now we want to pause the program and wait for a response
p_msg = 'Press Y to continue';
Dou %upper(myResponse) = 'Y';
dsply p_msg '' myResponse;
enddo;
p_success = *on;
else;
// if the environment code was *bad* then tell the previous caller
p_success = *off;
p_msg = 'Invalid Environment code received:' + p_env;
dsply p_msg;
endif;
return;
end-proc;

// -----------------------------------------------------------
// validate the environment code parameter
// -----------------------------------------------------------
dcl-proc valid_environment;
dcl-pi valid_environment ind;
p_env char(3) const;
end-pi;
if p_env = 'DEV' or p_env = 'TST' or p_env = 'UAT' or p_env = 'PRD';
return *on;
else;
return *off;
endif;
end-proc;
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>