IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Split the i/p record to 2 or 3 using cobol code


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
alluri12

New User


Joined: 15 Aug 2006
Posts: 44
Location: Virginia, USA

PostPosted: Tue Aug 28, 2007 9:26 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Aug 28, 2007 10:19 pm
Reply with quote

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
View user's profile Send private message
alluri12

New User


Joined: 15 Aug 2006
Posts: 44
Location: Virginia, USA

PostPosted: Tue Aug 28, 2007 10:30 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Aug 28, 2007 11:51 pm
Reply with quote

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
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Wed Aug 29, 2007 8:47 am
Reply with quote

Dick, i think he is just giving us an example of how the records are split.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 29, 2007 7:41 pm
Reply with quote

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
View user's profile Send private message
socker_dad

Active User


Joined: 05 Dec 2006
Posts: 177
Location: Seattle, WA

PostPosted: Thu Aug 30, 2007 1:38 am
Reply with quote

Sounds like a COBOL 101 homework assignment to me.
Back to top
View user's profile Send private message
jayachandra

New User


Joined: 08 Mar 2007
Posts: 3
Location: mumbai

PostPosted: Thu Aug 30, 2007 2:28 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 30, 2007 6:17 pm
Reply with quote

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
View user's profile Send private message
star_dhruv2000

New User


Joined: 03 Nov 2006
Posts: 87
Location: Plymouth, MN USA

PostPosted: Mon Feb 18, 2008 12:00 pm
Reply with quote

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! icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts run rexx code with jcl CLIST & REXX 15
Search our Forums:

Back to Top