11-30-2006 12:59 PM
I have 2 tables (t_account and t_item) from the FM. Table t_item has the quantity of items and t_account has the records equating to the item quantity in t_item. Thus t_item will have 1 rec with field quantity = 3, then t_account with have 3 recs with all the relevant data for the assets.
In a scenario where 2 out of 3 items are being receipted. i only need to update my Ztable with just the details for the 2 items and not pull through data from t_accoutn for all items.
Even though i've put in the check to restrict only 2 of 3 items to be updated and not all three. The 3rd item's data is still transferred to the ztable. i'm not sure why its pulling through the 3rd item.
I've attached the code below.
CASE flt_val.
****-- CONFIRMATION --****
WHEN 'BUS2203'.
break ebb1109.
CLEAR: l_header, t_item, t_account, l_item.
get confirmation details
CALL FUNCTION 'BBP_PD_CONF_GETDETAIL'
EXPORTING
i_guid = iv_doc_guid
i_with_itemdata = 'X'
IMPORTING
e_header = l_header
TABLES
e_item = t_item
e_account = t_account.
MOVE l_header-guid TO iv_doc_guid.
IF sy-subrc = 0.
READ TABLE t_item INTO l_item WITH KEY parent = iv_doc_guid.
IF sy-subrc = 0.
check that category_id is in table zbbp_asset_class
SELECT SINGLE * FROM zbbp_asset_class
INTO l_asset
WHERE catid EQ l_item-category_id.
IF sy-subrc = 0.
CLEAR: l_account, wa_serial_upd, it_serial_upd, t_serial, cnt.
LOOP AT t_account INTO l_account WHERE p_guid = l_item-guid
AND acc_cat = 'AS'.
check that asset_no is not already updated to table zbbp_serial_upd
SELECT SINGLE * FROM zbbp_serial_upd
INTO CORRESPONDING FIELDS OF wa_serial_upd
WHERE assetmst EQ l_account-asset_no
AND acc_no EQ l_account-acc_no.
if not then start mapping data for later use.
IF sy-subrc <> 0.
MOVE: l_account-asset_no TO wa_serial_upd-assetmst,
l_account-acc_no TO wa_serial_upd-acc_no,
l_header-object_id TO wa_serial_upd-confirm_no,
l_item-be_refobj TO wa_serial_upd-po_num,
l_item-be_refobj_item TO wa_serial_upd-po_itemno.
ADD 1 TO cnt.
if the number of records exceed the number of items then exit
IF cnt > l_item-quantity.
CLEAR: wa_serial_upd, l_account.
EXIT.
ELSE.
else update internal table it_serial_upd
APPEND wa_serial_upd TO it_serial_upd.
CLEAR: wa_serial_upd, l_account.
ENDIF.
ENDIF.
ENDLOOP.
CLEAR: l_serial, wa_serial_upd, fieldname, cnt.
LOOP AT it_serial_upd INTO wa_serial_upd.
ADD 1 TO num.
IF num > 50.
CLEAR: l_account, wa_serial_upd.
EXIT.
ENDIF.
get serial number from table l_item, and map to relevant record
SHIFT num LEFT DELETING LEADING '0'.
CONCATENATE 'L_ITEM-ZZSERNR'
num INTO fieldname.
ASSIGN (fieldname) TO <fs>.
MOVE: <fs> TO wa_serial_upd-serial_num.
update internal table it_serial_upd with serial numbers
MODIFY it_serial_upd FROM wa_serial_upd INDEX sy-tabix.
CLEAR: wa_serial_upd .
ENDLOOP.
break ebb1109.
transfer data to z table.
CLEAR wa_serial_upd.
LOOP AT it_serial_upd INTO wa_serial_upd
WHERE serial_num IS NOT INITIAL .
INSERT INTO zbbp_serial_upd VALUES wa_serial_upd .
CLEAR wa_serial_upd.
ENDLOOP.
CLEAR: it_serial_upd, wa_serial_upd.
ENDIF.
ENDIF.
ENDIF.
ENDCASE.
11-30-2006 1:10 PM
ur final internal tale is having all 3 records...u need to check some condition and delete the record from this final table so that only the 2 entries are inserted into table.
11-30-2006 2:21 PM
Hi Ramesh,
I'm not sure which itab you are referring to. I've debugged through the code - and even just before i insert records to my ztable i have to 2 recs in the itab.
Thanks
Chris.
11-30-2006 1:13 PM
Hey Christine,
Can u tell me at what point in ur code u are doing the following restriction. So that we can check that condition.
<b>Even though i've put in the check to restrict only 2 of 3 items to be updated and not all three. The 3rd item's data is still transferred to the ztable. i'm not sure why its pulling through the 3rd item.</b>
Regards,
Jayaram...
11-30-2006 1:24 PM
Hi Jayaram,
I'm doing the check when within my first loop as i loop through table t_account. Thus i'll only pick up the number of recods equivallent to the items i'm receipting to later update my ztable.
ADD 1 TO cnt.
if the number of records exceed the number of items then exit
IF cnt > l_item-quantity.
CLEAR: wa_serial_upd, l_account.
EXIT.
Thanks
Chrs.
11-30-2006 1:40 PM
Hi Chris,
Try with the following code. Ur code will check for the no of records greater than the quantity items. but not less than that.
ADD 1 TO cnt.
if the number of records exceed the number of items then exit
IF cnt = l_item-quantity-1.
CLEAR: wa_serial_upd, l_account.
EXIT.
Reward if helpful..
Regards,
Jayaram..
11-30-2006 2:16 PM
Hi Jayaram,
The code doesn't work this way. E.g If l_item-quantity = 3, and i'm only receipting 2 times - the FM automatically reads my receipt quantity and sets l_item-quantity = 2 . i don't need to further reduce my l_item-quantity.
I manage to pick up the right amount of records with my original code, only that it updates my ztable with recods that were not even passed to my itab in the first place.
Ta
Chris.
Message was edited by:
Christine Masipa
02-15-2007 11:12 AM
Split the process into different BADIs:-
1. Change
2. Check
3. Update