Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Split the i/p record to 2 or 3 using cobol code
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: 3158
Location: Tucson AZ

PostPosted: Tue Aug 28, 2007 10:19 pm    Post subject: Re: Split the i/p record to 2 or 3 using cobol code
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    Post subject:
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

Site Director


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

PostPosted: Tue Aug 28, 2007 11:51 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Aug 29, 2007 7:41 pm    Post subject:
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: 147
Location: Columbia, MO

PostPosted: Thu Aug 30, 2007 1:38 am    Post subject: Reply to: Split the i/p record to 2 or 3 using cobol code
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    Post subject:
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

Site Director


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

PostPosted: Thu Aug 30, 2007 6:17 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts How to Capture the Max return code of... anilkumar922 All Other Mainframe Topics 0 Thu Jan 12, 2017 12:02 pm
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us