I ran the following query a couple of days back:
SELECT LRAWFIELD FROM Z_TEST_TABLE
Z_TEST_TABLE is a table defined in my test SAP instance, and LRAWFIELD is a column of type LRAW and length 256. I was writing a unit test, and expected it to pass. Unfortunately, it failed! The value selected was only correct upto the first 32 bytes, the remaining 224 bytes were all zeros!
Debugging into it, I realized that its a SAP issue. When a LRAW field is present in any table, SAP requires that there exist a preceding INT2 column (I think this column is supposed to store the length). Now, when a SELECT query is run against SAP’s query processor, if the INT2 column is not selected, or appears in the SELECT field list after the LRAW column, incorrect data is returned for the LRAW column (only the first 32 bytes are correct).
Therefore, the solution is to make sure the corresponding INT2 column is also selected in the same SELECT statement, and that it appears immediately before the LRAW field in the SELECT list.