Application Development 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: 

dynamic variant

Former Member
0 Kudos

Hi everyone,

I need to create a dynamic variant for a batch job. There is an input date field in the abap program and when the job will run, this date field must be "the last day of month of 2 month ago".

I check in the selection variable screen for the date, but I don't see anything that be usefull for what I need.

regards

Hadrien

2 REPLIES 2

former_member1345686
Active Participant
0 Kudos

Hi Hadrien,

There is no such date in selection variable, so we have to move out of the box.

Let's say this batch job of yours ( ex: job_A ) is expected to run monthly.

You can then create a program , ex: job_B, consists of this logic :

- create selection screen entries for job_A

- calculate the last day of 2 month ago

- another check or values preparation

- submit job_A to background job using specified values defined previously

Then you could schedule this job_B to run monthly .

I hope this would help.

Rgds,

Tuwuh Sih Winedya

Former Member
0 Kudos

Hi

Look at the following Code

Please find the sample using RS_CREATE_VARIANT (FM).

It make use of other FM also , just have a look .

Hope this may help you.

REPORT ZEXAMPLE.

DATA: JVARI_DESC LIKE VARID,

RC LIKE SY-SUBRC,

VARIANT_TEXT LIKE VARIT-VTEXT,

JVT LIKE VARIT OCCURS 0 WITH HEADER LINE,

SELPA LIKE RSPARAMS OCCURS 0 WITH HEADER LINE,

PARMS LIKE RSPARAMS OCCURS 0 WITH HEADER LINE,

OBJS LIKE VANZ OCCURS 0 WITH HEADER LINE.

PARAMETERS: P_VAR LIKE RSVAR-VARIANT. "NAME OF VARIANT

JVARI_DESC-REPORT = SY-REPID.

JVARI_DESC-VARIANT = P_VAR.

JVARI_DESC-ENAME = 'EXAMPLES'.

JVT-REPORT = SY-REPID.

JVT-VARIANT = P_VAR.

JVT-LANGU = SY-LANGU.

JVT-VTEXT = 'FUNCTION EXAMPLES'.

APPEND JVT.

CLEAR SELPA.

SELPA-SIGN = 'I'.

SELPA-OPTION = 'EQ'.

SELPA-KIND = 'P'.

SELPA-SELNAME = 'P_VAR'.

SELPA-LOW = P_VAR.

APPEND SELPA.

  • CHECK IF VARIANT EXISTS

CALL FUNCTION 'RS_VARIANT_EXISTS'

EXPORTING

REPORT = JVARI_DESC-REPORT

VARIANT = P_VAR

IMPORTING

R_C = RC

EXCEPTIONS

NOT_AUTHORIZED = 1

NO_REPORT = 2

REPORT_NOT_EXISTENT = 3

REPORT_NOT_SUPPLIED = 4

OTHERS = 5.

IF RC = 0 AND SY-SUBRC EQ 0.

  • DELETE OLD VARIANT

CALL FUNCTION 'RS_VARIANT_DELETE'

EXPORTING

REPORT = JVARI_DESC-REPORT

VARIANT = P_VAR

FLAG_CONFIRMSCREEN = 'X'

EXCEPTIONS

NOT_AUTHORIZED = 1

NOT_EXECUTED = 2

NO_REPORT = 3

REPORT_NOT_EXISTENT = 4

REPORT_NOT_SUPPLIED = 5

VARIANT_LOCKED = 6

VARIANT_NOT_EXISTENT = 7

NO_CORR_INSERT = 8

VARIANT_PROTECTED = 9

OTHERS = 10.

IF SY-SUBRC NE 0.

WRITE: 'UNABLE TO DELETE VARIANT:', P_VAR ,'STATUS=', SY-SUBRC.

EXIT.

ELSE.

WRITE:/ P_VAR, 'DELETED'.

ENDIF.

ELSE.

WRITE:/ P_VAR, 'DOES NOT EXIST'.

ENDIF. " ALREADY EXISTS

CALL FUNCTION 'RS_CREATE_VARIANT'

EXPORTING

CURR_REPORT = JVARI_DESC-REPORT

CURR_VARIANT = P_VAR

VARI_DESC = JVARI_DESC

TABLES

VARI_CONTENTS = SELPA

VARI_TEXT = JVT

EXCEPTIONS

ILLEGAL_REPORT_OR_VARIANT = 1

ILLEGAL_VARIANTNAME = 2

NOT_AUTHORIZED = 3

NOT_EXECUTED = 4

REPORT_NOT_EXISTENT = 5

REPORT_NOT_SUPPLIED = 6

VARIANT_EXISTS = 7

VARIANT_LOCKED = 8

OTHERS = 9.

IF SY-SUBRC EQ 0.

WRITE:/ 'VARIANT', P_VAR, 'CREATED FOR PROGRAM', JVARI_DESC-REPORT.

ELSE.

WRITE:/ 'VARIANT', P_VAR, 'NOT CREATED FOR PROGRAM', JVARI_DESC-REPORT.

EXIT.

ENDIF.

CALL FUNCTION 'RS_VARIANT_CONTENTS'

EXPORTING

REPORT = JVARI_DESC-REPORT

VARIANT = P_VAR

TABLES

VALUTAB = PARMS

OBJECTS = OBJS

EXCEPTIONS

VARIANT_NON_EXISTENT = 1

VARIANT_OBSOLETE = 2

OTHERS = 3.

IF SY-SUBRC NE 0.

WRITE : / 'ERROR READING VARIANT CONTENTS.'.

ELSE.

CALL FUNCTION 'RS_VARIANT_TEXT'

EXPORTING

LANGU = SY-LANGU

CURR_REPORT = JVARI_DESC-REPORT

VARIANT = P_VAR

IMPORTING

V_TEXT = VARIANT_TEXT.

WRITE:/ 'VARIANT DESCRIPTION:', VARIANT_TEXT.

LOOP AT PARMS.

CHECK PARMS-LOW NE SPACE OR PARMS-HIGH NE SPACE.

READ TABLE OBJS WITH KEY NAME = PARMS-SELNAME.

WRITE : /2 PARMS-SELNAME, OBJS-TEXT,

45 PARMS-KIND,

PARMS-SIGN,

PARMS-OPTION,

PARMS-LOW,

PARMS-HIGH.

NEW-LINE.

ENDLOOP.

SKIP.

ENDIF.

some other approach....

  • This function module selects the Selection Screen contents

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'

EXPORTING

curr_report = sy-repid

TABLES

selection_table = loc_int_tab

EXCEPTIONS

not_found = 1

no_report = 2

OTHERS = 3.

IF sy-subrc NE 0.

MESSAGE i000 WITH 'Error in RS_REFRESH_FROM_SELECTOPTIONS'(029).

LEAVE LIST-PROCESSING.

ENDIF.

  • Craete the variant VAR1

CALL FUNCTION 'RS_CREATE_VARIANT'

EXPORTING

curr_report = sy-repid

curr_variant = wf_variant

vari_desc = loc_varid

TABLES

vari_contents = loc_int_tab

vari_text = loc_varit

EXCEPTIONS

illegal_report_or_variant = 1

illegal_variantname = 2

not_authorized = 3

not_executed = 4

report_not_existent = 5

report_not_supplied = 6

variant_exists = 7

variant_locked = 8

OTHERS = 9.

IF sy-subrc <> 0.

MESSAGE i000 WITH 'Error while creating dynamic variant'(028).

LEAVE LIST-PROCESSING.

ENDIF.

<b>Reward if usefull</b>