0% found this document useful (0 votes)
908 views

Create PO Service Line Using BAPI

This document provides a report to demonstrate using BAPI to create a new service line in a purchase order. It selects purchase order header and item data, calls the BAPI_PO_GETDETAIL1 and BAPI_PO_CHANGE functions to retrieve and update the data, and displays any error messages. Temporary internal tables are used to transfer data between the different BAPI functions and database tables.

Uploaded by

Marius Ursache
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
908 views

Create PO Service Line Using BAPI

This document provides a report to demonstrate using BAPI to create a new service line in a purchase order. It selects purchase order header and item data, calls the BAPI_PO_GETDETAIL1 and BAPI_PO_CHANGE functions to retrieve and update the data, and displays any error messages. Temporary internal tables are used to transfer data between the different BAPI functions and database tables.

Uploaded by

Marius Ursache
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

*--------------------------------------------------------------------*

*--------------------------------------------------------------------*
* 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: ucomm TYPE sy-ucomm.

DATA: itsad3t LIKE tsad3t.


DATA: errors TYPE szadr_error_table.

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.

DATA: wa_ext TYPE bapi_te_mepoheader,


wa_extx TYPE bapi_te_mepoheaderx.

DATA: ebeln LIKE ekko-ebeln.


DATA: ebelp LIKE ekpo-ebelp.
DATA: message(150).

DATA: it_msg TYPE esp1_message_tab_type,


wa_msg TYPE LINE OF esp1_message_tab_type.

DATA: wa_lfa1 LIKE lfa1,


xcpds LIKE t077k-xcpds.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME.


SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.
SELECTION-SCREEN: END OF BLOCK b1.

START-OF-SELECTION.

IF s_ebeln IS INITIAL.
MESSAGE 'Enter Po Number' TYPE 'E'.
ENDIF.

SELECT * FROM ekko INTO TABLE it_ekko


WHERE ebeln IN s_ebeln.

SELECT * FROM ekpo INTO TABLE it_ekpo


WHERE ebeln IN s_ebeln AND
loekz = ' '.

SELECT * FROM esll INTO TABLE it_esll


FOR ALL ENTRIES IN it_ekpo
WHERE packno = it_ekpo-packno AND
del = ''.

IF it_esll[] IS NOT INITIAL.


SELECT * FROM esll INTO TABLE it_esll1
FOR ALL ENTRIES IN it_esll
WHERE packno = it_esll-sub_packno.

SELECT * FROM eskl INTO TABLE it_eskl


FOR ALL ENTRIES IN it_esll
WHERE packno = it_esll-sub_packno.
ENDIF.

SELECT * FROM ekkn INTO TABLE it_ekkn WHERE ebeln IN s_ebeln.

FIELD-SYMBOLS: <fs_esll> LIKE wa_esll1.

DATA:pack_no TYPE ekpo-packno,


index TYPE i,
val TYPE esll-menge,
lv_introw TYPE esll-introw,
lv_extrow TYPE esll-extrow.

SORT it_ekko BY ebeln.


SORT it_ekpo BY ebeln ebelp.
CLEAR: wa_ekko.
LOOP AT it_ekko INTO wa_ekko.

CALL FUNCTION 'BAPI_PO_GETDETAIL1'


EXPORTING
purchaseorder = wa_ekko-ebeln
account_assignment = 'X'
item_text = 'X'
header_text = 'X'
services = 'X'
IMPORTING
poheader = poheader
* poexpimpheader = poexpimpheader
TABLES
return = it_return
poitem = it_poitem
poschedule = it_poschedule
poaccount = it_poaccount
poservices = it_poservices
posrvaccessvalues = it_posrvaccessvalues.

PERFORM fill_header_data. "ekko data passing here


DELETE: it_poitem WHERE delete_ind = 'L',
it_esll1 WHERE del = 'X'.
gt_esll1 = it_esll1.
SORT: it_poaccount[] DESCENDING,
gt_esll1[] DESCENDING.

LOOP AT it_poitem INTO wa_poitem .


PERFORM fill_item.
READ TABLE it_esll INTO wa_esll WITH KEY packno = wa_poitem-pckg_no." parent package number
IF sy-subrc = 0.
LOOP AT it_esll1 INTO wa_esll1 WHERE packno = wa_esll-sub_packno." childeren package numbe
IF wa_esll1-act_menge NE 0.
IF wa_esll1-menge GT wa_esll1-act_menge.
val = wa_esll1-menge - wa_esll1-act_menge.
PERFORM fill_po_data_new_bapi .
ENDIF.
ENDIF.
CLEAR: wa_esll1,val.
ENDLOOP.
CLEAR: wa_esll1, lv_introw,lv_extrow,wa_poitem.
ENDIF.
ENDLOOP.

IF poitem[] IS NOT INITIAL AND it_povalues[] IS NOT INITIAL.

CALL FUNCTION 'BAPI_PO_CHANGE'


EXPORTING
purchaseorder = wa_ekko-ebeln
poheader = poheader
poheaderx = poheaderx
TABLES
return = return[]
poitem = poitem[]
poitemx = poitemx[]
poaccount = poaccount[]
poaccountx = poaccountx[]
poservices = po_service[]
posrvaccessvalues = it_povalues[].

WAIT UP TO 2 SECONDS.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

DELETE return WHERE type = 'I'.


DELETE return WHERE type = 'W'.
CLEAR: wa_msg, it_msg[].

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.

CALL FUNCTION 'C14Z_MESSAGES_SHOW_AS_POPUP'


TABLES
i_message_tab = it_msg[].

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 .

DATA : l_date TYPE sy-datum.


DATA: wa_poschedule TYPE bapimeposchedule,
lv_count TYPE ekkn-zekkn.

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.

*** child informatioon


po_service-pckg_no = wa_esll1-packno.
po_service-line_no = wa_esll1-introw.
po_service-ext_line = wa_esll1-extrow.
po_service-service = wa_esll1-srvpos.
po_service-short_text = wa_esll1-ktext1.
po_service-subpckg_no = wa_esll1-sub_packno.
po_service-quantity = wa_esll1-act_menge. "actaul quanitiy
po_service-base_uom = wa_esll1-meins.
po_service-price_unit = wa_esll1-peinh.
po_service-gr_price = wa_esll1-netwr.
po_service-matl_group = wa_esll1-matkl.
po_service-tax_code = wa_esll1-mwskz.

APPEND po_service.
CLEAR po_service.

****New entry will be created with derived quantity as child entry


CLEAR: gw_esll1.

READ TABLE gt_esll1 INTO gw_esll1 WITH KEY packno = wa_esll-sub_packno.


IF sy-subrc = 0.
IF lv_introw IS NOT INITIAL AND lv_extrow IS NOT INITIAL.
lv_introw = lv_introw + 1.
lv_extrow = lv_extrow + 10.
ELSE.
lv_introw = gw_esll1-introw + 1.
lv_extrow = gw_esll1-extrow + 10.
ENDIF.
po_service-pckg_no = wa_esll1-packno.
po_service-line_no = lv_introw." new internal number used for account assignment category an
po_service-ext_line = lv_extrow.
po_service-service = wa_esll1-srvpos.
po_service-short_text = wa_esll1-ktext1.
po_service-subpckg_no = wa_esll1-sub_packno.
po_service-quantity = val. "Calculated/Derived quanitiy
po_service-base_uom = wa_esll1-meins.
po_service-price_unit = wa_esll1-peinh.
po_service-gr_price = wa_esll1-netwr.
po_service-matl_group = wa_esll1-matkl.
po_service-tax_code = wa_esll1-mwskz.

APPEND po_service.
CLEAR po_service.

*** poaccount structure details


CLEAR: wa_eskl, wa_ekkn.

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.

IF wa_ekkn-gsber IS NOT INITIAL.


poaccount-bus_area = wa_ekkn-gsber.
poaccountx-bus_area = 'X'.
ENDIF.
IF wa_ekkn-kostl IS NOT INITIAL.
poaccount-costcenter = wa_ekkn-kostl.
poaccountx-costcenter = 'X'.
ENDIF.
IF wa_ekkn-kokrs IS NOT INITIAL.
poaccount-co_area = wa_ekkn-kokrs.
poaccountx-co_area = 'X'.
ENDIF.
IF wa_ekkn-prctr IS NOT INITIAL.
poaccount-profit_ctr = wa_ekkn-prctr.
poaccountx-profit_ctr = 'X'.
ENDIF.
IF wa_ekkn-nplnr IS NOT INITIAL.
poaccount-network = wa_ekkn-nplnr.
poaccountx-network = 'X'.
DATA: aplzl TYPE afvc-aplzl,
aufpl TYPE afvc-aufpl,
nplnr TYPE ekkn-nplnr,
vornr TYPE afvc-vornr.

MOVE wa_ekkn-aplzl TO aplzl.


MOVE wa_ekkn-aufpl TO aufpl.

CALL FUNCTION 'READ_NETWORK_NPLNR_VORNR'


EXPORTING
aplzl = aplzl
aufpl = aufpl
* VSNMR =
IMPORTING
nplnr = nplnr
vornr = vornr
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
IF nplnr = wa_ekkn-nplnr.
MOVE vornr TO poaccount-activity.
ENDIF.
ENDIF.
poaccountx-activity = 'X'.
ENDIF.
IF wa_ekkn-aufnr IS NOT INITIAL.
poaccount-orderid = wa_ekkn-aufnr.
poaccountx-orderid = 'X'.
ENDIF.
IF wa_ekkn-ps_psp_pnr IS NOT INITIAL.
poaccountx-wbs_element = wa_ekkn-ps_psp_pnr.
poaccountx-wbs_element = 'X'.
ENDIF.
APPEND poaccount.
CLEAR poaccount.

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.

ENDFORM. " FILL_PO_DATA_NEW_BAPI


" GET_PO_TEXT
*&---------------------------------------------------------------------*
*& Form FILL_HEADER_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_header_data .

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.

**** PO itemX structure details


poitemx-po_item = wa_poitem-po_item.
poitemx-po_itemx = 'X'.
poitemx-item_cat = 'X'.
poitemx-acctasscat = 'X'.
poitemx-quantity = 'X'.
poitemx-pckg_no = 'X'.
* poitemx-po_price = 'X'.
APPEND poitemx.
CLEAR poitemx.

CLEAR: wa_poservices.
ENDFORM. " FILL_ITEM

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy