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

Example Program for BAPI_PO_CREATE1

abapdeveloper20
Contributor
0 Likes
8,919

Hi Gurus,

Can any one pls help me out with an example program of how to use this BAPI_PO_CREATE1????

I searched in the forum. many programs are not working here in 4.6c .

Any inputs on this will be highly appreciated...

Thanks in advance

Rdgs,

Lakshmiraj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,475

Check the sample code below.

&----


*& 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.

break gbpra8.

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

Reward points if this helps.

15 REPLIES 15
Read only

Former Member
0 Likes
3,476

Check the sample code below.

&----


*& 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.

break gbpra8.

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

Reward points if this helps.

Read only

0 Likes
3,475

Hi.

Thanks a lot for ur useful reply...

Pls let me know in which format the input file should be???? How the entries in that input file??? What is the coloumn order???

Waiting for ur reply

Read only

0 Likes
3,475

itab fields are the input fields..follow the same order in internal table..

REPORT zbapi_ss NO STANDARD PAGE HEADING.

DATA: BEGIN OF itab OCCURS 0,

doc_type(4),

suppl_plnt(4),

vendor(10),

purch_org(4),

pur_group(3),

comp_code(4),

vper_start(10),

vper_end(8),

po_item(5),

material(18),

  • SHORT_TEXT(40),

quantity(16),

  • NET_PRICE(28),

plant(4),

stge_loc(4),

  • DELIVERY_DATE(8),

END OF itab.

DATA: BEGIN OF it_log OCCURS 0,

message(70) TYPE c,

END OF it_log.

DATA: w_type(4) TYPE c.

CONSTANTS : c_x VALUE 'X'.

DATA: gstest LIKE bapimepoheader.

DATA: g_ebeln LIKE bapimepoheader-po_number.

DATA: BEGIN OF g_bapimepoheader OCCURS 0.

INCLUDE STRUCTURE bapimepoheader.

DATA: END OF g_bapimepoheader.

DATA: BEGIN OF g_bapimepoheaderx OCCURS 0.

INCLUDE STRUCTURE bapimepoheaderx.

DATA: END OF g_bapimepoheaderx.

DATA: BEGIN OF g_bapimeposchedule OCCURS 0.

INCLUDE STRUCTURE bapimeposchedule.

DATA: END OF g_bapimeposchedule.

DATA: BEGIN OF g_poschedulex OCCURS 0.

INCLUDE STRUCTURE bapimeposchedulx.

DATA: END OF g_poschedulex.

DATA: BEGIN OF g_bapieikp OCCURS 0.

INCLUDE STRUCTURE bapieikp.

DATA: END OF g_bapieikp.

DATA: BEGIN OF g_bapimepoitem OCCURS 0.

INCLUDE STRUCTURE bapimepoitem.

DATA: END OF g_bapimepoitem.

DATA: BEGIN OF g_poitemx OCCURS 0.

INCLUDE STRUCTURE bapimepoitemx.

DATA: END OF g_poitemx.

DATA: BEGIN OF g_bapiret2 OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA: END OF g_bapiret2.

DATA: it_itab LIKE itab OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-100.

PARAMETERS : p_file LIKE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK blk.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM file_selection.

START-OF-SELECTION.

PERFORM data_upload.

PERFORM bapi_upload.

PERFORM display.

&----


*& Form file_selection

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM file_selection.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = ' '

def_path = 'C:\'

mask = ',.txt,.txt.'

mode = 'O'

title = 'Open a TXT(Tab delimited) file only'

IMPORTING

filename = p_file

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

ENDFORM. " file_selection

&----


*& Form data_upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM data_upload .

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = itab

EXCEPTIONS

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

no_authority = 10

OTHERS = 11.

IF sy-subrc EQ 0 .

WRITE:/ 'Program : ', sy-repid.

WRITE:/ 'Filename: ', p_file.

WRITE AT /1(144) sy-uline.

  • ELSE .

  • MESSAGE i001.

ENDIF.

ENDFORM. " data_upload

&----


*& Form bapi_upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bapi_upload .

it_itab[] = itab[].

SORT itab BY vendor material.

DELETE ADJACENT DUPLICATES FROM itab COMPARING vendor.

LOOP AT itab.

MOVE-CORRESPONDING itab TO g_bapimepoheader.

w_type = itab-doc_type.

IF itab-doc_type = 'ZTRM'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = itab-vendor

IMPORTING

output = itab-vendor.

g_bapimepoheader-vendor = itab-vendor.

ENDIF.

g_bapimepoheader-creat_date = sy-datum.

g_bapimepoheader-created_by = sy-uname.

APPEND g_bapimepoheader.

g_bapimepoheaderx-comp_code = 'X'.

g_bapimepoheaderx-vendor = 'X'.

g_bapimepoheaderx-doc_type = 'X'.

g_bapimepoheaderx-purch_org = 'X'.

g_bapimepoheaderx-pur_group = 'X'.

g_bapimepoheaderx-suppl_plnt = 'X'.

g_bapimepoheaderx-vper_start = 'X'.

g_bapimepoheaderx-vper_end = 'X'.

APPEND g_bapimepoheaderx.

IF itab-doc_type = 'ZTRM'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = itab-vendor

IMPORTING

output = itab-vendor.

ENDIF.

LOOP AT it_itab WHERE vendor = itab-vendor.

MOVE-CORRESPONDING it_itab TO g_bapimepoitem.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = it_itab-material

IMPORTING

output = it_itab-material.

g_bapimepoitem-material = it_itab-material.

APPEND g_bapimepoitem.

MOVE-CORRESPONDING it_itab TO g_bapimeposchedule.

APPEND g_bapimeposchedule.

g_poitemx-po_item = it_itab-po_item.

g_poitemx-po_itemx = 'X'.

  • g_poitemx-item_cat = 'X'.

g_poitemx-plant = 'X'.

g_poitemx-stge_loc = 'X'.

  • g_poitemx-net_price = 'X'.

  • g_poitemx-acctasscat = 'X'.

g_poitemx-material = 'X'.

  • g_poitemx-short_text = 'X'.

  • g_poitemx-matl_group = 'X'.

g_poitemx-quantity = 'X'.

  • g_poitemx-po_unit = 'X'.

  • g_poitemx-orderpr_un = 'X'.

  • g_poitemx-trackingno = 'X'.

  • g_poitemx-delete_ind = 'X'.

APPEND g_poitemx.

g_poschedulex-po_item = it_itab-po_item.

  • g_poschedulex-SCHED_LINE = 1.

g_poschedulex-po_itemx = 'X'.

  • g_poschedulex-SCHED_LINEX = 'X'.

  • g_poschedulex-DEL_DATCAT_EXT = 'X'.

  • g_poschedulex-DELIVERY_DATE = 'X'.

  • g_poschedulex-QUANTITY = 'X'.

  • g_poschedulex-DELIV_TIME = 'X'.

  • g_poschedulex-STAT_DATE = 'X'.

  • g_poschedulex-PREQ_NO = 'X'.

  • g_poschedulex-PREQ_ITEM = 'X'.

  • g_poschedulex-PO_DATE = 'X'.

  • g_poschedulex-ROUTESCHED = 'X'.

  • g_poschedulex-MS_DATE = 'X'.

APPEND g_poschedulex.

ENDLOOP.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = g_bapimepoheader

poheaderx = g_bapimepoheaderx

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • POEXPIMPHEADER = G_BAPIEIKP

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

IMPORTING

exppurchaseorder = g_ebeln

  • EXPHEADER = gstest

  • EXPPOEXPIMPHEADER =

TABLES

return = g_bapiret2

poitem = g_bapimepoitem

poitemx = g_poitemx

  • POADDRDELIVERY =

poschedule = g_bapimeposchedule

poschedulex = g_poschedulex

  • POACCOUNT =

  • POACCOUNTPROFITSEGMENT =

  • POACCOUNTX =

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

  • NFMETALLITMS =

.

IF NOT g_ebeln IS INITIAL.

  • COMMIT WORK.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = ''.

  • APPEND L_BAPI2017_HEAD_RET TO LT_BAPI2017_HEAD_RET.

IF w_type = 'ZTRM'.

CONCATENATE 'LIS Trade Material created under the number' '-'

g_ebeln INTO it_log-message.

APPEND it_log.

CLEAR it_log.

ELSE.

CONCATENATE 'LIS STO Plant-Plant created under the number' '-'

g_ebeln INTO it_log-message.

APPEND it_log.

CLEAR it_log.

ENDIF.

CLEAR : it_itab,w_type,g_bapimepoitem,g_bapimepoheader,

g_bapimepoheaderx,g_bapiret2,g_poitemx,g_bapimeposchedule,

g_poschedulex.

REFRESH : g_bapimepoitem,g_bapimepoheader,g_bapimepoheaderx,

g_bapiret2,g_poitemx,g_bapimeposchedule,g_poschedulex.

ENDIF.

ENDLOOP.

ENDFORM. " bapi_upload

*----


&----


*& Form display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display .

LOOP AT g_bapiret2.

WRITE 😕 g_bapiret2-message.

ENDLOOP.

LOOP AT it_log.

WRITE 😕 it_log-message.

ENDLOOP.

ENDFORM. " display

Read only

0 Likes
3,475

Hi sugumar,

Thnks a lot for ur input.

while checking...it is giving error as..

The Field bapieikp is unknown , but there is field similar name as g_bapieikp.

wat to do???

i'm new to BAPI ..pls help...

Read only

0 Likes
3,475

hi..may i know in which part this error is coming..

Edited by: Sugumar Ganesan on Mar 25, 2008 6:19 AM

Read only

0 Likes
3,475

Hi,

the error points to this line

DATA: BEGIN OF g_bapieikp OCCURS 0.

INCLUDE STRUCTURE bapieikp.

DATA: END OF g_bapieikp.

when i check this structure in SE11..it is not found.

BAPIEIKP does not exist. Check name

Diagnosis

There is no object with this name in the ABAP Dictionary.

i'm using SAP 4.6C.. Pls help

Thnks a lot

Read only

0 Likes
3,475

i just commented those lines declarations... error solveed.

But now error is here

APPEND l_bapi2017_head_ret TO lt_bapi2017_head_ret.

wat this refers to lt_bapi2017_head_ret.?

Read only

0 Likes
3,475

Hi Lakshmiraj...you just comment that part of declaration..and then try...revert if u have any problem..

you comment that line also..

  • APPEND L_BAPI2017_HEAD_RET TO LT_BAPI2017_HEAD_RET.

Regards

Sugumar G

Edited by: Sugumar Ganesan on Mar 25, 2008 6:37 AM

Read only

0 Likes
3,475

Hi,

Working fine .Thanks a lot

Full points rewarded.

Read only

0 Likes
3,475

Hi,

Everything works fine but the delivery date is not coming properly. System is picking some default date for delivery option..

How to sort out this ????

Read only

Former Member
0 Likes
3,475

Hai.

check this example.

REPORT zpo_bapi_purchord_tej.

----


  • DATA DECLARATIONS *

----


TYPE-POOLS slis.

TYPES: BEGIN OF ty_table,

v_legacy(8),

vendor TYPE bapimepoheader-vendor,

purch_org TYPE bapimepoheader-purch_org,

pur_group TYPE bapimepoheader-pur_group,

material TYPE bapimepoitem-material,

quantity(13),

delivery_date TYPE bapimeposchedule-delivery_date,

net_price(23),

plant TYPE bapimepoitem-plant,

END OF ty_table.

TYPES: BEGIN OF ty_alv,

v_legs(8),

success(10),

v_legf(8),

END OF ty_alv.

TYPES: BEGIN OF ty_alv1,

v_legf1(8),

v_msg(500),

END OF ty_alv1.

*-----Work area declarations.

DATA: x_table TYPE ty_table,

x_header TYPE bapimepoheader,

x_headerx TYPE bapimepoheaderx,

x_item TYPE bapimepoitem,

x_itemx TYPE bapimepoitemx,

x_sched TYPE bapimeposchedule,

x_schedx TYPE bapimeposchedulx,

x_commatable(255),

x_alv TYPE ty_alv,

x_alv1 TYPE ty_alv1,

x_alv2 TYPE ty_alv1.

*-----Internal table declarations.

DATA: it_table TYPE TABLE OF ty_table,

it_commatable LIKE TABLE OF x_commatable,

it_item TYPE TABLE OF bapimepoitem,

it_itemx TYPE TABLE OF bapimepoitemx,

it_sched TYPE TABLE OF bapimeposchedule,

it_schedx TYPE TABLE OF bapimeposchedulx,

it_alv TYPE TABLE OF ty_alv,

it_alv1 TYPE TABLE OF ty_alv1,

it_alv2 TYPE TABLE OF ty_alv1.

DATA: po_number TYPE bapimepoheader-po_number,

x_return TYPE bapiret2,

it_return TYPE TABLE OF bapiret2,

v_file TYPE string,

v_temp(8),

v_succsount TYPE i VALUE 0,

v_failcount TYPE i VALUE 0,

v_total TYPE i.

DATA: v_temp1(5) TYPE n VALUE 0.

DATA: x_event TYPE slis_t_event,

x_fieldcat TYPE slis_t_fieldcat_alv,

x_list_header TYPE slis_t_listheader,

x_event1 LIKE LINE OF x_event,

x_layout1 TYPE slis_layout_alv,

x_variant1 TYPE disvariant,

x_repid2 LIKE sy-repid.

DATA : it_fieldcat TYPE TABLE OF slis_t_fieldcat_alv.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK v_b1 WITH FRAME.

*-----To fetch the flat file.

PARAMETERS: p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK v_b1.

----


  • AT SELECTION-SCREEN *

----


AT SELECTION-SCREEN.

IF p_file IS INITIAL.

MESSAGE text-001 TYPE 'E'.

ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*-----To use F4 help to find file path.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

v_file = p_file.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

PERFORM gui_upload.

LOOP AT it_table INTO x_table.

PERFORM header_details.

v_temp = x_table-v_legacy.

LOOP AT it_table INTO x_table WHERE v_legacy = v_temp.

PERFORM lineitem.

PERFORM schedule.

ENDLOOP.

DELETE it_table WHERE v_legacy = v_temp.

PERFORM bapicall.

MOVE po_number TO x_alv-success.

APPEND x_alv TO it_alv.

CLEAR x_alv.

*-----To clear the item details in internal table after the operation for a header.

REFRESH: it_item,

it_itemx,

it_sched,

it_schedx.

CLEAR: v_temp1.

ENDLOOP.

v_total = v_succsount + v_failcount.

PERFORM display_alv.

----


  • FORM GUI_UPLOAD *

----


FORM gui_upload .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

TABLES

data_tab = it_commatable

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.

*-----To fetch the comma seperated flat file into an internal table.

LOOP AT it_commatable INTO x_commatable.

IF x_commatable IS NOT INITIAL.

SPLIT x_commatable AT ',' INTO

x_table-v_legacy

x_table-vendor

x_table-purch_org

x_table-pur_group

x_table-material

x_table-quantity

x_table-delivery_date

x_table-net_price

x_table-plant.

APPEND x_table TO it_table.

ENDIF.

CLEAR x_table.

ENDLOOP.

ENDIF.

ENDFORM. " gui_upload

----


  • FORM HEADER_DETAILS *

----


FORM header_details .

MOVE 'NB' TO x_header-doc_type.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_table-vendor

IMPORTING

output = x_table-vendor

.

MOVE x_table-vendor TO x_header-vendor.

MOVE x_table-purch_org TO x_header-purch_org.

MOVE x_table-pur_group TO x_header-pur_group.

x_headerx-doc_type = 'X'.

x_headerx-vendor = 'X'.

x_headerx-purch_org = 'X'.

x_headerx-pur_group = 'X'.

ENDFORM. " header_details

----


  • FORM LINEITEM *

----


FORM lineitem .

v_temp1 = v_temp1 + 10.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_temp1

IMPORTING

output = v_temp1.

MOVE v_temp1 TO x_item-po_item.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_table-material

IMPORTING

output = x_table-material.

MOVE x_table-material TO x_item-material.

MOVE x_table-quantity TO x_item-quantity.

MOVE x_table-net_price TO x_item-net_price.

MOVE x_table-plant TO x_item-plant.

x_itemx-po_item = v_temp1.

x_itemx-material = 'X'.

x_itemx-quantity = 'X'.

x_itemx-net_price = 'X'.

x_itemx-plant = 'X'.

APPEND x_item TO it_item.

APPEND x_itemx TO it_itemx.

CLEAR: x_item, x_itemx.

ENDFORM. " lineitem1

----


  • FORM SCHEDULE *

----


FORM schedule .

MOVE x_table-delivery_date TO x_sched-delivery_date.

MOVE v_temp1 TO x_sched-po_item.

x_schedx-delivery_date = 'X'.

x_schedx-po_item = v_temp1.

APPEND x_sched TO it_sched.

APPEND x_schedx TO it_schedx.

CLEAR: x_sched, x_schedx.

ENDFORM. " schedule

----


  • FORM BAPICALL *

----


FORM bapicall .

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = x_header

poheaderx = x_headerx

IMPORTING

exppurchaseorder = po_number

TABLES

return = it_return

poitem = it_item

poitemx = it_itemx

poschedule = it_sched

poschedulex = it_schedx.

IF po_number IS NOT INITIAL.

v_succsount = v_succsount + 1.

MOVE x_table-v_legacy TO x_alv-v_legs.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ELSE.

v_failcount = v_failcount + 1.

MOVE x_table-v_legacy TO x_alv-v_legf.

MOVE x_table-v_legacy TO x_alv1-v_legf1.

LOOP AT it_return INTO x_return.

IF x_alv1-v_msg IS INITIAL.

MOVE x_return-message TO x_alv1-v_msg.

ELSE.

CONCATENATE x_alv1-v_msg x_return-message INTO x_alv1-v_msg SEPARATED BY space.

ENDIF.

ENDLOOP.

APPEND x_alv1 TO it_alv1.

CLEAR x_alv1.

ENDIF.

ENDFORM. " bapicall

----


  • FORM DISPLAY_ALV *

----


FORM display_alv .

PERFORM x_list_header.

PERFORM build_fieldcat CHANGING x_fieldcat.

x_repid2 = sy-repid.

x_event1-name = 'TOP_OF_PAGE'.

x_event1-form = 'TOP_OF_PAGE'.

APPEND x_event1 TO x_event.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = x_repid2

is_layout = x_layout1

it_fieldcat = x_fieldcat

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

i_save = 'A'

is_variant = x_variant1

it_events = x_event

TABLES

t_outtab = it_alv

EXCEPTIONS

program_error = 1

OTHERS = 2.

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. " display_master_data

----


  • FORM USER_COMMAND *

----


FORM user_command USING ucomm LIKE sy-ucomm selfield

TYPE slis_selfield.

READ TABLE it_alv INTO x_alv INDEX selfield-tabindex.

CLEAR : x_alv2,it_alv2[].

LOOP AT it_alv1 INTO x_alv1 WHERE v_legf1 = x_alv-v_legf.

x_alv2 = x_alv1.

APPEND x_alv2 TO it_alv2 .

ENDLOOP.

DATA : it_fieldcat TYPE slis_t_fieldcat_alv.

DATA : x3_fieldcat LIKE LINE OF it_fieldcat.

CLEAR : x3_fieldcat,it_fieldcat[].

CLEAR x3_fieldcat.

x3_fieldcat-col_pos = '1'.

x3_fieldcat-fieldname = 'V_LEGF1'.

x3_fieldcat-reptext_ddic = text-111.

x3_fieldcat-ref_tabname = 'IT_ALV2'.

APPEND x3_fieldcat TO it_fieldcat.

CLEAR x3_fieldcat.

CLEAR x3_fieldcat.

x3_fieldcat-col_pos = '1'.

x3_fieldcat-fieldname = 'V_MSG'.

x3_fieldcat-reptext_ddic = text-112.

x3_fieldcat-ref_tabname = 'IT_ALV2'.

APPEND x3_fieldcat TO it_fieldcat.

CLEAR x3_fieldcat.

x_layout1-colwidth_optimize = 'X'.

x_layout1-zebra = 'X'.

IF it_alv2[] IS NOT INITIAL.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = x_repid2

is_layout = x_layout1

it_fieldcat = it_fieldcat

i_save = 'A'

i_callback_top_of_page = 'TOP'

is_variant = x_variant1

it_events = x_event

TABLES

t_outtab = it_alv2

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDIF.

ENDFORM.

----


  • FORM USER_COMMAND *

----


FORM top.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = 'Commentry'.

ENDFORM.

----


  • FORM BUILD_FIELDCAT *

----


FORM build_fieldcat CHANGING et_fieldcat TYPE slis_t_fieldcat_alv.

DATA: x1_fieldcat TYPE slis_fieldcat_alv.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '1'.

x1_fieldcat-fieldname = 'V_LEGS'.

x1_fieldcat-reptext_ddic = text-108.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '2'.

x1_fieldcat-fieldname = 'SUCCESS'.

x1_fieldcat-key = 'X'.

x1_fieldcat-reptext_ddic = text-109.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '3'.

x1_fieldcat-fieldname = 'V_LEGF'.

x1_fieldcat-key = 'X'.

x1_fieldcat-reptext_ddic = text-110.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

ENDFORM. " build_fieldcat

----


  • FORM BUILD_LIST_HEADER *

----


FORM x_list_header.

DATA: x_list_header1 TYPE slis_listheader.

*-----List Header: type H

CLEAR x_list_header1 .

x_list_header1-typ = 'H'.

x_list_header1-info = text-105.

APPEND x_list_header1 TO x_list_header.

*-----List Key: type S

x_list_header1-typ = 'S'.

x_list_header1-key = text-106.

x_list_header1-info = v_total.

APPEND x_list_header1 TO x_list_header.

*-----List Key: Type S

CLEAR x_list_header1 .

x_list_header1-typ = 'S'.

x_list_header1-key = text-107.

x_list_header1-info = v_succsount.

APPEND x_list_header1 TO x_list_header.

ENDFORM. " build_list_header

----


  • FORM TOP_OF_PAGE *

----


FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = x_list_header.

ENDFORM. " TOP_OF_PAGE

regards.

sowjanya.b

Read only

abapdeveloper20
Contributor
0 Likes
3,475

Still more info required

Read only

0 Likes
3,475

if you are using same(code)..

MOVE-CORRESPONDING it_itab TO g_bapimeposchedule.

u just add one more field DELIVERY_DATE(10) in the internal table ITAB, and also uncomment the following line..

  • g_poschedulex-DELIVERY_DATE = 'X'.

hope it will work.

Regards

Sugumar G

Read only

Former Member
0 Likes
3,475

Can BAPI_PO_CREATE1 load specific PO line numbers from a legacy system? I having a problem where the PO and lines get created fine but the lines are defaulting in 10,20,30 instead of what I am giving for lines like 110, 250, etc.

Thanks

Marshall

Read only

0 Likes
3,475

REPORT ZTEST_BAPI_PO_PR_REF.





DATA: BEGIN OF itab OCCURS 0,



      doc_type(4),

      po_item(5), "commented

      quantity(16),

*      plant(4),

*      stge_loc(4),

      PREQ_NO(10),

      PREQ_ITEM(4), "Commented

      END OF itab.



DATA: BEGIN OF it_log OCCURS 0,



      message(70) TYPE c,



      END OF it_log.



DATA: w_type(4) TYPE c.



CONSTANTS : c_x VALUE 'X'.



DATA: gstest LIKE bapimepoheader.



DATA: g_ebeln LIKE bapimepoheader-po_number.



DATA: BEGIN OF g_bapimepoheader OCCURS 0.



        INCLUDE STRUCTURE bapimepoheader.



DATA: END OF g_bapimepoheader.



DATA: BEGIN OF g_bapimepoheaderx OCCURS 0.



        INCLUDE STRUCTURE bapimepoheaderx.



DATA: END OF g_bapimepoheaderx.



DATA: BEGIN OF g_bapimeposchedule OCCURS 0.



        INCLUDE STRUCTURE bapimeposchedule.



DATA: END OF g_bapimeposchedule.



DATA: BEGIN OF g_poschedulex OCCURS 0.



        INCLUDE STRUCTURE bapimeposchedulx.



DATA: END OF g_poschedulex.



DATA: BEGIN OF g_bapieikp OCCURS 0.



        INCLUDE STRUCTURE bapieikp.



DATA: END OF g_bapieikp.



DATA: BEGIN OF g_bapimepoitem OCCURS 0.



        INCLUDE STRUCTURE bapimepoitem.



DATA: END OF g_bapimepoitem.



DATA: BEGIN OF g_poitemx OCCURS 0.



        INCLUDE STRUCTURE bapimepoitemx.



DATA: END OF g_poitemx.



DATA: BEGIN OF g_bapiret2 OCCURS 0.



        INCLUDE STRUCTURE bapiret2.



DATA: END OF g_bapiret2.



DATA: it_itab LIKE itab OCCURS 0 WITH HEADER LINE.



SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-100.



PARAMETERS : p_file LIKE rlgrap-filename.



SELECTION-SCREEN END OF BLOCK blk.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.



  PERFORM file_selection.



START-OF-SELECTION.



  PERFORM data_upload.



  PERFORM bapi_upload.



  PERFORM display.



*&----

*

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

*

*

**&      Form  file_selection

*

*&----

*

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

*

*•

*      text

*

*

*----

*

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

*

*•

* -->  p1        text

*

*•

* <--  p2        text

*

*

*----

*

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





FORM file_selection.







  CALL FUNCTION 'WS_FILENAME_GET'



    EXPORTING



      def_filename     = ' '



      def_path         = 'C:\'



      mask             = ',.txt,.txt.'



      mode             = 'O'



      title            = 'Open a TXT(Tab delimited) file only'



    IMPORTING



      filename         = p_file



    EXCEPTIONS



      inv_winsys       = 1



      no_batch         = 2



      selection_cancel = 3



      selection_error  = 4



      OTHERS           = 5.







ENDFORM.                    " file_selection







*

*

*&----

*

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

*

*

**&      Form  data_upload

*

*&----

*

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

*

*•

*      text

*

*

*----

*

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

*

*•

* -->  p1        text

*

*•

* <--  p2        text

*

*

*----

*

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

*



FORM data_upload .







  CALL FUNCTION 'WS_UPLOAD'



    EXPORTING



      filename                = p_file



      filetype                = 'DAT'



    TABLES



      data_tab                = itab



    EXCEPTIONS



      conversion_error        = 1



      file_open_error         = 2



      file_read_error         = 3



      invalid_type            = 4



      no_batch                = 5



      unknown_error           = 6



      invalid_table_width     = 7



      gui_refuse_filetransfer = 8



      customer_error          = 9



      no_authority            = 10



      OTHERS                  = 11.



  IF sy-subrc EQ 0 .



    WRITE:/ 'Program : ', sy-repid.



    WRITE:/ 'Filename: ', p_file.



    WRITE AT /1(144) sy-uline.

*•

* ELSE .

*

*•

*   MESSAGE i001.





  ENDIF.







ENDFORM.                    " data_upload



*&----

*

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

*

*

**&      Form  bapi_upload

*

*&----

*

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

*

*•

*      text

*

*

*----

*

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

*

*•

* -->  p1        text

*

*•

* <--  p2        text

*

*

*----

*

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





FORM bapi_upload .







  it_itab[] = itab[].



  SORT itab BY PREQ_NO PREQ_ITEM.



  DELETE ADJACENT DUPLICATES FROM itab COMPARING PREQ_NO.







  LOOP AT itab.







    MOVE-CORRESPONDING itab TO g_bapimepoheader.



    w_type = itab-doc_type.





    g_bapimepoheader-creat_date = sy-datum.



    g_bapimepoheader-created_by = sy-uname.



    APPEND g_bapimepoheader.



    g_bapimepoheaderx-doc_type = 'X'.





    APPEND g_bapimepoheaderx.









    LOOP AT it_itab. "WHERE vendor = itab-vendor.



      MOVE-CORRESPONDING it_itab TO g_bapimepoitem.





      APPEND g_bapimepoitem.



      MOVE-CORRESPONDING it_itab TO g_bapimeposchedule.



      APPEND g_bapimeposchedule.



      g_poitemx-po_item = it_itab-po_item.



      g_poitemx-po_itemx = 'X'. "commented



      g_poitemx-quantity = 'X'.



*      g_poitemx-plant = 'X'.



*      g_poitemx-stge_loc = 'X'.



      g_poitemx-PREQ_NO = 'X'.

      g_poitemx-PREQ_ITEM = 'X'. "Commented



      APPEND g_poitemx.





      g_poschedulex-po_item = it_itab-po_item.



      g_poschedulex-po_itemx = 'X'.



      APPEND g_poschedulex.



    ENDLOOP.











    CALL FUNCTION 'BAPI_PO_CREATE1'



      EXPORTING



        poheader                     = g_bapimepoheader



        poheaderx                    = g_bapimepoheaderx





     IMPORTING



       exppurchaseorder             = g_ebeln



     TABLES



       return                       = g_bapiret2



       poitem                       = g_bapimepoitem



       poitemx                      = g_poitemx



       poschedule                   = g_bapimeposchedule



       poschedulex                  = g_poschedulex

            .



    IF NOT g_ebeln IS INITIAL.



      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'



        EXPORTING



          wait = ''.



      IF w_type = 'ZTRM'.



        CONCATENATE 'LIS Trade Material created under the number' '-'



        g_ebeln INTO it_log-message.



        APPEND it_log.



        CLEAR it_log.



      ELSE.



        CONCATENATE 'LIS STO Plant-Plant created under the number' '-'



        g_ebeln INTO it_log-message.



        APPEND it_log.



        CLEAR it_log.



      ENDIF.







      CLEAR : it_itab,w_type,g_bapimepoitem,g_bapimepoheader,



      g_bapimepoheaderx,g_bapiret2,g_poitemx,g_bapimeposchedule,



      g_poschedulex.











      REFRESH : g_bapimepoitem,g_bapimepoheader,g_bapimepoheaderx,



      g_bapiret2,g_poitemx,g_bapimeposchedule,g_poschedulex.







    ENDIF.



  ENDLOOP.



ENDFORM.                    " bapi_upload









*

**----

*

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

*

*&----

*

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

*

*

**&      Form  display

*

*&----

*

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

*

*•

*      text

*

*

*----

*

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

*

*•

* -->  p1        text

*

*•

* <--  p2        text

*

*

*----

*

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





FORM display .



  LOOP AT g_bapiret2.



    WRITE :/ g_bapiret2-message.



  ENDLOOP.



  LOOP AT it_log.



    WRITE :/ it_log-message.



  ENDLOOP.



ENDFORM.

My Input FILE is :

NB 10 1 15745271 10   ( this is tab de limited)

Please help me to resolve this issue.

Note i am able create PO by referring PR in another system. If i copy same code to my system it is giving error.

Regards,