COBOL File Processing Position wise



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

COBOL File Processing Position wise

Postby IBM MINAKSHI » Sat Jan 05, 2013 12:53 am

Hi,
Please help me in getting answer for a question related to file processing in a COBOL program and create an output file. Input file has 10 message fields, i need to write an output records for 5 message. i.e. if file has data for only message1 field then need to write one o/p records, if file has data for message1,message2 then need to write two o/p records and so on. means everytime i need to check whether multiple error messages present or not. in detail-
if Record has multiple Error messages then we have to check and process only 1st 5 error messages
I. For first error message, i need to write source, Account No, id,ccode,message1 to the o/p file.
II. For subsequent 5 error messages, need to write only the error message on the next line leaving the other fields (source, account nu, ID, ccode) blank.
my input file layout is -

source x(3)
Account number length x(15)
id length x(8)
ccode x(3)
message1 x(30)
message2 x(30)
message3 x(30)
message4 x(30)
message5 x(30)
message6 x(30)
message7 x(30)
message8 x(30)
message9 x(30)
message10 x(30)
Thanks.
IBM MINAKSHI
 
Posts: 8
Joined: Wed Jan 02, 2013 11:30 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL File Processing Position wise

 

Re: COBOL File Processing Position wise

Postby Akatsukami » Sat Jan 05, 2013 12:57 am

Are we to presume that if, e.g., MESSAGE2 is non-blank, MESSAGE1 must also be non-blank?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: COBOL File Processing Position wise

Postby IBM MINAKSHI » Sat Jan 05, 2013 1:11 am

Akatsukami wrote:Are we to presume that if, e.g., MESSAGE2 is non-blank, MESSAGE1 must also be non-blank?


Hi,
Message1 will always have a value.. but message2....10 may or may not have a value. becoz of that every time we have to check whether message 2..5 has data or not. if yes then we have to write corresponding records..
Thanks.
IBM MINAKSHI
 
Posts: 8
Joined: Wed Jan 02, 2013 11:30 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL File Processing Position wise

Postby dick scherrer » Sat Jan 05, 2013 1:41 am

Hello and welcome to the forum,

Suggest you post a few sets of sample input data and the output you want what those sample sets are processed.

You have answered the literal question about message1 and message2. I beileve what is needed is the answer to if any messageN has a value, must all of the messages lower than messageN have a value or may there be unfilled messages throughout?

The sample sets should show this.
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 File Processing Position wise

Postby Akatsukami » Sat Jan 05, 2013 2:50 am

As it happens, Minakshi-chan, I am not a COBOL programmer, at least not in recent decades. (I know, you were hoping that I'd write the program for you. Life is cruelly disappointing at times, my child.)

However, I did write this fine PL/I program:
 m45:  proc options (main) reorder;                                 
                                                                     
 %dcl (true, false, pagesize)       char;                           
 %true     = '''1''B';                                               
 %false    = '''0''B';                                               
 %pagesize = 34;                                                     
                                                                     
 dcl tulin                          file record input,               
     tulout                         file record output;             
                                                                     
 dcl 1 input_record                 unal,                           
       2 source                     char (3),                       
       2 account_number             char (15),                       
       2 id                         char (8),                       
       2 ccode                      char (3),                       
       2 message (10)               char (30);                       
                                                                     
 dcl 1 output_header_1              unal,                           
       2 *                          char (39) init(' '),             
       2 *                          char (31) init('KatsuSoft'),     
       2 *                          char (5)  init('Page'),         
       2 oh_page#                   pic '(4)z9';                     
                                                                     
 dcl 1 output_header_2              unal,                           
       2 *                          char (5)  init('Src'),           
       2 *                          char (17) init('Account Number'),
       2 *                          char (10) init('ID'),           
       2 *                          char (5)  init('Ccd'),           
       2 *                          char (43) init('Message');       
                                                                     
 dcl 1 output_header_3              unal,                           
       2 *                          char (5)  init((3)'='),         
       2 *                          char (17) init((15)'='),         
       2 *                          char (10) init((8)'='),         
       2 *                          char (5)  init((3)'='),         
       2 *                          char (43) init((30)'=');   
                                                               
 dcl 1 output_detail                unal,                       
       2 source                     char (5),                   
       2 account_number             char (17),                 
       2 id                         char (10),                 
       2 ccode                      char (5),                   
       2 message                    char (43);                 
                                                               
 dcl eof_tulin                      bit init(false),           
     blank_line                     char (80) init(' '),       
     i                              fixed bin (31),             
     page#                          fixed bin (31) init(1),     
     lineage                        fixed bin (31) init(99);   
                                                               
 on endfile (tulin) eof_tulin = true;                           
                                                               
 read file (tulin) into (input_record);                         
                                                               
 do while (¬eof_tulin);                                         
   output_detail.source         = input_record.source;         
   output_detail.account_number = input_record.account_number; 
   output_detail.id             = input_record.id;             
   output_detail.ccode          = input_record.ccode;           
   output_detail.message        = input_record.message (1);     
   call do_output;                                             
   output_detail.source         = ' ';                         
   output_detail.account_number = ' ';                         
   output_detail.id             = ' ';                         
   output_detail.ccode          = ' ';                         
                                                               
   do i = 2 to 5 while (input_record.message(i)¬=' ');         
     output_detail.message      = input_record.message (i);     
     call do_output;                                           
   end;                                                         
                                                               
   read file (tulin) into (input_record);     
 end;                                         
                                             
 do_output:  procedure;                       
                                             
 if (lineage>pagesize) then do;               
   oh_page# = page#;                         
   page#   += 1;                             
   write file (tulout) from (output_header_1);
   write file (tulout) from (output_header_2);
   write file (tulout) from (output_header_3);
   write file (tulout) from (blank_line);     
   lineage = 4;                               
 end;                                         
                                             
 write file (tulout) from (output_detail);   
 lineage += 1;                               
 end do_output;                               
 end m45;                                     

which, given the input
CBL012345678901234ABCD    123This is a test                             
PLI123456789012345defg    456This is another test          Katie is a pest               You're welcome, Minakshi

produces the output
                                       KatsuSoft                      Page     1
Src  Account Number   ID        Ccd  Message                                   
===  ===============  ========  ===  ==============================             
                                                                               
CBL  012345678901234  ABCD      123  This is a test                             
PLI  123456789012345  defg      456  This is another test                       
                                     Katie is a pest                           
                                     You're welcome, Minakshi                   

You may take this as pseudo-code, or we can discuss the COBOL statements corresponding to the PL/I, your choice.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: COBOL File Processing Position wise

Postby IBM MINAKSHI » Sat Jan 05, 2013 9:08 am

Thanks Akatsukami...

this is what i want to give as input and write as output but thru a Cobol Program.. how can i find Cobol Program code equal to PL/I code.. Can we discuss the COBOL Statements.
Thanks.
IBM MINAKSHI
 
Posts: 8
Joined: Wed Jan 02, 2013 11:30 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL File Processing Position wise

Postby IBM MINAKSHI » Sat Jan 05, 2013 9:42 am

Hi dick scherrer... Thanks

Akatsukami has already given sample input and output data... i want to give input data and expecting output data as..
Sample Input is-
CBL012345678901234id0001idAAAThis is a message1                                   
CBL012345678909876id0002idBBBThis is a message1  This is a message2  This is a message3                                   
PLI112345678901234id0003idCCCThis is a trail1         This is a trail2         This is a trail3         This is a trail4   This is a trail5  This is a trail6   This is a trail7   This is a trail8  This is a trail9  This is a trail10


and Sample output should be -

                                     Test Report                      Page     1
Src    Account Number      ID              Ccd   Message                                   
===   ===============  ========    ===   ==============================             
                                                                               
CBL  012345678901234  id0001id      AAA  This is a message1
CBL  012345678901234  id0002id      BBB  This is a message1
                                                              This is a message2
                                                              This is a message3                             
PLI  112345678901234   id0003id      CCC  This is a trail1
                                                               This is a trail2                       
                                                               This is a trail3                       
                                                               This is a trail4                       
                                                               This is a trail5                       


Thanks All..

Code'd
Thanks.
IBM MINAKSHI
 
Posts: 8
Joined: Wed Jan 02, 2013 11:30 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL File Processing Position wise

Postby Akatsukami » Sat Jan 05, 2013 8:52 pm

We shall discuss this, Minakshi-chan. First, though, note that you ought to enclose any information where alignment is significant (and it is very significant in both the input data and the report) in Code tags, so as to preserve that alignment. Note the differences in the appearance of my report and your mock-up.

Now, to discussion. Leaving aside for moment the variable declarations and overhead, the logic begins with:
 on endfile (tulin) eof_tulin = true;                           
                                                               
 read file (tulin) into (input_record);                         

The second statement is of course a mere I/O statement; the file tulin is being read into the variable input_record. In COBOL, the file definition (FD) must include some sort of record definition. However, this definition represents the actual I/O buffer; as the data in the buffer are volatile, you should always read into and write from working storage, so as to be sure the data are available when needed.

In PL/I I simply write
 dcl tulin                          file record input,     

whereas in COBOL you need a more complex definition. As I said supra, it has been many years since I programmed in COBOL, but IIRC the definition would be:
        ENVIRONMENT DIVISION.
        INPUT-OUTPUT SECTION.
        FILE-CONTROL.
           SELECT INPUT-FILE ASSIGN TO TULIN.
[...]
        DATA DIVISION.
        FILE SECTION.
        FD  INPUT-FILE
            DATA RECORD IS INPUT-BUFFER.
        01  INPUT-BUFFER                  PIC X(329).

In the FILE-CONTROL paragraph, you use the SELECT statement to associate a COBOL internal file, that I have named INPUT-FILE, with a external file, TULIN; in MVS this will be the name of the DD statement defining the actual data set in the JCL. In the FILE section, you then create a FD for the internal file.

Note that I have defined a on endfile statement for tulin. When a PL/I program is compiled, object code is generated so that when the end of the data set associated with tulin is reached, control is transferred to the on statement and then, when it executes, returns to the point of origin. In COBOL, this must be done explicitly, so that
  read file (tulin) into (input_record);                         

Becomes
           READ INPUT-FILE INTO INPUT-RECORD
                AT END MOVE 'Y' TO EOF-INPUT-FILE.

where, of course, EOF-INPUT-FILE is a PIC X variable in working storage, initialized to something other than 'Y' ('N' would be conventional and easy to interpret, but not absolutely necessary).

That’s enough for one morning. Digest that, and we shall then continue.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: COBOL File Processing Position wise

Postby IBM MINAKSHI » Sat Jan 05, 2013 9:24 pm

Thanks Akatsukami for explaining very nicely.. Also i will always keep in mind that Report Alignment should be proper and exact..

I understood your conversion very clearly.. Thanks again..
For Do while logic.. do we need to put array replacement in COBOL?
Thanks.
IBM MINAKSHI
 
Posts: 8
Joined: Wed Jan 02, 2013 11:30 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL File Processing Position wise

Postby NicC » Sat Jan 05, 2013 10:11 pm

Do While is Perform Until
An ARRAY in PL/1 is a TABLE in Cobol

An assignment in PL/1 is which in Cobol would be
MOVE B TO A
or
A = B + C
in PL/1 is
COMPUTE A = B + C
in Cobol
If you do not have a pl/1 manual available (and you do via the links on this page) use the Rexx Language reference as it is more PL/1-like and you will be using Rexx throughout your career.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post