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: 

Do you know the function module to create variants?

Former Member
0 Kudos

To automate the setting of variants on the selection-screens, I'd like to make some tool program to create variants.

I'd appreciate if you could tell me some function module(or any other methods) to create variants.

Thank you in advance for your information.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You would find useful FMs in the following link:

http://www.sapdevelopment.co.uk/fmodules/fmssap.htm

FASU_V_CREATE_VARIANT_RFC ASU: Create variant

FASU_RS_CREATE_VARIANT create variant (w/o selection screen) - client dependent

FASU_RS_CHANGE_CREATED_VARIANT change variant w/o selection screen - client dependent

Sample Program:

REPORT z_co99_cji5

NO STANDARD PAGE HEADING

MESSAGE-ID 00

LINE-SIZE 290.

*----


  • PROGRAM : Z_CO99_CJI5 *

  • TITLE : CJI5 In Background *

  • AUTHOR. : Raja Nesanoor *

  • DATE WRITTEN : 27-Feb_2007 *

  • REVTRAC : xxxxxx *

----


  • PROGRAM FUNCTION: *

  • To DISPLAY CJI5 Report in background *

----


  • PROGRAM TYPE : Executable program *

  • DEV. CLASS : XXXXXX *

  • LOGICAL DB : NA *

----


  • AUHTORIZATION CHECKS *

  • Object Authorization Fields ABAP Fields *

  • S_TCODE *

  • BUKRS v_BUKRS *

----


  • CHANGE HISTORY *

  • Date Id Name Indicator Description *

  • *

----


.

DATA : v_repid LIKE sy-repid VALUE 'ZRKPEP005' ,

v_variant LIKE varid-variant VALUE 'V_CJI5' .

DATA: BEGIN OF w_varid.

INCLUDE STRUCTURE varid.

DATA: END OF w_varid.

DATA: BEGIN OF i_rsparams OCCURS 10.

INCLUDE STRUCTURE rsparams.

DATA: END OF i_rsparams.

DATA: BEGIN OF i_rsparams1 OCCURS 10.

INCLUDE STRUCTURE rsparams.

DATA: END OF i_rsparams1.

DATA: BEGIN OF i_varit OCCURS 2.

INCLUDE STRUCTURE varit.

DATA: END OF i_varit.

DATA: BEGIN OF i_vscreens OCCURS 2.

INCLUDE STRUCTURE rsdynnr.

DATA: END OF i_vscreens.

&----


  • start-of-Selection

&----


START-OF-SELECTION.

SET PARAMETER ID 'CAC' FIELD 'GC10'.

SET PARAMETER ID 'PDB' FIELD '000000000001'.

PERFORM populate_var_table.

PERFORM create_variant.

PERFORM submit_cji5.

&----


*& Form POPULATE_VAR_TABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM populate_var_table .

CLEAR w_varid .

REFRESH i_varit .

REFRESH i_rsparams .

i_rsparams-selname = 'CN_NETNR'.

i_rsparams-kind = 'S'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = '90273536'.

i_rsparams-high = space.

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'CN_NETNR'.

i_rsparams-kind = 'S'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = '90274010'.

i_rsparams-high = space.

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'R_OBDAT'.

i_rsparams-kind = 'S'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'BT'.

i_rsparams-low = space .

i_rsparams-high = space.

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'P_DISVAR'.

i_rsparams-kind = 'P'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = '1SAP' .

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'P_USEDB'.

i_rsparams-kind = 'P'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = SPACE.

APPEND i_rsparams.

w_varid-mandt = sy-mandt.

w_varid-report = v_repid.

w_varid-variant = v_variant.

w_varid-flag1 = space.

w_varid-flag2 = space.

w_varid-transport = space.

w_varid-environmnt = 'A'. "Variant for batch and online

w_varid-protected = space.

w_varid-secu = space.

w_varid-version = '0'.

w_varid-ename = sy-uname.

w_varid-edat = sy-datum.

w_varid-etime = sy-uzeit.

w_varid-aename = space.

w_varid-aedat = space.

w_varid-aetime = space.

w_varid-mlangu = sy-langu.

i_varit-mandt = sy-mandt.

i_varit-langu = sy-langu.

i_varit-report = w_varid-report.

i_varit-variant = w_varid-variant.

i_varit-vtext = 'CO99-OUTPUT'.

APPEND i_varit.

ENDFORM. " POPULATE_VAR_TABLE

&----


*& Form CREATE_VARIANT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM create_variant .

data: h_rc like sy-subrc.

*Check variant exists.

CALL FUNCTION 'RS_VARIANT_EXISTS'

EXPORTING

report = v_repid

variant = v_variant

IMPORTING

R_C = h_rc

EXCEPTIONS

not_authorized = 01

no_report = 02

report_not_existent = 03

report_not_supplied = 04.

IF h_rc = 0.

CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'

EXPORTING

curr_report = v_repid

curr_variant = v_variant

vari_desc = w_varid

TABLES

vari_contents = i_rsparams

vari_text = i_varit

EXCEPTIONS

illegal_report_or_variant = 01

illegal_variantname = 02

not_authorized = 03

not_executed = 04

report_not_existent = 05

report_not_supplied = 06

variant_doesnt_exist = 07

variant_locked = 08

selections_no_match = 09.

COMMIT WORK.

ELSE.

CALL FUNCTION 'RS_CREATE_VARIANT'

EXPORTING

curr_report = v_repid

curr_variant = v_variant

vari_desc = w_varid

TABLES

vari_contents = i_rsparams

vari_text = i_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.

COMMIT WORK.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

ENDFORM. " CREATE_VARIANT

&----


*& Form submit_cji5

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM submit_cji5 .

CALL FUNCTION 'SUBST_START_REPORT_IN_BATCH'

EXPORTING

iv_jobname = 'TEST_JOB'

iv_repname = v_repid

iv_varname = v_variant

iv_authcknam = sy-uname

iv_language = sy-langu

iv_varianttext = 'CO99-OUTPUT'

TABLES

tt_reportparam = i_rsparams

EXCEPTIONS

variant_exist_check_failed = 1

variant_update_failed = 2

variant_update_not_authorized = 3

variant_update_no_report = 4

variant_update_no_variant = 5

variant_update_variant_locked = 6

variant_insert_failed = 7

variant_insert_not_authorized = 8

variant_insert_no_report = 9

variant_insert_variant_exists = 10

variant_insert_variant_locked = 11

variant_write_failed = 12

no_batch_service = 13

no_server_list = 14

batch_scheduling_failed = 15

OTHERS = 16.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM.

Regards,

Srilatha.

8 REPLIES 8

Former Member
0 Kudos

hi,

For ALV

REUSE_ALV_DEFAULT_VARAINT -to get a variant

REUSE_ALV_f4_VARIANT-to get list of variants

0 Kudos

Hi,

CALL FUNCTION 'RS_VARIANT_EXISTS' - check whether exists or not.

CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT' - update existing variant

CALL FUNCTION 'RS_CREATE_VARIANT' - create variant.

Regards,

GURU

0 Kudos

the question was not for ALV but for selection screen.

0 Kudos

Hi,

Check FM FASU_RS_CREATE_VARIANT.

Search in SE37 for createvariant*.

Regards,

Sesh

Former Member
0 Kudos

Hi,

You would find useful FMs in the following link:

http://www.sapdevelopment.co.uk/fmodules/fmssap.htm

FASU_V_CREATE_VARIANT_RFC ASU: Create variant

FASU_RS_CREATE_VARIANT create variant (w/o selection screen) - client dependent

FASU_RS_CHANGE_CREATED_VARIANT change variant w/o selection screen - client dependent

Sample Program:

REPORT z_co99_cji5

NO STANDARD PAGE HEADING

MESSAGE-ID 00

LINE-SIZE 290.

*----


  • PROGRAM : Z_CO99_CJI5 *

  • TITLE : CJI5 In Background *

  • AUTHOR. : Raja Nesanoor *

  • DATE WRITTEN : 27-Feb_2007 *

  • REVTRAC : xxxxxx *

----


  • PROGRAM FUNCTION: *

  • To DISPLAY CJI5 Report in background *

----


  • PROGRAM TYPE : Executable program *

  • DEV. CLASS : XXXXXX *

  • LOGICAL DB : NA *

----


  • AUHTORIZATION CHECKS *

  • Object Authorization Fields ABAP Fields *

  • S_TCODE *

  • BUKRS v_BUKRS *

----


  • CHANGE HISTORY *

  • Date Id Name Indicator Description *

  • *

----


.

DATA : v_repid LIKE sy-repid VALUE 'ZRKPEP005' ,

v_variant LIKE varid-variant VALUE 'V_CJI5' .

DATA: BEGIN OF w_varid.

INCLUDE STRUCTURE varid.

DATA: END OF w_varid.

DATA: BEGIN OF i_rsparams OCCURS 10.

INCLUDE STRUCTURE rsparams.

DATA: END OF i_rsparams.

DATA: BEGIN OF i_rsparams1 OCCURS 10.

INCLUDE STRUCTURE rsparams.

DATA: END OF i_rsparams1.

DATA: BEGIN OF i_varit OCCURS 2.

INCLUDE STRUCTURE varit.

DATA: END OF i_varit.

DATA: BEGIN OF i_vscreens OCCURS 2.

INCLUDE STRUCTURE rsdynnr.

DATA: END OF i_vscreens.

&----


  • start-of-Selection

&----


START-OF-SELECTION.

SET PARAMETER ID 'CAC' FIELD 'GC10'.

SET PARAMETER ID 'PDB' FIELD '000000000001'.

PERFORM populate_var_table.

PERFORM create_variant.

PERFORM submit_cji5.

&----


*& Form POPULATE_VAR_TABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM populate_var_table .

CLEAR w_varid .

REFRESH i_varit .

REFRESH i_rsparams .

i_rsparams-selname = 'CN_NETNR'.

i_rsparams-kind = 'S'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = '90273536'.

i_rsparams-high = space.

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'CN_NETNR'.

i_rsparams-kind = 'S'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = '90274010'.

i_rsparams-high = space.

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'R_OBDAT'.

i_rsparams-kind = 'S'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'BT'.

i_rsparams-low = space .

i_rsparams-high = space.

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'P_DISVAR'.

i_rsparams-kind = 'P'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = '1SAP' .

APPEND i_rsparams.

CLEAR : i_rsparams .

i_rsparams-selname = 'P_USEDB'.

i_rsparams-kind = 'P'.

i_rsparams-sign = 'I'.

i_rsparams-option = 'EQ'.

i_rsparams-low = SPACE.

APPEND i_rsparams.

w_varid-mandt = sy-mandt.

w_varid-report = v_repid.

w_varid-variant = v_variant.

w_varid-flag1 = space.

w_varid-flag2 = space.

w_varid-transport = space.

w_varid-environmnt = 'A'. "Variant for batch and online

w_varid-protected = space.

w_varid-secu = space.

w_varid-version = '0'.

w_varid-ename = sy-uname.

w_varid-edat = sy-datum.

w_varid-etime = sy-uzeit.

w_varid-aename = space.

w_varid-aedat = space.

w_varid-aetime = space.

w_varid-mlangu = sy-langu.

i_varit-mandt = sy-mandt.

i_varit-langu = sy-langu.

i_varit-report = w_varid-report.

i_varit-variant = w_varid-variant.

i_varit-vtext = 'CO99-OUTPUT'.

APPEND i_varit.

ENDFORM. " POPULATE_VAR_TABLE

&----


*& Form CREATE_VARIANT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM create_variant .

data: h_rc like sy-subrc.

*Check variant exists.

CALL FUNCTION 'RS_VARIANT_EXISTS'

EXPORTING

report = v_repid

variant = v_variant

IMPORTING

R_C = h_rc

EXCEPTIONS

not_authorized = 01

no_report = 02

report_not_existent = 03

report_not_supplied = 04.

IF h_rc = 0.

CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'

EXPORTING

curr_report = v_repid

curr_variant = v_variant

vari_desc = w_varid

TABLES

vari_contents = i_rsparams

vari_text = i_varit

EXCEPTIONS

illegal_report_or_variant = 01

illegal_variantname = 02

not_authorized = 03

not_executed = 04

report_not_existent = 05

report_not_supplied = 06

variant_doesnt_exist = 07

variant_locked = 08

selections_no_match = 09.

COMMIT WORK.

ELSE.

CALL FUNCTION 'RS_CREATE_VARIANT'

EXPORTING

curr_report = v_repid

curr_variant = v_variant

vari_desc = w_varid

TABLES

vari_contents = i_rsparams

vari_text = i_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.

COMMIT WORK.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

ENDFORM. " CREATE_VARIANT

&----


*& Form submit_cji5

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM submit_cji5 .

CALL FUNCTION 'SUBST_START_REPORT_IN_BATCH'

EXPORTING

iv_jobname = 'TEST_JOB'

iv_repname = v_repid

iv_varname = v_variant

iv_authcknam = sy-uname

iv_language = sy-langu

iv_varianttext = 'CO99-OUTPUT'

TABLES

tt_reportparam = i_rsparams

EXCEPTIONS

variant_exist_check_failed = 1

variant_update_failed = 2

variant_update_not_authorized = 3

variant_update_no_report = 4

variant_update_no_variant = 5

variant_update_variant_locked = 6

variant_insert_failed = 7

variant_insert_not_authorized = 8

variant_insert_no_report = 9

variant_insert_variant_exists = 10

variant_insert_variant_locked = 11

variant_write_failed = 12

no_batch_service = 13

no_server_list = 14

batch_scheduling_failed = 15

OTHERS = 16.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM.

Regards,

Srilatha.

Former Member
0 Kudos

Thank you very much for your help.

FM RS_CREATE_VARIANT would be a solution.

I beg one more help.

Can this FM set variat variables (TVARVC variables) or not ?

0 Kudos

Check the below link and it may help you

Thanks

seshu

Former Member
0 Kudos

I found that RS_CHANGE_CREATED_VARIANT can set the variant variable from TVARVC with TABLE parameter "OBJECTS".

Thank you very much for your help.