Filter not working in ALV GRID

If you have not mentioned reftable or reffield for a field during building of field catalog , this may happen.

Filter not working in ALV grid
Filter not working in ALV grid
OR

If you use primitive data types (like C,I,N etc) ;, then also you may face problem of filtering not working.

The solution(s) to this problem are
 1. Specify reftable and reffield for a field.
Ex: Reftable can be MARA ref field can be MATNR for MATNR field
wa_fieldcat-ref_tabname =mara
wa_fieldcat-ref_fieldname =matnr

2. Specify OUTPUTLEN to the limit of primitive data types
Ex:
wa_fieldcat-outputlen = '40'.