import java.util.Properties;
import java.io.InputStream;
import com.boomi.execution.ExecutionUtil;

for( int i = 0; i < dataContext.getDataCount(); i++ ) {
  InputStream is = dataContext.getStream(i);
  Properties props = dataContext.getProperties(i);

  String CombinePartNumberInput = ExecutionUtil.getDynamicProcessProperty("CombinePartNumberInput");
  String DDP_Site = ExecutionUtil.getDynamicDocumentProperty("DDP_Site");
  String Query = "SELECT   MIN(msib.segment1) part_number,   msib.inventory_item_id inventory_item_id,   msib.inventory_item_status_code status,   MAX(msib.item_type) type,   MIN(msib.attribute3) note,   MIN(msib.planning_make_buy_code) make_buy,   MAX(msib.organization_id) organization_id,   SUM(    decode(      mi.reservable_type,       1,       nvl(moq.transaction_quantity, 0),       0    )  ) qoh,   '0' quantity_reserved,   decode(    MIN(msib.planning_make_buy_code),     1,     'Make',     2,     'Buy',     '?'  ) source_code,   MAX(    mtl_org_item_trans.last_trans_date  ) last_trans_date,   MIN(    apps.vtk_partial_description(msib.description)  ) item_description,   MIN(msib.wip_supply_type) wip_supply_type,   to_char(    MIN(sysdate + msib.full_lead_time),     'YYYYMMDDHH24MI'  ) reqdate,   msib.primary_unit_of_measure uom,   cost_info.cost_info.item_cost FROM   mtl_system_items_b msib   JOIN mtl_parameters mp ON msib.organization_id = mp.organization_id   JOIN (    SELECT       msib.organization_id,       msib.inventory_item_id,       nvl(        MAX(mmt.transaction_date),         sysdate - 15 * 30      ) last_trans_date     FROM       mtl_material_transactions mmt,       mtl_system_items_b msib     WHERE       1 = 1       AND msib.organization_id = mmt.organization_id       AND msib.inventory_item_id = mmt.inventory_item_id ";
         Query = Query.concat(" AND segment1 IN " + CombinePartNumberInput + "");
         Query = Query.concat(" GROUP BY msib.organization_id, msib.inventory_item_id  ) mtl_org_item_trans ON mtl_org_item_trans.organization_id = msib.organization_id   AND mtl_org_item_trans.inventory_item_id = msib.inventory_item_id   LEFT OUTER JOIN mtl_onhand_quantities moq ON msib.organization_id = moq.organization_id   AND msib.inventory_item_id = moq.inventory_item_id OUTER APPLY (    SELECT       msib2.planning_make_buy_code,       cic.material_cost,       cic.material_overhead_cost,       nvl(cic.resource_cost, 0) res_cost,       cic.outside_processing_cost,       nvl(cic.overhead_cost, 0) overhead,       item_cost,       msib2.primary_unit_of_measure uom,       msib2.inventory_item_id,       msib2.organization_id     FROM       cst_item_costs cic,       mtl_system_items_b msib2     WHERE       1 = 1       AND msib2.organization_id = msib.organization_id       AND msib2.inventory_item_id = msib.inventory_item_id       AND cic.organization_id = msib2.organization_id       AND msib2.inventory_item_id = cic.inventory_item_id       AND cic.cost_type_id = 1  ) cost_info   JOIN mtl_secondary_inventories mi ON moq.organization_id = mi.organization_id   AND moq.subinventory_code = mi.secondary_inventory_name WHERE   1 = 1 " );
         Query = Query.concat(" AND msib.segment1 IN " + CombinePartNumberInput + "");
		 Query = Query.concat(" AND mp.organization_code NOT LIKE '__1' AND ( mp.organization_code = decode( " + DDP_Site +  'BGL', 'EOU', 'COK', 'CVO', 'DPK','HST', 'PQR', 'HST', 'FRE', 'FPT','SPV', 'SPR', 'SQR', 'SPR', " , " + DDP_Site + " ) )  AND msib.wip_supply_type <> 6 GROUP BY   msib.inventory_item_id,   msib.primary_unit_of_measure,   msib.inventory_item_status_code,   cost_info.cost_info.item_cost UNION SELECT   DISTINCT MIN(msic.segment1) part_number,   msic.inventory_item_id inventory_item_id,   msic.inventory_item_status_code status,   MAX(msic.item_type) type,   MIN(msic.attribute3) note,   MIN(msic.planning_make_buy_code) make_buy,   MAX(msic.organization_id) organization_id,   SUM(    decode(      mi.reservable_type,       1,       nvl(moq.transaction_quantity, 0),       0    )  ) qoh,   '0' quantity_reserved,   decode(    MIN(msib.planning_make_buy_code),     1,     'Make',     2,     'Buy',     '?'  ) source_code,   MAX(    mtl_org_item_trans.last_trans_date  ) last_trans_date,   MIN(    apps.vtk_partial_description(msic.description)  ) item_description,   MIN(msic.wip_supply_type) wip_supply_type,   to_char(    MIN(sysdate + msic.full_lead_time),     'YYYYMMDDHH24MI'  ) reqdate,   msic.primary_unit_of_measure uom,   cost_info.cost_info.item_cost FROM   mtl_parameters mp   JOIN mtl_system_items_b msib ON msib.organization_id = mp.organization_id   JOIN bom_bill_of_materials bom ON msib.organization_id = mp.organization_id   AND bom.assembly_item_id = msib.inventory_item_id   AND bom.organization_id = msib.organization_id   JOIN bom_inventory_components bic ON bic.bill_sequence_id = bom.bill_sequence_id   JOIN mtl_system_items_b msic ON bic.component_item_id = msic.inventory_item_id   AND bom.organization_id = msic.organization_id   AND effectivity_date < sysdate   AND nvl(bic.disable_date, sysdate) >= sysdate   JOIN (    SELECT       msib.organization_id,       msib.inventory_item_id,       nvl(        MAX(mmt.transaction_date),         sysdate - 15 * 30      ) last_trans_date     FROM       mtl_material_transactions mmt,       mtl_system_items_b msib     WHERE       1 = 1       AND msib.organization_id = mmt.organization_id       AND msib.inventory_item_id = mmt.inventory_item_id " ); 
         Query = Query.concat(" AND segment1 IN " + CombinePartNumberInput + "");
		 Query = Query.concat(" GROUP BY msib.organization_id,       msib.inventory_item_id  ) mtl_org_item_trans ON mtl_org_item_trans.organization_id = msic.organization_id   AND mtl_org_item_trans.inventory_item_id = msib.inventory_item_id   JOIN hr_organization_units h ON h.organization_id = mp.organization_id   LEFT OUTER JOIN mtl_onhand_quantities moq ON moq.organization_id = msic.organization_id   AND moq.inventory_item_id = msic.inventory_item_id OUTER APPLY (    SELECT       msib2.planning_make_buy_code,       cic.material_cost,       cic.material_overhead_cost,       nvl(cic.resource_cost, 0) res_cost,       cic.outside_processing_cost,       nvl(cic.overhead_cost, 0) overhead,       item_cost,       msib2.primary_unit_of_measure uom,       msib2.inventory_item_id,       msib2.organization_id     FROM       cst_item_costs cic,       mtl_system_items_b msib2     WHERE       1 = 1       AND msib2.organization_id = msic.organization_id       AND msib2.inventory_item_id = msic.inventory_item_id       AND cic.organization_id = msib2.organization_id       AND msib2.inventory_item_id = cic.inventory_item_id       AND cic.cost_type_id = 1  ) cost_info   LEFT OUTER JOIN mtl_secondary_inventories mi ON mi.organization_id = msic.organization_id   AND moq.subinventory_code = mi.secondary_inventory_name WHERE   ROWNUM < 500 " );
         Query = Query.concat(" AND msib.segment1 IN " + CombinePartNumberInput + "");
		 Query = Query.concat(" AND msib.wip_supply_type = 6   AND mp.organization_code = decode( " + DDP_Site + " , + " 'BGL', 'EOU', 'COK', 'CVO', 'DPK', 'HST', 'PQR', 'HST', 'FRE', 'FPT','SPV', 'SPR', 'SQR', 'SPR', " , " + DDP_Site + " )   AND msib.organization_id = mp.organization_id GROUP BY   msic.inventory_item_id,   msic.primary_unit_of_measure,   msic.inventory_item_status_code,   cost_info.cost_info.item_cost ORDER BY   part_number " );
		 
ExecutionUtil.setDynamicProcessProperty("Query", Query, false);  
  
  dataContext.storeStream(is, props);
} 

Groovy online compiler

Write, Run & Share Groovy code online using OneCompiler's Groovy online compiler for free. It's one of the robust, feature-rich online compilers for Groovy language, running the latest Groovy version 2.6. Getting started with the OneCompiler's Groovy editor is easy and fast. The editor shows sample boilerplate code when you choose language as Groovy and start coding.

Read inputs from stdin

OneCompiler's Groovy online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Groovy program which takes name as input and prints hello message with your name.

def name = System.in.newReader().readLine()
println "Hello " + name

About Groovy

Groovy is an object-oriented programming language based on java. Apache Groovy is a dynamic and agile language which is similar to Python, Ruby, Smalltalk etc.

Key Features

  • It's not a replacement for java but it's an enhancer to Java with extra features like DSL support, dynamic typing, closures etc.
  • Accepts Java code as it extends JDK
  • Greater flexibility
  • Concise and much simpler compared to Java
  • Can be used as both programming language and scripting language.

Syntax help

Data Types

Data typeDescriptionRange
StringTo represent text literalsNA
charTo represent single character literalNA
intTo represent whole numbers-2,147,483,648 to 2,147,483,647
shortTo represent short numbers-32,768 to 32,767
longTo represent long numbers-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
doubleTo represent 64 bit floating point numbers4.94065645841246544e-324d to 1.79769313486231570e+308d
floatTo represent 32 bit floating point numbers1.40129846432481707e-45 to 3.40282346638528860e+38
byteTo represent byte value-128 to 127
booleanTo represent boolean values either true or falseTrue or False

Variables

You can define variables in two ways

Syntax:

data-type variable-name;

[or]

def variable-name;

Loops

0.upto(n) {println "$it"}

or

n.times{println "$it"}

where n is the number of loops and 0 specifies the starting index

Decision-Making

1. If / Nested-If / If-Else:

When ever you want to perform a set of operations based on a condition or set of conditions, then If / Nested-If / If-Else is used.

if(conditional-expression) {
  // code
} else {
  // code
}

2. Switch:

Switch is an alternative to If-Else-If ladder and to select one among many blocks of code.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 //code to be executed when all the above cases are not matched;    
} 

List

List allows you to store ordered collection of data values.

Example:

def mylist = [1,2,3,4,5];
List MethodsDescription
size()To find size of elements
sort()To sort the elements
add()To append new value at the end
contains()Returns true if this List contains requested value.
get()Returns the element of the list at the definite position
pop()To remove the last item from the List
isEmpty()Returns true if List contains no elements
minus()This allows you to exclude few specified elements from the elements of the original
plus()This allows you to add few specified elements to the elements of the original
remove()To remove the element present at the specific position
reverse()To reverse the elements of the original List and creates new list