Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Copying ALV variants/layouts between programs

afordham
Participant
0 Likes
6,147

Hi guys,

Does anyone know how to copy ALV layouts between programs in the same client? I have created a copy of a report which uses the ALV functionality via the REUSE_* function modules. The original report has over 40 layouts, so I don't want to have to re-create them manually in the new program. These programs are in the same client on the same system, so the Import Layout and Transport Layout options aren't going to be of any use (as far as I can see...)

Any ideas greatly appreciated.

Cheers,

Andrew

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,525

hii Andrew

First call <b>LVC_VARIANT_SELECT</b> to read variant from the first program and

then call <b>LVC_VARIANT_SAVE</b> to save it for the second program.

check this demo program for more info

<b>BCALV_GRID_11</b>

Regards

Naresh

hii Andrew

First call <b>LVC_VARIANT_SELECT</b> to read variant from the first program and

then call <b>LVC_VARIANT_SAVE</b> to save it for the second program.

check this demo program for more info

<b>BCALV_GRID_11</b>

Regards

Naresh

5 REPLIES 5
Read only

Former Member
0 Likes
3,525

hi

plz refer asnwer to similar query

<b>

<b>

<b>

Read only

Former Member
0 Likes
3,525

Hi Andrew,

you can do like this..

instead of sy-repid

G_VARIANT-REPORT = sy-REPID.

use this..

repid = 'the program which is having 40 variants'.

G_VARIANT-REPORT = repid .

and but when you create new one then the new variant also saves under the original program(having 40 layouts)

i hope you got it.

Regards

vijay

Read only

0 Likes
3,524

Thanks Vijay. This will certainly help in the short term, but as you correctly point out, this will just make my new program work with the old program's variants, and any changes I make will also affect the old program.

I'm still looking for a way to copy the display variants/layouts from one program to the other so they each have their own.

Read only

Former Member
0 Likes
3,526

hii Andrew

First call <b>LVC_VARIANT_SELECT</b> to read variant from the first program and

then call <b>LVC_VARIANT_SAVE</b> to save it for the second program.

check this demo program for more info

<b>BCALV_GRID_11</b>

Regards

Naresh

Read only

Former Member
0 Likes
3,524

I took this approach and it worked for me:

1) Change your program so that everytime an ALV function is called it is using the original program name in the variant declaration, ensure you keep the original code commented out, you will need to put it back later. Examples:

FORM variant_init USING varname TYPE slis_vari.

CLEAR g_variant.

  • g_variant-report = g_repid.

g_variant-report = 'ORIGINAL_PROGRAM_NAME'.

FORM f4_for_variant.

  • g_variant-report = sy-repid.

g_variant-report = ‘ORIGINAL_PROGRAM_NAME’.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

FORM check_variant.

IF NOT p_vari IS INITIAL.

  • g_variant-report = sy-repid.

g_variant-report = ‘ORIGINAL_PROGRAM_NAME’.

g_variant-variant = p_vari.

CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

2) Display function lt_variant_save via SE37, set a breakpoint at the first executable line:

perform variant_save tables it_fieldcat

4) Run your program with the layout variant you wish to copy.

5) Hit Save Variant. You are now in debug mode.

6) Enter variable CS_VARIANT-REPORT in the variables 1 panel.

7) Double-click on CS_VARIANT-REPORT.

😎 Hit the Change Field Content button

9) Change the value to the name of your new program, then hit Enter.

10) Hit Execute (F8). You have now saved the variant under your new program name.

11) Exit and rerun your program as necessary for as many variants as you want to copy

12) Change your program back to using sy-repid (or whatever else it was referencing) wherever you changed it in step 1.

13) The variants have now been copied and you can run your program with the new variants.