Running the alv report in background and sending it thro email
hi,
i have to run the alv report in background and send the output through email
Hi
Many a times there is a requirement to display ALV Grid (not ALV List) in the background Job. I have checked the SDN Forum for the same and it has been mentioned that ALV Grid cannot be displayed in Background, but the list output of ALV is possible. So user wont have the actual Grid interface but the List interface.
There is a workaround to display ALV Grid in Background Job. The only restriction is you cant schedule the job through SM36. You need to execute the transaction of the report program, fill in the selection screen data and hit Execute.
The job would be executed in background. User will be able to see the Job Log and Job Status after executing the program. User doesnt have to go to SM37 to view the job status/log. Once the Job Status is changed to COMPLETED, user can click on DISPLAY SPOOL to view the ALV Grid.
Limitations:
Cant schedulea background job
The session should be active until the background job is completed. If the session is closed, then user wont be able to check the output in ALV Grid. User would be able to check the output through spool or SM37
Advantages:
If the spool width is greater than 255 characters, then the entire width could be seen in the output because the output is directed to an ALV Grid and not to spool
Interface of ALV Grid is available instead of ALV List even though its a background job.
Program wont give the TIME OUT error
Steps Required:
1. Once you execute the program, the following screen would be displayed
2. Click Display Job Status to check the Status of the Background Job
3. Click on Display the Job Log to check the Log
4. Click on Display Job Status to check the Job Status
5. Click on DISPLAY SPOOL to check the spool content once the Job Status is changed to COMPLETED. Output is displayed in ALV Grid
Programs:
1. Two different programs needs to be created
ZPROGRAM_ONE: This is the 1st program, where the selection screen and all the data validations would be done. Error handling for invalid data should be done in this program.
Once the data validation is done, this program would call the 2nd program ZPROGEAM_TWO. Build the logic to display ALV Grid in this program. The logic will only display ALV in foreground and it wont be reflected in the spool.
ZPROGRAM_TWO: This program would fetch all the data and do all the processing. If you want the spool output along with ALV Grid output, then build the logic in this program to display ALV Grid.
*& Report ZPROGRAM_ONE *
REPORT zprogram_one .
PRASHANT PATIL
TABLES : mara,
tsp01.
type-pools:slis.
TYPES : BEGIN OF t_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
END OF t_mara.
DATA : i_mara TYPE STANDARD TABLE OF t_mara,
wa_mara TYPE t_mara,
wa_index TYPE indx, " For Index details
wa_index_key TYPE indx-srtfd VALUE 'PRG_ONE',
i_jobsteplist TYPE STANDARD TABLE OF tbtcstep, " For spool number
wa_params TYPE pri_params, " To Get Print Parameters
wa_jobhead TYPE tbtcjob, " To know the status of job
wa_jobsteplist TYPE tbtcstep, " To know the spool
w_jobname TYPE tbtco-jobname, " Job name for bckgrnd job
w_jobcount TYPE tbtco-jobcount, " Unique id for bckgrd job
w_path TYPE string, " Upload path
w_lsind TYPE sy-lsind, " Index
wa_seltab TYPE rsparams,
i_seltab TYPE STANDARD TABLE OF rsparams,
wa_index1 TYPE indx, " For Index details
wa_index_key1 TYPE indx-srtfd VALUE 'PRG_TWO',
i_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF i_fieldcat.
CONSTANTS DECLARATION *
CONSTANTS :
c_a(1) TYPE c VALUE 'A',
c_m(1) TYPE c VALUE 'M',
c_l(1) TYPE c VALUE 'L',
c_c(1) TYPE c VALUE 'C',
c_zfdr(4) TYPE c VALUE 'ZFDR',
c_x(1) TYPE c VALUE 'X',
c_locl(4) TYPE c VALUE 'LOCL', " Destination is LOCAL
c_f(1) TYPE c VALUE 'F', " Job Status - Failed
c_s(1) TYPE c VALUE 'S',
c_p(1) TYPE c VALUE 'P'.
SELECTION SCREEN PARAMETERS
SELECT-OPTIONS : s_matnr FOR mara-matnr.
START-OF-SELECTION.
Before the export, fill the data fields before CLUSTR
wa_index-aedat = sy-datum.
wa_index-usera = sy-uname.
EXPORT s_matnr
TO DATABASE indx(st) FROM wa_index ID wa_index_key.
To Open the Job for background processing
PERFORM open_job.
To get the print parameters
PERFORM get_print_parameters.
Submit the job in background
PERFORM job_submit.
Close the background job
PERFORM job_close.
This is the output screen with the buttons ********
Create 3 buttons DISPLAY SPOOL, STATUS, JOBLOG
SET PF-STATUS 'ZS001'.
WRITE: / 'The program is submitted in Background'.
WRITE: / 'Press DISPLAY SPOOL to see the spool'.
WRITE: / 'Press STATUS to see the status of the background'.
AT USER-COMMAND.
If user presses the 'BACK' button
IF sy-ucomm = 'BAK'.
IF wa_jobhead-status = c_f OR
wa_jobhead-status = c_a.
LEAVE TO SCREEN 0.
ENDIF.
ENDIF.
If the user presses the 'DISPLAY SPOOL' Button
IF sy-ucomm = 'DISPLAY'.
PERFORM display_spool.
ENDIF.
If the user presses the 'JOB STATUS' Button
IF sy-ucomm = 'STATUS'.
PERFORM display_status.
ENDIF.
If the user presses the 'JOB LOG' Button
IF sy-ucomm = 'JOBLOG'.
PERFORM display_job_log.
ENDIF.
*& Form open_job
text
--> p1 text
<-- p2 text
FORM open_job .
This is to Create a new job which is to be submitted in background to
process sales order/delivery/invoice
Here we would get a unique id ( Jobcount ) which identifies our job
along with the job name which we have assigned to our job
CONCATENATE sy-uname
sy-datum
sy-uzeit
INTO w_jobname . " Assign unique jobname
CALL FUNCTION 'JOB_OPEN'
EXPORTING
DELANFREP = ' '
JOBGROUP = ' '
jobname = w_jobname
SDLSTRTDT = NO_DATE
SDLSTRTTM = NO_TIME
JOBCLASS =
IMPORTING
jobcount = w_jobcount
CHANGING
RET =
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 get_print_parameters
text
--> p1 text
<-- p2 text
FORM get_print_parameters .
DATA : l_valid TYPE c.
This is to get the Print Parameters for the job which is to be
submitted in background to process sales order/delivery/invoice
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
ARCHIVE_ID = C_CHAR_UNKNOWN
ARCHIVE_INFO = C_CHAR_UNKNOWN
ARCHIVE_MODE = C_CHAR_UNKNOWN
ARCHIVE_TEXT = C_CHAR_UNKNOWN
AR_OBJECT = C_CHAR_UNKNOWN
ARCHIVE_REPORT = C_CHAR_UNKNOWN
AUTHORITY = C_CHAR_UNKNOWN
COPIES = C_NUM3_UNKNOWN
COVER_PAGE = C_CHAR_UNKNOWN
DATA_SET = C_CHAR_UNKNOWN
DEPARTMENT = C_CHAR_UNKNOWN
destination = c_locl " LOCL
EXPIRATION = C_NUM1_UNKNOWN
immediately = space
IN_ARCHIVE_PARAMETERS = ' '
IN_PARAMETERS = ' '
LAYOUT = C_CHAR_UNKNOWN
LINE_COUNT = C_INT_UNKNOWN
LINE_SIZE = C_INT_UNKNOWN
LIST_NAME = C_CHAR_UNKNOWN
LIST_TEXT = C_CHAR_UNKNOWN
MODE = ' '
new_list_id = c_x
PROTECT_LIST = C_CHAR_UNKNOWN
no_dialog = c_x
RECEIVER = C_CHAR_UNKNOWN
RELEASE = C_CHAR_UNKNOWN
REPORT = C_CHAR_UNKNOWN
SAP_COVER_PAGE = C_CHAR_UNKNOWN
HOST_COVER_PAGE = C_CHAR_UNKNOWN
PRIORITY = C_NUM1_UNKNOWN
SAP_OBJECT = C_CHAR_UNKNOWN
TYPE = C_CHAR_UNKNOWN
user = sy-uname
USE_OLD_LAYOUT = ' '
UC_DISPLAY_MODE = C_CHAR_UNKNOWN
DRAFT = C_CHAR_UNKNOWN
ABAP_LIST = ' '
USE_ARCHIVENAME_DEF = ' '
DEFAULT_SPOOL_SIZE = C_CHAR_UNKNOWN
PO_FAX_STORE = ' '
NO_FRAMES = C_CHAR_UNKNOWN
IMPORTING
OUT_ARCHIVE_PARAMETERS =
out_parameters = wa_params
valid = l_valid
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 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. " get_print_parameters
*& Form job_submit
text
--> p1 text
<-- p2 text
FORM job_submit .
The job which we have created & the unique id ( jobcount ) which we
have got identifies our job. Hence those parameters are passed along
with the name of the background program "ZPROGRAM_TWO"
The job is submitted in background.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
ARCPARAMS =
authcknam = sy-uname
COMMANDNAME = ' '
OPERATINGSYSTEM = ' '
EXTPGM_NAME = ' '
EXTPGM_PARAM = ' '
EXTPGM_SET_TRACE_ON = ' '
EXTPGM_STDERR_IN_JOBLOG = 'X'
EXTPGM_STDOUT_IN_JOBLOG = 'X'
EXTPGM_SYSTEM = ' '
EXTPGM_RFCDEST = ' '
EXTPGM_WAIT_FOR_TERMINATION = 'X'
jobcount = w_jobcount
jobname = w_jobname
LANGUAGE = SY-LANGU
priparams = wa_params
report = 'ZPROGRAM_TWO'
VARIANT = ' '
IMPORTING
STEP_NUMBER =
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. " job_submit
*& Form job_close
text
--> p1 text
<-- p2 text
FORM job_close .
Once the job is submitted in background then the job is closed
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
AT_OPMODE = ' '
AT_OPMODE_PERIODIC = ' '
CALENDAR_ID = ' '
EVENT_ID = ' '
EVENT_PARAM = ' '
EVENT_PERIODIC = ' '
jobcount = w_jobcount
jobname = w_jobname
LASTSTRTDT = NO_DATE
LASTSTRTTM = NO_TIME
PRDDAYS = 0
PRDHOURS = 0
PRDMINS = 0
PRDMONTHS = 0
PRDWEEKS = 0
PREDJOB_CHECKSTAT = ' '
PRED_JOBCOUNT = ' '
PRED_JOBNAME = ' '
SDLSTRTDT = NO_DATE
SDLSTRTTM = NO_TIME
STARTDATE_RESTRICTION = BTC_PROCESS_ALWAYS
strtimmed = c_x
TARGETSYSTEM = ' '
START_ON_WORKDAY_NOT_BEFORE = SY-DATUM
START_ON_WORKDAY_NR = 0
WORKDAY_COUNT_DIRECTION = 0
RECIPIENT_OBJ =
TARGETSERVER = ' '
DONT_RELEASE = ' '
TARGETGROUP = ' '
DIRECT_START =
IMPORTING
JOB_WAS_RELEASED =
CHANGING
RET =
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. " job_close
*& Form display_spool
text
--> p1 text
<-- p2 text
FORM display_spool .
To Read the Job to get the spool details
DATA : l_rqident TYPE tsp01-rqident, " Spool Number
l_spoolno TYPE tsp01_sp0r-rqid_char.
CLEAR : l_rqident,
w_lsind,
wa_jobsteplist.
REFRESH : i_jobsteplist.
SET PF-STATUS 'ZAR02'.
Get the Spool Number
CALL FUNCTION 'BP_JOB_READ'
EXPORTING
job_read_jobcount = w_jobcount
job_read_jobname = w_jobname
job_read_opcode = '20'
JOB_STEP_NUMBER =
IMPORTING
job_read_jobhead = wa_jobhead
TABLES
job_read_steplist = i_jobsteplist
CHANGING
RET =
EXCEPTIONS
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 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.
Read the Job Step list to get the spool number
READ TABLE i_jobsteplist INTO wa_jobsteplist INDEX 1.
CHECK wa_jobsteplist-listident <> space.
Spool Number
l_rqident = wa_jobsteplist-listident.
MOVE l_rqident TO l_spoolno.
Check the spool in TSP01
SELECT SINGLE * FROM tsp01 WHERE rqident = l_rqident.
IF sy-subrc = 0.
LEAVE TO LIST-PROCESSING.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = l_spoolno
IMPORTING
RC =
STATUS =
PERFORM show_alv.
ENDIF.
w_lsind = sy-lsind.
IF sy-lsind GE 19.
sy-lsind = 1.
ENDIF.
ENDFORM. " display_spool
*& Form show_alv
text
--> p1 text
<-- p2 text
FORM show_alv .
Before the import, fill the data fields before CLUSTR.
wa_index1-aedat = sy-datum.
wa_index1-usera = sy-uname.
To Import the selection screen data from Calling Program
IMPORT i_mara
FROM DATABASE indx(st) ID wa_index_key1 TO wa_index1.
FREE MEMORY ID wa_index_key1.
This prepares the field-catalog for ALV.
PERFORM prepare_fieldcatalog.
This displays the output in ALV format .
PERFORM display_alv.
ENDFORM. " show_alv
*& Form display_status
text
--> p1 text
<-- p2 text
FORM display_status .
To Display the STATUS of the JOB which is exectued in background
CLEAR : wa_jobsteplist.
REFRESH : i_jobsteplist.
WRITE:/ 'DISPLAYING JOB STATUS'.
CALL FUNCTION 'BP_JOB_READ'
EXPORTING
job_read_jobcount = w_jobcount
job_read_jobname = w_jobname
job_read_opcode = '20'
JOB_STEP_NUMBER =
IMPORTING
job_read_jobhead = wa_jobhead
TABLES
job_read_steplist = i_jobsteplist
CHANGING
RET =
EXCEPTIONS
invalid_opcode = 1
job_doesnt_exist = 2
job_doesnt_have_steps = 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.
To Display the status text as per the status type
CASE wa_jobhead-status.
WHEN 'S'. WRITE: / 'Scheduled'.
WHEN 'R'. WRITE: / 'Released'.
WHEN 'F'. WRITE: / 'Completed'.
WHEN 'A'. WRITE: / 'Cancelled'.
WHEN OTHERS.
ENDCASE.
IF sy-lsind GE 19.
sy-lsind = 1.
ENDIF.
ENDFORM. " display_status
*& Form display_job_log
text
--> p1 text
<-- p2 text
FORM display_job_log .
To display the log of the background program
LEAVE TO LIST-PROCESSING.
CALL FUNCTION 'BP_JOBLOG_SHOW_SM37B'
EXPORTING
client = sy-mandt
jobcount = w_jobcount
joblogid = ' '
jobname = w_jobname
EXCEPTIONS
error_reading_jobdata = 1
error_reading_joblog_data = 2
jobcount_missing = 3
joblog_does_not_exist = 4
joblog_is_empty = 5
joblog_show_canceled = 6
jobname_missing = 7
job_does_not_exist = 8
no_joblog_there_yet = 9
no_show_privilege_given = 10
OTHERS = 11.
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. " display_job_log
*& Form prepare_fieldcatalog
text
--> p1 text
<-- p2 text
FORM prepare_fieldcatalog .
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-reptext_ddic = 'Material no.'.
wa_fieldcat-outputlen = '18'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ERSDA'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-reptext_ddic = 'Creation date'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ERNAM'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-reptext_ddic = 'Name of Person'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'LAEDA'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-reptext_ddic = ' Last Change'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO i_fieldcat.
ENDFORM. " prepare_fieldcatalog
*& Form display_alv
text
--> p1 text
<-- p2 text
FORM display_alv .
Call ABAP List Viewer (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = i_fieldcat
tables
t_outtab = i_mara.
ENDFORM. " display_alv
ZPROGRAM_TWO: This is the 2nd program which would be called from program ZPROGRAM_ONE.
*& Report ZPROGRAM_TWO *
REPORT zprogram_two .
PRASHANT PATIL
TABLES : mara.
TYPE-POOLS:slis.
TYPES : BEGIN OF t_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
laeda TYPE mara-laeda,
END OF t_mara.
DATA : i_mara TYPE STANDARD TABLE OF t_mara,
wa_mara TYPE t_mara,
wa_index TYPE indx, " For Index details
wa_index_key TYPE indx-srtfd VALUE 'PRG_ONE',
wa_index1 TYPE indx, " For Index details
wa_index_key1 TYPE indx-srtfd VALUE 'PRG_TWO',
i_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF i_fieldcat.
SELECT-OPTIONS : s_matnr FOR mara-matnr.
Before the import, fill the data fields before CLUSTR.
wa_index-aedat = sy-datum.
wa_index-usera = sy-uname.
To Import the selection screen data from Calling Program
IMPORT s_matnr
FROM DATABASE indx(st) ID wa_index_key TO wa_index.
FREE MEMORY ID wa_index_key.
SELECT matnr
ersda
ernam
laeda
FROM mara
INTO TABLE i_mara
WHERE matnr IN s_matnr.
PERFORM prepare_fieldcatalog.
PERFORM display_alv.
Before the export, fill the data fields before CLUSTR
wa_index1-aedat = sy-datum.
wa_index1-usera = sy-uname.
EXPORT i_mara
TO DATABASE indx(st) FROM wa_index1 ID wa_index_key1.
*& Form prepare_fieldcatalog
text
--> p1 text
<-- p2 text
FORM prepare_fieldcatalog .
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-outputlen = '18'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ERSDA'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ERNAM'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO i_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'LAEDA'.
wa_fieldcat-tabname = 'I_MARA'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO i_fieldcat.
ENDFORM. " prepare_fieldcatalog
*& Form display_alv
text
--> p1 text
<-- p2 text
FORM display_alv .
Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = i_fieldcat
TABLES
t_outtab = i_mara.
ENDFORM. " display_alv
its possible to display ALV Grid using OO ALV. Following code can be used instead of FM.
In the PBO, add following code
SET PF-STATUS 'ZSTAT'.
If program is executed in background
CALL METHOD cl_gui_alv_grid=>offline
RECEIVING
e_offline = off.
IF off IS INITIAL.
IF container1 IS INITIAL.
CREATE OBJECT container1
EXPORTING
container_name = 'CC_ALV1' .
ENDIF.
ENDIF.
CREATE OBJECT g_grid1
EXPORTING
i_parent = container1.
CALL METHOD g_grid1->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
i_save = 'A'
i_default = ' '
is_layout =
is_print =
IT_SPECIAL_GROUPS =
it_toolbar_excluding =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
it_outtab = i_output
it_fieldcatalog = i_fieldcatalog
IT_SORT =
IT_FILTER =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 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.
Reward points if useful
Regards
Anji
Similar Messages
-
Running a ALV Report in bakcground and sending it to Email/FAX
Hi,
I am designing a ALV report to send a email/fax/Printer which has to be run in background or foreground according to selection screen inputs.
I am doing the following
1. After generating ALV report, converting it to pdf
2. Sending Email or Fax or Print from selection screen value.
3. after that scheduling in background using JOB_OPEN and JOB_SUBMIT FM's.
Can I use SO_DOCUMENT_SEND_API1 FM for both Email and Fax.
When I schedule the report in the background using JOB_OPEN, at which point I have to code it inside the report. Is it after I generate the ALV Report and Email sending code or before it..
ThanksHi
How did you end up doing the emailing? I have the same task..... -
Running the ALV report in Background using layout variant
Hello Everyone,
I am facing a problem in downloading a text file to the Application server.
My requirement is, when the user downloads a file with the layout variant, the file should have only the columns which was selected in the variant.
Can anybody give me a optimized solution for this issue.
Regards,
VasanthHi,
How are you downloading the file to the app server, using which internal table? How are you building that internal table?
What you need to do is to build a internal table dynamically with only those columns that are a part of the layout variant. Then move the data from the original internal table into this and then download the dynamica internal table to the app server.
Regards,
Ravi
Note : Please mark the helpful answers -
Schedule ME2L in background and send output to email address
Hi,
Our Client has a requirement to schedule ME2L (particular variant) in background.
The report should run every day in background and output should get emailed to particular email address.
Any ideas??? Pleae let me know.Thanks for the information. Very useful.
I am just facing one road block at the moment.
I am now able to schedule the ME2L Report and email it as attachment.
But, we have created a particular layout for this report, which we want should get emailed.
But when we schedule the report in the background (or run it in background manually), it only picks the standard layout!
I cannot find any layout option in ME2L Selection Screen as well. (I could have saved it in the variant then)
Can you help? -
Convert SMARTFORM report to PDF and send as an email attachment
Hi
I am using the CONVERT_OTF function module to convert a SMARTFORM report in the "spool" to a PDF file. When I use the DOWNLOAD function module, the resulting file can be opened in acrobat.
I would like to email the report in PDF format as an attachment. I am using the function module SO_NEW_DOCUMENT_ATT_SEND_API1 to create an attachment however the attached file is not being created correctly and When try to open, it gives 'File is damaged and could not be repaired' error message. I believe that somehow I am not using the SO_NEW_DOCUMENT_ATT_SEND_API1 function module correctly.
Please help me to correct this
Thanks
Rohitha
see my code below,
I_OTF[] = W_RETURN-OTFDATA[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
IMPORTING
BIN_FILESIZE = V_LEN_IN
TABLES
OTF = I_OTF
LINES = I_TLINE
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
ENDIF.
LOOP AT I_TLINE.
TRANSLATE I_TLINE USING '~'.
CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.
ENDLOOP.
TRANSLATE WA_BUFFER USING '~'.
DO.
I_RECORD = WA_BUFFER.
APPEND I_RECORD.
SHIFT WA_BUFFER LEFT BY 132 PLACES.
IF WA_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
REFRESH: I_RECLIST,
I_OBJTXT,
I_OBJBIN,
I_OBJPACK.
CLEAR WA_OBJHEAD.
I_OBJBIN[] = I_RECORD[].
I_OBJTXT = 'PDF Attachment'.
APPEND I_OBJTXT.
DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.
READ TABLE I_OBJTXT INDEX V_LINES_TXT.
WA_DOC_CHNG-OBJ_NAME = 'Smartform_to_PDF'.
WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.
WA_DOC_CHNG-OBJ_DESCR = 'Smartform to PDF'.
WA_DOC_CHNG-SENSITIVTY = 'F'.
WA_DOC_CHNG-DOC_SIZE = STRLEN( I_OBJTXT ) + ( ( V_LINES_TXT - 1 ) * 255 ) .
CLEAR I_OBJPACK-TRANSF_BIN.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
I_OBJPACK-BODY_NUM = V_LINES_TXT.
I_OBJPACK-DOC_TYPE = 'RAW'.
APPEND I_OBJPACK.
I_OBJPACK-TRANSF_BIN = 'X'.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 1.
I_OBJPACK-BODY_START = 1.
DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.
READ TABLE I_OBJBIN INDEX V_LINES_BIN.
I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .
I_OBJPACK-BODY_NUM = V_LINES_BIN.
I_OBJPACK-DOC_TYPE = 'PDF'.
I_OBJPACK-OBJ_NAME = 'ATTACHMENT'.
I_OBJPACK-OBJ_DESCR = 'test'.
APPEND I_OBJPACK.
CLEAR I_RECLIST.
I_RECLIST-RECEIVER = 'my email address u2019.
I_RECLIST-REC_TYPE = 'U'.
APPEND I_RECLIST.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = I_OBJPACK
OBJECT_HEADER = WA_OBJHEAD
CONTENTS_BIN = I_OBJBIN
CONTENTS_TXT = I_OBJTXT
RECEIVERS = I_RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
WRITE:/ 'Error ', SY-SUBRC.
ELSE.
WRITE:/ 'Mail sent'.
ENDIF.Hi rohitha.wijewardena ,
Please find the below code which i followed and succeed ,
CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'
EXPORTING
pi_nast = nast
pi_country = lv_dlv-land
pi_addr_key = lv_addr_key
pi_repid = sy-repid
pi_screen = lc_x
IMPORTING
pe_returncode = gv_retcode
pe_itcpo = lv_itcpo
pe_device = lv_device
pe_recipient = lv_recipient
pe_sender = lv_sender.
IF gv_retcode = 0.
*moving the data to composer and control parameters for output
MOVE-CORRESPONDING lv_itcpo TO lv_composer_param.
lv_control_param-device = lv_device.
lv_control_param-no_dialog = lc_x.
lv_control_param-preview = lc_x.
lv_control_param-getotf = lv_itcpo-tdgetotf.
lv_control_param-langu = nast-spras.
lv_composer_param-tdnoprint = space.
ENDIF.
*Getting the Smartform Function module using Standard Function module
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lv_formname "Smartform Name
IMPORTING
fm_name = lv_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3
IF sy-subrc <> 0.
gv_retcode = sy-subrc.
PERFORM protocol_update.
PERFORM add_smfrm_prot.
ENDIF.
**Smartform function module to get the output
CALL FUNCTION lv_fm_name
EXPORTING
control_parameters = lv_control_param
mail_recipient = lv_recipient
mail_sender = lv_sender
output_options = lv_composer_param
user_settings = ' '
is_bil_invoice = lv_bil_invoice
gt_header = gt_header
IMPORTING
job_output_info = gv_job_output
TABLES
gt_item = gt_item
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5
IF sy-subrc <> 0.
gv_retcode = sy-subrc.
PERFORM protocol_update.
PERFORM add_smfrm_prot.
ENDIF.
IF nast-nacha = lc_mail.
gt_otfdata[] = gv_job_output-otfdata[].
* Converting Smartform to PDF *
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = lc_pdf
max_linewidth = 10
IMPORTING
bin_filesize = gv_binfilesize
bin_file = gv_pdf_xstring
TABLES
otf = gt_otfdata[]
lines = gt_pdftab[]
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Sending PDF to Email using Class *
IF NOT lv_email IS INITIAL .
TRY.
gv_send_request = cl_bcs=>create_persistent( ).
gv_pdf_content = cl_document_bcs=>xstring_to_solix( gv_pdf_xstring ).
gv_document = cl_document_bcs=>create_document(
i_type = lc_pdf
i_hex = gv_pdf_content
i_length = gv_pdf_size
i_subject = lc_subject ). "Subject for Email
gv_send_request->set_document( gv_document ).
gv_recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
gv_send_request->add_recipient( gv_recipient ).
gv_sent_to_all = gv_send_request->send( i_with_error_screen = lc_x ).
COMMIT WORK.
IF gv_sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH lv_email.
ELSE.
MESSAGE s022(so).
ENDIF.
CATCH cx_bcs INTO gv_bcs_exception.
MESSAGE i865(so) WITH gv_bcs_exception->error_type.
ENDTRY.
ENDIF. -
Periodically auto generation of Report in background and send result to user mail ID in Excel Format
Hi Experts, I want to get the warehouse inventory report to be receive by email in excel format every month end. also i have 4-5 transaction for that I need the report by email in excel format in specific frequency.
Can some one help me on this?
Regards,
RushikeshHi Rushikesh,
You can create batch Jobs (Trx. SM36) for executing the transactions in background at specified times and in the spool recipient option mention the email IDs of the recipients.
Regards,
Namita -
Running ALV REPORT in background
Hi Experts ,
Before writing this query , i went through all the threads related to ALV report in background . But found none of them satisfactory .
I am running a alv report in background . I am not using OO ALV . I am using " REUSE_ALV_GRID_DISPLAY" .
This report is schedules through a background job . It is creating a spool .
But I am getting a error message : *" FRONT END NOT AVIALABLE "*
What i have found so far :
I am planning to use sy-batch variable to check whether it is running in background or not , Then I am planning to read the spool and if the spool is created , i will display the ALV .
Is this the correct approach or some other way to generate the ALV REPORT .
Also by this way will the error message *" FRONT END NOT AVIALABLE "* go .
Please advice .
Regards,
AbhishekHello Everyone ,
Thanks for your replies .
I have the spool generated . But it is waiting status .
The issue here is how I am going to say that the spool is in " Completed " status . Because only after when my spool is in completed status , I want to display the status .
Is there way for this ?
Regards ,
Abhishek -
How to do the ALV report output in groups and caluculate the tOTALS(URGENT
Hi
In my ALV report output .I have to group the output based on the DAYS field
0-10 days in one group
10-30 days in one group
above 30 days one group
There is also a field by name "AMOUNT" in my output.
I have to calculate SUBTOTALs at the end of every group and at the end of the report i should caluculate GRAND TOTAL.
Please remember that i should not use any any BLOCKED ALVs and for Totals i should not use the SYMBOLS provided in the application toolbar of the report
Thanks in AdvancePlease don't repost your questions...
Check out my answer in your other post.
How to make the ALV report in groups and caluculate the TOTALS
Regards,
Naimesh Patel -
Scheduling of ALV Reports in Background
I have schedule a Report in the Back ground and also entered the spool list so that the mail can be sent to the said users but when the Report is recvd in the mail box it is recvd as html and there are many columnns in my report that are not visible.
can i schedule the report and send the report as an excel attchement in the background processing if so then how can i do that
you early reponse will be appreciated
abhishekHi,
Once you schedule the ALV report in background you will not get the entire list as it is. The output lenght of the ist generated in the background is set to 255 characters and generally data exceeding this lenght will be turncated.
You cannot download a report in excel in background. The FM's GUI_download will not work in backgorund. You will have to write the data on the application server and then write an additional program to read that data or alternatively use some of the std tcodes to fetch that data to the presentation system.
CHeers
VJ -
Error while running the Financial Reporting in Workspace.
Dear Folks
I am facing an issue with FR Report in Workspace
Hyperion Version : 11.1.1.3 on Windows 2003 64 bit.
Problem Description: We are trying to run the FRS reports in workspace and getting an error in a window "
Error Details :
Error "<?xml version="1.0" encoding="UTF-8"?>
<BpmResponse action="" type="error">
<code>0</code>
<desc>; nested exception is:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.InvalidClassException: com.hyperion.reporting.properties.PovProperties; local class incompatible: stream classdesc serialVersionUID = -1387329505542936014, local class serialVersionUID = 2904510004932374854</desc>
</BpmResponse>"
Please reply me with solution
Thanks in advance.
Thanks , Harsha.MHi Harsha,
Have you ever been able to run this report successfully? If yes, I would restart Reporting and Analysis services and see if it'll solve the issue?
Also, is there any special characters such as !, &, % in the report? If yes, I would try to remove these and re-run the report.
Hope it helps.
Mehmet -
Cant send an e-mail in ALV report for background executaion
Hello friends,
I am displaying ALV report using container.
Now when i run this report in background, an e-mail should be go with an EXCEL attachment of report.
I am able to send e-mail and attachment in foreground .
I am also able to run alv report in background.
now, only problem is that i am am not able to send e-mail in background.
any sujjetions ?
Points will rewarded if little bit useful.
Regards,
nimesh
if cl_gui_alv_grid=>offline( ) is initial.
Create custom container
CREATE OBJECT g_r_cust_container
EXPORTING
container_name = gv_ctrl_custom.
Create TOP-Document
CREATE OBJECT g_r_dd_document
EXPORTING
style = 'ALV_GRID'.
Create Splitter for custom_container
CREATE OBJECT g_r_splitter
EXPORTING
parent = g_r_cust_container
rows = 2
columns = 1.
Split the grid in two parts- top and grid
CALL METHOD g_r_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = g_r_parent_top.
CALL METHOD g_r_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = g_r_parent_grid.
Set height for g_parent_html
CALL METHOD g_r_splitter->set_row_height
EXPORTING
id = 1
height = 1.
Create grid object
CREATE OBJECT g_r_alvgrid
EXPORTING
i_parent = g_r_parent_grid. "g_r_cust_container.
else .
Create grid object
CREATE OBJECT g_r_alvgrid
EXPORTING
i_parent = or_doc. "g_r_cust_container.
endif .
Create object handler object (of type local class)
CREATE OBJECT g_r_handler.
SET HANDLER g_r_handler->top_of_page FOR g_r_alvgrid.
SET HANDLER g_r_handler->print_top_of_page FOR g_r_alvgrid.
w_disvariant-report = sy-repid.
w_disvariant-variant = p_vari.
CALL METHOD g_r_alvgrid->set_table_for_first_display
EXPORTING
i_structure_name = 'ysds_sox_price_change'
is_layout = w_layout
is_variant = w_disvariant
i_save = yc_chara
CHANGING
it_outtab = t_st_result
it_fieldcatalog = t_fieldcat[]
it_sort = t_sortinfo[].
CALL METHOD g_r_dd_document->initialize_document
EXPORTING
background_color = cl_dd_area=>col_textarea.no i am using container for ALV.
In above code i have mantioned If.......ELSE.....Condition.
which give me allow to run ALV in background mode but my problem is that i am not able to send e-mail with attachment in background mode.
DATA : or_doc type ref to cl_gui_docking_container .
My report is working fine in foreground but not able to send email in background.
so anybody can solve it? -
ALV report output to be send to the respective users through email
Hi Gurus,
My requirement is to send the ALV report output to the respective users Email ID (Lotus notes) when the report runs in background.
Could any one suggest me with sample coding, How to send a ALV report output to the respective email ID's ( Suggest me the FM that used to send a internal table)
Regards
PaulHi Paul,
Here for u the sample code:
<b>call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = gd_doc_data
put_in_outbox = 'X'
importing
sent_to_all = gd_sent_all
tables
packing_list = it_packing_list
contents_txt = it_message
receivers = it_receivers
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
Store function module return code
gd_error = sy-subrc.
Get it_receivers return code
loop at it_receivers.
endloop.</b>
Hope this helps you.Reply for queries
Regards,
Kumar. -
Regarding running a report in background and generate spool
Hi,
I am developing a report [<b>REPORT1</b>].
It is taking long to execute if data is more.
Now i want to schedule this report in background and generate spool along with.
So once i execute REPORT1 it should run in background & generate spool?
Can anybody give inputs for the same!
Thanks,
Deep.Hi,
to generate spool, use below code
FORM create_spool .
CONSTANTS : l_c_device(4) VALUE 'LOCL'.
Create Spool Request
NEW-PAGE PRINT ON
LINE-SIZE 120
DESTINATION l_c_device
IMMEDIATELY ' '
KEEP IN SPOOL 'X'
NEW LIST IDENTIFICATION 'X'
NO DIALOG.
ENDFORM. " create_spool
And after createing spool to get the spool number use below code,
FORM obtain_spool_id .
TYPES : BEGIN OF t_tsp01,
rqident TYPE tsp01-rqident,
rqowner TYPE tsp01-rqowner,
END OF t_tsp01.
DATA : it_tsp01 TYPE STANDARD TABLE OF t_tsp01,
wa_tsp01 LIKE LINE OF it_tsp01.
SELECT rqident
rqowner
FROM tsp01
INTO TABLE it_tsp01
WHERE rqowner = sy-uname.
SORT it_tsp01 BY rqident DESCENDING.
READ TABLE it_tsp01 INTO wa_tsp01 INDEX 1.
IF sy-subrc = 0 .
v_spool_nr = wa_tsp01-rqident.
ENDIF.
Capture the immediate spool created for this report
v_spool_nr = sy-spono.
ENDFORM. " obtain_spool_id
<b>Reward points</b>
Regards -
Is it possible to run ALV report in background if Yes how?
is it possible to run ALV report in background if Yes how?
Hi,
Why not?Through se38 only you create ALV report. there you can give your report name and go to program on menu bar - click - execute buton- click-Background . You will get new screen there you can choose Execute immediate or schedule.
<REMOVED BY MODERATOR>
Cheers,
Chandra Sekhar.
Edited by: Alvaro Tejada Galindo on Mar 4, 2008 2:12 PM -
How to send the ALV report output in mail
Dear all,
I have developed an ALV report.I need to send this output in the mail.Can anyone help me with the sample code of how to do this.Hi Ramya,
Check the links below :
http://wiki.sdn.sap.com/wiki/display/Snippets/Sending+Mail
http://wiki.sdn.sap.com/wiki/display/Snippets/AbapEMAILProgram
http://wiki.sdn.sap.com/wiki/display/ABAP/SendMessagetoExternalemailidandSAPUseridvia+ABAP
They will explain you to send an email.
Regards,
Kittu
Maybe you are looking for
-
Can I install 1333 MHz DDR3 RAM in my Macbook Pro?
I have a 2010 MacBook Pro and I want to upgrade to 8 GB of RAM. I found 1333 MHz RAM for cheaper than I could find the 1066MHz RAM that the computer is spec'ed for. Will the RAM work in my computer?
-
T510 Screen resolutions error?
To my knowledge, the screen resolution of 15,6" models should be as follows: HD: 1366 x 768 HD+: 1600 x 900 FHD: 1920 x 1080 Then why on European Lenovo websites all T510 models are listed as 15.6 " HD+ AntiGlare 1366x768 ?? Here is Italy, Germany an
-
Ibooks disappeared from my iPhone -- here we go again?
I know that this problem has come up and had been resolved in the past, but I just purchased and downloaded an ibook to itunes on my Macbook Pro, synced it to my iphone via USB --I'm away from wifi in a foreign land for the moment-- and the rest of m
-
Capture specific range of data in ECC
Dear All; We have a situation here: The customer database is huge (more than 1 TERA GB) in Production server, and it is difficult to do client copy of production server database to Test server for the testing/simulation purpose. Cause it will take l
-
I keep getting a screen asking me to license agreement or try free trial every time I login
I keep getting a screen asking me to license agreement or try free trial every time I login, but I already have an account and have been a member for a year now. I can't get past this screen.