View previous topic :: View next topic |
Author |
Message |
vallabhaneni Beginner
Joined: 26 Dec 2002 Posts: 23 Topics: 7
|
Posted: Fri Jan 10, 2003 1:59 pm Post subject: occurs |
|
|
Hi all,
I have a field in occurs(5 times) clause in file ,I want to write that file 5 times.Can you help me with syntax.
Thanks
Vallabhaneni |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Fri Jan 10, 2003 2:56 pm Post subject: |
|
|
Vallabhaneni,
The following program will give you the desired results.
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTA
DATE-COMPILED.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE
ASSIGN TO INFILE
ORGANIZATION IS SEQUENTIAL.
SELECT OUT-FILE
ASSIGN TO OUTFILE
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD IN-FILE
RECORDING MODE F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS IN-REC.
01 IN-REC.
05 IN-KEY PIC X(10) OCCURS 5 TIMES.
FD OUT-FILE
RECORDING MODE F
LABEL RECORDS ARE STANDARD
BLOCK CONTAINS 0 RECORDS
DATA RECORD IS OUT-REC.
01 OUT-REC.
05 OUT-KEY PIC X(10).
WORKING-STORAGE SECTION.
01 W-SUB PIC 9(1).
01 S-IN-FILE PIC X(1) VALUE 'N'.
PROCEDURE DIVISION.
PERFORM 1000-INITIALIZATION
PERFORM 2000-MAIN-PROCESS UNTIL S-IN-FILE = 'Y'
PERFORM 3000-WRAPUP
GOBACK
.
1000-INITIALIZATION.
*************************************************************
* THIS PARAGRAPH OPENS INPUT AND OUTPUT FILES AND DOES THE *
* PRIME READ. *
*************************************************************
OPEN INPUT IN-FILE
OUTPUT OUT-FILE
PERFORM 2100-READ-IN-FILE
.
2000-MAIN-PROCESS.
*************************************************************
*THIS PARAGRAPH PERFORMS THE MAIN LOGIC *
*************************************************************
PERFORM VARYING W-SUB FROM 1 BY 1 UNTIL W-SUB > 5
MOVE IN-KEY (W-SUB) TO OUT-KEY
WRITE OUT-REC
MOVE SPACES TO OUT-REC
END-PERFORM
PERFORM 2100-READ-IN-FILE
.
2100-READ-IN-FILE.
*************************************************************
*THIS PARAGRAPH READS THE IN-FILE *
*************************************************************
READ IN-FILE
AT END
MOVE 'Y' TO S-IN-FILE
END-READ
.
3000-WRAPUP.
*************************************************************
* THIS PARAGRAPH CLOSES THE INPUT & OUTPUT FILES. *
*************************************************************
CLOSE IN-FILE
OUT-FILE
.
|
Hope this helps...
cheers
kolusu |
|
Back to top |
|
|
vallabhaneni Beginner
Joined: 26 Dec 2002 Posts: 23 Topics: 7
|
Posted: Fri Jan 10, 2003 3:14 pm Post subject: |
|
|
Thank you very much kolusu
Vallabhaneni |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Mon Jan 13, 2003 1:28 pm Post subject: |
|
|
Vallabhaneni,
I moved the other topic to the similar topic. Please post all your similar queries in one forum.
Hi All,
I am moving records from input file to output file.One filed in input file having 8 times occurs but I need only five times in output.
Input Record 1
Code: |
01 file1 pic x.
01 filed2 pic 9.
01 field3 pic 9(2).
01 field4 occurs 8 times indexed by field.
05 code1 pic 9(3)
88 value1 '111'
88 value2 '112'
|
Output record
Code: |
01 filed pic x.
01 filed pic 9.
01 field pic 9(2).
01 field occurs 5 times indexed by fiel
05 code2 pic 9(3).
88 value1 '111'
88 value2 '112"
|
Can you help me how can I control in between moves i.e
move filef1 to field
move field 2 to field
PERFORM VARYING field +1 BY +1
UNTIL field GREATER +8
MOVE code1 (field) TO code2(field)
SET fiel +1
end-perform.
This will write 8 occurances frim input to output I need a put a contol to get only five occurances.
When I am in editing screen it is ok,when I did hit submit button after thet when I go to preview page it is not showing properly.
Thanks |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Mon Jan 13, 2003 1:34 pm Post subject: |
|
|
Vallabhaneni,
If you want only 5 occurances in the output file then control the perform for only 5 times. Change your perform statement to the following and and you don't need an explicit SET command to increment the counter.
Code: |
PERFORM VARYING field +1 BY +1 UNTIL field > 5
MOVE code1 (field) TO code2(field)
End-perform.
|
I suggest you read the cobol manual to get a clear idea of OCCURS AND GROUP MOVES
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3PG00/CCONTENTS
Hope this helps...
cheers
kolusu |
|
Back to top |
|
|
|
|