Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
freshsett
Hi,freshsett hat geschrieben:Hallo zusammen,
ist es möglich, dass man eine Rechnung zum Zeitpunkt des Drucks eine PDF generiert und dem Anhang (Dienste zum Objekt) anlegt ?
Gruß freshsett
Folgende Benutzer bedankten sich beim Autor ralf.wenzel für den Beitrag:
freshsett
Folgende Benutzer bedankten sich beim Autor ralf.wenzel für den Beitrag:
freshsett
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Subroutinepool yfaktura_gos by TRON *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
* WARNING : NO POPUPS - NO COMMIT WORK IN HERE !!!!!!!!!!!!!!!!!!!!!!!!!
REPORT yfaktura_gos.
DATA: retcode LIKE sy-subrc. "Returncode
DATA: xscreen(1) TYPE c. "Output on printer or screen
TABLES: nast, "Messages
tnapr. "Programs & Forms
*&---------------------------------------------------------------------*
*& Form ENTRY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RETURN_CODE text
* -->US_SCREEN text
*----------------------------------------------------------------------*
FORM entry USING return_code TYPE i
us_screen TYPE c.
FIELD-SYMBOLS: <f> TYPE itcpp,
<p> TYPE ssfcrescl.
DATA pgnam TYPE na_pgnam." Programname
DATA ronam TYPE na_ronam."Formname
DATA fm_name TYPE rs38l_fnam. "genr.Druckbaustein
DATA lv_vec(80).
DATA spoolid TYPE rspoid.
CLEAR retcode.
xscreen = us_screen.
* Call the "Original" Printroutine
* RVADIN01 = Sapscript
* RLB_INVOICE = Smartforms
*-Orig program------+
* |
*-Orig Form-+ |
* | |
PERFORM entry(RVADIN01) USING return_code us_screen.
* Try Sapscript
ASSIGN ('(SAPLSTXC)ITCPP') TO <f>.
IF sy-subrc = 0 AND
NOT <f>-tdspoolid IS INITIAL AND
us_screen IS INITIAL.
PERFORM putgos USING <f>-tdspoolid.
UNASSIGN <f>.
ELSE.
* Try Smartforms
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = tnapr-sform
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
retcode = 1.
EXIT.
ENDIF.
SELECT SINGLE pname FROM tfdir INTO lv_vec
WHERE funcname = fm_name.
IF sy-subrc = 0.
CONCATENATE '(' lv_vec ')JOB_OUTPUT_INFO' INTO lv_vec.
ASSIGN (lv_vec) TO <p>.
IF sy-subrc = 0 AND
NOT <p>-spoolids[] IS INITIAL AND
us_screen IS INITIAL.
LOOP AT <p>-spoolids INTO spoolid.
PERFORM putgos USING spoolid.
EXIT.
ENDLOOP.
UNASSIGN <p>.
ENDIF. " have Ids
ENDIF." tfdir entry
ENDIF." sapscript/smartforms
IF retcode NE 0.
return_code = 1.
ELSE.
return_code = 0.
ENDIF.
ENDFORM. "ENTRY
*&---------------------------------------------------------------------*
*& Form putgos
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->SPOOLID text
*----------------------------------------------------------------------*
FORM putgos USING spoolid TYPE itcpp-tdspoolid.
DATA:
ls_fol_id TYPE soodk,
ls_obj_id TYPE soodk,
ls_obj_data TYPE sood1,
ls_folmem_k TYPE sofmk,
ls_note TYPE borident,
ls_object TYPE borident,
lv_ep_note TYPE borident-objkey.
* SRGBTBREL
DATA:
it_objhead TYPE STANDARD TABLE OF soli,
it_content LIKE STANDARD TABLE OF soli,
wa_content LIKE soli.
ls_object-objkey = nast-objky.
ls_object-objtype = 'VBRK'.
* convert
DATA lcharlen TYPE i VALUE %_charsize.
DATA i TYPE i.
DATA j TYPE i.
DATA lbuffer TYPE xstring.
DATA lword(2) TYPE x.
DATA cl_bconv TYPE REF TO cl_abap_conv_out_ce.
DATA cl_xconv TYPE REF TO cl_abap_conv_out_ce.
DATA: numbytes TYPE i,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount.
DATA: BEGIN OF pdf OCCURS 0,
t(134),
END OF pdf.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolid
no_dialog = ' '
* DST_DEVICE =
* PDF_DESTINATION =
IMPORTING
pdf_bytecount = numbytes
pdf_spoolid = pdfspoolid
* OTF_PAGECOUNT =
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = pdf
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11.
IF sy-subrc = 0.
cl_bconv = cl_abap_conv_out_ce=>create( ).
cl_xconv = cl_abap_conv_out_ce=>create( ).
CLEAR: i, j.
LOOP AT pdf.
DO 134 TIMES.
i = sy-index - 1.
lword = cl_abap_conv_out_ce=>uccp( pdf+i(1) ).
IF lcharlen > 1.
cl_xconv->write( n = 1 data = lword+1(1) ).
j = j + 1.
IF j GE numbytes. EXIT. ENDIF.
cl_xconv->write( n = 1 data = lword(1) ).
j = j + 1.
IF j GE numbytes. EXIT. ENDIF.
ENDIF.
ENDDO.
ENDLOOP.
lbuffer = cl_xconv->get_buffer( ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lbuffer
TABLES
binary_tab = it_content[].
CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
EXPORTING
it_contents_bin = it_content[]
IMPORTING
et_contents_bin = it_content[].
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region = 'B'
IMPORTING
folder_id = ls_fol_id
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.
ls_obj_data-objsns = 'O'.
ls_obj_data-objla = sy-langu.
ls_obj_data-objdes = 'Rechnung'.
ls_obj_data-file_ext = 'PDF'.
ls_obj_data-objlen = LINES( it_content ) * 255.
CALL FUNCTION 'SO_OBJECT_INSERT'
EXPORTING
folder_id = ls_fol_id
object_hd_change = ls_obj_data
object_type = 'EXT'
IMPORTING
object_id = ls_obj_id
TABLES
objhead = it_objhead
objcont = it_content
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
dl_name_exist = 4
folder_not_exist = 5
folder_no_authorization = 6
object_type_not_exist = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
OTHERS = 15.
IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.
ls_folmem_k-foltp = ls_fol_id-objtp.
ls_folmem_k-folyr = ls_fol_id-objyr.
ls_folmem_k-folno = ls_fol_id-objno.
ls_folmem_k-doctp = ls_obj_id-objtp.
ls_folmem_k-docyr = ls_obj_id-objyr.
ls_folmem_k-docno = ls_obj_id-objno.
lv_ep_note = ls_folmem_k.
ls_note-objtype = 'MESSAGE'.
ls_note-objkey = lv_ep_note.
CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
obj_rolea = ls_object
obj_roleb = ls_note
relationtype = 'ATTA'
EXCEPTIONS
no_model = 1
internal_error = 2
unknown = 3
OTHERS = 4.
IF sy-subrc <> 0.
ENDIF.
ENDIF."SO_OBJECT_INSERT
ENDIF." convert otf
ENDFORM. "putgos
Code: Alles auswählen.
concatenate lines of pdf into lbuffer in byte mode. "Nullzeichen am Ende weil Tabelle mit fixer Zeilenbreite
lbuffer = lbuffer(numbytes). "Die Bytelänge aus dem CONVERT_OTFSPOOLJOB_2_PDF um die unnötigen Nullzeichen zu entfernen.