Page 1 of 3

Need Advice How to Increase FD layout to Existing Program

PostPosted: Fri Dec 07, 2012 11:26 pm
by crazycobol
Hello everyone. I am having a tough time understanding how to increase a layout of an existing program. I'll try and explain. Its probably really simple for you experts out there.

So I have a program that has been already written. I have a database called data1.dat


IDENTIFICATION DIVISION.
PROGRAM-ID.
AUTHOR.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER.
OBJECT-COMPUTER.

INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT MASTER-RECORD ASSIGN TO "C:\DATA1.DAT"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
LOCK MODE IS MANUAL
STATUS IS FILE-LOCK
RECORD KEY IS SSN.

DATA DIVISION.
FILE SECTION.

FD DATABASE LABEL RECORDS ARE STANDARD.

01 MASTER-RECORD.

     05 FILLER           PIC XXX.
     05 SSN                PIC X(9).
     05 FIRST NAME    PIC X(30).
     05 LAST NAME     PIC X(30).
     05 ADDRESS         PIC X(30).
     05 FILLER            PIC X(2).



So now the person want to add more to the master-record. Like include country and city. So the FD only has 2 space filler at the end so I have to increase it. If I increase it, I might as well increase it by a lot so I have room in the future for growth.

So how would I go about doing that?

I'm not an expert in cobol as you can see so any help is very much appreciated.

Please let me know what you think. Thank you so much.

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Fri Dec 07, 2012 11:47 pm
by Akatsukami
This appears to be a program that is to run on a Wintel box. This is a mainframe help board; the two environments are so very different that it is unlikely that our advice would be useful to you.

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 12:04 am
by crazycobol
hello thnx for the response. I have gotten advise on this forum that has helped.

I'm not sure about the wintel box you are referring too. Mainframe cobol should work almost the same as any other cobol.

I am using microfocus cobol software to compile. anyways, let me know what you think I should do and I'll try and see if I can apply it to the software. It wouldn't hurt :)

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 12:07 am
by Robert Sample
Write a COBOL program to copy the data from your old file to your new file.

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 12:56 am
by crazycobol
so I would create another FD with the increase field.


SELECT DATABASE2 ASSIGN TO "C:\DATA2.DAT"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
LOCK MODE IS MANUAL
STATUS IS FILE-LOCK
RECORD KEY IS SSN2.

FD DATABASE2 LABEL RECORDS ARE STANDARD.

01 MASTER-RECORD2.

     05 FILLER           PIC XXX.
     05 SSN2                PIC X(9).
     05 FIRST NAME2    PIC X(30).
     05 LAST NAME2     PIC X(30).
     05 ADDRESS2         PIC X(30).
     05 FILLER            PIC X(2).
     05 CITY               PIC X(30).
     05 COUNTRY        PIC X(30).
     05 FILLER            PIC X(200).




WORKING-STORAGE SECTION.
PROCEDURE DIVISION.


OPEN INPUT DATABASE.

OPEN OUTPUT DATABASE2.

READ DATABASE.

MV MASTER-RECORD TO MASTER-RECORD2.

WRITE MASTER-RECORD2.


CLOSE DATABASE.

CLOSE DATABASE2.

EXIT PROGRAM.
STOP RUN.




would it be something like that?

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 1:13 am
by NicC
Yes- you have to write a file conversion program - or you may be able to do it via sort - unlikely unless you are just initialising the new fields. Read the file with the current format usimg the old layout, copy to the new format as your output file and write.
wintel = windows intel which is not supported on the mainframe forums.

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 1:26 am
by dick scherrer
Hello,

Once you have the process to expand the record from the old length to the new length, EVERY process that uses this file will have to change for the new length.

Other than a test, do not even consider reformatting the "real" data until everything that has to be changed has been identified and dealt with.

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 3:51 am
by crazycobol
thanks for the reply. Very much appreciate.

I tried to create another database so I don't change the original FD. However when I run it, it error out with a CODE 48.


FILE-CONTROL.

           SELECT ADDFIELD     ASSIGN TO DISK   extrafield.dat
               ORGANIZATION    IS  INDEXED
               ACCESS MODE     IS  DYNAMIC
               LOCK MODE       IS  MANUAL
               STATUS          IS  FILE-LOCK
               RECORD KEY      IS  XADDFLDKEY.

       DATA DIVISION.
       FILE SECTION.

FD ADDFIELD LABEL RECORDS ARE STANDARD.


01 XADDFREC.

    05   XADDFLDKEY
            10     XSSN          PIC X(09).

    05 XCITY                PIC X(30)
    05 XCOUNTRY        PIC X(30)

     05 FILLER             PIC X(200)








Below is the PROCEDURE DIVISION.

     NL-ADDFIELD.

          OPEN OUTPUT  ADDFIELD.

       NL-ADD-START.

           INITIALIZE XADDFREC.

           MOVE SPACES TO WFLG.

           MOVE WGEMPR     TO XEMPR.
           MOVE MSSN       TO XSSN.


           START ADDFIELD KEY = XADDFLDKEY INVALID KEY
               PERFORM ACCEPT-ADDFIELD THRU NL-ADDFIELD-END
               CLOSE ADDFIELD
               GO TO NL-ADDFIELD-END.

       ACCEPT-ADDFIELD.

           DISPLAY SPACES UPON CRT     LINE 4 POSITION 1.

           DISPLAY "CITY...:" LINE 5 POSITION 1
                                       WITH FOREGROUND-COLOR 11.

           DISPLAY "COUNTRY" LINE 6 POSITION 1
                                       WITH FOREGROUND-COLOR 11.

           DISPLAY XCITY      LINE 5 POSITION 30
                                       WITH FOREGROUND-COLOR 11.

           DISPLAY XCOUNTRY    LINE 6 POSITION 30
                                       WITH FOREGROUND-COLOR 11.


           DISPLAY
           "LETTER TO CORRECT * A:CITY, B:COUNTRY * (NL)-OUT"
                                        LINE 24 POSITION 02
                                        WITH FOREGROUND-COLOR 12.

           MOVE SPACES TO WFLG.

           ACCEPT WFLG               LINE 24 POSITION 78 WITH PROMPT
                                        FOREGROUND-COLOR 12.

           IF WFLG = " " OR "O" OR "o"
               GO TO AFT-RD.


           IF WFLG = "A"
               ACCEPT XCITY LINE 5 POSITION 30 WITH PROMPT
                                       FOREGROUND-COLOR 12.

           IF WFLG = "B"
               ACCEPT XCOUNTRY LINE 6 POSITION 30 WITH PROMPT
                                       FOREGROUND-COLOR 12.

           MOVE SPACES TO WFLG.

           DISPLAY "IS EVERYTHING CORRECT * (Y/N) * (O) - OUT"
                                       LINE 21 POSITION 1
                                       WITH FOREGROUND-COLOR 12.

           ACCEPT WFLG                 LINE 21 POSITION 78 WITH PROMPT
                                       FOREGROUND-COLOR 12.

           IF WFLG EQUAL "O"
               GO TO NL-ADDFIELD-END.

           IF WFLG EQUAL "N"
               GO TO ACCEPT-ADDFIELD.

           IF WFLG NOT EQUAL "Y"
               GO TO ACCEPT-ADDFIELD.

           MOVE WGEMPR     TO  XEMPR.
           MOVE MSSN       TO  XSSN.



           WRITE XADDFREC.

           CLOSE ADDFIELD.



           IF FILE-LOCK EQUAL "00"
               GO TO NL-ADDFIELD-END
           ELSE
           IF FILE-LOCK EQUAL "22"
               NEXT SENTENCE
           ELSE
               DISPLAY " WRITE ERROR ON ADD FIELD"
                                       LINE 18 POSITION 01
                                       WITH FOREGROUND-COLOR 12
              DISPLAY FILE-LOCK        LINE 18 POSITION 25
                                       WITH FOREGROUND-COLOR 12
              ACCEPT WFLG              LINE 18 POSITION 40 WITH PROMPT
                                       FOREGROUND-COLOR 12.


       NL-ADDFIELD-END.





I think I have to create extrafield.dat first or if I use the command "OPEN OUTPUT ADDFIELD"

it should create the file if it doesn't exsist?

So before doing it, do I need to do an OPEN OUTPUT and then put in another command OPEN I-O so that I can write to the file?

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 4:44 am
by BillyBoyo
Well, you see, the differences are starting to kick-in. "OPEN OUTPUT ADDFIELD" won't compile on the mainframe, so don't know what it tries to do on yours.

What did you find out about the "48"?

On the mainframe you would OPEN OUTPUT, when processing each input record, move the existing data to the output record and initialise the new fields, then write the output record. If that doesn't work for you....

Re: Need Advice How to Increase FD layout to Existing Progra

PostPosted: Sat Dec 08, 2012 7:21 am
by crazycobol
Its the same thing...the "addfield" is the input record.

I did "INITIALIZE" the new input record (INITIALIZE XADDFREC.) The XADDFREC is the entire record in the FD "ADDFIELD"

however when I try to write the record to the file, it doesn't write.