on 2023 Nov 23 2:35 AM
I use business object -- Purchasing info record to implement batch import purchase info record.When I prepared the test data, the following error occurred during program execution.The StandardPurchaseOrderQuantity field should be "QUAN".
class ZCL_MM_021 definition
public
create public .
public section.
interfaces IF_HTTP_SERVICE_EXTENSION .
protected section.
private section.
ENDCLASS.
CLASS ZCL_MM_021 IMPLEMENTATION.
method IF_HTTP_SERVICE_EXTENSION~HANDLE_REQUEST.
* ----------Import Data Row Type.-----------
TYPES:
BEGIN OF ts_row,
* I_PurchasingInfoRecordApi01
Supplier TYPE c LENGTH 10,
Material TYPE c LENGTH 40,
* I_PurgInfoRecdOrgPlntDataApi01
PurInfoRecordCategory TYPE c LENGTH 1,
PurchasingOrganization TYPE c LENGTH 4,
Plant TYPE c LENGTH 4,
PriceValidityEnddate TYPE c LENGTH 8,
NetPriceAmount TYPE c LENGTH 13,
* net_price_amount TYPE p LENGTH 11 DECIMALS 2,
Currency TYPE c LENGTH 5,
MaterialPlannedDeliveryDurn TYPE p LENGTH 3 DECIMALS 0,
PurchasingGroup TYPE c LENGTH 3,
PricingDateControl TYPE c LENGTH 1,
Taxcode TYPE c LENGTH 2,
MaterialPriceUnitQty TYPE p LENGTH 5 DECIMALS 0,
END OF ts_row,
tt_row TYPE STANDARD TABLE OF ts_row WITH DEFAULT KEY.
DATA lt_rows TYPE tt_row.
* ----------Entities Types.-----------
DATA: cr_tab TYPE TABLE FOR CREATE i_purchasinginforecordtp,
cr_tab_child TYPE TABLE FOR CREATE i_purchasinginforecordtp\_PurgInfoRecdOrgPlntData,
mapped_resp TYPE RESPONSE FOR MAPPED i_purchasinginforecordtp, "response parameters
failed_resp TYPE RESPONSE FOR FAILED i_purchasinginforecordtp,
reported_resp TYPE RESPONSE FOR REPORTED i_purchasinginforecordtp.
* ----------transform JSON to ABAP.-----------
* transformation: camel_case_to_underscore, pascal_case_to_underscore, underscore_to_camel_case, underscore_to_pascal_case
* transformation: boolean_to_abap_bool
DATA(lv_json_string) = request->get_text( ).
TRY.
xco_cp_json=>data->from_string( lv_json_string )->apply( VALUE #(
( xco_cp_json=>transformation->underscore_to_pascal_case )
( xco_cp_json=>transformation->boolean_to_abap_bool )
) )->write_to( REF #( lt_rows ) ).
CATCH cx_xslt_deserialization_error INTO DATA(exc).
response->set_text( exc->get_text( ) ).
RETURN.
ENDTRY.
* ----------Processing Data.-----------
LOOP AT lt_rows INTO DATA(lo_row).
DATA(LV_CID) = lo_row-supplier && lo_row-material && lo_row-purchasingorganization && lo_row-plant && lo_row-pricevalidityenddate.
MODIFY ENTITIES OF i_purchasinginforecordtp
ENTITY purchasinginforecord
CREATE FIELDS ( supplier material ) WITH
VALUE #( ( %cid = LV_CID
supplier = lo_row-supplier
material = lo_row-material
) )
CREATE BY \_purginforecdorgplntdata
FIELDS ( purchasinginforecordcategory purchasingorganization plant pricevalidityenddate netpriceamount ) WITH
VALUE #( ( %cid_ref = LV_CID
%target = VALUE #( ( %cid = LV_CID && lo_row-netpriceamount
purchasinginforecordcategory = lo_row-purinforecordcategory
purchasingorganization = lo_row-purchasingorganization
plant = lo_row-plant
pricevalidityenddate = lo_row-pricevalidityenddate
netpriceamount = lo_row-netpriceamount
PurchasingGroup = lo_row-purchasinggroup
currency = lo_row-currency
StandardPurchaseOrderQuantity = '1'
MaterialPlannedDeliveryDurn = lo_row-materialplanneddeliverydurn
PurgDocOrderQuantityUnit = '1'
" NetPriceQuantityUnit = '30.00'
MaterialPriceUnitQty = lo_row-materialpriceunitqty
TaxCode = lo_row-taxcode
)
) ) )
MAPPED mapped_resp
REPORTED reported_resp
FAILED failed_resp.
COMMIT ENTITIES
RESPONSE OF i_purchasinginforecordtp
FAILED DATA(failed_commit)
REPORTED DATA(reported_commit).
ENDLOOP.
* DATA(lv_json_str) = xco_cp_json=>data->from_abap( failed_commit )->apply( VALUE #(
* ( xco_cp_json=>transformation->underscore_to_pascal_case )
* ) )->to_string( ).
response->set_text( 'ok' ).
endmethod.
ENDCLASS.
Purchasing Info Record
Request clarification before answering.
User | Count |
---|---|
120 | |
9 | |
8 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.