Thursday, November 3, 2011

GENTRAN:Server Don't Like FtpRcvMsgAll...


One of the sad things that has come out of Sterling Commerce's long running desire to sunset the Gentran:Server for Windows line has been an ever shortening list of resources that can truly make gentran sing, so when I see a peace of code like this where someone has answered one of my long running questions I take notice. Historically speaking Gentran:Server for Windows was originally a communications server with a translator built into it and nobody did it better than Sterling Commerce; however, over time they lost interest in expanding the products supported communication standards and since then most people don't even associate Gentran with the subject any more.

OK so here is the long running question: How can I connect to an FTP server and pull down only the files I need, the catch being you don't know the name of the files in advanced and second you don't want to pull all the files.

// FTP with read individual files.

scriptvar string[20] Directory;
string [100] DIR_COMMAND;
integer iCnt;
integer iIndex;
string [100] OneLine;
string [100] GetFile;
DIR_COMMAND = "EDI/SAPOUT/" + Directory;
FtpSetMode(ASCII);
FtpChangeDir(DIR_COMMAND);

if DoRcv then
iCnt = FtpGetDir(FALSE); // TRUE = LIST FALSE = NLST
iIndex = 0;
while iIndex < iCnt do
begin
FtpGetDirString(iIndex, OneLine);
GetFile = OneLine;
if left(GetFile,3) = "EDI" then
FtpRcvMsg(GetFile);
FtpDelete(GetFile);
end
iIndex = iIndex + 1;
end
end
SetStatus(SUCCESS);

Wednesday, October 12, 2011

Need to make a ton of copies of a Trading Partner Really Fast?


Last week I was asked to do something I personally have never done before, create 721 copies of a trading partner with a different EDI and App code and a unique partner id for each for a project needing divisional lookups. Now having suffered through the 30+ partners needed to make Ford happy I had no intentions of copying and pasting 721 DUNs numbers: so I quit the job and am now happily flipping burgers at BK. Just kidding; however, it made me wonder who is actually luckier, oh and by the way "the first 855s will be going out tomorrow morning".

Ok so here is what I did utilizing a little ingenuity and a quick VBScript.

1) Created a template trading partner with Gentran's Trading Partner manager and export the partner to the partners directory. Being sure to use Tag words.



2)Create a text file list of all my divisional lookup values.

012345671
012345672
012345673
012345674

3) Ok Next I created my vbscript. Your lucky I'm sharing the one I created right here.


' Example: cscript GenerateGentranPartners.vbs "C:\GENSRVNT\Partners\GHX - REPVAL.par" C:\PartnerList.txt C:\GENSRVNT\Partners\ ProfileID

' ******************************************************************************
' ******************************************************************************
' ** Create Gentran Partners Script **
' ** Version 0.0.1 **
' ** **
' ** Stephen Case **
' ** http://www.ediassociates.com **
' ** **
' ** Usage: **
' ** cscript.exe GenerateGentranPartners.vbs **
' ** **
' ** - An original working partner export from Gentran **
' ** - A list of values the new Gentran partners will be based on. **
' ** - Output Destination **
' ** - Gentran Partner Profile ID **
' ** **
' ******************************************************************************
' ******************************************************************************

option Explicit

Private strLoadDir, strLoadFile, QueueFolder, strLoadList, strProfileID
Private objFSOi, objFSOo
Private strSubDelim, strTerm, startPnt, i
Dim objSource, saveName
Dim intIndex

Call Main()

Sub Main


If (LoadParams) Then

set objFSOi = CreateObject("Scripting.FileSystemObject")
set objFSOo = CreateObject("Scripting.FileSystemObject")
Call GatherFiles
Else
DisplayUsage
End If
End Sub

Private Sub DisplayUsage

WScript.Echo "Usage: cscript.exe GenerateGentranPartners.vbs "

End Sub

'----------------------------------------------------------------------------------------------------------------------------------------------
Private Function LoadParams

dim blnResult
' Pick up our three command line values.
If (WScript.Arguments.Count = 4) then
strLoadFile = WScript.Arguments(0)
strLoadList = WScript.Arguments(1)
QueueFolder = WScript.Arguments(2)
strProfileID = WScript.Arguments(3)
blnResult = true
Else
blnResult = false
End If

LoadParams = blnResult

End Function

'----------------------------------------------------------------------------------------------------------------------------------------------
Private Sub GatherFiles

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strLoadFile) Then
Call SplitFile()
End If

End Sub

'----------------------------------------------------------------------------------------------------------------------------------------------
Private Sub SplitFile()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim objFileInT, objFileInL
Dim objFileOut
Dim strLine, tplLine
Dim WrkString, tpString, tpName
Dim oFileName
Dim LineCnt
Dim fso, MyFile

Set fso = CreateObject("Scripting.FileSystemObject")

LineCnt = 0

Set objFileInT = objFSOi.OpenTextFile(strLoadFile)
While (not objFileInT.AtEndOfStream)
tplLine = objFileInT.ReadLine
Wend
' WScript.Echo tplLine
Set objFileInL = objFSOi.OpenTextFile(strLoadList)
While (not objFileInL.AtEndOfStream)
strLine = objFileInL.ReadLine
LineCnt = LineCnt + 1
WrkString = tplLine

WScript.Echo QueueFolder & strProfileID & LineCnt & ".par"
oFileName = QueueFolder & strProfileID & LineCnt & ".par"
tpString = " " & strProfileID & LineCnt & " "
tpName = strProfileID & LineCnt & " - " & strLine
WrkString = Replace(WrkString, "REPNAME", tpName)
WrkString = Replace(WrkString, "REPVAL", strLine)
WrkString = Replace(WrkString, " "&strProfileID&" ", tpString)
Set MyFile = fso.OpenTextFile(oFileName, ForWriting, True)
MyFile.WriteLine WrkString
MyFile.Close

Wend
objFileInL.Close
End Sub

'----------------------------------------------------------------------------------------------------------------------------------------------
'File Exists function made by:
'Paw Jershauge
'http://Support.scf.dk
Public Function FileExists(Filename,Output)
on error resume next
dim fso 'create variables
set fso=Server.CreateObject("Scripting.FileSystemObject") ' creating the File System Object one server, provided by Microsoft)
Output = cbool(fso.FileExists(Filename))
set fso=nothing 'Kill the FSO object from the server after use.
if err.number <> 0 then 'if an error occurred then
ErrNum = err.number 'Save Error number for Get Error Function
ErrDes = err.description 'Save Error description for Get Error Function
err.clear 'Clear the err object, so new errors can be processed
FileExists = false ' return false because of the error that occurred
else
FileExists = true ' return true No errors :o)
end if
End function


4) Here is the command line for useing the script.
cscript C:\pathto\GenerateGentranPartners.vbs

Example: cscript C:\pathto\GenerateGentranPartners.vbs"C:\GENSRVNT\Partners\GHX - REPVAL.par" C:\PartnerList.txt C:\GENSRVNT\Partners\ GHX

5) Once the partner files have been created you can schedule a GDW_Partner_Import through Gentrans Process Controller to import all the partners in one sweep. Just a note to import my 721 partner took close to 45 minutes.

Happy Gentraning...

Saturday, October 1, 2011

Gentran - Need to Send that 997 Now

Recently I was visiting a client whom had a need to send functional acknowledgments instantly upon a transactions receipt. This works fine for any transaction being imported through the Process Controller as you can always put a GDW_Send at the end of the import workflow; but there is no mechanism for automatically sending those pesky 997s or any other system documents that were generated from data passing through the mailboxes and are not part of a Process Control work flow? Now you could setup a send session to run every one or two minutes; however, at times of great traffic those session can start to backup in the queue and really bog down the server. So is an alternative that will only send 997s as they are generated. As a note it has worked well in testing; however, I have not tried it yet on a large volume server, so I do not know what if any issues could come out of it. That said here is how it works.

1. Create a send session of the mailbox that will be sending the data.
2. Create a new Event and set it up as a Notification Type of Event.
3. Setup a new Audit Message under Gentran:Server Configuration, Audit/Notification Tab, under the Audit Messages button.
4. Setup a new Notification under Gentran:Server Configuration, Audit/Notification Tab, under the Notifications button.
5. Here is where everything gets tied together. Position an auditlog command under the Session Rules, Post-session so as the map closes it will initiate the Send Tutorial created in step 1.
6. Compile and Register the map and enjoy…

Sunday, September 25, 2011

Three Secrets to a Worry Free Gentran Server For Windows.

How can I keep my Gentran Server running smoothly? I’m not sure what it is, but I have been getting this question a lot recently and I can only speculate that it has something to do with aging Gentran Servers and the high turnover of employees do to the economy. What ever the reason behind the surge in maintenance related questions, I figure it’s about time I blogged about what 15 years of Sterling Commerce Gentran Server for Windows projects have taught me about the product. So enjoy and please feel free to leave questions, comments and requests for future subjects.

1) Keep process data clean – Process data are the active logs and data files currently in Gentran. Questions regarding process data are by far the number one question I get; like: Our system keeps running out of space? It takes so long to find anything? Why is Gentran so slow? All these questions generally stem from a misguided belief that every transaction ever processed or something close to it has to be kept in active history all the time. This simply is not true, even the IRS only requires 7 years and backups and archives of those transactions are perfectly legitimate. I generally recommend that a company only keep between 30 to 90 days max in there active process data. There are three key aspects to keeping process data clean and getting at the history when it’s needed.
  • Archives – (weekly) Run the Archive utility from the process controller on a regular schedule and keep track of the archive names and the date period of the data contained within each archive. This way you can quickly retrieve transactions as needed utilizing the archive viewer. Transactions can also be moved back to the active process data if needed. By doing this you free up the number of transactions Gentran has to keep track of and quite possibly your biggest gain in performance.
  • Database Maintenance – (Monthly) After Gentran has finished archiving especially if it was a large archive; find a time when you can shut down the Gentran services and ask your DBA to go ahead and compact the database.
  • Data Store Maintenance – (Monthly) One word “GICheck”. GICheck is a utility that comes with Gentran that verifies the integrity of the Data Store against the records contained in the database. This utility basically looks for and removes any orphaned files and database records. Note: if you’re getting file system related errors occasionally while trying to view transactions, GICheck will be your best friend.
2) Separation – Ok I can go on forever on this subject as I’ve seen thousands of installations and it’s always the same: We open up the directory Gentran was installed to and there is like literally hundreds of sub-directories right off the root and about half of them are no longer being used or even worse, users are actively doing their daily processing right out the bin directory. Here is what I recommend:
  • Create two directories “Not inside the Gentran application directory”, The first directory will be for the Gentran data store. The second directory will be for any user access data and utilities (example: scripts and the directories needed to support then, also any import and export directories).
  • Follow the instructions contained in Gentran’s documentation, share the new data store directory and move your existing data store to the new data store directory.
  • Make the necessary changes needed to move the any user access data and utilities to their new home.
3) Stay Organized – Simply put, keep it clean and organized. Things like naming conventions for scripts, maps and mailboxes along with approaching everything with a reusable object objective, can go a long way towards helping to keep your sanity.