Skip to Content
Oct 31, 2018 at 04:43 PM

Changing column order in SALV report and maintainability


Dear Gurus, Wizards, Clerics of Level 5 and beyond, and other SAP Community members!

We have an SALV report that includes information about two different sales document types and some related fields. "As is" situation: 3 structures are defined, one for each document type (let's call those VBAK_A and VBAK_B) and third one for miscellaneous fields. There is a SELECT with JOIN on 2 VBAKs and Z table that connects the documents by number. This reads the data into an internal table defined using the first two structures. Then the rest of the data is added and at the end using MOVE-CORRESPONDING the whole shebang is placed into the final ALV table.

This works perfectly for adding new fields. Just add it to the respective structure then to SELECT and be done with it. But, of course, the users ruin everything.

Now the end users want to add some related delivery fields (which are in LIKP/LIPS) and they're adamant those fields must be placed in the middle of VBAK fields. If I add those fields to the VBAK_A / VBAK_B structures then that messes up SELECT mentioned above. (Can't use SELECT INTO CORRESPONDING because I'm selecting from two VBAKs using aliases and field names in the structure also have to be different, like A_VKORG and B_VKORG.)

So the question is: how to re-order the columns while keeping the report as simple to maintain as possible? Below are the options I came up with, none is perfect, so still looking for alternatives. Keep in mind this is 7.31 version (no CDS views and such).
1. Tell the users to take a hike and use a layout - tried and this wasn't met with great enthusiasm by the users.
2. Change the definition of final ALV internal table to put the fields in the order the users want. This would mean that going forward we would also have to add new fields to yet another structure. Was hoping to avoid this.
3. Use SET_COLUMN_POSITION method (like mentioned here) before displaying ALV. But this would mean always assigning column numbers manually, so much worse than previous option.
4. Put the fields in the right order in the current structures and in SELECT use "AS..." for the fields - tried and it makes SELECT so terribly long that ABAP Editor can't even handle it and starts freezing with some C parser error.