View previous topic :: View next topic
|
Author |
Message |
alluri12
New User
Joined: 15 Aug 2006 Posts: 44 Location: Virginia, USA
|
|
|
|
Hi,
I have a variable length file input 500 bytes. I need to write that to FB output file 80 bytes.
I have to copy input file based on
1st record 1 to 72 position with 72 position = spaces to the output file.
If 72nd position is not spaces then need to check 71 position if SPACES then write to output file.
Then
From position we wrote (71 or 72) to next 72 position copy to output file if 144 or 143 is spaces.
From position we wrote (143 or 144) to next 72 position copy to output file if 221 or 222 is spaces.
Follow same till end of 1st record(500 bytes). then set a flag if end of 1st record.
once end of record
follow same as above for 2nd record and so on
Bottom line i need to split each input record into different 72 or 71 bytes in the output file USING COBOL program.
Here is the small Example of input file
.) AAA 1234567890 ABCDEFGHIJKLM AAAA AAAAAA BBBBBB CCCC DDD
.) AAA 1234567890 ABCDEFGHIJKLM AAAA AAAAAA BBBBBB CCCC DDD
Output file will be
.) AAA 1234567890
ABCDEFGHIJKLM
AAAA AAAAAA
BBBBBB CCCC
DDD
.) AAA 1234567890
ABCDEFGHIJKLM
AAAA AAAAAA
BBBBBB
CCCC
DDD
Could anybody please help me on this...
Thanks
Suresh |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
alluri12 wrote: |
Code: |
.) AAA 1234567890 ABCDEFGHIJKLM AAAA AAAAAA BBBBBB CCCC DDD
.) AAA 1234567890 ABCDEFGHIJKLM AAAA AAAAAA BBBBBB CCCC DDD |
Code: |
.) AAA 1234567890
ABCDEFGHIJKLM
AAAA AAAAAA
BBBBBB CCCC
DDD
.) AAA 1234567890
ABCDEFGHIJKLM
AAAA AAAAAA
BBBBBB
CCCC
DDD |
|
How come if the two input are identical, why are the outputs different? |
|
Back to top |
|
|
alluri12
New User
Joined: 15 Aug 2006 Posts: 44 Location: Virginia, USA
|
|
|
|
Oh my mistake.... It should be identical. Looks like i pressed enter twice.
.) AAA 1234567890
ABCDEFGHIJKLM
AAAA AAAAAA
BBBBBB CCCC
DDD
.) AAA 1234567890
ABCDEFGHIJKLM
AAAA AAAAAA
BBBBBB CCCC
DDD |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
What have you coded so far?
I'm a bit confused. Your "rules" say that you want to split after 71 or 72 bytes, but your example splits after far fewer bytes.
Where does the end-of-record flag come into the picture?
If you post what you have so far, and clarify the rules, we will be better able to offer suggestions. |
|
Back to top |
|
|
sandy_venkat
New User
Joined: 16 May 2007 Posts: 35 Location: India
|
|
|
|
Dick, i think he is just giving us an example of how the records are split. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Could be, but if so, the "rules" should be restated to match the sample data.
The code will be basically the same, just the break-points will be at different displacements.
Also, what should happen if neither of the break-point positions contains a space? Should a value just be chopped off or should the parser "back up" to the most recent space and write the record? |
|
Back to top |
|
|
socker_dad
Active User
Joined: 05 Dec 2006 Posts: 177 Location: Seattle, WA
|
|
|
|
Sounds like a COBOL 101 homework assignment to me. |
|
Back to top |
|
|
jayachandra
New User
Joined: 08 Mar 2007 Posts: 3 Location: mumbai
|
|
|
|
Hello,
Try this piece of code
FD INPUT-FILE.
01 WS-FILE.
05 WS-FILE-READ PIC X(500).
05 WS-REDIF-FILE REDEFINES WS-FILE-READ.
10 WS-SPLIT PIC X(71) OCCURS 8 TIMES.
FD OUTPUT-FILE
01 WS-OUT-REC PIC X(80).
.
.
.
MOVE HIGH-VALUES TO WS-REDIF-FILE.
READ INPUT-FILE.
PERFORM ARR-CNT FROM 1 BY 1
UNTIL ARR-CNT > 8
OR END-OF-RECORD
MOVE ZEROES TO WS-CNT
INSPECT WS-SPLIT(ARR-CNT)
TALLYING WS-CNT FOR LEADING HIGH-VALUES
IF WS-CNT = 71
SET END-OF-RECORD TO TRUE
ELSE
MOVE SPACES TO WS-OUT-REC
WRITE WS-OUT-REC FROM WS-SPLIT(ARR-CNT)
END-IF
END-PERFORM.
HOPE THIS MEETS UR REQUIREMENT |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello jayachandra,
Please review the requirement first posted and compare it to your suggestion.
Your code does not match "the rules" posted. |
|
Back to top |
|
|
star_dhruv2000
New User
Joined: 03 Nov 2006 Posts: 87 Location: Plymouth, MN USA
|
|
|
|
HI,
Please let me know if following worked for you:
Code: |
01 WS-VAR1 PIC 9(03).
77 END-OF-FILE-FLAG PIC X(01) VALUE 'N'.
88 END-OF-FILE-YES VALUE 'Y'.
88 END-OF-FILE-NO VALUE 'N'.
MAINLINE-PARA.
PERFORM READ-FILE-PARA
THRU READ-FILE-EXIT
IF END-OF-FILE-NO
PERFORM UNTIL END-OF-FILE-YES
MOVE 72 TO WS-VAR1
PERFORM UNTIL WS-VAR1 >= 500
EVALUATE TRUE
WHEN IN-REC(WS-VAR1:1) <= SPACES
MOVE (WS-VAR1:72) TO OUT-REC
WHEN IN-REC(WS-VAR1-1:1) <= SPACES
MOVE (WS-VAR1:71) TO OUT-REC
END-EVALUATE
WRITE OUT-REC
ADD 72 TO WS-VAR1
END-PERFORM
MOVE 'NEW RECORD' TO OUT-REC
WRITE OUT-REC
PERFORM READ-FILE-PARA
THRU READ-FILE-EXIT
END-PEFORM
ELSE
DISPLAY 'INPUT FILE HAS NO RECORDS'
END-IF.
STOP RUN.
MAINLINE-EXIT.
EXIT.
EJECT
READ-FILE-PARA.
READ INFILE
AT END SET END-OF-FILE-YES TO TRUE.
READ-FILE-EXIT.
EXIT.
EJECT |
Cheers! |
|
Back to top |
|
|
|