Latest Updates

FTP Script Automatically : UNIX

1 Month a go, we already passed our SAP Implementation (All Modules), there are some requirement for BASIS to support project from setting printer, setting user ID, setting Role.

In this case, we need to develop interface between SAP and FTP server to upload PO Document when user run Z Report automatically.

ABAPer already develop Z Report for creating PO document and in last line will call our UNIX automatically.

So, let begin develop FTP Script, we devide 3 bash shell scripts:
  1. Precheck Condition for FTP , we call sftp.sh
  2. FTP script for transfering file and moving , we call sftp_next.sh
  3. Batchmode for Uploading File, we call batchcmd

sftp.sh
lv_base="/usr/users/interfac/XX/outbound/outboundlog"
lv_batch="/usr/users/interfac/XX/outbound"
lv_c=`ls -ltr $lv_batch | grep -i XX | wc -l`

if [ $lv_c == 0 ]
then
echo "No Files for FTP or Has been transfered" $(/bin/date +%m-%d-%Y) >> $lv_base/no_transfer_$(/bin/date +%m-%d-%Y).txt
else
# In this case, we use Port Secure(31) instead of SFTP
/usr/bin/ftp -n <ipadressFTPserver> 31 < $lv_batch/batchcmd >> $lv_base/sftp_log_$(/bin/date +%m-%d-%Y-%H:%M:%S).txt
sleep 5
/usr/users/interfac/XX/outbound/sftp_next.sh
fi
 
sftp_next.sh
lv_direk="/usr/users/interfac/XX/outbound/outboundlog"
lv_log=$lv_direk/move_file_$(/bin/date +%m-%d-%Y-%H:%M:%S).txt
lv_base="/usr/users/interfac/XX/outbound"

mv /usr/users/interfac/XX/outbound/XX* $lv_direk
echo "Copy or Move File" $lv_file "Success" >> $lv_log
batchcmd : Sequence command, core of FTP script
batchcmd
user
user password
prompt
lcd /usr/users/interfac/XX/outbound/
mput XX*
pwd
bye

So, we already create UNIX script, lets we move to ABAP Code
here, we add some line ABAP code for call UNIX script
 
**  Unix Command
data: UNIXCOMM(50).
DATA: BEGIN OF ITABA occurs 0,
      LINE(200),
      end of ITABA.

*-- Unix Command to call a ftp script in unix
    unixcomm = '/bin/sh /usr/users/interfac/XX/outbound/sftp.sh'.
    call 'SYSTEM' id 'COMMAND' field  UNIXCOMM
       id 'TAB'   field  ITABA-*SYS*.

    MESSAGE i001(aq) WITH 'File Successfully Transferred'.

Done..Good Luck for your ABAP code

0 Response to "FTP Script Automatically : UNIX"

Posting Komentar