Easytrieve program to parse a string

Below program parses a string that contains 3 words which are separated by space.

FULL-NAME contains ‘KARTHIK KAR THIK’, which is split into First name, Middle name and Last name.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 DEFINE IND1 W 3 N VALUE 1 
 DEFINE IND2 W 3 N VALUE 1 
 DEFINE FLAG W 1 N VALUE 1 
 DEFINE FULL-NAME W 30 A VALUE 'KARTHIK KAR THIK' 
 DEFINE FIRST-NAME W 15 A 
 DEFINE MID-NAME W 15 A 
 DEFINE LAST-NAME W 15 A 
 DEFINE FULL-NAME-ARRAY  FULL-NAME  1 A OCCURS 30 
 DEFINE FIRST-NAME-ARRAY FIRST-NAME 1 A.OCCURS 15 
 DEFINE MID-NAME-ARRAY   MID-NAME   1 A OCCURS 15 
 DEFINE LAST-NAME-ARRAY  LAST-NAME  1 A OCCURS 15 
 JOB INPUT NULL 
   DO WHILE IND1 LE 30 
      IF FULL-NAME-ARRAY(IND1) NE ' '
         CASE FLAG 
            WHEN 1 
              MOVE FULL-NAME-ARRAY(IND1) TO FIRST-NAME-ARRAY(IND2)
            WHEN 2 
              MOVE FULL-NAME-APRAY(IND1) TO MID-NAME-ARRAY(IND2) 
            WHEN 3 
              MOVE FULL-NAME-ARRAY(IND1) TO LAST-NAME-ARRAY(IND2) 
         END-CASE 
         IND2 = IND2 + 1 
      ELSE 
         IND2 = 1 
         FLAG = FLAG + 1
      END-IF 
      IND1 = IND1 + 1 
   END-DO 
   DISPLAY FIRST-NAME 
   DISPLAY MID-NAME 
   DISPLAY LAST-NAME 
STOP

Output will be,

KARTHIK
KAR
THIK

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.