I have an ALV list as an output of the program and need to be able to dynamically get / fetch the columns and their positions.
The users can also save the columns / positions as a layout for future use and I want to get this information for the saved layouts.
I am expecting to get the columns and their positions of an ALV list as an internal table, to use it further, for example, to generate .xls file.
You can achieve it in the way described below. I wrote a sample code snippet with comments. Basically the starting table is
LTDX.First read the layouts for the program using FM
LT_VARIANTS_READ_FROM_LTDX. ReplaceREPORT_NAME_REPLACEwith your program name of interest. Additionally you can filter layouts for specific user(s) - uncomment lines with range tablelt_r_unameand replaceLOGIN_REPLACEwith your login.Next for the found layout(s) read the data - basic field catalog - with FM
LT_DBDATA_READ_FROM_LTDXand afterwards the field catalog itself with FMLT_FC_LOAD.The internal table lt_fcat contains columns of the layout: component fieldname the name of the column and col_pos its position. I filtered out from the internal table the columns which have parameter NO_OUT = 'X' and therefore are not displayed in the layout.