SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.




CRM Companies List
Web Based CRM Software


SAPSQL_DATA_LOSS ABAP Programming Error

At runtime I experienced SAPSQL_DATA_LOSS ABAP programming error in SAP after I change Select statement with SPRAS language criteria to new Open SQL syntax ABAP for HANA. I was just checking my previous codes developed in classic ABAP Select statements and re-writing some by transforming the old syntax to new enhanced ABAP Open SQL syntax which was introduced with NetWeaver AS ABAP 7.4

ABAP Programming Error
SAPSQL_DATA_LOSS
Data was lost while copying a value.

Since the error was not caught by the ABAP compiler in ABAP Editor and at my first meet I could not find any information about SAPSQL_DATA_LOSS ABAP programming error on the web, I decided to take some notes on my web blog kodyaz.com

Below sample codes are showing the previous and updated versions of the ABAP Select statement which the change caused the ABAP dumps at runtime that can be detailed by ST22 transaction code.

" prior ABAP code
DATA lv_maktx TYPE maktx.
SELECT SINGLE maktx INTO lv_maktx
 FROM makt
 WHERE spras EQ piv_lang
  AND matnr EQ piv_matnr.

" new enhanced OSQL syntax, ABAP for HANA
SELECT SINGLE maktx INTO @DATA(lv_maktx)
 FROM makt
 WHERE spras EQ @piv_lang
  AND matnr EQ @piv_matnr.

As programmers will see, it seems a standart way of transforming the ABAP Select for new syntax which introduced inline variable declarations and some performance improvements. ABAP developers which are new to this syntax can remember that the columns are seperated by comma and parameters are identified by "@" in front of them.

Unfortunately, with some improper parameter declaration for the form routine code including this select statement and the PERFORM statement calling this routine; ABAP programming error SAPSQL_DATA_LOSS was triggered.
When I execute SAP transaction ST22 to see details of the error I could reach below description which is actually enough to solve the issue.

ABAP Programming Error
SAPSQL_DATA_LOSS
Data was lost while copying a value.

The current ABAP program was trying to execute an Open SQL statement and discovered that a value needs to be copied into the database field type. This copy operation resulted in data loss. Either the data could not be converted, the data in source was not long enough to fill the target, or the source was a non-character type structure. The value was "TR". The ABAP field has type "C" length 1 with 0 decimal places. The target has type "C" length 1 with 0 decimal places.

If you are an ABAP developer, you know the language field has a conversion behind like EN to E for English, TR to T for Turkish, etc. The Langu or Spras is in fact is defined as a single character in ABAP data dictionary.

On the other hand, the previously used classic ABAP syntax is flexable enough to convert the two character inputs to expected data type for the language fields. So the prior code block for ABAP Select works fine.

On the contrary, the second enhanced ABAP Open SQL syntax demands the exact data type. And if it not supplied as in this case causes a programming error resulting with ABAP dump.

ABAP SAPSQL_DATA_LOSS error is similar to SQL Server data truncate errors in a way.

Solution for the ABAP error SAPSQL_DATA_LOSS in my case is to strictly define USING parameter for language. This will enable the ABAP editor to identify possible errors beforehand.

DATA ls_vbpr TYPE vbrp.
ls_vbpr-matnr = '000000000000140586'.
DATA lv_maktx LIKE makt-maktx.

* Erroneous call method with language or spras USING parameter with TR value
*PERFORM get_material_desc USING ls_vbpr-matnr 'TR' CHANGING lv_maktx.
PERFORM get_material_desc USING ls_vbpr-matnr 'T' CHANGING lv_maktx.

* In below Form definition missing data types in USING parameter for language was causing error
*FORM get_material_desc USING piv_matnr TYPE matnr piv_lang CHANGING pcv_maktx.
FORM get_material_desc USING piv_matnr TYPE matnr piv_lang TYPE langu CHANGING pcv_maktx.

SELECT SINGLE maktx INTO @DATA(lv_maktx)
 FROM makt
 WHERE spras EQ @piv_lang
 AND matnr EQ @piv_matnr.

IF sy-subrc IS INITIAL.
 pcv_maktx = lv_maktx.
ENDIF.

ENDFORM.





SAP Tutorials

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table






Related Articles and Tutorials(http://www.kodyaz.com/sap-abap/sapsql_data_loss-abap-programming-error.aspx)
SAP Invoice Output ZZZZ is not Defined
Read Address Data using FM ADDR_GET instead of Querying ADRC Table
CALL_FUNCTION_NOT_FOUND ABAP Run Time Error
ABAP CONVT_NO_NUMBER Error on SP01 due SP01_WARN Parameter
ABAP Runtime Error ST22 Transaction using Short Dump Analysis
Prevent DYNPRO_SEND_IN_BACKGROUND Error in Background Process
ABAP READ_TEXT Function Module Error : Text xxxxx ID ZZZZ language EN not found
No function module has been generated yet
Error when accessing graphic (BDS), RC = 5
SAP Web Dynpro Service Cannot be Reached Error
Web Dynpro Component Service Syntax Error in Program
Smartform Runtime Error CX_SY_CONVERSION_NO_NUMBER
Web Dynpro Component Service Syntax Error in Program
ABAP Try Catch for exception is neither caught Code Inspector Error
ABAP Transport Error : Object CUAD ReportName is Inactive
Unlock Objects Locked in Request or Task using Transport Organizer Tools
Smartforms Program Lines Error
Convert the table using the Database Utility (SE14)
Function module is not released for the Internet
ICF service node does not exist (see SAP Note 1109215)
Window MAIN does not fit onto page PAGE (height)
Switch ABAP Variable Value with Translate using Mask
Switch ABAP Variable Value with Translate using Mask


Copyright © 2004 - 2017 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems