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
 

 

Creat header record from the input file with record count

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
maxsubrat

New User


Joined: 27 Feb 2008
Posts: 72
Location: india

PostPosted: Wed Oct 27, 2010 12:01 pm    Post subject: Creat header record from the input file with record count
Reply with quote

1. ONE INPUT FILE WHICH HAS 9 RECORDS WITH FEW FIELDS. ONE FIELD IS DEP-ID.
2. SUPPOSE HERE THERE ARE 3 DEP-ID IN THE 9 RECORDS.
3. SO MY REQUIREMENT IS TO CREATE 3 HEADERS BECAUSE 3 DEP-ID IS AVAILABLE AND TO WRITE THE CORRESPONDING DETAIL RECORDS.
4. HEADER RECORD SHOULD CONSIST OF RECORD COUNT OF THE DETAIL RECORDS WITH EACH DEP-ID
INPUT FILE:
ITM-NBR DEP-ID FLAG SYS
0012 001 Y 05
0045 001 Y 09
0098 001 N 08
0034 002 Y 00
0036 002 N 07
0067 003 U 07
0067 003 N 09
0087 003 G 08
0076 003 H 08

OUTPUT FILE:
H00103
0012 001 Y 05
0045 001 Y 09
0098 001 N 08
H00202
0034 002 Y 00
0036 002 N 07
H00303
0067 003 U 07
0067 003 N 09
0087 003 G 08
0076 003 H 08

H00103: HEADER RECORD. H= HEADER, 001=DEP-ID,03=RECORD COUNT
Can someone plse give some basic outline of how to read the file and write it to the out put file because we have to put the record count of the records to the header which have same DEP-ID.
Thanks in advance.
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Wed Oct 27, 2010 2:32 pm    Post subject:
Reply with quote

How would you do this if there was only one kind of DEP-ID and you were to write a header having the count of that DEP-ID? Let's assume all other rules of the game are same.
Back to top
View user's profile Send private message
maxsubrat

New User


Joined: 27 Feb 2008
Posts: 72
Location: india

PostPosted: Thu Oct 28, 2010 11:56 am    Post subject: Reply to: Creat header record from the input file with recor
Reply with quote

I am not sure about whether we can do it in one program or not?
Can someone give some comments/ideas about how to do this requirement.

Is it possible to use SORT a flat file to create a header in top of detail records for each DEP-ID with record count?

Thanks
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Thu Oct 28, 2010 4:02 pm    Post subject:
Reply with quote

Well if there were only one header required and COBOL is your choice -- read the input-file, add +1 to some counter on every successful read, define your header-records something like:
Code:
01 some-header
  05 ws-header-title         PIC X(01) value 'H'.
  05 ws-dep-id               PIC X(03).
  05 ws-rec-count            PIC 9(02).
Move the respective values to ws-dep-id and ws-rec-count.

Now, try to extend this to have 3-different headers in your output file.
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Thu Oct 28, 2010 6:37 pm    Post subject:
Reply with quote

Well we can use redefine to use same memory location in 2 different format Header, Detail and whenever dept id changed write it thru header format else thru detail record format
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Thu Oct 28, 2010 6:39 pm    Post subject:
Reply with quote

fill remaning space of header with filler and move spaces into then before writing the record
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Thu Oct 28, 2010 7:14 pm    Post subject:
Reply with quote

I'm no sort expert , but how would you get the final file in the desired order ?
I would make the offset of dep-id in the header rec the same as in the detail rec.

How would you know what's a header and what's not ? everything with an 'H' in pos 1 is an header and anything else Detail ?
I would include a code in the detail record, saying it is a detail record.


And there is no need to redefine ws-header and ws-detail like bhairon singh rathore suggest. You can perfectly write fd-header from ws-header , write fd-detail from ws-detail
Back to top
View user's profile Send private message
Abhishek_Indore

New User


Joined: 20 Oct 2010
Posts: 6
Location: INDIA->US->UK

PostPosted: Mon Nov 01, 2010 12:50 pm    Post subject: Reply to: Creat header record from the input file with recor
Reply with quote

Hi,
By looking the Input and output records of your file,I suggest to use the arrays to store the records while reading.

The flow of program will be like,Read the Input files,keeping the count and header id in working storage Variable.So lets assume you have read the first record then store it in the array by incrementing the count.Repeat the same process until the header id is changed(this can be acheived by comapring the Header id from Input records and one which you have stored in working storage) . Whenever your header id will change,write the output file with header record (H+Headerid+Count)
and detail record(from array).Do repeat the same step until your end of file reach.

Please let me know if you have any concerns.there may be other approach to do the same work as well.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Nov 01, 2010 2:25 pm    Post subject: Reply to: Creat header record from the input file with recor
Reply with quote

the ts was already given a working dfsort solution here
http://ibmmainframes.com/viewtopic.php?t=51924&highlight=
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2168
Location: @my desk

PostPosted: Mon Nov 01, 2010 4:20 pm    Post subject:
Reply with quote

From the other topic, the TS seems to be using a primitive version of DFSORT and hence unable to use the solution provided.
But I feel a SPLICE alternative will do it, if not through a program.
Back to top
View user's profile Send private message
HectorSam101

New User


Joined: 04 Nov 2010
Posts: 3
Location: IN

PostPosted: Sat Nov 06, 2010 2:01 pm    Post subject:
Reply with quote

Hello maxsubrat,

DFSORT solution explained above is the best one... but if your shop does not support DFSORT the you can go with the below straight fwd solution:

This can be done in 3 steps:

1. Sort step to sort the input on DEP-ID along with other significant fields. (you can avoid this step if you are sure that your input is sorted on DEP-ID.

2. Program to generate intermediate result. The output will have detail records of each DEP-ID first followed by the corresponding header record.

3. Sort step to bring the header on top of each detail record.

Detailed Explanation:

2. Program:
The output file will have few extra bytes in the beginning. These field will be used in the next sort step for re-arranging the sequence and will be cropped in the same step.
The output record structure will be something like this:

01 WS-OUT.
05 WS-SORT-INF.
10 WS-SORT-DEP-ID PIC X(03).
10 WS-SORT-REC-TYPE PIC X(01) .
88 HDR-REC VALUE 'H'.
88 DETAIL-REC VALUE 'D'.
05 WS-ACTUAL-RECORD PIC X(<WHAT-EVER>)

Now read the first record, save the DEP-ID in SAV-DEP-ID.
Read thru the file, move detail record to WS-ACTUAL-RECORD, move the SAV-DEP-ID to WS-SORT-DEP-ID, set DETAIL-REC, write from WS-OUT. Increment the DEP-ID counter DEP-ID-CNTR.
When there is a break in DEP-ID in input file (DEP-ID NOT = SAV-DEP-ID). Create your header with the count from DEP-ID-CNTR. Move the header record to WS-ACTUAL-RECORD. Set HDR-REC. WS-SORT-DEP-ID will be SAV-DEP-ID. Write WS-OUT, move DEP-ID to SAV-DEP-ID, reset DEP-ID-CNTR
Do end-of-file processing also in the same manner.

Your intermediate o/p will be like this:


001D0012 001 Y 05
001D0045 001 Y 09
001D0098 001 N 08
001HH00103
002D0034 002 Y 00
002D0036 002 N 07
002HH00202


3. Sort the above file in ascending order of first 3 bytes (1,3), descending order of next 1 byte (4,1). Use OUTREC to remove first 4 bytes.
This would bring the header on top of each detail record and will crop the extra 4 bytes of sort info added in the previous step.
The final file will be ur expected o/p.

Let me know if this helps...
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
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 22 Tue Dec 06, 2016 8:04 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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