Separating digits from a packed decimal field

I have a 7 digit packed decimal field in my file. How can I determine the data elements that will extract / separate these 7 digits?

For example, I want to have the first two digits in one data element and the other digits in another, so I can manipulate them later.

+4
source share
2 answers

In some other languages, one of the things that could be spread would be to "divide by a multiple of 10", respectively, the corresponding factor.

However, never consider this with COBOL. "Separation" is "expensive."

       05  input-packed-decimal 
                            PACKED-DECIMAL PIC 9(7).

Then:

       05  FILLER 
           REDEFINES input-packed-decimal.
           10  ipd-split-two-and-five
                            PACKED-DECIMAL PIC 99V9(5).

   01  two-digits                          PIC 99.
   01  five-digits                         PIC 9(5).
   01  FILLER
       REDEFINES five-digits.
       05  five-digits-as-decimals         PIC V9(5).

       MOVE ipd-split-two-and-five  TO two-digits
                                       five-digits-as-decimals

two-digits five-digits , .

:

   01  ws-input-seven                      PIC 9(7).
   01  FILLER 
       REDEFINES ws-input-seven.
       05  two-digits                      PIC 99.
       05  five-digits                     PIC 9(5).

       MOVE input-packed-decimal    TO ws-input-seven

( S PICture).

, two-digits, MOVE , .

, PACKED-DECIMAL BINARY ( IBM COMP-3 COMP/COMP-4/COMP-5). , , . REDEFINES , , , " " . , , REDEFINES.

, :

       05  FILLER 
           REDEFINES input-packed-decimal.
           10  ignore-one-use-2nd-next-five
                            PACKED-DECIMAL PIC 9V9(5).

, PACKED-DECIMAL PIC 99V9 (5), , . , .

" REDEFINES", WORKING-STORAGE , , .

, , . , . , , , .

"Var (n)" , .

+5

01 the-array.

03  filler pic x(02) value '00'.

03  filler pic x(02) value '01'.

03  filler pic x(02) value '02'.

..,

03  filler pic x(02) value 'FF'.

01 two-array .

03  harry occurs 256 pic x(02).

91 sub1.

03  filler pic x(01) value low-values.

93  sub1-byte2 pic x(01).

01 sub2 sub1 comp.

01 pd pic x (04).

01 pub pic 9 (04).

01 .

03  eggs1 pic x(01).

03  eggs2 pic x(01).

1 1

pub > 4

move pd(pub:1) to sub1-byte2

move harry(sub2 + 1) to eggs

display eggs1 egg2

.

, 256 '00' 'FF'.

4 , .

( 1, , "00" ).

2 , 2 , .

.

0

Source: https://habr.com/ru/post/1660655/


All Articles