Skip to Content
0
Former Member
Nov 30, 2006 at 12:59 PM

Inserting data to ZTable

19 Views

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.