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

Former Member
0 Kudos

Hi gurus,

I have written this scenario before too but I didn't get the significant answer and I need to submit my program within an hour, so can anyone of you please help me in solvig this problem .

I have a scenario where I need to use BAPI_PO_CREATE1 to create PO's for multiple line items, and the file that I will be uploading looks like this:

the sequence of the fileds are:

<b>Ref no., Vendor, material,Quantity, Price, Ord_unit, Plant,

Strg_loc, purch_org, purch_grp,c_code, doc_typ</b>

1 101 123 100 10 car 101 121 114 112 222 NB

1 101 234 100 10 buc 101 121 114 112 222 NB

1 101 567 100 10 car 101 121 114 112 222 NB

2 102 123 100 10 car 101 121 114 112 222 NB

2 102 567 100 10 car 101 121 114 112 222 NB

3 103 234 100 10 buc 101 121 114 112 222 NB

3 103 567 100 10 car 101 121 114 112 222 NB

3 103 123 100 10 car 101 121 114 112 222 NB

4 104 567 100 10 car 101 121 114 112 222 NB

The refrence no. field in the text file will act as a unique identifier i.e. all records having the same REF NO should belong to the same purchase order, so basically in my case my program should create 4 Po's for the above text file for ref no. 1,2,3 and 4.

I don't have much time left so I will be really greatful to you if you guys will answer this problenm using my own objects as I very less time is left, I will really appreciate you efforts.

data: poheader LIKE bapimepoheader,

poheaderx LIKE bapimepoheaderx,

poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,

poitemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,

return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

return2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

exppurchaseorder LIKE bapimepoheader-po_number,

poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,

poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE.

data: begin of it_input_file OCCURS 0,

ref_no(2),

c_code(4),

doc_typ(4),

doc_date(10),

vend_no(10),

purch_org(4),

purch_grp(3),

currency(3),

item_no(3),

material(18),

Plant(4),

Strg_loc(4),

Quantity(13),

Price(10),

ord_unit(7),

del_date(10),

seq_num(5) type n,

end of it_input_file.

v_semfile = p_ifname.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = v_semfile

filetype = 'DAT'

TABLES

data_tab = it_input_file

EXCEPTIONS

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

gui_refuse_filetransfer = 8

OTHERS = 9.

2 REPLIES 2

Former Member
0 Kudos

Hi Rajeev,

Please refer the Code below for the same.

You can use <b>ON CHANGE OF</b> statement to differentiate the PO.

&----


*& Report YDM_PO_CREATE *

*& *

&----


*& *

*& *

&----


REPORT ydm_po_create.

*-- Input File Declaration

TYPES: BEGIN OF ty_input_file,

column1 TYPE char50,

column2 TYPE char50,

column3 TYPE char50,

column4 TYPE char50,

column5 TYPE char50,

column6 TYPE char50,

column7 TYPE char50,

column8 TYPE char50,

column9 TYPE char50,

column10 TYPE char50,

column11 TYPE char50,

column12 TYPE char50,

column13 TYPE char50,

column14 TYPE char50,

column15 TYPE char50,

column16 TYPE char50,

column17 TYPE char50,

column18 TYPE char50,

END OF ty_input_file.

DATA: i_input_file TYPE STANDARD TABLE OF ty_input_file,

wa_input_file TYPE ty_input_file.

CONSTANTS: c_path TYPE char20 VALUE 'C:\',

c_mask TYPE char9 VALUE ',*.*,*.*.',

c_mode TYPE char1 VALUE 'O',

c_filetype TYPE char10 VALUE 'ASC',

c_x TYPE char01 VALUE 'X'.

PARAMETERS : p_fname LIKE rlgrap-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

*-- Browse Presentation Server

PERFORM f4_presentation_file.

START-OF-SELECTION..

*-- Read presentation server file

PERFORM f1003_upload_file.

IF NOT i_input_file[] IS INITIAL.

PERFORM split_data.

ENDIF.

*&----


*& Form f4_presentation_file

*&----


*& F4 Help for presentation server

*&----


FORM f4_presentation_file .

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_path = c_path

mask = c_mask

mode = c_mode

title = text-001

IMPORTING

filename = p_fname

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " f4_presentation_file

*&----


*& Form f1003_upload_file

*&----


*& Upload File

*&----


FORM f1003_upload_file .

DATA: lcl_filename TYPE string.

lcl_filename = p_fname.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lcl_filename

filetype = c_filetype

has_field_separator = c_x

TABLES

data_tab = i_input_file

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

EXIT.

ENDIF.

ENDFORM. " f1003_upload_file

&----


*& Form split_data

&----


  • Collect data for creating Purchase Order

----


FORM split_data .

DATA: i_poitem TYPE STANDARD TABLE OF bapimepoitem,

i_poitemx TYPE STANDARD TABLE OF bapimepoitemx,

i_poitem_sch TYPE STANDARD TABLE OF bapimeposchedule,

i_poitem_schx TYPE STANDARD TABLE OF bapimeposchedulx,

i_acct_ass TYPE STANDARD TABLE OF bapimepoaccount,

i_acct_assx TYPE STANDARD TABLE OF bapimepoaccountx,

i_services TYPE STANDARD TABLE OF bapiesllc ,

i_srvacc TYPE STANDARD TABLE OF bapiesklc,

i_return TYPE STANDARD TABLE OF bapiret2,

wa_header TYPE bapimepoheader,

wa_headerx TYPE bapimepoheaderx,

wa_poitem TYPE bapimepoitem,

wa_poitemx TYPE bapimepoitemx,

wa_poitem_sch TYPE bapimeposchedule,

wa_poitem_schx TYPE bapimeposchedulx,

wa_acct_ass TYPE bapimepoaccount,

wa_acct_assx TYPE bapimepoaccountx,

wa_services TYPE bapiesllc,

wa_srvacc TYPE bapiesklc,

wa_return TYPE bapiret2,

ws_po TYPE bapimepoheader-po_number.

wa_services-pckg_no = 10.

wa_services-line_no = 1.

wa_services-outl_no = '0'.

wa_services-outl_ind = c_x.

wa_services-subpckg_no = 20.

APPEND wa_services TO i_services.

wa_srvacc-pckg_no = 10.

wa_srvacc-line_no = 1.

wa_srvacc-serno_line = 01.

wa_srvacc-serial_no = 01.

wa_srvacc-percentage = 100.

APPEND wa_srvacc TO i_srvacc.

LOOP AT i_input_file INTO wa_input_file.

IF wa_input_file-column2 EQ 'HD'.

wa_header-doc_type = wa_input_file-column3.

wa_header-creat_date = sy-datum.

wa_header-created_by = sy-uname.

wa_header-vendor = wa_input_file-column4.

PERFORM conversion_output USING wa_header-vendor

CHANGING wa_header-vendor.

wa_header-comp_code = 'DE03'.

wa_header-purch_org = 'DE03'.

wa_header-pur_group = 'DE1'.

wa_header-vper_start = wa_input_file-column9.

wa_header-vper_end = wa_input_file-column10.

wa_headerx-comp_code = c_x.

wa_headerx-doc_type = c_x.

wa_headerx-creat_date = c_x.

wa_headerx-created_by = c_x.

wa_headerx-vendor = c_x.

wa_headerx-purch_org = c_x.

wa_headerx-pur_group = c_x.

wa_headerx-vper_start = c_x.

wa_headerx-vper_end = c_x.

ENDIF.

IF wa_input_file-column2 EQ 'IT'.

wa_poitem-po_item = wa_input_file-column3.

wa_poitem-short_text = wa_input_file-column6.

wa_poitem-plant = wa_input_file-column8.

wa_poitem-quantity = '1'.

wa_poitem-tax_code = 'V0'.

wa_poitem-item_cat = 'D'.

wa_poitem-acctasscat = 'K'.

wa_poitem-matl_group = wa_input_file-column7.

wa_poitem-pckg_no = '10'.

APPEND wa_poitem TO i_poitem .

wa_poitemx-po_item = wa_input_file-column3.

wa_poitemx-po_itemx = c_x.

wa_poitemx-short_text = c_x.

wa_poitemx-plant = c_x.

wa_poitemx-quantity = c_x.

wa_poitemx-tax_code = c_x.

wa_poitemx-item_cat = c_x.

wa_poitemx-acctasscat = c_x.

wa_poitemx-matl_group = c_x.

wa_poitemx-pckg_no = c_x.

APPEND wa_poitemx TO i_poitemx.

wa_poitem_sch-po_item = wa_input_file-column3.

wa_poitem_sch-delivery_date = sy-datum.

APPEND wa_poitem_sch TO i_poitem_sch.

wa_poitem_schx-po_item = wa_input_file-column3.

wa_poitem_schx-po_itemx = c_x.

wa_poitem_schx-delivery_date = c_x.

APPEND wa_poitem_schx TO i_poitem_schx.

wa_acct_ass-po_item = 10.

wa_acct_ass-serial_no = 01.

wa_acct_ass-gl_account = '0006360100'.

wa_acct_ass-co_area = '1000'.

wa_acct_ass-costcenter = 'KC010000'.

APPEND wa_acct_ass TO i_acct_ass.

wa_acct_ass-po_item = 10.

wa_acct_ass-serial_no = 02.

wa_acct_ass-gl_account = '0006360100'.

wa_acct_ass-co_area = '1000'.

wa_acct_ass-costcenter = 'KC010000'.

APPEND wa_acct_ass TO i_acct_ass.

wa_acct_assx-po_item = 10.

wa_acct_assx-serial_no = 01.

wa_acct_assx-po_itemx = c_x.

wa_acct_assx-serial_nox = c_x.

wa_acct_assx-gl_account = c_x.

wa_acct_assx-co_area = c_x.

wa_acct_assx-costcenter = c_x.

APPEND wa_acct_assx TO i_acct_assx.

wa_acct_assx-po_item = 10.

wa_acct_assx-serial_no = 02.

wa_acct_assx-po_itemx = c_x.

wa_acct_assx-serial_nox = c_x.

wa_acct_assx-gl_account = c_x.

wa_acct_assx-co_area = c_x.

wa_acct_assx-costcenter = c_x.

APPEND wa_acct_assx TO i_acct_assx.

wa_services-pckg_no = 20.

wa_services-line_no = 2.

wa_services-service = wa_input_file-column9.

wa_services-quantity = '100'.

wa_services-gr_price = '100'.

wa_services-userf1_txt = wa_input_file-column13.

APPEND wa_services TO i_services.

wa_srvacc-pckg_no = 20.

wa_srvacc-line_no = 1.

wa_srvacc-serno_line = 02.

wa_srvacc-serial_no = 02.

wa_srvacc-percentage = 100.

APPEND wa_srvacc TO i_srvacc.

ENDIF.

ENDLOOP.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = wa_header

poheaderx = wa_headerx

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • POEXPIMPHEADER =

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

IMPORTING

exppurchaseorder = ws_po

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

return = i_return

poitem = i_poitem

poitemx = i_poitemx

  • POADDRDELIVERY =

poschedule = i_poitem_sch

poschedulex = i_poitem_schx

poaccount = i_acct_ass

  • POACCOUNTPROFITSEGMENT =

poaccountx = i_acct_assx

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

poservices = i_services

posrvaccessvalues = i_srvacc

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

.

break gbpra8.

LOOP AT i_return INTO wa_return.

ENDLOOP.

ENDFORM. " split_data

&----


*& Form conversion_output

&----


  • Conversion exit input

----


FORM conversion_output USING p_ip

CHANGING p_op.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = p_ip

IMPORTING

output = p_op.

ENDFORM. " conversion_output

<b>Reward points if this helps.

Manish</b>

0 Kudos

Thanks for the reply Manish, But as I told you I don't have much time left....I know thats not your problem, but I am sorry I don't have much time left, so can you please explain me using my scenario.

Rajeev Gupta