Search code examples
ibm-midrange

AS400 WRKQRY Concatenate Decimal


Within WRKQRY > Define Result Fields is throwing an error when trying to concatenate two fields where one field contains a decimal.

How do I get a value with a decimal to concatenate?

DSICF = .400

DSIUM = MG

Field       Expression                         Column Heading       
DOSE        DSICF||DSIUM                       DOSE

Value not allowed with concatenation operator.

After doing research, IBM states if any field in the expression is a double-byte character set (DBCS)-graphic, all fields or constants in the expression must be DBCS-graphic.

Still researching.


Solution

  • Numeric fields with decimals have to be converted to a string first. However, you lose the decimal in this conversion. In order to add the decimal back, you must parse the string and manually concatenate the decimal.

    Example

    DCIFC = 0.400
    DCIUM = MG
    
    Field           Expression
    CNVRTUNIT        digits(DCIFC)  //Converts .400 to 0000000400 
    
    NEWUNIT         substr(CNVRTUNIT,7,1)||'.'||substr(CNVRTUNIT,8,2)||'/'||DCIUM
    
    -----
    NEWUNIT now equals 0.400/MG