I want to retrieve the number of records in a file and use that to build a text message. If I use RTVMBRDSC tot get the record count into &RCDCNT and then use CHGVAR to move &RCDCNT to an alpha variable, I get all of the leading zeroes. What is the easiest way to suppress the leading zeroes? I know I can do some looping to remove the leading zeroes but is there an easier way?
Announcement
Collapse
No announcement yet.
Zero suppress in CL
Collapse
X
-
If there's a possibility of &RCDCNT being zero, the %TRIML would trim off all the zeros, leaving blank. This version checks in advance for zero.
Code:IF &RCDCNT *eq 0 THEN(CHGVAR VAR(&RCDCNTA) VALUE('0')) ELSE DO CHGVAR VAR(&RCDCNTA) VALUE(&RCDCNT) CHGVAR VAR(&RCDCNTA) VALUE(%TRIML(&RCDCNTA '0')) ENDDO CHGVAR VAR(&MSG) VALUE('Record count:' *BCAT &RCDCNTA)
Comment
-
Good point about a possible zero value for the record count. Here's a version without that pesky DO and ENDDO (sorry, I couldn't help myself ):
Code:CHGVAR VAR(&RCDCNTA) VALUE(&RCDCNT) CHGVAR VAR(&RCDCNTA) VALUE(%TRIML(&RCDCNTA '0')) IF COND(&RECCNTA = ' ') THEN(CHGVAR VAR(&RCDCNTA) VALUE('0')) CHGVAR VAR(&MSG) VALUE('Record count:' *BCAT &RCDCNTA)
Comment
Comment