Thursday, December 17, 2015

Smartforms Report



*&---------------------------------------------------------------------*
*& Program Name       :
*& Module Name        :
*& Sub-Module         :
*& Functional Analyst :
*& Programmer         :
*& Create Date        :
*& Program Type       :
*& Description        : Driver program
*& Transaction Code   :
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
*                    Modification Log                                  *
*----------------------------------------------------------------------*
* Date          Modified by            CTS number     Comments         *
*----------------------------------------------------------------------*
REPORT zpm0001
     NO STANDARD PAGE HEADING LINE-SIZE 255.
*----------------------------------------------------------------------*
*          T-Y-P-E P-O-O-L-S
*----------------------------------------------------------------------*
TYPE-POOLS: slis, sscr.
*----------------------------------------------------------------------*
*          T-A-B-L-E-S
*----------------------------------------------------------------------*
TABLES: qmel. "Quality Notification

DATA : it_tab1 TYPE TABLE OF tline,
       it_tab2  TYPE TABLE OF tline,
       it_tab3  TYPE TABLE OF tline.

DATA : lv_qmnum TYPE qmel-qmnum,
       lv_id     TYPE thead-tdid,
       lv_object TYPE thead-tdobject,
       lv_qname  TYPE thead-tdname.
*----------------------------------------------------------------------*
*          V-A-R-I-A-B-L-E-S
*----------------------------------------------------------------------*
DATA:
  gv_time      TYPE  maueh,
  gv_part      TYPE  z_part,
  gv_stopage   TYPE  zstopage,
  gv_ploss     TYPE  z_ploss,
  gv_impact    TYPE  z_impact,
  gv_action1   TYPE  z_action,
  gv_action2   TYPE  z_action,
  gv_action3   TYPE  z_action,
  gv_action4   TYPE  z_action,
  gv_action5   TYPE  z_action,
  gv_resp1     TYPE  z_resp,
  gv_resp2     TYPE  z_resp,
  gv_resp3     TYPE  z_resp,
  gv_resp4     TYPE  z_resp,
  gv_resp5     TYPE  z_resp,
  gv_due1      TYPE  z_duedate,
  gv_due2      TYPE  z_duedate,
  gv_due3      TYPE  z_duedate,
  gv_due4      TYPE  z_duedate,
  gv_due5      TYPE  z_duedate,
  gv_status1   TYPE  z_status,
  gv_status2   TYPE  z_status,
  gv_status3   TYPE  z_status,
  gv_status4   TYPE  z_status,
  gv_status5   TYPE  z_status,
  gv_comments1 TYPE  z_comments,
  gv_comments2 TYPE  z_comments,
  gv_comments3 TYPE  z_comments,
  gv_comments4 TYPE  z_comments,
  gv_comments5 TYPE  z_comments,
  gv_text1     TYPE  string,
  gv_text2     TYPE  string,
  gv_text3     TYPE  string.
*----------------------------------------------------------------------*
*          I-N-T-E-R-N-A-L T-A-B-L-E-S
*----------------------------------------------------------------------*
DATA: it_qmel TYPE STANDARD TABLE OF qmel.
DATA : gt_otf TYPE ssfcrescl, "Smart Forms: Return value at end of form printing
         gt_otf_f TYPE tsfotf.
*----------------------------------------------------------------------*
*          W-O-R-K A-R-E-A
*----------------------------------------------------------------------*
DATA: wa_qmel TYPE qmel.
*----------------------------------------------------------------------*
*          S-E-L-E-C-T-I-O-N S-C-R-E-E-N
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_qmnum TYPE qmel-qmnum OBLIGATORY. " VALUE CHECK,
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
*          I-N-I-T-I-A-L-I-Z-A-T-I-O-N
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
*                S-T-A-R-T O-F S-E-L-E-C-T-I-O-N
*----------------------------------------------------------------------*
START-OF-SELECTION.
*--get data
  PERFORM f_getdata.
*--output (calling smartform)
  PERFORM f_output.

END-OF-SELECTION.

FORM initilization.
  DATA: selopt   TYPE sscr_ass,
        opt_list TYPE sscr_opt_list,
        restrict TYPE sscr_restrict.

  CLEAR opt_list.
  opt_list-name = 'BT'.
  opt_list-options-bt    = 'X'.
  APPEND opt_list TO restrict-opt_list_tab.

  CLEAR selopt.
  selopt-kind            = 'S'.
  selopt-name            = 'S_DATE'.
  selopt-sg_main         = 'I'.
  selopt-sg_addy         = ' '.
  selopt-op_main         = 'BT'.
  selopt-op_addy         = 'BT'.
  APPEND selopt  TO restrict-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
    EXPORTING
      restriction            = restrict
    EXCEPTIONS
      too_late               = 1
      repeated               = 2
      selopt_without_options = 5
      selopt_without_signs   = 6
      invalid_sign           = 7
      empty_option_list      = 9
      invalid_kind           = 10
      repeated_kind_a        = 11
      OTHERS                 = 12.
ENDFORM.



FORM f_getdata.

  CLEAR : it_qmel,
          wa_qmel.

  SELECT * FROM qmel INTO TABLE it_qmel
                     WHERE qmnum = p_qmnum.
*--looping it_qmel
  CLEAR: gv_time,gv_part,gv_stopage,gv_ploss,gv_impact,
         gv_action1,gv_action2,gv_action3,gv_action4,gv_action5,
         gv_resp1,gv_resp2,gv_resp3,gv_resp4,gv_resp5,
         gv_due1,gv_due2,gv_due3,gv_due4,gv_due5,
         gv_status1,gv_status2,gv_status3,gv_status4,gv_status5,
         gv_comments1,gv_comments2,gv_comments3,gv_comments4,gv_comments5.




  LOOP AT it_qmel INTO wa_qmel.

    IF sy-subrc = 0.
      gv_time           = wa_qmel-zztime.
      gv_part           = wa_qmel-zzpart.
      gv_stopage        = wa_qmel-zzstopage.
      gv_ploss          = wa_qmel-zzploss.
      gv_impact         = wa_qmel-zzimpact.
      gv_action1        = wa_qmel-zzaction1.
      gv_action2        = wa_qmel-zzaction2.
      gv_action3        = wa_qmel-zzaction3.
      gv_action4        = wa_qmel-zzaction4.
      gv_action5        = wa_qmel-zzaction5.
      gv_resp1          = wa_qmel-zzresp1.
      gv_resp2          = wa_qmel-zzresp2.
      gv_resp3          = wa_qmel-zzresp3.
      gv_resp4          = wa_qmel-zzresp4.
      gv_resp5          = wa_qmel-zzresp5.
      gv_due1           = wa_qmel-zzdue1.
      gv_due2           = wa_qmel-zzdue2.
      gv_due3           = wa_qmel-zzdue3.
      gv_due4           = wa_qmel-zzdue4.
      gv_due5           = wa_qmel-zzdue5.
      gv_status1        = wa_qmel-zzstatus1.
      gv_status2        = wa_qmel-zzstatus2.
      gv_status3        = wa_qmel-zzstatus3.
      gv_status4        = wa_qmel-zzstatus4.
      gv_status5        = wa_qmel-zzstatus5.
      gv_comments1      = wa_qmel-zzcomments1.
      gv_comments2      = wa_qmel-zzcomments2.
      gv_comments3      = wa_qmel-zzcomments3.
      gv_comments4      = wa_qmel-zzcomments4.
      gv_comments5      = wa_qmel-zzcomments5.
**  read text
      lv_id = 'Z001'.
      lv_object = 'ZQMELWHY'.
      lv_qname = wa_qmel-qmnum.
      CALL FUNCTION 'READ_TEXT'
        EXPORTING
          client                  = sy-mandt
          id                      = lv_id
          language                = 'E'
          name                    = lv_qname
          object                  = lv_object
*         ARCHIVE_HANDLE          = 0
*         LOCAL_CAT               = ' '
* IMPORTING
*         HEADER                  =
*         OLD_LINE_COUNTER        =
        TABLES
          lines                   = it_tab1
        EXCEPTIONS
          id                      = 1
          language                = 2
          name                    = 3
          not_found               = 4
          object                  = 5
          reference_check         = 6
          wrong_access_to_archive = 7
          OTHERS                  = 8.
      IF sy-subrc EQ 0.
        CLEAR lv_id.
      ENDIF.

      lv_id = 'Z002'.
**  read text
      CALL FUNCTION 'READ_TEXT'
        EXPORTING
          client                  = sy-mandt
          id                      = lv_id
          language                = 'E'
          name                    = lv_qname
          object                  = lv_object
*         ARCHIVE_HANDLE          = 0
*         LOCAL_CAT               = ' '
* IMPORTING
*         HEADER                  =
*         OLD_LINE_COUNTER        =
        TABLES
          lines                   = it_tab2
        EXCEPTIONS
          id                      = 1
          language                = 2
          name                    = 3
          not_found               = 4
          object                  = 5
          reference_check         = 6
          wrong_access_to_archive = 7
          OTHERS                  = 8.
      IF sy-subrc EQ 0.
        CLEAR lv_id.
      ENDIF.

      lv_id = 'Z003'.
**  read text
      CALL FUNCTION 'READ_TEXT'
        EXPORTING
          client                  = sy-mandt
          id                      = lv_id
          language                = 'E'
          name                    = lv_qname
          object                  = lv_object
*         ARCHIVE_HANDLE          = 0
*         LOCAL_CAT               = ' '
* IMPORTING
*         HEADER                  =
*         OLD_LINE_COUNTER        =
        TABLES
          lines                   = it_tab3
        EXCEPTIONS
          id                      = 1
          language                = 2
          name                    = 3
          not_found               = 4
          object                  = 5
          reference_check         = 6
          wrong_access_to_archive = 7
          OTHERS                  = 8.
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.

    ENDIF.
  ENDLOOP.
*--Plants/Branches
  CLEAR wa_qmel.

ENDFORM.


FORM f_output.
  DATA: lf_formname        TYPE tdsfname,
        swnes              TYPE regud-swnes,
        langu              TYPE sy-langu,
        spell              TYPE spell,
        control_parameters TYPE ssfctrlop,          "Control Parameters
        output_options     TYPE ssfcompop.              "o/p options
*--control parameters
  control_parameters-preview   = 'X'.
  control_parameters-no_dialog = 'X'.
  control_parameters-device    = 'PRINTER'.
*--output options
  output_options-tdpageslct  = space.         "all pages
  output_options-tdcopies    = 1.             "one copy
  output_options-tddest      = 'ZLOC'.        "name of printer
  output_options-tdnoprev    = ' '.           "preview
  output_options-tdcover     = space.         "no cover page
  output_options-tdsuffix1   = 'ZLOC'.        "name or printer

*--smart form
  lf_formname = 'ZPMF0001'.
*--language
  langu = 'EN'.

  control_parameters-langu     = 'EN'.

  PERFORM f_call_form USING lf_formname
                                control_parameters
                                output_options.

ENDFORM. "f_output_form

FORM f_call_form USING lf_formname
                       control_parameters
                       output_options.
  DATA: lf_fm_name            TYPE rs38l_fnam.
  REFRESH: gt_otf_f.
  CLEAR gt_otf.
* determine smartform function module
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = lf_formname
    IMPORTING
      fm_name            = lf_fm_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  IF sy-subrc EQ 0.


    CALL FUNCTION lf_fm_name
      EXPORTING
*       ARCHIVE_INDEX      =
*       ARCHIVE_INDEX_TAB  =
*       ARCHIVE_PARAMETERS =
        control_parameters = control_parameters
*       MAIL_APPL_OBJ      =
*       MAIL_RECIPIENT     =
*       MAIL_SENDER        =
        output_options     = output_options
        user_settings      = ' '
        gv_part            = gv_part
        gv_stopage         = gv_stopage
        gv_ploss           = gv_ploss
        gv_impact          = gv_impact
        gv_action1         = gv_action1
        gv_action2         = gv_action2
        gv_action3         = gv_action3
        gv_action4         = gv_action4
        gv_action5         = gv_action5
        gv_resp1           = gv_resp1
        gv_resp2           = gv_resp2
        gv_resp3           = gv_resp3
        gv_resp4           = gv_resp4
        gv_resp5           = gv_resp5
        gv_due1            = gv_due1
        gv_due2            = gv_due2
        gv_due3            = gv_due3
        gv_due4            = gv_due4
        gv_due5            = gv_due5
        gv_status1         = gv_status1
        gv_status2         = gv_status2
        gv_status3         = gv_status3
        gv_status4         = gv_status4
        gv_status5         = gv_status5
        gv_comments1       = gv_comments1
        gv_comments2       = gv_comments2
        gv_comments3       = gv_comments3
        gv_comments4       = gv_comments4
        gv_comments5       = gv_comments5
      IMPORTING
*       DOCUMENT_OUTPUT_INFO       =
        job_output_info    = gt_otf
*       JOB_OUTPUT_OPTIONS =
      TABLES
        gt_ztline1         = it_tab1
        gt_ztline2         = it_tab2
        gt_ztline3         = it_tab3
      EXCEPTIONS
        formatting_error   = 1
        internal_error     = 2
        send_error         = 3
        user_canceled      = 4
        OTHERS             = 5.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
*--PDF preview
    gt_otf_f[] = gt_otf-otfdata[]. " OTF data
    IF gt_otf_f[] IS NOT INITIAL.
      CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
        EXPORTING
          i_otf                    = gt_otf_f
        EXCEPTIONS
          convert_otf_to_pdf_error = 1
          cntl_error               = 2
          OTHERS                   = 3.
      IF sy-subrc <> 0.
*      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDIF.

  ENDIF.

ENDFORM. "f_call_form

*Selection texts
*----------------------------------------------------------
* P_QMNUM         Notification Number