BOR
BOR

Reputation: 11

COBOL : Move PIC X TO PIC S9.99 COMP-3

How I can move data from example : I-DATA PIC X7 VALUE ' 12.34'. to O-DATA PIC S9(13)V99 COMP-3.

Upvotes: 1

Views: 2584

Answers (2)

Scott Nelson
Scott Nelson

Reputation: 616

Your pic clause for i-data is bad (it should be PIC X(7)).

Anyway to answer your question, use MOVE ... TO ... WITH CONVERSION ON EXCEPTION ... END-MOVE

05 I-DATA PIC X(7).
05 O-DATA PIC S9(13)V99 COMP-3.
05 HAD-ERROR-FLAG PIC X.
   88  HAD-ERROR VALUE "Y" FALSE "N".
...

MOVE I-DATA TO O-DATA WITH CONVERSION
ON EXCEPTION
  MOVE ZERO TO O-DATA
  SET HAD-ERROR TO TRUE
NOT ON EXCEPTION
  SET HAD-ERROR TO FALSE
END-MOVE

Upvotes: 1

James Anderson
James Anderson

Reputation: 27478

   05 I-DATA PIC X(7).
   05 I-NUMERIC REDEFINES I-DATA PIC 9999.99.
   .
   .
   MOVE I-NUMERIC TO O-DATA.

You need to redefine you AlphaNumerc as a Display Numeric which can then be moved to the packed decimal variable. Be careful as this will bomb out with an OC7 if there is anything other than numbers or spaces plus the '.' in the data.

Upvotes: 1

Related Questions