This recipe is comprised of two subrecipes:
We will see how the personnel number (PERNR
) column may be set as key with blue colour. In addition, how a particular column Amount, where a zero amount is shown as 0.00, may be made to appear blank.
For making the above adjustments, proceed as follows:
cl_salv_column_table
.get_column
method of the mycolumns
object pointing to the columns of the ALV in order to get the reference to the column PERNR
. We will then use the set_key
method to set the PERNR
column as the key column.get_column
method is called for the Amount column BET01
. The set_zero
method is called to convert the zeros to blanks while outputting the BET01
column. It is necessary that the value space (' '
) is passed to the set_zero
method.mycolumns
statement followed by the factory
method call
.We already had the reference to the entire set of ALV columns within the variable mycolumns
. For each of the two columns, PERNR
and BET01
, the single column object reference was required. This was done through usage of the get_column
method. Methods set_key
and set_zero
were then called and appropriate values passed for parameters (if necessary) for setting the key column and removal of zeros respectively.
Any exception raised due to wrong name supplied to the get_column
method is caught using the TRY .. ENDTRY
and CATCH
statements. The exception that was addressed was CX_SALV_NOT_FOUND
. We can add a suitable MESSAGE
statement after the catch
statement to output a message in case an error arises, which is not been shown in the previous screenshot:
Note the change in the PersNo. and the Amount column.
18.216.88.54