Home > Archive > Cobol > February 2005 > Interesting Cobol Problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Interesting Cobol Problem
|
|
|
|
Hi,
Encountered an interesting problem and would like to s some help to
resolve it.
Can anybody enlightened ??
Basically the objective is to extract the full record from the input file
and output to an o/p file with the following
format
Input
======
xxxxx xxxxx xxxxx xxxxx
Ouput
======
YYYY-MM-DDx xxxxx xxxxx xxxxx xxxxx <= o/p need to include a 10 byte date
field and
a
1 byte indicator field, followed by the input file
records
that were extracted.
As the input copybook consists of a lot of fields (incl OCCURS stt etc),
hence I thought of just writing out the full record to an o/p FLAT file,
done with a single declaration in the o/p copybk
(rather than move field by field from input to o/p).
However, when I do that, part of the record extracted out contain
the prev record data from the input file which is weird as I did
initialised it and it only happen to some records extracted
and not all. In short , o/p will be something like this :
<----------(Ok)-------------><---(Not ok)contain prev i/p rec data--->
YYYY-MM-DDX xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx
Can anybody enlightened ??
In addition, the record o/p happen only from column 700 of the
input file onward of the data to be o/p.
The rest of the field are extracted correctly
If not, must I really declared my o/p file field by field and write
each out by a 'MOVE' statement. That's will be a massive effort.
Below are my extracted files and code.
========================================
=
===============
Extracted Input
===============
1) Input file 1st record is NOT to be extracted based on criteria.
2) Data to be extracted are 2nd, 3rd and 4th rec
(Input) ------------------- COLUMNS 000699 <==**Take note
===> SCROLL ===> C
-0----+----1----+----2----+----3----+----4----+----5----+----6----+-
AFLOTAO10001 0001 31 00000000 <=1st
rec
<=2nd
rec
<=3rd
rec
AFTPEND10306 0889 21 00000000 <=4th
rec
=================
Extracted Output
=================
1) Notice that the o/p record of 2nd and 3rd record pick the field
of the input file 1st record (For other fields of the 2nd and
3rd record, it is extracting the record correctly, juz that
halfway thru, some field at the back will containprev record of the
input file field)
2) 4th record is extracted successfully and correctly.
3) In addition, the o/p record of 2nd and 3rd record pick the record
starting from'BRCHO' with the 'AF' disappearing as seen from the
input file.
(Output) ------------------- Columns 00710 <=**Take note
===> Scroll ===>
1----+----2----+----3----+----4----+----5----+----6----+----7----+-
LOTAO10001 0001 31 00000000 <=2nd rec
LOTAO10001 0001 31 00000000 <=3rd rec
AFTPEND10306 0889 21 00000000 <=4th rec
**************************** Bottom of Data ***********************
===============
Extracted CODE
===============
*=====================
INPUT-OUTPUT SECTION.
*=====================
FILE-CONTROL.
*=============
SELECT TRANS-FILE ASSIGN TO AQTFILE
ORGANIZATION IS INDEXED
ACCESS IS SEQUENTIAL
RECORD KEY IS TFKEY
FILE STATUS IS TRANS-STATUS.
SELECT TREXTR-FILE ASSIGN TO AQEXTR.
*==============
DATA DIVISION.
*==============
FILE SECTION.
*=============
FD TRANS-FILE
LABEL RECORDS STANDARD
RECORD CONTAINS 700 TO 1527 CHARACTERS <=**Take note
BLOCK CONTAINS 0 RECORDS.
01 TRANS-FILE-REC.
05 TFKEY.
10 xxx PIC XX.
10 xxx PIC X(20).
10 xxx PIC X(11).
10 xxx PIC X(13).
10 xxx PIC XX.
10 xxx PIC 99.
05 FILLER PIC X(34).
05 xxx PIC 9(8).
05 FILLER PIC X(1435).
01 TRANS-FILE-REC2.
05 xxx PIC X(50).
05 FILLER PIC X(650).
FD TREXTR-FILE
LABEL RECORDS STANDARD
BLOCK CONTAINS 0 RECORDS.
COPY AQEXTR.
** The above copybk(AQEXTR) consist of just a single
length declaration for the header, detail and footer.
ie, Did NOT declare field by field for the detail part.
Just specified the full length for it)
*=========================
30000-PROCESS-TRANS.
*=========================
PERFORM UNTIL xxxx
MOVE TRANS-FILE-REC TO TRANS-RECORD <==
PERFORM 32000-EXTRACT-ATRANS
PERFORM 33000-GET-NEXT-TRANS
END-PERFORM.
*====================
32000-EXTRACT-ATRANS.
*====================
INITIALIZE ATRANS-RECORD. <== Did initialise here of the o/p rec
PERFORM 33000-WRITE-TRANS-HEADER.
PERFORM 34000-WRITE-TRANS-DETAIL.
*=========================
34000-WRITE-TRANS-DETAIL.
*=========================
MOVE WS-BIZ-DATE TO ATRANS-BIZ-DATE
MOVE ' ' TO ATRANS-DML-TAG
MOVE TRANS-RECORD TO ATRANS-RECORD. <= move all i/p to o/p for 'detail'part
of o/p file
WRITE ATRANS-DETAIL.
| |
| Lueko Willms 2005-02-03, 8:55 am |
| .. On 02.02.05
wrote leng1@bigfoot.com (Rick)
on /COMP/LANG/COBOL
in ctqkiq$m7q$1@reader01.singnet.com.sg
about Interesting Cobol Problem
As with your previous question, I am not sure, if I have really
understood your problem.
Let me state what I have understood, and correct me, if I am
wrong:
You have an input file with records of variable length, and want
to build an output file with the same contents, but just prefixed with
a calendar date and a 1 byte indicator field.
Is that correct?
So I see two solutions:
a) assuming the record description is available as a COPY element, you
use the same COPY element in the description, but with a REPLACING
clause which adds the above mentioned prefixes; then in the loop
processing the input record, you simply MOVE the three fields. See
details further down.
b) you define the output record as having VARIABLE length DEPENDING on
an item in WORKING-STORAGE SECTION, and then STRING the caledar date,
the indicator field, and the input record, all DELIMITED BY SIZE into
the single very large field (PIX X(1538)) of the output record, WITH
POINTER the item in WORKING-STORAGE SECTION which controls the length
ot the output record.
For solution a) I assume that the COPY-element for the record
looks like this, as taken from your code sample:
01 TRANS-FILE-REC.
05 TFKEY.
10 xxx PIC XX.
10 xxx PIC X(20).
10 xxx PIC X(11).
10 xxx PIC X(13).
10 xxx PIC XX.
10 xxx PIC 99.
05 FILLER PIC X(34).
05 xxx PIC 9(8).
05 FILLER PIC X(1435).
well, this is probably not the correct description, because of
your
RECORD CONTAINS 700 TO 1527 CHARACTERS <=**Take note
So you would use a COPY statement like this:
COPY TRANS-FILE-REC REPLACING
== 01 == BY
== 01 Out-File-Record.
02 Prefixed-Date PIC X(10).
02 Prefixed-Indicator PIC X.
02 ==
Since the same fields controling the number of OCCURS causing the
input record to be of variable length, are thus present in the
description of your output-file record, there is no need to worry
about the length of this.
And your loop would look basically like this:
READ Input-File
PERFORM UNTIL has-reached-EOF IN input-file-status
MOVE My-Date TO Prefixed-Date OF Out-File-Record
MOVE The-Indicator TO Prefixed-Indicator OF Out-File-Record
MOVE Input-File-Record TO Trans-File-Rec OF Out-File-Record
WRITE Out-File-Record
READ Input-File
END-PERFORM
Does that answer your question?
Yours,
Lüko Willms http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --
Gerade das Gegenteil tun heißt auch nachahmen, es heißt nämlich das
Gegenteil nachahmen. -G.C.Lichtenberg
| |
|
|
"Lueko Willms" <l.willms@jpberlin.de> wrote in message >
>
> As with your previous question, I am not sure, if I have really
> understood your problem.
>
> Let me state what I have understood, and correct me, if I am
> wrong:
>
> You have an input file with records of variable length, and want
> to build an output file with the same contents, but just prefixed with
> a calendar date and a 1 byte indicator field.
>
> Is that correct?
====> Hi Lueko. Tks in adv first for the advise :-)
Actually my input file is a fixed length file (contain many many fields +
those
OCCURS statement etc.Basically it's a transaction file containing a lot of
different
info)
Yes. You are right. I want to build an output file(also is a fixed length
file)
with the same contents, but just prefixed with a calendar date and a
1 byte indicator field.
My problem is that some of the records, it extracted correctly and fine
while some other records, the fields are extracted correctly but from
column 700 like that, sometimes the fields will contain the prev input file
field,
which indeed the fields should be blank.
(Take note: It only happen from certain columns onward)
Hi, I had reposted my problem again in the newsgroup as I noticed that
the alighment were all out when I sent in this post.
You can see my coding in the newly sent post.
I am still trying to find out what's wrong in the coding.
| |
| Lueko Willms 2005-02-03, 3:55 pm |
| .. On 03.02.05
wrote leng1@bigfoot.com (Rick)
on /COMP/LANG/COBOL
in ctta2j$jgp$1@mawar.singnet.com.sg
about Re: Interesting Cobol Problem
l> Actually my input file is a fixed length file (contain many many
l> fields + those OCCURS statement etc.Basically it's a transaction
l> file containing a lot of different info)
l> Yes. You are right.
l> I want to build an output file(also is a fixed length file) with
l> the same contents, but just prefixed with a calendar date and a
l> 1 byte indicator field.
l> My problem is that some of the records, it extracted correctly and
l> fine while some other records, the fields are extracted correctly but
l> from column 700 like that, sometimes the fields will contain the prev
l> input file field, which indeed the fields should be blank.
So I think that your input file is actually NOT a fixed length
file, just as the FD declaration specifies -- from 700 to mor then
1000 bytes length.
From what you show in the pieces of code you quote, I have no clue
what you are trying to do.
What about the simple proposal I made? Did you understand it?
Yours,
Lüko Willms http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --
Ein Buch ist ein Spiegel, wenn ein Affe hineinsieht, so kann kein Apostel herausgucken. -G.C.Lichtenberg
| |
|
|
"Lueko Willms" <l.willms@jpberlin.de> wrote in message >
> So I think that your input file is actually NOT a fixed length
> file, just as the FD declaration specifies -- from 700 to mor then
> 1000 bytes length.
>
> From what you show in the pieces of code you quote, I have no clue
> what you are trying to do.
>
> What about the simple proposal I made? Did you understand it?
>
===> Hi Lueko, actually extracted are just part of my code.
My objective is basically to extract out the full input record (based on
condition) from the input to an o/p file.
The extracted code are actually to show the process of my extraction
made.
Some of the FD (eg TFKEY) that you have seen is basically to provide
as a KEY for me to extract the record.
The advise you mentioned, I don't really quite understand.
Could you advice based on the code that I have given and advise
from there which area should I make change.
Been trying to find out what went wrong and to no avail :-(
Tks Lueko for your kind advise given all along :-)
| |
| Lueko Willms 2005-02-10, 3:55 am |
| .. On 02.02.05
wrote leng1@bigfoot.com (Rick)
on /COMP/LANG/COBOL
in ctqkiq$m7q$1@reader01.singnet.com.sg
about Interesting Cobol Problem
As with your previous question, I am not sure, if I have really
understood your problem.
Let me state what I have understood, and correct me, if I am
wrong:
You have an input file with records of variable length, and want
to build an output file with the same contents, but just prefixed with
a calendar date and a 1 byte indicator field.
Is that correct?
So I see two solutions:
a) assuming the record description is available as a COPY element, you
use the same COPY element in the description, but with a REPLACING
clause which adds the above mentioned prefixes; then in the loop
processing the input record, you simply MOVE the three fields. See
details further down.
b) you define the output record as having VARIABLE length DEPENDING on
an item in WORKING-STORAGE SECTION, and then STRING the caledar date,
the indicator field, and the input record, all DELIMITED BY SIZE into
the single very large field (PIX X(1538)) of the output record, WITH
POINTER the item in WORKING-STORAGE SECTION which controls the length
ot the output record.
For solution a) I assume that the COPY-element for the record
looks like this, as taken from your code sample:
01 TRANS-FILE-REC.
05 TFKEY.
10 xxx PIC XX.
10 xxx PIC X(20).
10 xxx PIC X(11).
10 xxx PIC X(13).
10 xxx PIC XX.
10 xxx PIC 99.
05 FILLER PIC X(34).
05 xxx PIC 9(8).
05 FILLER PIC X(1435).
well, this is probably not the correct description, because of
your
RECORD CONTAINS 700 TO 1527 CHARACTERS <=**Take note
So you would use a COPY statement like this:
COPY TRANS-FILE-REC REPLACING
== 01 == BY
== 01 Out-File-Record.
02 Prefixed-Date PIC X(10).
02 Prefixed-Indicator PIC X.
02 ==
Since the same fields controling the number of OCCURS causing the
input record to be of variable length, are thus present in the
description of your output-file record, there is no need to worry
about the length of this.
And your loop would look basically like this:
READ Input-File
PERFORM UNTIL has-reached-EOF IN input-file-status
MOVE My-Date TO Prefixed-Date OF Out-File-Record
MOVE The-Indicator TO Prefixed-Indicator OF Out-File-Record
MOVE Input-File-Record TO Trans-File-Rec OF Out-File-Record
WRITE Out-File-Record
READ Input-File
END-PERFORM
Does that answer your question?
Yours,
Lüko Willms http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --
Gerade das Gegenteil tun heißt auch nachahmen, es heißt nämlich das
Gegenteil nachahmen. -G.C.Lichtenberg
|
|
|
|
|