Skip to Content
Product Information
Author's profile photo Ecco Liu

如何使用盘点API过账到上期间

近期我们收到多位客户反馈他们在日常盘点业务处理中,希望使用API进行盘点并过账到上期间以节省时间并符合实际业务,在S/4HANA中我们可以使用系统中的标准API实现这一需求。具体操作如下:

1.首先使用库存盘点凭证(Physical Inventory Documents)API的GET方法来获取x-csrf-token,以便在后续API测试中使用;

2.使用API创建库存盘点凭证,这里使用到的是库存盘点凭证(Physical Inventory Documents)API的POST方法,首先将x-csrf-token作为参数填写到headers中,在Body中填入库存盘点凭证创建所需的参数,我们这里测试数据使用的Payload如下:

{

    "Plant": "1010",

    "StorageLocation": "101A",

    "DocumentDate": "2022-09-15T00:00:00",

    "PhysInventoryPlannedCountDate": "2022-09-15T00:00:00",



    "to_PhysicalInventoryDocumentItem": [

        {

            "Material": "TG12"

        }

    ]

}

运行之后的结果如下:

<?xml version="1.0" encoding="utf-8"?>
<entry m:etag="W/&quot;datetimeoffset'2022-09-20T09%3A09%3A01.9226260Z'&quot;" xml:base="https://cc3-715-api.wdf.sap.corp/sap/opu/odata/sap/API_PHYSICAL_INVENTORY_DOC_SRV/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
    <id>https://cc3-715-api.wdf.sap.corp/sap/opu/odata/sap/API_PHYSICAL_INVENTORY_DOC_SRV/A_PhysInventoryDocHeader(FiscalYear='2022',PhysicalInventoryDocument='100004361')</id>
    <title type="text">A_PhysInventoryDocHeader(FiscalYear='2022',PhysicalInventoryDocument='100004361')</title>
    <updated>2022-09-20T09:09:02Z</updated>
    <category term="API_PHYSICAL_INVENTORY_DOC_SRV.A_PhysInventoryDocHeaderType" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
    <link href="A_PhysInventoryDocHeader(FiscalYear='2022',PhysicalInventoryDocument='100004361')" rel="self" title="A_PhysInventoryDocHeaderType"/>
    <link href="A_PhysInventoryDocHeader(FiscalYear='2022',PhysicalInventoryDocument='100004361')/to_PhysicalInventoryDocumentItem" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/to_PhysicalInventoryDocumentItem" type="application/atom+xml;type=feed" title="to_PhysicalInventoryDocumentItem">
        <m:inline>
            <feed xml:base="https://cc3-715-api.wdf.sap.corp/sap/opu/odata/sap/API_PHYSICAL_INVENTORY_DOC_SRV/">
                <id>https://cc3-715-api.wdf.sap.corp/sap/opu/odata/sap/API_PHYSICAL_INVENTORY_DOC_SRV/A_PhysInventoryDocHeader(FiscalYear='2022',PhysicalInventoryDocument='100004361')/to_PhysicalInventoryDocumentItem</id>
                <title type="text">A_PhysInventoryDocItem</title>
                <updated>2022-09-20T09:09:02Z</updated>
                <author>
                    <name/>
                </author>
                <link href="A_PhysInventoryDocHeader(FiscalYear='2022',PhysicalInventoryDocument='100004361')/to_PhysicalInventoryDocumentItem" rel="self" title="A_PhysInventoryDocItem"/>
            </feed>
        </m:inline>
    </link>
    <content type="application/xml">
        <m:properties>
            <d:FiscalYear>2022</d:FiscalYear>
            <d:PhysicalInventoryDocument>100004361</d:PhysicalInventoryDocument>
            <d:InventoryTransactionType>IB</d:InventoryTransactionType>
            <d:Plant>1010</d:Plant>
            <d:StorageLocation>101A</d:StorageLocation>
            <d:InventorySpecialStockType/>
            <d:DocumentDate>2022-09-15T00:00:00</d:DocumentDate>
            <d:PhysInventoryPlannedCountDate>2022-09-15T00:00:00</d:PhysInventoryPlannedCountDate>
            <d:PhysicalInventoryLastCountDate m:null="true"/>
            <d:PostingDate m:null="true"/>
            <d:FiscalPeriod>0</d:FiscalPeriod>
            <d:CreatedByUser>CC0000002699</d:CreatedByUser>
            <d:PostingIsBlockedForPhysInvtry>false</d:PostingIsBlockedForPhysInvtry>
            <d:PhysicalInventoryCountStatus/>
            <d:PhysInvtryAdjustmentPostingSts/>
            <d:PhysInvtryDeletionStatus/>
            <d:PhysInvtryDocHasQtySnapshot>false</d:PhysInvtryDocHasQtySnapshot>
            <d:PhysicalInventoryGroupType/>
            <d:PhysicalInventoryGroup/>
            <d:PhysicalInventoryNumber/>
            <d:PhysInventoryReferenceNumber/>
            <d:PhysicalInventoryDocumentDesc/>
            <d:PhysicalInventoryType/>
            <d:LastChangeDateTime>2022-09-20T09:09:01.9226260Z</d:LastChangeDateTime>
        </m:properties>
    </content>
</entry>

3.为了获取库存盘点结果录入所需的If-Match参数,我们这里使用盘点凭证单号加财年作为参数对上一步API创建的库存盘点凭证进行查询,在查询结果中记录etag作为If-Match参数保留。

4.接下来进行库存盘点结果的录入,这里使用Count Physical Inventory Document Items的PATCH方法,在测试这个API时,将x-csrf-token和If-Match作为参数填入Headers,在Body中填入库存盘点凭证创建所需的参数,尤其需要注意的是将参数LastCountDate填写为上期间的日期,我们这里使用的Payload如下,若返回状态码204则表示运行成功。

{

    "Material" : "TG12",

    "QuantityInUnitOfEntry" : "20735272.004",

    "UnitOfEntry" : "PC",

    "PhysicalInventoryLastCountDate" : "2022-08-15T00:00:00"

}

5.最后一步对盘点差异进行过账,使用Post Differences的POST方法时,将x-csrf-token和If-Match作为参数填入Headers,并在测试该API时填入所需的参数,此时PostingDate必须填写为上期间中的日期。这里列出成功运行API返回的结果作为参考:

<?xml version="1.0" encoding="utf-8"?>
<entry m:etag="W/&quot;datetimeoffset'2022-09-20T09%3A12%3A34.0684300Z'&quot;" xml:base="https://cc3-715-api.wdf.sap.corp/sap/opu/odata/sap/API_PHYSICAL_INVENTORY_DOC_SRV/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
    <id>https://cc3-715-api.wdf.sap.corp/sap/opu/odata/sap/API_PHYSICAL_INVENTORY_DOC_SRV/A_PhysInventoryDocItem(FiscalYear='2022',PhysicalInventoryDocument='100004361',PhysicalInventoryDocumentItem='1')</id>
    <title type="text">A_PhysInventoryDocItem(FiscalYear='2022',PhysicalInventoryDocument='100004361',PhysicalInventoryDocumentItem='1')</title>
    <updated>2022-09-20T09:12:35Z</updated>
    <category term="API_PHYSICAL_INVENTORY_DOC_SRV.A_PhysInventoryDocItemType" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
    <link href="A_PhysInventoryDocItem(FiscalYear='2022',PhysicalInventoryDocument='100004361',PhysicalInventoryDocumentItem='1')" rel="edit" title="A_PhysInventoryDocItemType"/>
    <link href="A_PhysInventoryDocItem(FiscalYear='2022',PhysicalInventoryDocument='100004361',PhysicalInventoryDocumentItem='1')/to_PhysicalInventoryDocument" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/to_PhysicalInventoryDocument" type="application/atom+xml;type=entry" title="to_PhysicalInventoryDocument"/>
    <link href="A_PhysInventoryDocItem(FiscalYear='2022',PhysicalInventoryDocument='100004361',PhysicalInventoryDocumentItem='1')/to_SerialNumbers" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/to_SerialNumbers" type="application/atom+xml;type=feed" title="to_SerialNumbers"/>
    <content type="application/xml">
        <m:properties>
            <d:FiscalYear>2022</d:FiscalYear>
            <d:PhysicalInventoryDocument>100004361</d:PhysicalInventoryDocument>
            <d:PhysicalInventoryDocumentItem>1</d:PhysicalInventoryDocumentItem>
            <d:Plant>1010</d:Plant>
            <d:StorageLocation>101A</d:StorageLocation>
            <d:Material>TG12</d:Material>
            <d:Batch/>
            <d:InventorySpecialStockType/>
            <d:PhysicalInventoryStockType>1</d:PhysicalInventoryStockType>
            <d:SalesOrder/>
            <d:SalesOrderItem>0</d:SalesOrderItem>
            <d:Supplier/>
            <d:Customer/>
            <d:WBSElement/>
            <d:LastChangeUser/>
            <d:LastChangeDate m:null="true"/>
            <d:CountedByUser>CC0000002699</d:CountedByUser>
            <d:PhysicalInventoryLastCountDate>2022-08-15T00:00:00</d:PhysicalInventoryLastCountDate>
            <d:AdjustmentPostingMadeByUser>CC0000002699</d:AdjustmentPostingMadeByUser>
            <d:PostingDate>2022-08-15T00:00:00</d:PostingDate>
            <d:PhysicalInventoryItemIsCounted>true</d:PhysicalInventoryItemIsCounted>
            <d:PhysInvtryDifferenceIsPosted>true</d:PhysInvtryDifferenceIsPosted>
            <d:PhysInvtryItemIsRecounted>false</d:PhysInvtryItemIsRecounted>
            <d:PhysInvtryItemIsDeleted>false</d:PhysInvtryItemIsDeleted>
            <d:IsHandledInAltvUnitOfMsr>true</d:IsHandledInAltvUnitOfMsr>
            <d:CycleCountType/>
            <d:IsValueOnlyMaterial>false</d:IsValueOnlyMaterial>
            <d:PhysInventoryReferenceNumber/>
            <d:MaterialDocument/>
            <d:MaterialDocumentYear>0000</d:MaterialDocumentYear>
            <d:MaterialDocumentItem>0</d:MaterialDocumentItem>
            <d:PhysInvtryRecountDocument/>
            <d:PhysicalInventoryItemIsZero>false</d:PhysicalInventoryItemIsZero>
            <d:ReasonForPhysInvtryDifference>0</d:ReasonForPhysInvtryDifference>
            <d:MaterialBaseUnit>PC</d:MaterialBaseUnit>
            <d:BookQtyBfrCountInMatlBaseUnit>20735301.004</d:BookQtyBfrCountInMatlBaseUnit>
            <d:Quantity>20735272.004</d:Quantity>
            <d:UnitOfEntry>PC</d:UnitOfEntry>
            <d:QuantityInUnitOfEntry>20735272.004</d:QuantityInUnitOfEntry>
            <d:Currency>EUR</d:Currency>
            <d:DifferenceAmountInCoCodeCrcy>319.58</d:DifferenceAmountInCoCodeCrcy>
            <d:EnteredSlsAmtInCoCodeCrcy>0.00</d:EnteredSlsAmtInCoCodeCrcy>
            <d:SlsPriceAmountInCoCodeCrcy>0.00</d:SlsPriceAmountInCoCodeCrcy>
            <d:PhysInvtryCtAmtInCoCodeCrcy>228502475.77</d:PhysInvtryCtAmtInCoCodeCrcy>
            <d:BookQtyAmountInCoCodeCrcy>228502795.35</d:BookQtyAmountInCoCodeCrcy>
            <d:LastChangeDateTime>2022-09-20T09:12:34.0684300Z</d:LastChangeDateTime>
        </m:properties>
    </content>
</entry>

通过如上API测试可知,若想盘点过账至上期间,需保证API中的LastCountDate和Posting Date放在一个月份,否则API无法成功运行。

若需获得本API详细使用规范,可参考Physical Inventory Documents – Read, Create | SAP Help Portal

另外,关于更多API使用需求,可参考SAP API Business Hub (https://api.sap.com) ,获得关于API使用的更多信息。有关更多SAP S/4HANA Cloud 供应链请访问:https://community.sap.com/topics/s4hana-cloud-supply-chain

询问有关 SAP S/4HANA Cloud for Supply Chain 的问题可关注:https://answers.sap.com/tags/253c6759-2b52-46f4-be45-e2ab78f2f420

您也可以阅读其他 SAP S/4HANA Cloud供应链相关博客文章:https://blogs.sap.com/tags/253c6759-2b52-46f4-be45-e2ab78f2f420/

感谢您的阅读,请关注我的个人资料以获取未来的博文,也欢迎您在评论区中分享您的反馈或者想法。

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.