You didn't mention your environmment, so I'll assume it's one of the COBOLs. Take a look at the UNSTRING stmt, especially the DELIMITED BY clause. I think it'll do what you're looking for.
Gianni's solution is the more efficient solution if the fields are of constant length. You can even make it more efficient in this case by defining the field as follows:
05 whole-date.
10 f pic x(003).
10 yrs pic 9(002).
10 f pic x(006).
10 mos pic 9(002).
10 f pic x(004).
10 days pic 9(002).
Then move yrs, mos, days to a numeric fld or leave them where they are since the field is defined as numeric.
But the more usual case is that the field will be variable, e.g.:
19yrs20months44days
6yrs7months121days
19yrs6months3days
etc.
In this case UNSTRING is one of the preferred solutions.
A free form field is always a bad idea.
Never let a user input information like a date in a field unless you govern the rules the field is going to be stored by; otherwise you have garbage in and garbage out.
a date could be 6/6/2001, 6-6-2001, June 6 2001, 20010606.
This is a programming error not a user error. You have to expect the user to enter anything possible. A good rule of thumb is to store all dates the same way in every file you have. I prefer yyyymmdd because it sorts well. Even if the user enters 6/6/2000 I would still store it yyyymmdd.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.