Rahul
Rahul

Reputation: 119

Abend S0C7 error while moving data to COMP-3 fields

Moving data to COMP-3 fields after UNSTRING.

UNSTRING is working fine but I am not able to move data to COMP-3 fields without an S0C7 data exception abend.

I think it is an issue with storing data.

Below is my COBOL program.

IDENTIFICATION DIVISION.                              
 PROGRAM-ID. ADDPROG.                                  
 DATA DIVISION.                                        
   WORKING-STORAGE SECTION.                            
    01 VALUEA         PIC X(20) VALUE '64.99|64.99'.   
    01 NOA            PIC S9(9)V9(02).                 
    01 NOB            PIC S9(9)V9(02).                 
    01 NOC            PIC S9(9)V99 COMP-3.             
    01 NOD            PIC S9(9)V99 COMP-3.             
 PROCEDURE DIVISION.                                   
  000-MAIN.                                            
     DISPLAY "EARLIER".                                
     DISPLAY 'NOA-' NOA.                               
     DISPLAY 'NOB-' NOB.                               
     DISPLAY "AFTER".                                  
     UNSTRING VALUEA                                   
     DELIMITED BY '|'                                  
     INTO NOA,NOB.          
     DISPLAY 'NOA-' NOA.    
     DISPLAY 'NOB-' NOB.    
     MOVE NOA TO NOC.       
     MOVE NOB TO NOD.       
     DISPLAY 'NOC-' NOC.    
     DISPLAY 'NOD-' NOD.    
     STOP RUN. 

Output I am getting after compiling.

enter image description here

Please let me know is there any other way to move data to COMP-3 fields or to avoid this error.

Upvotes: 0

Views: 1085

Answers (3)

sanket nawale
sanket nawale

Reputation: 11

Your decimal data field are wrong just have . Like 01 NOA PIC S9(9).(02) In them! Same with noc variabile then it should run.

To move data from a numeric field to a COMP-3 field, you need to make sure that the data in the numeric field is valid for the COMP-3 field. A COMP-3 field stores packed decimal data, which means that the digits of the number are packed into two-digit decimal fields. The decimal point is not stored, and the sign of the number is stored in the last nibble of the field.

Upvotes: 0

Scott Nelson
Scott Nelson

Reputation: 616

Like piet.t said, the UNSTRING statement is like a alphanumeric move. Therefore my suggestion is to:

  1. make NOA and NOB be alphanumeric (PIC X(12)), and
  2. change your move statements to include WITH CONVERSION so that it will convert the numeric data in the alphanumeric field into COMP-3.

Upvotes: 0

piet.t
piet.t

Reputation: 11921

Your code has two main problems. To see them you first have to understand that your UNSTRING into NOA and NOB works like any other character-to-character MOVE. So it starts from the left and moves character after character until one field ends and if necessary adds some blanks to fill up the receiving field.

So problem one is that NOA contains the value left-justified while according to your PIC-clause it should be right-justified, so you would need an intermediate PIC X(12) JUSTIFIED RIGHT field that you UNSTRING to.

The second problem that is causing the S0C7 is that your PIC-clause does not include a decimal-point. The V specifies the implied position of the decimal point but it would not show on output nor is it handled correctly when parsing the field-contents. To have a field that correctly handles the decimal point you should have a PIC S9(9)V.9(02).

Please also see this question.

Upvotes: 3

Related Questions