ZRMM079

 REPORT zrmm079 NO STANDARD PAGE HEADING LINE-COUNT 65 LINE-SIZE  255.

*Declaration tables for this program
TABLES:mkpf,mseg,usr01.
*Data declaration: ALV parameters
TYPE-POOLS: slis.
 
DATA: gt_fieldcat  TYPE slis_t_fieldcat_alv,"Field catalogue
      gt_sp_group  TYPE slis_t_sp_group_alv."Groups for list display
DATA: gt_layout TYPE slis_layout_alv.
DATA: gt_events TYPE slis_t_event.
 
DATA: es_excluding TYPE slis_t_extab.
*Constants for ALV
DATA: g_boxnam     TYPE slis_fieldname VALUE 'CHECK'.
DATA: g_repid      LIKE sy-repid.
DATA: g_variant    LIKE disvariant.
DATA: t_fieldcat   TYPE slis_t_fieldcat_alv,
      w_filedcat   LIKE LINE OF t_fieldcat.
DATA: t_listheader TYPE slis_t_listheader,
      w_listheader LIKE LINE OF t_listheader.
DATA: t_event      TYPE slis_t_event,
      w_event      LIKE LINE OF t_event.
DATA: t_sort       TYPE slis_t_sortinfo_alv.
DATA: x_sort       LIKE LINE OF t_sort.
DATA: gs_layout       TYPE slis_layout_alv.
*DATA  g_status        TYPE slis_formname VALUE 'STANDARD'.
DATA: g_user_command  TYPE slis_formname VALUE 'MYCOMMAND'.
 
DATA: l_itcpo LIKE itcpo.
* printer control setting
DATA: l_prn_comp TYPE ssfcompop,
      l_prn_ctrlop TYPE ssfctrlop,
      job_output_options TYPE ssfcresop,
      job_output_info TYPE ssfcrescl.
 
DATA: z_kind TYPE c.  "added by MansonTang 20090429
 
DATA: BEGIN OF gt_result OCCURS 0,
  check TYPE c,
  werks LIKE mseg-werks,
  plant LIKE t001w-name1,
  budat LIKE mkpf-budat,
  bwart LIKE mseg-bwart,
  mblnr LIKE mkpf-mblnr,
  matnr LIKE mseg-matnr,
  zeile LIKE mseg-zeile,  "mat doc item
  bismt LIKE mara-bismt,  "old mat
  z0001 LIKE mara-z0001,  "brand
  brand LIKE wrf_brands_t-brand_descr,
  ebeln LIKE mseg-ebeln,
  ebelp LIKE mseg-ebelp,
  lgort LIKE mseg-lgort,
  lgobe LIKE t001l-lgobe,
  umlgo LIKE mseg-umlgo,
  lgobe2 LIKE t001l-lgobe,
  shkzg LIKE mseg-shkzg,
  bstmg LIKE mseg-bstmg,
  erfmg LIKE mseg-erfmg,  "for 931 932
  kbetr LIKE konp-kbetr,  "unit price
  total(16) TYPE p DECIMALS 2,  "TOTAl = BSTMG * KBETR
  netpr LIKE ekpo-netpr,  "PO NET PRICE
  poamt(16) TYPE p DECIMALS 2,  "PO TOTAL = NETPR * BSTMG.
  verpr LIKE mbew-verpr,  "Moving Price
  zcost(16) TYPE p DECIMALS 2,  "COST = VERPR * BSTMG.
  waers LIKE mseg-waers,
END OF gt_result.
 
DATA:it_result LIKE gt_result OCCURS 0 WITH HEADER LINE.
DATA:gt_result_print LIKE gt_result OCCURS 0 WITH HEADER LINE.
DATA:gt_result_print_tmp LIKE gt_result OCCURS 0 WITH HEADER LINE.
 
*Define the selection-screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS:     p_werks LIKE mseg-werks OBLIGATORY DEFAULT '1221'.
SELECT-OPTIONS: s_budat FOR mkpf-budat OBLIGATORY.
SELECT-OPTIONS: s_bwart FOR mseg-bwart OBLIGATORY DEFAULT '931' TO '932'.
SELECT-OPTIONS: s_matnr FOR mseg-matnr.
SELECT-OPTIONS: s_mblnr FOR mkpf-mblnr.
SELECT-OPTIONS: s_lgort FOR mseg-lgort NO-EXTENSION NO INTERVALS..
SELECT-OPTIONS: s_umlgo FOR mseg-umlgo NO-EXTENSION NO INTERVALS..
PARAMETERS:  s_alv1 RADIOBUTTON GROUP gr1 DEFAULT 'X',
             s_alv2 RADIOBUTTON GROUP gr1.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
INITIALIZATION.
 
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
 
*    IF s_aufnr = ''.
*      MESSAGE '请使用“工单编号”或者“成本中心”其中一个作为查询条件!' TYPE 'E'.
*    ENDIF.
*----------------------------------------------------------------------*
*TOP-OF-PAGE
*----------------------------------------------------------------------*
TOP-OF-PAGE.
*---------------------------------------------------------------------*
* AT USER-COMMAND
*---------------------------------------------------------------------*
*AT USER-COMMAND.
*  IF SY-UCOMM = 'ZPOST' .
*  ENDIF.
END-OF-PAGE.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM get_data.
 
END-OF-SELECTION.
  PERFORM output_data.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
FORM get_data.
  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_result FROM mkpf AS a
    INNER JOIN mseg AS b ON a~mblnr = b~mblnr
    WHERE a~mblnr IN s_mblnr AND a~budat IN s_budat AND b~bwart IN s_bwart AND b~matnr IN 
 
s_matnr AND b~werks = p_werks AND b~shkzg = 'H'
    AND b~lgort IN s_lgort AND b~umlgo IN s_umlgo.
 
  LOOP AT gt_result.
    SELECT SINGLE name1 INTO gt_result-plant FROM t001w WHERE werks = gt_result-werks.
    SELECT SINGLE lgobe INTO gt_result-lgobe FROM t001l WHERE lgort = gt_result-lgort.
    SELECT SINGLE lgobe INTO gt_result-lgobe2 FROM t001l WHERE lgort = gt_result-umlgo.
    SELECT SINGLE bismt INTO gt_result-bismt FROM mara WHERE matnr = gt_result-matnr.
    SELECT SINGLE z0001 INTO gt_result-z0001 FROM mara WHERE matnr = gt_result-matnr.
    SELECT SINGLE brand_descr INTO gt_result-brand FROM wrf_brands_t WHERE 
 
wrf_brands_t~brand_id = gt_result-z0001.
    SELECT SINGLE kbetr INTO gt_result-kbetr FROM konp AS a
*      INNER JOIN a902 AS b ON a~knumh = b~knumh
      INNER JOIN a902 AS b ON a~knumh = b~knumh AND a~kschl = b~kschl
*      WHERE b~vkorg = gt_result-werks AND b~matnr = gt_result-matnr.
      WHERE b~vkorg = gt_result-werks AND b~matnr = gt_result-matnr AND b~kschl = 'ZRET'.
    gt_result-total = gt_result-kbetr * gt_result-erfmg.
    SELECT SINGLE netpr INTO gt_result-netpr FROM ekpo WHERE ebeln = gt_result-ebeln AND 
 
ebelp = gt_result-ebelp.
    gt_result-poamt = gt_result-netpr * gt_result-erfmg.
    SELECT SINGLE verpr INTO gt_result-verpr FROM mbew WHERE bwkey = gt_result-werks AND 
 
matnr = gt_result-matnr.
    gt_result-zcost = gt_result-verpr * gt_result-erfmg.
    MODIFY gt_result.
  ENDLOOP.
  APPEND LINES OF gt_result TO it_result.
ENDFORM.                    "GET_DATA
 
 
*&---------------------------------------------------------------------*
*&      Form  OUTPUT_DATA
*&---------------------------------------------------------------------*
FORM output_data.
  IF gt_result[] IS INITIAL.
    MESSAGE 'No data!' TYPE 'S'.
    STOP.
  ELSE.
    CLEAR gt_fieldcat.
    PERFORM get_fields_attribute USING 'GT_RESULT' .
    PERFORM get_alv_fields USING 'GT_RESULT'.
    PERFORM output_detail_alv.
  ENDIF.
ENDFORM.                    "OUTPUT_DATA
 
*&---------------------------------------------------------------------*
*&      Form  GET_FIELDS_ATTRIBUTE
*&---------------------------------------------------------------------*
FORM get_fields_attribute USING p_table .
  IF s_alv1 = 'X'.
    PERFORM change_field_name USING 'CHECK'  p_table '打印' '' '' 'X' 'X' '' '' ''.
    PERFORM change_field_name USING 'LGORT'  p_table '店铺' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'LGOBE'  p_table '店铺名称' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'BRAND'  p_table '牌子' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'MATNR'  p_table '物料编号' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'BISMT'  p_table '存货代码' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'MBLNR'  p_table '转仓单编号' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'LGORT'  p_table '出仓仓位' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'LGOBE'  p_table '出仓地点' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'UMLGO'  p_table '入仓仓位' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'LGOBE2'  p_table '入仓地点' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'ERFMG'  p_table '数量' 'X' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'WAERS'  p_table '货币' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'VERPR'  p_table '移动平均价' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'ZCOST'  p_table '成本总金额' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'KBETR'  p_table '零售单价' 'X' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'TOTAL'  p_table '零售总金额' 'X' '' '' '' '' '' ''.
  ELSE.
    PERFORM change_field_name USING 'CHECK'  p_table '打印' '' '' 'X' 'X' '' '' ''.
    PERFORM change_field_name USING 'MBLNR'  p_table '转仓出仓单' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'BUDAT'  p_table '日期' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'BWART'  p_table '移动类型' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'MATNR'  p_table '物料编号' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'BISMT'  p_table '存货代码' '' '' '' '' '' '' ''.
*  PERFORM change_field_name USING 'EBELN'  p_table '原PO' '' '' '' '' '' '' ''.
*  PERFORM change_field_name USING 'ZEILE'  p_table '项目' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'BRAND'  p_table '牌子' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'ERFMG'  p_table '数量' 'X' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'KBETR'  p_table '零售单价' 'X' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'TOTAL'  p_table '零售金额' 'X' '' '' '' '' '' ''.
*  PERFORM change_field_name USING 'POAMT'  p_table 'PO金额' '' '' '' '' '' '' ''.
*  PERFORM change_field_name USING 'ZCOST'  p_table '成本价' '' '' '' '' '' '' ''.
*  PERFORM change_field_name USING 'WERKS'  p_table '商场' '' '' '' '' '' '' ''.
*  PERFORM change_field_name USING 'PLANT'  p_table '商场名称' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'LGORT'  p_table '出仓仓位' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'LGOBE'  p_table '出仓地点' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'UMLGO'  p_table '入仓仓位' '' '' '' '' '' '' ''.
    PERFORM change_field_name USING 'LGOBE2'  p_table '入仓地点' '' '' '' '' '' '' ''.
  ENDIF.
  PERFORM build_alv_sort USING:  'MBLNR' p_table 'X' '' 'X' ''.
 
ENDFORM.                    "GET_FIELDS_ATTRIBUTE
 
*&---------------------------------------------------------------------*
*&      Form  build_alv_sort
*&---------------------------------------------------------------------*
FORM build_alv_sort USING fname fitab fup fdown fsubt fsum.
  DATA: zsort TYPE slis_sortinfo_alv.
  CLEAR zsort.
  zsort-fieldname = fname.
  zsort-tabname   = fitab.
  zsort-up = fup.
  zsort-down = fdown.
  zsort-subtot = fsubt.
  APPEND zsort TO t_sort.
ENDFORM.                    "build_alv_sort
 
*&---------------------------------------------------------------------*
*&      Form  CHANGE_FIELD_NAME
*&---------------------------------------------------------------------*
FORM change_field_name  USING pl_field pl_itab   pl_text pl_sum pl_fix pl_edit  pl_checkbox 
 
pl_input  pl_ref_fieldname  pl_ref_tabname.
  DATA  lt_fieldcat TYPE slis_fieldcat_alv.
  lt_fieldcat-fieldname    = pl_field.
  lt_fieldcat-tabname      = pl_itab.
  lt_fieldcat-reptext_ddic   = pl_text.
  lt_fieldcat-seltext_l      = pl_text.
  lt_fieldcat-seltext_m      = pl_text.
  lt_fieldcat-seltext_s      = pl_text.
  lt_fieldcat-do_sum         = pl_sum.
  lt_fieldcat-fix_column     = pl_fix.
  lt_fieldcat-edit_mask      = ''.
  lt_fieldcat-edit           = pl_edit.
  lt_fieldcat-checkbox       = pl_checkbox. "the column is checkbox
  lt_fieldcat-input           = pl_input.    "the column can be edited in ALV
  lt_fieldcat-ddictxt        = 'L'.
  lt_fieldcat-ref_fieldname           = pl_ref_fieldname.
  lt_fieldcat-ref_tabname          = pl_ref_tabname.
*  lt_fieldcat-no_zero = '1' .
  APPEND lt_fieldcat TO gt_fieldcat.
  CLEAR: lt_fieldcat.
ENDFORM.                    "CHANGE_FIELD_NAME
 
*&---------------------------------------------------------------------*
*&      Form  GET_ALV_FIELDS
*&---------------------------------------------------------------------*
FORM get_alv_fields  USING    p_itabn.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = sy-repid
      i_internal_tabname     = p_itabn
    CHANGING
      ct_fieldcat            = gt_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
ENDFORM.                    " GET_ALV_FIELDS
 
*&---------------------------------------------------------------------*
*&      Form  OUTPUT_DETAIL_ALV
*&---------------------------------------------------------------------*
FORM output_detail_alv .
 
  " for print button
  DATA  i_event_exit TYPE slis_t_event_exit.
  DATA gw_event_exit       LIKE LINE OF i_event_exit.
  DATA gt_event_exit TYPE slis_t_event_exit.
  gw_event_exit-ucomm = '&ALL'. "User command for print.
  gw_event_exit-before = 'X'.
  APPEND gw_event_exit TO gt_event_exit.
  gw_event_exit-ucomm = '&SAL'. "User command for print.
 
  APPEND gw_event_exit TO gt_event_exit.
 
  gt_layout-colwidth_optimize = 'X'.
  gt_layout-box_fieldname = g_boxnam.
 
*  DELETE ADJACENT DUPLICATES FROM gt_result COMPARING mblnr matnr.
 
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-cprog
      i_callback_user_command = 'USER_COMMAND'
      i_callback_pf_status_set   = 'SET_PF_STATUS'
*      i_structure_name        = 'GT_RESULT'
      it_fieldcat             = gt_fieldcat[]
      it_sort                 = t_sort
*I_DEFAULT                      = 'X'
      i_save                  = 'A'
      is_layout               = gt_layout
      it_events               = gt_events[]
    it_event_exit             = gt_event_exit
    TABLES
      t_outtab                = gt_result
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
ENDFORM.                    "OUTPUT_DETAIL_ALV
 
*&---------------------------------------------------------------------*
*&      Form  SET_PF_STATUS1
*&---------------------------------------------------------------------*
FORM set_pf_status  USING  extab TYPE slis_t_extab.
  DATA: r_ucomm LIKE sy-ucomm.
  SET PF-STATUS 'ZSTANDARD'   ."EXCLUDING ES_EXCLUDING.
ENDFORM.                    "SET_PF_STATUS
 
*&---------------------------------------------------------------------*
*&      Form  sub_call_openform
*&---------------------------------------------------------------------*
FORM sub_call_openform .
  CALL FUNCTION 'SSF_OPEN'
    EXPORTING
*    ARCHIVE_PARAMETERS       = ARCHIVE_PARAMETERS
     user_settings            = ' '
     output_options           = l_prn_comp
     control_parameters       = l_prn_ctrlop
   IMPORTING
     job_output_options       = job_output_options
   EXCEPTIONS
     formatting_error         = 1
     internal_error           = 2
     send_error               = 3
     user_canceled            = 4
     OTHERS                   = 5.
  IF sy-subrc <> 0.
*    MESSAGE 'User Cancelled' TYPE 'W'.
  ENDIF.
ENDFORM.                    " sub_call_openform
 
*&---------------------------------------------------------------------*
*&      Form  sub_call_closeform
*&---------------------------------------------------------------------*
FORM sub_call_closeform .
  CALL FUNCTION 'SSF_CLOSE'
    IMPORTING
      job_output_info  = job_output_info
    EXCEPTIONS
      formatting_error = 1
      internal_error   = 2
      send_error       = 3
      OTHERS           = 4.
ENDFORM.                    " sub_call_closeform
 
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
FORM user_command USING rf_ucomm    LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield .
  FIELD-SYMBOLS: <fs>,<fs1>,<fs2>.
  ASSIGN COMPONENT  6 OF STRUCTURE rs_selfield TO <fs>.
  ASSIGN COMPONENT 14 OF STRUCTURE rs_selfield TO <fs1>.
  ASSIGN COMPONENT  2 OF STRUCTURE rs_selfield TO <fs2>.
  DATA: wa_analy LIKE gt_result.
  READ TABLE gt_result INDEX <fs2> INTO wa_analy.
  DATA: index        TYPE i.
  DATA: answer       TYPE c.
  DATA: refresh_list TYPE c.
  DATA: cursor_pos   LIKE sy-tabix.
  rs_selfield-tabindex = sy-tabix.
 
*---------------------------------------------------------------------------
  DATA ref TYPE REF TO cl_gui_alv_grid.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = ref.
  CALL METHOD ref->check_changed_data.
  rs_selfield-refresh = 'X'.
*--------------------------------------------------------------------------
 
  CASE rf_ucomm.
    WHEN 'ZPRINTB'.
      PERFORM set_data_to_print.
      PERFORM print_form.
    WHEN 'ZPRINTPDF'.
      PERFORM set_data_to_print.
      PERFORM download_pdf.
    WHEN 'RETURN' OR 'BACK' OR 'CANCE'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDFORM.                    "USER_COMMAND
 
 
*&---------------------------------------------------------------------*
*&      Form  set_data_to_print
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM set_data_to_print.
  CLEAR:  gt_result_print.
  REFRESH:gt_result_print.
 
  LOOP AT gt_result WHERE check EQ 'X'.
*    gt_result-zneed = gt_result-bdmng - gt_result-enmng.
    MOVE-CORRESPONDING gt_result TO gt_result_print.
    APPEND gt_result_print.
  ENDLOOP.
 
*  remove the select when you go back.  added by mansontang20090409
  LOOP AT gt_result WHERE check NE ''.
    gt_result-check = ''.
    MODIFY gt_result.
  ENDLOOP.
 
* --------------Delete the DUPLICATES data
*  DELETE ADJACENT DUPLICATES FROM gt_result_print.
 
  IF gt_result_print[] IS INITIAL.
    MESSAGE 'Please choose!' TYPE 'E'.
  ELSE." choosed print
 
    PERFORM sub_set_printer_control.
    l_prn_ctrlop-no_open = 'X'.
    l_prn_ctrlop-no_close = 'X'.
*&---------------------------------------------------------------------*
    REFRESH gt_result_print_tmp.
    APPEND LINES OF gt_result_print TO gt_result_print_tmp.
 
    DELETE ADJACENT DUPLICATES FROM gt_result_print_tmp COMPARING mblnr.
 
    REFRESH gt_result_print.
    LOOP AT gt_result_print_tmp.
      LOOP AT it_result WHERE mblnr = gt_result_print_tmp-mblnr.
        APPEND it_result TO gt_result_print.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
ENDFORM.                    "set_data_to_print
 
 
**&---------------------------------------------------------------------*
**&      Form  SET_DATA_TO_PRINT
**&---------------------------------------------------------------------*
*FORM set_data_to_print.
*  CLEAR:  gt_result_print.
*  REFRESH:gt_result_print.
*
*  LOOP AT gt_result WHERE check EQ 'X'.
*
**    gt_result-zneed = gt_result-bdmng - gt_result-enmng.
*    MOVE-CORRESPONDING gt_result TO gt_result_print.
*    APPEND gt_result_print.
*
*  ENDLOOP.
*
**  remove the select when you go back.  added by mansontang20090409
*  LOOP AT gt_result WHERE check NE ''.
*    gt_result-check = ''.
*    MODIFY gt_result.
*  ENDLOOP.
*
** --------------Delete the DUPLICATES data
**  DELETE ADJACENT DUPLICATES FROM gt_result_print COMPARING mblnr matnr.
*
*  IF gt_result_print[] IS INITIAL.
*    MESSAGE 'Please choose!' TYPE 'E'.
*  ELSE." choosed print
*
*    PERFORM sub_set_printer_control.
*
*    DATA l_function TYPE rs38l_fnam.
*    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
*      EXPORTING
*        formname = 'ZRMM079'
*      IMPORTING
*        fm_name  = l_function.
*
*    PERFORM sub_call_openform.
*    l_prn_ctrlop-no_open = 'X'.
*    l_prn_ctrlop-no_close = 'X'.
**&---------------------------------------------------------------------*
*    REFRESH gt_result_print_tmp.
*    APPEND LINES OF gt_result_print TO gt_result_print_tmp.
*
*    DELETE ADJACENT DUPLICATES FROM gt_result_print_tmp COMPARING mblnr.
*
*    LOOP AT gt_result_print_tmp.
*      REFRESH gt_result_print.
*      LOOP AT it_result WHERE mblnr = gt_result_print_tmp-mblnr.
*        APPEND it_result TO gt_result_print.
*      ENDLOOP.
*
*      CALL FUNCTION l_function
*      EXPORTING
*      control_parameters = l_prn_ctrlop
*      output_options     = l_prn_comp
*      user_settings      = ''        " using current setting
**          ITAB               = gt_result_print
*       EXCEPTIONS
*         formatting_error           = 1
*         internal_error             = 2
*         send_error                 = 3
*         user_canceled              = 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.
*      ENDIF.
*
*    ENDLOOP.
*
*    PERFORM sub_call_closeform.
*
*  ENDIF.
*ENDFORM.              "SET_DATA_TO_PRINT
 
*&---------------------------------------------------------------------*
*&      Form  print_form
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM print_form.
  DATA l_function TYPE rs38l_fnam.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname = 'ZRMM079'
    IMPORTING
      fm_name  = l_function.
  PERFORM sub_call_openform.
  CALL FUNCTION l_function
    EXPORTING
      control_parameters = l_prn_ctrlop
      output_options     = l_prn_comp
      user_settings      = ''        " using current setting
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.
  IF sy-subrc <> 0.ENDIF.
  PERFORM sub_call_closeform.
ENDFORM.                    "print_form
 
*&---------------------------------------------------------------------*
*&      Form  sub_set_printer_control
*&---------------------------------------------------------------------*
FORM sub_set_printer_control .
  CLEAR usr01.
  SELECT SINGLE * FROM usr01 WHERE bname = sy-uname.
  l_prn_ctrlop-no_open = 'X'.
*  l_prn_ctrlop-no_close = 'X'.
* control setting
  l_prn_ctrlop-preview = 'X'.
  l_prn_ctrlop-no_dialog = 'X'.
 
*  IF sy-langu = '1' OR sy-langu = 'M'.
  l_prn_ctrlop-langu = '1'.
*  ENDIF.
  l_prn_ctrlop-device = 'PRINTER'.
* printer setting
  l_prn_comp-tdcopies = '1'.
  l_prn_comp-tdsuffix2 = sy-repid.
  l_prn_comp-tddest = usr01-spld.
***  l_prn_comp-tdprinter = 'PRINTER'.
  l_prn_comp-tdnewid = 'X'.
  l_prn_comp-tdimmed = 'X'. "print it now.
  l_prn_comp-tdfinal = 'X'.
* l_prn_comp-tddelete = 'X'.
ENDFORM.                    " sub_set_printer_control
 
 
*&---------------------------------------------------------------------*
*&      Form  download_pdf
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM download_pdf.
* variable declarations
  DATA:
  w_cparam TYPE ssfctrlop,
  w_outoptions TYPE ssfcompop,
  w_bin_filesize TYPE i," Binary File Size
  w_filename TYPE string,
  w_file_path TYPE string,
  w_full_path TYPE string.
 
  CONCATENATE sy-cprog '-' sy-datum '-' sy-uzeit '.PDF' INTO w_filename.
* Internal tables declaration
* Internal table to hold the OTF data
  DATA:
  t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
* Internal table to hold OTF data recd from the SMARTFORM
  t_otf_from_fm TYPE ssfcrescl,
* Internal table to hold the data from the FM CONVERT_OTF
  t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.
 
* Calling the SMARTFORM using the function module retrieved above
* GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
* format of the output
  w_cparam-no_dialog = 'X'.
  w_cparam-preview = space. " Suppressing the dialog box
  w_cparam-getotf = 'X'.                                      " for print preview
  w_cparam-langu = '1'.
* Printer name to be used is provided in the export parameter
* OUTPUT_OPTIONS
*  w_outoptions-tddest = 'LP01'.
  w_outoptions-tddest = 'DEFAULT'.
 
*&---------------------------------------------------------------------*
  DATA l_function TYPE rs38l_fnam.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname = 'ZRMM079'
    IMPORTING
      fm_name  = l_function.
 
  CALL FUNCTION l_function
    EXPORTING
      control_parameters = w_cparam
      output_options     = w_outoptions
    IMPORTING
      job_output_info    = t_otf_from_fm
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 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.
  ENDIF.
 
  t_otf[] = t_otf_from_fm-otfdata[].
* Function Module CONVERT_OTF is used to convert the OTF format to PDF
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_filesize          = w_bin_filesize
    TABLES
      otf                   = t_otf
      lines                 = t_pdf_tab
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 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.
  ENDIF.
 
* To display File SAVE dialog window
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      default_file_name    = w_filename
    CHANGING
      filename             = w_filename
      path                 = w_file_path
      fullpath             = w_full_path
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 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.
 
* Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
* presentation server
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize = w_bin_filesize
      filename     = w_full_path
      filetype     = 'BIN'
    TABLES
      data_tab     = t_pdf_tab.
  IF sy-subrc <> 0.
  ENDIF.
 
ENDFORM.                    "download_pdf
 

你可能感兴趣的:(职场,Data,休闲,ZRMM079)