Within COBOL, a logic control statement referred to as EVALUATE TRUE is commonly used.
It functions similarly to switch-case statements found in other languages or the match-case statement found in Python, except for its ability to resolve logical expressions within its cases.
See the example below;
EVALUATE TRUE
WHEN (TRANSACTION_AMOUNT > MINIMUM_AMOUNT) AND (PAYMENT_METHOD = ‘CASH’)
{do something}
WHEN (TRANSACTION_AMOUNT < MINIMUM_AMOUNT) AND (PAYMENT_METHOD = ‘CARD’)
{do something}
END-EVALUATE
Note the WHEN conditions are what is evaluated and TRUE is what we’re “matching” to.
The magic is in the conditions themselves. In the event TRANSACTION_AMOUNT = 10.00, MINIMUM_AMOUNT = 5.00 and PAYMENT_METHOD = ‘CASH’, the first WHEN condition is resolved as TRUE, and subsequently its code is executed. Otherwise, the next WHEN condition is resolved, and so on.
This functionality doesn’t exist within Python match-case statements. While there are other methods that can be used to emulate this, I think it would be a useful enhancement to the language. This would be an example of how it might look in Python;
matchTrue:
case (trans_amount > min_amount and pay_method.is_cash()):
{do something}
case (trans_amount < min_amount and pay_method.is_card()):
{do something}