Solved

Conversion of Axapta C Code loop to T-SQL SPROC

Posted on 2006-06-20
4
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

623 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