Copy a layout variant

ABAP

How to quickly copy layout variant from a report to another (assuming their are compatible) ?

REPORT ZBC_LAYOUT_VARIANT_COPY.
DATA lt_ltdx LIKE ltdx OCCURS 0 WITH HEADER LINE.
DATA lt_ltdxt LIKE ltdxt OCCURS 0 WITH HEADER LINE.

PARAMETERS report1 LIKE ltdx-report OBLIGATORY.
PARAMETERS report2 LIKE ltdx-report OBLIGATORY.
"copy layout of report1 to report2.

START-OF-SELECTION.
  SELECT * INTO TABLE lt_ltdx FROM ltdx
                WHERE report = report1.
  SELECT * INTO TABLE lt_ltdxt FROM ltdxt
                WHERE report = report1.

  LOOP AT lt_ltdx.
    lt_ltdx-report = report2.
    MODIFY ltdx FROM lt_ltdx.
  ENDLOOP.

  LOOP AT lt_ltdxt.
    lt_ltdxt-report = report2.
    MODIFY ltdxt FROM lt_ltdxt.
  ENDLOOP.

  MESSAGE 'Copy Complete.' TYPE 'I'.


SAP News, tips and tricks