demo prog

Upload: anupam-samanta

Post on 08-Aug-2018

248 views

Category:

Documents


3 download

TRANSCRIPT

  • 8/22/2019 Demo Prog

    1/33

    *&---------------------------------------------------------------------**& Include ZH99_HRFORMS_CALL_FORM*&---------------------------------------------------------------------**&---------------------------------------------------------------------**& Form enable_disable_fields*&---------------------------------------------------------------------*form enable_disable_fields.statics sx_all_enabled type xfeld.

    *if report is called via menu/transaction no molga and fclass*if report is called from somewhere else molga and fclass = activeif p_molga is initial and p_fclass is initial.

    loop at screen.if screen-name eq 'P_MOLGA' or screen-name eq 'P_FCLASS'.

    screen-input = 1.modify screen.

    endif.endloop.sx_all_enabled = 'X'. "molga/fclass is initial!

    else.loop at screen.if screen-name cs 'P_MOLGA' or screen-name cs 'P_FCLASS'.

    if sx_all_enabled is initial and not sy-tcode eq 'SE38'.screen-input = 0.

    else.

    screen-input = 1.endif.modify screen.

    endif.endloop.

    endif.endform. "enable_disable_fields*&---------------------------------------------------------------------**& Form check_all*&---------------------------------------------------------------------*form check_all using iv_molga type thrforms_01-molga

    iv_variant type vari-variantchanging ov_fclass type thrforms_01-formclass

    ov_fname type thrforms_01-infonetov_report type rsvar-reportox_error type sysubrc.

    data ls_thrforms like thrforms_01.ox_error = 0.

    *****get/check the name of the print program (message if error)perform get_report_name changing ov_fname ov_report ox_error.check ox_error eq 0.

    *transform all parameters to upper casetranslate ov_fclass to upper case. "#EC SYNTCHARtranslate ov_fname to upper case. "#EC SYNTCHAR

    *****check if report, molga and fclass belong togetherselect single * from thrforms_01

    into corresponding fields of ls_thrformswhere infonet eq ov_fname and

    molga eq iv_molga andprintprog eq ov_report andformclass eq ov_fclass.

    if sy-subrc 0.*there is no form with this name

    ox_error = 1.perform error_msg using 'S' 'HRFORMS' '038' '' '' '' ''

    c_save_error_msg.

  • 8/22/2019 Demo Prog

    2/33

    elseif ls_thrforms-printprog is initial.*there is no active print report for this form

    ox_error = 2.perform error_msg using 'S' 'HRFORMS' '036' '' '' '' ''

    c_save_error_msg.endif.check ox_error eq 0.

    *****check if variant exists (no check if no variant assigned)perform check_variant using ov_report iv_variant

    changing ox_error.check ox_error eq 0.

    endform. "check_all*&---------------------------------------------------------------------**& Form get_report_name*&---------------------------------------------------------------------*form get_report_name changing ov_fname type thrforms_01-infonet

    ov_report type rsvar-reportox_error type sysubrc.

    ox_error = 0.translate ov_fname to upper case. "#EC SYNTCHAR

    call method cl_hrform_hrf02=>get_programexporting

    im_infonet = ov_fnamereceivingre_program = ov_report

    exceptionsinfonet_error = 1no_authority = 2others = 3.

    if sy-subrc 0.ox_error = 1.perform error_msg using sy-msgty sy-msgid sy-msgno

    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4c_save_error_msg.

    elseif ov_report is initial.

    *there is no active print report for this formox_error = 2.perform error_msg using 'S' 'HRFORMS' '036' '' '' '' ''

    c_save_error_msg.endif.

    endform. " get_report_name*&---------------------------------------------------------------------**& Form get_variant*&---------------------------------------------------------------------*form get_variant using iv_report type rsvar-report

    changing ov_variant type vari-variantox_error type sysubrc.

    data: lv_variant like rsvar-variant.ox_error = 0.

    call function 'RS_VARIANT_CATALOG'exportingreport = iv_report

    importingsel_variant = lv_variant

    exceptions

  • 8/22/2019 Demo Prog

    3/33

    no_report = 1report_not_existent = 2report_not_supplied = 3no_variants = 4no_variant_selected = 5variant_not_existent = 6others = 7.

    if sy-subrc eq 1 or sy-subrc eq 2 or sy-subrc eq 3.ox_error = 1.perform error_msg using 'S' 'HRFORMS' '036' '' '' '' ''

    c_save_error_msg.elseif sy-subrc eq 4 or sy-subrc eq 5

    or sy-subrc eq 6 or sy-subrc eq 7.ox_error = 2.perform error_msg using 'S' 'HRFORMS' '037' '' '' '' ''

    c_save_error_msg.endif.

    ov_variant = lv_variant.

    endform. " get_variant*&---------------------------------------------------------------------**& Form check_variant

    *&---------------------------------------------------------------------*form check_variant using iv_report type rsvar-reportiv_variant type vari-variant

    changing ox_error type sysubrc.

    ox_error = 0.check not iv_variant is initial.call function 'RS_VARIANT_EXISTS'

    exportingreport = iv_reportvariant = iv_variant

    importingr_c = ox_error

    exceptionsnot_authorized = 1no_report = 2report_not_existent = 3report_not_supplied = 4others = 5.

    if sy-subrc 0.ox_error = 1.perform error_msg using sy-msgty sy-msgid sy-msgno

    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4c_save_error_msg.

    elseif ox_error ne 0.perform error_msg using 'S' 'HRFORMS' '037' '' '' '' ''

    c_save_error_msg.endif.

    endform. "check_variant*&---------------------------------------------------------------------**& Form read_dynpro*&---------------------------------------------------------------------**the dynpro reading is only to avoid pressing 'enter' every time,*when choosing the form via F4 or entering the name manuallyform read_dynpro changing ov_molga type thrforms_01-molga

    ov_fclass type thrforms_01-formclass

  • 8/22/2019 Demo Prog

    4/33

    ov_fname type thrforms_01-infonet.

    data lt_dynpfields like dynpread occurs 1 with header line.data lv_dynpro_prog like d020s-prog.

    lt_dynpfields-fieldname = 'P_MOLGA'.append lt_dynpfields.lt_dynpfields-fieldname = 'P_FCLASS'.append lt_dynpfields.lt_dynpfields-fieldname = 'P_FNAME'.append lt_dynpfields.

    lv_dynpro_prog = sy-repid.

    call function 'DYNP_VALUES_READ'exportingdyname = lv_dynpro_progdynumb = '1000'

    tablesdynpfields = lt_dynpfields.

    read table lt_dynpfields with key fieldname = 'P_MOLGA'.ov_molga = lt_dynpfields-fieldvalue.read table lt_dynpfields with key fieldname = 'P_FCLASS'.

    ov_fclass = lt_dynpfields-fieldvalue.read table lt_dynpfields with key fieldname = 'P_FNAME'.ov_fname = lt_dynpfields-fieldvalue.

    endform. " read_dynpro*&---------------------------------------------------------------------**& Form select_data_f4*&---------------------------------------------------------------------*form select_data_f4 using iv_molga type thrforms_01-molga

    changing ov_fclass type thrforms_01-formclassox_error type sysubrc.

    data: begin of lt_value_tab occurs 0.

    data: infonet like thrforms_01-infonet,text like tinfonet_t_01-text,end of lt_value_tab,lt_field_tab type standard table of dfies,ls_field_tab like line of lt_field_tab,lt_help_tab type standard table of dfies,ls_help_tab like line of lt_help_tab.

    data: lv_dynpro_prog like d020s-prog.

    ox_error = 0.translate ov_fclass to upper case. "#EC SYNTCHAR

    select thrforms_01~infonet tinfonet_t_01~text

    into corresponding fields of table lt_value_tabfrom thrforms_01 inner join tinfonet_t_01 "#EC CI_BUFFJOINon thrforms_01~infonet = tinfonet_t_01~infonet

    where thrforms_01~molga eq iv_molga andthrforms_01~formclass eq ov_fclass andtinfonet_t_01~sprsl eq sy-langu.

    lv_dynpro_prog = sy-repid.

    *change the text for the 1st column of the F4 screen to "Formularname"

  • 8/22/2019 Demo Prog

    5/33

    *and not "Objectname"call function 'DDIF_FIELDINFO_GET'

    exportingtabname = 'THRFORMS_01'langu = sy-languall_types = 'X'

    tablesdfies_tab = lt_field_tab

    exceptionsothers = 0.

    delete lt_field_tab where not fieldname eq 'INFONET'.

    loop at lt_field_tab into ls_field_tab.ls_field_tab-reptext = text-002.modify lt_field_tab from ls_field_tab.

    endloop.

    *add text for the second column "Beschreibung"call function 'DDIF_FIELDINFO_GET'

    exportingtabname = 'TINFONET_T_01'langu = sy-languall_types = 'X'

    tablesdfies_tab = lt_help_tabexceptionsothers = 0.

    delete lt_help_tab where not fieldname eq 'TEXT'.

    loop at lt_help_tab into ls_help_tab.ls_help_tab-offset = '16'.append ls_help_tab to lt_field_tab.

    endloop.

    *call F4 screen

    call function 'F4IF_INT_TABLE_VALUE_REQUEST'exportingretfield = 'INFONET'dynpprog = lv_dynpro_progdynpnr = '1000'dynprofield = 'P_FNAME'window_title = text-002value_org = 'S'

    tablesvalue_tab = lt_value_tabfield_tab = lt_field_tab

    exceptionsparameter_error = 1

    no_values_found = 2others = 3.

    if sy-subrc 0.ox_error = 1.perform error_msg using sy-msgty sy-msgid sy-msgno

    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4c_save_error_msg.

    endif.endform. " select_data_f4*&---------------------------------------------------------------------*

  • 8/22/2019 Demo Prog

    6/33

    *& Form error_msg*&---------------------------------------------------------------------*form error_msg using iv_msgty type symsgty

    iv_msgid type symsgidiv_msgno type symsgnoiv_msgv1 type symsgviv_msgv2 type symsgviv_msgv3 type symsgviv_msgv4 type symsgvix_save_or_output type c.

    statics ss_symsg type symsg.if ix_save_or_output eq c_save_error_msg.

    clear ss_symsg.ss_symsg-msgty = iv_msgty.ss_symsg-msgid = iv_msgid.ss_symsg-msgno = iv_msgno.ss_symsg-msgv1 = iv_msgv1.ss_symsg-msgv2 = iv_msgv2.ss_symsg-msgv3 = iv_msgv3.ss_symsg-msgv4 = iv_msgv4.

    elseif ix_save_or_output eq c_output_error_msg.if not ss_symsg is initial.if iv_msgty is initial. "message type not forced

    message id ss_symsg-msgid type ss_symsg-msgty number ss_symsg-msgno

    with ss_symsg-msgv1 ss_symsg-msgv2 ss_symsg-msgv3 ss_symsg-msgv4.else. "message type forced (prevents dumps at F4s)message id ss_symsg-msgid type iv_msgty number ss_symsg-msgno

    with ss_symsg-msgv1 ss_symsg-msgv2 ss_symsg-msgv3 ss_symsg-msgv4.endif.clear ss_symsg.

    endif.endif. "save or output message ?

    endform. "error_msg*&---------------------------------------------------------------------**& Form SUB_DISPLAY*&---------------------------------------------------------------------** text

    *----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    7/33

    importingf_current_begda = gv_start_datef_current_endda = gv_end_date

    changingf_current_period = lv_pabrpf_current_year = lv_pabrj

    exceptionspcr_does_not_exist = 1abkrs_does_not_exist = 2period_does_not_exist = 3others = 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.

    loop at gt_mail into gs_mail.

    lv_frac = frac( lv_cont / 2 ).if lv_frac > 0.format color col_normal intensified on inverse off.

    else.format color col_normal intensified off inverse off.

    endif.

    clear gv_check.if p_check is initial.write:/3 gv_check as checkbox input on,

    8 '|'.else.write:/3 gv_check as checkbox input off,

    8 '|'.endif.clear gv_stat.gv_stat = '@5B@'.if gs_mail-mflag is initial.gv_stat = '@5D@'.

    gt_log-pernr = gs_mail-pernr.gt_log-class = '00'.gt_log-msgno = '398'.gt_log-msgv1 = 'There is no'.gt_log-msgv2 = 'Email ID'.gt_log-sever = 'W'.append gt_log.

    endif.

    clear lv_indctr.* subroutine to check whether the finnce posting is done for the employee in thegiven period or not

    perform sub_check_post_pernr using gs_mail-pernr

    changing lv_indctr.

    if lv_indctr = 'X'.gv_stat = '@5C@'.

    endif.

    write: 9(6) gv_stat.write: 16 '|',

    17(10) gs_mail-pernr hotspot on,28 '|',

  • 8/22/2019 Demo Prog

    8/33

    29(30) gs_mail-ename,60 '|',61(40) gs_mail-usrid,102 '|'.

    hide gs_mail.

    lv_cont = lv_cont + 1.

    endloop.if p_check is not initial.

    if gt_log[] is not initial.message s003(zemami_message) with 'Please see Error Log!'.

    endif.endif.

    endform. " SUB_DISPLAY*&---------------------------------------------------------------------**& Form SUB_HEADING*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    9/33

    read line lv_cnt index sy-lsind field value gv_check into lv_chkgv_stat into lv_stat.

    if sy-subrc 0.exit.

    endif.if lv_chk = ' ' and lv_stat = '@5B@'.modify line lv_cnt index sy-lsind field value gv_check from 'X'.

    endif.lv_cnt = lv_cnt + 1.

    enddo.

    endform. " SUB_SELECT_ALL*&---------------------------------------------------------------------**& Form SUB_DESELECT_ALL*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    10/33

    clear: gv_selec,gv_sent,bin_size.

    * to get the calender period from payroll area and fi periodcall function 'PA03_PERIODDATES_GET'

    exportingf_abkrs = lv_abkrs

    importingf_current_begda = gv_start_datef_current_endda = gv_end_date

    changingf_current_period = lv_pabrpf_current_year = lv_pabrj

    exceptionspcr_does_not_exist = 1abkrs_does_not_exist = 2period_does_not_exist = 3others = 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.

    *-- setup the print parmaterscall function 'GET_PRINT_PARAMETERS'exportingauthority = spacecopies = '1'cover_page = spacedata_set = spacedepartment = spacedestination = spaceexpiration = '1'immediately = spacenew_list_id = 'X'no_dialog = 'X'

    user = sy-unameimportingout_parameters = mstr_print_parmsvalid = mc_valid

    exceptionsarchive_info_not_found = 1invalid_print_params = 2invalid_archive_params = 3others = 4.

    describe table gt_selected lines gv_selec.

    loop at gt_selected into ls_selected.

    if ls_selected-usrid is initial.gt_log-pernr = ls_selected-pernr.gt_log-class = '00'.gt_log-msgno = '398'.gt_log-msgv1 = 'There is no'.gt_log-msgv2 = 'Email ID'.gt_log-sever = 'W'.append gt_log.

  • 8/22/2019 Demo Prog

    11/33

    continue.endif.clear: job_name,

    job_cnt,lv_indctr,gv_seqnr,gs_seqnr,gt_mess_att,gt_mess_bod,gt_log.

    refresh: gt_seqnr,gt_mess_att,gt_mess_bod.

    * subroutine to check whether the finnce posting is done for the employee in thegiven period or not

    perform sub_check_post_pernr using ls_selected-pernrchanging lv_indctr.

    if lv_indctr = 'X'.continue.

    endif.concatenate 'PAY' ls_selected-pernr sy-datum sy-uzeit into job_name.call function 'JOB_OPEN'exporting

    jobname = job_nameimportingjobcount = job_cnt

    exceptionscant_create_job = 1invalid_job_data = 2jobname_missing = 3others = 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.

    * submitting the spool requestsubmit (gv_report) "#EC CI_SUBMITto sap-spoolspool parameters mstr_print_parmswithout spool dynprovia job job_name number job_cntwith pnptimed eq pnptimed "curr period, other period, etcwith pnpbegda eq pnpbegda "selection begin datewith pnpendda eq pnpendda "selection end datewith pnpxabkr eq pnpxabkr "payroll periodwith pnppabrp eq pnppabrpwith pnppabrj eq pnppabrj

    with pnppayty eq pnppaytywith pnppayid eq pnppayidwith pnpbondt eq pnpbondtwith pnppernr eq ls_selected-pernr"IN pnppernr "pernrs"WITH pnpabkrs IN pnpabkrs "payroll periods

    *UNNI - 1122174 - passing PNP Personnel Area table - Beginwith pnpwerks in pnpwerks

    *UNNI - 1122174 - End of changes*UNNI - 1102750 - passing sort tables - Begin

    with pnpsort eq pnpsort

  • 8/22/2019 Demo Prog

    12/33

    with pnpsortt eq pnpsortt*UNNI - 1102750 - End of changes*KVHN1459714 - Starts

    with pnpansvh in pnpansvhwith pnpbtrtl in pnpbtrtlwith pnpbukrs in pnpbukrswith pnpename in pnpenamewith pnpfistl in pnpfistlwith pnpfkber in pnpfkberwith pnpgeber in pnpgeberwith pnpgsber in pnpgsberwith pnpjuper in pnpjuperwith pnpkokrs in pnpkokrswith pnpkostl in pnpkostlwith pnporgeh in pnporgehwith pnppersg in pnppersgwith pnppersk in pnpperskwith pnpplans in pnpplanswith pnpsacha in pnpsachawith pnpsachp in pnpsachpwith pnpsachz in pnpsachzwith pnpsname in pnpsnamewith pnpstat1 in pnpstat1with pnpstat2 in pnpstat2

    with pnpstat3 in pnpstat3with pnpstell in pnpstellwith pnpvdsk1 in pnpvdsk1

    *KVHN1459714 - Endswith p_popup eq p_popup "show print popup switchand return.

    call function 'JOB_CLOSE'exporting

    jobcount = job_cntjobname = job_namestrtimmed = 'X'

    exceptions

    cant_start_immediate = 1invalid_startdate = 2jobname_missing = 3job_close_failed = 4job_nosteps = 5job_notex = 6lock_failed = 7invalid_target = 8others = 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.

    commit work.if sy-subrc = 0.do.

    * selecting from tbtcp table the spool idselect single *from tbtcpwhere jobname = job_name and

    jobcount = job_cnt andstepcount = 1 and

  • 8/22/2019 Demo Prog

    13/33

    listident '0000000000'.if sy-subrc = 0.exit.

    endif.enddo.

    endif.

    *converting the spool request into pdfdata lv_listident type tsp01-rqident.move tbtcp-listident to lv_listident.data lv_flag type i value 0.data lv_status type tbtcjob-status.

    lv_listident = lv_listident - 1.

    call function 'RSPO_GET_PAGES_SPOOLJOB'exporting

    rqident = lv_listidentimporting

    rq = gs_tsp01exceptions

    no_such_job = 1others = 2.

    if sy-subrc 0.gt_error-pernr = ls_selected-pernr.gt_error-arbgb = '00'.gt_error-msgno = '398'.gt_error-msgv1 = 'No Payslip Data for the Employee'.gt_error-msgv2 = 'In the given Period'.gt_error-arbgb = 'E'.append gt_error.continue.

    elseif gs_tsp01-rq0name 'HRFORM'.gt_error-pernr = ls_selected-pernr.gt_error-arbgb = '00'.

    gt_error-msgno = '398'.gt_error-msgv1 = 'No Payslip for the Employee'.gt_error-msgv2 = 'In the given Period'.gt_error-arbgb = 'E'.append gt_error.continue.

    else.call function 'CONVERT_OTFSPOOLJOB_2_PDF'

    exportingsrc_spoolid = lv_listidentno_dialog = 'X'pdf_destination = 'X'

    no_background = 'X'importingpdf_bytecount = bin_sizebin_file = pdf_xstring

    tablespdf = it_pdf

    exceptionserr_no_otf_spooljob = 1err_no_spooljob = 2err_no_permission = 3

  • 8/22/2019 Demo Prog

    14/33

    err_conv_not_possible = 4err_bad_dstdevice = 5user_cancelled = 6err_spoolerror = 7err_temseerror = 8err_btcjob_open_failed = 9err_btcjob_submit_failed = 10err_btcjob_close_failed = 11others = 12.

    if sy-subrc 0.gt_log-pernr = ls_selected-pernr.gt_log-class = sy-msgid.gt_log-msgno = sy-msgno.gt_log-msgv1 = sy-msgv1.gt_log-msgv2 = sy-msgv2.gt_log-msgv3 = sy-msgv3.gt_log-msgv4 = sy-msgv4.gt_log-sever = sy-msgty.append gt_log.

    else.lv_flag = 1.

    endif.endif.

    check sy-subrc = 0.

    do.

    call function 'BP_JOB_CHECKSTATE'exportingdialog = 'N'jobcount = job_cntjobname = job_name

    importingactual_status = lv_status

    exceptionschecking_of_job_has_failed = 1

    correcting_job_status_failed = 2invalid_dialog_type = 3job_does_not_exist = 4no_check_privilege_given = 5ready_switch_too_dangerous = 6others = 7.

    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 lv_status = 'F'.exit.

    endif.

    enddo.

    data lv_spoolid type tsp01_sp0r-rqid_char.move tbtcp-listident to lv_spoolid.call function 'RSPO_R_RDELETE_SPOOLREQ'exporting

    spoolid = lv_spoolid.clear lv_spoolid.

  • 8/22/2019 Demo Prog

    15/33

    move lv_listident to lv_spoolid.call function 'RSPO_R_RDELETE_SPOOLREQ'exporting

    spoolid = lv_spoolid.call function 'BP_JOB_DELETE'exporting

    jobcount = job_cntjobname = job_name

    exceptionscant_delete_event_entry = 1cant_delete_job = 2cant_delete_joblog = 3cant_delete_steps = 4cant_delete_time_entry = 5cant_derelease_successor = 6cant_enq_predecessor = 7cant_enq_successor = 8cant_enq_tbtco_entry = 9cant_update_predecessor = 10cant_update_successor = 11commit_failed = 12jobcount_missing = 13jobname_missing = 14job_does_not_exist = 15

    job_is_already_running = 16no_delete_authority = 17others = 18.

    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 lv_flag = 1.

    * CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'* EXPORTING* line_width_dst = 255

    * TABLES* content_in = it_pdf* content_out = gt_mess_att* EXCEPTIONS* err_line_width_src_too_long = 1* err_line_width_dst_too_long = 2* err_conv_failed = 3* OTHERS = 4.

    pdf_size = bin_size.* to prepare the mail and send it to the mail id of the employee

    move ls_selected-usrid to gv_mail_id.if p_check is initial.

    perform sub_send using gv_mail_idls_selected-pernr.

    * PERFORM sub_send_email USING gv_mail_id* ls_selected-pernr.

    endif.

    endif.endloop.

    * to display mail error logperform sub_show_mail_error_log.

  • 8/22/2019 Demo Prog

    16/33

    endform. " SUB_SEND_MAIL*&---------------------------------------------------------------------**& Form SUB_GET_DATA*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    17/33

    gs_name.endloop.

    sort gt_mail by pernr.delete adjacent duplicates from gt_mail comparing pernr.

    endform. " SUB_GET_DATA*&---------------------------------------------------------------------**& Module STATUS_2000 OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*module status_2000 output.

    * SET PF-STATUS 'ZMAIL'.* SET TITLEBAR 'ZMAIL'.

    endmodule. " STATUS_2000 OUTPUT*&---------------------------------------------------------------------**& Module USER_COMMAND_2000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*module user_command_2000 input.

    * CASE ok_code.* WHEN 'ACCEPT'.* CLEAR ok_code.* IF email IS NOT INITIAL.* PERFORM sub_update_mail.* ELSE.* MESSAGE 'No Email ID is Entered!!' TYPE 'W'.* ENDIF.* WHEN 'CANCEL'.* CLEAR ok_code.* LEAVE SCREEN.* ENDCASE.

    endmodule. " USER_COMMAND_2000 INPUT*&---------------------------------------------------------------------**& Module SUB_DISPLAY OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*module sub_display output.

    * empid = gv_pernr_sel.* empname = gv_name_sel.

    endmodule. " SUB_DISPLAY OUTPUT*&---------------------------------------------------------------------*

    *& Form SUB_UPDATE_MAIL*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    18/33

    move email to lv_email.call function 'ZEMAMI_UPDATE_MAIL'

    exportingpernr = gv_pernremail = lv_email

    tablesmessage = message.

    leave screen.

    endform. " SUB_UPDATE_MAIL*&---------------------------------------------------------------------**& Form SUB_LINE_SELECTION*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    19/33

    clear gs_sval.sy-lsind = sy-lsind - 1.

    clear gv_return.call function 'POPUP_GET_VALUES'

    exportingpopup_title = 'Email ID'

    importingreturncode = gv_return

    tablesfields = gt_sval

    exceptionserror_in_fields = 1others = 2.

    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 gv_return 'A'.read table gt_sval into gs_sval index 3.if gs_sval-value is not initial.

    move gs_sval-value to gv_mail.call function 'ZEMAMI_UPDATE_MAIL'exporting

    pernr = gs_mail-pernremail = gv_mailflag = gv_flag

    tablesmessage = gt_message.

    data lv_indctr type c.* subroutine to check whether the finnce posting is done for the employee in thegiven period or not

    perform sub_check_post_pernr using lv_pernrchanging lv_indctr.

    if lv_indctr = 'X'.modify line sy-lilli index sy-lsind field value gs_mail-usrid from gs_

    sval-value gv_stat from '@5C@'.elseif lv_indctr = ' '.modify line sy-lilli index sy-lsind field value gs_mail-usrid from gs_

    sval-valuegv_stat from '@5B@'.

    endif.

    gs_0105-usrid_long = gv_mail.modify table gt_0105 from gs_0105.clear: gv_mail,

    gs_0105,gv_flag.

    endif.

    endif.

    endif.

    endform. " SUB_LINE_SELECTION*&---------------------------------------------------------------------**& Form SUB_SHOW_PAYSLIP*&---------------------------------------------------------------------*

  • 8/22/2019 Demo Prog

    20/33

    * text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    21/33

    * expiration = '1'* immediately = space* new_list_id = 'X'* no_dialog = 'X'* user = sy-uname* importing* out_parameters = mstr_print_parms* valid = mc_valid* exceptions* archive_info_not_found = 1* invalid_print_params = 2* invalid_archive_params = 3* others = 4.** concatenate 'PAY' lv_pernr sy-datum sy-uzeit into job_name.* call function 'JOB_OPEN'* exporting* jobname = job_name* importing* jobcount = job_cnt* 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.**** submitting the spool request* submit (gv_report) "#EC CI_SUBMIT* to sap-spool* spool parameters mstr_print_parms* without spool dynpro* via job job_name number job_cnt

    * with pnptimed eq pnptimed "curr period, other period, etc* with pnpbegda eq pnpbegda "selection begin date* with pnpendda eq pnpendda "selection end date* with pnpxabkr eq pnpxabkr "payroll period* with pnppabrp eq pnppabrp* with pnppabrj eq pnppabrj* with pnppayty eq pnppayty* with pnppayid eq pnppayid* with pnpbondt eq pnpbondt* with pnppernr eq lv_pernr"IN pnppernr "pernrs* with pnpabkrs in pnpabkrs "payroll periods**UNNI - 1122174 - passing PNP Personnel Area table - Begin* with pnpwerks in pnpwerks

    **UNNI - 1122174 - End of changes**UNNI - 1102750 - passing sort tables - Begin* with pnpsort eq pnpsort* with pnpsortt eq pnpsortt**UNNI - 1102750 - End of changes**KVHN1459714 - Starts* with pnpansvh in pnpansvh* with pnpbtrtl in pnpbtrtl* with pnpbukrs in pnpbukrs* with pnpename in pnpename

  • 8/22/2019 Demo Prog

    22/33

    * with pnpfistl in pnpfistl* with pnpfkber in pnpfkber* with pnpgeber in pnpgeber* with pnpgsber in pnpgsber* with pnpjuper in pnpjuper* with pnpkokrs in pnpkokrs* with pnpkostl in pnpkostl* with pnporgeh in pnporgeh* with pnppersg in pnppersg* with pnppersk in pnppersk* with pnpplans in pnpplans* with pnpsacha in pnpsacha* with pnpsachp in pnpsachp* with pnpsachz in pnpsachz* with pnpsname in pnpsname* with pnpstat1 in pnpstat1* with pnpstat2 in pnpstat2* with pnpstat3 in pnpstat3* with pnpstell in pnpstell* with pnpvdsk1 in pnpvdsk1**KVHN1459714 - Ends* with p_popup eq p_popup "show print popup switch* and return.*

    * call function 'JOB_CLOSE'* exporting* jobcount = job_cnt* jobname = job_name* strtimmed = 'X'* 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.** commit work.* if sy-subrc = 0.* do.** selecting from tbtcp table the spool id* select single ** from tbtcp

    * where jobname = job_name and* jobcount = job_cnt and* stepcount = 1 and* listident '0000000000'.* if sy-subrc = 0.* exit.* endif.* enddo.* endif.*

  • 8/22/2019 Demo Prog

    23/33

    ***converting the spool request into pdf* data lv_listident type tsp01-rqident.* data lt_otf type tsfotf.* data lv_flag type i value 0.* data lv_status type tbtcjob-status.* move tbtcp-listident to lv_listident.* lv_listident = lv_listident - 1.** call function 'RSPO_GET_PAGES_SPOOLJOB'* exporting* rqident = lv_listident* importing* rq = gs_tsp01* exceptions* no_such_job = 1* others = 2.* if sy-subrc 0.* message ' No Payslip for the Employee in this period!' type 'S'.* elseif gs_tsp01-rq0name 'HRFORM'.* message ' No Payslip for the Employee in this period!' type 'S'.* else.* call function 'RSPO_RETURN_SPOOLJOB'* exporting

    * rqident = lv_listident* tables* buffer = lt_otf* exceptions* no_such_job = 1* job_contains_no_data = 2* selection_empty = 3* no_permission = 4* can_not_access = 5* read_error = 6* type_no_match = 7* others = 8.* if sy-subrc 0.

    * message id sy-msgid type sy-msgty number sy-msgno* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.* else.* lv_flag = 1.* endif.* endif.**** check sy-subrc = 0.** do.*

    * call function 'BP_JOB_CHECKSTATE'* exporting* dialog = 'N'* jobcount = job_cnt* jobname = job_name* importing* actual_status = lv_status* exceptions* checking_of_job_has_failed = 1* correcting_job_status_failed = 2

  • 8/22/2019 Demo Prog

    24/33

    * invalid_dialog_type = 3* job_does_not_exist = 4* no_check_privilege_given = 5* ready_switch_too_dangerous = 6* others = 7.* 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 lv_status = 'F'.* exit.* endif.** enddo.* data lv_spoolid type tsp01_sp0r-rqid_char.* move tbtcp-listident to lv_spoolid.* call function 'RSPO_R_RDELETE_SPOOLREQ'* exporting* spoolid = lv_spoolid.* clear lv_spoolid.* move lv_listident to lv_spoolid.* call function 'RSPO_R_RDELETE_SPOOLREQ'* exporting

    * spoolid = lv_spoolid.* call function 'BP_JOB_DELETE'* exporting* jobcount = job_cnt* jobname = job_name* 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.** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    ** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.* endif.** if lv_flag = 1.** displaying payslip* call function 'HR_EFI_SHOW_PDF_FORM'* tables* otf_table = lt_otf.** endif.

  • 8/22/2019 Demo Prog

    25/33

    endform. " SUB_SHOW_PAYSLIP*&---------------------------------------------------------------------**& Form SUB_DISABLE_FIELDS*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    26/33

    exit.endif.read table gt_seqnr into gs_seqnr index lv_lines.gv_seqnr = gs_seqnr-seqnr.

    * to check whether the finance posting is done or notcall function 'HR_EVAL_PROD_A_RUN_GET'

    exportingperno = p_pernrseqno = gv_seqnr

    importingrun_not_posted = lv_post

    exceptionsno_run_found = 1others = 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 lv_post = 'X'.gt_log-pernr = p_pernr.gt_log-class = '00'.gt_log-msgno = '398'.

    gt_log-msgv1 = 'Account Posting'.gt_log-msgv2 = 'Not Found'.gt_log-sever = 'E'.append gt_log.p_indctr = 'X'.exit.

    endif.

    endform. " SUB_CHECK_POST_PERNR*&---------------------------------------------------------------------**& Form SUB_SHOW_ERROR_LOG*&---------------------------------------------------------------------** text

    *----------------------------------------------------------------------** --> p1 text* = 1.call function 'HR_BEN_SHOW_ERROR_LOG'exporting

    title = 'ERROR LOG'tree_text = 'ERROR'

    tableserror_table = gt_log.

    endif.endform. " SUB_SHOW_ERROR_LOG*&---------------------------------------------------------------------*

  • 8/22/2019 Demo Prog

    27/33

    *& Form SUB_GET_SELECTED_EMP*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    28/33

    * with all the parameters and attachment sending the mailperform send_file_as_email_attachment

    tables gt_mess_bodgt_mess_att

    using p_mail_id'Payslip Attachment''PDF'gd_attachment_namegd_attachment_descgv_sendergd_sender_typegd_subjectp_pernr

    changing gd_errorgd_reciever.

    endform. " SUB_SEND_EMAIL*&---------------------------------------------------------------------**& Form SEND_FILE_AS_EMAIL_ATTACHMENT*&---------------------------------------------------------------------** Send email*----------------------------------------------------------------------*form send_file_as_email_attachment

    tables it_messageit_attachusing p_email

    p_mtitlep_formatp_filenamep_attdescriptionp_sender_addressp_sender_addres_typep_subjectp_pernr

    changing p_errorp_reciever.

    data: ld_error type sy-subrc,ld_reciever type sy-subrc,ld_mtitle like sodocchgi1-obj_descr,ld_email like somlreci1-receiver,ld_format type so_obj_tp ,ld_attdescription type so_obj_nam ,ld_attfilename type so_obj_des ,ld_sender_address like soextreci1-receiver,ld_sender_address_type like soextreci1-adr_typ,ld_receiver like sy-subrc,t_header type standard table of solisti1 with header line.

    data: t_packing_list like sopcklsti1 occurs 0 with header line,t_contents like solisti1 occurs 0 with header line,

    t_receivers like somlreci1 occurs 0 with header line,t_attachment like solisti1 occurs 0 with header line,t_object_header like solisti1 occurs 0 with header line,w_cnt type i,w_sent_all(1) type c,w_doc_data like sodocchgi1 .

    ld_email = p_email.ld_mtitle = p_mtitle.ld_format = p_format.

  • 8/22/2019 Demo Prog

    29/33

    ld_attdescription = p_attdescription.ld_attfilename = p_filename.ld_sender_address = p_sender_address.ld_sender_address_type = p_sender_addres_type.t_header-line = p_subject.append t_header.

    * fill the document data.w_doc_data-doc_size = 1.

    * populate the subject/generic message attributesw_doc_data-obj_langu = sy-langu.w_doc_data-obj_name = 'SAPRPT'.w_doc_data-obj_descr = ld_mtitle .w_doc_data-sensitivty = 'F'.

    * fill the document data and get size of attachmentclear w_doc_data.describe table it_attach lines w_cnt.read table it_attach index w_cnt.w_doc_data-doc_size =

    ( w_cnt - 1 ) * 255 + strlen( it_attach ).w_doc_data-obj_langu = sy-langu.w_doc_data-obj_name = 'SAPRPT'.w_doc_data-obj_descr = ld_mtitle.w_doc_data-sensitivty = 'F'.

    clear t_attachment.refresh t_attachment.t_attachment = it_attach.t_attachment[] = it_attach[].

    * describe the body of the messageclear t_packing_list.refresh t_packing_list.t_packing_list-transf_bin = space.t_packing_list-head_start = 1.t_packing_list-head_num = 0.t_packing_list-body_start = 1.describe table it_message lines t_packing_list-body_num.

    t_packing_list-doc_type = 'RAW'.append t_packing_list.

    * create attachment notificationt_packing_list-transf_bin = 'X'.t_packing_list-head_start = 1.t_packing_list-head_num = 1.t_packing_list-body_start = 1.describe table t_attachment lines t_packing_list-body_num.t_packing_list-doc_type = ld_format.t_packing_list-obj_descr = ld_attdescription.t_packing_list-obj_name = ld_attfilename.t_packing_list-doc_size = t_packing_list-body_num * 255.

    append t_packing_list.

    * add the recipients email addressclear t_receivers.refresh t_receivers.t_receivers-receiver = ld_email.t_receivers-rec_type = 'U'.t_receivers-com_type = 'INT'.t_receivers-notif_del = 'X'.t_receivers-notif_ndel = 'X'.

  • 8/22/2019 Demo Prog

    30/33

    append t_receivers.

    * to send the mail with attachmentcall function 'SO_DOCUMENT_SEND_API1'

    exportingdocument_data = w_doc_datasender_address = ld_sender_addresssender_address_type = ld_sender_address_typecommit_work = 'X'

    importingsent_to_all = w_sent_all

    tablesobject_header = t_headerpacking_list = t_packing_listcontents_bin = t_attachmentcontents_txt = it_messagereceivers = t_receivers

    exceptionstoo_many_receivers = 1document_not_sent = 2document_type_not_exist = 3operation_no_authorization = 4parameter_error = 5x_error = 6

    enqueue_error = 7others = 8.if sy-subrc 0.

    gt_error-pernr = p_pernr.gt_error-arbgb = sy-msgid.gt_error-msgno = sy-msgno.gt_error-msgv1 = sy-msgv1.gt_error-msgv2 = sy-msgv2.gt_error-msgv3 = sy-msgv3.gt_error-msgv4 = sy-msgv4.gt_error-msgty = 'E'.append gt_error.

    else.

    gv_sent = gv_sent + 1.endif.* populate zerror return codeld_error = sy-subrc.

    endform. "SEND_eMAIL*&---------------------------------------------------------------------**& Form SUB_SHOW_MAIL_ERROR_LOG*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text*

  • 8/22/2019 Demo Prog

    31/33

    ted by ' '.

    data lv_count type i.sort gt_error[].delete adjacent duplicates from gt_error[].describe table gt_error lines lv_count.

    if lv_count < 1.gt_error-arbgb = '00'.gt_error-msgty = 'S'.gt_error-msgno = '398'.gt_error-msgv1 = 'All mails sent successfully'.append gt_error.

    endif.

    call function 'HR_DISPLAY_ERROR_LIST'exportingno_print = 'X'no_img = ' 'no_msgno = 'X'linesize = sy-linszlistheader = lv_msgcolheader = 'Message'

    tables

    error = gt_errorexceptionsinvalid_linesize = 1others = 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. " SUB_SHOW_MAIL_ERROR_LOG*&---------------------------------------------------------------------**& Form SUB_SEND*&---------------------------------------------------------------------*

    * text*----------------------------------------------------------------------** -->P_GV_MAIL_ID text* -->P_LS_SELECTED_PERNR text*----------------------------------------------------------------------*form sub_send using mail_id

    selected_pernr.

    data: lv_body type soli_tab,lt_message_body type bcsy_text value is initial,lv_body1 type soli,lv_header type soli_tab,lv_string type string,

    lv_date1 type char10,lv_date2 type char10,lv_vorna type pa0002-vorna,lv_nachn type pa0002-nachn,lv_midnm type pa0002-midnm,lv_anred type pa0002-anred,lv_name type string,lv_atext type char5,lv_ename type string.

  • 8/22/2019 Demo Prog

    32/33

    clear: send_request,pdf_content,document,recipient,sent_to_all.

    * fetching the name of the employeeselect single vorna

    midnmnachnanred

    from pa0002into (lv_vorna , lv_midnm , lv_nachn , lv_anred)where pernr = selected_pernr and

    begda = gv_end_date.

    select single atextfrom t522tinto lv_atextwhere sprsl = 'E' and

    anred = lv_anred.

    if lv_midnm is initial.concatenate lv_atext '.' lv_vorna into lv_name.

    else.concatenate lv_atext '.' lv_vorna ' ' lv_midnm into lv_name.endif.

    concatenate 'Dear' lv_name lv_nachn ',' into lv_ename separated by ' '.

    write gv_start_date to lv_date1.write gv_end_date to lv_date2.concatenate 'Please find the attached Payslip for period' lv_date1 '-' lv_date

    2 into lv_string separated by ' '.append lv_ename to lt_message_body.append '' to lt_message_body.append lv_string to lt_message_body.

    append '' to lt_message_body.** CONCATENATE '***Wishing you and your family a very Happy Durga Puja***' '.'into lv_string SEPARATED BY ' '.** APPEND lv_string TO lt_message_body.** APPEND '' TO lt_message_body.** APPEND '' TO lt_message_body.append 'Thank you,' to lt_message_body.append 'EMAMI Ltd.' to lt_message_body.

    move mail_id to mailto.try.

    * create persistent send request

    send_request = cl_bcs=>create_persistent( ).

    * create and set documentpdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).

    document = cl_document_bcs=>create_document(i_type = 'RAW'i_text = lt_message_bodyi_subject = 'Payslip' ).

  • 8/22/2019 Demo Prog

    33/33

    * attaching payslipdocument->add_attachment(

    exportingi_attachment_type = 'PDF'i_attachment_subject = 'Payslip'i_attachment_size = pdf_sizei_att_content_hex = pdf_content ).

    * document = cl_document_bcs=>create_document(* i_type = 'PDF'* "i_text = lv_body* i_hex = pdf_content* i_length = pdf_size* "i_header = lv_header* i_subject = 'Payslip' ).

    * add document object to send requestsend_request->set_document( document ).

    * add recipient (e-mail address)* create recipient object

    recipient = cl_cam_address_bcs=>create_internet_address( mailto ).

    * add recipient object to send request

    send_request->add_recipient( recipient ).

    * send documentsent_to_all = send_request->send( i_with_error_screen = 'X' ).

    commit work.

    if sent_to_all is initial.gt_error-pernr = selected_pernr.message i500(sbcoms) with mailto into gt_error-msgv1.gt_error-msgty = 'E'.append gt_error.

    else.

    gv_sent = gv_sent + 1.endif.

    * exception handlingcatch cx_bcs into bcs_exception.gt_error-pernr = selected_pernr.message i865(so) with bcs_exception->error_type into gt_error-msgv1.gt_error-msgty = 'E'.append gt_error.

    endtry.

    endform. " SUB_SEND