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

Hepl need in code

Former Member
0 Likes
857

Hi all,

I am trying to create a reservation using bapi, its returning a value of

000000000

select * from mard into table itab up to 10 rows

where werks = 'xxx'

AND LGORT = 'xxx'.

  • Prepare header data

w_resb_header-plant = 'xxx'.

w_resb_header-res_date = sy-datum.

w_resb_header-created_by = sy-uname.

w_resb_header-cost_ctr = s_kostl.

w_resb_header-move_type = s_bwart.

loop at itab.

itab_resb-material = itab-MATNR.

itab_resb-plant = ITAB-werks.

itab_resb-store_loc = ITAB-lgort.

itab_resb-quantity = 1.

itab_resb-unit = 'EA'.

append itab_resb.

clear itab_resb.

endloop.

CALL FUNCTION 'BAPI_RESERVATION_CREATE'

EXPORTING

RESERVATION_HEADER = w_resb_header

  • NO_COMMIT =

  • MOVEMENT_AUTO =

IMPORTING

RESERVATION = w_resb_no

TABLES

RESERVATION_ITEMS = itab_resb

RETURN = itab_bapi_return

.

WRITE : / w_resb_no.

7 REPLIES 7
Read only

uwe_schieferstein
Active Contributor
0 Likes
810

Hello Swathi

Do not forget to commit your work using BAPI_TRANSACTION_COMMIT (perhaps with WAIT = 'X').

Regards

Uwe

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
810

I need to see the entire program. Please post.

Regards

Rich Heilman

Read only

Former Member
0 Likes
810

Hi

u r using append stmt with in a loop its goin infinite loop

can u chk it out

Read only

0 Likes
810

If you post the entire code, it would be helpful.

Also you did not specify if there were any errors. I assume you are checking the BAPI return structure for any errors.

Read only

Former Member
0 Likes
810

Hi Swathi,

Here BAPI is returning some errors, that's why it's not creating reservation. U can catch the errors by checking the itab_bapi_return. Please check this sample of code :

DATA: BEGIN OF itab_resb OCCURS 10.

INCLUDE STRUCTURE bapiresbc.

DATA: END OF itab_resb.

DATA: BEGIN OF w_resb_header.

INCLUDE STRUCTURE bapirkpfc.

DATA: END OF w_resb_header.

DATA: w_resb_no LIKE resb-rsnum.

DATA: BEGIN OF return OCCURS 10.

INCLUDE STRUCTURE bapireturn.

DATA: END OF return.

DATA : itab TYPE TABLE OF mard WITH HEADER LINE.

SELECT * FROM mard INTO TABLE itab UP TO 10 ROWS

WHERE werks = 'xxx'

AND lgort = 'xxx'.

w_resb_header-created_by = sy-uname.

w_resb_header-res_date = sy-datlo.

LOOP AT itab.

itab_resb-material = itab-matnr.

itab_resb-plant = itab-werks.

itab_resb-store_loc = itab-lgort.

itab_resb-quantity = 1.

itab_resb-unit = 'EA'.

APPEND itab_resb.

CLEAR itab_resb.

ENDLOOP.

CLEAR itab_bapi_return.

REFRESH itab_bapi_return.

CALL FUNCTION 'BAPI_RESERVATION_CREATE'

EXPORTING

reservation_header = w_resb_header

IMPORTING

reservation = w_resb_no

TABLES

reservation_items = itab_resb

return = itab_bapi_return

EXCEPTIONS

OTHERS = 0.

IF itab_bapi_return[] IS INITIAL.

DATA: return TYPE bapiret2.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

IMPORTING

return = return.

WRITE : / w_resb_no.

ELSE.

ROLLBACK WORK.

ENDIF.

Hope this would help u in some way.

Read only

ivan_ivanov119
Explorer
0 Likes
810

Hi there,

the following code is never true:

"...itab_bapi_return[] IS INITIAL."

the bapi always gives you something in return ... that's the idea of the return codes in general.

Try checking this:

itab_bapi_return-TYPE = 'S'

that means that the bapi has finished with success.

Hope it helps.

Cheers,

Ivan

Read only

uwe_schieferstein
Active Contributor
0 Likes
810

Hello Swathi

I must disagree with Ivan that BAPIs will always return a suceess message. For me a BAPI was executed successfully if it returns either a S(uccess) message or nothing.

Regards

Uwe