Вы находитесь на странице: 1из 16

IBM MAINFRAMES

COBOL Training Class-10

Introduction to COPY Stat ! nt

A COPY statement is used to bring a series of prewritten COBOL entries that have been stored in library, into a program. These are used at

Common routines like error routine, date validation


routine are oded in a library and bring into the program by COPY.

!aster files are used in multiple programs. Their layout


an be pla ed in one opyboo" and be pla ed wherever the files are used. #t promotes program standardi$ation sin e all the programs share the same layout and the same data names. !ostly %now as COPYBOOK

Introduction to COPY Stat ! nt contd""

Copyboo"s are stored as members in P&' library


and during ompilation time, they are in luded into the program.

By default, the opyboo" library is 'Y'L#B. Copyboo"s an be used in


ENVIRONMENT IVI!ION "T" IVI!ION PROCE #RE IVI!ION$

Pur#os

O$ COPY Stat ! nt

This redu

es oding and debugging time. Change in layout needs hange in opyboo" only. #t is enough if we (ust re ompile the program for ma"ing the new opy effe tive.

'ynta)*
COPY opyboo"+name

,-.PLAC#/0 string+to+be+repla ed BY repla ing+ string1

R #lacing o#tion %it& COPY

One opyboo" an be used with -.PLAC#/0 verb to repla e high+level 2ualifier of the all the variables with another 2ualifier. .)ample*

COPY C3'TO!.- -.PLAC#/0 4C3'T5+4 BY 4C3'T6+4.

&elimiter %& &' should be used for repla ing pseudo te)ts. The repla ing option does not alter the prewritten entries in the library7 the hanges are made to the user8s sour e program only.

Introduction to CALL Stat ! nt

9hen a spe ifi fun tionality need to be performed in more than one program, it is best to write them separately and all them into ea h program. The main program that referen es or alls a subprogram is referred to as the alling program. The subprogram that is lin"ed and e)e uted within the main program is referred to as the alled program.

Main Progra! in ' tails


Main Pro(ram CALL statement is used for e)e uting the sub+program from the main program. A sample of CALL statement is given below* C")) %P*MN"ME+' #!IN* BY RE,ERENCE -!.V"R+, BY CONTENT -!.V"R/$ P0!/A!.5 is alled here. 9'+:A-5 and 9'+:A-6 are wor"ing storage items. 9'+:A-5 is passed by referen e. 9'+ :A-6 is passed by Content. BY -.;.-./C. is default in COBOL and need not be oded.

Pass B( R $ r nc
BY RE,ERENCE

) Pass B( Cont nt
BY CONTENT

Call 4P0!/A!.8 3'#/0 BY -.;.-./C. ws+var5. #t is default in COBOL

Call 4P0!/A!.8 3'#/0 BY CO/T./T ws+var5. BY CO/T./T "ey word is re2uired The sub+program modifi ations on the passed elements are lo al to that sub+program and not visi0le in the main program.

"ddress of ws+var5 is passed Value of ws+var5 is passed The sub+program modifi ations on the passed elements are visible in the main program.

Su* Progra! in ' tails


PRO*R"M.I . <Program+name= #' INITI") PRO*R"M. #f #' INITI") PRO*R"M is oded along with program+id of sub program, then the program will be in initial stage every time it is alled >COBOL?@ featureA. Alternatively C"NCE) issued after CALL, will set the sub+ program to initial state.

#f the sub program is modified then it needs to be re ompiled. The need for main program re ompilation is de ided by the ompiler option used for the main program. #f the YN"M ompiler is used, then there is no need to re ompile the main program. NO YN"M is default that e)pe ts the main program re ompilation.

Su* Progra! in ' tails cond""

L#/%A0. '.CT#O/ is used to define all the re eiving data items . P-OC.&3-. &#:#'#O/ 3'#/0 L%+:A-5,L%+:A-6 There is a one+one orresponden e between passed elements and re eived elements BY PO'#T#O/. This implies that the name of the identifiers in the alled and alling program need not be the same >9'+:A-5 B L%+:A-5A but the number of elements and pi ture lause should be same. The last statement of your sub+program should be .C#T P-O0-A!D0OBAC%. This returns the ontrol ba " to main program. 3se 0OBAC% but not 'TOP -3/.

'i$$ r nc

B+, Static ) '(na!ic CALL

#dentified by CALL literal E12 C")) %PRO*N"ME'$ &efault ompiler option is /O&Y/A! #f subprogram undergoes hanges main program B sub program both should be re ompiled

#dentified by variable should be populated at run time.


E32 C")) -!.PR*N"ME.

Compiler option is &Y/A! -e ompilation of subprogram is enough

Static ) '(na!ic

Cond""

'ub modules are lin" edited with main module 'i$e of load module is lar(e ,ast a ess )ess 4le1i0le 9ill not be in initial state the ne)t time it is alled unless e)pli itly use INITI") O- CA/C.L after ea h CALL

'ub modules are pi "ed up during run Load si$e is less !lo5 ompared to stati More fle)ible 9ill be in initial state every time it alled.

MAIN PRO-RAM

IDENTIFICATION DIVISION. PROGRAM-ID. MAINPGM. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 Sales-Data. 05 WS-NO-UNITS 05 WS-COST 05 WS-AMNT 01 WS-PGMNAME PIC %(0&! VA'UE PROCEDURE DIVISION. 100-MAIN-'OGIC.

PIC 9( !. PIC 9("!V9(#!. PIC 9($!V9(#!. (SU)PROG*.

ACCEPT WS-NO-UNITS. ACCEPT WS-COST. ACCEPT WS-AMNT. CA'' (SU)PROG*+WS-PGMNAME USING WS-NO-UNITS,WS-COST ,WSAMNT. STOP RUN.

S.B PRO-RAM

IDENTIFICATION DIVISION. PROGRAM-ID. SU)PROG IS INITIA' PROGRAM. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 'INKAGE SECTION. 01 'S-Sales-Data. 05 'S-NO-UNITS PIC 9( !. 05 'S-COST PIC 9("!V9(#!. 05 'S-AMNT PIC 9($!V9(#!. PROCEDURE DIVISION USING 'S-NO-UNITS 'S-COST 'S-AMNT. 100-MAIN-'OGIC. DISP'A- 'S-SA'ES-DATA. GO)ACK.

PARM Para! t r

#t is used to a ess the data that are e)ternal to the program. ECL an send ma)imum 5FF hara ters to a program thru PA-!. Lin"age se tion !3'T be oded with a hal4 5ord 0inary 4ield, prior to a tual field. #f length field is not oded, the first two bytes of the field oded in the lin"age se tion will be filled with length and so there are han es of 6 bytes data trun ation in the a tual field.

F5 L%+&ATA.
F@ L%+L./0TG P#C 'H>FIA CO!P. F@ L%+:A-#ABL. P#C C>F?A.

T&an/ You

Вам также может понравиться