Skip to content

Feature Request: AddParameterInd() - for indicator parameters. #221

@dickdonohue

Description

@dickdonohue

If you use AddParameterZoned() when the parameter is a zoned field, and you use AddParameterChar() when the parameter is a character field, doesn't it make sense that when adding a Parameter that is an indicator (boolean), you use AddParameterInd() function?

This would be especially useful for functions in a *SRVPGM that have an indicator return value (e.g. to indicate success or not).

I think this code might work and allow flexibility for what values you use to set the value. It would even allow for passing an array of indicators.
I'd be happy to create the pull request, etc. if somebody was willing to help me do that (I've never done it before).

static function AddParameterInd($io, $comment, $varName = '', $value = '', $dimension = 0,
    $by = '', $isArray = false, $ccsidBefore = '', $ccsidAfter = '', $useHex = false
) {
    // on/*on/yes/true/1/'1' becomes '1'
    // off/*off/no/false/0/'0' and anything else (e.g. 'x') becomes '0'
    // trim off any leading "*" character, and convert to lower-case, then let `filter_var` set the value
    $value   = (filter_var(
        ltrim( strtolower( (string) ($value ) ), '*' ),
        FILTER_VALIDATE_BOOLEAN,    FILTER_NULL_ON_FAILURE
    ) ?? false) ? '1' : '0';

    // these two parms are needed for CharParam, but are removed from param list for this function
    $varying = 'off'; // can't have a varying indicator
    $size = '1'; // indicator is always '1' or '0' 
    return new CharParam(
        $io, $size, $comment, $varName, $value, $varying, $dimension, $by,
        $isArray, $ccsidBefore, $ccsidAfter, $useHex
    );
}

Example Uses:

$parms[] = $toolkit::AddParameterInd('both', 'is Customer', 'isCustomer', '*on'); 
$retVal[] = $toolkit::AddParameterInd('out', 'success', 'success');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions