Solved

Conversion of Axapta C Code loop to T-SQL SPROC

Posted on 2006-06-20
4
313 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 how to clear a vector as well as how to detect empty vectors in C++.

864 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

23 Experts available now in Live!

Get 1:1 Help Now