Larry is an Avid Reader. No contributions for 2024.
Without a doubt, there will be something to
share on the Community in 2025!
User bio
404 bio not found
Member since Mar 23, 2018
Replies:

Try this:

ROU>s val="sd123X"             ; value to be justified

ROU>s len=9                             ; length of the total string

ROU>k z                                      ; make sure z is undefined

ROU>s $P(z,"0",len)=val        ; set z to value with leading zeros

ROU>s val=$E(z,*-(len-1),*)   ; trim value to required length

ROU>w !,val

000sd123X

While adding the length check is valid for a pure coding solution, the most practical reason where leading zero's are necessary is for values that are required to be a fixed length such as SSN's.

If a value initially  exceeded that fixed length, it most likely would have been trapped out as an invalid entry before it reached the length adjustment code.

Certifications & Credly badges:
Larry has no Certifications & Credly badges yet.
Global Masters badges:
Larry has no Global Masters badges yet.
Followers:
Larry has no followers yet.
Following:
Larry has not followed anybody yet.