Unstring in Visual COBOL


I am trying to perform an Unstring on a response received(String).

Following is the code which i am using

01 numeric-test-var PIC 9(1) .

01 input-String1 PIC x(9) value spaces .

01 String2  PIC x(6) value spaces .


move 'ABCDEF! !' to input-String1.

Unstring input-String1 delimited by '!' into



display numeric-test-var.


When the above code executed i am getting the following value in "numeric-test-var"

' '.

I am getting space in numeric variable. Which is different.

Also if i change the defination of "numeric-test-var" from PIC 9(1) to PIC 9(5) and perform the same code as above and display the value of "numeric-test-var" then the response will be

'0000 '. The last digit in numeric field is spaces now.

Please let me know if you can provide what i need to do to correct it? Also this is not happening in Net Express 5.1.




  • The rules for the UNSTRING statement state that the behavior of unstringing a value into a receiving field will be the same as if a MOVE were done between the sending literal and the receiving field and this is what is happening in both NX and VC.

    The problem is that you are moving invalid data (space) into a numeric field.

    The resultant field when it is defined as PIC 9 will contain a space character X"20" in both NX and VC. The difference is that in NX the DISPLAY statement seems to output a "0" character and in VC the DISPLAY outputs a " ". The behavior in VC although different appears to be more correct to me.

    If you are expecting that the UNSTRING will convert a space into a "0" when it is moved to a numeric field then you might try to turn on directive SPZERO and you might get the expected behavior you desire.