Skip to main content

Posts

Showing posts from 2017

Compacting internal memory of SAP tables in ABAP.

How to force-free memory from deleted entries in internal tables in SAP ABAP, since the garbage collector won't touch these. This is only needed in rare occasions and/or when memory fragmentation needs to be avoided.
This method will do it fast, and correctly:
CLASS cl_demo DEFINITION.PUBLIC SECTION.CLASS-METHODS compact CHANGING ct_tab TYPE ANY TABLE.ENDCLASS.CLASS cl_demo IMPLEMENTATION.METHOD compact.FIELD-SYMBOLS:<lt_buffer>TYPE ANY TABLE,<lt_buffer_std>TYPESTANDARDTABLE,<ls_buffer>TYPE any,<ls_buffer_prev>TYPE any.DATA: ltr_buffer TYPEREF TOdata, lsr_buffer TYPEREF TOdata, l_kind TYPEc LENGTH 1." simple case:IF ct_tab IS INITIAL.FREE ct_tab. RETURN.ENDIF.CREATEDATA ltr_buffer LIKE ct_tab.DESCRIBETABLE ct_tab KIND l_kind.CASE l_kind.WHENsydes_kind-standard.ASSIGN ltr_buffer->*TO<lt_buffer_std>.<lt_buffer_std> = ct_tab." this will create/copy a new instance of the tableAPPEND INITIAL LINETO<lt_buf…

ABAP fails again, on literal/packed to numeric parameters.

Yet another ABAP packed/literal bug:

CLASS cl_test DEFINITION.PUBLIC SECTION.CLASS-METHODS test IMPORTING i_num TYPE numeric.ENDCLASS.CLASS cl_test IMPLEMENTATION.METHOD test.WRITE:/ i_num.ENDMETHOD.ENDCLASS.START-OF-SELECTION.DATA: l_f TYPEdecfloat34." This works correctly: l_f = '10.1231231233'. l_f = '10.12312312334234234'. l_f = '10.12312312334234234345345'." This has some kind of MOD overflow error on packed's maximum decimals of 16: cl_test=>test('10.1231231233')." OK: "10.1231231233" P(16) DECIMALS 10 cl_test=>test('10.12312312334234234')." FAIL: "10.1" P(16) DECIMALS 1 cl_test=>test('10.12312312334234234345345')." FAIL: "10.1231231" P(16) DECIMALS 7