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

creating a variant

Former Member
0 Likes
1,329

hi guys,

i have a module pool program which needs to be created . using the set pf-status i have created a save button.but the requirement is that when we click the save button a variant needs to be created that saves the values that are present in the selection screen.kindly help me out if there are any function modules or anything else that can help serve my purpose.i have been on it for a few days now.

8 REPLIES 8
Read only

Former Member
0 Likes
989

Hi anup,

Welcome to SDN.

1. u can try this fm

RS_VARIANT_SAVE_FROM_SELSCREEN

Regards,

amit m.

Read only

athavanraja
Active Contributor
0 Likes
989

Welcome to SDN.

for creating variants programatically you can use FM

RS_CREATE_VARIANT.

But you cannot create variants for module pool programs.

Raja

Read only

0 Likes
989

HI Nath,

Use FM RS_CREATE_VARIANT ...

Regards,

Santosh

Read only

Former Member
0 Likes
989

Hi,

Try to insert the data in table TVARV. Please check it once.

Read only

vinod_gunaware2
Active Contributor
0 Likes
989

Hi

Use below function module for variant operation

RS_CREATE_VARIANT Creating a variant (not using a selection screen)

RS_VARIANT_CATALOG Returns variant directory for a report in an internal table

RS_VARIANT_EXISTS Checks whether variant exists

RS_VARIANT_TEXT Returns text for a variant

regards

vinod

Read only

0 Likes
989

Hi,

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.

Cheers

Sunny

Read only

0 Likes
989

hi

I used the FM rs_create_variant, as per the code. when i executed it asked me to specify the program name.

what should be done?

Regards

Naga

Read only

christian_wohlfahrt
Active Contributor
0 Likes
989

Hi Arup!

Maybe it is easier to create a report, which calls a screen. Then selection screen and variants are handled automatically by SAP.

If you absolutely need a module pool, you might call this with a 'call transaction ... skip first screen' after start-of-selection. By this you can fill the values from the report selection screen and user sees only second screen of module pool program

Regards,

Christian