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: 

create Dynamic variant for date field

Former Member
0 Kudos

Hello all,

I need to have the current month year displayed in my selection screen in format MM.YYYY and the field is of type SPMON (Period to analyze - month).

and while saving the variant it is showing only 'T' (entries from TVARVC table) in "selection variable" field and not showing 'D' (Dynamic selection) for the above field.

So,please help me in resolving this issue.

Thanks in advance.

3 REPLIES 3

Former Member
0 Kudos

Hi,

you can maintan tvarv/tvarvc via job changing values needed monthly. (basically create program that sets value in tvarvc table and run it in a job as a first thing when a month starts). i suppose u did try to green tick 'D' option on 'choose variant variables for variant input'.

hope it helps,

regards,

zlatko

0 Kudos

Hello Zlatko Stracenski ,

Thanks for the reply,do you mean to say that to create a job which should be run every month to update the values in tvarv table for the parameter from which we are picking the current month.

If this is the case then it might be difficult for the user to execute it every month to update the values and after that running his report.

This may not be acceptable is there any other alternative

if so please give me a bit detailed description for this.

thanks

Former Member
0 Kudos

hi

good

go through this code,i hope this ll help you to create the dynamic variant.

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.

reward point if helpful.

thanks

mrutyun^