I'm an AS/400 Cobol/RPG programmer. I'm struggling with something, which should be easy. I'm trying to allow a...
user to INPUT a negative number, but permit the sign on either side of the number. When INPUT is done with the sign on the left side, the number displays as positive. Any solutions?
Example: A UNPDCURR01 10Y02B 11 30 A DSPATR(UL) A* EDTCDE(Z) A EDTWRD(' , , 0 . -') A TEXT('UNPD-CURR-01') A CHANGE(18) A 14 DSPATR(PR) A 15 DSPATR(HI) A 15 DSPATR(PC) A 16 DSPATR(ND) A 15 COLOR(RED) A 14 COLOR(BLU)
Unfortunately, there are no "Pretty" solutions for this one. The AS/400 Workstation Display Manager does not allow an edit code or an edit word that will allow a negative sign on either side. Furthermore, in order for it to interpret the value as negative, the Field (-) key must be used. When a user enters a negative sign (-) to the left of the value, the Workstation Display Manager strips it, considering it an invalid character. You could change the field to a 13A and an keyboard shift of "M" to only allow 0-9, periods, commas, blank(s) and/or the plus or minus sign. However, this may also cause problems because you would then have to edit the data yourself. The Workstation Display Manager would only edit to see if the entered keystroke matches one of the above. It would be possible for a user to enter something like "-+123.45 32- " without generating an error. Additionally, if the user hits the field (-) key, the data could look something like "123456(})". The "(})" in the rightmost position indicates that the field (-) key was used. If you were to do your own editing, you might use multiple scans to check for more than one entry of the "-" and/or "+" signs. You would also need to strip out the commas, and check for imbedded blanks. The editing for multiple minus signs might look something like: * Check for entry of both positive and negative C '-' Scan scChar:1 sPos C '+' Scan scChar:1 sPtest C sPos IfGt *Zeros C sPtest AndGt *Zeros C Eval iError = iTrue C Else * Check for more than one negative C Eval scChar = %trim(unpdc2) C '-' Scan scChar:1 sPos C sPos IfGt *Zeros C Eval sPtest = sPos +1 C '-' Scan scChar:sPtest sPTest C sPTest IfGt *Zeros * Set Error Condition C Eval iError = iTrue C Else C Eval iNegative = iTrue C End C End * Check for more than one positive C Eval scChar = %trim(unpdc2 C '+' Scan scChar:1 sPos C sPos IfGt *Zeros C Eval sPtest = sPos +1 C '+' Scan scChar:sPtest sPTest C sPTest IfGt *Zeros * Set Error Condition C Eval iError = iTrue C End C Else * Strip out Plus signs C '+':' ' Xlate unpdc2 scChar C End C End You would then have to strip out the commas and check for imbedded blanks. There might be easier ways, but in any event, it will be "UGLY".
Related Q&A from John Brandt
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.