Skip to Content
-2
Jan 12, 2017 at 11:14 AM

Error in BAPI_RESERVATION_CREATE Program?

298 Views

Hi,

Pl find my coding below, while executing the same, the value of the cost center field is saved to Profit center field in RKPF table,

pl suggest.

type-pools :truxs.
selection-screen begin of block blck with frame title text-011.
parameters:p_file type rlgrap-filename .

selection-screen end of block blck.

types: begin of st_resb,

bwart type rkpf-bwart,
werks type resb-werks,
matnr type resb-matnr,
erfmg type resb-erfmg,
lgort type resb-lgort,
end of st_resb.

data:it_itab type table of st_itab,
wa_itab type st_itab,
it_raw type truxs_t_text_data.

at selection-screen on value-request for p_file. "F1 help for file input

call function 'F4_FILENAME'
exporting
field_name = 'P_FILE'
importing
file_name = p_file.



start-of-selection.

call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =
* i_line_header = p_head
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
tables
i_tab_converted_data = it_itab[] "ACTUAL DATA
exceptions
conversion_failed = 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.



data :wa1_headdata type bapirkpfc,
wa_headdata type bapirkpfc ,
it2_headdata type bapirkpfc,
it_itemdata type table of bapiresbc,
wa_itemdata type bapiresbc,
wa_return type bapireturn occurs 0 with header line .

data: res_no like bapirkpfc-res_no,
tlines type i.

loop at it_itab into wa_itab.

wa_headdata-res_date = sy-datum.
* WA_HEADDATA-MOVE_PLANT = WA_ITAB-WERKS.
wa_headdata-move_type = wa_itab-bwart.
wa_headdata-cost_ctr = wa_itab-kostl.
* WA_HEADDATA-CREATED_BY = SY-UNAME.


*LOOP AT IT_ITAB INTO WA_ITAB.
wa_itemdata-material = wa_itab-matnr.
wa_itemdata-quantity = wa_itab-erfmg.
wa_itemdata-store_loc = wa_itab-lgort.
wa_itemdata-plant = wa_itab-werks.
wa_itemdata-req_date = sy-datum.
append wa_itemdata to it_itemdata.
clear wa_itemdata.
perform check.
clear wa_resb.
endloop.

*BREAK-POINT.
call function 'BAPI_RESERVATION_CREATE'
exporting
reservation_header = wa_headdata
* NO_COMMIT =
movement_auto ='X'
importing
reservation = res_no
tables
reservation_items = it_itemdata
* RETURN =
.
*BREAK-POINT.

call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'
* IMPORTING
* RETURN = WA_RETURN
.
*BREAK-POINT.

describe table wa_return lines tlines.
if tlines gt 0.
format color col_negative.
write : / 'Update Failed.',wa_return-message(200), 255 ' '.
else.
format color col_normal.
write :res_no, 'Reservation created successfully ', 255 ' '.
endif.
form check.
loop at it_resb into wa_resb.
wa1_headdata-move_type = wa_resb-bwart.


if wa1_headdata-move_type ne wa_headdata-move_type.
message 'Pl Maintain a Single movement type throughout the Excel file' type 'A'.
endif.
endloop.
endform.