I would like to share my experience from one of Ariba network integration with ECC project. The requirement was to send PO pdf as part of the attachment list when sending PO cXML to Ariba network. There was already a custom output type (I will call this PRN1) defined for generating the PO PDF. After processing PRN1, PO pdf gets stored in an archive drive. So only thing we have to do is while processing our ARIBA output (I will call this ZZAR), somehow process the PRN1 output and read the PO PDF that gets stored in archive and include that as part of the attachment list.
Design and Implementation
The processing program and form for PRN1 output are ZPRN1PROCESS and PROCESS_PRN1
Define a custom output type ZZAR and processing program as ZARIBA_PROCESS_PROGRAM. This program is a copy of standard processing program ARBERP_NAST_CXML_MESSAGE
The approach that we took is as below
- Copy the processing form PROCESS_PRN1 to a new form form called PROCESS_PRN1_FR_ZZAR
- Here add the below code, which processes the PRN1 output and stores the PO PDF in archive
SELECT SINGLE * FROM nast INTO nast WHERE objky = ent_nast-objky AND kschl = 'PRN1' AND kappl = 'EF' AND vstat = '0'. IF sy-subrc = 0. SELECT SINGLE * FROM tnapr INTO tnapr WHERE kschl = 'PRN1' AND kappl = 'EF'. x_formty = '1'. zzusbest-vertrag = ' '. PERFORM old_entry_neu USING ent_retco ent_screen. PERFORM nast_update(rsnast00) USING ent_retco. ENDIF.
- Create a custom RFC FM with below import parameters
- include the below code to process the PRN1 output
IF is_nast-vstat = 0. PERFORM PROCESS_PRN1_FR_ZZAR(ZPRN1PROCESS) USING iv_returncode iv_us_screen is_nast. ENDIF. COMMIT WORK.
Define a custom output type as ZZAR and processing program as
ZARIBA_PROCESS_PROGRAM ( this is the copy of standard processing program ARBERP_NAST_CXML_MESSAGE)
Within the form SEND_DOCUMNET include below code
DATA: lv_name(120) TYPE c, lo_nast TYPE REF TO cl_arberp_nast, ls_nast TYPE nast. * tell the calling program that the call was OK CLEAR: iv_returncode. * define field symbols FIELD-SYMBOLS: <fs_nast> TYPE any. * get NAST information via global assign from calling program CONCATENATE '(RSNAST00)' 'NAST' INTO lv_name. ASSIGN (lv_name) TO <fs_nast>. MOVE-CORRESPONDING <fs_nast> TO ls_nast. DATA: ls_nast_prn1 TYPE nast. SELECT SINGLE * FROM nast INTO ls_nast_prn1 WHERE objky = ls_nast-objky AND kschl = 'PRN1' AND kappl = 'EF' AND vstat = '0'. IF sy-subrc = 0. *call FM in new task CALL FUNCTION 'ZMM_NEU1_PROCESS' STARTING NEW TASK 'ZARITASK' EXPORTING is_nast = ls_nast_neu1 iv_returncode = iv_returncode iv_us_screen = iv_us_screen. * WAIT UP TO 5 SECONDS. * * create an object of the nast class and call the send method CREATE OBJECT lo_nast EXPORTING iv_appl_comp_id = if_arbfnd_appl_comp_id_c=>gc_erp is_nast = ls_nast. lo_nast->send_message( EXPORTING iv_us_screen = iv_us_screen CHANGING cv_returncode = iv_returncode ).
The reason why we have to call the FM in separate task is the FM has COMMIT WORK inside. We are trying to process PRN1 output inside ZZAR output. Output processing in general is done in update task and as per SAP standard update process needs COMMIT WORK to complete the process. We cannot have COMMIT WORK inside an update process. So to avoid this we are calling processing of PRN1 in a separate task with COMMIT WORK inside the FM and wait for 5 seconds to allow system to finish the processing of PRN1. After that we proceed with ZZAR output processing. I have not provided here the details of how to fetch the PO PDF data from Archive as this is not the main purpose of the blog.