IBM Mainframes: COBOL Training Class-6

You might also like

Download as ppsx, pdf, or txt
Download as ppsx, pdf, or txt
You are on page 1of 33

IBM Mainframes

COBOL Training Class-6

Edited Picture Symbols Edit Symbol

Meaning
Zero suppression

Z * , -/+

Check protection Comma insertion

Plus or Minus sign insertion

Edited Picture Symbols Edit Symbol


$ CR DB B / . BLANK

Meaning
Dollar sign insertion Credit symbol Debit symbol Blank insertion Slash insertion Decimal point insertion

!"N #"R$ Blank insertion %hen the &al'e is (ero

Edit Symbol
(())) ---)) $)))) /)))) 1)))) ))2))) )).)) 99CR/DB 99B99

Value
12 12 0123 1234 1234 1234 12.345 12 1234

Edited Value
*+, ---+, $*+,. /+,.0 1+,.0 *+2,.0 +,..0 12CR/DB 12 34

RE I!I"ES #" RE"#MES

O$er$ie%

&'at is Redefines
Sometime two or more different varia les defined in a program are not in use simultaneousl!" #heir memor! can e then saved ! sharing the same location for all such varia les" $acilitates two or more data-%tems to point to the same memor! location" Simple wa! to save memor! while using data-items Should e declared at the time of data item definition in data division"

Rules

overning RE!EFINES Clause"

&edefining varia le and redefined varia le should e of same level number. #he PIC Clause of redefining varia le and redefined varia le need not e same" Multiple &'('$%)'S is allowed for a data-item"
&'('$%)'S

clause must not e used for *+ level in FILESECTION"

Must not e used for data-items defined in level num ers ,, and -- , should not have an .CC/&S clause" 0hen we use redefines we can1t use value clause for redefining item"

Synta( #nd E(am)le


S#NT$%" LEVEL&NO !$T$&N$ME&' RE!EFINES !$T$&N$ME&(. E%$MPLE )' *S&!$TE PIC %+,V$L.E /('0''0''/. )' *S&!$T$&!M# RE!EFINES *S&!$TE. )1 *S&!! PIC 2+(-. )1 FILLER PIC %. )1 *S&MM PIC2+(-. )1 FILLER PIC%. )1 *S&## PIC2+(-. )' C.STOMER&!$T$. )1 C.STOMER&I! PIC %+),-. )1 C.STOMER&I!&P$RTS RE!EFINES C.STOMER&I!. ') LOC$TION PIC %+3-. ') N$ME&$4REV PIC %+1.-

RE E!I"ES CL#*SE + WS00-YEAR2 e(am)le re e!"#e$ WS00-YEAR1.


I% "$ %&e $'(e ) *+%e$ ,! "#!,r('%",# -&".& WS00-YEAR2 /r,0" e$ "# %&e Ye'r1 M,#%& 2 D'+ !,r('% "# "%3$ $4*-"%e($. A#+ .&'#5e "# WS00-YEAR1 .&'#5e$ 0'64e ,! WS00-YEAR2 '# 0".e-0er$'.

************************************ YEAR FOR ENTERED DATE IS : 2005

Output SPOOL

MONTH FOR ENTERED DATE IS : 01 DAY FOR ENTERED DATE IS : 01 ************************************

REN$MES Clause

$acilitates re-grouping of elementar! data items in a record" 2fter the renames enforcement the elementar! items would elong to the original 3renamed4 group item as well as the new 3renaming4 group item"

S!nta5 6 55 data&name&' REN$MES data&name&( T6R. data&name&3. &ules #o 7e $ollowed 0hile /sing &')2M'S

&')2M'S must e used after the description of the fields re8uired" Must e coded onl! with level num er ,," (ata-names 9 and : should not have level num ers *+ and .CC/&S Clause" #he elementar! items getting renamed should e contiguous"

REN$MES Clause E7am8le


Example
01 05 05 05 05 STUD-DETAILS. REG-NO PIC 9(5). S-F-NAME PIC X(15). S-M-NAME PIC X(12). S-L-NAME PIC X(8). T&e e6e(e#%'r+ "%e($ 5e%%"#5 re#'(e $&,46 *e .,#%"54,4$.

66 STUD-NAME RENAMES S-F-NAME THRU M4$% *e ., e ,#6+ -"%& 6e0e6 #4(*er 77.

S-L-NAME.

REN$MES Clause E7am8le


0.&;%)<-S#.&2<' S'C#%.)" *+ P2=-&.>>-%)$." *: 'MP-P2=" *? 'MP-72S%C P%C @3?4 A2>/' @***" *? 'MP-B&2 P%C @3C4 A2>/' :***" *: 'MP-P2=-.#B'&S" *? 'MP-(2P%C @3:4 A2>/' -**" *? 'MP-%)C')#%A'S P%C @3*:4 A2>/' ?**" *: 'MP-('(/C#%.)S" *? 'MP-P$-#D P%C @3*:4 A2>/' @**" *? 'MP-P&.$-#D P%C @3*:4 A2>/' 9**" ,, 0S-A2&+ &')2M'S 'MP-72S%C #B&/ 'MP-(2" ,, 0S-A2&9 &')2M'S 'MP-P$-#D #B&/ 'MP-P&.$-#D"

Conditional ,erbs

I! #nd E$aluate

Introduction

%n programming, Man! times program needs to run one or more sets of statements ased on some condition %f condition is true, one set of statements get e5ecuted" %f condition is false another set of statements will get e5ecuted" Conditional statements altersE the control flow of the e5ecution %n C.7.> the Conditional statements are

IF Statement. E$L.$TE Statement.

Terminator/s " Im8li9it terminator statement ends :it; a 8eriod +.- and e78li9it terminator a statement :;i9; ends :it; verb t;at 8re9eded by EN! <ey:ord +S9o8e terminator-.

COBOL I! ST#TEME"T
D"!!ere#% F,r($ ,! IF S%'%e(e#%. S"(/6e IF IF CONDITION $%'%e(e#% END-IF. IF-E8SE IF CONDITION $%'%e(e#% E8SE $%'%e(e#% END-IF. END-IF E8SE IF CONDTION $%'%e(e#% E8SE $%'%e(e#% END-IF IF - E8SE 8' er IF CONDITION $%'%e(e#%

ifferent Ty)es Of Conditions

91: C6'$$ .,# "%",# 92: C,# "%",#-#'(e .,# "%",# 93: Re6'%",# .,# "%",# 94: S"5# .,# "%",# 95: Ne5'%e $"(/6e .,# "%",# 97: C,(*"#e .,# "%",#$

Class Condition
Class condition determines whether the identifier contains numeric value .& alpha etic value"
=Identi>ier&'? @isA @notA = numeri9 0 al8;abeti9 0 al8;abeti9&lo:er 0 al8;abeti9&u88er ?

#his condition is ver! useful to minimiFe the program errors" 7efore doing arithmetic operation we want to check whether the identifier contains the numeric data or not"
%$ 0S-2M# %S )/M'&%C 2(( 0S-2M# #. 0S-72)>2)C' '>S' M.A' Z'&.S #. 0S-2M# ')(-%$"

Condition-name -Condition "ame Condition .



Condition&name is a identifier defined with level number ,,. %t has onl! A2>/' clause, it does not contain an! picture clause" %t must alwa!s e associated to a data name called the conditional varia le" T;is one ma<es 8rogram more readability . Format " -- condition-name GA2>/' %S / A2>/'S 2&'H literal-+ I G#B&/H literal-9 J I, literal-: I G#B&/H literal-CJ """ J

'5ample K *+ 0S-2<' ----P%C @@" G--- conditional varia le %)$2)# A2>/' *" 727= A2>/' +,9" CB%>( A2>/' : #B&/ +9" #'')-2<'& A2>/' +: #B&/ +@"

/o% %e can use t'is in PROCE *RE

I,ISIO"0

IF INF$NT MOVE () TO *S&SI N$L PERFORM ())&INF$NT&P$R$ EN!&IF. IF *S&$ E B ) MOVE () TO *S&SI N$L PERFORM ())&INF$NT&P$R$ EN!&IF

Relation Condition

&elation condition compares two operands either of


which can e an identifier, literal, arithmetic e5pression" $ormat .perand + Grelational operatorH .perand 9 #he &elational operator specifies the t!pe of comparison

Relational O)erator
Re6'%",#'6 O/er'%,r . IS ;REATER THAN IS NOT ;REATER THAN IS 8ESS THAN IS NOT 8ESS THAN IS E>?A8 TO IS NOT E>?A8 TO IS ;REATER THAN OR E>?A8 TO IS 8ESS THAN OR E>?A8 TO C'# *e -r"%%e# '$ IS IS IS IS IS IS IS IS < NOT < = NOT = @ NOT @ <@ =@

Sign Condition
#he sign condition determines whether the given numeric value is grater than the CERO +or- less t;an t;e CERO +or- eDual to CERO " $ormat + o8erand&' @ISA @NOTA =POSITIVE0NE $TIVE0CERO? .perand-+ must e defined as a numeric identifier" %S P.S%#%A' condition will ecome true, if the operand-+ value grater than Z'&. %S )'<2#%A' condition will ecome true, if the operand-+ value less than Z'&. %S Z'&. condition will ecome true, if the operand-+ contains Z'&.

"egated sim)le condition


0e can negate the simple condition ! using ke!word ).#" '5" %$ 2 L 7 C.MP/#' C L 2 ** 9 ')(-%$ if 2 M 7 contains the same value, C.MP/#' statement will get e5ecuted" if we use ).# with the condition, C.MP/#' wont get e5ecuted, when 2 M 7 contains the same value" %$ ).# 2 L 7 C.MP/#' C L 2 ** 9 ')(-%$

Combined conditions

Com ined conditions contains two or more conditions connected using logical operators $N! or OR. $ormat condition-+ G2)(/.&H condition-9 I G2)(/.&H condition-: J"""

Combined Conditions

contd11

Be6,- %'*6e 5"0e$ %&e re$46%$ ,! 4$"#5 6,5".'6 ,/er'%,r$ AND 2 OR *e%-ee# %-, .,# "%",#$ COND1 2 COND2.
CO" 2
TR?E TR?E F8ASE F8ASE

CO" 3
TR?E F8ASE TR?E F8ASE

CO" 2 4 CO" 3
TR?E F8ASE F8ASE F8ASE

CO" 2 OR CO" 3
TR?E TR?E TR?E TR?E

E(am)le -2

I! !IVISION. PRO R$M&I!. IFPRO )'. ENVIRONMENT !IVISION. !$T$ !IVISION. *OREIN &STOR$ R SECTION. )' *S& EN!ER PIC %+)'- V$L.E SP$CE. PROCE!.RE !IVISION. M$IN&P$R$. $CCEPT *S& EN!ER. IF *S& EN!ER B FM/ !ISPL$# FMR/ EN!&IF. IF *S& EN!ER B FF/ !ISPL$# FMRs/ EN!&IF. STOP R.N.

E(am)le 5 2

contd1

I! !IVISION. PRO R$M&I!. IFPRO )(. ENVIRONMENT !IVISION. !$T$ !IVISION. *OREIN &STOR$ R SECTION. )' *S& EN!ER PIC %+)'- V$L.E SP$CE. PROCE!.RE !IVISION. M$IN&P$R$. $CCEPT *S& EN!ER. IF *S& EN!ER B FM/ !ISPL$# FMR/ ELSE !ISPL$# FMRs/ EN!&IF. STOP R.N.

E(am)le 5 2

cont+

I! !IVISION. PRO R$M&I!. IFPRO )3. ENVIRONMENT !IVISION. !$T$ !IVISION. *OREIN &STOR$ R SECTION. )' *S& EN!ER PIC %+)'- V$L.E SP$CE. PROCE!.RE !IVISION. M$IN&P$R$. $CCEPT *S& EN!ER. IF *S& EN!ER B FM/ !ISPL$# FMR/ ELSE IF *S& EN!ER B FF/ !ISPL$# FMRs/ ELSE !ISPL$# FERROR EN!ER INP.T/ EN!&IF EN!&IF. STOP R.N.

E,#L*#TE Statement

'valuate is also used for conditional checking similar to %$ statement" 'valuate was designed in Cobol&,1" 'valuate efficientl! and effectivel! re8la9es Nested&I> statements. 'valuate is of three t!pes6

EV$L.$TE TR.E EV$L.$TE OPTION EV$L.$TE $LSO

Synta(
EV$L.$TE V$RI$4LE&N$ME *6EN V$L.E ST$TEMENT' ST$TEMENT( *6EN V$L.E ST$TEMENT3 ST$TEMENTG *6EN OT6ER ST$TEMENT1 ST$TEMENT5 EN!&EV$L.$TE. CON!ITION TR.E CON!ITION

Points to "oted

Ma5imum we can check 9?? when conditions using evaluate" 0hen other is an optional statement ut it is highl! recommenda le to code" 0B') .#B'& is alwa!s a true statement, hence should e coded as last condition" 0hen a match found the statement following the *6EN clause and efore the ne5t *6EN clause, are e5ecuted and control is then passed to statement following the EN!&EV$L.$TE" %f no matching when clause is found, the statements following the *6EN OT6ER statement is e5ecuted

CO"TI"*E 4 "E6T SE"TE"CE

C.)#%)/' M )'D# S')#')C'


).#B%)< operation statement" after '5plicit Scope terminator"

are (.

Continue6 Continue passes control to )e5t Statement Ne7t Senten9e6 %t Passes control to the )e5t
Statement after %mplicit Scope #erminator"

T'an7 8ou

You might also like