Need Advice How to Increase FD layout to Existing Program



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

Need Advice How to Increase FD layout to Existing Program

Postby crazycobol » Fri Dec 07, 2012 11:26 pm

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.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

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

 

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

Postby Akatsukami » Fri Dec 07, 2012 11:47 pm

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.
"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: Need Advice How to Increase FD layout to Existing Progra

Postby crazycobol » Sat Dec 08, 2012 12:04 am

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 :)
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

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

Postby Robert Sample » Sat Dec 08, 2012 12:07 am

Write a COBOL program to copy the data from your old file to your new file.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

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

Postby crazycobol » Sat Dec 08, 2012 12:56 am

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?
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

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

Postby NicC » Sat Dec 08, 2012 1:13 am

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.
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

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

Postby dick scherrer » Sat Dec 08, 2012 1:26 am

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.
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: Need Advice How to Increase FD layout to Existing Progra

Postby crazycobol » Sat Dec 08, 2012 3:51 am

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?
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

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

Postby BillyBoyo » Sat Dec 08, 2012 4:44 am

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....
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

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

Postby crazycobol » Sat Dec 08, 2012 7:21 am

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.
crazycobol
 
Posts: 35
Joined: Fri Dec 04, 2009 3:33 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post