SAP Ariba Cloud Integration - ERP Q&A https://www.erpqna.com Trending SAP Career News and Guidelines Mon, 29 Jan 2024 10:47:12 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.3 https://www.erpqna.com/wp-content/uploads/2021/11/cropped-erpqna-32x32.png SAP Ariba Cloud Integration - ERP Q&A https://www.erpqna.com 32 32 Send SAPscript form PDF from output type message to Business Network https://www.erpqna.com/send-sapscript-form-pdf-from-output-type-message-to-business-network/?utm_source=rss&utm_medium=rss&utm_campaign=send-sapscript-form-pdf-from-output-type-message-to-business-network Sat, 14 Oct 2023 09:12:49 +0000 https://www.erpqna.com/?p=78959 One of the common requirements when we are implementing SAP Ariba Commerce Automation or Digital Supplier Network, is to send attachments inside the purchase order to Ariba Business Network, but this functionality is already included implementing the next Include in the User Exit EXIT_SAPLEINM_002: But…what happens when you want to send the PDF of the […]

The post Send SAPscript form PDF from output type message to Business Network first appeared on ERP Q&A.

]]>
One of the common requirements when we are implementing SAP Ariba Commerce Automation or Digital Supplier Network, is to send attachments inside the purchase order to Ariba Business Network, but this functionality is already included implementing the next Include in the User Exit EXIT_SAPLEINM_002:

INCLUDE ARBCIG_ORDER_REQUEST_002 IF FOUND.

But…what happens when you want to send the PDF of the purchase order, and this PDF is generated in a SAPScript form, that is executed inside the output type message:

Message Output

This Output type is configured in NACE transaction where you enter the form name of the SAPScript that will be triggered:

NACE Output Type

The complication of this functionality is that this printout of the purchase order, is triggered when the output message is already processed and the purchase order is already approved, but when you are sending the purchase order to Ariba Business Network, this steps are not finished yet, so you must implement a logic to print the PDF of the purchase order, executing manually the SAPScript in real time when the PO is sent to Business Network.

We can do that implementing the BADI ARBCIG_BADI_ATTACHMENT_UTIL where we process the attachments of the PO.

BADI ARBCIG_BADI_ATTACHMENT_UTIL

We only need the method PRE_ATTACHMENT_PROCESS:

METHOD PRE_ATTACHMENT_PROCESS

Inside this method, we will implement the next logic:

  1. Search in NAST table with the PO ID if exists the message you are configured in NACE transaction for the purchase order you are approving.
  2. Read the data of the PO from MF ME_READ_PO_FOR_PRINTING.
  3. Execute the MF ECP_PRINT_PO with the form ID.
  4. Read the OTF data of the form with MF READ_OTF_FROM_MEMORY.
  5. Convert OTF data to PDF with MF CONVERT_OTF.
  6. Encrypt the PDF from Hexadecimal to Base64 with MF SCMS_BASE64_ENCODE_STR.
  7. Complete the E1ARBCIG_ATTACH_HDR_DET segment with header data of attachment.
  8. Complete the E1ARBCIG_ATTACH_CONTENT_DET segment with the content of Base64 string.

All this steps are detailed in the next code:

method IF_ARBCIG_ATTACHMENT_UTIL~PRE_ATTACHMENT_PROCESS.


    DATA: gint_nast      TYPE nast,
          lv_count       TYPE i,
          lv_ebeln       TYPE ebeln,
          ent_screen     TYPE c,
          ent_retco      TYPE i,
          l_nast         TYPE nast,
          l_druvo        TYPE t166k-druvo,
          l_from_memory,
          toa_dara       TYPE toa_dara,
          arc_params     TYPE arc_params,
          aux_form       TYPE tnapr-fonam VALUE 'ZMMSS_PEDCOMPRAS',
          lv_message     TYPE tnapr-fonam VALUE 'ZPC',
          lt_docs        TYPE TABLE OF docs,
          l_doc          TYPE meein_purchase_doc_print,
          otf            TYPE TABLE OF itcoo,
          pdf_bytecount  TYPE i,
          nom_archivo    TYPE string,
          pdfout         TYPE TABLE OF tline,
          lv_debug       TYPE char1,
          pdf            TYPE XSTRING,
          ls_e1edk01     TYPE e1edk01,
          ls_hdr_det     TYPE E1ARBCIG_ATTACH_HDR_DET,
          ls_hdr_content TYPE E1ARBCIG_ATTACH_CONTENT_DET,
          idoc_data      TYPE edidd,
          lv_base64      TYPE string,
          len            TYPE i,
          lv_offset_mx   TYPE i,
          lv_offset_mn   TYPE i,
          div            TYPE i,
          temp           TYPE i.

*"---------------------------------------------------------------------
*" NOTES:
*"  1) Control display of PO in GUI window
*"       ENT_SCREEN = 'X'   => PO is displayed in GUI window
*"       ENT_SCREEN = space => Spool file of the PO is created
*"                               Spool number is returned in message
*"  2) Write PO to memory as OTF
*"       NAST-SORT1 = 'SWP' => PO is written to memory as OTF
*"                               Memory ID = PO Number - Use function
*"                               READ_OTF_FROM_MEMORY to retrieve
*"       NAST-SORT1 = space => PO is NOT written to memory
*"---------------------------------------------------------------------

*Infinite LOOP only for debug
    SELECT SINGLE low
    FROM ARBCIG_TVARV
    WHERE name = 'DEBUG_PRE_ATTACHMENT_PROCESS'
    INTO @lv_debug.

    IF lv_debug EQ 'X'.
      WHILE lv_debug IS NOT INITIAL.
      ENDWHILE.
    ENDIF.

*First we obtain the PO ID from field
*Belnr from segment e1edk01
    READ TABLE c_edidd[] INTO idoc_data INDEX 1.
    CHECK idoc_data-segnam EQ 'E1EDK01'.
    MOVE idoc_data-sdata TO ls_e1edk01.

    lv_ebeln = ls_e1edk01-belnr.

    IF lv_ebeln IS NOT INITIAL.

*Field lv_message is the output type message where the form is configured
      SELECT SINGLE *
         FROM nast INTO gint_nast WHERE objky EQ lv_ebeln
          AND kschl EQ lv_message.

*We ensure the output type exists for the PO.
      CHECK sy-subrc EQ 0.

      gint_nast-sort1 = 'SWP'.

      IF gint_nast-aende EQ space.
        l_druvo = '1'.
      ELSE.
        l_druvo = '2'.
      ENDIF.

      CLEAR ent_retco.

      CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'
        EXPORTING
          IX_NAST        = gint_nast
          IX_SCREEN      = ent_screen
        IMPORTING
          EX_RETCO       = ent_retco
          DOC            = l_doc
          EX_NAST        = l_nast
        CHANGING
          CX_DRUVO       = l_druvo
          CX_FROM_MEMORY = l_from_memory.

*      CHECK ent_retco EQ 0.
      IF ent_retco EQ 3.
        "It means the PO is not released yet, but this is normal, dont panic.
        
        CLEAR ent_retco.
      ENDIF.

      CHECK ent_retco EQ 0.

*Field aux_form is the SAPScript ID form.
      CALL FUNCTION 'ECP_PRINT_PO'
        EXPORTING
          IX_NAST        = l_nast
          IX_DRUVO       = l_druvo
          DOC            = l_doc
          IX_SCREEN      = ent_screen
*         IX_XFZ         =
*         IX_MFLAG       = ' '
          IX_FROM_MEMORY = l_from_memory
          IX_TOA_DARA    = toa_dara
          IX_ARC_PARAMS  = arc_params
          IX_FONAM       = aux_form
        IMPORTING
          EX_RETCO       = ent_retco.

      CLEAR otf.

      CALL FUNCTION 'READ_OTF_FROM_MEMORY'
        EXPORTING
          MEMORY_KEY = l_nast-objky " PO Number
        TABLES
          OTF        = otf
*       EXCEPTIONS
*         MEMORY_EMPTY       = 1
*         OTHERS     = 2
        .
      IF sy-subrc <> 0.
*        RAISE otf_error.
      ENDIF.

*We transform OTF to PDF
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = 'PDF'
        IMPORTING
          bin_filesize          = pdf_bytecount
          BIN_FILE              = PDF
        TABLES
          otf                   = otf
          lines                 = pdfout
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          OTHERS                = 4.
      IF sy-subrc <> 0.
*        RAISE error.  " oops
      ENDIF.

*We transform the PDF from Hexa to Base64
      CHECK PDF IS NOT INITIAL.

      CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
        EXPORTING
          INPUT  = PDF
        IMPORTING
          OUTPUT = lv_base64.

*If all its OK, we already have the PDF in Base64
      CHECK lv_base64 IS NOT INITIAL.

      CLEAR idoc_data.
*We insert segment E1ARBCIG_ATTACH_HDR_DET.
      idoc_data-segnam = 'E1ARBCIG_ATTACH_HDR_DET'.
      CONCATENATE lv_ebeln  '.pdf' INTO ls_hdr_det-filename.
      ls_hdr_det-charset = 'UTF-8'.
      ls_hdr_det-contentid = '1'.
      ls_hdr_det-contenttype = 'application/pdf'.
      ls_hdr_det-contentlength = pdf_bytecount.
      CONDENSE ls_hdr_det-contentlength NO-GAPS.
      MOVE ls_hdr_det TO idoc_data-sdata.
      APPEND idoc_data TO c_edidd[].

*We insert segments E1ARBCIG_ATTACH_CONTENT_DET.
      CLEAR idoc_data.
      idoc_data-segnam = 'E1ARBCIG_ATTACH_CONTENT_DET'.
      len = strlen( lv_base64 ).
      lv_offset_mx = 255.
      lv_offset_mn = 0.
      div = ceil( len / 255 ).
      do div times.
        clear ls_hdr_content.
        IF lv_offset_mn GE len.
          "Last loop
          EXIT.
        ELSE.
          temp = len - lv_offset_mn.
          IF temp LT lv_offset_mx.
          "Last loop
            ls_hdr_content-content = lv_base64+lv_offset_mn(temp).
            MOVE ls_hdr_content TO idoc_data-sdata.
            APPEND idoc_data TO c_edidd[].
            EXIT.
          ENDIF.
          ls_hdr_content-content = lv_base64+lv_offset_mn(lv_offset_mx).
          MOVE ls_hdr_content TO idoc_data-sdata.
          APPEND idoc_data TO c_edidd[].
          lv_offset_mn = lv_offset_mn + lv_offset_mx.
        ENDIF.
      enddo.

    ENDIF.

  endmethod.

Summary

As a final result, the buyer will only add the message output type in the purchase order, without need of attaching anything to the purchase order, and the system automatically will print this PDF in background and will be attached this PDF to the IDOC sent to business network.

IDOC with attachments

And finally, the supplier will have the PDF inside the purchase order in business network:

Business Network with PDF
Rating: 0 / 5 (0 votes)

The post Send SAPscript form PDF from output type message to Business Network first appeared on ERP Q&A.

]]>
Integration from one SAP ERP to two SAP Ariba Realms through SAP BTP Integration Suite https://www.erpqna.com/integration-from-one-sap-erp-to-two-sap-ariba-realms-through-sap-btp-integration-suite/?utm_source=rss&utm_medium=rss&utm_campaign=integration-from-one-sap-erp-to-two-sap-ariba-realms-through-sap-btp-integration-suite Thu, 15 Jun 2023 12:05:01 +0000 https://www.erpqna.com/?p=75449 Disclaimer: SAP Ariba Cloud Integration Gateway (CIG) has been renamed to SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network, some graphics may still refer to the previous name, mainly due to size restrictions. Business Case A customer wants to migrate an SAP Ariba realm to the SAP Ariba realms of the […]

The post Integration from one SAP ERP to two SAP Ariba Realms through SAP BTP Integration Suite first appeared on ERP Q&A.

]]>
Disclaimer: SAP Ariba Cloud Integration Gateway (CIG) has been renamed to SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network, some graphics may still refer to the previous name, mainly due to size restrictions.

Business Case

A customer wants to migrate an SAP Ariba realm to the SAP Ariba realms of the global company.

This global company has two different Ariba Accounts, and therefore two different ANIDs and two different SAP Ariba Realms. One account is used for SAP Business Network (Ariba Network / Commerce Automation) while the other is used for SAP Ariba Sourcing & Contracts.

To summarize: in this business case, 2 different SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network (ex CIG) accounts are in use, alongside a single SAP ERP system.

Connectivity Diagram

From left to right: the connection is from the SAP ERP to SAP BTP Integration Suite and then Integration Suite bifurcates the payloads to the corresponding SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network account.

Implemented Solution

SAP Integration Suite needs to be implemented as a middleware using the SAP ERP and SAP S/4HANA Integration with SAP Ariba package. Furthermore, two iflows need to be edited to determine to which SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network the payload must go to based on whether it is a Sourcing & Contracts or a Commerce Automation one.

Details and Configuration

Basic configuration

1. In the “Discovery” section in the SAP Integration Suite the Ariba package must be copied, the search functionality can be used to easily find it.

2. All required iflows for the customer need to be deployed, in this example the following are deployed:

i. SOAP Outbound Pass-Through Content for Ariba Applications
ii. SOAP Inbound Pass-Through Content for Ariba
iii. IDOC Outbound Pass-Through Content for Ariba Network
iv. SOAP Outbound Pass-Through Content for Ariba Network

3. The SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network certificate must be added to the CPI KeyStore

4. The user credentials must be deployed in the SAP Integration Suite “Security Materials”. Usually, only two user credentials can be found here: the SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network user and the SAP ECC or SAP S/4HANA communication user. In this business case, since 2 different SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network accounts are used, then 3 user credentials will be deployed.

5. The Value Mappings must be configured in the “SAP ERP and S/4HANA with Cloud Integration Gateway” package

For the purpose of this demonstration, the full list of value mappings will not be shown. Please refer to the following section for the customized Value Mappings.

Customizations

Custom variables to be added in the value mappings:

i. HCI Connection: as per standard only one Value Mapping is required to be completed. This field refers to the credential for the “SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network” user.

For this business case, as two “SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network” are in use, the standard value mapping is used for the Network account and an extra value mapping must be added for the Sourcing SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network account. For this demonstration that additional credential is named “Connection_S2C”.

ii. HCI Solution: this value mapping contains the different SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network endpoints. As per standard only “Apps”, “MasterData”, “Sourcing_Direct” and “Network” are displayed.
Even if the “Network” value mapping is expected to work for Commerce Automation IDocs, such as Purchase Orders, it does not account for Sourcing IDocs (RFQ). To include these documents a new value mapping is created, named “Sourcing_IDOC”

2. Two of the deployed iflows had to be edited:

i. SOAP Outbound Pass-Through Content for Ariba Applications

An extra script must be added between the XSLT mapping and the standard script.
The custom script is really simple: if the incoming message is for Sourcing, a header property called docType is set with the value “Sourcing”.

Then the standard script must also be edited to account for this header property.

This script chooses the connection credentials based on the docType variable. If the value of the docType variable is “Sourcing”, it will get the connection credentials from the custom value mapping “Connection_S2C”. The same behavior will occur for Master Data payloads.Important Note: If the customer has Ariba Procurement Master Data integration, this iflow will require further customization to account for that.

ii. IDOC Outbound Pass-Through Content for Ariba Network

Both steps from this iflow must be edited, starting with the XSLT mapping whose logic is the following one: if the incoming payload is an ”ARBCIG_REQOTE” IDoc, the “docType” header property is set to “Sourcing”, otherwise it is set to “IDOC”.

The script also must be modified to make use of “docType” header property

Similar to the previous iflow, if the value of “docType” is “Sourcing” then the “Connection_S2C” credential will be used instead of the standard one, in order for this payload to be sent to the Sourcing SAP Integration Suite, Managed Gateway for Spend Management and SAP Business Network.

Rating: 0 / 5 (0 votes)

The post Integration from one SAP ERP to two SAP Ariba Realms through SAP BTP Integration Suite first appeared on ERP Q&A.

]]>
Integrate Ariba ITK Services with CPI https://www.erpqna.com/integrate-ariba-itk-services-with-cpi/?utm_source=rss&utm_medium=rss&utm_campaign=integrate-ariba-itk-services-with-cpi Wed, 04 Jan 2023 11:18:31 +0000 https://www.erpqna.com/?p=71549 Requirement: Integrate SAP Ariba ITK services with SAP CPI. Overview SAP Ariba ITK (Integration Tool Kit) helps to integrate SAP Ariba with any ERP system to exchange master and transactional data via coma-separated-value (CSV) file upload and download. Refer SAP Ariba integration toolkit guide SAP Ariba integration toolkit guide for more details. To integrate SAP […]

The post Integrate Ariba ITK Services with CPI first appeared on ERP Q&A.

]]>
Requirement:

Integrate SAP Ariba ITK services with SAP CPI.

Overview

SAP Ariba ITK (Integration Tool Kit) helps to integrate SAP Ariba with any ERP system to exchange master and transactional data via coma-separated-value (CSV) file upload and download. Refer SAP Ariba integration toolkit guide SAP Ariba integration toolkit guide for more details. To integrate SAP Ariba ITK with SAP PO, SAP Ariba Integration Toolkit is installed on SAP PO. SAP Ariba Procurement Solution will generate the data in a CSV file and place it the desired SAP PO SFTP folder location. But in SAP CPI there is no such provision to install integration toolkit. To achieve this SAP Ariba is exposed as a Ariba ITK Style service and SAP CPI sends file upload and download request in MIME multipart format.

In this blog post I will share how to download and upload files to SAP Ariba ITK Services from SAP CPI in 2 sections. More details are provided in the solution section below.

Solution:

The approach to integrate SAP ARIBA will be divided into 2 sections:

  1. File download
  2. File Upload

Section1: File download: Integration Process Details:

Download csv data file from Ariba Style ITK service to SFTP location.

Figure 1: File Download iFlow

Get Ariba MIME Parameters: Set the Ariba MIME parameters in content modifier

Figure 2:Get Ariba MIME Parameters for file download

MIME Ariba Request:

Groovy script for MIME request to download files from SAP Ariba ITK style service.

Below parameters need to be passed in MIME request:
sharedsecret: Ariba credentials

event: Event required to pull data from Ariba.

clienttype, clientinfo, clientversion: Source system details (SAP CPI system details in this case)

from and to: Date range to pull data. In above case I have selected date range from 20th Dec 2022 to current date time.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.util.Iterator;
import javax.activation.DataHandler;
import javax.mail.internet.ContentType;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
import com.sap.it.api.ITApi
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.*
import com.sap.gateway.ip.core.customdev.util.Message

def Message processData(Message message) {
   
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
    
    def SharedSecret = message.getProperties().get("SharedSecret")
	def Event = message.getProperties().get("Event")
    def ClientType = message.getProperties().get("ClientType")
    def ClientInfo = message.getProperties().get("ClientInfo")
    def ClientVersion = message.getProperties().get("ClientVersion")
    def From = message.getProperties().get("FromDate")
    
    //Get current system date and time
    def date = new Date()
    def dtFormat = "E MMM dd HH:mm:ss z YYYY"
    def CurrentDate = date.format(dtFormat, TimeZone.getTimeZone('CET'))
    def To = CurrentDate
    message.setHeader("CurrentDate", CurrentDate);
    
    try{
    
        byte[] bytes = message.getBody(byte[])
		 //  Construct Multipart
        MimeBodyPart bodyPartHead1 = new MimeBodyPart()
        bodyPartHead1.setText(SharedSecret)
        bodyPartHead1.setDisposition('form-data; name="sharedsecret"')
        
        MimeBodyPart bodyPartHead2 = new MimeBodyPart()
        bodyPartHead2.setText(Event)
        bodyPartHead2.setDisposition('form-data; name="event"')
        
        MimeBodyPart bodyPartHead3 = new MimeBodyPart()
        bodyPartHead3.setText('ClientType')
        bodyPartHead3.setDisposition('form-data; name="clienttype"')
        
        MimeBodyPart bodyPartHead4 = new MimeBodyPart()
        bodyPartHead4.setText(ClientInfo)
        bodyPartHead4.setDisposition('form-data; name="clientinfo"')
        
        MimeBodyPart bodyPartHead5 = new MimeBodyPart()
        bodyPartHead5.setText(ClientVersion)
        bodyPartHead5.setDisposition('form-data; name="clientversion"')
        
        MimeBodyPart bodyPartHead6 = new MimeBodyPart()
        bodyPartHead6.setText(From)
        bodyPartHead6.setDisposition('form-data; name="from"')
        
        MimeBodyPart bodyPartHead7 = new MimeBodyPart()
        bodyPartHead7.setText(To)
        bodyPartHead7.setDisposition('form-data; name="to"')
               

        MimeMultipart multipart = new MimeMultipart()
        multipart.addBodyPart(bodyPartHead1)
        multipart.addBodyPart(bodyPartHead2)
        multipart.addBodyPart(bodyPartHead3)
        multipart.addBodyPart(bodyPartHead4)
        multipart.addBodyPart(bodyPartHead5)
        multipart.addBodyPart(bodyPartHead6)
        multipart.addBodyPart(bodyPartHead7)
        

        multipart.updateHeaders()
        
        multipart.writeTo(outputStream)
        message.setBody(outputStream)
    
        // Set Content type with boundary
        String boundary = (new ContentType(multipart.contentType)).getParameter('boundary');
        message.setHeader('Content-Type', "multipart/form-data; boundary=\"${boundary}\"")
        
        // Calculate message size
        message.setHeader('content-length', message.getBodySize())
    
    }catch(Exception e){
        
    }finally{
        outputStream.close()
    }


    return message
}

Ariba_HTTPS_RequestReply: Ariba connection configurations

Figure 3: Ariba HTTPs Request

Section 2: File upload: Integration Process Details:

Upload csv data file from CPI to Ariba Style ITK service.

Figure 4: File Upload iFlow

Input CSV Payload:

Figure 5: Input CSV Data

Get Ariba MIME Parameters: Set the Ariba MIME parameters in content modifier

Figure 6: Get Ariba MIME Parameters for file upload

Zipped CSV File: Groovy script to create a zipped csv file:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.io.IOException;
import java.util.Arrays;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.apache.camel.impl.DefaultAttachment;
import javax.mail.util.ByteArrayDataSource;

def Message processData(Message message) {
	//Read the filename and attachment name
	def FileName = message.getProperties().get("FileName");
	def Attachment = message.getProperties().get("Attachment");
	
   //Body
    def body = message.getBody(java.lang.String) as String; // this value is used for the CSV file
    byte[] b = body.getBytes(); // converting body to byteArray
    ByteArrayOutputStream byteArrayOutputStreamcsv = new ByteArrayOutputStream();
    byteArrayOutputStreamcsv.write(b,0,b.length);

    // Zipping Content
    ByteArrayOutputStream zipbyteArrayOutputStream = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(zipbyteArrayOutputStream);
    
    ZipEntry ze2 = new ZipEntry(FileName); // give csv file name as per naming convention
    
    zos.putNextEntry(ze2);
    byte[] bytescsv =  byteArrayOutputStreamcsv.toByteArray() // putting CSV content in byteArray
    zos.write(bytescsv, 0, bytescsv.length);
    zos.closeEntry();
    zos.close();
    
   
    def dataSource = new ByteArrayDataSource(zipbyteArrayOutputStream.toByteArray(),'application/zip') //  Construct a DefaultAttachment object
    def attachment = new DefaultAttachment(dataSource) //    Add the attachment to the message
    message.addAttachmentObject(Attachment, attachment) // give zipfile name as per naming convention
    return message;
}

Check Attachment Exists: Groovy script to check if attachment exists

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.util.Iterator;
import javax.activation.DataHandler;

def Message processData(Message message) {

   Map<String, DataHandler> attachments = message.getAttachments()
   if (attachments.isEmpty()) {
       message.setBody("No attachment Found")
     return message;
   } else {
      Iterator<DataHandler> it = attachments.values().iterator()
      DataHandler attachment = it.next()
      message.setBody(attachment.getContent())
   }
   return message
}

Setup Ariba MIME parameters: Groovy script for MIME request to download files from SAP Ariba ITK style service.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.util.Iterator;
import javax.activation.DataHandler;
import javax.mail.internet.ContentType;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
import com.sap.it.api.ITApi
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.*
import com.sap.gateway.ip.core.customdev.util.Message


def Message processData(Message message) {
    
    //Fetch the parameters
    def SharedSecret = message.getProperties().get("SharedSecret")
    def Event = message.getProperties().get("Event")
    def ClientType = message.getProperties().get("ClientType")
    def ClientInfo = message.getProperties().get("ClientInfo")
    def ClientVersion = message.getProperties().get("ClientVersion")
    def FullLoad = message.getProperties().get("FullLoad")
    def Attachment = message.getProperties().get("Attachment");
        
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
    
    try{

        byte[] bytes = message.getBody(byte[])
        //  Construct Multipart
        MimeBodyPart bodyPartHead1 = new MimeBodyPart()
        bodyPartHead1.setText(SharedSecret)
        bodyPartHead1.setDisposition('form-data; name="sharedsecret"')
        
        MimeBodyPart bodyPartHead2 = new MimeBodyPart()
        bodyPartHead2.setText(Event)
        bodyPartHead2.setDisposition('form-data; name="event"')
        
        MimeBodyPart bodyPartHead3 = new MimeBodyPart()
        bodyPartHead3.setText(ClientType)
        bodyPartHead3.setDisposition('form-data; name="clienttype"')
        
        MimeBodyPart bodyPartHead4 = new MimeBodyPart()
        bodyPartHead4.setText(ClientInfo)
        bodyPartHead4.setDisposition('form-data; name="clientinfo"')
        
        MimeBodyPart bodyPartHead5 = new MimeBodyPart()
        bodyPartHead5.setText(ClientVersion)
        bodyPartHead5.setDisposition('form-data; name="clientversion"')
        
        MimeBodyPart bodyPartHead6 = new MimeBodyPart()
        bodyPartHead6.setText(FullLoad)
        bodyPartHead6.setDisposition('form-data; name="fullload"')
        
        MimeBodyPart bodyPart = new MimeBodyPart()
        ByteArrayDataSource dataSource = new ByteArrayDataSource(bytes, 'application/zip')
        DataHandler byteDataHandler = new DataHandler(dataSource)
        bodyPart.setDataHandler(byteDataHandler)
        bodyPart.setFileName(Attachment)
        bodyPart.setDisposition('form-data; name="content"')
    
        MimeMultipart multipart = new MimeMultipart()
        multipart.addBodyPart(bodyPartHead1)
        multipart.addBodyPart(bodyPartHead2)
        multipart.addBodyPart(bodyPartHead3)
        multipart.addBodyPart(bodyPartHead4)
        multipart.addBodyPart(bodyPartHead5)
        multipart.addBodyPart(bodyPartHead6)

        
        multipart.addBodyPart(bodyPart)
        
        multipart.updateHeaders()
        
        multipart.writeTo(outputStream)
        message.setBody(outputStream.toByteArray()); 
        // Set Content type with boundary
        String boundary = (new ContentType(multipart.contentType)).getParameter('boundary');
        message.setHeader('Content-Type', "multipart/form-data; boundary=\"${boundary}\"")
        

    }catch(Exception e){
        
    }finally{
        outputStream.close()
    }


    return message
}

Ariba_HTTPS_RequestReply: Ariba Connection Configurations

Figure 7: Ariba HTTPs Request

Testing:

Test Case1: File download

MIME request sent to SAP Ariba

Figure 8: MIME request sent to SAP Ariba

Zip file generated in SFTP directory:

Figure 9: Output Zip file

Test Case2: File upload

MIME request sent to SAP Ariba

Figure 10: MIME request sent to SAP Ariba

Ariba Response:

Figure 11: Ariba Response
Rating: 0 / 5 (0 votes)

The post Integrate Ariba ITK Services with CPI first appeared on ERP Q&A.

]]>
SAP Ariba Real-Time Budget Check in Mediated Connectivity using CIG and CPI https://www.erpqna.com/sap-ariba-real-time-budget-check-in-mediated-connectivity-using-cig-and-cpi/?utm_source=rss&utm_medium=rss&utm_campaign=sap-ariba-real-time-budget-check-in-mediated-connectivity-using-cig-and-cpi Tue, 28 Sep 2021 09:10:14 +0000 https://www.erpqna.com/?p=54836 1. Requirement Overview (Introduction) Client is using Ariba Buying & Invoicing solution integrated with S4HANA ERP. Purchase Requisitions are being created in Ariba and once the Purchase Requisition (PR) is approved in Ariba, it sends the information to S4HANA to create the Purchase Order (PO). If PO successfully created in S4HANA, Ariba receives the PO […]

The post SAP Ariba Real-Time Budget Check in Mediated Connectivity using CIG and CPI first appeared on ERP Q&A.

]]>
1. Requirement Overview (Introduction)

Client is using Ariba Buying & Invoicing solution integrated with S4HANA ERP. Purchase Requisitions are being created in Ariba and once the Purchase Requisition (PR) is approved in Ariba, it sends the information to S4HANA to create the Purchase Order (PO).

If PO successfully created in S4HANA, Ariba receives the PO number back from S4HANA & PR/PO status changed to Ordered. If PO failed to get created in S4HANA, Ariba receives the error message details.

Currently, there is no real-time validation of the data captured on the Requisition before submission & sent for the approval. Ariba receives error messages only once the PR is fully approved and sent to S4HANA for PO creation. Client is looking for a solution where the PRs can be validated in S4HANA before the submission.

Ariba’s Real-Time Budget Check interface functionality (RTBC hereafter) is being proposed to not only validate the budget in ERP but also to check the requisitions validations in S4HANA. This will further reduces the errors which are being sent from S4HANA during the PO creation stage.

1.1 Applicable Module(s)

The solution covered in this blog will be applicable to the following Modules(s):

Ariba Buying & Invoicing X
Ariba Sourcing Suite    
CIG Integration  
Ariba Commerce Automation    


ERP- Backend System : SAP S4HANA On-premise

Middleware : SAP Cloud platform integration

2. Solution/Configuration Details

Solution offers to validate the Requisitions during submission is SAP Ariba’s standard feature Real-time budget check.

When user initiates a budget check voluntarily on a Requisition or during requisition submission by the system, Ariba triggers the synchronous call and sends the message to Cloud Integration Gateway. CIG will send this message post processing to CPI, where CPI will just be a pass through to send the Budget check request message to SAP ERP (S4HANA ERP). SAP ERP validates the request message and respond back with success or failure. S4HANA will creates a corresponding Purchase Requisition and return with SAP ERP Purchase Requisition reference number.

SAP Ariba RTBC Synchronous Service Flow

2.1 Solution Overview

Real-time budget check interface will trigger at below scenarios to validate the Ariba Purchase Requisition with budget maintain in SAP S4HANA and other Requisition validations.

Real-time budget check scenarios

2.2 Steps for Configuration

Real-time budget check functionality requires configuration in SAP Ariba, CIG, S4HANA and CPI.

Please follow the below sections for the details

2.2.1. Configuration in SAP Ariba

1. Below are the parameters to be enabled by raising the Service Request with customer support of SAP Ariba

# Parameter
1 Application.Budget.StartDateToEnableRealTimeBudgetChecksInExternalSystems 
2 Application.Budget.SendEarlierVersionRequisitionToExternalSystemForBudgetReversal 
3 Application.Budget.EnableBudgetRevertOnDeletingRequisitionWithErrors 
4 Application.Budget.RealTimeBudgetSynchronousSubmit


2. Web-Services to be enabled in SAP Ariba @ Ariba > Core Administration > Integration Manager > Cloud Integration Gateway

  • Export Requisitions for User-Initiated External Budget Chec
  • Export Submitted Requisitions for External Budget Check
  • Export Requisitions to External System to Revert Funds
  • Export Modified Requisitions To Revert Funds
  • Export Submitted Requisitions for Budget Checks Using SAP Ariba Cloud Integration Gateway
Real-time budget check web services in Ariba

2.2.2 Configuration in CIG

Web-services used to integrate Requisitions as part of real-time budget check functionality are synchronous calls and there is separate iFlow in CPI to be configured. Due to this reason, a separate Project has to be created with individual connections for each of the synchronous services to be used for Real-time budget check integration.

Below are the two connection details to be maintained:

DocumentType: RequisitionBudgetCheckExportRequest/RequisitionExportRequest

# Attribute Name Attribute Value Details
Transport Type   HTTPS  Select HTTPS from drop down
Environment   TEST  Select Test or Prod
Name  XXXX-BUDGET1   Provide appropriate name
System ID   XXXCLNT5XX   S4HANA backend System ID (SLD)
DocumentType   RequisitionBudgetCheckExportRequest/RequisitionExportRequest   Make sure to select this document type. Do not create the connection for synchronous webservice with Any documents type
URL  https://exxxxx-iflmap.hcisbt.eu2.hana.ondemand.com/cxf/receiveCIGSyncDocument  CPI team to share the appropriate URL for connections during implementation.
Authentication Type   Basic  Basic Authentication type
Username(CPI-UserName)   To be Shared by CPI support Team   To be Shared by CPI support Team
Password  To be Shared by CPI support Team   To be Shared by CPI support Team

Document Type : RequisitionRevertExportRequest

# Attribute Name Attribute Value
Transport Type   HTTPS 
Environment   TEST 
Name  CLIENT-REVERTBUDGET-XX
System ID   XXCLNT5XX
DocumentType   RequisitionRevertExportRequest
URL  https://exxxxx-iflmap.hcisbt.eu2.hana.ondemand.com/cxf/receiveCIGSyncDocument
Authentication Type   Basic 
Username(CPI-UserName) To be Shared by CPI support
Password  To be Shared by CPI support

Note: Please repeat the same parameters for production connections.

CIG Project Details

Connections maintained above is being used in a project created specifically for synchronous services.

Note: RTBC services are synchronous webservice unlike other Ariba Buying & Invoicing asynchronous webservices. For mediated connectivity with CPI, separate project for RTBC synchronous webservices is required.

Please refer cloud integration gateway guide to know more about CIG project creations.

Project Name: Client_P2P_RTB

Cross-Reference – Parameters Maintained as below. We are using a separate doc type of SAP S4HANA for creation of requisitions from Ariba, which needs to be maintained as below in CIG.

CIG Project Cross Reference Values

Note: Please add the connections created for production RTBC webservices in this project only following the same above process.

CIG Custom Mapping

If required, custom mappings to be done at below mentioned cXML Document Type. As being the synchronous calls, payloads of this transaction are not visible in CIG and cannot be downloaded through transaction tracker in CIG.

CIG custom mapping objects for RTBC

2.2.3 Configuration in Middleware (CPI)

Deploy the standard I-flow as below in CPI instance

Package Name-

SAP ERP and SAP S/4HANA Integration with SAP Ariba Solutions

https://lxxxxxx-txx.hci.eu2.hana.ondemand.com/itspaces/shell/design

I-flow Name-

SOAP Synchronous Pass Through Content for Ariba Procurement

Validate the value mapping table bi-directional values.

2.2.4. Configuration in ERP

2.2.4.1. MM Configurations

Details of new doc type for Ariba PR – We have created new document type ZEX for Ariba Purchase Requisition.

Note: As being synchronous webservice, message payloads are currently not visible in CIG. For troubleshooting in your test environment, payload trace can be enabled in SAP S4HANA using srt_util t-code.

SRT_UTIL Payload Traces for Synchronous Webservices

For any integration issues, please debug ARBCIG_PREQ & ARBCIG_PREQ_Delete FM.

2.2.4.2. SOAMANAGER Configurations

Please ensure the appropriate Web Service configuration in SOAMANAGER, as shown below.

BuyerPurchaseRequisition_Sync_

BuyerPurchaseRequisitionDelete_Sync_In

SOAMANAGER Configuration changes for RTBC web service

3. Benefits

  • Real-time check of the budgets available in the back-end ERP
  • Reservation of budget in ERP for the Requisitions created in SAP Ariba
  • Validation check of the Ariba requisition data, resulting lesser failures at Purchase Order creation interface.
  • Lower End to End cycle time by automating validations and budget check with backend ERP.
  • Better user-experience by using budget check button.
Sample screens with ERP PR Number
Rating: 0 / 5 (0 votes)

The post SAP Ariba Real-Time Budget Check in Mediated Connectivity using CIG and CPI first appeared on ERP Q&A.

]]>