  | 
		
HP COBOL Reference Manual
 
 
 
  
    
       
      
IF ITEMA > 10
  MOVE "X" TO ITEMB
ELSE
  GO TO PROC-A.
ADD ...
 
 |   
  
    | ITEMA  | 
    Next   Statement  | 
    ITEMB  | 
   
  
    | 
      96
     | 
    
      ADD
     | 
    
      "X"
     | 
   
  
    | 
      8
     | 
    
      PROC-A
     | 
    
      ?
     | 
   
 
  With NEXT SENTENCE phrase:  (In each case, the next executable
  statement is the ADD statement.)
 
  
    
       
      
IF ITEMA < 10 OR > 20
  NEXT SENTENCE
ELSE
  MOVE "X" TO ITEMB.
ADD ...
 
 |   
  
    | ITEMA  | 
    ITEMB  | 
   
  
    | 
      5
     | 
    
      ?
     | 
   
  
    | 
      17
     | 
    
      "X"
     | 
   
  
    | 
      35
     | 
    
      ?
     | 
   
 
  Nested IF statements:
 
  
    
       
      
IF ITEMA > 10
  IF ITEMA = ITEMC
    MOVE "X" TO ITEMB
  ELSE
    MOVE "Y" TO ITEMB
ELSE
  GO TO PROC-A.
ADD ...
 |   
  
    Input   Values  | 
      | 
    Output   Value  | 
   
  
    | ITEMA  | 
    ITEMC  | 
    Next   Statement  | 
    ITEMB  | 
   
  
    | 
      12
     | 
    
      6
     | 
    
      ADD
     | 
    
      "Y"
     | 
   
  
    | 
      12
     | 
    
      12
     | 
    
      ADD
     | 
    
      "X"
     | 
   
  
    | 
      8
     | 
    
      8
     | 
    
      PROC-A
     | 
    
      ?
     | 
   
 
  END-IF:  (In this example, the initial value of ITEMD is 5.)
 
  
    
       
      
IF ITEMA > 10
  IF ITEMA = ITEMC
    ADD 1 TO ITEMD
    MOVE "X" TO ITEMB
  END-IF
  ADD 1 TO ITEMD.
 |   
  
    | ITEMA  | 
    ITEMC  | 
    ITEMB  | 
    ITEMD  | 
   
  
    | 
      4
     | 
    
      6
     | 
    
      ?
     | 
    
      5
     | 
   
  
    | 
      15
     | 
    
      6
     | 
    
      ?
     | 
    
      6
     | 
   
  
    | 
      13
     | 
    
      13
     | 
    
      "X"
     | 
    
      7
     | 
   
  
    | 
      7
     | 
    
      7
     | 
    
      ?
     | 
    
      5
     | 
   
 
6.8.18 INITIALIZE
Function 
 
 
The INITIALIZE statement sets selected types of data fields to
predetermined values.
  
 
fld-name
is the identifier of the receiving area data item.
val
is the sending area. It can be a literal or the identifier of a data
item.
 
Syntax Rules 
 
 
  - The phrase after the word REPLACING is the category phrase.
  
 - The category of the data item referred to by val must be
  consistent with that in the category phrase. The combination of
  categories must allow execution of a valid MOVE statement.
  
 - The same category cannot be repeated in a REPLACING phrase.
  
 - The description of fld-name or any item subordinate to it
  cannot contain the OCCURS clause DEPENDING phrase.
  
 - Neither fld-name nor val can be index data items.
  
 - fld-name cannot contain a RENAMES clause.
  
General Rules 
 
 
  - The key word that follows the word REPLACING corresponds to a
  category of data. (See the section on Categories and Classes of Data in
  the Data Division chapter.)
  
 - fld-name can be an elementary or group item. If it is a
  group item, the INITIALIZE statement operates on the elementary items
  within the group item. For a table within a group item, INITIALIZE
  operates on the elementary items within the table.
  
 - Whether fld-name is an elementary item or a group item, if
  the REPLACING phrase is specified, all data movement operations occur
  as if they resulted from a series of MOVE statements with elementary
  item receiving areas:
  
    - If the receiving area is a group item, INITIALIZE affects only
    those subordinate elementary items whose category matches a category
    phrase. General Rule 6 describes the effect on elementary items when
    there is no REPLACING phrase.
    
 - INITIALIZE affects all eligible elementary items, including all
    occurrences of table items in the group.
    
 - If the receiving area is an elementary item, that item is
    initialized only if it matches a category phrase.
  
  
   - INITIALIZE does not affect index data items and FILLER data items.
  
 - INITIALIZE does not affect items subordinate to fld-name
  that contain a REDEFINES clause. Nor does it affect data items
  subordinate to those items. However, fld-name itself can have
  a REDEFINES clause or be subordinate to a data item that does.
  
 - When there is a REPLACING phrase, val is the sending field
  for each of the implicit MOVE statements.
  
 - When there is no REPLACING phrase, the sending field for the
  implicit MOVE statements is as follows:
  
    - SPACES, if the data item category is alphabetic, alphanumeric, or
    alphanumeric edited
    
 - ZEROS, if the data item category is numeric or numeric edited
  
  
   - INITIALIZE operates on each fld-name in the order it
  appears in the statement. When fld-name is a group item,
  INITIALIZE operates on its eligible subordinate elementary items in the
  order they are defined in the group.
  
 - If fld-name occupies the same storage area as
  val, the execution result of this statement is undefined. (See
  the section on Overlapping Operands and Incompatible Data.)
  
Additional References 
 
 
Examples 
 
 
In the examples' results, a hyphen (-) means that the value of the data
item is unchanged; s represents the character space. The examples
assume this data description:
 
 
  
    
       
      
01  ITEMA.
    03  ITEMB      PIC X(4).
    03  ITEMC.
        05  ITEMD  PIC 9(5).
        05  ITEME  PIC $$$9.99.
        05  ITEMF  PIC XX/XX.
    03  ITEMG.
        05  ITEMH  PIC 999.
        05  ITEMI  PIC XX.
        05  ITEMJ  PIC 99.9.
    03  ITEMK      PIC X(4) JUSTIFIED RIGHT.
 |   
  - 
INITIALIZE ITEMA.
  
 - 
INITIALIZE ITEMB ITEMG.
  
 - 
INITIALIZE ITEMA REPLACING ALPHANUMERIC BY "ABCDE".
  
 - 
INITIALIZE ITEMG REPLACING NUMERIC BY 9.
  
 - 
INITIALIZE ITEMA REPLACING NUMERIC-EDITED BY 16.
  
 - 
INITIALIZE ITEMA REPLACING ALPHANUMERIC-EDITED BY "ABCD".
  
 - 
INITIALIZE ITEMA REPLACING ALPHANUMERIC BY "99".
  
  
    |   | 
    ITEMB  | 
    ITEMD  | 
    ITEME  | 
    ITEMF  | 
    ITEMH  | 
    ITEMI  | 
    ITEMJ  | 
    ITEMK | 
   
  
    | 
      1.
     | 
    
      ssss
     | 
    
      00000
     | 
    
      ss$0.00
     | 
    
      ss/ss
     | 
    
      000
     | 
    
      ss
     | 
    
      00.0
     | 
    
      ssss
     | 
   
  
    | 
      2.
     | 
    
      ssss
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      000
     | 
    
      ss
     | 
    
      00.0
     | 
    
      --
     | 
   
  
    | 
      3.
     | 
    
      ABCD
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      AB
     | 
    
      --
     | 
    
      BCDE
     | 
   
  
    | 
      4.
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      009
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
   
  
    | 
      5.
     | 
    
      --
     | 
    
      --
     | 
    
      s$16.00
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      16.0
     | 
    
      --
     | 
   
  
    | 
      6.
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      AB/CD
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
   
  
    | 
      7.
     | 
    
      99ss
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      --
     | 
    
      99
     | 
    
      --
     | 
    
      ss99
     | 
   
 
  
  
		 |