Incrementing a 2-Character Alphanumeric Code in RPG Free

Incrementing a 2-Character Alphanumeric Code in RPG Free




Today I’m sharing a small but useful RPG Free program to increment a 2-character alphanumeric code using the sequence A..Z, 0..9. The program also handles wrap-around after "99", restarting at "AA".

Source Code

You can copy and paste the code directly from the field below:

How It Works

  • The program takes a 2-character input code.
  • It validates that both characters are within the allowed sequence A..Z,0..9.
  • It increments the second character and carries over to the first if necessary.
  • If the code exceeds "99", it wraps back to "AA".
  • If the input contains invalid characters, an error code INVALIDVAL is set and the output is cleared.

Ideas for Improvement

This simple module can be enhanced in several ways:

  • Handle codes longer than 2 characters.
  • Allow custom sequences, e.g., only letters or only numbers.
  • Create a reverse function to decrement a code.
  • Make the code case-insensitive.

Try it on your IBM i, experiment with improvements, and share your optimizations. Improving these small programs is a great way to become more skilled in RPG Free and DB2!

Comments

Popular posts from this blog

SQL Indicator Variables in Embedded SQL for RPG on IBM i

Using a Parameterized Cursor in SQLRPGLE

Dynamic SQL in RPG