Professional Documents
Culture Documents
Create PO Service Line Using BAPI
Create PO Service Line Using BAPI
*--------------------------------------------------------------------*
* Created by: Mahesh Atmakuri ( www.sapyard.com )
* Demo Report to show how to use BAPI to create New Servcie Line
* 'BAPI_PO_CHANGE' Table POSERVICES
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
REPORT zbapi_po_change_serv_po
NO STANDARD PAGE HEADING LINE-SIZE 255.
TABLES: addr1_data,sza1_d0100,ekko.
DATA:
it_ekko LIKE TABLE OF ekko,
wa_ekko LIKE ekko,
it_ekpo LIKE TABLE OF ekpo,
wa_ekpo LIKE ekpo,
it_ekkn LIKE TABLE OF ekkn,
wa_ekkn LIKE ekkn,
it_eket LIKE TABLE OF eket,
wa_eket LIKE eket,
it_esll LIKE TABLE OF esll,
wa_esll LIKE esll,
it_esll1 LIKE TABLE OF esll,
gt_esll1 LIKE TABLE OF esll,
wa_esll1 LIKE esll,
gw_esll1 LIKE esll,
it_eskl LIKE TABLE OF eskl,
wa_eskl LIKE eskl,
it_t007s LIKE TABLE OF t007s,
wa_t007s LIKE t007s.
* it_data like table of zipr_data,
* wa_data like zipr_data.
DATA:
po_service LIKE TABLE OF bapiesllc WITH HEADER LINE,
it_povalues LIKE TABLE OF bapiesklc WITH HEADER LINE,
potext LIKE TABLE OF bapimepotextheader WITH HEADER LINE.
DATA: poheader LIKE bapimepoheader,
poheaderx LIKE bapimepoheaderx,
return LIKE TABLE OF bapiret2 WITH HEADER LINE,
it_return LIKE TABLE OF bapiret2 WITH HEADER LINE,
poitem LIKE TABLE OF bapimepoitem WITH HEADER LINE,
it_poitem LIKE TABLE OF bapimepoitem,
wa_poitem LIKE bapimepoitem,
poitemx LIKE TABLE OF bapimepoitemx WITH HEADER LINE,
it_poschedule LIKE TABLE OF bapimeposchedule WITH HEADER LINE,
poschedule LIKE TABLE OF bapimeposchedule WITH HEADER LINE,
poschedulex LIKE TABLE OF bapimeposchedulx WITH HEADER LINE,
it_poaccount LIKE TABLE OF bapimepoaccount WITH HEADER LINE,
poaccount LIKE TABLE OF bapimepoaccount WITH HEADER LINE,
wa_poaccount TYPE bapimepoaccount,
poaccountx LIKE TABLE OF bapimepoaccountx WITH HEADER LINE,
it_poservices LIKE TABLE OF bapiesllc WITH HEADER LINE,
wa_poservices TYPE bapiesllc,
it_posrvaccessvalues LIKE TABLE OF bapiesklc WITH HEADER LINE.
START-OF-SELECTION.
IF s_ebeln IS INITIAL.
MESSAGE 'Enter Po Number' TYPE 'E'.
ENDIF.
WAIT UP TO 2 SECONDS.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
LOOP AT return .
IF return-type = 'E' OR return-type = 'S' .
wa_msg-msgid = return-id.
wa_msg-msgty = return-type.
wa_msg-msgno = return-number.
wa_msg-msgv1 = return-message_v1.
wa_msg-msgv2 = return-message_v2.
wa_msg-msgv3 = return-message_v3.
wa_msg-msgv4 = return-message_v4.
APPEND wa_msg TO it_msg.
CLEAR: wa_msg.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR: wa_ekpo,wa_ekko,poheader,poheaderx,ebeln,return,return[],potext,potext[],
poitem, poitem[],poitemx,poitemx[],poschedule,poschedule[],poschedulex,poschedulex[],
poaccount,poaccount[],poaccountx,poaccountx[],po_service,po_service[],it_povalues,it_pov
REFRESH:return[],
it_poitem[],
it_poschedule[],
it_poaccount[],
it_poservices[],
it_posrvaccessvalues[].
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form FILL_PO_DATA_NEW_BAPI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_po_data_new_bapi .
IF lv_introw IS INITIAL.
** Parent information
po_service-pckg_no = wa_esll-packno.
po_service-line_no = wa_esll-introw.
po_service-ext_line = '0000000000'.
po_service-outl_level = 0.
po_service-outl_ind = 'X'.
po_service-subpckg_no = wa_esll-sub_packno.
po_service-from_line = 1.
APPEND po_service.
CLEAR po_service.
ENDIF.
APPEND po_service.
CLEAR po_service.
APPEND po_service.
CLEAR po_service.
READ TABLE it_eskl INTO wa_eskl WITH KEY packno = wa_esll-sub_packno introw = wa_esll1-introw.
IF sy-subrc = 0.
READ TABLE it_ekkn INTO wa_ekkn WITH KEY ebeln = wa_ekko-ebeln ebelp = wa_poitem-po_item zekk
IF sy-subrc = 0. " This statement used for get the selected record gl details and order id an
poaccount-po_item = wa_poitem-po_item.
poaccount-serial_no = wa_ekkn-zekkn.
poaccount-quantity = val.
poaccount-gl_account = wa_ekkn-sakto.
poaccountx-po_item = wa_poitem-po_item.
poaccountx-serial_no = wa_ekkn-zekkn.
poaccountx-po_itemx = 'X'.
poaccountx-serial_nox = 'X'.
poaccountx-quantity = 'X'.
poaccountx-gl_account = 'X'.
APPEND poaccountx.
CLEAR poaccountx.
ENDIF.
it_povalues-pckg_no = wa_eskl-packno.
it_povalues-line_no = wa_esll1-introw.
it_povalues-serno_line = 01.
it_povalues-serial_no = wa_eskl-zekkn.
it_povalues-quantity = val.
APPEND it_povalues.
CLEAR it_povalues.
it_povalues-pckg_no = wa_eskl-packno.
it_povalues-line_no = lv_introw.
it_povalues-serno_line = 01.
it_povalues-serial_no = wa_eskl-zekkn.
it_povalues-quantity = val.
APPEND it_povalues.
CLEAR it_povalues.
ENDIF.
ENDIF.
CLEAR: wa_esll1, poitem,wa_poaccount.
CLEAR: poheader.
poheader-po_number = wa_ekko-ebeln.
poheader-currency = wa_ekko-waers.
poheader-created_by = sy-uname.
poheader-doc_date = sy-datum.
poheader-doc_type = wa_ekko-bsart.
poheader-purch_org = wa_ekko-ekorg.
poheader-pur_group = wa_ekko-ekgrp.
poheader-comp_code = wa_ekko-bukrs.
poheader-pmnttrms = wa_ekko-zterm.
poheader-vendor = wa_ekko-lifnr.
poheader-item_intvl = '00010'.
poheaderx-currency = 'X'.
poheaderx-created_by = 'X'.
poheaderx-doc_date = 'X'.
poheaderx-doc_type = 'X'.
poheaderx-purch_org = 'X'.
poheaderx-pur_group = 'X'.
poheaderx-vendor = 'X'.
poheaderx-pmnttrms = 'X'.
poheaderx-comp_code = 'X'.
poheaderx-item_intvl = 'X'.
ENDFORM. " FILL_HEADER_DATA
*&---------------------------------------------------------------------*
*& Form FILL_ITEM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_item .
**** PO item structure details
poitem-po_item = wa_poitem-po_item.
poitem-item_cat = wa_poitem-item_cat.
poitem-acctasscat = wa_poitem-acctasscat.
poitem-quantity = wa_poitem-quantity.
poitem-pckg_no = wa_poitem-pckg_no.
* poitem-po_price = '2'.
APPEND poitem.
**CLEAR poitem.
CLEAR: wa_poservices.
ENDFORM. " FILL_ITEM