Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI for LI14, and LI20

Former Member
0 Kudos

hi folks,

i had a requirement where in i need to display the ALV list and from there the user can select/ deselct particular records and post in LI14(all selected records) and LI20 (unchecked records).

i want to know , is there any BAPI existing for LI14 & LI20,if no bapi is existing how can i handle this situation?

points will be rewarded for helpful hints

thanks

5 REPLIES 5

Former Member
0 Kudos

Hi,

If there is no BAPI you can go ahead and create a BDC recording and use it in you program.

Or simply you can call the transaction itself using <b>call transaction</b> statement

get all the data from ALV and loop at internal table to post data in call transaction statement.

0 Kudos

thanks for ur response sandeep,

i want to know is there any BAPi for LI14/Li20..?

however ur reply helpedme ...

cheers

0 Kudos

I dont think there is any BAPI for this

you can check this function module.

IVIEW_SM_INV_RECOUNT

see if this helps you.

0 Kudos

hi sanddep,

i couldnt find the FM 'IVIEW_SM_INV_RECOUNT' , r u sure is that the FM?

0 Kudos

Hi,

I have checked this in 4.6C and 4.7.

On both the version this function module exists.

check this code .

FUNCTION IVIEW_SM_INV_RECOUNT.

*"----


""Local interface:

*" TABLES

*" IT_ITEM_POST STRUCTURE IVIEW_SM_INV_COUNT_ITEMLIST

*" ET_RETURN STRUCTURE BAPIRET2

*"----


*This function is used by the Inventory Count IView to recount a

*document item (via a RFC call) as it is done in R/3 with transaction

*MI11 (Recount).

*The item table will be updated to return only the new document item.

*Any error will be send back to the IView via the Return table.

data: ls_iseg like iseg,

ls_ikpf like ikpf,

ls_mard like mard,

ls_mchb like mchb,

ls_msku like msku.

data: lt_post_item type gt_iview_count_list,

ls_post_item type iview_sm_inv_count_itemlist,

lt_save_item type gt_iview_count_list,

ls_save_item type iview_sm_inv_count_itemlist.

data: ls_head type BAPI_PHYSINV_HEAD,

lt_items type table of BAPI_PHYSINV_ITEM,

ls_items type BAPI_PHYSINV_ITEM,

ls_new_head type BAPI_PHYSINV_CREATE_HEAD,

ls_new_items type BAPI_PHYSINV_CREATE_ITEMS,

lt_new_items type table of BAPI_PHYSINV_CREATE_ITEMS.

data: l_nblnr type IBLNR,

l_dmbtr type difwr,

lv_error type c.

data: ls_return type bapiret2,

lt_return type table of BAPIRET2,

ls_item type iview_sm_inv_count_itemlist.

  • Copy input table.

*----


loop at it_item_post INTO ls_save_item.

append ls_save_item to lt_save_item.

endloop.

  • I. Read entry

*----


loop at lt_save_item INTO ls_save_item.

  • II. Check document

*----


refresh: lt_items, lt_return. clear: ls_head, ls_return.

CALL FUNCTION 'BAPI_MATPHYSINV_GETDETAIL'

EXPORTING

PHYSINVENTORY = ls_save_item-physinventory

FISCALYEAR = ls_save_item-FISCALYEAR

IMPORTING

HEAD = ls_head

TABLES

ITEMS = lt_items

RETURN = lt_return.

loop at lt_return into ls_return.

append ls_return to et_return.

endloop.

  • Document not found

read table lt_return into ls_return with key type = 'E'.

if sy-subrc is initial.

perform message_to_bapiret2 TABLES et_return

using 'M7' 'E' '810' ls_save_item-physinventory ' ' ' ' ' '.

exit.

endif.

  • Item not found

read table lt_items into ls_items with key item = ls_save_item-item.

if not sy-subrc is initial.

perform message_to_bapiret2 TABLES et_return

using 'M7' 'E' '551' ls_save_item-item ' ' ' ' ' '.

exit.

endif.

  • Check document

Perform Check_document tables et_return

using ls_save_item ls_iseg ls_ikpf.

read table et_return into ls_return with key type = 'E'.

if sy-subrc is initial.

exit.

endif.

  • III. Recount item.

  • Calculate difference

clear l_dmbtr.

  • Perform Calculate_diff_amount using ls_head ls_items

  • ls_iseg ls_return.

  • l_dmbtr = ls_iseg-dmbtr.

  • Desactivate item

if ls_head-SPEC_STOCK ne 'W'.

if ls_items-BATCH is initial.

select single * from mard into ls_mard where

matnr = ls_items-material and werks = ls_head-plant

and lgort = ls_head-stge_loc.

if sy-subrc is initial.

clear: ls_mard-sperr, ls_mard-kzill.

update mard from ls_mard.

else.

exit.

endif.

else.

select single * from mchb into ls_mchb where

matnr = ls_items-material and werks = ls_head-plant

and lgort = ls_head-stge_loc and charg = ls_items-BATCH.

if sy-subrc is initial.

clear: ls_mchb-sperc, ls_mchb-kzicl.

update mchb from ls_mchb.

else.

exit.

endif.

endif.

else. " consignement stock

if ls_items-BATCH is initial.

select single * from msku into ls_msku where

matnr = ls_items-material and werks = ls_head-plant

and SOBKZ = ls_items-SPEC_STOCK

and KUNNR = ls_items-customer. "#EC *

if sy-subrc is initial.

clear: ls_msku-kuspr, ls_msku-kuill(2).

update msku from ls_msku.

else.

exit.

endif.

else.

select single * from msku into ls_msku where

matnr = ls_items-material and werks = ls_head-plant

and CHARG = ls_items-BATCH and SOBKZ = ls_items-SPEC_STOCK

and KUNNR = ls_items-customer.

if sy-subrc is initial.

clear: ls_msku-kuspr, ls_msku-kuill(2).

update msku from ls_msku.

else.

exit.

endif.

endif.

endif.

commit work and wait.

  • Create a new document

refresh lt_new_items.

read table lt_items into ls_items with key item = ls_save_item-item.

move-corresponding ls_head to ls_new_head.

move-corresponding ls_items to ls_new_items.

append ls_new_items to lt_new_items.

refresh lt_return.

CALL FUNCTION 'BAPI_MATPHYSINV_CREATE_MULT'

EXPORTING

HEAD = ls_new_head

TABLES

ITEMS = lt_new_items

RETURN = lt_return.

clear lv_error.

loop at lt_return into ls_return.

  • Clear one of the duplicate entry

collect ls_return into et_return.

if ls_return-type = 'E'.

lv_error = 'X'.

elseif ls_return-type = 'S' and ls_return-id = 'M7'

and ls_return-number = '710'.

l_nblnr = ls_return-message_v1.

shift l_nblnr right deleting trailing space.

overlay l_nblnr with '0000000000'.

endif.

endloop.

if lv_error = 'X'. exit. endif.

  • Post document if no more open items

loop at lt_items into ls_items where diff_posted = ' '

and recount = ' ' and delete_ind = ' '

and item ne ls_save_item-item.

endloop.

if not sy-subrc is initial.

ls_IKPF-DSTAT = 'X'.

ls_ikpf-bldat = sy-datum.

ls_ikpf-gidat = sy-datum.

update IKPF from ls_Ikpf.

commit work and wait.

endif.

  • Set item status to recounted

Select single * from ISEG into ls_iseg

where IBLNR = ls_save_item-physinventory

and ZEILI = ls_save_item-item

and GJAHR = ls_save_item-FISCALYEAR.

  • add the number of the new pi-document into the old document

ls_ISEG-XNZAE = 'X'.

ls_iseg-nblnr = l_nblnr.

ls_iseg-dmbtr = l_dmbtr.

update ISEG from ls_Iseg.

commit work and wait.

  • set the event type of the new document to recount (IN)

select single * from IKPF into ls_IKPF where iblnr = l_nblnr.

ls_ikpf-VGART = 'IN'.

update IKPF from ls_Ikpf.

commit work and wait.

  • Update return table with the new document

delete table it_item_post from ls_save_item.

ls_save_item-physinventory = ls_iseg-nblnr.

ls_save_item-item = ls_iseg-zeili.

clear ls_save_item-count_date.

clear ls_save_item-entry_qnt.

clear ls_save_item-quantity.

append ls_save_item to it_item_post.

endloop.

ENDFUNCTION.