Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

field change

Status
Not open for further replies.

666satan

Programmer
Jan 1, 2009
18
hi guys, i have a small doubt can we increase the size of a field say i wa nt to increase the size of account no is of 6 bytes to 8bytes in both fixed length records and also variable length records,
 
Do you mean in existing files? Are these files Indexed, and if so, is the account number part of the key? Is the account number wholly numeric?
 
And...operating system, compiler vendor?

Tom Morrison
 
ya for existing files , ya they r indexed files and primary key is index and the operating system is mvs
 
If the account number is numeric, you can convert it to Packed Decimal (Comp-3) for an increase to 11 digits. If the account number consists of letters and digits, you can use a simple compression algorithm to store 8 characters in 6 bytes. Beyond that, I can't think of any way other than to write a conversion program to copy the file and expand the keys. If it were not the key, the precaution of always defining a record layout with extra filler bytes would have solved the problem.
 
hi webrabbit, thanks for giving the answer , but i want to learn more about field changes in cobol. it will be helpful to me if u suggest some link where i can get the whole information abt field change and different types of record length files

thanks
 
In COBOL, field changes generally require 1) Changing all the programs that access the file, and 2) A conversion program to read the old format and write the new format. Even if the data can be compressed as in the examples I gave above, all programs that access the fields must be changed. In that case though, you can avoid the conversion program if you code an algorithm to detect whether the field is compressed or non-compressed. For replacing a Display with a Packed-Decimal, IF NUMERIC will suffice. None-the-less, not converting all records may turn out to be unworkable.

Years ago, I maintained a payroll system where the basic code was from a vendor. Every few years, gonvernment mandated changes required field changes. Also, IRS requires that payroll end-of-year files be archived for seven years. This meant that either the old system had also to be archived, or the archived files retrieved, converted, and re-archived. The latter was what we always did.
 
hi webrabbit, thats a great answet, cool explanation..........i'd be happy if u can post some code where u have done fieldchanges....ill be greatful to u if u can do so
 
Ok. Here's the program.
Code:
 Identification Division.
 Program-ID.    JCTBL01.
 Author.        James C. Fairfield
 Installation.  JackRabbit Computer Systems
 Date-Written.  12/30/2007
     *>
     *> Convert Brand, Class, Color and Department Tables.
     *>
     *> Table Number is always numeric and is converted from two bytes display
     *> to two digits packed decimal (1 byte).
     *>
     *> Table Entry is two bytes display and is converted to four digits (two
     *> bytes) packed decimal through a conversion routine.
     *>
     *> Desciption is expanded from 14 bytes to 30 bytes.
     *>
     *> An alternate key is added to enable a table search by Description.
     *> As the definition for this key does not support duplicates, this
     *> ensures against the addition of multiple codes for the same Description.
     *>
 Environment Division.
 Input-Output Section.
 File-Control.
     Select MEW-TABLE-FILE
         Assign        to Dynamic NEW-TABLE-FILE-NAME
         File Status   is FILE-STATUS
         Record Key    is T01-KEY
         Alternate Key is T01-KEY-1 = T01-NBR T01-DESCRIPTION
         Access Mode   is Sequential
         Organization  is Indexed
         .

     Select OLD-TABLE-FILE
         Assign       to Dynamic OLD-TABLE-FILE-NAME
         Organization is Indexed
         Access Mode  is Dynamic
         Lock Mode    is Manual
         Record Key   is RECORD-KEY
         File Status  is FILE-STATUS
         .

 Data Division.
 File Section.
 FD  OLD-TABLE-FILE.
 01  TBL01-RECORD.
     05  TBL01-KEY.
         10  TBL01-NBR               Pic X(02).
             88  TBL01-BRAND                   Value '03'.
             88  TBL01-CLASS                   Value '04'.
             88  TBL01-COLOR                   Value '05'.
             88  TBL01-DEPT                    Value '06'.
         10  TBL01-ENTRY             Pic X(02).
     05  TBL01-DATA                  Pic X(60).

 FD  NEW-TABLE-FILE.
 01  T01-RECORD.
     05  T01-KEY.
         10  T01-NBR             Pic 9(02) Comp-6.
             88  T01-BRAND                 Value 1.
             88  T01-LOCATION              Value 2.
             88  T01-COLOR                 Value 3.
             88  T01-DEPT                  Value 4.
         10  T01-CODE            Pic 9(04) Comp-6.
     05  T01-DESCRIPTION         Pic X(30).

 Data Division.
 Working-Storage Section.
 77  CR2009  Pic X(64) Value 'Copyright 2009 by James C. Fairfield all rights reserved.'.

 78  PROGRAM-NAME                Value 'JCTBL01v2'.

 01  FILE-STATUS                 Pic X(02).

 01  CODE-CONVERSION-DATA.
     05  CC-ALPHA-CODE           Pic X(02).
     05  redefines CC-ALPHA-CODE.
         10  CC-ALPHA-CODE-1     Pic X(01) Comp-X.
         10  CC-ALPHA-CODE-2     Pic X(01) Comp-X.
     05  redefines CC-ALPHA-CODE.
         10  CC-DEPARTMENT       Pic 9(02).
     05  CC-NUMERIC-CODE         Pic 9(04) Comp-6.
     05  redefines CC-NUMERIC-CODE.
         10 CC-NUMERIC-CODE-1    Pic 9(02) Comp-6.
         10 CC-NUMERIC-CODE-2    Pic 9(02) Comp-6.

 78  CONVERSION-OFFSET           Value 32.

 01  NEW-TABLE-FILE-NAME         Pic X(13) Value 'TBL01.ISM'.

 01  OLD-TABLE-FILE-NAME         Pic X(13) Value 'TABLE1.DAT'.

 01.
     05  WS-TBL-NBR              Pic 9(02) Value Zero.
     05  WS-DEPT                 Pic 9(02).
     05  WS-T01-NBR              Pic 9(02) Value Zero Comp-6.
     05  WS-ENTRY-NBR            Pic 9(04) Value Zero Comp-6.
     05  IN-CNT                  Pic 9(06) Value Zero.
     05  OUT-CNT                 Pic 9(06) Value Zero.

 01  CNT-TABLE.
     05                          Pic X(18) Value '000000 Brands'.
     05                          Pic X(18) Value '000000 Locations'.
     05                          Pic X(18) Value '000000 Colors'.
     05                          Pic X(18) Value '000000 Departments'.
 01  redefines CNT-TABLE.
     05   CT-ENTRY occurs 4 times.
          10  CT-CNT             Pic 9(06).
          10                     Pic X(12).

 Procedure Division.
 000-START.
     Display Space   upon CRT
     Display PROGRAM-NAME
     Open Input OLD-TABLE-FILE
     Open Output NEW-TABLE-FILE
     Perform 100-CONVERT
     Close OLD-TABLE-FILE
     Close NEW-TABLE-FILE
     Display IN-CNT  ' Records in'
     Display OUT-CNT ' Records out'
     Display CT-ENTRY(1)
     Display CT-ENTRY(2)
     Display CT-ENTRY(3)
     Display CT-ENTRY(4)
     Stop Run
     .

 100-CONVERT.
     Perform Until Exit
         Read OLD-FILE-TABLE
         If FILE-STATUS >= '10'
             Exit Perform
         Add 1                        to IN-CNT
         If TBL01-NBR < '03' or > '06'
         or TBL01-NBR = '04' and TBL01-ENTRY = 'NA'
         or TBL01-NBR = '05' and TBL01-ENTRY(1:1) = 'N'
         and (TBL01-ENTRY(2:1) = 'A' or >= '1' and <= '9')
             Exit Perform Cycle
         End-If
         If TBL01-NBR not = WS-TBL-NBR
             Move Zero                to WS-ENTRY-NBR
             Move TBL01-NBR           to WS-TBL-NBR
             Move WS-TBL-NBR          to WS-T01-NBR
             Subtract 2             from WS-T01-NBR
         End-If
         Move WS-T01-NBR              to T01-NBR
         Move TBL01-ENTRY             to CC-ALPHA-CODE
         Evaluate T01-NBR
             When 1
             When 2
                 Perform CONVERT-CODE-TO-NUMERIC
                 Move CC-NUMERIC-CODE to T01-CODE
             When 3
                 Add 1                to WS-ENTRY-NBR
                 Move WS-ENTRY-NBR    to T01-CODE
             When 4
                 Move CC-DEPARTMENT   to T01-CODE
         End-Evaluate
         Move TBL01-DATA(1:14)        to T01-DESCRIPTION
         Write T01-RECORD
         Add 1                        to OUT-CNT
         Add 1                        to CT-CNT(WS-T01-NBR)
     End-Perform
     .

 CONVERT-CODE-TO-NUMERIC.
     Compute CC-NUMERIC-CODE-1 = CC-ALPHA-CODE-1 - CONVERSION-OFFSET
     Compute CC-NUMERIC-CODE-2 = CC-ALPHA-CODE-2 - CONVERSION-OFFSET
     .

 CONVERT-CODE-TO-ALPHA.
     Compute CC-ALPHA-CODE-1 = CC-NUMERIC-CODE-1 + CONVERSION-OFFSET
     Compute CC-ALPHA-CODE-2 = CC-NUMERIC-CODE-2 + CONVERSION-OFFSET
     .

 Notes:  Comp-6 is similar to Comp-3, except there is no sign nibble if there
         is no "S" in the Picture.  This makes it ideal for storing non-signed
         numeric data such as dates.  In this case, the month number and day
         number each consist of one byte with both digits in that byte.

         Even though the input file has 60 bytes allotted for the description
         (TBL01-DATA), only 14 bytes are used.  The output file will use all
         30 bytes.

         TBL01-ENTRY is numeric for Departments.  As the department number is
         often as meaningful to the user as the department name, this number
         is retained during the conversion.  This field consists of letters and
         digits for the other tables.  As the equivalent field in the output is
         strictly numeric, each character is expanded to a two-digit value
         computed from the ascii code for that character.

         Although the original program had extensive file error checking code,
         this code was removed for clearity.
 
Thanks Jack, so nice of u.....I really love mainframes , i worked hard to enhance my techncal skills, right now im in a pursuit of a job, im able to clear technical questions, but when they r giving me some real time situations im unable to give them right answers, im finding quite a difficulty in clearing especially team lead rouns, s they r asking me all time real quesstions, i want to master this technolgy, i want to be a cobol coder.....i know cobol, but i want to be in top 10 cobol coders of the world, plzz guide me, where i can get the complete notes of cobol,so that i cud learn A TO Z IN cobol.......i will ask u simpl question, but i dunno the perfect sloution for this , can u plzzz answer

there are 2 files

1st file has 2nd file has


acnt 101 annt 102 acnt name
acnt 103 acnt 104 acnt name
acnt 106 acnt 105 acnt name
acnt 109 acnt 108 acnt name


now what we have to do is compare both files and write the files and write them to another file which file1 and file 2 doesnt have


thanks & regards






























































































































































































































acnt 110




thanks & regards
 
This is a simple two-file match. In psuedo code (COBOL is very close to psuedo code, that's why I like it):

Read file 1
Read file 2
Loop Until both files are at end
Compare keys (a file that is at end is always high)
If file 1 is low
Process for mismatch on file 1
Fead file 1
Return to beginning of loop
End If
If file 2 is low
Process for mismatch on file 2
Read file 2
Return to beginning of loop
End If
Process for a match
Read file 1
Read file 2
Return to beginnin of loop
End loop
 
thanks alot jack, i have one more doubt, can a squential file be converted to vsam file and vice-vers. post the code also and some more codes on tables and how r they searched using subscript and index......can redfines clause can be used with occurs clause?
 
To convert the format of a file, simply write a program to read the old format and write the new format. On the mainframe, there are also a number of untilities than can be used. Using SORT with a FIELDS=COPY control card is one. Note that to create a VSAM file you must first define it with a utility program, I seem to recall that its name is IDECAMS.

On searching a table, you can use the SEARCH verb or the PERFORM verb.

SEARCH requires an index. By default, the first or only index defined for the table is used, but if there are multiple indices defined for the table, you can use the VARYING clause to select other than the first.

There are two forms of the SEARCH verb: The sequential search and the binary search. To invoke the binary search use the keyword ALL immediatly after the verb SEARCH. The table must be defined with the ASCENDING/DECENDING KEY syntax. If the keys are not in the proper order, the results are unpredictable.

For a sequential search (no ALL), the index must be intitialized prior to the SEARCH. The index is incremented after each SEARCH cydle, but the logic is internal and otherwise need not concern the programmer. The syntax is
Code:
SEARCH table_name [VARYING index_name]
    [AT END action . . .]
    {WHEN condition action . . .} . . .
END-SEARCH
The AT END code is invoked if none of the WHEN conditions are satisfied before the index is incremented to be greater than the number of occurances defined for the table.

To search a table using PERFORM the syntax is as follows:
Code:
PERFORM VARYING index/subscript FROM initial_value BY increment UNTIL end_condition
     CONTINUE/statements . . .
END-PERFORM
Note that the interior of the PERFORM may be null (consist of the null verb CONTINUE only). Also, the end_condition need not reference the table at all. This is the only way to search a table backwards, by specifying an initial_value equal to the occurance of the table and a negative (usually -1) as the increment. Using the PERFORM verb, the incrementing and end_conditions must be coded explicity, unlike with the SEARCH verb where they are implicit.
 
ohhh great, thanks jack, r u familiar with only cobol , do u know jcl, db2 ,vsam too? 2 more questions, can redefines clause be used with occurs clause, can we use internal sort to compare two files in cobol? and one more query is , what r the general changes that a progammer can make in cobol+db2 program ?
 
I used JCL up until '83. VSAM too. Never used DB2. I know there's been changes in the last 25 years.

REDEFINES can be used with OCCURS but I think it's too confusing, I always split it up:
Code:
05  REDEFINES A.
    10  B PIC X(nn) OCCURS mm TIMES.
If one of the files is already in the sequence you need, yes, but you cannot have two internal sorts active at the same time. In the OUTPUT PROCEDURE, replace one of the READs with the RETURN.
 
hi jack, thanks for giving answers to all my questions....what are cntrol cards in jcl, and why they are3 used? explain me with some code?
 
Although control cards are ususally included in the JCL stream, they are not JCL. They would follow a // DD * JCL statemnt, although they also might exist in a data set, usually a member of a library (PDS). They are application-specific parameter statements.

For the external Sort program, they include definition of sort keys, summarization data, and other parameters.
 
thanks jack, jack one real time question, how we will get the work assigned in mainframes, i mean client request , and do u know anything abt banking project, i mean to say how we will have the access of files, give me a clear description of a banking project,



thanks & regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top