Abap Tricks and Tips: Select Where VS Select + Check
Abap Tricks and Tips: Select Where VS Select + Check
LOGON TO ABAPLOVERS.BLOGSPOT.COM
If you are interested if there exists at least one row of a database table or view with a certain condition, use the Select Single statement instead of a Select-Endselect-loop. Select Single requires one communication with the database system, whereas Select-Endselect needs two.
It is always faster to use the Into Table version of a Select statement than to use Append statements.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
LOGON TO ABAPLOVERS.BLOGSPOT.COM
LOGON TO ABAPLOVERS.BLOGSPOT.COM
For all frequently used, read-only tables, try to use SAP buffering. Network load is considerably less.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Column Update
SELECT * FROM SFLIGHT INTO SFLIGHT_WA. SFLIGHT_WA-SEATSOCC = SFLIGHT_WA-SEATSOCC - 1. UPDATE SFLIGHT FROM SFLIGHT_WA. ENDSELECT. VS
Whenever possible, use column updates instead of single-row updates to update your database tables. Network load is considerably less.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Use the special operators CO, CA, CS, instead of programming the operations yourself. If ABAP/4 statements are executed per character on long strings, CPU consumption can rise substantially.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
VS
CONCATENATE T100_WA-ARBGB T100_WA-MSGNR T100_WA-TEXT INTO CLA.
Some function modules for string manipulation have become obsolete and should be replaced by ABAP/4 statements or functions: STRING_CONCATENATE... -> CONCATENATE, STRING_SPLIT... -> SPLIT, STRING_LENGTH -> strlen(), STRING_CENTER -> WRITE...TO...CENTERED, STRING_MOVE_RIGHT -> WRITE...TO...RIGHT-JUSTIFIED ________________________________________________________________________
LOGON TO ABAPLOVERS.BLOGSPOT.COM
VS
* MOVE 'Jane' TO CMA. * MOVE 'Miller' TO CMB. * MOVE 'New York City' TO CMC. CONCATENATE 'Mrs.' CMA CMB 'from' CMC INTO CHA SEPARATED BY SPACE. * Mrs. Jane Miller from New York City" is the final value of CHA.
Use the CONCATENATE statement instead of programming a string concatenation of your own.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
* CLA contains the string * ' "Editor line n'. IF CLA CN SPACE. ENDIF. SHIFT CLA BY SY-FDPOS PLACES LEFT. VS * CLA contains the string * ' "Editor line n'.
SHIFT CLA LEFT DELETING LEADING SPACE. If you want to delete the leading spaces in a string, use the ABAP/4 statement SHIFT...LEFT DELETING LEADING... .Other constructions (with CN and SHIFT...BY SY-FDPOS PLACES, with CONDENSE if possible, with CN and ASSIGN CLA+SY-FDPOS(LEN) ...) are not as fast. In any case, avoid using SHIFT inside a WHILE-loop!
LOGON TO ABAPLOVERS.BLOGSPOT.COM
VS
* CMA contains '(410)-45174-66354312' and shall be * split into AREA_CODE, * TEL_NO1, * TEL_NO2. SPLIT CMA AT '-' INTO AREA_CODE TEL_NO1 TEL_NO2.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
* DATA: BEGIN OF STR, LINE TYPE X, END OF STR, * CHECK_SUM TYPE I. * MOVE 'KALEBVPQDSCFG' TO CLA.
DO 64 TIMES VARYING STR FROM CLA NEXT CLA+1. CHECK STR NE SPACE. ADD STR-LINE TO CHECK_SUM. ENDDO.
VS
* DATA: BEGIN OF STR, LINE TYPE X, END OF STR, * CHECK_SUM TYPE I. * MOVE 'KALEBVPQDSCFG' TO CLA. I1 = STRLEN( CLA ). DO I1 TIMES VARYING STR FROM CLA NEXT CLA+1. CHECK STR NE SPACE. ADD STR-LINE TO CHECK_SUM. ENDDO. Use the strlen( ) function to restrict the DO loop to the relevant part of the field, e.g. when determinating a check-sum.
LOGON TO ABAPLOVERS.BLOGSPOT.COM
Use "CLEAR f WITH val" whenever you want to initialize a field with a value different from the field's typespecific initial value.
LOGON TO ABAPLOVERS.BLOGSPOT.COM