#!/bin/sh
# encode the authentication details for the Authorization Header
USER="DEVELOPER"
PASSWD="DEVELOPER"
PASS=` echo "${USER}:${PASSWD}" | uuencode -m - | grep -v -E '====|begin'`
HOST=seahorse.local.net
PORT=8000

# do the SOAP call via HTTP
#POST -u http://seahorse.local.net:8000/sap/bc/soap/rfc
SOAP='<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><rfc:RFC_READ_REPORT xmlns:rfc="urn:sap-com:document:sap:rfc:functions"><PROGRAM>RSRSCAN1</PROGRAM><QTAB><item><LINE/></item></QTAB></rfc:RFC_READ_REPORT></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
'

MYOUT=` \
( \
sleep 1; \
echo "POST /sap/bc/soap/rfc HTTP/1.1"; \
echo "User-Agent: MHTTP1/0"; \
echo "Host: ${HOST}"; \
echo "Accept: text/xml"; \
echo "Accept: multipart/*"; \
echo "Content-Type: text/xml; charset=iso-8859-1"; \
echo "Connection: close"; \
echo "Authorization: Basic ${PASS}"; \
echo "Content-Length: 558"; \
echo "SOAPAction: \"urn:sap-com:document:sap:rfc:functions#RFC_READ_REPORT\""; \
echo ""; \
echo "${SOAP}"; \
sleep 3; \
 ) | telnet ${HOST} ${PORT} 2>/dev/null`


# get the contents of QTAB
# parse out the row markers
# translate unicode characters
echo $MYOUT | sed -e 's/^\(.*<QTAB>\)\(.*\)\(<\/QTAB.*\)$/\2/' \
                  -e 's/<\/LINE><\/item>/\n/g' \
                  -e 's/<item><LINE>//g' \
                  -e 's/&#34;/"/g' \
                  -e 's/&#60;/</g' \
                  -e 's/&#62;/>/g' \
                  -e "s/&#39;/'/g"

