Copyright 2024 - BV TallVision IT

Sometimes it can be useful to have a default variant for a report. The transaction variant can help you there, where a transaction is linked to a report + variant (see more on this in atricle Variants). Or the SUBMIT is used.

Reports can be submitted with a variant, so if your report was just started and you have a default variant you like to use, simply re-SUBMIT it. Here's a simple setup on how to do this:

REPORT ZABAPCADABRA_VARIANTREADER.

TABLES pernr.
INFOTYPES 0001.

*-------------------------------------
INITIALIZATION.

* When a transaction is set up for this report and the report
* was started using the transaction, the existance of a variant
* with the same name as the transaction is checked. If such
* variant is available, it is regarded as the default variant
* and the report is re-started using this variant.
  IF sy-batch = space and     "Not run as batch job
    sy-tcode(1) co 'YZ'and    "Started via Y or Z transaction
    sy-slset <> sy-tcode.     "Current variant <> transaction code
* Check: variant with the name of the transaction available ?
    data: lw_varid type varid.

    select single * from varid into lw_varid
      where report = sy-repid and
            variant = sy-tcode and
            flag1 = space and
            flag2 = space.
     IF sy-subrc = 0.
* A variant exists, restart the report for this variant:
       message 'Variant automatically picked up' type 'S'.
       SUBMIT (lw_varid-report)
         USING SELECTION-SET lw_varid-variant
         VIA SELECTION-SCREEN.
     ENDIF.
   ENDIF.

*-------------------------------------
GET pernr.

*-------------------------------------
END-OF-SELECTION.
  write: / 'Whatever needs to be written'.

The example uses a PNP logcal database, which has an enormous set of selection parameters. The concept also works with simple reports, as long as they have a selection screen. Note that this logic can be linked to e.g. a transaction code: if your report started with transaction code ZHRI_CONCUR could check the existance of variant CONCUR, and automatically restart.

Note that a variant can be filled in as a default when a transaction is created. The difference between doing that and the above setup is that pre-filled variants will have to exist as "System variant". System variants are transported through the landscape and are easier to protect from changes. As with many themes: the choice is yours.