Page 1 of 1

Access numerics fields by bytes.

Posted: Wed Apr 18, 2018 5:47 pm
by Manoj Verma
Hi,

Can we do byte level manipulation in COBOL? To this question, I said, yes we can do it. Then second question was, how can we access bytes in a numeric field? To which I had not had a good answer. But later I thought and said that every digit in any numeric field will take a byte and as such that is a byte level manipulation. But my interviewer was not satisfied. Can someone please help me with this question?

Re: Access numerics fields by bytes.

Posted: Wed Apr 18, 2018 6:45 pm
by Robert Sample
Reference modification only works with USAGE DISPLAY type data (USAGE DISPLAY, DISPLAY-1, NATIONAL). So your answer was seriously incomplete since numeric variables may be USAGE DISPLAY, COMP, COMP-3 (COMP-1 and COMP-2 should not ever be manipulated using reference modification, while COMP-4 and COMP-5 are the equivalent of COMP). For COMP and COMP-3 variables, to use reference modification on them you can either move them to a USAGE DISPLAY variable or use a REDEFINES to create a PIC X variable. If you use REDEFINES, manipulating the individual bytes requires significant knowledge of the internal representation of numbers or you'll manage to completely screw up the data.