12-04-2007 4:08 PM
Hi Fellow Abapers,
I need to edit a report whereby there is an option to display further fields. Now if they select this option, the report NEEDS to run in the background and output to the file. This will later be retrieved byt the SAP Output Controller (Which there is already a program). It is a must.
Does anybody have any links, codes, tips? Helpful posters will be awarded.
12-04-2007 4:13 PM
Use submit report when the user select Displ. further filelds, then it will run in backgorund and it will create a spool, so you can see it in SP01.
Pavan
12-04-2007 4:13 PM
Use submit report when the user select Displ. further filelds, then it will run in backgorund and it will create a spool, so you can see it in SP01.
Pavan
12-04-2007 4:17 PM
Ok - but I don't know how to submit the report to the spool. Can you explain please?
12-04-2007 4:43 PM
1) Read help on the ABAP statement SUBMIT
2) Examine JOB_OPEN and JOB_CLOSE function modules by issuing a where-used command and finding out how to use these FMs.
3) Within your program, watch for the new checkbox. If it is checked, SUBMIT the same again in background and exit the program.
You have to build your own logic to determine if the program is running in dialog mode or background mode and behave differently if the checkbox is checked. Make sure that the program doesn't go in a never ending recursive loop.
call function 'JOB_OPEN' ...
submit ...
call function 'JOB_CLOSE' ...
12-04-2007 5:50 PM
You can run your program from SE38, from program menu -> choose Execute in Background.
To make some decisions you can use the following code
if sy-batch is initial.
Process for foreground.
else.
process for background.
endif.
Regards,
Baburaj
12-04-2007 5:59 PM
Hi You can do that programatically, no need to say execute it in background from se38. Make sure you are not using file download but use open dataset. here is the sample program. Just copy and paste this in test program and check it. hope this will be helpfull. this report reads only materials for plant and there is an option on the selection screen to print or email or you can write it to spool. ofcourse it does automatically and then you can retrieve or print from SP01 but in your case you have to write to application server.
REPORT ysam_test5 MESSAGE-ID zsummit.
DATA: marc TYPE marc.
TYPES: BEGIN OF t_marc,
matnr TYPE matnr,
werks TYPE werks_d,
mmsta TYPE mmsta,
maabc TYPE maabc,
END OF t_marc.
DATA: it_marc TYPE TABLE OF t_marc,
wa_marc TYPE t_marc.
DATA : gr_table TYPE REF TO cl_salv_table.
DATA : gr_functions TYPE REF TO cl_salv_functions_list.
*fields used for variant create
DATA: wa_var_desc TYPE varid,
it_var_contents TYPE TABLE OF rsparams,
it_var_text TYPE TABLE OF varit,
wa_var_text TYPE varit,
w_var_varname TYPE variant.
*printer information
DATA: wa_print_options TYPE fpm_parcon,
wa_arc_options TYPE fpm_parcon,
w_print_options TYPE pri_params.
*email information
INCLUDE <cntn01>.
DATA: w_recipient TYPE swc_object,
w_recipient_obj TYPE swotobjid.
*container macro
swc_container w_swc_container.
*batch job information
INCLUDE lbtchdef.
DATA: w_job TYPE tbtcjob.
*constants
CONSTANTS: c_on VALUE 'X',
c_off VALUE space,
c_int(11) VALUE ' 0123456789'.
SELECTION-SCREEN BEGIN OF BLOCK main with frame.
SELECT-OPTIONS: s_matnr FOR marc-matnr,
s_werks FOR marc-werks.
SELECTION-SCREEN BEGIN OF BLOCK back WITH FRAME TITLE text-ss2.
PARAMETERS: p_fore RADIOBUTTON GROUP proc DEFAULT 'X', "foreground
p_ball radiobutton group proc,
p_berr radiobutton group proc.
SELECTION-SCREEN END OF BLOCK back.
SELECTION-SCREEN BEGIN OF BLOCK mail WITH FRAME TITLE text-ss3.
PARAMETERS: p_print RADIOBUTTON GROUP mail DEFAULT 'X',
p_email RADIOBUTTON GROUP mail.
SELECTION-SCREEN END OF BLOCK mail.
SELECTION-SCREEN END OF BLOCK main.
START-OF-SELECTION.
IF sy-batch = c_off AND p_fore = c_off.
PERFORM create_variant.
PERFORM build_print_parameters.
IF p_email = c_on.
PERFORM build_email_container.
ENDIF.
PERFORM open_job.
PERFORM submit_job.
PERFORM close_job.
MESSAGE i000 WITH 'Job' w_job-jobname
'has been submitted'.
perform delete_variant.
EXIT.
ENDIF.
perform select_data.
END-OF-SELECTION.
PERFORM salv_grid.
&----
*& Form salv_grid
&----
text
----
FORM salv_grid .
DATA: lref TYPE REF TO cx_root .
DATA: lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = it_marc ).
CATCH cx_salv_msg INTO lref.
ENDTRY.
***Sub Total
PERFORM sub_total.
***Layout
lr_layout = gr_table->get_layout( ).
ls_key-report = sy-cprog.
lr_layout->set_key( ls_key ).
lr_layout->set_default( 'X' ).
lr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
***toolbar
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( 'X' ).
*final display
gr_table->display( ).
ENDFORM. " salv
&----
*& Form sub_total
&----
FORM sub_total .
DATA: lr_aggregations TYPE REF TO cl_salv_aggregations.
lr_aggregations = gr_table->get_aggregations( ).
lr_aggregations->clear( ).
TRY.
lr_aggregations->add_aggregation( columnname = 'Z_BALANCE_REM' ).
CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.
ENDTRY.
TRY.
lr_aggregations->add_aggregation( columnname = 'Z_PAY_AMT' ).
CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.
ENDTRY.
ENDFORM. " sub_total
&----
*& Form select_data
&----
form select_data .
select matnr werks mmsta maabc into table it_marc
from marc
where matnr in s_matnr
and werks in s_werks.
endform. " select_data
&----
*& Form create_variant
&----
form create_variant .
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = sy-cprog
TABLES
selection_table = it_var_contents
EXCEPTIONS
not_found = 1
no_report = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CONCATENATE sy-datum sy-timlo INTO w_var_varname.
wa_var_desc-mandt = sy-mandt.
wa_var_desc-report = sy-cprog.
wa_var_desc-variant = w_var_varname.
wa_var_desc-transport = 'F'.
wa_var_desc-environmnt = 'A'.
wa_var_desc-version = '1'.
wa_var_text-mandt = sy-mandt.
wa_var_text-langu = sy-langu.
wa_var_text-report = sy-cprog.
wa_var_text-variant = w_var_varname.
CONCATENATE 'Batch Job Variant -' sy-uname INTO wa_var_text-vtext.
APPEND wa_var_text TO it_var_text.
CALL FUNCTION 'RS_CREATE_VARIANT'
EXPORTING
curr_report = sy-cprog
curr_variant = w_var_varname
vari_desc = wa_var_desc
TABLES
vari_contents = it_var_contents
vari_text = it_var_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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
endform. " create_variant
&----
*& Form build_print_parameters
&----
form build_print_parameters .
IF p_print = c_on.
CALL FUNCTION 'MAINTAIN_PRINT_PARAMETERS'
EXPORTING
i_title_text = 'Select your printer'
CHANGING
c_pri_params = wa_print_options
c_arc_params = wa_arc_options
EXCEPTIONS
parameters_not_valid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Print parameters could not be gathered'.
ENDIF.
ENDIF.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'CHECK_PRINT_PARAMETERS'
EXPORTING
i_title_text = 'Select your printer'
i_pri_params = wa_print_options
i_arc_params = wa_arc_options
IMPORTING
e_pri_params = w_print_options
EXCEPTIONS
parameters_not_valid = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Print parameters could not be assigned'.
ENDIF.
IF p_print = c_on.
w_print_options-primm = c_on.
ELSE.
w_print_options-primm = c_off.
ENDIF.
endform. " build_print_parameters
&----
*& Form build_email_container
&----
form build_email_container .
swc_create_object w_recipient 'RECIPIENT' space.
swc_clear_container w_swc_container.
swc_set_element w_swc_container 'AddressString' sy-uname.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
swc_set_element w_swc_container 'TypeId' 'B'.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
swc_call_method w_recipient 'CreateAddress' w_swc_container.
IF sy-subrc <> 0.
MESSAGE e000 WITH 'Could not determine email address'.
ENDIF.
swc_set_element w_swc_container 'SendExpress' 'X'.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
swc_call_method w_recipient 'SetExpress' w_swc_container.
swc_call_method w_recipient 'Save' w_swc_container.
swc_object_to_persistent w_recipient w_recipient_obj.
endform. " build_email_container
&----
*& Form open_job
&----
form open_job .
CONCATENATE sy-cprog '-' sy-uname INTO w_job-jobname.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = w_job-jobname
jobclass = 'A'
IMPORTING
jobcount = w_job-jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
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. " open_job
&----
*& Form submit_job
&----
form submit_job .
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
authcknam = sy-uname
jobcount = w_job-jobcount
jobname = w_job-jobname
priparams = w_print_options
report = 'YSAM_TEST5'
variant = w_var_varname
EXCEPTIONS
bad_priparams = 1
bad_xpgflags = 2
invalid_jobdata = 3
jobname_missing = 4
job_notex = 5
job_submit_failed = 6
lock_failed = 7
program_missing = 8
prog_abap_and_extpg_set = 9
OTHERS = 10.
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. " submit_job
&----
*& Form close_job
&----
form close_job .
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = w_job-jobcount
jobname = w_job-jobname
strtimmed = c_on
recipient_obj = w_recipient_obj
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
invalid_target = 8
OTHERS = 9.
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. " close_job
&----
*& Form delete_variant
&----
form delete_variant .
CALL FUNCTION 'RS_VARIANT_DELETE'
EXPORTING
report = sy-cprog
variant = w_var_varname
FLAG_CONFIRMSCREEN = 'X'
FLAG_DELALLCLIENT = 'X'
IMPORTING
VARIANT =
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 <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform. " delete_variant