728x90
반응형
FORM print_data .
DATA : lt_job_output_info TYPE ssfcrescl,
ls_control TYPE ssfctrlop,
ls_output TYPE ssfcompop,
lv_fname TYPE rs38l_fnam.
DATA: lt_head TYPE TABLE OF zs001,
lt_item TYPE TABLE OF zs002,
lt_ekpo TYPE TABLE OF zs002 WITH NON-UNIQUE SORTED KEY ebeln COMPONENTS ebeln.
*-- Smartform option setting
PERFORM set_ssf_form CHANGING ls_control
ls_output
lv_fname.
*-- Smartform data select
PERFORM get_data TABLES lt_head lt_ekpo.
"여러개 미리보기 위해 스마트폼 OPEN 유지
IF gv_okcode = gc_view_pdf. "Smartform 미리보기
CALL FUNCTION 'SSF_OPEN'
EXPORTING
user_settings = ''
output_options = ls_output
control_parameters = ls_control
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
ENDIF.
*-- Make data
LOOP AT lt_head INTO DATA(ls_head).
"헤더와 동일한 문서의 품목만 SMARTFORM 전송
lt_item = FILTER #( lt_ekpo USING KEY ebeln
WHERE ebeln = ls_head-ebeln ).
LOOP AT lt_item INTO DATA(ls_item).
"데이터 가공
ENDLOOP.
**-- SMARTFORM 실행
CALL FUNCTION lv_fname
EXPORTING
control_parameters = ls_control
output_options = ls_output
user_settings = ''
gs_head = ls_head
IMPORTING
job_output_info = lt_job_output_info
TABLES
gt_item = lt_item
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.
EXIT.
ENDIF.
*-- PDF 출력
IF gv_okcode = gc_dl_pdf.
PERFORM get_ssf_pdf TABLES lt_job_output_info-otfdata
USING ls_head-ebeln.
ENDIF.
CLEAR: ls_head, lt_job_output_info.
ENDLOOP.
"여러개 미리보기 위해 OPEN했던 스마트폼 CLOSE
IF gv_okcode = gc_view_pdf.
CALL FUNCTION 'SSF_CLOSE'
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
OTHERS = 4.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form set_ssf_form
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- LS_CONTROL
*& <-- LS_OUTPUT
*& <-- LV_FNAME
*&---------------------------------------------------------------------*
FORM set_ssf_form CHANGING cs_control TYPE ssfctrlop
cs_output TYPE ssfcompop
cv_fname.
CONSTANTS: lc_formname TYPE tdsfname VALUE '스마트폼 이름'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lc_formname
IMPORTING
fm_name = cv_fname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
* PDF 출력
IF gv_okcode = gc_dl_pdf.
cs_control-no_dialog = gc_x. "인쇄출력팝업 안 띄우기
cs_control-getotf = gc_x.
cs_output-tdnoprev = gc_x.
ELSE.
cs_control-no_close = gc_x.
cs_control-no_open = gc_x.
cs_control-preview = gc_x.
* cs_control-no_dialog = ''.
* cs_control-getotf = ''.
cs_control-langu = sy-langu.
cs_output-tdtitle = '미리보기'.
* cs_output-tdnoprev = ''.
cs_output-tdimmed = gc_x.
cs_output-tddelete = gc_x.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form get_ssf_pdf
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LT_JOB_OUTPUT_INFO
*&---------------------------------------------------------------------*
FORM get_ssf_pdf TABLES pt_otfdata STRUCTURE itcoo
USING pv_ebeln TYPE ebeln.
CONSTANTS: lc_pdf TYPE char3 VALUE 'PDF',
lc_file1 TYPE string VALUE '\PO_',
lc_file2 TYPE string VALUE '.pdf',
lc_bin TYPE char10 VALUE 'BIN'.
DATA: pdf_fsize TYPE i,
pdf_table TYPE rcl_bag_tline,
lv_window_title TYPE string VALUE 'Directory Path',
lv_initial_folder TYPE string.
CHECK pt_otfdata[] IS NOT INITIAL.
*-- SMARTFORM -> PDF 형식으로 변환
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = lc_pdf
IMPORTING
bin_filesize = pdf_fsize
TABLES
otf = pt_otfdata[]
lines = pdf_table
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.
EXIT.
ENDIF.
IF gv_path IS INITIAL.
* 파일 경로 선택
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = lv_window_title
initial_folder = lv_initial_folder
CHANGING
selected_folder = gv_path "선택한 경로
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
ENDIF.
CHECK gv_path IS NOT INITIAL.
* 경로 + 저장될 파일이름 구성
DATA(lv_filename) = gv_path && lc_file1 && pv_ebeln && lc_file2.
* PDF 파일 사용자 PC에 저장
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = pdf_fsize
filename = lv_filename
filetype = lc_bin
TABLES
data_tab = pdf_table
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
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.
728x90
반응형
'ABAP' 카테고리의 다른 글
[ALV] GET_SELECTED_ROWS (0) | 2023.03.02 |
---|---|
[Smartform] 금액 수량 단위 필드 (0) | 2023.03.02 |
Text editor object (0) | 2023.03.02 |
[ALV] ALV + Hotspot Event (0) | 2023.03.02 |
[SD] Sales Order Update/Delete BAPI (0) | 2023.03.01 |
댓글