cancel
Showing results for 
Search instead for 
Did you mean: 

Create Physical Inventory Adjustment via ABSL

Former Member
0 Kudos

Hi Everyone!

Please look at the below code. I have tried to create Physical Inventory Adjustment using ABSL.

I have tried this blog. https://archive.sap.com/discussions/message/16777316#16777316

But I'm facing the below error.

BeforeSave Script:

import ABSL;
import AP.LogisticsExecution.Global;

var createPIA : elementsof PhysicalInventoryCount;
createPIA.LocationID.content = "L1100";
createPIA.CountMethodCode = "2";
var resultPIA = PhysicalInventoryCount.Create(createPIA);

var operationalCnt = resultPIA.OperationCount.Create();
operationalCnt.PhysicalInventoryCountScopeCode = "4";

var Activity = operationalCnt.OperationActivity.Create();

var InventoryNoe = Activity.OperationActivityCountInventory.Create();
InventoryNoe.LogisticsAreaKey.ID = "L1100-30-10";
InventoryNoe.LogisticsAreaKey.SiteID.content = "L1100";
InventoryNoe.AddItem();

var inventoryItem = InventoryNoe.OperationActivityInventoryItem.Create();
inventoryItem.MainInventorySeparatingValues.MaterialKey.ProductID.content = "EMB51";

var qty = inventoryItem.OperationActivityInventoryItemQuantity.Create();
qty.ZeroCountedQuantityConfirmedIndicator = true;

Activity.EndCountActivity();

Am I Missing anything? Please help to solve this problem.

Regards

Sankaran A

Accepted Solutions (1)

Accepted Solutions (1)

óespinar
Participant
0 Kudos

Hello all,

This is the revised code working perfectly. The bug was in the creation of OperationActivityInventoryItem and OperationActivityInventoryItemQuantity Nodes.

import ABSL;
import AP.LogisticsExecution.Global;

//1.Create Root node instance of PhysicalInventoryCount BO with Count Method = 2 and provide Location ID 
var createPIA : elementsof PhysicalInventoryCount;
createPIA.LocationID.content = "COM";
createPIA.CountMethodCode = "3";
var resultPIA = PhysicalInventoryCount.Create(createPIA);

//2.Create OperationCount node instance with CountScopeCode = 4
var operationalCnt = resultPIA.OperationCount.Create();
operationalCnt.PhysicalInventoryCountScopeCode = "4";

//3.Create Activity node instance
var Activity = operationalCnt.OperationActivity.Create();

//4.Create CountInventory node instance and here provide LogisticsAreaID ..
var InventoryNoe = Activity.OperationActivityCountInventory.Create();
InventoryNoe.LogisticsAreaKey.ID = "A.";

//5.Perform Action “AddItem” in the Inventory Node
InventoryNoe.AddItem();

//6.Navigate to InventoryItem node instance and provide all the Product details required which needs to be adjusted.
var inventoryItem = InventoryNoe.OperationActivityInventoryItem.GetFirst();
inventoryItem.MainInventorySeparatingValues.MaterialKey.ProductID.content = "ALXRN02";
inventoryItem.IdentifiedStockInventorySeparatingValues.IdentifiedStockKey.ID.content = "304050607080";

//7.Navigate to InventoryItemQuantity node instance and provide the adjustable quantity in CountedQuantity.
var qty = inventoryItem.OperationActivityInventoryItemQuantity.GetFirst();
qty.CountedQuantity.content = 12;
qty.CountedQuantity.unitCode = "EA";
qty.ZeroCountedQuantityConfirmedIndicator = false;

//8.Perform Action “EndCountActivity” on the instance of Activity node.
Activity.EndCountActivity();

//9.Perform Action “ApproveCount” on the instance of Root node.
//resultPIA.ApproveCount();

Regards,

Óscar

Tri
Participant

Hi espinar.oscar,

In your code, you comment "//1.Create Root node instance of PhysicalInventoryCount BO with Count Method = 2 and provide Location ID".

However, you put createPIA.CountMethodCode = "3";

So which one is correct? 2 or 3?

Regards,

Tri

ThiagoSarmento
Product and Topic Expert
Product and Topic Expert

Hello there triminhle,

The CountMethodCode = "2" refers to Inventory Adjustment and "3" refers to Product Count.

Either one can be used, but if you want to create an Inventory Adjustment (2), it is mandatory to approve the document with ApproveCount() method on the script, like in Oscar's step 9: resultPIA.ApproveCount();

The ApproveCount is not mandatory when creating a Product Count (3).

This is also documented on this KBA:

https://launchpad.support.sap.com/#/notes/3223402

I hope this helps!!

Tri
Participant
0 Kudos

Thanks thiago.sarmento.

One more question is: is it possible to get the PI count document ID?

I've tried to add the line "var sID = resultPIA.ID;" at the end after "resultPIA.ApproveCount();".

But it's empty.

Regards,

Tri

ThiagoSarmento
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi triminhle,

Perhaps it should be "var sID = resultPIA.ID.content"?

Tri
Participant
0 Kudos

Thanks thiago.sarmento.

I've tried "var sID = resultPIA.ID.content" but it said resultPIA.ID is not set.

Regards,

Tri

Answers (8)

Answers (8)

former_member275924
Active Participant
0 Kudos

Hi May,

Thanks for your advice , I already find this path .

There is no data in text collection node.

Best Regards,

Charm

may_thitsaoo
Contributor
0 Kudos

Hi Charm,

Please find in this path.

PhysicalInventoryCount>OperationCount>OperationActivity>OperationActivityTextCollection>Text>TextContent

Regards,

May

former_member275924
Active Participant
0 Kudos

Hi Everyone、

I also create physical inventory count with this code .

It is ok.

I want to add internal comment of inventory adjustment via absl.

I can't write internal comment and can't find the internal comment value in repository .

I can't execute the internal comment value via query of PhysicalInventoryCount .

Could you please point out me technical value?

Best Regards,

Charm

Former Member
0 Kudos
import ABSL;
import AP.LogisticsExecution.Global;
var createPIA : elementsof PhysicalInventoryCount;
createPIA.LocationID.content = "L1100";
createPIA.CountMethodCode = "2";
var resultPIA = PhysicalInventoryCount.Create(createPIA);
var operationalCnt = resultPIA.OperationCount.Create();
operationalCnt.PhysicalInventoryCountScopeCode = "4";
var Activity = operationalCnt.OperationActivity.Create();
var InventoryNoe = Activity.OperationActivityCountInventory.Create();


InventoryNoe.LogisticsAreaKey.ID = "L1100-30-10";
InventoryNoe.LogisticsAreaKey.SiteID.content = "L1100";
InventoryNoe.AddItem();
var inventoryItem = InventoryNoe.OperationActivityInventoryItem.Create();


inventoryItem.MainInventorySeparatingValues.MaterialKey.ProductID.content = "EMB51";
var qty = inventoryItem.OperationActivityInventoryItemQuantity.Create();
qty.ZeroCountedQuantityConfirmedIndicator = true;


// BEGIN OF ADDITIONAL CODE
foreach(var inst in InventoryNoe.OperationActivityInventoryItem)
{
  if(inst.MainInventorySeparatingValues.MaterialKey.ProductID.content.IsInitial())
  {
      inst.Delete();
  }
}

// END OF ADDITIONAL CODE
Activity.EndCountActivity();
resultPIA.ApproveCount();

Sorry for the delay. The above code is working for me.

@Óscar thanks for your effect. Your code is also working for me.

Regards

Sankaran A

óespinar
Participant
0 Kudos

Hello Sankara,

Did you get your code finally working? Could you share some tips...

Regards,

Óscar

stefan_resag
Employee
Employee
0 Kudos

Hi,

I talked to development. They ask you to create an incident for this.

Best regards,

Stefan

Former Member
0 Kudos

Thanks Stefan,

I have raised an incident. Incident External ID is: 3500296063.

Please look at it.

Regards

Sankara A

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Sankaran,

Is the link to knut.heusermann available for you?

Bye,
Horst

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Sankaran,

This is that special that you need someone from Logistics Execution (or @Knut.Heusermann).

Sorry,
Horst

Former Member
0 Kudos

Hi Horst,

Thanks for your help.

Can I contact someone from Logistics Execution? I am not able to continue my development due to this issue. I need someone's help on this topic.

Regards

Sankaran A