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

Need sample code for BAPI

Former Member
0 Likes
1,433

Hi,

I want a sample code for BAPI(ex: bapi for creating purchase order) I knew the BAPI which is used for this purpose is BAPI_PO_CREATE. But i want to know the code how the parameters are passed and how the declarations are done. Since i am new for this topic please help me in providing material and code for this.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,282

hi,

Follow the link for step by step tutorial.

http://www.saptechnical.com/Tutorials/BAPI/BAPIMainPage.htm

BAPI-step by step

http://www.sapgenie.com/abap/bapi/example.htm

Hope this helps, Do reward.

4 REPLIES 4
Read only

Former Member
0 Likes
1,282

Hai ,

GO through This Code Snippet For BAPI's.

&----

-


*& Report Z_PED_TRAS *

*& *

&----

-


*& *

*& *

&----

-


REPORT z_ped_tras .

Definición de la tabla asociada la tabla interna bdcdata

*DATA :in_data LIKE bdcdata OCCURS 0 WITH HEADER LINE.

Definición de la estructura que contendrá los pedidos

DATA : s_cabeceras_pedidos LIKE bapiekkoc,

s_pos_pedidos LIKE bapiekpoc.

DATA : t_cabeceras_pedidos LIKE bapiekkoc OCCURS 0 WITH HEADER LINE,

t_pos_pedidos LIKE bapiekpoc OCCURS 0 WITH HEADER LINE,

t_final_cabeceras_pedidos LIKE bapiekkoc OCCURS 0 WITH HEADER

LINE,

t_final_pos_pedidos LIKE bapiekpoc OCCURS 0 WITH HEADER LINE.

Data : item_schedule like BAPIEKET occurs 0 with header line.

*DATA : BEGIN OF pedidos,

ematn TYPE mepo1211-ematn, "Número de material

menge TYPE mepo1211-menge, "Cantidad de pedido

name1 TYPE mepo1211-name1," Centro destino

lgobe TYPE mepo1211-lgobe, "Almacén

END OF pedidos.

*

*

*DATA: s_pedidos LIKE pedidos,

wa_pedidos LIKE pedidos,

t_pedidos LIKE pedidos OCCURS 0 .

Variables auxiliaires

Variables para la ejecución del explorador de archivos

DATA: l_temp_dir TYPE string.

DATA: l_filter TYPE string.

DATA: l_files TYPE filetable.

DATA: l_rc TYPE i.

DATA: l_file TYPE filename.

DATA: l_filename TYPE string.

DATA: excel TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.

DATA: s_excel TYPE alsmex_tabline.

DATA: qid LIKE apqi-qid.

Declaración de parametros de selección

PARAMETERS :

p_center LIKE bapiekkoc-suppl_plnt OBLIGATORY,"" Proveedor/Centro

p_ekorg LIKE bapiekkoc-purch_org OBLIGATORY , " Organización compras

p_ekgrp LIKE bapiekkoc-pur_group OBLIGATORY, " Grupo de compras

p_bukrs LIKE bapiekkoc-co_code OBLIGATORY,"Sociedad"

p_date LIKE sy-datum DEFAULT sy-datum OBLIGATORY, "fecha

test AS CHECKBOX DEFAULT 'X'.

p_center LIKE mepo_topline-superfield, " Proveedor/Centro

p_ekorg LIKE mepo1222-ekorg, " Organización de compras

p_ekgrp LIKE mepo1222-ekgrp, " Grupo de compras

p_bukrs LIKE mepo1222-bukrs,"Sociedad"

p_date LIKE sy-datum," Fecha

test AS CHECKBOX DEFAULT 'X'.

PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'C:PEDIDOS.XLS'. " Ruta

Carga del explorador de ficheros **

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

l_temp_dir = 'C:A'.

l_filter = '.'.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

default_extension = '*.xls'

file_filter = l_filter

initial_directory = l_temp_dir

CHANGING

file_table = l_files

rc = l_rc

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4

OTHERS = 5.

IF NOT l_files[] IS INITIAL.

READ TABLE l_files INTO l_file INDEX 1.

p_file = l_file.

TRANSLATE p_file TO UPPER CASE.

ENDIF.

*******************************************************************

START-OF-SELECTION.

IF p_file NE space.

PERFORM upload_data.

PERFORM fill_data.

PERFORM llamar_bapi.

ENDIF.

END-OF-SELECTION.

************************************************************************

&----

-


*& Form Upload_data

&----

-


text

-

-


--> p1 text

<-- p2 text

-

-


FORM upload_data .

IF excel IS INITIAL .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = 1

i_begin_row = 2

i_end_col = 4

i_end_row = 50000

TABLES

intern = excel

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc 0.

WRITE :/'Hay un problema al cargar los datos delfichero excell'.

ENDIF.

SORT excel DESCENDING BY row col.

ENDIF.

ENDFORM. " Upload_data

&----

-


*& Form fill_excell

&----

-


text

-

-


--> p1 text

<-- p2 text

-

-


FORM fill_data .

DATA : cant TYPE i ,

value_row TYPE i VALUE 1,

data_aux TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.

Leer las filas del fichero excell.

IF test NE 'X'.

s_cabeceras_pedidos-suppl_plnt = p_center.

s_cabeceras_pedidos-purch_org = p_ekorg.

s_cabeceras_pedidos-pur_group = p_ekgrp .

s_cabeceras_pedidos-co_code = p_bukrs .

s_cabeceras_pedidos-doc_date = p_date.

APPEND s_cabeceras_pedidos TO t_cabeceras_pedidos.

cant = excel-row.

DO cant TIMES.

LOOP AT excel WHERE row EQ value_row.

APPEND excel TO data_aux.

ENDLOOP.

SORT data_aux BY col.

LOOP AT data_aux.

CASE data_aux-col.

WHEN '1'.

s_pos_pedidos-pur_mat = data_aux-value.

WHEN '2'.

s_pos_pedidos-DISP_QUAN = data_aux-value.

WHEN '3'.

s_pos_pedidos-plant = data_aux-value.

WHEN '4'.

s_pos_pedidos-store_loc = data_aux-value.

ENDCASE.

ENDLOOP.

APPEND s_pos_pedidos TO t_pos_pedidos.

ENDDO.

ENDIF.

ENDFORM. " fill_data

&----

-


*& Form llamar_Bapi

&----

-


text

-

-


--> p1 text

<-- p2 text

-

-


FORM llamar_bapi .

data : T_RETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE,

PORDER LIKE BAPIEKKOC-PO_NUMBER.

t_final_cabeceras_pedidos] = t_cabeceras_pedidos[.

t_final_pos_pedidos] = t_pos_pedidos[.

CALL FUNCTION 'BAPI_PO_CREATE'

EXPORTING

po_header = t_final_cabeceras_pedidos

IMPORTING

PURCHASEORDER = PORDER

TABLES

po_items = t_final_pos_pedidos

po_item_schedules = item_schedule

RETURN = T_RETURN

.

IF sy-subrc EQ 0 .

WRITE 😕 'P O created well'.

ELSE .

WRITE 😕 'P .O was not created well'.

endif.

ENDFORM. " llamar_Bapi

Read only

Former Member
0 Likes
1,282

here is a sample code

BAPI_PO_CREATE

--> PERFORM po_item_generate

--> CALL FUNCTION 'ME_CREATE_PO_ITEM'

--> PERFORM si_generate(sapmm06e)

--> PERFORM SI_CREATE

--> CALL FUNCTION 'ME_CREATE_SUB_ITEM'

--> PERFORM rm06e-skondi_fc

--> IF KOMP-NETWR LE 0.

MESSAGE E215(06).

ENDIF.[/code]

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

-


use the link

hope it helps u,Do reward

Read only

Former Member
0 Likes
1,283

hi,

Follow the link for step by step tutorial.

http://www.saptechnical.com/Tutorials/BAPI/BAPIMainPage.htm

BAPI-step by step

http://www.sapgenie.com/abap/bapi/example.htm

Hope this helps, Do reward.

Read only

Former Member
0 Likes
1,282

Hi Ramya,

send me ur personal mail_id , i have docus on this ,details please view my Business Card

Regards

Fareedas

Edited by: Fareeda Tabassum S on Mar 10, 2008 12:31 PM

Edited by: Fareeda Tabassum S on Mar 10, 2008 12:32 PM