How to insert and delete column in SAP ALV Display of type CL_SALV_TABLE.

The column is inserted through the field catalog of the ALV Table. It is set during the method call FACTORY ().

Step1: Extend the structure either locally or globally through the Transaction SE11 with the additional field.

TYPES: BEGIN OF ty_contact.

                            INCLUDE STRUCTURE ztt_db_table2.

                            TYPES: contact_age TYPE ZDE_contact_age.

              END OF ty_contact.

DATA lt_contact TYPE STANDARD TABLE OF ty_contact.

              It is always recommended to use an unique Data element for the fields of the structure, so that the column heading text can be easily maintained.

Step2: Call the Factory() Method of class CL_SALV_TABLE

CALL METHOD cl_salv_table => factory

              IMPORTING

                            r_salv_table = lr_alv_object

              CHANGING

                            t_table = lt_contact.

Through the field catalog of the ALV Table, a new column can be inserted or deleted.

There is a method REMOVE_COLUMN() for the column class ‘CL_SALV_COLUMN_TABLE’. But it is protected. Therefore the inheritance is needed to remove the column.

How to delete a column from the SAP ALV List

The column can be deleted from the SAP ALV List using the field catalog. Column deletion is constrained based on the fieldname of the field catalog.

Let us look at the following example:

DELETE lt_field_cat WHERE fieldname = ‘Contact_address’.

Once it is deleted through the field catalog, it cannot be further added using the layout button of the toolbar.

How to Delete records from the internal table in SAP ABAP

The Data records present in the internal table can be deleted in following ways.

  • Key or work area (structure)
  • WHERE conditions.
  • Index
  • From Index TO Index
  • Clean, Refresh, free

DATA lt_internal_table TYPE TABLE OF ztt_db_table2.

DATA ls_structure TYPE ztt_db_table2.

SELECT *FROM ztt_db_Table2 INTO TABLE lt_internal_table.

              ls_structure – contact_id = 102.

              ls_structure – contact_name = ‘Thiru’.

              ls_structure – contact_address = ‘Street 10’.

Key or Work Area:

DELETE TABLE lt_internal_Table FROM ls_structure.

Only for key or structure, ‘TABLE’ is written explicitly after DELETE in the syntax.

WHERE:

DELETE lt_internal_table WHERE contact_id = 102.

INDEX:

DELETE lt_internal_table INDEX 2.

FROM INDEX TO INDEX:

DELETE lt_internal_table FROM 2 TO 3.

If the deletion is successful, then the system field sy-subrc will hold the value 0. If it is not successful, it will hold the value 4.