[Stackoverflow] [Progress OpenEdge ABL] make 4 digits if its less than 4 digit - Progress 4GL

Status
Not open for further replies.
B

Bharat

Guest
I want to convert a data to 4 digits value if it is less than 4 digits. for example, data1 is 145 then the program should convert it to 0145. Need to put 0 in front of the number to make it four. I tried below query but I feel this is not a correct way to do it. Note - I used variable cdata to store the data but no idea about while storing the data into table field should be stored as 4 digits value.

i.e if user enter value 1 then it should store 0001 in table field. If the user enter four and more than four digits value , Need to store as it is..no prefix to be added

Code:
define variable cdata as character no-undo.
cdata = "183".
if length(cdata) < 4 then cdata = "0" + cdata.
else if length(cdata) < 3 then cdata = "00" + cdata.
else if length(cdata) < 2 then cdata = "000" + cdata.

Continue reading...
 
Status
Not open for further replies.
Top