Ad essere sincero non ho ben capito come mai prima non funzionava (quando si faceva riferimento a posizioni multiple, ma solo per singole posizioni) e poi, dopo alcuni tentativi e piccoli aggiustamenti, adesso funziona correttamente.
Questa la sequenza di videate della transazione:
L'utente inserisce (anche leggendo da barcode riportato nella picking list) il numero della consegna di spedizione:
Sceglie il materiale di imballo:
A questo punto ha 2 possibilità:
- inserire il numero ordine di produzione del materiale (nei nostri imballi applichiamo una etichetta con barcode dell'odp).
- inserire il materiale da imballare.
Il programma verifica la quantità ancora da imballare del materiale e propone la quantità di imballo (da noi gestita tramite una tabellina Z).
Nota: si possono inserire più ordini di produzione poichè, i materiali contenuti in un imballo, possono provenire da diversi ordini di produzione (per esempio completamento di un ordine e apertura di un nuovo lotto).
Quando si preme SAVE (F5) il programma crea l'imballo, imballa il materiale, assegna alla consegna e stampa l'odette di spedizione (gestita esternamente a SAP tramite Bartender).
queste le principali FORM del programma:
verifica quantità da imballare:
tabella globale utilizzata:
TYPES: BEGIN OF t_posizioni,
posnr LIKE lips-posnr,
lfimg LIKE lips-lfimg,
werks LIKE lips-werks,
lgort LIKE lips-lgort,
lgnum LIKE lips-lgnum,
meins LIKE lips-meins,
END OF t_posizioni.
DATA: pos_da_imb TYPE t_posizioni OCCURS 100
WITH HEADER LINE.
codice (ci sono alcune variabili globali e campi dello SCREEN ma sono abbastanza intuitivi)
*&---------------------------------------------------------------------*
*& Form CALCOLA-QTA-DA-IMBALLARE
*&---------------------------------------------------------------------*
FORM calcola-qta-da-imballare .
DATA: w_qta LIKE lips-lfimg,
w_qta_imb LIKE lips-lfimg,
w_qta_imb_t LIKE lips-lfimg,
w_qta_da_imb LIKE lips-lfimg.
REFRESH pos_da_imb.
CLEAR pos_da_imb.
w_qta = 0.
w_qta_imb_t = 0.
CLEAR: d300-qta_tot_imb, d300-num_pos_da_imb, wa_qta_tot_imb.
SELECT * FROM lips WHERE vbeln = <consegna> AND
matnr = <materiale>.
ADD lips-lfimg TO w_qta.
w_qta_imb = 0.
SELECT * FROM vepo WHERE vbeln = lips-vbeln AND
posnr = lips-posnr.
ADD vepo-vemng TO w_qta_imb.
ADD vepo-vemng TO w_qta_imb_t.
ENDSELECT.
w_qta_da_imb = lips-lfimg - w_qta_imb.
IF w_qta_da_imb > 0.
ADD 1 TO d300-num_pos_da_imb.
ADD w_qta_da_imb TO wa_qta_tot_imb.
pos_da_imb-posnr = lips-posnr.
pos_da_imb-lfimg = w_qta_da_imb.
pos_da_imb-werks = lips-werks.
pos_da_imb-lgort = lips-lgort.
pos_da_imb-lgnum = lips-lgnum.
pos_da_imb-meins = lips-meins.
APPEND pos_da_imb.
ENDIF.
ENDSELECT.
WRITE wa_qta_tot_imb TO d300-qta_tot_imb.
ENDFORM. " CALCOLA-QTA-DA-IMBALLARE
gestione imballo
*&---------------------------------------------------------------------*
*& Form CREA-IMBALLO
*&---------------------------------------------------------------------*
FORM crea-imballo .
DATA:
new_hu TYPE c,
update_db TYPE c,
hu_ref_doc TYPE hum_object,
mm_data LIKE hum_plant_stloc,
* for material_read function and batch check
mtcom_charg LIKE mtcom,
mtcom_mbew LIKE mtcom,
mlvs LIKE mlvs,
mtcor LIKE mtcor,
mtper LIKE mtper,
unpack_hu_ext TYPE hum_exidv_t WITH HEADER LINE,
unpack_hu_int TYPE hum_venum_t WITH HEADER LINE,
hu_header_main TYPE huhdr_prop WITH HEADER LINE,
hu_header_capacity TYPE huhdr_cap WITH HEADER LINE,
hu_header_additional TYPE huhdr_add WITH HEADER LINE,
hu_header_transport TYPE huhdr_tra WITH HEADER LINE,
hu_items_proposal TYPE huitm_prop WITH HEADER LINE,
hu_serial_nr_list TYPE huitem_sernr WITH HEADER LINE,
is_item_proposal TYPE huitm_proposal,
hu_ref_id TYPE vpobjkey,
hu_work_header TYPE hum_hu_header_t WITH HEADER LINE,
hu_work_items TYPE hum_hu_item_t WITH HEADER LINE,
from_hu_id LIKE huitem_from,
hu_unpack_items LIKE huitem_unpack,
hu_messages TYPE huitem_messages_t WITH HEADER LINE,
source_plant LIKE vekp-werks,
source_storage_loc LIKE vekp-lgort,
source_warehouse LIKE lein-lgnum,
source_storage_type LIKE lein-lgtyp,
source_bin_location LIKE lein-lgpla,
destination_plant LIKE vekp-werks,
destination_storage_loc LIKE vekp-lgort,
destination_warehouse LIKE lein-lgnum,
destination_storage_type LIKE lein-lgtyp,
destination_bin_location LIKE lein-lgpla,
mvmt_type LIKE lips-bwlvs,
whs_mgmt_flg TYPE c,
initial_flag TYPE c,
* PREP_SCREEN_FIELDS TYPE PLMOB_PREP_FIELDS,
operation_type(2) TYPE c,
create_hu TYPE c,
hu_activity_type(4) TYPE c,
pack_type(3) TYPE c,
save_step(4) TYPE c,
int_dlvry_type TYPE likp-vbtyp.
DATA: read_mat_im LIKE mard-matnr,
read_ser_nr TYPE mobsernr,
check_hu_flag TYPE c,
hu_for_to LIKE vekp-exidv,
pack_mat_for_to LIKE vekp-vhilm,
hu_to_id LIKE ltak-tanum,
hu_storage_type LIKE ltap-nltyp,
hu_storage_bin LIKE ltap-nlpla,
hu_type LIKE ltap-letyp,
hu_object_type LIKE vekp-vpobj,
hu_object_id LIKE vekp-vpobjkey,
hu_id LIKE rlmob-clenum,
hu_header_prop TYPE huhdr_proposal.
hu_activity_type = 'PACK'.
pack_type = 'MAT'.
update_db = 'X'.
hu_ref_doc-object = '01'.
hu_ref_doc-objkey = likp-vbeln.
save_step = 'HEAD'.
int_dlvry_type = 'J'.
DATA: lt_return LIKE STANDARD TABLE OF bapiret2,
ls_return LIKE LINE OF lt_return,
lv_hukey TYPE bapihukey-hu_exid,
ls_huheader TYPE bapihuheader,
ls_headerproposal TYPE bapihuhdrproposal,
lt_itemproposal TYPE STANDARD TABLE OF bapihuitmproposal,
ls_itemproposal LIKE LINE OF lt_itemproposal.
ls_headerproposal-plant = <divisione>.
ls_headerproposal-stge_loc = <magazzino>.
ls_headerproposal-pack_mat = <materiale imballo>.
* Creazione Imballo
CALL FUNCTION 'BAPI_HU_CREATE'
EXPORTING
headerproposal = ls_headerproposal
IMPORTING
huheader = ls_huheader
hukey = lv_hukey
TABLES
itemsproposal = lt_itemproposal
return = lt_return.
IF lt_return[] IS INITIAL.
CLEAR ls_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = ls_return.
ELSE.
PERFORM get_bapi_error USING lt_return.
ENDIF.
* Imposto il collegamento al documento di spedizione
ls_huheader-pack_mat_object = '01'.
ls_huheader-pack_mat_obj_key = <consegna>.
ls_huheader-salesorg = <org.commerciale>.
REFRESH lt_return.
CALL FUNCTION 'BAPI_HU_CHANGE_HEADER'
EXPORTING
hukey = ls_huheader-hu_exid
huchanged = ls_huheader
IMPORTING
huheader = ls_huheader
TABLES
return = lt_return.
IF lt_return[] IS INITIAL.
CLEAR ls_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = ls_return.
ELSE.
PERFORM get_bapi_error USING lt_return.
ENDIF.
REFRESH hu_items_proposal.
CLEAR is_item_proposal.
CLEAR hu_items_proposal.
hu_header_prop-exidv = lv_hukey.
hu_header_prop-vhilm = <materiale>.
* se trovo una posizione da imballare con la stessa quantità di imballo prendo quella.
LOOP AT pos_da_imb WHERE lfimg = d300-qta_da_imb.
hu_items_proposal-exidv = lv_hukey.
hu_items_proposal-velin = 1.
hu_items_proposal-belnr = likp-vbeln.
hu_items_proposal-posnr = pos_da_imb-posnr.
hu_items_proposal-quantity = pos_da_imb-lfimg.
hu_items_proposal-meins = pos_da_imb-meins.
hu_items_proposal-matnr = wa_matnr_da_imb.
hu_items_proposal-werks = pos_da_imb-werks.
hu_items_proposal-lgort = pos_da_imb-lgort.
APPEND hu_items_proposal.
ENDLOOP.
* Altrimenti: ordino per quantità e procedo con l'imballo fino a completare la qtà da imballare
IF sy-subrc <> 0.
SORT pos_da_imb BY lfimg posnr.
DATA: wa_lfimg LIKE lips-lfimg.
wa_lfimg = d300-qta_da_imb.
LOOP AT pos_da_imb.
IF pos_da_imb-lfimg => wa_lfimg.
hu_items_proposal-quantity = wa_lfimg.
CLEAR wa_lfimg.
ELSE.
hu_items_proposal-quantity = pos_da_imb-lfimg.
wa_lfimg = wa_lfimg - pos_da_imb-lfimg.
ENDIF.
hu_items_proposal-exidv = lv_hukey.
hu_items_proposal-velin = 1.
hu_items_proposal-belnr = likp-vbeln.
hu_items_proposal-posnr = pos_da_imb-posnr.
hu_items_proposal-meins = pos_da_imb-meins.
hu_items_proposal-matnr = wa_matnr_da_imb.
hu_items_proposal-werks = pos_da_imb-werks.
hu_items_proposal-lgort = pos_da_imb-lgort.
APPEND hu_items_proposal.
IF wa_lfimg = 0.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
mm_data-plant = <org.commerciale>.
mm_data-stge_loc = <magazzino>.
hu_activity_type = 'PACK'.
pack_type = 'MAT'.
update_db = 'X'.
create_hu = ' '.
new_hu = 'X'.
save_step = 'HEAD'.
int_dlvry_type = 'J'.
hu_id = ls_huheader-hu_id.
hu_header_prop-exidv = lv_hukey.
DATA: lt_created_hus TYPE STANDARD TABLE OF vekpvb.
CALL FUNCTION 'PROCESS_HU_INBOUND_DLVRY'
EXPORTING
i_packing_activity = hu_activity_type
i_pack_type = pack_type
i_hu_id = hu_id
i_new_hu = new_hu
i_update_db = update_db
i_create_hu = create_hu
i_reference_object = hu_ref_doc
i_mm_data = mm_data
i_hu_header_main = hu_header_prop
i_hu_items = hu_items_proposal[]
i_hu_serial_nr = hu_serial_nr_list[]
i_save_step = save_step
i_pack_activity = pack_type
i_hu_external = unpack_hu_ext[]
i_hu_internal = unpack_hu_int[]
i_delivery_type = int_dlvry_type
is_item_proposal = is_item_proposal
i_unpack_items = hu_unpack_items
i_from_hu = from_hu_id
IMPORTING
o_hu_ref_id = hu_ref_id
o_hu_header = hu_work_header[]
o_hu_items = hu_work_items[]
o_hu_messages = hu_messages[]
TABLES
et_created_hus = lt_created_hus
EXCEPTIONS
input_missing = 01
not_possible = 02
fatal_error = 03
operation_failed = 04
delivery_update_error = 05
error_message = 99.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2
sy-msgv3 sy-msgv4.
LEAVE TO SCREEN '300'.
ELSE.
COMMIT WORK AND WAIT.
WAIT UP TO 1 SECONDS.
PERFORM stampa-odette USING lv_hukey ls_huheader-hu_id.
ENDIF.
ENDFORM. " CREA-IMBALLO
*&---------------------------------------------------------------------*
*& Form STAMPA-ODETTE
*&---------------------------------------------------------------------*
FORM stampa-odette USING p_hukey p_HU_ID.
* stampo messaggi
DATA: l_it_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: l_it_hukey TYPE bapihukey OCCURS 0 WITH HEADER LINE.
DATA: l_it_hukey_copy TYPE bapihukey OCCURS 0 WITH HEADER LINE.
DATA: l_it_outputtype TYPE bapioutptype OCCURS 0 WITH HEADER LINE.
REFRESH: l_it_hukey.
MOVE p_hukey TO l_it_hukey-hu_exid.
APPEND l_it_hukey.
* verifico se esiste il messaggio da stampare
* prima cerco il messaggio Z004
DATA wa_kschl LIKE nast-kschl.
SELECT SINGLE kschl FROM nast INTO wa_kschl
WHERE kappl = 'V6'
AND objky = p_HU_ID
AND kschl = 'Z004'
AND vstat = '0'.
IF sy-subrc <> 0.
SELECT SINGLE kschl FROM nast INTO wa_kschl
WHERE kappl = 'V6'
AND objky = p_HU_ID
AND vstat = '0'.
ENDIF.
CHECK sy-subrc = 0.
REFRESH l_it_outputtype.
MOVE '1' TO l_it_outputtype-trans_medium.
MOVE wa_kschl TO l_it_outputtype-output_type. "tipo messaggio odette
APPEND l_it_outputtype.
CALL FUNCTION 'BAPI_HU_PROCESS_MSG_DIRECT'
* EXPORTING
* DYNAMICOUTPUTDEVICE =
* PROCESSING = 1
* SORTMESSAGE = 1
TABLES
hukey = l_it_hukey
outputtype = l_it_outputtype
* MESSAGEPROTOCOL =
return = l_it_return.
ENDFORM. " STAMPA-ODETTE
Nota: utilizziamo diversi messaggi di stampa, in alcuni casi viene assegnato il tipo Z004 che ha precedenza rispetto agli altri. Per la gestione dell'associazione messaggi usare la transazione VV62.
Nessun commento:
Posta un commento