Highlighted
Absent Member.
Absent Member.
844 views

Unstring in Visual COBOL

Hi

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 .

Para1. 

move 'ABCDEF! !' to input-String1.

Unstring input-String1 delimited by '!' into

 String2

 numeric-test-var.

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.

Thanks

Charan

 

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

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.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.