Solved

Conversion of Axapta C Code loop to T-SQL SPROC

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 95
AVI wait icons for CAnimateCtrl in Visual Studio 2008 MFC 1 160
c++ syntax question 9 57
Unable to start eclipse ? 17 163
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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

740 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