Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Parse a Field

Status
Not open for further replies.

gotluru

Programmer
Oct 16, 2000
10
US
Hi,
I have free form field, i want to parse one field into 3 differant Numeric fields Numeric

Ex: 19Yrs20Months44Days
Yrs : 19
Months: 20
Days: 44

Thanks in Advance,

Prasad

 
Hi Prasad,

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.

Regards, Jack.
 
Hello

It depending from which cobol you are using.
A simple way to extract the yrs, months and days value could be :

WORKING-STORAGE SECTION.
01 TIME-VALUE PIC X(50) VALUE "19Yes20Months44Days".
01 Yrs PIC XX.
01 Months PIC XX.
01 Days PIC XX.

PROCEDURE DIVISION.

...
MOVE TIME-VALUE (1:2) TO YRS
MOVE TIME-VALUE (6:2) TO MONTHS
MOVE TIME-VALUE (14:2) TO DAYS


I tested it using Powercobol and it works.

That's All!

Hope in this help..

Regards, Gianni
 
Hi Prasad,

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.

Jack
 
Hi Jack and Gianni,

Thanks for all your help.

I used unstring with delimiter phrase. It works.

Thanks once again.

Prasad
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top