What’s DCL-C?

DCL-C lets you declare constants in free-format RPGLE values that stay put, like a pizza menu taped to the wall. The syntax is as straightforward as a plain cheese pizza:

DCL-C constant-name value;

Use it for strings, numbers, or single characters. These values are locked in tighter than a pizza box on delivery day.

The Pizza Code Breakdown

This program simulates a pizza order at CodeSlice Pizzeria. Here’s what’s on the menu:

Constants:
  • PIZZA_PRICE: $12.99 for a large pepperoni pizza.
  • SHOP_NAME: Our pizzeria’s name, CodeSlice Pizzeria.
  • MAX_TOPPINGS: 5, because too many toppings make the pizza structurally unsound.
  • DELIVERY_FEE: $3.50 to get that pizza to your coding desk.
Variables:
  • OrderQty: Number of pizzas (because one pizza is just an appetizer).
  • ToppingCount: Extra toppings for that gourmet touch.
  • TotalCost: The final bill, including pizzas, toppings, and delivery.
  • OrderMsg: A string to display the order summary.
Logic:
  • Calculates the total cost: (OrderQty * PIZZA_PRICE) + (ToppingCount * 1.50) + DELIVERY_FEE.
  • Checks if ToppingCount exceeds MAX_TOPPINGS. If so, it warns you about pizza overload. Otherwise, it builds a friendly order summary.
  • Uses DSPLY to show the order details, because nothing says “success” like a console message.
// Lesson: Using DCL-C in IBM i RPGLE Programming
// Purpose: Teach DCL-C with a pizza-ordering twist
// Author: Nick Litten (the RPGLE pizza chef)

// Declare constants with DCL-C - because pizza prices don’t wobble
DCL-C PIZZA_PRICE 12.99; // Cost of a large pepperoni pizza
DCL-C SHOP_NAME 'CodeSlice Pizzeria'; // Our coding pizzeria’s name
DCL-C MAX_TOPPINGS 5; // Max toppings before the pizza collapses
DCL-C DELIVERY_FEE 3.50; // Fee for delivering pizza to your cubicle

// Declare variables - the ingredients of our pizza order
DCL-S OrderQty PACKED(3:0); // Number of pizzas ordered
DCL-S ToppingCount INT(5); // Number of extra toppings
DCL-S TotalCost PACKED(7:2); // Total order cost
DCL-S OrderMsg CHAR(100); // Message to display order summary

// Main procedure - let’s bake some code!

// Initialize sample order data
OrderQty = 2; // Two pizzas, because one is never enough
ToppingCount = 3; // Extra cheese, peppers, and dreams

// Calculate total cost: pizzas + toppings + delivery
TotalCost = (OrderQty * PIZZA_PRICE) + (ToppingCount * 1.50) + DELIVERY_FEE;

// Check if we’ve gone topping-crazy
IF ToppingCount > MAX_TOPPINGS;
   OrderMsg = 'Whoa, ' + SHOP_NAME + '! ' +
   %CHAR(ToppingCount) + ' toppings? Pizza might tip over!';
ELSE;
   OrderMsg = SHOP_NAME + ': ' + %CHAR(OrderQty) +
   ' pizzas, ' + %CHAR(ToppingCount) +
   ' toppings, Total: $' + %CHAR(TotalCost);
ENDIF;

// Display the order summary
DSPLY OrderMsg;

// Shut down the pizza shop and go debug
*INLR = *ON;
RETURN;

Why DCL-C Rocks

Constants are like the perfect pizza recipe: set it once, and you’re golden. If the price of pepperoni spikes, you update PIZZA_PRICE in one spot instead of hunting through your code like it’s a bad topping. Plus, constants prevent accidental changes because nobody wants a $0 pizza by mistake.

How to Run

Pop this code into your IBM i system.
Compile it with CRTRPGMOD or CRTBNDRPG.
Run it and watch the DSPLY output serve up your order summary.

Pro Tips for doing it your own way

Name your constants clearly, like PIZZA_PRICE instead of PP. Vague names are like ordering “some pizza” at a restaurant, nobody knows what you mean, and you’ll regret it later.

So, fire up your IBM i, bake this code, and enjoy a slice of RPGLE goodness with DCL-C. May your programs compile as smoothly as a pizza slides out of the oven!

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>