As always, first we are going to place the call of our next setting (OPTIMIZE_COLUMN_WIDTH) in the subroutine, called INITIALIZE_ALV. As we move forward, we are going to place the call of these setting subroutines one by one under each other.
As I mentioned above, to customize the columns of an ALV, we need an instance of the class, CL_SALV_COLUMNS_TABLE that we are going to get by calling the CL_SALV_TABLE method, called GET_COLUMNS(), and save the received instance reference in a reference variable, named COLUMNS (it refers to the class, CL_SALV_COLUMNS_TABLE ).
As we get the required instance, there is nothing left, than calling its method, named SET_OPTIMIZE(). That's obvious, isn't it? We want to optimize the width of the columns, so that we call the method, SET_OPTIMIZE(). It has an optional importing bool parameter, named VALUE that is true by default.
Let's check that code! Since the importing parameter of the SET_OPTIMIZE() is true by default, we are going to call it simply without any parameter.
Before optimizing the columns width.
After optimizing the columns width. It looks better, right?
As a summary I want to show you a snapshot about the instance members of the CL_SALV_TABLE class that hopefully clarifies the architecture of this class. On the picture below, you can see many familiar class, such as CL_SALV_LAYOUT, CL_SALV_COLUMNS, and so on. The CL_SALV_TABLE stores one-one instance of these classes, and you can reach them by calling their GETTER methods, like GET_LAYOUT, GET_COLUMNS, and so on. As you get the references of these instances, you can set their properties to perform the required settings.
That's the trick of the CL_SALV_TABLE class. I hope you liked it! Next, we are going to deal with the columns again, but we are going to customize them individually.