skip to main content

Procedure Division Statements : DIVIDE

DIVIDE
General Format
Format 1
DIVIDE {Identifier-1} INTO { Identifier-2 [ROUNDED] } ... 
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-DIVIDE]
Format 2
DIVIDE {Identifier-1} INTO {Identifier-2}
  GIVING { Identifier-3 [ROUNDED] } ... 
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-DIVIDE]
Format 3
DIVIDE {Identifier-2} BY {Identifier-1}
  GIVING { Identifier-3 [ROUNDED] } ... 
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-DIVIDE]
Format 4
DIVIDE {Identifier-1} INTO {Identifier-2}
  GIVING { Identifier-3 [ROUNDED]  } ...
  REMAINDER Identifier-4
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-DIVIDE]
Format 5
DIVIDE {Identifier-2} BY {Identifier-1}
  GIVING { Identifier-3 [ROUNDED]  } ...
  REMAINDER Identifier-4
  [ ON SIZE ERROR Imperative-Statement-1 ]
  [ NOT ON SIZE ERROR Imperative-Statement-2 ]
  [END-DIVIDE]
Syntax rules
1.
2.
3.
4.
General rules
All Formats
1.
A.
B.
C.
Format 1
2.
A.
B.
Formats 2 and 3
3.
A.
B.
Formats 4 and 5
4.
A.
B.
C.
Examples
Format 1 - Divide literal into variable and validate size error.
move    10500   to num-years
divide 365.25 into num-years
    on size error display message "Invalid result size of last divide operation!"
    not on size error display message "Number of years : " num-years
Format 2 - Divide variable into variable and leave result in separate variable, validating size error.
move 365 to year-days
move  15 to period-days
move zero to num-periods-year
divide period-days into year-days giving num-periods-year 
 on size error display message "Invalid result size of last divide operation!"
 not on size error display message "Number of periods a year : " num-periods-year
Format 3 - Divide variable by variable and leave result in separate variable, validating size error.
move 365 to year-days
move  15 to period-days
move zero to num-periods-year
divide year-days by period-days giving num-periods-year 
 on size error display message "Invalid result size of last divide operation!"
 not on size error display message "Number of periods a year : " num-periods-year
Format 4 - Divide variable into variable leaving result in separate variable and remainder in another variable too.
move 365 to year-days
move  15 to period-days
move zero to num-periods-year
divide period-days into year-days giving num-periods-year 
       remainder not-used-days
display message 
        "A year of 365 days, has " num-periods-year 
         " periods of 15 days plus " not-used-days " days"
Format 5- Divide variable by variable leaving result in separate variable and remainder in another variable too.
move 365 to year-days
move  15 to period-days
move zero to num-periods-year
divide year-days by period-days giving num-periods-year 
       remainder not-used-days
display message 
        "A year of 365 days, has " num-periods-year 
         " periods of 15 days plus " not-used-days " days"

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left