Debugging Internal Tables and Field Symbols
Debug internal table reads, loops, field symbols and missing/incorrect row updates.
Explanation
Many ABAP bugs are caused by internal table handling. Common issues include READ TABLE not finding data, sy-subrc not checked, wrong key used, field symbol not assigned, work area changed but internal table not modified, or DELETE/MODIFY inside LOOP causing unexpected behavior. In debugger, check the table content, key fields, sy-subrc, sy-tabix and whether the code uses INTO or ASSIGNING. If LOOP INTO is used, changes happen to a copy and need MODIFY. If ASSIGNING is used, changes affect the actual row. A senior debugger quickly identifies whether the bug is due to missing data, wrong key, stale work area or incorrect row update pattern.
Code example
* Bug pattern:* Status is changed in work area, but internal table is not updated. LOOP AT gt_upload INTO DATA(ls_upload). IF ls_upload-matnr IS INITIAL. ls_upload-status = 'E'. ls_upload-message = 'Material missing'. * Debugging point: * LS_UPLOAD changed, but GT_UPLOAD row is still unchanged unless MODIFY is used. ENDIF. ENDLOOP. * Correct pattern 1: Use MODIFY when LOOP INTO is usedLOOP AT gt_upload INTO ls_upload. IF ls_upload-matnr IS INITIAL. ls_upload-status = 'E'. ls_upload-message = 'Material missing'. MODIFY gt_upload FROM ls_upload TRANSPORTING status message. ENDIF. ENDLOOP. * Correct pattern 2: Use ASSIGNING for direct row updateLOOP AT gt_upload ASSIGNING FIELD-SYMBOL(<ls_upload>). IF <ls_upload>-matnr IS INITIAL. <ls_upload>-status = 'E'. <ls_upload>-message = 'Material missing'. ENDIF. ENDLOOP.Real project scenario
An upload report marks rows as successful, but ALV still shows old status. Debugging shows the code used LOOP INTO work area and changed the work area without MODIFY.
Common mistakes
- Changing work area but forgetting MODIFY. - Not checking sy-subrc after READ TABLE. - Using wrong key in READ TABLE. - Using unassigned field symbols.
Best practices
- Check table content in debugger. - Check key values before READ TABLE. - Check sy-subrc immediately. - Use ASSIGNING for direct updates. - Use MODIFY TRANSPORTING for selected field updates.
Interview angle
Interviewers often give code snippets where internal table is not updated. Explain copy vs reference and how to debug it.