Das ist auf jeden Fall einfacher, als das Anlegen einer "internen Anlage" per Programm, weil die Funktion "Drucken und Ablegen" am Funktionsbaustein OPEN_FORM schon vorhanden ist... über ArchiveLink mit dem Fertigungsauftrag verbinden..
Code: Alles auswählen.
* OPEN_FORM to open form
PERFORM PPPR_OPEN_FORM USING 'PAG_RES'.
Code: Alles auswählen.
data l_OPTIONS type ITCPO.
data l_ARCHIVE_INDEX type TOA_DARA.
data l_ARCHIVE_PARAMS type ARC_PARAMS.
l_options = pr_options.
l_options-TDARMOD = '3'. " setzen auf "drucken und ablegen"
l_options-tdnewid = 'X'.
l_options-tdlifetime = '8'.
l_options-tddelete = ''.
* Archive Index (XXXX gegen Deine Parameter ersetzen)
l_ARCHIVE_INDEX-MANDANT = sy-mandt.
l_ARCHIVE_INDEX-SAP_OBJECT = XXXX
l_ARCHIVE_INDEX-OBJECT_ID = XXXXX .
l_ARCHIVE_INDEX-AR_OBJECT = XXXX.
l_ARCHIVE_INDEX-RESERVE+0(6) = XXX.
* set the values the Archive paramters
l_ARCHIVE_PARAMS-SAP_OBJECT = XXXX.
l_ARCHIVE_PARAMS-ARCHIV_ID = XXX
l_ARCHIVE_PARAMS-AR_OBJECT = XXXXX.
l_ARCHIVE_PARAMS-DOC_TYPE = XXXXX
l_ARCHIVE_PARAMS-MANDANT = sy-mandt.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
ARCHIVE_INDEX = l_ARCHIVE_INDEX
ARCHIVE_PARAMS = l_ARCHIVE_PARAMS
DEVICE = 'PRINTER'
DIALOG = SPACE
FORM = PRINT_CO-FORML
LANGUAGE = PRINT_CO-SPRAS
OPTIONS = l_OPTIONS
EXCEPTIONS
CANCELED = 01
DEVICE = 02
FORM = 03
OPTIONS = 04
UNCLOSED = 05.
CALL FUNCTION 'START_FORM'
EXPORTING
STARTPAGE = 'PAG_RES'.
CLEAR FLG_MAIN_STARTED.
Code: Alles auswählen.
PERFORM zpppr_open_form USING 'PAG_STD'.
Code: Alles auswählen.
FORM zpppr_open_form USING STARTPAGE.
DATA: L_OPTIONS TYPE ITCPO,
L_ARCHIVE_INDEX TYPE TOA_DARA,
L_ARCHIVE_PARAMS TYPE ARC_PARAMS,
I_ARCHIVE_PARAMS TYPE ARC_PARAMS,
I_RESULT TYPE ITCPP.
pr_options-TDARMOD = '3'. " drucken und ablegen
* Archive Index (XXXX gegen Deine Parameter ersetzen)
l_ARCHIVE_INDEX-SAP_OBJECT = 'BUS2005'.
l_ARCHIVE_INDEX-OBJECT_ID = caufvd-aufnr.
l_ARCHIVE_INDEX-AR_OBJECT = 'ZPP1001OBJ'.
* set the values the Archive paramters
l_ARCHIVE_PARAMS-SAP_OBJECT = 'BUS2005'.
l_ARCHIVE_PARAMS-ARCHIV_ID = '1P'.
l_ARCHIVE_PARAMS-AR_OBJECT = 'ZPP1001OBJ'.
l_ARCHIVE_PARAMS-DOC_TYPE = 'PDF'.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
ARCHIVE_INDEX = l_ARCHIVE_INDEX
ARCHIVE_PARAMS = l_ARCHIVE_PARAMS
DEVICE = 'PRINTER'
DIALOG = SPACE
FORM = PRINT_CO-FORML
LANGUAGE = PRINT_CO-SPRAS
OPTIONS = PR_OPTIONS
IMPORTING
NEW_ARCHIVE_PARAMS = I_ARCHIVE_PARAMS
RESULT = I_RESULT
EXCEPTIONS
CANCELED = 01
DEVICE = 02
FORM = 03
OPTIONS = 04
UNCLOSED = 05.
CALL FUNCTION 'START_FORM'
EXPORTING
STARTPAGE = 'PAG_RES'
ARCHIVE_INDEX = l_ARCHIVE_INDEX.
CLEAR FLG_MAIN_STARTED.
Code: Alles auswählen.
l_ARCHIVE_PARAMS-DOC_TYPE = 'PDF'.
Das Programm verwendet ein Sapscriptformular (ZTEST im Anhang) und legt es im Archiv ab.OAC0
Z4 ARCHLINK HTTP-Content-Server 0045
OAC2
SDOORDER Auftragsbestätigung OTF
OAC3
VBAK SDOORDER X Z4 TOA01 10
Code: Alles auswählen.
:
* Im VERBUCHER kein Commit work !!
*Values: 1: in update task, 0: not in update task
CALL FUNCTION 'TH_IN_UPDATE_TASK'
IMPORTING
in_update_task = l_utask.
IF l_utask IS INITIAL.
COMMIT WORK.
ENDIF.
:
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report ZTEST_ARCHIVE_SAPSCRIPT *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZTEST_ARCHIVE_SAPSCRIPT.
* Druck Variablen
DATA:
l_utask TYPE sy-subrc,
dpar TYPE itcpo,
l_toa TYPE toa_dara,
l_arc TYPE arc_params.
START-OF-SELECTION.
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME.
SELECTION-SCREEN SKIP.
PARAMETERS: lp TYPE itcpo-tddest DEFAULT 'LP01'.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK a.
* Simulation Drucken und Ablegen einer Auftragsbestätigung (BelegNr. 2)
CLEAR l_toa.
*l_toa-FUNCTION
l_toa-mandant = sy-mandt.
*l_toa-DEL_DATE
l_toa-sap_object = 'VBAK'.
l_toa-ar_object = 'SDOORDER'.
l_toa-object_id = '0000000002'. "Belegnummer
*l_toa-FORM_ID
*l_toa-FORMARCHIV
*l_toa-RESERVE
*l_toa-NOTIZ
CLEAR l_arc.
l_arc-sap_object = 'VBAK'.
l_arc-ar_object = 'SDOORDER'.
*l_arc-ARCHIV_ID
*l_arc-DOC_TYPE
*l_arc-RPC_HOST
*l_arc-RPC_SERVIC
*l_arc-INTERFACE
l_arc-mandant = sy-mandt.
*l_arc-REPORT
*l_arc-INFO
*l_arc-ARCTEXT
*l_arc-DATUM
l_arc-arcuser = sy-uname.
l_arc-printer = lp.
*l_arc-FORMULAR
*l_arc-ARCHIVPATH
*l_arc-PROTOKOLL
*l_arc-VERSION
*l_arc-ACHECK
* Drucker-Parameter Defaults
CLEAR dpar.
dpar-tddest = lp. "Spool: Ausgabegerät
dpar-tdcopies = 0. "Anzahl Ausdrucke
dpar-tdimmed = 'X'. "Druckparameter, sofort ausgeben
dpar-tddelete =' '. "Druckparameter, löschen nach Ausgabe
* dpar-tdnewid = 'X'. "Druckparameter, neuer Spool-Auftrag
* dpar-tdlifetime = '1'."Spool-Verweildauer (Tage)
* dpar-tdfinal = 'X'. "Spool-Auftrag ist abgeschlossen
dpar-tdprogram = sy-cprog.
dpar-tdarmod = 3.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
archive_index = l_toa
archive_params = l_arc
device = 'PRINTER'
dialog = ' '
form = 'ZTEST'
language = 'D'
OPTIONS = dpar
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* SPONUMIV =
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
EXCEPTIONS
canceled = 1
device = 2
form = 3
OPTIONS = 4
unclosed = 5
mail_options = 6
archive_error = 7
invalid_fax_number = 8
more_params_needed_in_batch = 9
spool_error = 10
codepage = 11
OTHERS = 12.
IF sy-subrc = 0.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'MAIN'
window = 'MAIN'.
CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
* RESULT = Result
* RDI_RESULT =
* TABLES
* OTFDATA =
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
codepage = 5
OTHERS = 6.
ENDIF.
* Im VERBUCHER kein Commit work !!
*Values: 1: in update task, 0: not in update task
CALL FUNCTION 'TH_IN_UPDATE_TASK'
IMPORTING
in_update_task = l_utask.
IF l_utask IS INITIAL.
COMMIT WORK.
ENDIF.
Code: Alles auswählen.
FORM zpppr_open_form USING STARTPAGE.
DATA: ls_archive_index TYPE toa_dara,
ls_archive_params TYPE arc_params,
ls_params TYPE pri_params.
* Druckoptionen anpassen:
pr_options-tdarmod = '3'. "drucken und ablegen
* Archivindex (toa_dara) ermitteln:
ls_archive_index-mandant = sy-mandt.
ls_archive_index-sap_object = 'BUS2005'. "BusinessObjekt 'Fertigungsauftrag'
ls_archive_index-object_id = caufvd-aufnr. "Verknüpfung zwischen Auftrag und Dokument
ls_archive_index-ar_object = 'ZPP1001OBJ'. "Dokumentart
ls_archive_index-reserve(6) = 'COMMIT'. "COMMIT nach close_form
* die restlichen Parameter kommen aus dem Customizing (TCode OAC2)
* Archivparameter (arc_params) ermitteln:
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
destination = sy-pdest
immediately = 'X'
new_list_id = 'X'
sap_object = ls_archive_index-sap_object
ar_object = ls_archive_index-ar_object
archive_mode = '3' "drucken und ablegen
no_dialog = 'X'
IMPORTING
out_parameters = ls_params
out_archive_parameters = ls_archive_params
EXCEPTIONS
archive_info_not_found = 01
invalid_print_params = 02
invalid_archive_params = 03.
* Formulardruck öffnen:
CALL FUNCTION 'OPEN_FORM'
EXPORTING
archive_index = ls_archive_index
archive_params = ls_archive_params
device = 'PRINTER'
dialog = space
form = print_co-forml
language = print_co-spras
options = pr_options
EXCEPTIONS
canceled = 01
device = 02
form = 03
options = 04
unclosed = 05.
* Formular ausführen:
CALL FUNCTION 'START_FORM'
EXPORTING
startpage = startpage
archive_index = ls_archive_index.
CLEAR flg_main_started.
ENDFORM. " zpppr_open_form
Code: Alles auswählen.
ls_archive_index-reserve(6) = 'COMMIT'.
Code: Alles auswählen.
ls_archive_index-reserve(6) = 'COMMIT'.
Code: Alles auswählen.
** Objekt-Id bestimmen
objid+00(16) = nast-objky.
objid+16(04) = nast-kschl.
objid+20(08) = nast-erdat.
objid+28(06) = nast-eruhr.
* DARA-Parameter bestimmen
wa_dara-mandant = sy-mandt.
wa_dara-sap_object = 'BUS2107001'. "Objekttyp
wa_dara-ar_object = 'ZIX_B_ZIB1'. "Dokumentart
wa_dara-object_id = objid. "Objekt-Id
wa_dara-reserve(6) = 'COMMIT'.
* Archiv-Parameter bestimmen
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
new_list_id = 'X'
archive_mode = '3'
ar_object = wa_dara-ar_object
immediately = 'X'
no_dialog = 'X'
sap_object = wa_dara-sap_object
IMPORTING
out_archive_parameters = wa_archiv
out_parameters = wa_print
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF sy-subrc <> 0. rc = sy-subrc. EXIT. ENDIF.
Code: Alles auswählen.
FORM pppr_open_form USING startpage.
DATA: l_options TYPE itcpo,
l_archive_index TYPE toa_dara,
l_archive_params TYPE arc_params,
i_archive_params TYPE arc_params,
i_result TYPE itcpp,
ls_params TYPE pri_params,
ls_archive_params TYPE arc_params.
pr_options-tdarmod = '3'. " drucken und ablegen
* Archive Index (XXXX gegen Deine Parameter ersetzen)
l_archive_index-mandant = sy-mandt.
l_ARCHIVE_INDEX-sap_object = 'BUS2005'.
l_ARCHIVE_INDEX-object_id = caufvd-aufnr.
l_ARCHIVE_INDEX-ar_object = 'ZPPKOMP'.
l_archive_index-reserve(6) = 'COMMIT'.
* die restlichen Parameter kommen aus dem Customizing (TCode OAC2)
* Archivparameter (arc_params) ermitteln:
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
destination = sy-pdest
immediately = 'X'
new_list_id = 'X'
sap_object = l_archive_index-sap_object
ar_object = l_archive_index-ar_object
archive_mode = '2' "nur ablegen
no_dialog = 'X'
IMPORTING
out_parameters = ls_params
out_archive_parameters = ls_archive_params
EXCEPTIONS
archive_info_not_found = 01
invalid_print_params = 02
invalid_archive_params = 03.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
archive_index = l_ARCHIVE_INDEX
archive_params = ls_archive_params
device = 'PRINTER'
dialog = space
form = print_co-forml
language = print_co-spras
options = pr_options
EXCEPTIONS
canceled = 01
device = 02
form = 03
options = 04
unclosed = 05.
CALL FUNCTION 'START_FORM'
EXPORTING
startpage = startpage.
CLEAR flg_main_started.
ENDFORM.
Code: Alles auswählen.
FORM pppr_close_form.
DATA: l_utask TYPE sy-subrc.
IF NOT flg_main_started IS INITIAL.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'MAIN_FINISH'
window = 'MAIN'.
ENDIF.
CALL FUNCTION 'END_FORM'.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
result = pr_result
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
codepage = 5
OTHERS = 6.
* Im VERBUCHER kein Commit work !!
*Values: 1: in update task, 0: not in update task
CALL FUNCTION 'TH_IN_UPDATE_TASK'
IMPORTING
in_update_task = l_utask.
IF l_utask IS INITIAL.
COMMIT WORK.
ENDIF.
ENDFORM.