View previous topic :: View next topic |
Author |
Message |
sushshibu Beginner
Joined: 21 Jul 2004 Posts: 3 Topics: 3 Location: chennai
|
Posted: Wed Jul 21, 2004 11:44 pm Post subject: How to use the occurs clause with files |
|
|
Hi
how do we use the occurs clause in files i.e. how do we do it. just check this pgm please
Code: |
FILE SECTION.
FD INFILE
RECORD CONTAINS 80 CHARACTERS
RECORDING MODE IS F.
01 IN-REC.
02 EMP OCCURS 3 TIMES.
03 EMP-ID PIC X(4).
03 FILLER PIC X.
03 EMP-NAME PIC X(10).
03 FILLER PIC X.
03 EMP-SALARY PIC 999V99.
01 IN-NEW.
02 EMP1 OCCURS 3 TIMES.
03 EMP-ID1 PIC X(4).
03 FILLER PIC X.
03 EMP-NAME1 PIC X(10).
03 FILLER PIC X.
03 EMP-SALARY1 PIC 999V99.
WORKING-STORAGE SECTION.
77 I PIC 9.
77 K PIC X(2).
PROCEDURE DIVISION.
P1.
OPEN OUTPUT INFILE.
PERFORM P2 VARYING I FROM 1 BY 1 UNTIL I > 3.
PERFORM P3 VARYING I FROM 1 BY 1 UNTIL I > 3.
CLOSE INFILE.
STOP RUN.
P2.
ACCEPT EMP-ID(I).
ACCEPT EMP-NAME(I).
ACCEPT EMP-SALARY(I).
P3.
MOVE EMP-ID(I) TO EMP-ID1(I).
MOVE EMP-NAME(I) TO EMP-NAME1(I).
MOVE EMP-SALARY(I) TO EMP-SALARY1(I).
WRITE IN-NEW.
|
the file compilation and execution is successful but it is being written as follows
Code: |
M101 SUSHMA 99999M102 SHIVANI 99999M103 NAMRATA 99999
0
0
|
this is how my records are being written. why is this. what should i do if i want to write the records one below the other and where am i doing the mistake.
please help
sush |
|
Back to top |
|
|
Meg Beginner
Joined: 08 Jul 2003 Posts: 44 Topics: 16
|
Posted: Thu Jul 22, 2004 4:01 am Post subject: |
|
|
Hi Sush,
I think you should be doing the following:
PERFORM P2 VARYING I FROM 1 BY 1 UNTIL I > 3.
P2
ACCEPT EMP-ID(I).
ACCEPT EMP-NAME(I).
ACCEPT EMP-SALARY(I).
MOVE EMP-ID(I) TO EMP-ID1(I).
MOVE EMP-NAME(I) TO EMP-NAME1(I).
MOVE EMP-SALARY(I) TO EMP-SALARY1(I).
WRITE IN-NEW.
The paragraph p3 should not be perfomed after performing all the iterations of p2, but should be performed after each iteration.
Thanks,
Meg |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Jul 22, 2004 4:05 am Post subject: |
|
|
sushshibu,
I guess you are confused with occur clause. If your sole intention is to write one record after another then you don't need an occurs clause. change your code for IN-REC & IN-NEW to the following
Code: |
01 IN-REC.
03 EMP-ID PIC X(4).
03 FILLER PIC X.
03 EMP-NAME PIC X(10).
03 FILLER PIC X.
03 EMP-SALARY PIC 999V99.
|
Code: |
01 IN-NEW.
03 EMP-ID1 PIC X(4).
03 FILLER PIC X.
03 EMP-NAME1 PIC X(10).
03 FILLER PIC X.
03 EMP-SALARY1 PIC 999V99.
|
Code: |
PROCEDURE DIVISION.
P1.
OPEN OUTPUT INFILE
PERFORM P2 3 TIMES
CLOSE INFILE
STOP RUN.
P2.
ACCEPT EMP-ID1.
ACCEPT EMP-NAME1.
ACCEPT EMP-SALARY1.
WRITE IN-REC FROM IN-NEW
INTIALIZE IN-NEW
|
This will produce
Code: |
----+----1----+----2----+
M101 SUSHMA 99999
M102 SHIVANI 99999
M103 NAMRATA 99999
|
Hope this helps..
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
|
|