SELECTiASP - a Simple Question and Answer CLLE

This program has one simple purpose - ask the user a question and act on the reply.

This little CL (Control Language) code snippet asks the user what iASP they want to connect to during a signon step, but this question could be anything.

Here we simply declare one variable &IASP which will contain the reply from the main message sent by the SNDUSRMSG command.

I am then using a SELECT group to handle the reply value, but could easily have used an IF/ELSE loop instead.

The code is simple and should be self-explanatory - so let's look at it:

/* -------------------------------------------------- */
/* Simple CLLE Bound Program to ask/answer a question */
/* -------------------------------------------------- */
/* Author: nick@nicklitten.com                        */
/* Date: February 25th 2025                           */
/* -------------------------------------------------- */PGM 
DCL VAR(&IASP) TYPE(*CHAR) LEN(10)

MSG: SNDUSRMSG MSG('Which iASP do you want to use? (ASP1/ASP2/*NONE)') VALUES(ASP1 ASP2 *NONE) TOMSGQ(*) MSGRPY(&IASP)

/* This is the select group to handle the user reply */
SELECT 

  WHEN COND(&IASP *EQ '*NONE' *OR &IASP *EQ '*none') THEN(DO)
    SETASPGRP ASPGRP(*NONE)
  ENDDO 

  WHEN COND(&IASP *EQ 'ASP1' *OR &IASP *EQ 'asp1') THEN(DO)
    SETASPGRP ASPGRP(T1)
  ENDDO 

  WHEN COND(&IASP *EQ 'ASP2' *OR &IASP *EQ 'asp2') THEN(DO)
    SETASPGRP ASPGRP(T2)
  ENDDO 

  OTHERWISE CMD(DO)    /* This is the logic for other answers - NOTE this should not process because the valid answers are on the VALUES prompt for the SNDUSRMSG command above. BUT you could add stuff here if you wanted to expand the VALUES for more answers */
    GOTO CMDLBL(MSG)
  ENDDO 

ENDSELECT

/* if the code drops to here then its answered so stick a message in the joblog and goto the MAIN IBM i Menu */
SNDPGMMSG MSG('iASP' *BCAT &IASP *TCAT ' selected.') TOPGMQ(*EXT) TOMSGQ(*TOPGMQ) MSGTYPE(*COMP) 

GO MENU(MAIN) 

ENDPGM

Simple right?

PS: I'm not saying this as the best solution. It's definitely not the most elegant. But, it is a simple solution if you want to quickly ask a user a question and act on the answer!

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