Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unable to get the freight to calculate correctly for multi-pkg 1

Status
Not open for further replies.

PBREP

MIS
Mar 14, 2003
75
US
Hello All:

To summarize, the cus_main.prg creates an export text file containing the daily shipping data for importing into customers AS400 host.

An important feature of this cus_main is to consolodate multi-pak shipments into one record. This is the feature that is not working. However, it does create a single record for a multi-pak, but it doesn't calculates the
total weight and total charges correctly.

The purpose of this cus_main routine is to create a text file of the daily shipments in the format that the customers AS400 host system can import. The record format is described below. The other important function that this routine is designed to perform is the consolidation of multi-pkg shipments. The consolidation is to create one record containing the total weight and total freight charges of each shipment of a multi-pkg group.

The cus_main works with the export script named ANAPA. The actual export file name is ‘shipment.txt’. Note that there is a temporary file that is also created during the execution of the ANAPA export script called ‘shipmen2.txt’. This file is used in setting up the cus-main and is always empty. The process for generating this ‘shipment.txt’ file is simply at the end of the day run the export script ANAPA and the file is created in the root of the c: drive.

The record format for shipment.txt:

Col 1-7 consignee code; Col 8-13 invoice #; Col 14-19 weight / lbs
Col 20-30 freight charges; Col 31-33 ‘lbs’

Below there two test files that demonstrate the problem.

The first test file example #1 demonstrates the error in addition with the freight charges. The file contains 4 records; the last record represents the mult-pkg. This multi-pkg is made of 3 shipments; the shipments generated is listed below:
1) 1 lbs @ 4.02 2) 2 lbs @ 4.48 3) 3 lbs @ 4.78; therefore the total (lbs) equals 6 and the total freight equals 13.28. In this case the (lbs) were correct but the freight at 9.56 is not correct.

#1:
0000AZC00111100000100000004.02Lbs
0000CAR00222200000200000004.58Lbs
0000DEC00333300000300000004.46Lbs
0000CTC4444.000000600000009.56Lbs

#2:
0000ALC00100100000100000003.82Lbs
0000FLC00100200001000000006.28Lbs
0000CTC1003.000002000000012.56Lbs

The second file example #2 contains 3 records; the last record represents a 2-package multi-pkg. Note that in this example both the weight and the freight are wrong. The multi-pkg data: 1) 5 lbs @ 5.30 2) 10 lbs @ 6.28; therefore total (lbs) should be 15 and total freight 11.58.

Note that the first records in each test file are single shipments and established for me that the single shipments are being created correctly, in each case the (lbs) and the freight are accurate and match the data for that shipment.

I have been unable to get the freight to calculate correctly for multi-pkg.


Thank you in advance for your help.

~PM

* Code:

Function NapaFileOut()
* This is a function to create a file from export for Napa *that allows certain fields to be padded with zeros and for *a single consolidated record for mutli pack shipments.
************************************************************
Local lnPrevWa
Local lnFileHandle
Local lmCode
Local lmInvnum
Local lmWeight
Local lmChgs
Local lmMasterInvnum
Local lmMasterCode
Local lmTotalWeight
Local lmTotalChgs
Local i
Local lnRecnum
Local answer
local curinvnum
local lcSafety
local lnCurrRec
local lcOrder
*set step on
lcSafety = set("Safety")
set safety off
answer = 6

If file("c:\shipment.txt")
answer =messageb("Do you want to overwrite the export file?",4)
endif
If answer = 7
return ""
endif

lnFileHandle = Fcreate("C:\"+"Shipment.txt")
IF lnFileHandle = -1
=messageb("File Shipment.txt Cannot be Created")
return ""
ENDIF

lnPrevWa = select()
*use upsman.dbf in 0 shared alias napa
select man
lnCurrRec = recno()
lcOrder = order()
index on invnum to man
set index to man
Go Top

lnrecnum = reccount()
i = 0
lmMasterCode = man->cscode
lmMasterInvnum = left(man->invnum,6)
lmTotalweight=0
lmTotalchgs=0
curinvnum = left (man->invnum,6)
do while i <= lnrecnum
if !eof()
lmcode=man->cscode
lminvnum=left (man->invnum,6)
lmweight=man->wight
lmchgs=man->fright
If i <> 0
If left (man->invnum,6) <> curinvnum
=Fputs(lnFileHandle, padl(trim(lmMasterCode), 7, "0") + padl(trim(lmMasterInvnum), 6, "0") + padl(alltrim(str(lmTotalweight, 6, 0)), 6, "0") + padl(alltrim(str(lmTotalChgs, 11, 2)), 11, "0")+"Lbs")
lmMasterInvnum = lminvnum
lmMasterCode = lmCode
lmTotalWeight = lmWeight
lmTotalchgs = lmChgs
curinvnum = left (man->invnum,6)
else
lmTotalWeight = lmWeight + man->wight
lmTotalchgs = lmchgs + man->fright
endif
else
lmTotalweight = lmWeight
lmTotalchgs = lmChgs
endif
skip
else
=Fputs(lnFileHandle, padl(trim(lmMasterCode), 7, "0") + padl(trim(lmMasterInvnum), 6, "0") + padl(alltrim(str(lmTotalweight, 6, 0)), 6, "0") + padl(alltrim(str(lmTotalChgs, 11, 2)), 11, "0")+"Lbs")
endif
i = i+1
enddo
=fclose(lnFileHandle)
*use
set index to
set order to &lcOrder
goto lnCurrRec
select (lnPrevWa)
set safety &lcSafety
return ""
ENDFUNC
 
ADDITIONAL NOTE:

NOTE: This way comes out to be the same results for instance, if I do a Multipackage of 3 packages the export file shows "three separate" records. What I'm attempting to do is create an export file that has one record, The record format for shipment.txt is as followed:

Col 1-7 consignee code; Col 8-13 invoice #; Col 14-19 weight / lbs
Col 20-30 freight charges; Col 31-33 ‘lbs’

* Which our format is correct but for three separate files, not one.

The important function that this routine is designed to perform is the consolidation of multi-pkg shipments. The consolidation is to create one record containing the total weight and total freight charges of each shipment of a multi-pkg group (i.e. The multi-pkg data: 1) 5 lbs @ 5.30 2) 10 lbs @ 6.28; therefore total (lbs) should be 15 and total freight 11.58).

Thanks,
~PM
 
Send me a copy of the dbf that you are calling "man" and I can take a look. I think you are taking an around the block trip to go next door. I will post some code to create the shipment.txt file

Forward the dbf to steveb@ultraex.com


Steve Bowman
steve.bowman@ultraex.com

 
My suggestion is

Function getas400

IF VERSION(5)=800
SET ENGINEBEHAVIOR 70
ENDIF

cOldWorkArea=SELECT(0)

SELECT Upsman.cscode, Upsman.invnum, SUM(Upsman.wight) as TotalWgt,SUM(Upsman.fright) as Freight;
FROM upsman ;
GROUP BY Upsman.cscode ;
ORDER BY cscode ;
INTO CURSOR ExportFile


SELECT ExportFile
cExportdata=""
CR=CHR(13)+CHR(10)
SCAN
cExportdata=cExportData+padl(trim(ExportFile.cscode), 7, "0") + ;
padl(trim(ExportFile.invnum), 6, "0") + ;
padl(alltrim(str(ExportFile.TotalWgt, 6, 0)), 6, "0") + ;
padl(alltrim(str(ExportFile.Freight, 11, 2)), 11, "0")+"Lbs" + CR
ENDSCAN

USE IN ExportFile

DELETE FILE c:\shipment.txt
=STRTOFILE(cExportData,"c:\Shipment.txt")
rvalue=.f.
IF FILE("c:\shipment.txt")
rvalue=.t.
ENDIF

SELECT (cOldWorkArea)

RETURN (rvalue)


Steve Bowman
steve.bowman@ultraex.com

 
Thanks Steve. Please check your email (ref. question).

~PM
 
THANKS TO STEVE FOR HIS SUBERB ASSISTANCE !!!
~PM

Function getas400()
Parameter cOutFileName
*DATE: 03-11-04
*PURPOSE: This is a function to create a file (i.e. AS400) *from export that allows certain fields to be padded with zeros *and for a single consolidated record for mutli pack *shipments. ************************************************************
Local loExporter
loExporter = CreateObject('myNapaOut')

m.loExporter.Export()

Define Class myNapaOut As Form && Work with a private datasession
DataSession=2

Procedure Export
Lparameters tcOutput
* Default to 'c:\Shipment.txt' if not passed
tcOutput = Iif(Empty(m.tcOutput), 'c:\Shipment.txt', m.tcOutput)
If File(m.tcOutput) And ;
Messageb("File "+Fullpath(m.tcOutput)+" exists."+Chr(13)+;
"Do you want to overwrite the export file?",4) = 7
Return ""
Endif

Set Safety Off
Select cscode, ;
invnum,;
sum(wight) As totWeight, ;
Sum(fright) As totFreight ;
from upsman myUPS ;
group By 1 ;
into Cursor crsShipments ;
nofilter

Set Fields Global
Set Fields To ;
cscodeout = Padl(Trim(cscode), 7, "0"), ;
invnumout = Padl(Trim(Left(invnum,6)),6,"0"), ;
tWgtOut = Padl(Int(totWeight),6,'0'),;
tFrgtOut = Transform(totFreight,'@L 99999999.99'),;
postfix = 'Lbs'

Copy To (m.tcOutput) Type Sdf
Set Fields To
Return ""
EndProc
Enddefine
************************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top