I'm trying to merge several lines in one file so that it prints out as one record in another file. Something seems to be making my code go into infinite loops though as it is taking my program almost 300 seconds to run and that only because I ended the job manually.
The program is supposed to combine all the lines for a single order and write or update the combined lines as one record in another file. Below are the details
Input file - OrdIns
A R OrdInst
*
A S4SORD 10
A S4SLIN 2
A S4DATA 40
A K S4SORD
A K S4SLIN
The records would look like
Order12345 1 instruction1
Order12345 2 instruction2
Order12345 3 instruction3
Output/Update file - StorIns
A R PSHPINS
A ORD# 10
A INST1 40
A INST2 40
A INST3 40
A INST4 40
A INST5 40
The contents should look like:
Order12345 instruction1 instruction2 instruction3
Below is the program I;ve come up with:
FBBOSINS4 IF E K DISK
FBSHIPINS UF A E K DISK
*
D DS
D INST1 11 50
D INST2 51 90
D INST3 91 130
D INST4 131 170
D INST5 171 210
D txtFields 11 210 DIM(5)
*
D tmpOrd S 10A
D recstat S 1A
D indx S 1s 0
/FREE
Read OrdIns;
tmpOrd = S4SORD;
Dow not %eof(OrdIns);
Clear txtFields;
Chain(E) S4SORD StorIns;
If %found(StorIns);
recstat = 'U';
Clear txtFields;
Else;
recstat = 'A';
Endif;
Dow S4SORD = tmpOrd;
indx = %DEC(S4SLIN:1:0);
txtFields(indx) = S4DATA;
Reade tmpOrd OrdIns;
Enddo;
If recstat = 'A';
write PSHPINS;
endif;
If recstat = 'U';
update PSHPINS;
endif;
tmpOrd = S4SORD;
Enddo;
*inlr = *on;
/END-FREE
Any advice would be greatly appreciated.
The program is supposed to combine all the lines for a single order and write or update the combined lines as one record in another file. Below are the details
Input file - OrdIns
A R OrdInst
*
A S4SORD 10
A S4SLIN 2
A S4DATA 40
A K S4SORD
A K S4SLIN
The records would look like
Order12345 1 instruction1
Order12345 2 instruction2
Order12345 3 instruction3
Output/Update file - StorIns
A R PSHPINS
A ORD# 10
A INST1 40
A INST2 40
A INST3 40
A INST4 40
A INST5 40
The contents should look like:
Order12345 instruction1 instruction2 instruction3
Below is the program I;ve come up with:
FBBOSINS4 IF E K DISK
FBSHIPINS UF A E K DISK
*
D DS
D INST1 11 50
D INST2 51 90
D INST3 91 130
D INST4 131 170
D INST5 171 210
D txtFields 11 210 DIM(5)
*
D tmpOrd S 10A
D recstat S 1A
D indx S 1s 0
/FREE
Read OrdIns;
tmpOrd = S4SORD;
Dow not %eof(OrdIns);
Clear txtFields;
Chain(E) S4SORD StorIns;
If %found(StorIns);
recstat = 'U';
Clear txtFields;
Else;
recstat = 'A';
Endif;
Dow S4SORD = tmpOrd;
indx = %DEC(S4SLIN:1:0);
txtFields(indx) = S4DATA;
Reade tmpOrd OrdIns;
Enddo;
If recstat = 'A';
write PSHPINS;
endif;
If recstat = 'U';
update PSHPINS;
endif;
tmpOrd = S4SORD;
Enddo;
*inlr = *on;
/END-FREE
Any advice would be greatly appreciated.