Search code examples
variablescobolmainframe

How to pass a real decimal value into a virtual decimal value?


I have a PIC 9(14).9(2) variable that receives data from an incoming file. I wish to pass it into a report variable that is a PIC 9(14)V9(2). The format of incoming data can't be altered. Is there any way I can pass one value into another?


Solution

  • The pic 9(14).9(2) is essentially a Pic X field. You could set up redefine fields or use reference modification

    i.e.

           03 F1                 PIC 9(14).9(2).
           03 filler redefines F1.
              05 F1-Int          pic 9(14).
              05 filler          pic X.
              05 F1-decimal      pic 9(2).
    
           03 F2                 PIC 9(14)V9(2).
           03 filler redefines F2.
              05 F2-Int          pic 9(14).
              05 F2-decimal      pic 9(2).
    
           Move F1-int          to f2-int.
           Move F1-decimal      to f2-decimal.
    
    or    
           Move F1(1:14)        to F2(1:14).   
           Move F1(16:2)        to F2(15:2).   // Forgoten the correct format for cobol