Display ALV Grid in very few lines of code
There are many way’s to display ALV. Either using REUSE_ALV function modules or CL_GUI_ALV_GRID class. But these methods somehow doesn’t give you easy option to display internal table directly in ALV format. You need to either build field catalog, layouts and sometime custom containers.
If you want to display the ALV with many other functionalities like adding buttons/ events and also editable options you may need to write some more logic but Most of the requirements are just to display the result and not doing much. For example, displaying log or normal report to show material data or customer data. in these scenario’s below logic will help you.
The option i am using here is CL_SALV_TABLE.
Here you go
CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = GREF_TABLE CHANGING T_TABLE = IM_TABLE ).
That’s it. It will show you result in ALV format. Here GREF_TABLE refers to CL_SALV_TABLE
In this case it will take the data element field labels will be used as it is to display the ALV. In most of the scenario’s it will be the same. If you want to change the column you can definitely do it using CL_SALV_COLUMNS_TABLE and CL_SALV_COLUMN
DATA(GREF_COLUMNS) = GREF_TABLE->GET_COLUMNS( ). DATA(GREF_COLUMN) = GREF_COLUMNS->GET_COLUMN( COLUMNNAME = 'COLUMN NAME' ). GREF_COLUMN->SET_SHORT_TEXT( 'COLUMN SHORT TEXT' ). GREF_COLUMN->SET_MEDIUM_TEXT( 'COLUMN MEDIUM TEXT' ). GREF_COLUMN->SET_LONG_TEXT( 'COLUMN LONG TEXT' ).
You can also set status for your ALV report
GREF_TABLE->SET_SCREEN_STATUS( EXPORTING REPORT = 'SAPLKKBL' PFSTATUS = 'STD_LIGHT_FULLSCREEN' SET_FUNCTIONS = GREF_TABLE->C_FUNCTIONS_ALL ).
You can use many way’s to display the report but this one I felt the easiest approach to display ALV with very few lines of code.
See you all in next post.
It is nice that you are bringing CL_SALV_TABLE to peoples attention.
However I would note that class was created over fourteen years ago, circa 2006 as I recall.
In 2006 Facebook started. And Twitter. You don't get many blogs in 2022 trying to explain to people what those two new things are. However I understand ABAP world works a little bit differently.
Anyway, if an ABAP programmer has not heard of CL_SALV_TABLE in the last fourteen years what exactly have they been doing? If the answer is they are still using the function module REUSE_ALV_GRID for new projects I am going to burst into tears. Sadly that is probably exactly what has been happening. They might even still be using WRITE statements and using the HIDE command to see what line the user has clicked on.
True actually... 😉
Seeing the blog title even I thought it's about the new ALV with IDA.... but was a bit disappointed to see the basics of SALV class...
Just take a look at the questions. Plenty of programmers still using the function modules for ALV. And for sending emails. Some are still using Forms, and consider methods and classes to be new fangled ideas that will never catch on.
Even the SALV with IDA is about five years old.
I was thinking just now that if someone wanted to post a blog about a technology which was over ten years old and which nobody had heard about yet then maybe ABAP2XLSX should be the subject.
And since we are on the subject of CL_SALV_TABLE I would of course mention that you cannot have an editable grid like you can with CL_GUI_ALV_GRID.
I have been posting blogs about this for the last twelve years e.g.
Somehow I think this will be released the day you retire, just because 😀
Welcome to the year 2022 😉
Thanks. Sometimes repetition is welcome. Even if other people have already posted the same kind of blog post (Easily display your internal table – Method display_data using cl_salv_table | SAP Blogs), almost every day there is a question in the forum about obsolete REUSE_ALV_GRID_DISPLAY, CL_GUI_ALV_GRID and so on. So we can answer the author to use CL_SALV_TABLE and link to your short post.
Completely agreed with you Sandra. I am surprised of the tone of some comments above. Your post saved my day and alerted me to the new way ALV concepts as I am new to the ABAP world, coming from a web development side. I do have a trivial question though: how can i make your code run without errors as I get that the field GREF_TABLE is unknown? Many Thanks
Another new blog out of already existing 100s of blogs explaining the same several years older SALV class. Kindly search before creating a blog.
Hi, do you know how to cycle?
I want to loop through all the columns and loop through this object? CL_ SALV_ COLUMNS_ TABLE
for(int i = 0; i<columns.COUNTS;i++)
columns[i].name = 'AA';