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

Replicating records ina flat file


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

New User


Joined: 14 Aug 2007
Posts: 1
Location: kochin

PostPosted: Wed Mar 09, 2011 12:18 am
Reply with quote

Hi I have a file with 1 header 1 footer and 1 detailed record.

I want to replicate only the detailed record to say 1 million times with same data except 2 fileds unique(acct number and another field ), remaining all fileds in the detailed record should be same.

So my output file should have 1 header, 1 footer and 1 million detailed record.

Can someone tell me the cobol code for this?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Wed Mar 09, 2011 12:22 am
Reply with quote

Yes, but given that you can't even be bothered to post in the correct forum it is unlikely that anyone will.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Mar 09, 2011 12:50 am
Reply with quote

Just how is the process to determine what the million acct numbers are the other undefined field.
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 Mar 09, 2011 1:05 am
Reply with quote

Hello and welcome to the forum,

First - you need to learn that JCL cannot do this. . . Never has , never will. JCL EXECutes things. That is all it does.

This may be done using some utility (like the sort) or code you have written. Neither is JCL. . .

Which release of which sort product is used on your system?

And one the tool has been decided, you need to answer Craig's question:
Quote:
Just how is the process to determine what the million acct numbers are the other undefined field.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Wed Mar 09, 2011 2:39 am
Reply with quote

Since you asked for a COBOL solution, here is some COBOL Pseudo-code I quickly cobbled together - Assumes that both Acct Number and Other Field are numeric, and can accommodate numbers up to and including one million - adjust as needed.
Code:

Be sure to specify the FILE STATUS clause in the SELECTs pointing to STATUS-CODE
Define FD's for your INPUT-FILE with INPUT-HEADER, INPUT-DETAIL, and INPUT-TRAILER
            and your OUTPUT-FILE with OUTPUT-HEADER, OUTPUT-DETAIL, and OUTPUT-TRAILER (with the fields to be overlaid defined as well)


In the WORKING-STORAGE SECTION:

define SW-IP-OPEN with a PICTURE of X.
define SW-OP-OPEN with a PICTURE of X.
define SW-ERROR with a PICTURE of X.
define STATUS-CODE with a PICTURE of XX.
define SUB-SCRIPT with a PICTURE of S9(9) COMP.


In the PROCEDURE DIVISION:

MOVE 'N' TO SW-ERROR
OPEN INPUT INPUT-FILE
IF STATUS-CODE NOT = '00'
THEN
   DISPLAY 'ERROR OPENING INPUT-FILE'
   DISPLAY 'STATUS CODE WAS ' STATUS-CODE
   MOVE 'N' TO SW-IP-OPEN
   MOVE 'Y' TO SW-ERROR
ELSE
   MOVE 'Y' TO SW-IP-OPEN
   OPEN OUTPUT OUTPUT-FILE
   IF STATUS-CODE NOT = '00'
   THEN
      DISPLAY 'ERROR OPENING OUTPUT-FILE'
      DISPLAY 'STATUS CODE WAS ' STATUS-CODE
      MOVE 'N' TO SW-OP-OPEN
      MOVE 'Y' TO SW-ERROR
   ELSE
      MOVE 'Y' TO SW-OP-OPEN
      READ INPUT-FILE
         AT END
            DISPLAY 'INPUT FILE IS EMPTY'
            MOVE 'Y' TO SW-ERROR
      END-READ
      IF SW-ERROR = 'N' AND
         STATUS-CODE NOT = '00'
      THEN
         DISPLAY 'ERROR READING HEADER RECORD'
         DISPLAY 'STATUS CODE WAS ' STATUS-CODE
         MOVE 'Y' TO SW-ERROR
      END-IF
   END-IF
END-IF
IF SW-ERROR = 'N'
THEN
   MOVE INPUT-HEADER TO OUTPUT-HEADER
   WRITE OUTPUT-HEADER
   IF STATUS-CODE NOT = '00'
   THEN
      DISPLAY 'ERROR WRITING HEADER RECORD'
      DISPLAY 'STATUS CODE WAS ' STATUS-CODE
      MOVE 'Y' TO SW-ERROR
   ELSE
      READ INPUT-FILE
         AT END
            DISPLAY 'INPUT FILE CONTAINS NO DETAIL RECORDS'
            MOVE 'Y' TO SW-ERROR
      END-READ
      IF SW-ERROR = 'N' AND
         STATUS-CODE NOT = '00'
      THEN
         DISPLAY 'ERROR READING DETAIL RECORD'
         DISPLAY 'STATUS CODE WAS ' STATUS-CODE
         MOVE 'Y' TO SW-ERROR
      END-IF     
   END-IF
END-IF
IF SW-ERROR = 'N'
THEN
   PERFORM
      VARYING SUB-SCRIPT
      FROM 1
      BY 1
      UNTIL SW-ERROR = 'Y' OR
            SUB-SCRIPT > 1000000
      MOVE INPUT-DETAIL TO OUTPUT-DETAIL
      MOVE SUB-SCRIPT TO ACCT-NUMBER OF OUTPUT-DETAIL
      MOVE SUB-SCRIPT TO OTHER-FIELD OF OUTPUT-DETAIL
      WRITE OUTPUT-DETAIL
      IF STATUS-CODE NOT = '00'
      THEN
         DISPLAY 'ERROR WRITING DETAIL RECORD # ' SUBSCRIPT
         DISPLAY 'STATUS-CODE WAS ' STATUS-CODE
         MOVE 'Y' TO SW-ERROR
      END-IF
   END-PERFORM
END-IF
IF SW-ERROR = 'N'
THEN
   READ INPUT-FILE
      AT END
         DISPLAY 'INPUT TRAILER RECORD MISSING'
         MOVE 'Y' TO SW-ERROR
   END-READ
   IF SW-ERROR = 'N' AND
      STATUS-CODE NOT = '00'
   THEN
      DISPLAY 'ERROR READING TRAILER RECORD'
      DISPLAY 'STATUS CODE WAS ' STATUS-CODE
      MOVE 'Y' TO SW-ERROR
   END-IF
END-IF
IF SW-ERROR = 'N'
THEN
   MOVE INPUT-TRAILER TO OUTPUT-TRAILER
   MOVE 1000000 TO TRAILER-COUNT OF OUTPUT-TRAILER
   WRITE OUTPUT-TRAILER
   IF STATUS-CODE NOT = '00'
      DISPLAY 'ERROR WRITING TRAILER RECORD'
      DISPLAY 'STATUS CODE WAS ' STATUS-CODE
      MOVE 'Y' TO SW-ERROR
   END-IF
END-IF
IF SW-OP-OPEN = 'Y'
THEN
   CLOSE OUTPUT-FILE
END-IF
IF SW-IP-OPEN = 'Y'
THEN
   CLOSE INPUT-FILE
END-IF
GOBACK.
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 Mar 09, 2011 3:13 am
Reply with quote

Thanks RB - i missed the last line of the initial post. . . icon_redface.gif

d
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
Search our Forums:

Back to Top