COBOL Files



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

COBOL Files

Postby reebahs » Mon Aug 15, 2011 3:20 pm

Hi Every One!
I have a requirement and need to write a new program.

My input file will be like below:

Mem-nbr Prod-nbr Begin-dt end-dt amt
A123 p111 01162011 01312011 5000
A123 p111 02102011 01282011 10000
A123 p111 03122011 03312011 2000
A123 p222 04162011 04302011 7000
A123 p222 01162011 01312011 5000
A444 p333 05162011 05312011 2000
A444 p123 06122011 06302011 14000
A444 p222 07162011 07302011 2000
A444 p444 03162011 03312011 4000

my output file should be like below:
total-amt=5000+10000+2000+7000+5000 = 29000

Header of A123 total-amt
Detail record of A123
Detail record of A123
Detail record of A123
Detail record of A123
Detail record of A123
Header of A444 total-amt
Detail record of A444
Detail record of A444
Detail record of A444
Detail record of A444



i.e output file :

A123 29000
A123 p111 01162011 01312011 5000
A123 p111 02102011 01282011 10000
A123 p111 03122011 03312011 2000
A123 p222 04162011 04302011 7000
A123 p222 01162011 01312011 5000
A444 22000
A444 p333 05162011 05312011 2000
A444 p123 06122011 06302011 14000
A444 p222 07162011 07302011 2000
A444 p444 03162011 03312011 4000


can anybody help me out to write the logic for above requirement ?

Thanks in advance...
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL Files

 

Re: COBOL Files

Postby BillyBoyo » Mon Aug 15, 2011 3:44 pm

If you want the total amount on the header, you are complicating things. It is easier on a trailer. For a header, you need to store your records in a table, so that you can write the header with the amount. Or, if there will be too many, you need to write the header "out of sequence" and sort the file afterwards.

Can you get the spec changed, or are you stuck with it?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: COBOL Files

Postby reebahs » Mon Aug 15, 2011 5:48 pm

Hi BillyBoyo!
Thanks for your quick response.
Could you please provide me the procedural steps need to be followed to accomplish the requirement.

Regards,
Shabeer.
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL Files

Postby Robert Sample » Mon Aug 15, 2011 6:21 pm

How are you distinguishing header records from detail records? I don't think you've thought enough about your output file, yet.

Processing logic is straight forward:
Read first record
Save key in WORKING-STORAGE
Loop until end of file
    If input record key not equal WORKING-STORAGE key
        Output header record
        Output each detail record from table
        Reset table counter
        Reset total to zero
    End-if
    Move input record to next table entry
    Accumulate total
    If table is full
         Output message and stop
    End-if
    Read input record
End-loop
Output final header record
Output each detail record from table
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: COBOL Files

Postby reebahs » Tue Aug 16, 2011 10:02 am

Below are my output file Header and Detail record Layouts.

03 Header-record.
   05 H-Record-Type         PIC X(01).
      88 Header-rec      Value ‘H’.
   05 H-Eligibility-System-ID   PIC X(04).
      88  STAR-System-ID   Value ‘STRE’.
   05 FILLER            PIC X(01) Value Spaces.
   05 H-Contract-Ind         PIC X(01)
      88 H-Group         Value ‘G’.
      88 H-Individual      Value ‘I’.
   05 FILLER            PIC X(01) Value Spaces.
   05 H-Group-ID         PIC X(10).
   05 FILLER            PIC X(01) Value Spaces.
   05 H-Sub-Group-ID         PIC X(10).
   05 FILLER            PIC X(01) Value Spaces.
   05 WLP-Group-Desig      PIC X(02). *** always send ‘SG’ ***
      88 Large-Group      Value ‘LG’.
      88 Small-Group      Value ‘SG’.
   05 FILLER            PIC X(01) Value Spaces.
   05 Date-Extract         PIC X(08).
   05 FILLER            PIC X(01) Value Spaces.
   05 Total-Prem-Amt         PIC S9(28).
   05 FILLER            PIC X(01) Value Spaces.
   05 H-Covg-Begin-Dt      PIC X(08).
   05 FILLER            PIC X(01) Value Spaces.
   05 H-Covg-End-dt         PIC X(08).
   05 FILLER            PIC X(01) Value Spaces.
   05 Broker-System-ID      PIC X(04).
      88 STAR-Broker      Value ‘STRB’.

03    Detail-record redefines Header-record.
   05 D-Record-type         PIC X(01).
      88 Detail-rec      Value ‘L’.
   05 D-Subscriber-ID      PIC X(11).    *** HCID***
   05 FILLER            PIC X(01) Value Spaces.
   05 D-Bus-unit         PIC X(05) Value Spaces.
   05 FILLER            PIC X(01) Value Spaces.
   05 D-MBU            PIC X(08) Value Spaces.
   05 FILLER            PIC X(01) Value Spaces.
   05 D-Product         PIC X(06) Value Spaces.
   05 FILLER            PIC X(01) Value Spaces.
   05 D-Funding-Type         PIC X(05) Value Spaces.
   05 FILLER            PIC X(01) Value Spaces.
   05 D-LOB            PIC X(08).
   05 FILLER            PIC X(01) Value Spaces.
   05 D-Earned-Prem-Amt      PIC X(28).
   
   05 FILLER            PIC X(01) Value Spaces.
   05 D-Covg-Begin-Dt      PIC X(08).
   05 FILLER            PIC X(01) Value Spaces.
   05 D-Covg-End-dt         PIC X(08).  ***last day of month, 01312011 ***
   05 FILLER            PIC X(01) Value Spaces.
   05 D-State            PIC X(06).

   05 FILLER            PIC X(01) Value Spaces.
   05 D-Brk-Agent-ID         PIC X(10) ?? *** required only for IND bus ***
   05 FILLER            PIC X(01) Value Spaces.
   05 J-Brk-TIN         PIC X(10). ?? *** required only for IND bus***
   05 FILLER            PIC X(01) Value Spaces.
"Code'd"

Could you please elaborate your explanation ?
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL Files

Postby dick scherrer » Tue Aug 16, 2011 11:07 am

Hello,

What does the record layout have to do with understanding the processing logic Robert provided? Where are you stuck?

When posting code it is best to copy/paste from the terminal and use the Code tag. Your post has been "Coded" but notice the alignment is not correct. When posting code or jcl or data, only copy/paste - do not try to space or delete things into alignment. To see how your post will appear to the forum, use Preview. When you are satisfied with how the post appears, Submit.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: COBOL Files

Postby Robert Sample » Tue Aug 16, 2011 4:08 pm

There's nothing to elaborate on -- pseudocode is English narrative. Either you can read English or you cannot. Either you understand how to translate pseudocode into COBOL, or you need to go take a COBOL course. If you are taking a COBOL course now, and you cannot translate this pseudocode into COBOL, you need a better teacher.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: COBOL Files

Postby reebahs » Tue Aug 16, 2011 4:58 pm

Hi Robert!
ThankQ for u`re pseudo code.It helped me a lot.
I wrote the program and it is working fine.
ThankQ for spending u`re valuable time for me.
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL Files

Postby reebahs » Tue Aug 16, 2011 5:00 pm

ThankQ BillyBoyo for ur suggestions on the issue.
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post