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: 

Variant in Background

Former Member
0 Kudos

Hi Experts,

Can we make a variant run in background by default??

If yes then how??

1 ACCEPTED SOLUTION

former_member386202
Active Contributor
0 Kudos

Hi,

Yes, try like this.

SUBMIT REPORT01

VIA SELECTION-SCREEN

USING SELECTION-SET 'VARIANT1'

USING SELECTION-SETS OF PROGRAM 'REPORT00'

AND RETURN.

Regards,

Prashant

3 REPLIES 3

Former Member
0 Kudos

Hi

first Save the variant for that program and use in Job scheduling

Create a Variant for the Program and

Schedule JOB in background:

Go to SM36 create a Job

enter Program and Variant for that program in STEP..

click on Start Condition

Click on DATE and TIME enter date scheduled Start and END times

click on Period Values

Click on HOURLY/WEEKLY etc

CLick on RESTRICTIONS also to use further criteria.

so your job will be scheduled and run as per your requirement.

and in SM37 Transaction check the status of that JOB

Check this link for scheduling jobs..

http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a7f87505211d189550000e829fbbd/content.htm

Regards

Anji

former_member188829
Active Contributor
0 Kudos

Hi,

By Usin Fm:RS_CREATE_VARIANT

Check This Code....

  • build range table for parameters of the variant

CLEAR t_contents. REFRESH t_contents.

PERFORM add_param_to_var.

PERFORM add_param_to_var1 USING 'P_YEAR' 'P' p_year.

PERFORM add_param_to_var1 USING 'P_PERIOD' 'P' p_period.

PERFORM add_param_to_var1 USING 'P_MATNR' 'P' p_matnr.

  • setup variant name

CONCATENATE p_period

p_year INTO r_var SEPARATED BY '_'.

r_varit-report = sy-repid.

r_varit-variant = r_var.

  • get rid of old variant if it exists

CLEAR t_delvar.

REFRESH t_delvar.

APPEND r_var TO t_delvar.

CALL FUNCTION 'RS_VARIANT_DEL_ALL_CLIENTS'

EXPORTING

report = w_cprog

TABLES

del_variants = t_delvar

EXCEPTIONS

not_authorized = 1

not_executed = 2

no_report = 3

report_not_existent = 4

report_not_supplied = 5

variant_locked = 6

OTHERS = 7.

IF sy-subrc <> 0.

*-- For EPC Checks

CLEAR sy-subrc.

ENDIF.

  • setup variant text

CLEAR t_text. REFRESH t_text.

t_text-langu = sy-langu.

t_text-report = w_cprog.

t_text-variant = r_var.

t_text-vtext = 'System_Generated_variant **do not touch **'(010).

APPEND t_text.

  • create new variant

CALL FUNCTION 'RS_CREATE_VARIANT'

EXPORTING

curr_report = w_cprog

curr_variant = r_var

vari_desc = r_varit

TABLES

vari_contents = t_contents

vari_text = t_text

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.

  • FOR EPC warnings

CLEAR sy-subrc.

ENDIF.

ENDFORM. " create_variant

&----


*& Form add_param_to_var

&----


FORM add_param_to_var.

LOOP AT s_matkl.

  • add value to sel options table

CLEAR t_contents.

t_contents-selname = 'S_MATKL'.

t_contents-kind = 'S'.

MOVE-CORRESPONDING s_matkl TO t_contents.

APPEND t_contents.

ENDLOOP.

LOOP AT s_spart.

  • add value to sel options table

CLEAR t_contents.

t_contents-selname = 'S_SPART'.

t_contents-kind = 'S'.

MOVE-CORRESPONDING s_spart TO t_contents.

APPEND t_contents.

ENDLOOP.

ENDFORM. " add_param_to_var

&----


*& Form submit_in_background

&----


FORM submit_in_background .

DATA : l_parameters TYPE pri_params,

l_valid TYPE c,

l_days(1) TYPE n VALUE 2,

l_count(3) TYPE n VALUE 1.

DATA: l_jobnam LIKE tbtcjob-jobname, "job name

l_jobcnt LIKE tbtcjob-jobcount. "internal job number

RANGES r_bname FOR usr03-bname. "mail recipients

  • build range of recipients as just current user

r_bname = 'IEQ'.

r_bname-low = sy-uname.

APPEND r_bname.

  • build job name as program +user +time

CONCATENATE w_cprog sy-uname sy-uzeit INTO l_jobnam

SEPARATED BY '_'.

CONDENSE l_jobnam NO-GAPS.

*Calling GET_PRINT_PARAMETERS function module to avoid EPC warning

  • as "SUBMIT ... TO SAP-SPOOL WITHOUT SPOOL DYNPRO" statement

  • produces unexpected results without the essential("DESTINATION",

  • "IMMEDIATELY", "KEEP IN SPOOL") print parameters.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

copies = l_count

destination = 'LOCL'

expiration = l_days

immediately = ' '

new_list_id = 'X'

no_dialog = ' '

release = 'X'

user = sy-uname

IMPORTING

out_parameters = l_parameters

valid = l_valid

EXCEPTIONS

archive_info_not_found = 1

invalid_print_params = 2

invalid_archive_params = 3

OTHERS = 4.

IF sy-subrc <> 0.

  • FOR EPC warnings

CLEAR sy-subrc.

MESSAGE s000(zh) WITH

'Job not scheduled, Invalid print parameters.'.

EXIT.

ENDIF.

IF l_valid <> ' '.

  • create the job

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = l_jobnam

IMPORTING

jobcount = l_jobcnt

EXCEPTIONS

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3

OTHERS = 4.

IF sy-subrc <> 0.

  • FOR EPC warnings

CLEAR sy-subrc.

ENDIF.

SUBMIT zbcrp005 "Report distributor

WITH p_pgm = w_cprog

WITH p_var = r_var

WITH s_recvr IN r_bname

AND RETURN

TO SAP-SPOOL

SPOOL PARAMETERS l_parameters

WITHOUT SPOOL DYNPRO

VIA JOB l_jobnam NUMBER l_jobcnt.

  • close and submit the job

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = l_jobcnt

jobname = l_jobnam

strtimmed = 'X'

EXCEPTIONS

cant_start_immediate = 1.

IF sy-subrc <> 0.

  • FOR EPC warnings

CLEAR sy-subrc.

ENDIF.

  • issue message

MESSAGE i126(zh) WITH l_jobnam.

ENDIF.

ENDFORM. " SUBMIT_IN_BACKGROUND

&----


*& Form add_param_to_var1

&----


FORM add_param_to_var1 USING l_selname TYPE any

l_kind TYPE any

l_low TYPE any.

  • add value to sel options table

CLEAR t_contents.

t_contents-selname = l_selname.

t_contents-kind = l_kind.

t_contents-low = l_low.

APPEND t_contents.

ENDFORM. " add_param_to_var

Message was edited by:

Vishnu Reddy

former_member386202
Active Contributor
0 Kudos

Hi,

Yes, try like this.

SUBMIT REPORT01

VIA SELECTION-SCREEN

USING SELECTION-SET 'VARIANT1'

USING SELECTION-SETS OF PROGRAM 'REPORT00'

AND RETURN.

Regards,

Prashant