Background job mass creation program

REPORT Z_BG_JOB NO STANDARD PAGE HEADING
LINE-SIZE 132
LINE-COUNT 65.
* MESSAGE-ID zhpa.
” Message id according to the module
* Change the line size line-count according to the report layout
*======================================================================*
* Functional spec ID : PS_
* Program ID : ZJOB_CREATE
* Program Description : Schedule Background Jobs Based on
*Excel File input
* Functional Consultant :
* Created By :
* Start Date :
* End Date :
*======================================================================*
* Modify Log History.
*———————————————————————-*
*No. Modified by Date Description
*— ———– —- ———–
*
*======================================================================*

* Selection Screen —————————————————-*
INCLUDE <cntn01>.
TYPES: BEGIN OF gty_s_joblist,
job TYPE btcjob,
job_class type char1,
exec_server TYPE BTCSRVNAME,
recipient TYPE string,
rec_type TYPE char1,
immediate TYPE char1,
start_date TYPE datum,
start_time TYPE UZEIT,
no_start_after_date TYPE datum,
no_start_after_time TYPE UZEIT,
periodic_job TYPE char1,
period_value TYPE string,
explicit_period_month_value TYPE string,
explicit_period_week_value TYPE string,
explicit_period_day_value TYPE string,
explicit_period_hour_value TYPE string,
explicit_period_minute_value TYPE string,
factory_cal_id TYPE BTCCALID,
factory_cal_behaviour TYPE BTCPRDBHV,
EventId TYPE BTCEVENTID,
eventparam TYPE BTCEVTPARM,
after_job_name TYPE BTCEVTPARM,
op_mode_name TYPE BTCEVTPARM,
wdt_fac_cal_id TYPE BTCCALID,
wdt_workday TYPE BTCPDAY,
wdt_time TYPE BTCSTIME,
wdt_date TYPE BTCLSDATE,
wdt_workday_rel_to TYPE BTCPMIN,
wdt_period_months TYPE BTCPMNTH,
step TYPE i,
stepuserid TYPE CHAR12,
abap_program TYPE btcprog,
abap_variant TYPE btcvariant,
ext_param TYPE BTCXPGPAR,
target_server TYPE BTCTGTSYS,
ext_prog_name TYPE BTCXPGPGM,
ext_command_name TYPE SXPGLOGCMD,
op_system TYPE SYOPSYS,

END OF gty_s_joblist,

BEGIN OF gty_data ,
v0001(50) TYPE c,
v0002(50) TYPE c,
v0003(50) TYPE c,
v0004(50) TYPE c,
v0005(50) TYPE c,
v0006(50) TYPE c,
v0007(50) TYPE c,
v0008(50) TYPE c,
v0009(50) TYPE c,
v0010(50) TYPE c,
v0011(50) TYPE c,
v0012(50) TYPE c,
v0013(50) TYPE c,
v0014(50) TYPE c,
v0015(50) TYPE c,
v0016(50) TYPE c,
v0017(50) TYPE c,
v0018(50) TYPE c,
v0019(50) TYPE c,
v0020(50) TYPE c,
v0021(50) TYPE c,
v0022(50) TYPE c,
v0023(50) TYPE c,
v0024(50) TYPE c,
v0025(50) TYPE c,
v0026(50) TYPE c,
v0027(50) TYPE c,
v0028(50) TYPE c,
v0029(50) TYPE c,
v0030(50) TYPE c,
v0031(50) TYPE c,
v0032(50) TYPE c,
v0033(50) TYPE c,
v0034(50) TYPE c,
v0035(50) TYPE c,
v0036(50) TYPE c,
v0037(50) TYPE c,
v0038(50) TYPE c,
END OF gty_data,

BEGIN OF ty_alv,
jobname TYPE string,
jobstatus TYPE string,
remarks TYPE string,
END OF ty_alv.
TYPES: gty_t_joblist TYPE STANDARD TABLE OF gty_s_joblist.
DATA: gt_joblist TYPE gty_t_joblist,
gs_joblist TYPE gty_s_joblist.
DATA gs_user_print_params TYPE pri_params.
DATA: BEGIN OF intern OCCURS 50000.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF intern,
wa_intern TYPE alsmex_tabline,
wa1_data TYPE gty_data,
wa_data1 TYPE gty_data.
data: g_error TYPE c,
it_alv TYPE STANDARD TABLE OF ty_alv,
ls_alv TYPE ty_alv.

* Structure for optical archiving parameters
DATA gs_user_arc_params TYPE arc_params.

FIELD-SYMBOLS : <fs1>.

* Additional printing/archiving declarations
DATA:
* count(3) TYPE n VALUE 1,
gv_valid TYPE c.

* Data declarations for the mail recipient
DATA : it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
wa_layout TYPE slis_layout_alv.

DATA gs_recipient TYPE swc_object.
DATA gs_recipient_obj TYPE swotobjid.
swc_container gt_container.

DATA:
gv_jobnumber TYPE tbtcjob-jobcount, ” Job ID and
gv_jobname TYPE tbtcjob-jobname, ” job name.
gv_job_released TYPE btch0000-char1. ” JOB_CLOSE: Was job released?

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-s00.

PARAMETERS: p_fname TYPE rlgrap-filename OBLIGATORY ,
rb_s RADIOBUTTON GROUP RB , rb_r RADIOBUTTON GROUP RB.

SELECTION-SCREEN: END OF BLOCK b1.

* AT SELECTION-SCREEN ON VALUE-REQUEST FOR
*======================================================================*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
PERFORM f_get_fpath CHANGING p_fname.

*_ Remove this Event and related logic for ALV reports
*======================================================================*
* TOP-OF-PAGE
*======================================================================*
TOP-OF-PAGE.

**_ To Print Header
PERFORM f_print_heading.

*======================================================================*
* START-OF-SELECTION
*======================================================================*
START-OF-SELECTION.

*_ Process Main logic
PERFORM f_process_data.

*& Form F_PRINT_HEADING
*&———————————————————————*
* To Print page heading
*———————————————————————-*
FORM f_print_heading . “#EC NEEDED

*CONSTANTS lc_xx TYPE xx.
CONSTANTS: lc_right_tab TYPE i VALUE 50,
lc_report_name_length TYPE i VALUE 40.

*– Print report title
FORMAT COLOR OFF.
WRITE: sy-title.
NEW-LINE.
ULINE.
NEW-LINE.

NEW-LINE.
* write: ‘Plant: ‘.
* M_DISPLAY_SELECTION WERKS. ” Print selection for Plant
WRITE: AT lc_right_tab ‘Page:'(w01),
sy-pagno LEFT-JUSTIFIED.

* new-line.
* write: ‘PR date: ‘.
* M_DISPLAY_SELECTION BADAT. ” Print selection for PR Date
WRITE: AT lc_right_tab ‘Report:'(w02),
AT (lc_report_name_length) sy-repid. ” Report Name

* new-line.
* write: ‘Purchasing Group: ‘.
* M_DISPLAY_SELECTION EKGRP. ” Print selection for Purchasing Group
WRITE: AT lc_right_tab ‘User Name:'(w03),
sy-uname. ” User Name

NEW-LINE.
WRITE: AT lc_right_tab ‘Print Date:'(w04),
sy-datum. ” System Date
*– write Print Time in addition to Print Date
WRITE: ‘/’,
sy-uzeit. ” System Time

NEW-LINE.
ULINE.
NEW-LINE.

ENDFORM. ” F_PRINT_HEADING

*& Form F_PROCESS_DATA
*&———————————————————————*
* For Main Processing logic
*———————————————————————-*
FORM f_process_data . “#EC NEEDED

* ” Upload Excel File containing background jobs information
PERFORM upload_job_schedule_file.
PERFORM get_print_parameters.
PERFORM schedule_background_jobs.
IF it_alv IS NOT INITIAL.
PERFORM display_alv.
ENDIF.

ENDFORM. ” F_PROCESS_DATA

 

FORM upload_job_schedule_file .

*Variables ————————————————————*
DATA lv_path TYPE string .

*Work area ————————————————————*

DATA ls_joblist TYPE gty_s_joblist .

TYPE-POOLS truxs.
DATA: lt_raw_data TYPE truxs_t_text_data,
lt_string TYPE STANDARD TABLE OF string.
DATA: lo_tabledescr TYPE REF TO cl_abap_tabledescr,
lo_structdescr TYPE REF TO cl_abap_structdescr,
lx_err TYPE REF TO cx_root,
lr_data TYPE REF TO data,
lv_string TYPE string,
lv_name TYPE RLGRAP-FILENAME, “string,
lv_sep TYPE char01.
FIELD-SYMBOLS: <lv_stru> TYPE any.

 

lv_path = p_fname .

lv_name = lv_path.

CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
EXPORTING
FILENAME = lv_name
i_begin_col = 1
i_begin_row = 1
i_end_col = 40
i_end_row = 5000
TABLES
INTERN = intern
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF sy-subrc <> 0.
g_error = ‘1’.
ENDIF.

IF g_error IS NOT INITIAL.
PERFORM display_error USING g_error.
EXIT.
ENDIF.

***>>Transfer data to record table
PERFORM extract_records.

ENDFORM. ” UPLOAD_JOB_SCHEDULE_FILE
FORM f_split_string USING pv_string TYPE string
pv_sep TYPE char01
po_struct TYPE REF TO cl_abap_structdescr
CHANGING cv_stru TYPE any.

DATA: lt_split TYPE STANDARD TABLE OF string,
ls_struct TYPE abap_compdescr,
lv_split TYPE string,
lv_sep TYPE char01,
lv_index TYPE sy-tabix.
FIELD-SYMBOLS: <lv_value> TYPE any.

IF pv_sep IS INITIAL.
lv_sep = cl_abap_char_utilities=>horizontal_tab.
ELSE.
lv_sep = pv_sep.
ENDIF.

SPLIT pv_string AT lv_sep INTO TABLE lt_split.
LOOP AT lt_split INTO lv_split.
lv_index = sy-tabix.
ASSIGN COMPONENT lv_index OF STRUCTURE cv_stru TO <lv_value>.
*- Check if the assign is successfull or not
IF sy-subrc = 0.
READ TABLE po_struct->components
INTO ls_struct INDEX lv_index.
CASE ls_struct-type_kind.
WHEN ‘P’ OR ‘I’ OR ‘F’.
REPLACE ALL OCCURRENCES OF ‘,’ IN lv_split WITH ”.
WHEN OTHERS.
ENDCASE.
IF ls_struct-type_kind = ‘D’.
CALL FUNCTION ‘CONVERT_DATE_TO_INTERNAL’
EXPORTING
DATE_EXTERNAL = lv_split
IMPORTING
DATE_INTERNAL = lv_split
EXCEPTIONS
DATE_EXTERNAL_IS_INVALID = 1
OTHERS = 2.
ENDIF.
<lv_value> = lv_split.
ENDIF.
CLEAR: ls_struct, lv_split, lv_index.
ENDLOOP.

ENDFORM. ” f_split_string

*&———————————————————————*
*& Form GET_PRINT_PARAMETERS
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM get_print_parameters .
* GET_PRINT_PARAMETERS: As coded, presents the user with the
* standard R/3 popup window for collecting printer and optical
* archiving specifications. You can export default values for
* printing and archiving options. These values are presented as
* defaults in interactive mode or can be written directly into
* the parameter structures in non-interactive mode. Use the
* IMPORTING OUT* parameters to pass the printing and archiving
* specifications to JOB_SUBMIT or ABAP SUBMIT.
DATA ls_joblist TYPE gty_s_joblist .

READ TABLE gt_joblist INTO ls_joblist INDEX 1 .
IF sy-subrc = 0.
CALL FUNCTION ‘GET_PRINT_PARAMETERS’
EXPORTING
mode = ‘BATCH’
report = ls_joblist-ABAP_PROGRAM “‘ZFPSPR030’
no_dialog = ‘ ‘
IMPORTING
out_parameters = gs_user_print_params
out_archive_parameters = gs_user_arc_params
valid = gv_valid
EXCEPTIONS
OTHERS = 0 .”99.

IF gv_valid = space.
MESSAGE e208(00) WITH ‘Cannot get Print Parameters'(e05).
* STOP.
ENDIF.
ENDIF.
ENDFORM. ” GET_PRINT_PARAMETERS
*&———————————————————————*
*& Form SCHEDULE_BACKGROUND_JOBS
*&———————————————————————*
* Schedule Background Jobs
*———————————————————————-*
* –> p1 text
* –> gt_joblist Job List
*———————————————————————-*
FORM schedule_background_jobs .
data: lv_step TYPE TBTCJOB-STEPCOUNT,
gv_jobclass TYPE BTCJOBCLAS,
gv_exec_server TYPE BTCSRVNAME,
gv_day TYPE BTCPDAY,
gv_hour TYPE BTCPHOUR,
gv_week TYPE BTCPWEEK,
gv_month TYPE BTCPMNTH,
gv_minute TYPE BTCPMIN,
gv_periodic_job TYPE BTCCHAR1,
gv_start_date TYPE BTCSDATE,
gv_start_time TYPE BTCSTIME,
gv_no_start_after_date TYPE BTCSDATE,
gv_no_start_after_time TYPE BTCSTIME,
gv_factory_cal_id TYPE BTCCALID,
gv_fac_cal_behaviour TYPE BTCPRDBHV,
gv_eventId TYPE BTCEVENTID,
gv_eventparam TYPE BTCEVTPARM,
gv_dont_release TYPE char1,
gv_userid TYPE char12.

IF rb_s IS NOT INITIAL.
GV_DONT_RELEASE = ‘X’.
ELSE.
GV_DONT_RELEASE = ‘ ‘.
ENDIF.

clear : gv_jobclass , gv_exec_server, gv_day, gv_hour , gv_week, gv_month, gv_minute, gv_periodic_job, gv_start_date , gv_start_time , gv_userid.
* sort gt_joblist ASCENDING by job step.
LOOP AT gt_joblist INTO gs_joblist.
* lv_job = gs_joblist-JOB.

*– Begin of creating Spool List Recipient List
* Generate recipient object (see report RSSOKIF1 for an example)
*** 1. Create the recipient:

IF gs_joblist-recipient <> space.
“** 1.1 Generate an object reference to a recipient object
swc_create_object gs_recipient ‘RECIPIENT’ space.

“** 1.2 Write the import parameters for method
“** recipient.createaddress into the container
“** and empty the container
swc_clear_container gt_container.
“** Set address element
swc_set_element gt_container ‘AddressString’ gs_joblist-recipient.
“** Set address type
swc_set_element gt_container ‘TypeId’ gs_joblist-rec_type.

“** 1.3 Call the method recipient.createaddress
swc_call_method gs_recipient ‘CreateAddress’ gt_container.
“** Issue any error message generated by a method exception
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE ‘E’ NUMBER sy-msgno.
ENDIF.
swc_call_method gs_recipient ‘Save’ gt_container.
swc_object_to_persistent gs_recipient gs_recipient_obj.
ENDIF.
*** Recipient has been generated and is ready for use in a
*** background job
*– End of creating Spool List Recipient List

* Create your job with JOB_OPEN. The module returns a unique job
* number. Together with the jobname, this number identifies the
* job. Other parameters are available, but are not required.
clear : gv_jobclass, gv_exec_server, gv_start_date, gv_start_time,
gv_no_start_after_date , gv_no_start_after_time, GV_FACTORY_CAL_ID,
GV_FAC_CAL_BEHAVIOUR , gv_periodic_job , GV_EVENTID, GV_EVENTPARAM,
gv_day, gv_hour , gv_week, gv_month , gv_minute.

gv_jobclass = GS_JOBLIST-JOB_CLASS.
gv_exec_server = GS_JOBLIST-EXEC_SERVER.
gv_start_date = GS_JOBLIST-START_DATE.
gv_start_time = GS_JOBLIST-START_time.
gv_periodic_job = gs_joblist-periodic_job.
gv_no_start_after_date = GS_JOBLIST-NO_START_AFTER_DATE.
gv_no_start_after_time = GS_JOBLIST-NO_START_AFTER_TIME.
GV_FACTORY_CAL_ID = GS_JOBLIST-FACTORY_CAL_ID.
GV_FAC_CAL_BEHAVIOUR = GS_JOBLIST-FACTORY_CAL_BEHAVIOUR.
gv_userid = GS_JOBLIST-STEPUSERID.

data(gv_immediate) = GS_JOBLIST-IMMEDIATE.
IF GS_JOBLIST-EVENTID IS NOT INITIAL.
gv_eventid = GS_JOBLIST-EVENTID.
GV_EVENTPARAM = GS_JOBLIST-EVENTPARAM.
ELSEIF GS_JOBLIST-AFTER_JOB_NAME IS NOT INITIAL.
gv_eventid = ‘SAP_END_OF_JOB’.
GV_EVENTPARAM = GS_JOBLIST-AFTER_JOB_NAME.
ELSEIF GS_JOBLIST-OP_MODE_NAME IS NOT INITIAL.
gv_eventid = ‘SAP_OPMODE_SWITCH’.
GV_EVENTPARAM = GS_JOBLIST-OP_MODE_NAME.
data : gv_op_mode type PFEBANAME.
gv_op_mode = GS_JOBLIST-OP_MODE_NAME.
IF GS_JOBLIST-PERIODIC_JOB is NOT INITIAL.
data :gv_op_mode_periodic type BTCCHAR1.
gv_op_mode_periodic = ‘X’.
case GS_JOBLIST-PERIOD_VALUE.
WHEN ‘Hourly’.
gv_hour = ’01’.
* gv_periodic_job = ‘X’.
when ‘Daily’.
gv_day = ‘001’.
* gv_periodic_job = ‘X’.
when ‘Weekly’.
gv_week = ’01’.
* gv_periodic_job = ‘X’.
when ‘Monthly’.
gv_month = ’01’.
* gv_periodic_job = ‘X’.
when ‘Other’.

* CASE GS_JOBLIST-EXPLICIT_PERIOD.
* WHEN ‘Month’.
GV_MONTH = GS_JOBLIST-EXPLICIT_PERIOD_MONTH_VALUE.
* WHEN ‘Week’.
GV_WEEK = GS_JOBLIST-EXPLICIT_PERIOD_WEEK_VALUE.
* WHEN ‘Day’.
GV_DAy = GS_JOBLIST-EXPLICIT_PERIOD_DAY_VALUE.

* WHEN ‘Hour’.
GV_HOUR = GS_JOBLIST-EXPLICIT_PERIOD_HOUR_VALUE.
* WHEN ‘Minute’.
GV_minute = GS_JOBLIST-EXPLICIT_PERIOD_MINUTE_VALUE.

* WHEN OTHERS.
* ENDCASE.

ENDCASE.
ENDIF.
ELSEIF GS_JOBLIST-WDT_FAC_CAL_ID IS NOT INITIAL. “last mode – workday /time
gv_minute = GS_JOBLIST-WDT_WORKDAY_REL_TO.
gv_day = GS_JOBLIST-WDT_WORKDAY.
GV_FACTORY_CAL_ID = GS_JOBLIST-WDT_FAC_CAL_ID.
gv_month = GS_JOBLIST-WDT_PERIOD_MONTHS.
GV_PERIODIC_JOB = GS_JOBLIST-PERIODIC_JOB.
GV_NO_START_AFTER_DATE = GS_JOBLIST-WDT_DATE.
gv_start_time = GS_JOBLIST-WDT_TIME.
ENDIF.

AT NEW job.
gv_jobname = gs_joblist-job.

CALL FUNCTION ‘JOB_OPEN’
EXPORTING
jobname = gv_jobname
JOBCLASS = gv_jobclass
IMPORTING
jobcount = gv_jobnumber
EXCEPTIONS
cant_create_job = 01
invalid_job_data = 02
jobname_missing = 03
OTHERS = 99.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
endat.
* Add a job step: ABAP program
clear lv_step.
CALL FUNCTION ‘JOB_SUBMIT’
EXPORTING
authcknam = gv_userid ” Runtime authorizations user
COMMANDNAME = GS_JOBLIST-EXT_COMMAND_NAME “ext command name
OPERATINGSYSTEM = GS_JOBLIST-OP_SYSTEM “operating system
EXTPGM_NAME = GS_JOBLIST-EXT_PROG_NAME “ext program name
EXTPGM_PARAM = GS_JOBLIST-EXT_PARAM “ext parameter
EXTPGM_SYSTEM = GS_JOBLIST-TARGET_SERVER “Target Host for Executing External Program
jobcount = gv_jobnumber ” Value from JOB_OPEN
jobname = gv_jobname ” Value from JOB_OPEN
report = gs_joblist-abap_program ” Report to be run
variant = gs_joblist-abap_variant ” Variant to use with report
priparams = gs_user_print_params ” User printing options
arcparams = gs_user_arc_params ” User archiving
IMPORTING
STEP_NUMBER = lv_step
*options Both sets of options come from GET_PRINT_PARAMETERS
EXCEPTIONS
bad_priparams = 01
invalid_jobdata = 02
jobname_missing = 03
job_notex = 04
job_submit_failed = 05
ock_failed = 06
program_missing = 07
prog_abap_and_extpg_set = 08
OTHERS = 99.
IF sy-subrc <> 0.
CALL FUNCTION ‘BP_JOB_DELETE’
EXPORTING
jobcount = gv_jobnumber
jobname = gv_jobname
forcedmode = ‘X’
commitmode = ‘X’.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* Error processing in the event of a non-recoverable error should
* include a call to BP_JOB_DELETE with FORCEDMODE = ‘X’ to remove
* the job from the database. This is required for error
* processing in all calls after JOB_OPEN. (The background system
* cleans up automatically in the event of a problem in JOB_OPEN).
*
* Please see Selecting and Deleting a Job for a programming
* example.

* Submit job for processing: immediate start
at END OF job.
CALL FUNCTION ‘JOB_CLOSE’
EXPORTING
jobcount = gv_jobnumber ” Job identification: number
jobname = gv_jobname ” and name.
AT_OPMODE = GV_OP_MODE
AT_OPMODE_PERIODIC = GV_OP_MODE_PERIODIC
CALENDAR_ID = GV_FACTORY_CAL_ID
STARTDATE_RESTRICTION = GV_FAC_CAL_BEHAVIOUR
SDLSTRTDT = gv_start_date
SDLSTRTTM = gv_start_time
LASTSTRTDT = GV_NO_START_AFTER_DATE
LASTSTRTTM = GV_NO_START_AFTER_TIME
PRDDAYS = GV_DAy
PRDHOURS = GV_HOUR
PRDMINS = gv_minute
PRDMONTHS = GV_MONTH
PRDWEEKS = gv_week
recipient_obj = gs_recipient_obj
TARGETSERVER = GV_EXEC_SERVER
EVENT_ID = GV_EVENTID
EVENT_PARAM = GV_EVENTPARAM
EVENT_PERIODIC = gv_periodic_job
strtimmed = GV_IMMEDIATE ” Schedules the job for immediate start. The job
*is started immediately only if the user has the RELE authorization to
*release a job to run.
dont_release = GV_DONT_RELEASE
IMPORTING
job_was_released = gv_job_released ” If user has authorization to
*release jobs to run, job is automatically released when it is
*scheduled. ” This field is set to ‘x’ if
*the job has been released.
” Otherwise, the job is
*scheduled but must be released by an administrator before it can be
*started.
EXCEPTIONS
* CANT_START_IMMEDIATE No longer used. Replaced by IMPORTING
* parameter JOB_WAS_RELEASED.
invalid_startdate = 01
jobname_missing = 02
job_close_failed = 03
job_nosteps = 04
job_notex = 05
lock_failed = 06
OTHERS = 99.
IF sy-subrc <> 0.
* CALL FUNCTION ‘BP_JOB_DELETE’
* EXPORTING
* jobcount = gv_jobnumber
* jobname = gv_jobname
* forcedmode = ‘X’
* commitmode = ‘X’.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

CALL FUNCTION ‘BP_JOB_DELETE’
EXPORTING
JOBCOUNT = gv_jobnumber
JOBNAME = gv_jobname
FORCEDMODE = ‘X’
COMMITMODE = ‘X’
* DELINFO = ‘ ‘
EXCEPTIONS
CANT_DELETE_EVENT_ENTRY = 1
CANT_DELETE_JOB = 2
CANT_DELETE_JOBLOG = 3
CANT_DELETE_STEPS = 4
CANT_DELETE_TIME_ENTRY = 5
CANT_DERELEASE_SUCCESSOR = 6
CANT_ENQ_PREDECESSOR = 7
CANT_ENQ_SUCCESSOR = 8
CANT_ENQ_TBTCO_ENTRY = 9
CANT_UPDATE_PREDECESSOR = 10
CANT_UPDATE_SUCCESSOR = 11
COMMIT_FAILED = 12
JOBCOUNT_MISSING = 13
JOBNAME_MISSING = 14
JOB_DOES_NOT_EXIST = 15
JOB_IS_ALREADY_RUNNING = 16
NO_DELETE_AUTHORITY = 17
OTHERS = 18
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

* STOP.
* LEAVE to LIST-PROCESSING .
else.
IF gv_job_released IS NOT INITIAL.
* NEW-LINE.
* WRITE: ‘JOB’, gv_jobname, ‘WAS RELEASED’.
ls_alv-JOBNAME = GV_JOBNAME.
ls_alv-JOBSTATUS = ‘Released’.
append ls_alv to IT_ALV.

ELSE.
* NEW-LINE.
* WRITE: ‘JOB’, gv_jobname, ‘WAS SCHEDULED (WAS NOT RELEASED)’.
ls_alv-JOBNAME = GV_JOBNAME.
ls_alv-JOBSTATUS = ‘Scheduled’.
append ls_alv to IT_ALV.
ENDIF.
ENDIF.

endat.
ENDLOOP.
ENDFORM. ” SCHEDULE_BACKGROUND_JOBS
*&———————————————————————*
*& Form F_GET_FPATH
*&———————————————————————*
* get file path
*———————————————————————-*
* <–cv_fname File Path
*———————————————————————-*
FORM f_get_fpath CHANGING cv_fname TYPE rlgrap-filename .
DATA: lt_ftab TYPE filetable,
* ls_ftab TYPE LINE OF filetable,
lv_rc TYPE i.
CONSTANTS:lc_ftype TYPE string VALUE ‘XLSX’ ,
lc_fname TYPE string VALUE space ,”‘*.XLS’,
lc_dir TYPE string VALUE ‘C:’.

*– Get Input Filename
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
* window_title =
* default_extension =
default_extension = lc_ftype
* default_filename =
default_filename = lc_fname
* file_filter =
* with_encoding =
initial_directory = lc_dir
* multiselection =
CHANGING
file_table = lt_ftab
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 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.
ELSE.
IF lt_ftab IS NOT INITIAL.
READ TABLE lt_ftab INTO cv_fname INDEX 1.
ENDIF.
ENDIF.

ENDFORM. ” F_GET_FPATH
*&———————————————————————*
*& Form display_error
*&———————————————————————*
*& text
*&———————————————————————*
*& –> G_ERROR
*&———————————————————————*
FORM display_error USING l_error.
CASE l_error.
WHEN ‘1’.
MESSAGE ‘Upload Error!’ TYPE ‘S’ DISPLAY LIKE ‘E’.
WHEN ‘2’.
MESSAGE ‘Date Formate Error!’ TYPE ‘S’ DISPLAY LIKE ‘E’.
ENDCASE.
ENDFORM.
*&———————————————————————*
*& Form extract_records
*&———————————————————————*
*& text
*&———————————————————————*
*& –> p1 text
*& <– p2 text
*&———————————————————————*
FORM extract_records .
DATA:lv_count TYPE i.
DATA : count1 TYPE i VALUE IS INITIAL.
IF intern[] IS NOT INITIAL.
CLEAR:lv_count, count1.
LOOP AT intern INTO wa_intern.
CONCATENATE ‘WA_data1-V’ wa_intern-col INTO wa1_data.
ASSIGN (wa1_data) TO <fs1>.
<fs1> = wa_intern-value.
AT END OF row.
lv_count = lv_count + 1.
IF lv_count NE 1.
count1 = count1 + 1.
gs_joblist-JOB = wa_data1-v0001.
gs_joblist-JOB_CLASS = wa_data1-v0002.
gs_joblist-EXEC_SERVER = wa_data1-v0003.
gs_joblist-recipient = wa_data1-v0004.
gs_joblist-rec_type = wa_data1-v0005.
gs_joblist-IMMEDIATE = wa_data1-v0006.
gs_joblist-start_date = wa_data1-v0007.
* gs_joblist-start_time = wa_data1-v0007.
CONCATENATE WA_DATA1-V0008+0(2) WA_DATA1-V0008+3(2) WA_DATA1-V0008+6(2) INTO gs_joblist-start_time.
gs_joblist-NO_START_AFTER_DATE = wa_data1-v0009.
* gs_joblist-start_time = wa_data1-v0007.
CONCATENATE WA_DATA1-V0010+0(2) WA_DATA1-V0010+3(2) WA_DATA1-V0010+6(2) INTO gs_joblist-NO_START_AFTER_TIME.

GS_JOBLIST-PERIODIC_JOB = wa_data1-v0011.
gs_joblist-period_value = wa_data1-v0012.
GS_JOBLIST-EXPLICIT_PERIOD_MONTH_VALUE = wa_data1-v0013.
GS_JOBLIST-EXPLICIT_PERIOD_WEEK_VALUE = wa_data1-v0014.
GS_JOBLIST-EXPLICIT_PERIOD_DAY_VALUE = wa_data1-v0015.
GS_JOBLIST-EXPLICIT_PERIOD_HOUR_VALUE = wa_data1-v0016.
GS_JOBLIST-EXPLICIT_PERIOD_MINUTE_VALUE = wa_data1-v0017.
gs_joblist-FACTORY_CAL_ID = wa_data1-v0018.
gs_joblist-FACTORY_CAL_BEHAVIOUR = wa_data1-v0019.
gs_joblist-EVENTID = wa_data1-v0020.
gs_joblist-EVENTPARAM = wa_data1-v0021.
gs_joblist-AFTER_JOB_NAME = wa_data1-v0022.
gs_joblist-OP_MODE_NAME = wa_data1-v0023.
gs_joblist-WDT_FAC_CAL_ID = wa_data1-v0024.
gs_joblist-WDT_WORKDAY = wa_data1-v0025.
CONCATENATE WA_DATA1-v0026+0(2) WA_DATA1-v0026+3(2) WA_DATA1-v0026+6(2) INTO gs_joblist-WDT_TIME.
gs_joblist-WDT_DATE = wa_data1-v0027.
gs_joblist-WDT_WORKDAY_REL_TO = wa_data1-v0028.
gs_joblist-WDT_PERIOD_MONTHS = wa_data1-v0029.
gs_joblist-STEP = wa_data1-v0030.
GS_JOBLIST-STEPUSERID = wa_data1-v0031.
gs_joblist-ABAP_PROGRAM = wa_data1-v0032.
gs_joblist-ABAP_VARIANT = wa_data1-v0033.
gs_joblist-EXT_PARAM = wa_data1-v0034.
gs_joblist-TARGET_SERVER = wa_data1-v0035.
gs_joblist-EXT_PROG_NAME = wa_data1-v0036.
gs_joblist-EXT_COMMAND_NAME = wa_data1-v0037.
gs_joblist-OP_SYSTEM = wa_data1-v0038.
* wa_input-lifnr = wa_data1-v0002 .
* wa_input-abtnr = wa_data1-v0003 .
* wa_input-name1 = wa_data1-v0004 .
* wa_input-psovn = wa_data1-v0005 .
* wa_input-smtp_addr = wa_data1-v0006 .
* wa_input-count = count1 .
APPEND GS_JOBLIST TO GT_JOBLIST.
* CLEAR:wa_data1,wa_input.
ENDIF.
CLEAR:wa_data1.
ENDAT.
CLEAR :wa1_data.
ENDLOOP.
IF GT_JOBLIST[] IS INITIAL.
MESSAGE ‘No data to display’ TYPE ‘S’ DISPLAY LIKE ‘E’.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ENDFORM.
*&———————————————————————*
*& Form display_alv
*&———————————————————————*
*& text
*&———————————————————————*
*& –> p1 text
*& <– p2 text
*&———————————————————————*
FORM display_alv .

PERFORM buildfieldcat.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
is_layout = wa_layout
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_alv
EXCEPTIONS
program_error = 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.
ENDFORM.
*&———————————————————————*
*& Form buildfieldcat
*&———————————————————————*
*& text
*&———————————————————————*
*& –> p1 text
*& <– p2 text
*&———————————————————————*
FORM buildfieldcat .
REFRESH: it_fieldcat[].

CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = ‘JOBNAME’.
wa_fieldcat-seltext_l = text-010.
APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = ‘JOBSTATUS’.
wa_fieldcat-seltext_l = text-011.
APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = ‘REMARKS’.
wa_fieldcat-seltext_l = text-012.
APPEND wa_fieldcat TO it_fieldcat.
ENDFORM.

Scroll to Top