cancel
Showing results for 
Search instead for 
Did you mean: 

Using Run OS Command Before Message Processing

Former Member
0 Kudos

I'm currently creating an two interfaces where files from Shipment Interface will wait until all Shipping Confirmation files are picked up and processed.

To do this, I'm maximizing Run OS Command Before Message Processing so that the Shipment Interface will check the Shipping Confirmation folder and temporarily sleep if it sees files there. My script is:

------------------------------

#!/bin/ksh

#

# Check first if there are existing SHPCON files. If there's none, process SHPMNT files.

#

file=$1

extension=$2

while [[ -f ${file}*${extension} ]];do

sleep 10

done

------------------------------

Sample input: ksh /util/bin/pi/file_check.ksh /sapin/DEV/ExternalParty/SHPCON/snd/ESRTP2SHPCON .xml

============================

Even if I remove the "extension" variable both in the script and as an argument, the logic still fails. However, when I use an absolute file name, the logic works.

So there might be another way of checking the file. I need the wildcard since the file name has a timestamp and, obviously, the file name is not the same always.

HELP!!!!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Since this query is script related, here is the working script. But, I am still considering the other suggestions posted here in this forum.

#!/bin/ksh

#

# Check first if there are existing SHPCON files. If there's none, process SHPMNT files.

#

filepath=$1

filename=$2

while [ -n "`ls -1 $filepath | grep $filename`" ]; do

sleep 10

done

Sample input: ksh /util/bin/pi/file_check.ksh /sapin/DEV/ExternalParty/SHPCON/snd ESRTP2SHPCON

Answers (1)

Answers (1)

JaySchwendemann
Active Contributor
0 Kudos

Two questions came to my mind:

1. How do you now an empty folder "/sapin/DEV/ExternalParty/SHPCON/snd/" means all confirmation files have been picked up? Couldn't it be the case that pickup has run and another confirmation was delivered after that?

2. If you know for sure that you may process the contents of the SHMPNT directory after SHPCON is empty you could change the process of SHPCON pickup to run a OS command AFTER the processing. Check in the script if SHPCON directory is empty. If so, rename file in SHPMNT directory or move file to a subdirectory. Change target file schema / directory of SHPMNT pickup process accordingly to match the then renamed or moved SHPMNT file.

Former Member
0 Kudos

1. Both SHPCON and SHPMNT files are placed in their respective folders every five minutes. Should there be any new transactions, it won't come after that five minutes. That's why in the script, I only let it sleep for 10 seconds. I just need to delay the processing of SHPMNT files up until the SHPCON folder is cleared.

2. The files come from an external party and has already agreed to a naming convention. We're already in the middle of testing and that's why we're minimizing the changes to the solution. Hence this "delay" in SHPMNT processing.

JaySchwendemann
Active Contributor
0 Kudos

If you are on Dual Stack you may try ccBPM, of course.

Maybe someone with sound knowledge of scripting may help you out why your logic fails. In my opinion the approach with sleeping if files are there will be horrid performance-wise and I wouldn't opt for that.

Cheers

Jens

iaki_vila
Active Contributor
0 Kudos

Hi Jan,

Have you tried with the option -e ?. It seems to be less restrictive Bash Shell: Check File Exists or Not

Regards.

iaki_vila
Active Contributor
0 Kudos

Hi Jan,

I agree with

Former Member
0 Kudos

Can you explain further regarding this?

You could do a file lookup in the confirmation scenario to take the second file, even to use the logical positive and to ask in the second scenario if the first file is deposited in archive to continue.


Thanks!

Former Member
0 Kudos

Actually, the challenge is that the logic is actually working when I'm using my personal computer. It now fails when the script is running via PI runtime.

It fails when it's using the wildcard but logic is successful when checking via an absolute/complete filename and it exists.

iaki_vila
Active Contributor
0 Kudos

Hi Jan,

I assume the next in your scenario:

1. It is File - (Proxy or RFC or IDOC, any kind of ERP destination)

2. If the shipment confirmation file is deposited the shipment file must be deposited as well.

You can do a sender file that polls for the shipment confirmation. The sender file adapter takes the file, at mapping level you pick up the shipment file with an UDF: File Lookup in UDF - Process Integration - SCN Wiki. You can do any conversion with the file taken and to generate in the UDF or a Java Mapping the outstream desired to do a second mapping to get the XML needed to be sent to the ERP destination.

If my second supposition is wrong, the scenario can be more complicated. However in your ERP you can do a job/or simple report that starts a channel to take second file: . Why a job or simple report?, if the second file is not present you can try n times to start the sender file channel to pick up the file or a job that n minutes check what confirmations are arrived and try to take the second file.

Hope this helps.

Regards.

iaki_vila
Active Contributor
0 Kudos

Hi Jan,

Have you used in PI the variables %f or %F for the file or the absolute path instead of $1 and $2?.

Defining Operating System Commands Before/After Processing - Advanced Adapter Engine - SAP Library

Regards.

Former Member
0 Kudos

The %f and %F will get the SHPMNT files but, unfortunately, I need the SHPMNT file channel to check the SHPCON file whether it exists or not.