Professional Documents
Culture Documents
IBM Mainframes: COBOL Training Class-6
IBM Mainframes: COBOL Training Class-6
IBM Mainframes: COBOL Training Class-6
Meaning
Zero suppression
Z * , -/+
Meaning
Dollar sign insertion Credit symbol Debit symbol Blank insertion Slash insertion Decimal point insertion
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
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
&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
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"
Output SPOOL
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"
66 STUD-NAME RENAMES S-F-NAME THRU M4$% *e ., e ,#6+ -"%& 6e0e6 #4(*er 77.
S-L-NAME.
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
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#%
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# ')(-%$"
'5ample K *+ 0S-2<' ----P%C @@" G--- conditional varia le %)$2)# A2>/' *" 727= A2>/' +,9" CB%>( A2>/' : #B&/ +9" #'')-2<'& A2>/' +: #B&/ +@"
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
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'&.
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
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
are (.
Continue6 Continue passes control to )e5t Statement Ne7t Senten9e6 %t Passes control to the )e5t
Statement after %mplicit Scope #erminator"
T'an7 8ou