MRPUpdateAdjustedSalesAndForecas

MRP, Update Adjusted Sales and Forecast Qty

Minor Business Rule

Object Name: B3400400

Parent DLL: CMFG

Location: Client/Server

Language: C

1.Functional Description
This business function reads the MRP Item Quantity Cache and calculates the Adjusted Forecast and 
Sales Order Quantities based on the Time Fence Rule and Time Fence Days.  It then updates the cache with 

the calculated quantities. The time fence rules handled are 'G', 'C', 'F' ,'S', '1', '3' and 'H' with 

forecast consumption logic turned on.
. These are described in the UDC tables and are hard coded.

1.1Purpose

This function is used to net the requirements of an Item based on how the sales and forecasts are 
handled based on the Time fence rules for the MRP Planning Program. Forecast Consumption logic using 

Shipped quantities is also taken into account before adjusting the sales orders with the forecast 

quantities.


1.2Setup Notes and Prerequisites
The following must be done prior to calling the function:

• The application must call business function B3401270 to create the planning caches.
The User Index F34UI001 must be Loaded with the Planning Dates using Business Function B3400360.

• Item Balance Data - Time Fence Rule and the Planning Date must be precalculated and obtained. 
This business function will be exclusively used by the planning programs and hence caution must be 
used while modifying or maintaining it.


1.3Special Logic

None

2.Technical Specifications

The following actions have to be performed by the Business Function.
1. Get Cache Handles and Initialize Arrays to Zero

Create the following Arrays an Initialize them
@FQU[$PND] - Forecast Quantity Unadjusted

@FQ[$PND] - Forecast Quantity Adjusted

@SOU[$PND] - Sales Order Quantity Unadjusted

@SO[$PND] - Sales Order Quantity Adjusted

@BD[$PND] - Bucket Flag Array

@HQ[$PND] - Shipped Quantities Array


Wk Exit flag = ' '

Wk Index $X = 0

Wk First Call = '1'


  // Load @DT, @BD, @FC arrays from the bucketless date cache.

Call B3401270 in mode '1' to get first date record from cache using Input Date Branch.
While Cache Error Code = '0'
@DT[$X] = Date from Cache.

@BD[$X] = Bucket Flag (EV01) from Cache.

@FC[$X] = Forecast Consumption Bucket Flag (EV03) from Cache.

$X++

Call B3401270 in mode '6' to get next date record from cache using Input Date 

Branch.

   End While

// Load @SOU, @FQU(Unadjusted Sales Orders and Unadjusted Forecast Quantities) from cache.


Wk Cache Branch = Input Branch

If Input Consolidation Method = '2'

Wk SalesOrderType = 'SOT'

Else

Wk SalesOrderType = 'SOU'
If Input Consolidation Method = '1'

Wk Cache Branch = Input Date Branch

End If

End IF
Call B3401290 in mode '1' to get first quantity record from cache using Wk Cache Branch.

While Cache Code Error = '0'

If Quantity Type from Cache = 'FQU'

$X=0
Scan @DT array for first @DT[$X] >= Date From Cache.

@FQU[$X] = @FQU[$X] + Quantity from Cache.

Else

If Quantity Type from Cache = SalesOrderType

$X=0
Scan @DT array for first @DT[$X] >= Date From Cache.

@SOU[$X] = @SOU[$X] + Quantity from Cache.
End If

End If

Call B3401290 in mode '6' to get next quantity record from cache using Wk Cache Branch

End While

If Cache Cursor Ptr <> 0 then

Call B3401290 in mode '9' to close out the cursor and free data ptr.

End If


Wk End Date = @DT[$PND] 


If Input $$SFOG = 'H' And $$FCP = '1' And Input $52 = '1' then

Execute internal function Adjust Forecast Quantities using Shipped Quantities.

End If

Execute internal function Calculate Adjusted Quantities


Close all Tables and Deallocate memory for Arrays
Exit the function with Error Code = 0




2. Internal Function Calculate the Adjusted Quantities 

** Note that @SQ is actually @SO

If Input $$SFOG = Blanks, $$SFOG = 'G' and Input $$PLDT = Wk End Date + 1

Wk Quantity = 0

Wk Index ($G) = 1.

For $X = 1 to $PND, Do

If Input $$FCP = '1' And $$SFOG = 'H' then Break

If @FQU[$X] > 0 or @SQU[$X] > 0

Begin Case

Case $$SFOG = 'C'

If @DT[$X] > $$PLDT

@SQ[$X] = @SQU[$X]

@FQ[$X] = @FQU[$X]

Wk Quantity = Wk Quantity + @SQ[$X]

Else

@SQ[$X]= @SQU[$X]

Endif

Break

Case $$SFOG = 'F'

If @DT[$X] > $$PLDT

@SQ[$X]= @SQU[$X]

@FQ[$X] = @FQU[$X] 

Else

@FQ[$X]=  @FQU[$X]

Endif

Break

Case $$SFOG = 'G'

If @DT[$X] > $$PLDT

@FQ[$X]= @FQU[$X]

Else

@SQ[$X]= @SQU[$X]

@FQ[$X] = @FQU[$X]

Wk Quantity = Wk Quantity + @SQ[$X]

Endif

Break

Case $$SFOG = 'S'

If @DT[$X] > $$PLDT

@FQ[$X]= @FQU[$X]

Else

@SQ[$X]= @SQU[$X]

Endif

Break

Case $$SFOG = '1'

If @DT[$X] > $$PLDT

@FQ[$X]= @FQU[$X]

Endif

Break

Case $$SFOG = '3'

If @DT[$X] > $$PLDT

@FQ[$X]=  @FQU[$X] 

@SQ[$X] =  @SQU[$X] 

Endif

Break

Endcase

Endif

If  @BD[$X] = 'B' 

$G = $X.

If  ($$SFOG = 'G' and @DT[$G] <= $$PLDT) or  ($$SFOG = 'C' and 

@DT[$G] > $$PLDT)

Do the following

If @FQ[$G] > 0

If Wk Quantity >= @FQ[$G]

Wk Quantity = Wk Quantity - @FQ[$G]

@FQ[$G] = 0

Else

@FQ[$G] = @FQ[$G]  - Wk Quantity

Wk Quantity = 0

Endif

Endif

$G = $G -1

End While @BD[$G] <> 'B' and $G > 0

Wk Quantity = 0

Endif

Endif

Enddo

If Input $$FCP = '1' And $$SFOG = 'H' then

Copy All @FQU values to @FQ

Copy All @SQU value to @SQ

Call Adjust Sales and Forecast Qtys using Forecast Consumption.
End If

// Output Array Quantities into Cache as Adjusted Sales Order and Forecast Quantities.

For $X = 1 to $PND
 If FQ[$X] > 0 

Call B3401290 in mode '2' using Wk Cache Branch, @DT[$R], and 'FQ' and @FQ[$X]
End If
If @SQ[$X] > 0 

Call B3401290 in mode '1' using Wk Cache Branch, @DT[$R], and 'SO' and @SQ[$X]
End If
If @HQ[$R] > 0

Call B3401290 in mode '1' using Wk Cache Branch, @DT[$R], and 'SHP' and @HQ[$X]
End If

     End For

3.Internal Function Adjust Forecast Quantities using Shipped Quantities

//Load Sales Order Shipped Quantities - S005S

If Input Consolidation Method = '1' then

// Select Shipped Qtys by a group of branches.

Wk Number of Plants = Input Number of Branches.

Allocate Array @Branch with size = Wk Number Of Plants * sizeof (MCU)
$X = 0

Select All Records from F35UI001

While Exit <>'1'
Read F35UI001

If Failed then Exit Loop.

Copy Branch to @Branch[$X * sizeof(MCU)]

$X++

End While

Select F3462 Records using MBITM=Input Item, MBMCU=@Branch and Input $$FBDT <= MBPDDJ <= 

Wk End Date.

Else

Select F3462 Records using MBITM=Input Item, MBMCU=Input Branch and Input $$FBDT <= MBPDDJ 
<= Wk End Date

End If

Wk Exit Flag = '0'

While Wk Exit Flag <> '1'

Fetch F3462 Record.

If Fetch Failed then Break out of While Loop

If MBPDDJ = 0 then Continue

Scan @DT for first @DT[$X] >= MBPDDJ

If Scan Succeeded then

@HQ[$X] = @HQ[$X] + MBUORG
End If

End While


// Adjust Shipped Quantities with Unadjusted Forecast Quantities.

Wk $$BALQ = 0

Scan @DT for @DT[$R] > $$Input $$FBDT

Wk Index $$BG=$R

For $R = $$BG to $$PND

$$BALQ = $$BALQ + @HQ[$R]

@HQ[$R] = 0

If @FC[$R] = '1' 

For $X = $$BG to $R

If @FQU[$X] < 0 And $X <> $R then Continue.

If $X <> $R 

If $$BALQ >= @FQU[$X]

$$BALQ = $$BALQ - @FQU[$X]

@HQ[$X] = @HQ[$X] + @FQU[$X]

@FQU[$X] = 0

Else

@FQU[$X] = @FQU[$X] - $$BALQ

@HQ[$X] = @HQ[$X] + $$BALQ

$$BALQ = 0

End If

Else

@FQU[$X] = @FQU[$X] - $$BALQ

@HQ[$X] = @HQ[$X] + $$BALQ

$$BALQ = 0

$$BG = $X + 1

If $$BG > $$PND then

$$BG = $$PND

End If

If @FQU [$X] < 0 then

@FQU[$X] = 0

End If

End If

End For

End If

End For


If @Branch was allocated then Free the memory used for this array.


4. Adjust Sales Order and Forecast Quantities Using Forecast Consumption 
For $X = 1 to $$PND
If @DT[$X] <= Plan Date $$PLDT

Copy @SQU[$X] to @SQ[$X]

End If

Copy @FQU [$X] to @FQ[$X]

End For

Wk $$BALQ = 0

For $X = 1 to $$PND And @DT[$X] <= $$PLDT

If @SQ[$X] <> 0 Or @FQ[$X] <> 0 then

If SQ[$X] >= FQ[$X] then
Balance = SQ[$X] - FQ[$X]

FQ[$X] = 0

If FC[$X] = '1' then
$Y = $$PND + 1

Else

$Y = $X + 1
End If

While Balance > 0 And Y <= $$PND
If FC[$Y] = '1' then

FQ[$Y] = FQ[$Y] - Balance

Balance = 0

If FQ[$Y] < 0 then
FQ[

Data Structure

D3400400 - MRP, Update Adjusted Sales and Forecast Qty

Parameter NameData ItemData TypeReq/OptI/O/Both
cTimeFenceRuleMPSPcharNONENONE

A code (system 34, table TF) that the system uses in conjunction with the Planning Time Fence Days field to determine how forecast 
demand or actual customer demand is used. For example:    S tells the system to plan using customer demand before the time fence and forecast 
after the time fence    F tells the system to plan using forecast before the time fence and forecast plus customer demand after the time fence  If 
you enter 5 in the Planning Time Fence Days field and S in this field, then the system uses only customer demand for the regeneration for the 
first 5  days. After 5 days, the system uses the forecast for the regeneration. Valid codes are:    C Customer demand before, greater of forecast 
or customer demand after    F Forecast before, forecast plus customer demand after    G Greater of forecast or customer demand before, 
forecast after    S Customer demand before, forecast after    1   Zero before, forecast after    3   Zero before, forecast plus customer demand after 

jdPlanDateDATE01JDEDATENONENONE

Event point for JDE Date.

cSuppressErrorMessageEV01charNONENONE

An option that specifies the type of processing for an event.

cErrorCodeERRCcharNONENONE

This error code indicates if any errors occurred during the creation of the Trip Document Detail (F4914) records by the Delivery Document 
Set Server program (XT4914).

szErrorMessageIDDTAIcharNONENONE

A code that identifies and defines a unit of information. It is an alphanumeric code up to 8 characters long that does not allow blanks or 
special characters such as %, &, or +. You create new data items using system codes 55-59. You cannot change the alias.

szBranchMCUcharNONENONE

An alphanumeric code that identifies a separate entity within a business for which you want to track costs. For example, a business unit 
might be a warehouse location, job, project, work center, branch, or plant. You can assign a business unit to a document, entity, or person for 
purposes of responsibility reporting. For example, the system provides reports of open accounts payable and accounts receivable by 
business unit to track equipment by responsible department. Business unit security might prevent you from viewing information about business units 
for which you have no authority.

szJobNumberJOBcharNONENONE

Job Number

jdFirstDateDATE01JDEDATENONENONE

Event point for JDE Date.

cForecastConsumptionFlagEV03charNONENONE

A radio button that specifies the level at which trace/track result is to be displayed.  Select the Detail to display all transactions except IB, IX, 
and IZ types.  Or, select Derivative Lots Only to display only those transactions that may have created new derivative lot. 

jdForecastBeginningDateDATE04JDEDATENONENONE

Event point for JDE Date.

nNumberBucketlessDatesINT01integerNONENONE

Number of Days in Future to Query for Responses Due. 

mnShortItemNumberITMMATH_NUMERICNONENONE

An inventory item number. The system provides three separate item numbers plus an extensive cross-reference capability to other item 
numbers (see data item XRT) to accommodate substitute item numbers, replacements, bar codes, customer numbers, supplier numbers, and 
so forth. The item numbers are as follows:   o Item Number (short) - An eight-digit, computer-assigned item number     o 2nd Item Number - The 
25-digit, free-form, user defined alphanumeric item number     o 3rd Item Number - Another 25-digit, free-form, user defined alphanumeric item 
number

nNumberPastDueDatesINT02integerNONENONE

Number of Days in the Past to Query for Quote Requests Received. 

cIncludeShippedQuantitiesEV04charNONENONE

PeopleSoft event point processing flag 04.

szDateBranchMCUcharNONENONE

An alphanumeric code that identifies a separate entity within a business for which you want to track costs. For example, a business unit 
might be a warehouse location, job, project, work center, branch, or plant. You can assign a business unit to a document, entity, or person for 
purposes of responsibility reporting. For example, the system provides reports of open accounts payable and accounts receivable by 
business unit to track equipment by responsible department. Business unit security might prevent you from viewing information about business units 
for which you have no authority.

cConsolidationMethodEV01charNONENONE

An option that specifies the type of processing for an event.

nNumberOfBranchesINT01integerNONENONE

Number of Days in Future to Query for Responses Due. 

szComputerIDCTIDcharNONENONE

cForecastIncludedEV01charOPTNONE

An option that specifies the type of processing for an event.

cSalesOrderIncludedEV02charOPTNONE

An option that specifies the type of processing for an event.

cSupplyDemandExistsEV01charOPTNONE

An option that specifies the type of processing for an event.

cInterplantConsumesForecastEV01charOPTNONE

An option that specifies the type of processing for an event.

szProgramIdPIDcharOPTNONE

The number that identifies the batch or interactive program (batch or interactive object). For example, the number of the Sales Order Entry 
interactive program is P4210, and the number of the Print Invoices batch process report is R42565. The program ID is a variable length value. 
It is assigned according to a structured syntax in the form TSSXXX, where: T The first character of the number is alphabetic and identifies the 
type, such as P for Program, R for Report, and so on. For example, the value P in the number P4210 indicates that the object is a 
program. SS The second and third characters of the number are numeric and identify the system code. For example, the value 42 in the number P4210 
indicates that this program belongs to system 42, which is the Sales Order Processing system. XXX The remaining characters of the numer are 
numeric and identify a unique program or report. For example, the value 10 in the number P4210 indicates that this is the Sales Order Entry 
program.

szNewForecastTypeTYPFcharOPTNONE

A user defined code (34/DF) that indicates one of the following:     o The forecasting method used to calculate the numbers displayed about 
the item     o The actual historical information about the item 

szUserIdUSERcharOPTNONE

The code that identifies a user profile.

mnCustomerNumberAN8MATH_NUMERICOPTNONE

A number that identifies an entry in the Address Book system, such as employee, applicant, participant, customer, supplier, tenant, or 
location.

Related Functions

B3401270 Cache, Process MRP Bucketless Dates
B3401290 Cache, Process MRP Item Quantities

Related Tables

F3462 Forecast Shipment Summary
F35UI001 MPS/MRP Planning - Multiple Plant User Index