Application Development and Automation 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: 
Read only

Service fields problem in BAPI_PO_CREATE1 function

Former Member
0 Likes
1,165

hi all,

I have a problem when I use BAPI_PO_CREATE1 to create a Purchasing order.

I want to create a service PO in the system ( R3 4.6C ) . I have the data from our key user and I can create PO sucessfully manually. But when using BAPI, It alway occurs a error.

I use POSERVICE Structure, But i have NO idea about which field is MUST, Is there anyone have an example about these service PO??

Any suggestion is helpful and thanks in advance.

Regards

Ned

5 REPLIES 5
Read only

GauthamV
Active Contributor
0 Likes
946

hi,

WELCOME TO SDN.

use this program for creating service po's using bapi.

&----


*& Report ZMM_PO_CREATE1 *

*& *

&----


*& *

*& *

&----


REPORT ZMM_PO_CREATE1 .

data : POHEADER like BAPIMEPOHEADER occurs 0 with header line,

POHEADERX like BAPIMEPOHEADERX occurs 0 with header line,

POITEM like BAPIMEPOITEM occurs 0 with header line,

POITEMX like BAPIMEPOITEMX occurs 0 with header line,

POESLLC like BAPIESLLC occurs 0 with header line,

POACCOUNT like BAPIMEPOACCOUNT occurs 0 with header line,

POACCOUNTX like BAPIMEPOACCOUNTX occurs 0 with header line,

POCONDHEADER like BAPIMEPOCONDHEADER occurs 0 with header line,

POCONDHEADERX like BAPIMEPOCONDHEADERX occurs 0 with header line,

POCOND like BAPIMEPOCOND occurs 0 with header line,

RETURN like BAPIRET2 occurs 0 with header line.

data : po_no(10).

data : begin of it_head occurs 0,

ref(10),

bsart like ekko-bsart,

lifnr like ekko-lifnr,

ekorg like ekko-ekorg,

ekgrp like ekko-ekgrp,

bukrs like ekko-bukrs,

verkf like ekko-verkf,

telf1 like ekko-telf1,

ihrez like ekko-ihrez,

unsez like ekko-unsez,

kdatb(10),

kdate(10),

end of it_head.

data : begin of it_det occurs 0,

ref(10),

knttp like ekpo-knttp,

pstyp like ekpo-pstyp,

txz01 like ekpo-txz01,

matkl like ekpo-matkl,

werks like ekpo-werks,

afnam like ekpo-afnam,

ktext1 like esll-ktext1,

srvpos like esll-srvpos,

frmval1 like esll-frmval1,

frmval2 like esll-frmval2,

menge like esll-menge,

kostl like eskn-kostl,

sakto like eskn-sakto,

zzcode like eskn-zzcode,

kbetr like konv-kbetr,

end of it_det.

data : c_col1 TYPE i VALUE '0001',

c_col2 TYPE i VALUE '0002',

c_col3 TYPE i VALUE '0003',

c_col4 TYPE i VALUE '0004',

c_col5 TYPE i VALUE '0005',

c_col6 TYPE i VALUE '0006',

c_col7 TYPE i VALUE '0007',

c_col8 TYPE i VALUE '0008',

c_col9 TYPE i VALUE '0009',

c_col10 TYPE i VALUE '0010',

c_col11 TYPE i VALUE '0011',

c_col12 TYPE i VALUE '0012',

c_col13 TYPE i VALUE '0013',

c_col14 TYPE i VALUE '0014',

c_col15 TYPE i VALUE '0015',

c_col16 TYPE i VALUE '0016'.

data : v_currentrow type i,

v_currentrow1 type i.

data : itab_head like ALSMEX_TABLINE occurs 0 with header line,

itab_det like ALSMEX_TABLINE occurs 0 with header line.

data : file_head type RLGRAP-FILENAME,

file_item type RLGRAP-FILENAME.

file_head = 'C:\Documents and Settings\Desktop\head.xls'.

file_item = 'C:\Documents and Settings\Desktop\item.xls'.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = file_head

i_begin_col = 1

i_begin_row = 1

i_end_col = 12

i_end_row = 50

tables

intern = itab_head

  • 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.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = file_item

i_begin_col = 1

i_begin_row = 1

i_end_col = 16

i_end_row = 50

tables

intern = itab_det

  • 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.

IF itab_head[] IS INITIAL.

WRITE:/ 'No Header Data Exists '.

STOP.

ELSE.

sort itab_head by row col.

read table itab_head index 1.

v_currentrow = itab_head-row.

loop at itab_head.

if itab_head-row ne v_currentrow.

APPEND it_head.

v_currentrow = itab_head-row.

ENDIF.

CASE itab_head-col.

WHEN c_col1.

it_head-ref = itab_head-value.

WHEN c_col2.

it_head-bsart = itab_head-value.

WHEN c_col3.

it_head-lifnr = itab_head-value.

WHEN c_col4.

it_head-ekorg = itab_head-value.

WHEN c_col5.

it_head-ekgrp = itab_head-value.

WHEN c_col6.

it_head-bukrs = itab_head-value.

WHEN c_col7.

it_head-verkf = itab_head-value.

WHEN c_col8.

it_head-telf1 = itab_head-value.

WHEN c_col9.

it_head-ihrez = itab_head-value.

WHEN c_col10.

it_head-unsez = itab_head-value.

WHEN c_col11.

it_head-kdatb = itab_head-value.

WHEN c_col12.

it_head-kdate = itab_head-value.

ENDCASE.

ENDLOOP.

APPEND it_head.

CLEAR it_head.

ENDIF.

IF itab_det[] IS INITIAL.

WRITE:/ 'No Item Data Exists '.

STOP.

ELSE.

sort itab_det by row col.

read table itab_det index 1.

v_currentrow1 = itab_det-row.

loop at itab_det.

if itab_det-row ne v_currentrow1.

APPEND it_det.

v_currentrow1 = itab_det-row.

ENDIF.

CASE itab_det-col.

WHEN c_col1.

it_det-ref = itab_det-value.

WHEN c_col2.

it_det-knttp = itab_det-value.

WHEN c_col3.

it_det-pstyp = itab_det-value.

WHEN c_col4.

it_det-txz01 = itab_det-value.

WHEN c_col5.

it_det-matkl = itab_det-value.

WHEN c_col6.

it_det-werks = itab_det-value.

WHEN c_col7.

it_det-afnam = itab_det-value.

WHEN c_col8.

it_det-srvpos = itab_det-value.

WHEN c_col9.

it_det-ktext1 = itab_det-value.

WHEN c_col10.

it_det-frmval1 = itab_det-value.

WHEN c_col11.

it_det-frmval2 = itab_det-value.

WHEN c_col12.

it_det-menge = itab_det-value.

WHEN c_col13.

it_det-kostl = itab_det-value.

WHEN c_col14.

it_det-sakto = itab_det-value.

WHEN c_col15.

it_det-zzcode = itab_det-value.

WHEN c_col16.

it_det-kbetr = itab_det-value.

ENDCASE.

ENDLOOP.

APPEND it_det.

CLEAR it_det.

ENDIF.

loop at it_head.

poheader-doc_type = it_head-bsart.

poheader-vendor = it_head-lifnr.

poheader-purch_org = it_head-ekorg.

poheader-pur_group = it_head-ekgrp.

poheader-comp_code = it_head-bukrs.

poheader-sales_pers = it_head-verkf.

poheader-telephone = it_head-telf1.

poheader-REF_1 = it_head-ihrez.

poheader-OUR_REF = it_head-unsez.

poheader-VPER_START = it_head-kdatb.

poheader-VPER_END = it_head-kdate.

loop at it_det where ref = it_head-ref.

poitem-acctasscat = it_det-knttp.

poitem-item_cat = it_det-pstyp.

poitem-short_text = it_det-txz01.

poitem-matl_group = it_det-matkl.

poitem-plant = it_det-werks.

poitem-PREQ_NAME = it_det-afnam.

POESLLC-SERVICE = it_det-srvpos.

POESLLC-SHORT_TEXT = it_det-ktext1.

POESLLC-FORM_VAL1 = it_det-frmval1.

POESLLC-FORM_VAL2 = it_det-frmval2.

POESLLC-QUANTITY = it_det-menge.

POACCOUNT-COSTCENTER = it_det-kostl.

POACCOUNT-GL_ACCOUNT = it_det-sakto.

POCONDHEADER-COND_TYPE = 'R000'.

POCONDHEADER-COND_VALUE = it_det-kbetr.

endloop.

endloop.

poheaderx-doc_type = 'X'.

poheaderx-vendor = 'X'.

poheaderx-purch_org = 'X'.

poheaderx-pur_group = 'X'.

poheaderx-comp_code = 'X'.

poheaderx-sales_pers = 'X'.

poheaderx-telephone = 'X'.

poheaderx-REF_1 = 'X'.

poheaderx-OUR_REF = 'X'.

poheaderx-VPER_START = 'X'.

poheaderx-VPER_END = 'X'.

poitemx-acctasscat = 'X'.

poitemx-item_cat = 'X'.

poitemx-short_text = 'X'.

poitemx-matl_group = 'X'.

poitemx-plant = 'X'.

poitemx-PREQ_NAME = 'X'.

*POESLLCx-SHORT_TEXT = 'X'.

POACCOUNTx-COSTCENTER = 'X'.

POACCOUNTx-GL_ACCOUNT = 'X'.

POCONDHEADER-cond_type = 'X'.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = poheader

POHEADERX = poheaderx

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • POEXPIMPHEADER =

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

IMPORTING

EXPPURCHASEORDER = po_no

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

RETURN = return

POITEM = poitem

POITEMX = poitemx

  • POADDRDELIVERY =

  • POSCHEDULE =

  • POSCHEDULEX =

POACCOUNT = poaccount

  • POACCOUNTPROFITSEGMENT =

POACCOUNTX = poaccountx

POCONDHEADER = pocondheader

POCONDHEADERX = pocondheaderx

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

POSERVICES = poesllc

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

if sy-subrc = 0.

loop at return.

write return-MESSAGE_V1.

write po_no.

endloop.

endif.

Read only

Former Member
0 Likes
946

hi gautham,

Thanks a lot for your answer. But I still can't create PO with service using BAPI.

I saw

POESLLC-SERVICE = it_det-srvpos.

POESLLC-SHORT_TEXT = it_det-ktext1.

POESLLC-FORM_VAL1 = it_det-frmval1.

POESLLC-FORM_VAL2 = it_det-frmval2.

POESLLC-QUANTITY = it_det-menge.

.

These fields are used for service. Do you have more detail about the service part?

Actually I can create PO WITHOUT service using BAPI. so I think the question may come from the service structure( POESLLC )?

Thanks in advance.

Ned

Read only

Former Member
0 Likes
946

I have solved the problem.

Actually you should manually input the temp package number and temp item number. (1,2 for example). and the system will replace these numbers when the bapi run.

after all, Thanks

Ned

Read only

0 Likes
946

Hi Ming,

are these package and subpackage numbers infact temperory. even i'm facing these problems.

waiting for your reply.

regards

varun

Read only

Former Member
0 Likes
946

got it