Wednesday 7 March 2012

Print program for Order confirmation(Form entry and print parameters)

report  zet05r0003.

*&---------------------------------------------------------------------*
*& Declare Data Object                                                 *
*&                                                                     *
*&---------------------------------------------------------------------*
include zet05r0003top.

include zet05r0003f01.

*---------------------------------------------------------------------*
*       FORM ENTRY
*---------------------------------------------------------------------*
form entry using prf_return_code type sy-subrc
                 prf_us_screen   type c.              "#EC CALLED

  data: ldf_return type sy-subrc.

  gdf_xscreen = prf_us_screen.
  perform processing_outp using prf_us_screen
                       changing ldf_return.
  if ldf_return ne 0.
    prf_return_code = 1.
  else.
    prf_return_code = 0.
  endif.

endform.                    "entry

**************************************************************************
 
*&---------------------------------------------------------------------*
*&  Include           ZEL03R0010F01
*&---------------------------------------------------------------------*
*& renew date   transport No  change by         contents               *
*& 18.11.2011   EJ3K941377    702068010     Change print params        *
*& 21.12.2011    EJ3K943103   Swapna Narra  Fix for Email Functionality*
*&---------------------------------------------------------------------*
*&      Form  processing
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      -->PRF_SCREEN  prf_screen(us_screen)
*&      <--PRF_RETURN  prf_return(return_code)
*&---------------------------------------------------------------------*

form processing_outp  using    prf_screen type c
                 changing prf_return type sy-subrc.
*Smartform Call
  perform output_list using    prf_screen
                      changing prf_return.

endform.                    " processing

*&---------------------------------------------------------------------*
*&      Form  output_list
*&---------------------------------------------------------------------*
*       To Display the Smartform for Display
*----------------------------------------------------------------------*
*      -->PRF_SCREEN  prf_screen(us_screen)
*      <--PRF_RETURN  prf_return(return_code)
*----------------------------------------------------------------------*
form output_list  using    prf_screen  type c
                 changing  prf_return  type sy-subrc.
*Local Variables
  data: lds_control_param              type ssfctrlop.
  data: lds_composer_param             type ssfcompop.
  data: lds_recipient                  type swotobjid.
  data: lds_sender                     type swotobjid.
  data: ldf_form                       type tdsfname.
  data: ldf_fm_name                    type rs38l_fnam.
  data: lds_addr_key                   type addr_key.
*Local Constants.
  constants: lcf_blank(1value ''.

* If no reference key is passed, it'll be handled as an exception and exit the processing.
  if nast-objky is initial.
    perform nast_prot_updt.
*Exit from the Subroutine
    exit.
  endif.

  if prf_return = 0.
*In Case No Error Exists move the Name of Smartform.
    move tnapr-sform to ldf_form.
    perform get_data changing lds_addr_key
                             prf_return  .
*Setting the Print Parameters.
    perform set_print_param using    lds_addr_key
                            changing lds_control_param
                                     lds_composer_param
                                     lds_recipient
                                     lds_sender
                                     prf_return.

*Function Module Call for the Smartform.
    call function 'SSF_FUNCTION_MODULE_NAME'
      exporting
        formname           = ldf_form
      importing
        fm_name            = ldf_fm_name
      exceptions
        no_form            = 1
        no_function_module = 2
        others             = 3.
    if sy-subrc <> 0.
*Error Handling
      prf_return = sy-subrc.
      if prf_screen = lcf_blank.
*Error Logging is Performed
        perform protocol_update.
      endif.
    endif.
  endif.

*In Case There are no Errors the Smartform Handling is done here.
  if prf_return = 0.
*   call smartform
    call function ldf_fm_name
      exporting
        control_parameters = lds_control_param
        mail_recipient     = lds_recipient
        mail_sender        = lds_sender
        output_options     = lds_composer_param
        user_settings      = lcf_blank
        i_nast             = nast
      exceptions
        formatting_error   = 1
        internal_error     = 2
        send_error         = 3
        user_canceled      = 4
        others             = 5.
    if sy-subrc <> 0.
*Error handling
      prf_return = sy-subrc.

      if prf_screen = lcf_blank.
*Error Logging is Performed
        perform protocol_update.
      endif.
*Get SmartForm protocol and store it in the NAST protocoll
      perform add_smfrm_prot.
    endif.
  endif.
endform.                    " output_list

*---------------------------------------------------------------------*
*       FORM PROTOCOL_UPDATE                                          *
*---------------------------------------------------------------------*
*       The messages are collected for the processing protocol.       *
*---------------------------------------------------------------------*

form protocol_update.

  check gdf_xscreen = space.

*Funtion Module Call for Error Logging
  perform nast_prot_updt.

endform.                    "PROTOCOL_UPDATE

*&---------------------------------------------------------------------*
*&      Form  ADD_SMFRM_PROT
*&---------------------------------------------------------------------*
form add_smfrm_prot.

  data: ldt_errortab             type tsferror.
  field-symbols: <fs_errortab>   type line of tsferror.
  constants: lcf_e(1)            value 'E'.

*Get smart form protocoll
  call function 'SSF_READ_ERRORS'
    importing
      errortab = ldt_errortab.

* add smartform protocoll to nast protocoll
  loop at ldt_errortab assigning <fs_errortab>.

*Updating the Error Log
    call function 'NAST_PROTOCOL_UPDATE'
      exporting
        msg_arbgb              = <fs_errortab>-msgid
        msg_nr                 = <fs_errortab>-msgno
        msg_ty                 = <fs_errortab>-msgty
        msg_v1                 = <fs_errortab>-msgv1
        msg_v2                 = <fs_errortab>-msgv2
        msg_v3                 = <fs_errortab>-msgv3
        msg_v4                 = <fs_errortab>-msgv4
      exceptions
        message_type_not_valid = 1
        no_sy_message          = 2
        others                 = 3.
    if sy-subrc <> 0.
      message id sy-msgid type lcf_e number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
  endloop.

endform.                               " ADD_SMFRM_PROT

*&---------------------------------------------------------------------*
*&      Form  SET_PRINT_PARAM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      -->  prs_addr_key
*&      <--  prs_control_param
*&      <--  prs_composer_param
*&      <-- prs_recipient
*&      <-- prs_sender
*&      <-- prf_return
*&---------------------------------------------------------------------*

form set_print_param using    prs_addr_key       type addr_key
                     changing prs_control_param  type ssfctrlop
                              prs_composer_param type ssfcompop
                              prs_recipient      type swotobjid
                              prs_sender         type swotobjid
                              prf_return         type sy-subrc.
*Local Declarations.
  data: lds_itcpo     type itcpo.
  data: ldf_repid     type sy-repid.
  data: ldf_device    type tddevice.
*Program Name
  ldf_repid = sy-repid.
*Local Constants.
  constants: lcf_x(1value 'X'.
*Smartform Conditions.
  call function 'WFMC_PREPARE_SMART_FORM'
    exporting
      pi_nast       = nast
      pi_addr_key   = prs_addr_key
      pi_repid      = ldf_repid
    importing
      pe_returncode = prf_return
      pe_itcpo      = lds_itcpo
      pe_device     = ldf_device
      pe_recipient  = prs_recipient
      pe_sender     = prs_sender.

  if prf_return = 0.
*Setting up the Display of Smartform.
    move-corresponding lds_itcpo to prs_composer_param.
    concatenate prs_composer_param-tdcovtitle
             space
             nast-objky
             into prs_composer_param-tdtitle.

*   prs_composer_param-tdnewid = lcf_x  .                  "<EJ3K941377
    prs_control_param-device      = ldf_device.
    prs_control_param-no_dialog   = lcf_x.
    prs_control_param-preview     = gdf_xscreen.
    prs_control_param-getotf      = lds_itcpo-tdgetotf.
    prs_control_param-langu       = nast-spras.
  endif.
endform.                               " SET_PRINT_PARAM

*&---------------------------------------------------------------------*
*&      Form  nast_prot_updt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form nast_prot_updt.
  constants: lcf_e(1value 'E'.
  call function 'NAST_PROTOCOL_UPDATE'
    exporting
      msg_arbgb              = syst-msgid
      msg_nr                 = syst-msgno
      msg_ty                 = syst-msgty
      msg_v1                 = syst-msgv1
      msg_v2                 = syst-msgv2
      msg_v3                 = syst-msgv3
      msg_v4                 = syst-msgv4
    exceptions
      message_type_not_valid = 1
      no_sy_message          = 2
      others                 = 3.
  if sy-subrc <> 0.
    message id sy-msgid type lcf_e number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.



endform.                    "nast_prot_updt
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LDS_ADDR_KEY  text
*----------------------------------------------------------------------*
form get_data  changing prf_addr_key type addr_key
                        prf_retcode  type sy-subrc.
  data: ldt_mess type standard table of vbfs,
        lds_mess like vbfs.
  databegin of ldt_vbdpa occurs 0.        "Internal table for items
          include structure vbdpa.
  dataend of ldt_vbdpa.
  data :lds_vbco3         type vbco3.

  lds_vbco3-mandt = sy-mandt.
  lds_vbco3-spras = nast-spras.
  lds_vbco3-vbeln = nast-objky.
  lds_vbco3-kunde = nast-parnr.
  lds_vbco3-parvw = nast-parvw.

  call function 'RV_DOCUMENT_PRINT_VIEW'
    exporting
      comwa                       = lds_vbco3
    importing
      kopf                        = vbdka
    tables
      pos                         = ldt_vbdpa
      mess                        = ldt_mess
    exceptions
      fehler_bei_datenbeschaffung = 1.
  if sy-subrc ne 0.
    perform protocol_update.
    prf_retcode = 1.
    exit.
  else.
    loop at ldt_mess into lds_mess.
      sy-msgid = lds_mess-msgid.
      sy-msgno = lds_mess-msgno.
      sy-msgty = lds_mess-msgty.
      sy-msgv1 = lds_mess-msgv1.
      sy-msgv2 = lds_mess-msgv2.
      sy-msgv3 = lds_mess-msgv3.
      sy-msgv4 = lds_mess-msgv4.
      perform protocol_update.
    endloop.
  endif.
* fill address key --> necessary for emails
  prf_addr_key-addrnumber = vbdka-adrnr.
  prf_addr_key-persnumber = vbdka-adrnp.
  prf_addr_key-addr_type  = vbdka-address_type.
endform.                    " GET_DATA

1 comment:

  1. If nast-cmfpnr IS INITIAL, we should call 'NAST_PROTOCOL_STORE' after 'NAST_PROTOCOL_UPDATE' to create and save journal. inspite of it there will be nothing in Message detail -> Processing log

    ReplyDelete