Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
kasralikarpratik
Explorer
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 

Step 1:
  CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = GREF_TABLE
CHANGING T_TABLE = IM_TABLE ).

Step 2:
GREF_TABLE->DISPLAY( ).

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 ).

Conclusion:

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.
14 Comments
hardyp180
Active Contributor
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.
Mithun_Kumar
Active Participant
0 Kudos
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...
hardyp180
Active Contributor
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.

https://blogs.sap.com/2020/02/08/international-editable-salv-day-2020/
matt
Active Contributor
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.
shais
Participant
Welcome to the year 2022 😉
Sandra_Rossi
Active Contributor
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.
abo
Active Contributor
Somehow I think this will be released the day you retire, just because 😄
hatrigt
Participant
Another new blog out of already existing 100s of blogs explaining the same several years older SALV class. Kindly search before creating a blog.
sas70
Explorer
0 Kudos
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
leike
Discoverer
0 Kudos
Hi, do you know how to cycle?

I want to loop through all the columns and loop through this object? CL_ SALV_ COLUMNS_ TABLE

C#
for(int i = 0; i<columns.COUNTS;i++)
{
columns[i].name = 'AA';
}
vitpilk
Participant
0 Kudos

GREF_TABLE did not work for me either. I played around a bit with a few options and ended up with the code below. One can use SFLIGHT table or any of the "flight set of tables" instead of SPFLI. It worked for me in ADT (connected to my local SAP ABAP NW 7.52 S04 Developer Edition). I guess if one copies the code below into a new program in ADT it should run without issues.

SELECT * FROM spfli INTO TABLE @DATA(itab).

cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lref_cl_alv)
CHANGING t_table = itab ).

lref_cl_alv->display( ).
vitpilk
Participant
0 Kudos
One never knows which of those 100s appears at the top of one's search. As long as these 100s of blogs are accurate and the content is well-explained, it surely does not hurt me if there are 100s of them or even more 😉 As long as there's something to learn from them, let there be more ! 🙂
vitpilk
Participant
0 Kudos
As far as I understand, this blog is about using cl_salv_table to display an internal table, not to loop through it. The code snippet you supplied appears to be in C#, not in ABAP. In ABAP you can use LOOP AT [internal table] into [structure or work area] ...... END LOOP. Hope this helps.
kasralikarpratik
Explorer
0 Kudos
It is reference to CL_SALV_TABLE. you can use DATA(GREF_TABLE).
Labels in this area