Solved

Conversion of Axapta C Code loop to T-SQL SPROC

Posted on 2006-06-20
4
312 Views
Last Modified: 2010-04-01
We want to convert this script from C to a SQL Query or SPROC but I am no expert in the Axapta Programming area and I was hoping someone could guide us in the meaning of the script I have enclosed.  We have determined the basic intent of this procedure but we really are not sure how everything fits together particularly how the variables are declared and the first part of the if/then statement leading into the loop.  Please contact me if you need further information.  any help is greatly appreciated.  thanks!

static server real CalcSqFtYieldGross(InventLocationId _InventLoactionId,
WrkCtrId _WrkCtrId, TransDate _BeginDate, TransDate _EndDate)
{
    real            sqftgross;
    RM_LayersCut    rmlayerscut;
    DC_Scan         dcscan;
    ProdId          lastProdId;
    real            lastSqFt;
    ;

    IF (_InventLoactionId == "" && _WrkCtrId == "")
    {
         while select  dcscan order by prodorder
            where dcscan.ScanDate >= _BeginDate && dcscan.ScanDate < _EndDate
            {
                if (lastProdId != dcscan.ProdOrder)
                {
                    select firstonly SqFt from rmlayerscut where
dcscan.ProdOrder == rmlayerscut.OrderId;
                    sqftgross += rmlayerscut.SqFt;

                    lastProdId = dcscan.ProdOrder;
                    lastSqFt = rmlayerscut.SqFt;
                }
                else
                {
                    sqftgross += lastSqFt;
                }
            }
    }
    ELSE IF (_InventLoactionId != "" && _WrkCtrId == "")
    {
         while select  dcscan order by prodorder
            where dcscan.ScanDate >= _BeginDate && dcscan.ScanDate < _EndDate
            && dcscan.Warehouse == _InventLoactionId
            {
                if (lastProdId != dcscan.ProdOrder)
                {
                    select firstonly SqFt from rmlayerscut where
dcscan.ProdOrder == rmlayerscut.OrderId;
                    sqftgross += rmlayerscut.SqFt;

                    lastProdId = dcscan.ProdOrder;
                    lastSqFt = rmlayerscut.SqFt;
                }
                else
                {
                    sqftgross += lastSqFt;
                }
            }
    }
    ELSE IF (_InventLoactionId != "" && _WrkCtrId != "")
    {
        while select  dcscan order by prodorder
            where dcscan.ScanDate >= _BeginDate && dcscan.ScanDate < _EndDate
            && dcscan.Warehouse == _InventLoactionId
            && dcscan.WorkCenter == _WrkCtrId
            {
               if (lastProdId != dcscan.ProdOrder)
                {
                    select firstonly SqFt from rmlayerscut where
dcscan.ProdOrder == rmlayerscut.OrderId;
                    sqftgross += rmlayerscut.SqFt;

                    lastProdId = dcscan.ProdOrder;
                    lastSqFt = rmlayerscut.SqFt;
                }
                else
                {
                    sqftgross += lastSqFt;
                }
            }
    }
    ELSE IF (_InventLoactionId == "" && _WrkCtrId != "")
    {
        while select  dcscan order by prodorder
            where dcscan.ScanDate >= _BeginDate && dcscan.ScanDate < _EndDate
            && dcscan.WorkCenter == _WrkCtrId
            {
                if (lastProdId != dcscan.ProdOrder)
                {
                    select firstonly SqFt from rmlayerscut where
dcscan.ProdOrder == rmlayerscut.OrderId;
                    sqftgross += rmlayerscut.SqFt;

                    lastProdId = dcscan.ProdOrder;
                    lastSqFt = rmlayerscut.SqFt;
                }
                else
                {
                    sqftgross += lastSqFt;
                }
            }
    }

    return sqftgross;
}

0
Comment
Question by:carlg1000
4 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 16950895
I am no expert in the Axapta Programming too but I can explain what the function does:

It sums up sqare foot values from a table named 'rmlayerscut'. The keys to the table 'rmlayerscut' it gets from an outer select to table 'dcscan'.

There are three kinds of queries:

A: select all entries of dcscan within a given time interval
B: query A filtered by  dcscan.Warehouse == _InventLoactionId
C: query A filtered by  dcscan.WorkCenter == _WrkCtrId

All queries were sorted by 'ProdOrder'. That is because the square foot value 'SqFt' only needs to be queried once for any different 'ProdOrder' key of table 'dcscan'. For all entries of the result set of queries A, B, C the square foot values associated to 'Prodorder' were summed up into variable sqftgross which was returned from the function.

Regards, Alex
 
0
 

Author Comment

by:carlg1000
ID: 16950927
thanks a million.  this is what I was looking for and confirmed our assumptions.  
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now