0% found this document useful (0 votes)
44 views6 pages

Convert to PDF Data SAP

The document outlines an SAP ABAP program designed to print delivery notes using Smart Forms. It includes data declarations, form definitions, and processing logic to retrieve print data, set parameters, and handle errors during the printing process. The program also manages the conversion of output to PDF format and facilitates file downloads.

Uploaded by

mihaela.traista
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views6 pages

Convert to PDF Data SAP

The document outlines an SAP ABAP program designed to print delivery notes using Smart Forms. It includes data declarations, form definitions, and processing logic to retrieve print data, set parameters, and handle errors during the printing process. The program also manages the conversion of output to PDF format and facilitates file downloads.

Uploaded by

mihaela.traista
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

---------------------------------------------------------------------*

* Print of a delivery note by SAPscript SMART FORMS *


*----------------------------------------------------------------------*
REPORT zpv_mostre_publicitare_v2.

* declaration of data
INCLUDE rle_delnote_data_declare.
* definition of forms
INCLUDE rle_delnote_forms.
INCLUDE rle_print_forms.

*---------------------------------------------------------------------*
* FORM ENTRY
*---------------------------------------------------------------------*
FORM entry USING return_code us_screen.

DATA: lf_retcode TYPE sy-subrc.


xscreen = us_screen.
PERFORM processing USING us_screen
CHANGING lf_retcode.
IF lf_retcode NE 0.
return_code = 1.
ELSE.
return_code = 0.
ENDIF.

ENDFORM.
*---------------------------------------------------------------------*
* FORM PROCESSING *
*---------------------------------------------------------------------*
FORM processing USING proc_screen
CHANGING cf_retcode.

DATA: ls_print_data_to_read TYPE ledlv_print_data_to_read.


DATA: ls_dlv_delnote TYPE ledlv_delnote.
DATA: lf_fm_name TYPE rs38l_fnam.
DATA: ls_control_param TYPE ssfctrlop.
DATA: ls_composer_param TYPE ssfcompop.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
DATA: lf_formname TYPE tdsfname.
DATA: ls_addr_key LIKE addr_key.

DATA:
ls_pv_text TYPE zspv_predare_mostre,
ls_pv_mostre TYPE zspv_predare_mostre2,
lt_pv_mostre TYPE ztpv_predare_mostre,
lt_lips TYPE TABLE OF lips,
ls_lips TYPE lips.

DATA: lv_kunnr TYPE kunwe.

DATA: wa_control_parameters TYPE ssfctrlop.


DATA: wa_output_options TYPE ssfcompop.
DATA: wa_job_output_info TYPE ssfcrescl.
DATA: fmname TYPE tdsfname.
DATA: v_bin_filesize TYPE i.
DATA: v_filename TYPE string. "VALUE 'formtest.pdf'.
DATA: it_lines TYPE STANDARD TABLE OF tline.
DATA: it_docs TYPE STANDARD TABLE OF docs.
DATA: file_path TYPE string,
full_path TYPE string.

* SmartForm from customizing table TNAPR


lf_formname = tnapr-sform.

* determine print data


PERFORM set_print_data_to_read USING lf_formname
CHANGING ls_print_data_to_read
cf_retcode.

IF cf_retcode = 0.
* select print data
PERFORM get_data USING ls_print_data_to_read
CHANGING ls_addr_key
ls_dlv_delnote
cf_retcode.
ENDIF.

IF cf_retcode = 0.
PERFORM set_print_param USING ls_addr_key
CHANGING ls_control_param
ls_composer_param
ls_recipient
ls_sender
cf_retcode.
ENDIF.

IF cf_retcode = 0.
* determine smartform function module for delivery note
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING formname = lf_formname
* variant = ' '
* direct_call = ' '
IMPORTING fm_name = lf_fm_name
EXCEPTIONS no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
* error handling
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
ENDIF.

IF cf_retcode = 0.
"LS_DLV_DELNOTE-HD_GEN-deliv_numb

DATA : lv_vbeln TYPE LIKP-VBELN ,


LV_vbelv TYPE VBFA-VBELV,
lv_kunnr_s TYPE VBAK-KUNNR.
SELECT SINGLE lfdat, kunnr , VBELN FROM likp
WHERE vbeln = @ls_dlv_delnote-hd_gen-deliv_numb
INTO (@ls_pv_text-lfdat, @lv_kunnr ,@LV_VBELN).
"modif 05.11.2024
SELECT SINGLE VBELV FROM VBFA
WHERE vbeln = @LV_VBELN
INTO @lv_vbelv .
SELECT SINGLE KUNNR FROM VBAK
WHERE VBELN = @lv_vbelv
INTO @lv_kunnr_s.
SELECT SINGLE name1, name2 FROM kna1
WHERE kunnr = @lv_kunnr
INTO (@ls_pv_text-name1, @ls_pv_text-name2).
SELECT SINGLE stceg FROM kna1
WHERE kunnr = @lv_kunnr_s
INTO @ls_pv_text-stceg.

SELECT * FROM lips


WHERE vbeln = @ls_dlv_delnote-hd_gen-deliv_numb
INTO TABLE @lt_lips.

LOOP AT lt_lips INTO ls_lips.

SELECT SINGLE maktx FROM makt


WHERE matnr = @ls_lips-matnr
INTO @ls_pv_mostre-maktx.

ls_pv_mostre-matnr = ls_lips-matnr.
ls_pv_mostre-werks = ls_lips-werks.
ls_pv_mostre-lfimg = ls_lips-lfimg.
ls_pv_mostre-meins = ls_lips-meins.

APPEND ls_pv_mostre TO lt_pv_mostre.

ENDLOOP.

ls_pv_text-tabel = lt_pv_mostre.

*if nast-nacha = '1'.


wa_control_parameters-no_dialog = 'X'.
wa_control_parameters-getotf = 'X'.
wa_output_options-tddest = 'LP01'.

*Exporting data to smartforam


CALL FUNCTION lf_fm_name
EXPORTING
USER_SETTINGS = 'X'
i_vbeln = ls_dlv_delnote-hd_gen-deliv_numb
ls_pv_text = ls_pv_text
control_parameters = wa_control_parameters
output_options = wa_output_options
IMPORTING
job_output_info = wa_job_output_info
EXCEPTIONS
formatting_error = 1
* INTERNAL_ERROR = 2
* SEND_ERROR = 3
* USER_CANCELED = 4
* OTHERS = 5
.
IF sy-subrc <> 0.
* error handling
cf_retcode = sy-subrc.
PERFORM protocol_update.
* get SmartForm protocoll and store it in the NAST protocoll
PERFORM add_smfrm_prot. "INS_HP_335958
ENDIF.

* get SmartForm protocoll and store it in the NAST protocoll


* PERFORM ADD_SMFRM_PROT. DEL_HP_335958

*CALL FUNCTION 'CONVERT_OTF_2_PDF'


*
* IMPORTING
* bin_filesize = v_bin_filesize
* TABLES
* otf = wa_job_output_info-otfdata
* doctab_archive = it_docs
* lines = it_lines
* EXCEPTIONS
* err_conv_not_possible = 1
* err_otf_mc_noendmarker = 2
* OTHERS = 3.
*
*
*IF sy-subrc NE 0.
*
* WRITE: / 'conversion error, RC:', sy-subrc.
*
* STOP.
*
*ENDIF.
*
*
*
*CALL METHOD cl_gui_frontend_services=>file_save_dialog
*
* EXPORTING
* default_extension = 'pdf'
* file_filter = 'PDF Files (*.pdf)|*.pdf|All Files (*.*)|*.*'
** window_title =
** default_extension =
** default_file_name =
** with_encoding =
** file_filter =
** initial_directory =
** prompt_on_overwrite = 'X'
*
* CHANGING
* filename = v_filename
* path = file_path
* fullpath = full_path
** user_action =
** file_encoding =
* EXCEPTIONS
* cntl_error = 1
* error_no_gui = 2
* not_supported_by_gui = 3
* OTHERS = 4
*
* .
*
*IF sy-subrc <> 0.
** Implement suitable error handling here
*ENDIF.
**------------
*
*
**--------------------Downloading the Form------------------*
*
*CALL FUNCTION 'GUI_DOWNLOAD'
* EXPORTING
* bin_filesize = v_bin_filesize
* filename = v_filename
* filetype = 'BIN'
* TABLES
* data_tab = it_lines
* 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 NE 0.
*
* WRITE: / 'download error, RC:', sy-subrc.
*
* ENDIF.

*elseif nast-nacha = '2'. "wa_control_parameters-preview = 'X'.

CALL FUNCTION lf_fm_name


EXPORTING
i_vbeln = ls_dlv_delnote-hd_gen-deliv_numb
ls_pv_text = ls_pv_text
EXCEPTIONS
formatting_error = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
.
IF sy-subrc <> 0.
"error handling
cf_retcode = sy-subrc.
PERFORM protocol_update.
" get SmartForm protocoll and store it in the NAST protocoll
PERFORM add_smfrm_prot. "INS_HP_335958
ENDIF.

*
*endif.

ENDIF.
ENDFORM.

You might also like