Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member181985
Active Contributor

               Recently, I saw there are couple of threads (Data and trigger  (Data and trigger) & Parallel processing for one large message  (Parallel processing for one large message) ) on SDN asking this requirement "how to handle huge volumes from ABAP Proxy to File". Though I answered the threads with my solution, however I want to blog this as I am seeing this FAQ.                     

Also as suggested by other experts, this can be achieved using two proxies (Main Proxy and Triggering Proxy). Main proxy sends the data in chunks in EOIO fashion followed by Trigger proxy. For receiving application on the file system, triggering file indicates that main proxy data has been complete. However I am focusing on my solution here. 

Requirement:-   ABAP Proxy (chunking concept with EOIO) --> PI --> File (single File)   

Lets assume that the receiving application expects the file name should start "Systemsync".For ABAP EOIO check this blog: XI: Reliable Messaging – EOIO in ABAP Proxies   (XI: Reliable Messaging – EOIO in ABAP Proxies)     

My Solution: Single Proxy. The proxy contains extra FileName field which will be populated programmatically and uniquely from ABAP report. Let us assume that filename format as "ZSystemsync_YYYYMMDD_HHMMSS". So, with in ABAP report this YYYYMMDD_HHMMSS gets evaluated once and will be used for all chunks. However for the last chunk the ABAP report should send "Systemsync_YYYYMMDD_HHMMSS" as file name which we will treat in SAP PI as final transaction and handle this accordingly with Dynamic Configuration and scripts.    

  In this blog, I am not concentrating on the ABAP report code. I am more interested in providing info how it can be achieved in SAP PI with *Dynamic configuration* at mapping level and *Script* at the file channel level.     For simplicity, let us assume that we have the below structures for proxy and file.         

ABAP Proxy Structure

     

FLAT FILE Structure

 

Message Mapping with Dynamic Configuration

Dynamic Configuration Code in Mapping

try
{
          DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
          DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
          DynamicConfigurationKey KEY_LASTTRANSACTION = DynamicConfigurationKey.create("http://custom.com","IsItLastTransaction");
          if(a.startsWith("Z")) //Its not last transaction
          {
                    conf.put(KEY_FILENAME, a);
                    conf.put(KEY_LASTTRANSACTION, "NO");
          }
          else //Its last transaction
          {
                    conf.put(KEY_FILENAME, "LASTZ" + a);
                    conf.put(KEY_LASTTRANSACTION, "YES");
          }
}
catch(Exception e)
{
          e.printStackTrace();
}
return "1";

File channel Configuration              

Enable ASMA (Adapter-Specific Message Attributes for FileName) and Set Maximum Concurrency to 1 & use Run Operating System Command Before and After Message Processing in the receiver file channel.      

RECEIVER FILE CHANNEL CONFIG

Scripts    

Run OS Command Before Message Processing

absFileStr=$1                                   #Argument one from PI %F i.e., Absolute File Path 
FileStr=$2                                   #Argument two from PI %f i.e., Only FileName
echo $absFileStr
echo $FileStr
absfileLen=${#absFileStr}                         #Length of variable absFileStr 
fileLen=${#FileStr}                              #Length of variable FileStr
echo $absfileLen
echo $fileLen
fileLenRem=`expr $absfileLen - $fileLen`
getDirFromAbsFilePath=`echo $absFileStr | head -c $fileLenRem`     #From Argument1 using Argument2  
echo 'Present Working Directory (PWD): ' $getDirFromAbsFilePath
cd $getDirFromAbsFilePath                         #Change Current Working directory 
################ OS SCRIPT BEFORE MESSAGE PROCESSING ####################
u=5
getFirstFiveLettersFromFileName=`echo $FileStr | head -c $u`     
echo "FirstFiveLetters: " $getFirstFiveLettersFromFileName  
if [ "$getFirstFiveLettersFromFileName" == "LASTZ" ]     
then          
          echo "Yes FileName starts with LASTZ, so it is the final transaction"          
          vLast="LAST"          
          vLastLength=${#vLast}         
          v=`expr $vLastLength - 1`          
          remainingZfileLen=`expr $fileLen - $v`          
          echo "remainingZfileLen: " $remainingZfileLen          
          getRemainingZFileName=`echo $FileStr | tail -c $remainingZfileLen`          
          echo "getRemainingZFileName: " $getRemainingZFileName          
          mv $getRemainingZFileName $FileStr               
else          
          echo "FileName starts with Z, so it is not the final transaction. Do Nothing...."
fi
################ OS SCRIPT BEFORE MESSAGE PROCESSING ####################

Run OS Command After Message Processing   

absFileStr=$1                                   #Argument one from PI %F i.e., Absolute File Path 
FileStr=$2                                   #Argument two from PI %f i.e., Only FileName
echo $absFileStr
echo $FileStr
absfileLen=${#absFileStr}                         #Length of variable absFileStr 
fileLen=${#FileStr}                              #Length of variable FileStr
echo $absfileLen
echo $fileLen
fileLenRem=`expr $absfileLen - $fileLen`
getDirFromAbsFilePath=`echo $absFileStr | head -c $fileLenRem`     #From Argument1 using Argument2  
echo 'Present Working Directory (PWD): ' $getDirFromAbsFilePath
cd $getDirFromAbsFilePath                         #Change Current Working directory 
################ OS SCRIPT AFTER MESSAGE PROCESSING ####################
u=5
getFirstFiveLettersFromFileName=`echo $FileStr | head -c $u`     
echo "FirstFiveLetters: " $getFirstFiveLettersFromFileName  
if [ "$getFirstFiveLettersFromFileName" == "LASTZ" ]     
then          
          echo "Yes FileName starts with LASTZ, so it is the final transaction"          
          vLast="LASTZ"          
          vLastLength=${#vLast}          
          v=`expr $vLastLength - 1`          
          remainingZfileLen=`expr $fileLen - $v`          
          echo "remainingZfileLen: " $remainingZfileLen          
          getRemainingZFileName=`echo $FileStr | tail -c $remainingZfileLen`          
          echo "getRemainingZFileName: " $getRemainingZFileName          
          mv $FileStr $getRemainingZFileName          
     else          
          echo "FileName starts with Z, so it is not the final transaction. Do Nothing...."
fi
################ OS SCRIPT AFTER MESSAGE PROCESSING ####################


For PAYLOAD1

     

For PAYLOAD2(Last Transaction)

 

3 Comments
Labels in this area