Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Conversion of Axapta C Code loop to T-SQL SPROC

Posted on 2006-06-20
4
Medium Priority
?
327 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
2 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

773 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