Program to Get Background Daily Job Report


** Anıl Ozgen – Program to get background

*               job details and send an excel report

*               by e-mail to

*               users

tablestbtco.

* Mail Data

data:   imessage       type standard table of solisti1

                       with header line,

        iattach        type standard table of solisti1

                       with header line,

        ipacking_list  like sopcklsti1 occurs with header line,

        ireceivers     like somlreci1  occurs with header line,

        iattachment    like solisti1   occurs with header line.

datalt_tbtco      type table of tbtco.

datals_tbtco      type          tbtco.

datalv_sender     type          ad_smtpadr

                   value ‘anilozgen@anilozgen.com.tr’.

datalt_recepients type          bcsy_smtpa.

datalv_receiver   type          ad_smtpadr.

datalv_email   type somlreci1receiver ,

      lv_date(12)                        ,

      lv_date2(12)                       ,

      lv_uzeit(8)                        ,

      lv_uzeit2(8)                       ,

      lv_statu   type string            .

selectoptionsp_jname for tbtcojobname.

selectoptionsp_sdate for tbtcosdlstrtdt default sydatum.

parameters    p_mail  type ad_smtpadr

       default ‘anil.ozgen@anilozgen.com’ obligatory.

startofselection.

check p_mail is not initial.

lv_email p_mail.

perform get_data.

perform prepeare_excel.

perform send_mail.

form get_data.

select from tbtco into corresponding fields of table lt_tbtco

  where jobname   in p_jname

    and sdlstrtdt in p_sdate.

check lt_tbtco is not initial and lt_tbtco[]

 is not initial.

endform.

form prepeare_excel.

constantscon_tab  type c value cl_abap_char_utilities=>horizontal_tab,

           con_cret type c value cl_abap_char_utilities=>cr_lf.

 concatenate ‘Job Name’

             ‘Start Date’

             ‘Start Time’

             ‘User’

             ‘End Date’

             ‘End Time’

             ‘Status’

             into iattach separated by con_tab.

  concatenate con_cret iattach into iattach.

  append  iattach.

  clear iattach.

  loop at lt_tbtco into ls_tbtco .

    clear lv_date.    write ls_tbtcosdlstrtdt to lv_date.

    clear lv_date2.   write ls_tbtcoenddate   to lv_date2.

    clear lv_uzeit.   write ls_tbtcosdlstrttm to lv_uzeit.

    clear lv_uzeit2.  write ls_tbtcoendtime   to lv_uzeit2.

    clear lv_statu.

    if ls_tbtcostatus ‘A’.

      lv_statu ‘Aborted’.

    elseif ls_tbtcostatus ‘F’.

      lv_statu ‘Success’.

    elseif ls_tbtcostatus ‘S’.

      lv_statu ‘Scheduled’.

    elseif ls_tbtcostatus ‘R’.

      lv_statu ‘Released’.

    elseif ls_tbtcostatus ‘X’.

      lv_statu ‘Unknown error’.

    elseif ls_tbtcostatus ‘Z’.

      lv_statu ‘Active’.

    elseif ls_tbtcostatus ‘Y’.

      lv_statu ‘Ready’.

    elseif ls_tbtcostatus ‘P’.

      lv_statu ‘Planned’.

    endif.

    concatenate

      ls_tbtcojobname

      lv_date

      lv_uzeit

      ls_tbtcosdluname

      lv_date2

      lv_uzeit2

      lv_statu

    into iattach separated by con_tab.

    concatenate con_cret iattach  into iattach.

    append  iattach.

  endloop .

endform.

form send_mail.

dataxdocdata like sodocchgi1,

      xcnt     type i.

clearimessageimessage[].   refresh imessage.

imessage ‘Dear Client, ‘.

append imessageclear imessage.

append imessage.

imessage =

‘You can find daily background job report at attachment’.

append imessageclear imessage.

append imessage.

imessage ‘Have a good day,’.

append imessage.

imessage ‘Anil Ozgen’.

append imessage.

xdocdatadoc_size 1.

xdocdataobj_langu sylangu .

xdocdataobj_name  ‘SAPRPT’ .

xdocdataobj_descr ‘Daily Job Report’ .

xdocdataobj_descr ‘Daily Job Report’ .

clear xdocdata.

read table iattach index xcnt.

xdocdatadoc_size =

   xcnt – 255 strleniattach ).

xdocdataobj_langu  sylangu.

xdocdataobj_name   ‘SAPRPT’.

xdocdataobj_descr  ‘Daily Job Report’.

clear iattachment.  refresh iattachment.

iattachment[] iattach[].

clear ipacking_list.  refresh ipacking_list.

ipacking_listtransf_bin space.

ipacking_listhead_start 1.

ipacking_listhead_num 0.

ipacking_listbody_start 1.

describe table imessage lines ipacking_listbody_num.

ipacking_listdoc_type ‘RAW’.

append ipacking_list.

ipacking_listtransf_bin ‘X’.

ipacking_listhead_start 1.

ipacking_listhead_num   1.

ipacking_listbody_start 1.

describe table iattachment lines ipacking_listbody_num.

ipacking_listdoc_type   =  ‘XLS’.

ipacking_listobj_descr  =  ‘Daily Job Report’.

ipacking_listobj_name   =  ‘Daily Job Report’.

ipacking_listdoc_size   =  ipacking_listbody_num * 255.

append ipacking_list.

clear ireceivers.  refresh ireceivers.

ireceiversreceiver lv_email.

ireceiversrec_type ‘U’.

ireceiverscom_type ‘INT’.

ireceiversnotif_del ‘X’.

ireceiversnotif_ndel ‘X’.

append ireceivers.

call function ‘SO_DOCUMENT_SEND_API1’

   exporting

    document_data              xdocdata

    put_in_outbox              ‘X’

    commit_work                ‘X’

   tables

    packing_list               ipacking_list

    contents_bin               iattachment

    contents_txt               imessage

    receivers                  ireceivers

   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 sysubrc eq 0.

   write ‘Succesful!’.

else.

   write ‘Error!’.

endif.

endform.

Leave a comment

Your email address will not be published. Required fields are marked *