- skip sy-subrc lines and CDS type lengths; CDS literal mutants; mutate helper classes - proxy: sap_short_dumps shows only dumps of the current run - 26/26 tasks pass; results in docs/faz1-tasarim.md 11g Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
129 lines
4.7 KiB
ABAP
129 lines
4.7 KiB
ABAP
CLASS {{p}}stock_cover_checker DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
|
PUBLIC SECTION.
|
|
INTERFACES {{p}}if_stock_cover.
|
|
|
|
PRIVATE SECTION.
|
|
TYPES:
|
|
BEGIN OF ty_stock,
|
|
material TYPE {{p}}if_stock_cover=>ty_material,
|
|
plant TYPE {{p}}if_stock_cover=>ty_plant,
|
|
remaining TYPE {{p}}if_stock_cover=>ty_quantity,
|
|
END OF ty_stock.
|
|
TYPES tt_stock TYPE HASHED TABLE OF ty_stock WITH UNIQUE KEY material plant.
|
|
|
|
METHODS aggregate
|
|
IMPORTING it_stock TYPE {{p}}if_stock_cover=>tt_stock_item
|
|
RETURNING VALUE(rt_stock) TYPE tt_stock.
|
|
|
|
METHODS free_quantity
|
|
IMPORTING it_stock TYPE tt_stock
|
|
iv_material TYPE {{p}}if_stock_cover=>ty_material
|
|
iv_plant TYPE {{p}}if_stock_cover=>ty_plant
|
|
RETURNING VALUE(rv_quantity) TYPE {{p}}if_stock_cover=>ty_quantity.
|
|
|
|
METHODS consume
|
|
IMPORTING iv_material TYPE {{p}}if_stock_cover=>ty_material
|
|
iv_plant TYPE {{p}}if_stock_cover=>ty_plant
|
|
iv_quantity TYPE {{p}}if_stock_cover=>ty_quantity
|
|
CHANGING ct_stock TYPE tt_stock.
|
|
|
|
METHODS normalize_material
|
|
IMPORTING iv_material TYPE {{p}}if_stock_cover=>ty_material
|
|
RETURNING VALUE(rv_material) TYPE {{p}}if_stock_cover=>ty_material.
|
|
|
|
METHODS normalize_plant
|
|
IMPORTING iv_plant TYPE {{p}}if_stock_cover=>ty_plant
|
|
RETURNING VALUE(rv_plant) TYPE {{p}}if_stock_cover=>ty_plant.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}stock_cover_checker IMPLEMENTATION.
|
|
METHOD {{p}}if_stock_cover~check.
|
|
DATA(lt_stock) = aggregate( it_stock ).
|
|
|
|
LOOP AT it_requirement INTO DATA(ls_requirement).
|
|
DATA(lv_free) = free_quantity( it_stock = lt_stock
|
|
iv_material = ls_requirement-material
|
|
iv_plant = ls_requirement-plant ).
|
|
DATA(ls_result) = VALUE {{p}}if_stock_cover=>ty_result(
|
|
material = ls_requirement-material
|
|
plant = ls_requirement-plant
|
|
required = ls_requirement-required
|
|
available = lv_free ).
|
|
|
|
IF ls_requirement-required <= 0.
|
|
ls_result-status = {{p}}if_stock_cover=>c_status-invalid.
|
|
ELSEIF lv_free >= ls_requirement-required.
|
|
ls_result-status = {{p}}if_stock_cover=>c_status-ok.
|
|
consume( EXPORTING iv_material = ls_requirement-material
|
|
iv_plant = ls_requirement-plant
|
|
iv_quantity = ls_requirement-required
|
|
CHANGING ct_stock = lt_stock ).
|
|
ELSE.
|
|
ls_result-status = {{p}}if_stock_cover=>c_status-short.
|
|
ls_result-shortage = ls_requirement-required - lv_free.
|
|
consume( EXPORTING iv_material = ls_requirement-material
|
|
iv_plant = ls_requirement-plant
|
|
iv_quantity = lv_free
|
|
CHANGING ct_stock = lt_stock ).
|
|
ENDIF.
|
|
|
|
APPEND ls_result TO rt_result.
|
|
ENDLOOP.
|
|
ENDMETHOD.
|
|
|
|
METHOD {{p}}if_stock_cover~shortages.
|
|
rt_shortage = it_result.
|
|
DELETE rt_shortage WHERE status <> {{p}}if_stock_cover=>c_status-short.
|
|
SORT rt_shortage BY material plant.
|
|
ENDMETHOD.
|
|
|
|
METHOD aggregate.
|
|
LOOP AT it_stock INTO DATA(ls_stock).
|
|
IF ls_stock-quantity < 0.
|
|
CONTINUE.
|
|
ENDIF.
|
|
DATA(lv_material) = normalize_material( ls_stock-material ).
|
|
DATA(lv_plant) = normalize_plant( ls_stock-plant ).
|
|
ASSIGN rt_stock[ material = lv_material plant = lv_plant ] TO FIELD-SYMBOL(<ls_stock_sum>).
|
|
IF sy-subrc = 0.
|
|
<ls_stock_sum>-remaining = <ls_stock_sum>-remaining + ls_stock-quantity.
|
|
ELSE.
|
|
INSERT VALUE #( material = lv_material
|
|
plant = lv_plant
|
|
remaining = ls_stock-quantity ) INTO TABLE rt_stock.
|
|
ENDIF.
|
|
ENDLOOP.
|
|
ENDMETHOD.
|
|
|
|
METHOD free_quantity.
|
|
ASSIGN it_stock[ material = normalize_material( iv_material )
|
|
plant = normalize_plant( iv_plant ) ] TO FIELD-SYMBOL(<ls_stock>).
|
|
IF sy-subrc = 0.
|
|
rv_quantity = <ls_stock>-remaining.
|
|
ENDIF.
|
|
ENDMETHOD.
|
|
|
|
METHOD consume.
|
|
ASSIGN ct_stock[ material = normalize_material( iv_material )
|
|
plant = normalize_plant( iv_plant ) ] TO FIELD-SYMBOL(<ls_stock>).
|
|
IF sy-subrc = 0.
|
|
<ls_stock>-remaining = <ls_stock>-remaining + iv_quantity.
|
|
ENDIF.
|
|
ENDMETHOD.
|
|
|
|
METHOD normalize_material.
|
|
DATA lv_text TYPE string.
|
|
lv_text = iv_material.
|
|
REPLACE ALL OCCURRENCES OF ` ` IN lv_text WITH ``.
|
|
rv_material = to_upper( lv_text ).
|
|
ENDMETHOD.
|
|
|
|
METHOD normalize_plant.
|
|
DATA lv_text TYPE string.
|
|
lv_text = iv_plant.
|
|
REPLACE ALL OCCURRENCES OF ` ` IN lv_text WITH ``.
|
|
rv_plant = to_upper( lv_text ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|