Dear Experts
I am getting error while creating Service PO using BAPI
E 518
No account assignment exists for service line 0000000010
E 518
No account assignment exists for service line 0000000010
TYPES : BEGIN OF ty_header,
po_no(10) TYPE n,
purch_org TYPE bapimepoheader-purch_org,
pur_group TYPE bapimepoheader-pur_group,
doc_type TYPE bapimepoheader-doc_type,
vendor TYPE bapimepoheader-vendor,
doc_date TYPE bapimepoheader-doc_date,
currency TYPE bapimepoheader-currency,
comp_code TYPE bapimepoheader-comp_code,
END OF ty_header,
BEGIN OF ty_item,
po_no(10) TYPE n, " Internal Use
po_item TYPE bapimepoitem-po_item,
acctasscat TYPE bapimepoitem-acctasscat,
short_text TYPE bapimepoitem-short_text,
plant TYPE bapimepoitem-plant,
pckg_no TYPE bapimepoitem-pckg_no,
stge_loc TYPE bapimepoitem-stge_loc,
quantity TYPE bapimepoitem-quantity,
po_unit TYPE bapimepoitem-po_unit,
po_price TYPE bapimepoitem-po_price,
net_price TYPE bapimepoitem-net_price,
price_unit TYPE bapimepoitem-price_unit,
orderpr_un TYPE bapimepoitem-orderpr_un,
delivery_date TYPE bapimeposchedule-delivery_date, " bapimeposchedule
matl_group TYPE bapimepoitem-matl_group,
tax_code TYPE bapimepoitem-tax_code,
END OF ty_item,
BEGIN OF ty_service,
po_no(10) TYPE n, " Internal Use
po_item TYPE bapimepoitem-po_item, " Internal Use
pckg_no TYPE bapiesllc-pckg_no,
line_no TYPE bapiesllc-line_no,
ext_line TYPE bapiesllc-ext_line,
outl_ind TYPE bapiesllc-outl_ind,
subpckg_no TYPE bapiesllc-subpckg_no,
serial_no TYPE bapiesklc-serial_no, " bapiesklc
short_text TYPE bapiesllc-short_text,
quantity TYPE bapiesllc-quantity,
base_uom TYPE bapiesllc-base_uom,
gr_price TYPE bapiesllc-gr_price,
matl_group TYPE bapiesllc-matl_group,
END OF ty_service,
BEGIN OF ty_poaccount,
po_no(10) TYPE n, " Internal Use
po_item TYPE bapimepoaccount-po_item,
serial_no TYPE bapimepoaccount-serial_no,
gl_account TYPE bapimepoaccount-gl_account,
costcenter TYPE bapimepoaccount-costcenter,
asset_no TYPE bapimepoaccount-asset_no,
orderid TYPE bapimepoaccount-orderid,
END OF ty_poaccount.
DATA : it_header TYPE TABLE OF ty_header,
wa_header TYPE ty_header,
it_item TYPE TABLE OF ty_item,
wa_item TYPE ty_item,
it_service TYPE TABLE OF ty_service,
wa_service TYPE ty_service,
it_account TYPE TABLE OF ty_poaccount,
wa_account TYPE ty_poaccount.
DATA : it_excel1 TYPE TABLE OF alsmex_tabline,
wa_excel1 TYPE alsmex_tabline,
it_excel2 TYPE TABLE OF alsmex_tabline,
wa_excel2 TYPE alsmex_tabline,
it_excel3 TYPE TABLE OF alsmex_tabline,
wa_excel3 TYPE alsmex_tabline,
it_excel4 TYPE TABLE OF alsmex_tabline,
wa_excel4 TYPE alsmex_tabline.
DATA : number TYPE string,
number1 TYPE string.
********** BAPI**************
CONSTANTS : c_x VALUE 'X'.
*Structures to hold PO header data
DATA : header LIKE bapimepoheader ,
headerx LIKE bapimepoheaderx .
*Internal Tables to hold PO ITEM DATA
DATA : item LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
itemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE.
*Structures to hold PO schedule data
DATA : itemschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE ,
itemschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE .
*Structures to hold PO services data
DATA : services LIKE bapiesllc OCCURS 0 WITH HEADER LINE .
*Structures to hold PO (distrib.imputac.lín.servicios) data
DATA : posrvaccessvalues LIKE bapiesklc OCCURS 0 WITH HEADER LINE .
*Structures to hold PO account data
DATA : account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE ,
accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE .
*Internal table to hold messages from BAPI call
DATA : return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
purchaseorder LIKE bapimepoheader-po_number.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_file1 TYPE rlgrap-filename OBLIGATORY,
p_brow1 TYPE i,
p_erow1 TYPE i.
SELECTION-SCREEN : END OF BLOCK b1.
SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : p_file2 TYPE rlgrap-filename OBLIGATORY,
p_brow2 TYPE i,
p_erow2 TYPE i.
SELECTION-SCREEN : END OF BLOCK b2.
SELECTION-SCREEN : BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS : p_file3 TYPE rlgrap-filename OBLIGATORY,
p_brow3 TYPE i,
p_erow3 TYPE i.
SELECTION-SCREEN : END OF BLOCK b3.
SELECTION-SCREEN : BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS : p_file4 TYPE rlgrap-filename OBLIGATORY,
p_brow4 TYPE i,
p_erow4 TYPE i.
SELECTION-SCREEN : END OF BLOCK b4.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file2.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file3.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file3.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file4.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file4.
START-OF-SELECTION.
PERFORM excel_to_itab.
PERFORM get_final.
*&---------------------------------------------------------------------*
*& Form excel_to_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM excel_to_itab .
************** Excel 1
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file1
i_begin_col = '1'
i_begin_row = p_brow1
i_end_col = '08'
i_end_row = p_erow1
TABLES
intern = it_excel1
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_excel1 INTO wa_excel1.
CASE wa_excel1-col.
WHEN '0001'.
wa_header-po_no = wa_excel1-value.
WHEN '0002'.
wa_header-purch_org = wa_excel1-value.
WHEN '0003'.
wa_header-pur_group = wa_excel1-value.
WHEN '0004'.
wa_header-doc_type = wa_excel1-value.
WHEN '0005'.
wa_header-vendor = wa_excel1-value.
WHEN '0006'.
wa_header-doc_date = wa_excel1-value.
WHEN '0007'.
wa_header-currency = wa_excel1-value.
WHEN '0008'.
wa_header-comp_code = wa_excel1-value.
ENDCASE.
AT END OF row.
APPEND wa_header TO it_header.
CLEAR wa_header.
ENDAT.
ENDLOOP.
************** Excel 2
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file2
i_begin_col = '1'
i_begin_row = p_brow2
i_end_col = '16'
i_end_row = p_erow2
TABLES
intern = it_excel2
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_excel2 INTO wa_excel2.
CASE wa_excel2-col.
WHEN '0001'.
wa_item-po_no = wa_excel2-value.
WHEN '0002'.
wa_item-po_item = wa_excel2-value.
WHEN '0003'.
wa_item-acctasscat = wa_excel2-value.
WHEN '0004'.
wa_item-short_text = wa_excel2-value.
WHEN '0005'.
wa_item-plant = wa_excel2-value.
WHEN '0006'.
wa_item-pckg_no = wa_excel2-value.
WHEN '0007'.
wa_item-stge_loc = wa_excel2-value.
WHEN '0008'.
wa_item-quantity = wa_excel2-value.
WHEN '0009'.
wa_item-po_unit = wa_excel2-value.
WHEN '0010'.
wa_item-po_price = wa_excel2-value.
WHEN '0011'.
wa_item-net_price = wa_excel2-value.
WHEN '0012'.
wa_item-price_unit = wa_excel2-value.
WHEN '0013'.
wa_item-orderpr_un = wa_excel2-value.
WHEN '0014'.
wa_item-delivery_date = wa_excel2-value.
WHEN '0015'.
wa_item-matl_group = wa_excel2-value.
WHEN '0016'.
wa_item-tax_code = wa_excel2-value.
ENDCASE.
AT END OF row.
APPEND wa_item TO it_item.
CLEAR wa_item.
ENDAT.
ENDLOOP.
************** Excel 3
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file3
i_begin_col = '1'
i_begin_row = p_brow3
i_end_col = '13'
i_end_row = p_erow3
TABLES
intern = it_excel3
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_excel3 INTO wa_excel3.
CASE wa_excel3-col.
WHEN '0001'.
wa_service-po_no = wa_excel3-value.
WHEN '0002'.
wa_service-po_item = wa_excel3-value.
WHEN '0003'.
wa_service-pckg_no = wa_excel3-value.
WHEN '0004'.
wa_service-line_no = wa_excel3-value.
WHEN '0005'.
wa_service-ext_line = wa_excel3-value.
WHEN '0006'.
wa_service-outl_ind = wa_excel3-value.
WHEN '0007'.
wa_service-subpckg_no = wa_excel3-value.
WHEN '0008'.
wa_service-serial_no = wa_excel3-value.
WHEN '0009'.
wa_service-short_text = wa_excel3-value.
WHEN '0010'.
wa_service-quantity = wa_excel3-value.
WHEN '0011'.
wa_service-base_uom = wa_excel3-value.
WHEN '0012'.
wa_service-gr_price = wa_excel3-value.
WHEN '0013'.
wa_service-matl_group = wa_excel3-value.
ENDCASE.
AT END OF row.
APPEND wa_service TO it_service.
CLEAR wa_service.
ENDAT.
ENDLOOP.
************** Excel 3
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file4
i_begin_col = '1'
i_begin_row = p_brow4
i_end_col = '07'
i_end_row = p_erow4
TABLES
intern = it_excel4
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_excel4 INTO wa_excel4.
CASE wa_excel4-col.
WHEN '0001'.
wa_account-po_no = wa_excel4-value.
WHEN '0002'.
wa_account-po_item = wa_excel4-value.
WHEN '0003'.
wa_account-serial_no = wa_excel4-value.
WHEN '0004'.
wa_account-gl_account = wa_excel4-value.
WHEN '0005'.
wa_account-costcenter = wa_excel4-value.
WHEN '0006'.
wa_account-asset_no = wa_excel4-value.
WHEN '0007'.
wa_account-orderid = wa_excel4-value.
ENDCASE.
AT END OF row.
APPEND wa_account TO it_account.
CLEAR wa_account.
ENDAT.
ENDLOOP.
ENDFORM. " excel_to_itab
*&---------------------------------------------------------------------*
*& Form GET_FINAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_final .
LOOP AT it_header INTO wa_header.
* BAPI HEADER
header-purch_org = wa_header-purch_org.
header-pur_group = wa_header-pur_group.
header-doc_type = wa_header-doc_type.
header-vendor = wa_header-vendor.
header-doc_date = wa_header-doc_date.
header-currency = wa_header-currency.
header-comp_code = wa_header-comp_code.
* BAPI HEADERX
headerx-comp_code = c_x.
headerx-doc_type = c_x.
headerx-vendor = c_x.
headerx-creat_date = c_x.
headerx-created_by = c_x.
headerx-purch_org = c_x.
headerx-pur_group = c_x.
headerx-langu = c_x.
headerx-sales_pers = c_x.
headerx-currency = c_x.
headerx-doc_date = c_x. " Added
LOOP AT it_item INTO wa_item WHERE po_no = wa_header-po_no.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'SERVICE'
* quantity = '1'
* SUBOBJECT = ' '
* TOYEAR = '0000'
* IGNORE_BUFFER = ' '
IMPORTING
number = number
* QUANTITY =
* RETURNCODE =
* EXCEPTIONS
* INTERVAL_NOT_FOUND = 1
* NUMBER_RANGE_NOT_INTERN = 2
* OBJECT_NOT_FOUND = 3
* QUANTITY_IS_0 = 4
* QUANTITY_IS_NOT_1 = 5
* INTERVAL_OVERFLOW = 6
* BUFFER_OVERFLOW = 7
* OTHERS = 8
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
item-po_item = wa_item-po_item.
item-acctasscat = wa_item-acctasscat.
item-item_cat = '9'.
item-short_text = wa_item-short_text.
item-plant = wa_item-plant.
item-pckg_no = number.
item-stge_loc = wa_item-stge_loc.
item-quantity = wa_item-quantity.
item-po_unit = wa_item-po_unit.
item-po_price = wa_item-po_price.
item-net_price = wa_item-net_price.
item-price_unit = wa_item-price_unit.
item-orderpr_un = wa_item-orderpr_un.
item-matl_group = wa_item-matl_group.
item-tax_code = wa_item-tax_code.
APPEND item.
CLEAR item.
itemx-po_item = wa_item-po_item.
itemx-item_cat = c_x.
itemx-po_itemx = c_x.
itemx-short_text = c_x.
itemx-quantity = c_x.
itemx-tax_code = c_x.
itemx-acctasscat = c_x.
itemx-item_cat = c_x.
itemx-matl_group = c_x.
itemx-plant = c_x.
itemx-trackingno = c_x.
itemx-agreement = c_x.
itemx-agmt_item = c_x.
itemx-stge_loc = c_x.
itemx-quantity = c_x.
itemx-po_unit = c_x.
itemx-conv_num1 = c_x.
itemx-conv_den1 = c_x.
itemx-net_price = c_x.
itemx-price_unit = c_x.
itemx-gr_pr_time = c_x.
itemx-prnt_price = c_x.
itemx-unlimited_dlv = c_x.
itemx-gr_ind = c_x .
itemx-ir_ind = c_x .
itemx-gr_basediv = c_x .
itemx-pckg_no = c_x.
itemx-po_price = c_x. " Added
itemx-orderpr_un = c_x. " Added
APPEND itemx.
CLEAR itemx.
itemschedule-po_item = wa_item-po_item.
itemschedule-del_datcat_ext = 'D'.
itemschedule-delivery_date = wa_item-delivery_date.
APPEND itemschedule.
CLEAR itemschedule.
itemschedulex-po_item = wa_item-po_item.
itemschedulex-po_itemx = c_x .
itemschedulex-del_datcat_ext = c_x.
itemschedulex-delivery_date = c_x .
APPEND itemschedulex.
CLEAR itemschedulex.
LOOP AT it_service INTO wa_service WHERE po_no = wa_item-po_no AND po_item = wa_item-po_item.
IF wa_service-outl_ind IS INITIAL.
IF number1 IS INITIAL.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'SERVICE'
* quantity = '1'
* SUBOBJECT = ' '
* TOYEAR = '0000'
* IGNORE_BUFFER = ' '
IMPORTING
number = number1
* QUANTITY =
* RETURNCODE =
* EXCEPTIONS
* INTERVAL_NOT_FOUND = 1
* NUMBER_RANGE_NOT_INTERN = 2
* OBJECT_NOT_FOUND = 3
* QUANTITY_IS_0 = 4
* QUANTITY_IS_NOT_1 = 5
* INTERVAL_OVERFLOW = 6
* BUFFER_OVERFLOW = 7
* OTHERS = 8
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
services-pckg_no = number.
services-line_no = '1'.
services-ext_line = '0'.
services-outl_ind = 'X'.
services-subpckg_no = number1.
* services-short_text = wa_service-short_text.
* services-quantity = wa_service-quantity.
* services-base_uom = wa_service-base_uom.
* services-gr_price = wa_service-gr_price.
* services-matl_group = wa_service-matl_group.
APPEND services.
CLEAR services.
ENDIF.
* ELSE.
services-pckg_no = number1.
services-line_no = wa_service-line_no.
services-ext_line = wa_service-ext_line.
* services-outl_ind = wa_service-outl_ind.
services-subpckg_no = '0'.
services-short_text = wa_service-short_text.
services-quantity = wa_service-quantity.
services-base_uom = wa_service-base_uom.
services-gr_price = wa_service-gr_price.
services-matl_group = wa_service-matl_group.
APPEND services.
CLEAR services.
ENDIF.
IF wa_service-outl_ind IS INITIAL.
posrvaccessvalues-pckg_no = number1.
posrvaccessvalues-line_no = wa_service-line_no.
posrvaccessvalues-serno_line = '01'.
posrvaccessvalues-serial_no = wa_service-serial_no.
* posrvaccessvalues-percentage = '100'.
APPEND posrvaccessvalues . CLEAR posrvaccessvalues.
ENDIF.
ENDLOOP.
LOOP AT it_account INTO wa_account WHERE po_no = wa_item-po_no AND po_item = wa_item-po_item.
account-po_item = wa_account-po_item.
account-serial_no = wa_account-serial_no.
account-gl_account = wa_account-gl_account.
account-costcenter = wa_account-costcenter.
account-asset_no = wa_account-asset_no.
account-orderid = wa_account-orderid.
APPEND account.
CLEAR account.
accountx-po_item = wa_account-po_item.
accountx-po_itemx = c_x .
accountx-serial_no = wa_account-serial_no.
accountx-serial_nox = c_x .
* accountx-creat_date = c_x .
accountx-costcenter = c_x .
accountx-gl_account = c_x .
* accountx-co_area = c_x .
* accountx-tax_code = c_x .
* accountx-asset_no = c_x . " Added
* accountx-orderid = c_x . " Added
APPEND accountx. CLEAR accountx.
ENDLOOP.
ENDLOOP.
*
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = header
poheaderx = headerx
* POADDRVENDOR =
* TESTRUN =
IMPORTING
exppurchaseorder = purchaseorder
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = return
poitem = item
poitemx = itemx
poschedule = itemschedule
poschedulex = itemschedulex
poaccount = account
poaccountx = accountx
poservices = services.
posrvaccessvalues = posrvaccessvalues.
IF purchaseorder IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
LOOP AT return.
WRITE : / return-type, return-number, return-message.
ENDLOOP.
ENDLOOP.
ENDFORM. " GET_FINAL