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: 

Reg: Modification of Master Tables using BDC/BAPI

Former Member
0 Kudos

Dear All,

Thanks for Support shown from all of you.

I want the detailed procedure for Modifying the existing data in the Master Tables using BDC's / BAPI's and Dialog programming.

Please send me one example code.

Please Help me Out.

Thanks In Advance.

Regards,

Adinarayana.B

9 REPLIES 9

hymavathi_oruganti
Active Contributor
0 Kudos

bapi example

REPORT ZMMR_DELETEPO NO STANDARD PAGE HEADING MESSAGE-ID zisb.

tables : zvtls_sap.

*C-- Types Declarations

TYPES : BEGIN OF tp_flatfile_vtls,

ebeln(10),

ebelp type ekpo-ebelp,

END OF tp_flatfile_vtls.

*=====================================================================

  • INTERNAL TABLES DECLARATION

*=====================================================================

DATA: t_flatfile_vtls TYPE tp_flatfile_vtls OCCURS 0 WITH HEADER LINE.

data : begin of t_sapdata occurs 0,

po like zvtls_sap-posap,

item like zvtls_sap-itemsap,

end of t_sapdata.

data : begin of t_flatfile_vtls1 occurs 0,

po(10),

item like zvtls_sap-itemsap,

end of t_flatfile_vtls1.

data : begin of t_update occurs 0,

mandt like zvtls_sap-mandt,

povtls like zvtls_sap-povtls,

itemvtls like zvtls_sap-itemvtls,

posap like zvtls_sap-posap,

itemsap like zvtls_sap-itemsap,

aedat like zvtls_sap-aedat,

paedt like zvtls_sap-paedt,

loekz like zvtls_sap-loekz,

end of t_update.

data : begin of t_poheader occurs 0,

po like zvtls_sap-posap,

end of t_poheader.

data : begin of t_poitem occurs 0,

po like zvtls_sap-posap,

item like zvtls_sap-itemsap,

end of t_poitem.

DATA : BEGIN OF T_MESSAGE OCCURS 0,

MSGTY,

MSGID(2),

MSGNO(3),

MSGTX(100),

PO like zvtls_sap-povtls,

item like zvtls_sap-itemvtls,

END OF T_MESSAGE.

DATA : BEGIN OF t_bapi_poheader OCCURS 0.

INCLUDE STRUCTURE bapimepoheader.

DATA : END OF t_bapi_poheader.

DATA : BEGIN OF t_bapi_poheaderx OCCURS 0.

INCLUDE STRUCTURE bapimepoheaderx.

DATA : END OF t_bapi_poheaderx.

DATA : BEGIN OF t_bapi_poitem OCCURS 0.

INCLUDE STRUCTURE bapimepoitem.

DATA : END OF t_bapi_poitem.

DATA : BEGIN OF t_bapi_poitemx OCCURS 0.

INCLUDE STRUCTURE bapimepoitemx.

DATA : END OF t_bapi_poitemx.

DATA : BEGIN OF t_bapireturn OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA : END OF t_bapireturn.

*=====================================================================

  • V A R I A B L E S

*=====================================================================

DATA: w_success(6) TYPE n,

w_bklas like t023-bklas,

w_curryear(4),

w_begda like sy-datum,

w_endda like sy-datum,

w_begyr(4),

w_endyr(4),

w_currmon(2),

w_assetclass like ankt-anlkl,

w_price type p,

w_recordsap type i,

w_povtls(10),

w_count type i.

DATA: w_filepath TYPE rlgrap-filename,

w_rc TYPE sy-subrc,

w_sscrfields_ucomm1 TYPE sscrfields-ucomm,

w_file1 TYPE string,

w_file2 TYPE FILENAME-FILEINTERN.

*=====================================================================

  • C O N S T A N T S

*=====================================================================

CONSTANTS: c_x TYPE c VALUE 'X',

c_hyp TYPE c VALUE '-',

c_err TYPE bdc_mart VALUE 'E'.

CONSTANTS: c_slash(1) TYPE c VALUE '/',

c_hash(1) TYPE c VALUE '#',

c_pipe TYPE c VALUE '|',

c_1 TYPE i VALUE 1,

c_zero TYPE n VALUE '0',

c_rg1(3) TYPE c VALUE 'rg1',

c_gr3(3) TYPE c VALUE 'GR3',

c_gr2(3) TYPE c VALUE 'GR2',

c_e(1) TYPE c VALUE 'E',

c_filepath(8) TYPE c VALUE '/interf/',

c_filetype(10) TYPE c VALUE 'ASC'.

CONSTANTS : c_bapimepoheaderx TYPE x030l-tabname

VALUE 'bapimepoheaderx',

c_bapimepoitem TYPE x030l-tabname

VALUE 'bapimepoitem',

c_bapimepoaccount TYPE x030l-tabname

VALUE 'bapimepoaccount',

c_t_bapi_poheader(15) TYPE c

VALUE 't_bapi_poheader',

c_t_bapi_poitem(13) TYPE c

VALUE 't_bapi_poitem',

c_t_bapi_poitemx(14) TYPE c

VALUE 't_bapi_poitemx',

c_t_bapi_poheaderx(16) TYPE c

VALUE 't_bapi_poheaderx'.

CLASS cl_abap_char_utilities DEFINITION LOAD.

CONSTANTS:con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

*======================================================================

  • SELECTION SCREEN

*======================================================================

SELECTION-SCREEN BEGIN OF BLOCK inputpath WITH FRAME TITLE text-001.

SELECTION-SCREEN : BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.

PARAMETERS : p_fore RADIOBUTTON GROUP rg1

USER-COMMAND pc,

p_back RADIOBUTTON GROUP rg1 DEFAULT 'X'.

SELECTION-SCREEN : END OF BLOCK blk2.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-003.

PARAMETERS : p_file1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr2.

PARAMETERS : p_afile1 LIKE rlgrap-filename OBLIGATORY MODIF ID gr3.

SELECTION-SCREEN : END OF BLOCK blk1.

SELECTION-SCREEN END OF BLOCK inputpath.

*C-- Initialization Event

INITIALIZATION.

CLEAR w_filepath.

CONCATENATE c_filepath sy-sysid c_slash sy-mandt c_slash INTO

w_filepath.

CONDENSE w_filepath NO-GAPS.

p_file1 = text-008.

p_afile1 = text-009.

*======================================================================

  • SELECTION SCREEN EVENTS

*======================================================================

*C-- Selection Screen Output

AT SELECTION-SCREEN OUTPUT.

IF p_fore = c_x.

w_sscrfields_ucomm1 = space.

ELSE.

w_sscrfields_ucomm1 = c_rg1.

ENDIF.

LOOP AT SCREEN.

*C--Modify selection screen if presentation

*C--or application server radio button is chosen

IF w_sscrfields_ucomm1 = space.

IF screen-group1 = c_gr3.

screen-active = c_zero.

ENDIF.

ELSE.

IF screen-group1 = c_gr2.

screen-active = c_zero.

ENDIF.

ENDIF.

if screen-name = 'P_AFILE1'.

screen-input = 0.

ENDIF.

MODIFY SCREEN.

ENDLOOP.

*C-- Selection Screen VALUE-REQUEST FOR File path

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.

IF p_fore EQ c_x.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file1.

ENDIF.

*C-- At Start of the Selection Process

START-OF-SELECTION.

IF p_fore EQ c_x.

w_file1 = p_file1.

ELSE.

w_file2 = p_afile1.

ENDIF.

IF p_fore EQ c_x. " Presentaion Server

*C--Validations for the input files

PERFORM validate_pre_file USING p_file1.

*C-- Load the contents of the input file into the internal table

PERFORM upload_file TABLES t_flatfile_vtls

USING w_file1

CHANGING w_rc.

IF w_rc <> 0.

MESSAGE s006 DISPLAY LIKE c_e.

ENDIF.

ELSE. " Application Server

*C--Validations for the input files

PERFORM validate_app_file USING w_file2.

*C-- Load the contents of the input file into the internal table

PERFORM upload_file_app TABLES t_flatfile_vtls

USING w_file2

CHANGING w_rc.

ENDIF.

loop at t_flatfile_vtls.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = t_flatfile_vtls-ebeln

IMPORTING

output = t_flatfile_vtls1-po.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = t_flatfile_vtls-ebelp

IMPORTING

output = t_flatfile_vtls1-item.

append t_flatfile_vtls1.

clear t_flatfile_vtls1.

endloop.

perform get_podata.

loop at t_poheader.

perform move_to_bapi.

perform call_bapi.

endloop.

PERFORM STORE_MESSAGES TABLES T_MESSAGE.

*&----


*

*& Form validate_pre_file

*&----


*

  • Routine to validate presentation server file path.

*----


*

  • -->fp_name text

*----


*

FORM validate_pre_file USING fp_name TYPE rlgrap-filename.

DATA : l_result,

l_filename TYPE string.

l_filename = fp_name.

CLEAR l_result.

CALL METHOD cl_gui_frontend_services=>file_exist

EXPORTING

file = l_filename

RECEIVING

result = l_result

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE s007 DISPLAY LIKE c_e.

LEAVE LIST-PROCESSING.

ELSEIF l_result IS INITIAL.

MESSAGE s008 DISPLAY LIKE c_e.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " validate_pre_file_hdr

*&----


*

*& Form validate_app_file

*&----


*

  • text - Checks if the path entered and filename is correct

*----


*

FORM validate_app_file USING fp_file TYPE FILENAME-FILEINTERN.

data : l_fname(60).

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

LOGICAL_FILENAME = FP_FILE

OPERATING_SYSTEM = SY-OPSYS

IMPORTING

FILE_NAME = L_FNAME

EXCEPTIONS

FILE_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC = '0'.

OPEN DATASET L_FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE s007 DISPLAY LIKE c_e.

ELSE.

CLOSE DATASET l_fname.

ENDIF.

ENDIF.

ENDFORM. " validate_app_file

*&----


*

*& Form upload_file

*&----


*

  • Routine to upload data from file to tables.

*----


*

  • -->P_fp_flatfile

  • -->P_fp_file

  • <--P_fp_rc

*----


*

FORM upload_file TABLES fp_flatfile

USING fp_file TYPE string

CHANGING fp_rc TYPE sy-subrc.

IF fp_flatfile[] IS INITIAL.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = fp_file

filetype = c_filetype

has_field_separator = c_x

TABLES

data_tab = fp_flatfile

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.

MOVE sy-subrc TO fp_rc.

ENDIF.

ENDFORM. " upload_file

&----


*& Form upload_file_app

&----


  • text

----


  • -->FP_FLATFILEtext

  • -->FP_FILE text

  • -->FP_RC text

----


FORM upload_file_app TABLES fp_flatfile

USING fp_file TYPE FILENAME-FILEINTERN

CHANGING fp_rc TYPE sy-subrc.

DATA: l_string TYPE tedata-data.

DATA: wa_data_file TYPE tp_flatfile_vtls,

l_wllength TYPE i,

FNAME(60).

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

LOGICAL_FILENAME = FP_FILE

OPERATING_SYSTEM = SY-OPSYS

IMPORTING

FILE_NAME = FNAME

EXCEPTIONS

FILE_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC = 0.

OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

  • *C-- commented by Bikash

  • MESSAGE s107(yaero_ps) DISPLAY LIKE c_e.

message e008.

ELSE.

DO.

CLEAR: l_string.

READ DATASET FNAME INTO l_string LENGTH l_wllength.

IF sy-subrc NE 0.

EXIT.

ELSE.

SPLIT l_string AT con_tab INTO wa_data_file-ebeln

wa_data_file-ebelp.

APPEND wa_data_file TO fp_flatfile.

ENDIF.

ENDDO.

CLOSE DATASET FNAME.

ENDIF.

ENDIF.

ENDFORM. " upload_file_app

&----


*& Form get_podata

&----


  • text

----


form get_podata.

select *

into table t_update

from zvtls_sap

for all entries in t_flatfile_vtls1

where itemvtls = t_flatfile_vtls1-item

and povtls = t_flatfile_vtls1-po.

sort t_update by posap itemsap.

loop at t_update.

at new posap.

t_poheader-po = t_update-posap.

append t_poheader.

clear t_poheader.

endat.

t_poitem-po = t_update-posap.

t_poitem-item = t_update-itemsap.

append t_poitem.

clear t_poitem.

t_update-paedt = sy-datum.

t_update-loekz = 'X'.

modify t_update.

endloop.

modify zvtls_sap from table t_update.

endform. "get_podata

&----


*& Form move_to_bapi

&----


  • text

----


form move_to_bapi.

t_bapi_poheader-po_number = t_poheader-po.

CLEAR t_bapi_poheaderx.

PERFORM fill_check_structure USING c_bapimepoheaderx

c_t_bapi_poheader

c_t_bapi_poheaderx

c_x.

refresh : t_bapi_poitem,t_bapi_poitemx.

loop at t_poitem where po = t_poheader-po.

clear t_bapi_poitem.

t_bapi_poitem-po_item = t_poitem-item.

t_bapi_poitem-delete_ind = 'X'.

CLEAR t_bapi_poitemx.

PERFORM fill_check_structure USING c_bapimepoitem

c_t_bapi_poitem

c_t_bapi_poitemx

c_x.

t_bapi_poitemx-po_item = t_poitem-item.

t_bapi_poitemx-po_itemx = c_x.

APPEND t_bapi_poitem.

APPEND t_bapi_poitemx.

clear t_bapi_poitem.

clear t_bapi_poitemx.

endloop.

endform. "move_to_bapi

*&----


*

*& Form call_bapi

*&----


*

  • This form Routine is used to commit the data records

----


FORM call_bapi .

DATA : l_msgty TYPE c,

l_msgid(2) TYPE c,

l_msgno(3) TYPE c,

l_msgtx(100) TYPE c,

l_errflag TYPE c.

CLEAR: t_bapireturn.

REFRESH: t_bapireturn.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

PURCHASEORDER = T_POHEADER-PO

POHEADER = T_BAPI_POHEADER

POHEADERX = T_BAPI_POHEADERX

TABLES

RETURN = T_BAPIRETURN

POITEM = T_BAPI_POITEM

POITEMX = T_BAPI_POITEMX.

READ TABLE t_bapireturn WITH KEY type = c_err TRANSPORTING NO FIELDS.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = c_x.

ENDIF.

*C-- Write messages

WRITE: / 'PO Number', t_poheader-po.

clear : t_update,w_povtls.

read table t_update with key posap = t_poheader-po.

w_povtls = t_update-povtls.

CLEAR l_errflag.

LOOP AT t_bapireturn.

CLEAR: l_msgty, l_msgid, l_msgno, l_msgtx.

l_msgty = t_bapireturn-type.

l_msgid = t_bapireturn-id.

l_msgno = t_bapireturn-number.

l_msgtx = t_bapireturn-message.

WRITE: / l_msgty, l_msgid, l_msgno, l_msgtx.

if l_msgtx cs t_poheader-po.

w_count = w_count + 1.

loop at t_update.

if sy-tabix = w_count.

t_message-item = t_update-itemvtls.

endif.

endloop.

endif.

t_message-msgty = l_msgty.

t_message-msgid = l_msgid.

t_message-msgno = l_msgno.

t_message-msgtx = l_msgtx.

t_message-po = w_povtls.

append t_message.

clear t_message.

IF l_msgty EQ c_err.

l_errflag = c_x.

ENDIF. " l_msgty EQ 'E'

ENDLOOP.

ULINE.

IF l_errflag NE c_x.

w_success = w_success + 1.

ENDIF. " l_errflag NE C_X

endform. "call_bapi

*&----


*

*& Form fill_check_structure

*&----


*

  • This form Routine will check whether the specified structure

  • exist/active

*----


*

FORM fill_check_structure USING fp_tabname TYPE any

fp_orgtabname TYPE any

fp_chktabname TYPE any

fp_check TYPE c.

FIELD-SYMBOLS : <fs_chk>, <fs_org>.

DATA: l_char1(61) TYPE c,

l_char2(61) TYPE c.

DATA: BEGIN OF tl_nametab OCCURS 60.

INCLUDE STRUCTURE x031l.

DATA: END OF tl_nametab.

REFRESH tl_nametab.

CALL FUNCTION 'RFC_GET_NAMETAB'

EXPORTING

tabname = fp_tabname

TABLES

nametab = tl_nametab

EXCEPTIONS

table_not_active = 1

OTHERS = 2.

IF sy-subrc <> 0.

CLEAR tl_nametab.

ENDIF.

LOOP AT tl_nametab.

CLEAR: l_char1, l_char2.

CONCATENATE fp_chktabname c_hyp tl_nametab-fieldname INTO l_char1.

ASSIGN (l_char1) TO <fs_chk>.

CONCATENATE fp_orgtabname c_hyp tl_nametab-fieldname INTO l_char2.

ASSIGN (l_char2) TO <fs_org>.

IF <fs_org> IS NOT INITIAL.

<fs_chk> = fp_check.

ENDIF.

ENDLOOP.

ENDFORM. " fill_check_structure

&----


*& Form STORE_MESSAGES

&----


  • text

----


  • -->FP_MESSAGEStext

----


FORM STORE_MESSAGES TABLES FP_MESSAGES STRUCTURE T_MESSAGE.

DATA: wl_output_data LIKE t_MESSAGE.

DATA: l_catstr TYPE string.

DATA: l_fieldvalue TYPE string.

DATA: l_index TYPE i VALUE 1.

DATA: L_FNAME(60).

FIELD-SYMBOLS <fs>.

CLEAR l_catstr.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

LOGICAL_FILENAME = '/USR/SAP/VTLS/POCHANGE/LOG'

OPERATING_SYSTEM = SY-OPSYS

IMPORTING

FILE_NAME = L_FNAME

EXCEPTIONS

FILE_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC = '0'.

IF fp_messages[] IS NOT INITIAL.

OPEN DATASET L_FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

LEAVE LIST-PROCESSING.

ELSE.

LOOP AT fp_messages INTO wl_output_data.

DO.

ASSIGN COMPONENT l_index OF STRUCTURE wl_output_data TO <fs>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

MOVE <fs> TO l_fieldvalue.

IF l_catstr IS NOT INITIAL.

CONCATENATE l_catstr l_fieldvalue INTO l_catstr SEPARATED

BY con_tab.

ELSE.

MOVE l_fieldvalue TO l_catstr.

ENDIF.

l_index = l_index + c_1.

CLEAR l_fieldvalue.

CLEAR <fs>.

ENDDO.

l_index = c_1.

TRANSFER l_catstr TO L_FNAME .

CLEAR wl_output_data.

CLEAR l_catstr.

ENDLOOP.

CLOSE DATASET L_FNAME.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. "STORE_MESSAGES

hymavathi_oruganti
Active Contributor
0 Kudos

bdc example

REPORT ZMM_BDC_CONFIRMATION_UPLOAD

NO STANDARD page heading

message-id ZV.

include bdcrecx1.

TABLES: EKPO,EKES.

data : begin of t_itab occurs 0,

ebeln like ekko-ebeln,

ebelp like ekpo-ebelp,

bstae like ekpo-bstae,

ebtyp like ekes-ebtyp ,

eindt(10),

menge like ekes-menge,

xblnr like ekes-xblnr,

end of t_itab.

DATA: BEGIN OF record,

ebeln type ebeln,

ebelp type ebelp,

END OF record.

      • creating an internal table containg the Items***

DATA : t_tab LIKE record OCCURS 0 WITH HEADER LINE.

PARAMETER : filename LIKE rlgrap-filename OBLIGATORY.

***declaring temporary variables

DATA :

v_cnt(2) TYPE n,

v_bst(2) TYPE n,

v_bn type i,

v_bstpo(25),

v_ebtyp(25),

v_menge(25),

v_eeind(25),

v_xblnr(25),

v_xblnr1(25),

v_ebelp(2) type n,

v_ebelpt(2),

v_menge1(11),

v_ebt type i,

v_vebtyp like ekes-ebtyp,

V_EB(2) TYPE N,

v_tcselflag(40),

v_tem(2) type n,

v_file type string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

field_name = filename

CHANGING

file_name = filename.

START-OF-SELECTION.

v_file = filename.

***uploading from flat file into internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = t_itab.

loop at t_itab.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = t_itab-ebeln

IMPORTING

OUTPUT = t_itab-ebeln

.

modify t_itab.

clear t_itab.

endloop.

      • checking the item numbers in the flat file.

loop at t_itab.

select ebeln ebelp from ekpo into table t_tab

where ebeln = t_itab-ebeln.

endloop.

IF t_tab[] is not initial.

perform open_group.

***looping at purchase order level.

LOOP at t_itab.

clear v_bn.

clear v_ebt.

perform bdc_dynpro using 'SAPMM06E' '0105'.

perform bdc_field using 'BDC_CURSOR'

'RM06E-BSTNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RM06E-BSTNR'

t_itab-ebeln.

**Changing alphanumeric fields and quantity fields to character type**

v_ebelp = t_itab-ebelp.

clear v_ebelpt.

v_menge1 = t_itab-menge.

v_ebelpt = v_ebelp.

**End Of Changing**

**Checking for the exact number of the item**

loop at t_tab where ebeln = t_itab-ebeln.

if t_tab-ebelp = t_itab-ebelp.

exit.

else.

v_bn = v_bn + 1.

endif.

endloop.

v_bst = v_bn + 1.

**End Of Checking**

**Mapping items**

v_tem = 1.

CONCATENATE 'RM06E-BSTPO(' v_bst ')' INTO v_bstpo.

CONCATENATE 'RM06E-TCSELFLAG(' v_tem ')' INTO v_tcselflag.

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

v_bstpo.

perform bdc_field using 'BDC_OKCODE'

'=DETA'.

perform bdc_field using 'RM06E-EBELP'

v_ebelpt.

perform bdc_dynpro using 'SAPMM06E' '0111'.

perform bdc_field using 'BDC_CURSOR'

'EKPO-BSTAE'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

v_bstpo.

perform bdc_field using 'BDC_OKCODE'

'=BSTA'.

perform bdc_field using 'RM06E-EBELP'

v_ebelpt.

perform bdc_field using v_tcselflag

'X'.

**Checking weather Confirmation category already exists**

select ebtyp from ekes into v_vebtyp where ebelp =

t_itab-ebelp and ebeln = t_itab-ebeln.

endselect.

if sy-dbcnt > 0.

v_ebt = sy-dbcnt.

endif.

V_EB = V_EBT + 1.

**End Of Checking**

**For Line items**

CONCATENATE 'EKES-EBTYP(' v_eb ')' INTO v_ebtyp.

CONCATENATE 'EKES-MENGE(' v_eb ')' INTO v_menge.

CONCATENATE 'RM06E-EEIND(' v_eb ')' INTO v_eeind.

CONCATENATE 'EKES-XBLNR(' v_eb ')' INTO v_xblnr.

**End**

perform bdc_dynpro using 'SAPLEINB' '0200'.

perform bdc_field using 'BDC_CURSOR'

v_xblnr.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using v_ebtyp

t_itab-ebtyp.

perform bdc_field using v_eeind

t_itab-eindt.

perform bdc_field using v_menge

v_menge1.

perform bdc_field using v_xblnr

t_itab-xblnr.

**End Of Mappings**

perform bdc_transaction using 'ME22'.

ENDLOOP.

**End Of Purchase Order Loop**

perform close_group.

ELSE.

MESSAGE I083(zv).

ENDIF

0 Kudos

Hi,

Could you send some sample BAPI Program to create

Vendor master by using 'FK01' transaction

Thanks

Ganesh

hymavathi_oruganti
Active Contributor
0 Kudos

module pool example

PROGRAM SAPMZMM_UPDATING_OLD_CHALANS.

***declaring table work area

TABLES: J_1IEXCDTL,J_1IEXCHDR.

***declaring table control

CONTROLS TAB TYPE TABLEVIEW USING SCREEN 20.

***declaring variables in the layout

DATA: V_EXNUM LIKE J_1IEXCDTL-EXNUM,

V_WERKS LIKE J_1IEXCDTL-WERKS,V_SEL.

***declaring variables for counting

DATA: V_C TYPE I VALUE 1,

V_CNT TYPE I,

V_S TYPE I ,

V_TN TYPE I,

V_STATUS LIKE J_1IEXCDTL-STATUS.

      • declaring internal table

DATA T_TAB LIKE J_1IEXCDTL OCCURS 0 WITH HEADER LINE.

*

*&----


*& Module STATUS_0020 OUTPUT

*&----


  • text

*----


MODULE STATUS_0020 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

***selecting data from dbtable into internal table.

select * from J_1IEXCDTL

into corresponding fields of t_tab." where STATUS <> 'C'

  • AND exnum = v_exnum and werks = v_werks.

append t_tab.

ENDSELECT.

V_CNT = SY-DBCNT.

refresh control 'TAB' from screen '0020'.

IF sy-dbcnt = 0.

MESSAGE I078(ZV).

CALL SCREEN 10.

ENDIF.

describe table t_tab lines v_tn.

TAB-LINES = v_tn.

SELECT STATUS FROM J_1IEXCDTL INTO V_STATUS WHERE STATUS = 'C' AND

EXNUM = V_EXNUM AND WERKS = V_WERKS.

ENDSELECT.

V_S = SY-DBCNT.

ENDMODULE. " STATUS_0020 OUTPUT

&----


*& Module MOVE-TAB OUTPUT

&----


  • text

----


MODULE MOVE-TAB OUTPUT.

***moving data from internal table to the screen

IF T_TAB[] IS NOT INITIAL.

MOVE-CORRESPONDING T_TAB TO J_1IEXCDTL.

ENDIF.

ENDMODULE. " MOVE-TAB OUTPUT

&----


*& Module USER_COMMAND_0010 INPUT

&----


  • text

----


MODULE USER_COMMAND_0010 INPUT.

CASE SY-UCOMM.

WHEN 'EXEC'.

CALL SCREEN 20.

ENDCASE.

ENDMODULE. " USER_COMMAND_0010 INPUT

&----


*& Module UPDATE_TAB INPUT

&----


  • text

----


MODULE UPDATE_TAB INPUT.

CASE SY-UCOMM.

WHEN 'SAVE'.

IF V_SEL = 'X'.

T_TAB-MENGR = T_TAB-MENGE - J_1IEXCDTL-MENGA.

IF T_TAB-MENGR < 0.

MESSAGE E079(ZV).

call screen 20.

ELSE.

***moving data from internal table to the screen.

T_TAB-MENGA = J_1IEXCDTL-MENGA.

T_TAB-STATUS = 'C'.

T_TAB-CREDIT_QTY = J_1IEXCDTL-MENGA.

V_S = V_S + 1.

MODIFY T_TAB INDEX V_C.

MODIFY TABLE T_TAB.

ENDIF.

      • updating the internal table

  • MODIFY TABLE T_TAB.

ENDIF.

      • updating dbtable from internal table

UPDATE J_1IEXCDTL FROM T_TAB.

IF V_S = V_CNT.

CALL SCREEN 30 STARTING AT 20 40 ENDING AT 40 50.

ENDIF.

WHEN 'BACK'.

REFRESH T_TAB.

CLEAR V_EXNUM.

CLEAR V_WERKS.

CALL SCREEN 10.

ENDCASE.

V_C = V_C + 1.

ENDMODULE. " UPDATE_TAB INPUT

----


  • MODULE UPDATE_TAB1 INPUT

----


*

----


MODULE UPDATE_TAB1 INPUT.

CASE SY-UCOMM.

WHEN 'YES'.

UPDATE J_1IEXCHDR SET STATUS = 'C' WHERE EXNUM =

v_EXNUM and WERKS = v_WERKS.

CLEAR V_EXNUM.

CLEAR V_WERKS.

CALL SCREEN 10.

WHEN 'NO'.

CALL SCREEN 10.

ENDCASE.

ENDMODULE. " UPDATE_TAB1 INPUT

&----


*& Module EXIT INPUT

&----


  • text

----


MODULE EXIT INPUT.

CASE SY-UCOMM.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " EXIT INPUT

&----


*& Module AUTHORITY INPUT

&----


  • text

----


MODULE AUTHORITY INPUT.

CALL FUNCTION 'ZAUTHORITYCHECK'

EXPORTING

  • I_P_BUKRS =

  • I_P_GSBER =

  • I_P_EKORG =

I_P_WERKS = V_WERKS

  • I_P_VKORG =

  • TABLES

  • T_DIVISION =

  • T_BAREA =

  • T_BUNIT =

  • T_BUKRS =

  • T_GSBER =

  • T_EKORG =

  • T_WERKS = V_WERKS

  • T_VKORG =

.

ENDMODULE.

former_member188685
Active Contributor
0 Kudos

Hi,

The below proram is used to change or create material master using BAPI. check this..

REPORT Z_BAPI_MAT.


**********************************************************************
*                STRUCTURE  DECLARATIONS                             *
**********************************************************************

TABLES: BAPIMATHEAD,  "Headerdata
        BAPI_MARA,    "Clientdata
        BAPI_MARAX,   "Clientdatax
        BAPI_MARC,    "Plantdata
        BAPI_MARCX,   "Plantdatax
        BAPI_MAKT,    "Material description
        BAPIRET2.     "Return messages

DATA:V_FILE TYPE STRING.


DATA:
  BEGIN OF LSMW_MATERIAL_MASTER,
    MATNR(018) TYPE C,  "Material number
    MTART(004) TYPE C,  "Material type
    MBRSH(001) TYPE C,  "Industry sector
    WERKS(004) TYPE C,  "Plant
    MAKTX(040) TYPE C,  "Material description
    DISMM(002) TYPE C,  "Extra Field Added In the Program as itsrequired
    MEINS(003) TYPE C,  "Base unit of measure
    MATKL(009) TYPE C,  "Material group
    SPART(002) TYPE C,  "Division
    LABOR(003) TYPE C,  "Lab/office
    PRDHA(018) TYPE C,  "Product hierarchy
    MSTAE(002) TYPE C,  "X-plant matl status
    MTPOS_MARA(004) TYPE C,  "Gen item cat group
    BRGEW(017) TYPE C,  "Gross weight
    GEWEI(003) TYPE C,  "Weight unit
    NTGEW(017) TYPE C,  "Net weight
    GROES(032) TYPE C,  "Size/Dimensions
    MAGRV(004) TYPE C,  "Matl grp pack matls
    BISMT(018) TYPE C,  "Old material number
    WRKST(048) TYPE C,  "Basic material
    PROFL(003) TYPE C,  "DG indicator profile
    KZUMW(001) TYPE C,  "Environmentally rlvt
    BSTME(003) TYPE C,  "Order unit
    VABME(001) TYPE C,
    EKGRP(003) TYPE C,  "Purchasing group
    XCHPF(001) TYPE C,  "Batch management
    EKWSL(004) TYPE C,  "Purchasing key value
    WEBAZ(003) TYPE C,  "GR processing time
    MFRPN(040) TYPE C,  "Manufacturer part number
    MFRNR(010) TYPE C,  "Manufacturer number
    VPRSV(001) TYPE C,  "Price control indicator
    STPRS(015) TYPE C,  "Standard price
    BWPRH(014) TYPE C,  "Commercial price1
    BKLAS(004) TYPE C,  "Valuation class
  END OF LSMW_MATERIAL_MASTER.


**********************************************************************
*                INTERNAL TABLE DECLARATIONS                         *
**********************************************************************

*to store the input data
DATA:
  BEGIN OF it_matmaster OCCURS 0.
        INCLUDE STRUCTURE LSMW_MATERIAL_MASTER.

DATA:
  END OF it_matmaster.

*for material description
DATA:BEGIN OF IT_MATERIALDESC OCCURS 0.
     INCLUDE STRUCTURE BAPI_MAKT .
DATA:END OF IT_MATERIALDESC.

*to return messages
DATA:BEGIN OF IT_RETURN OCCURS 0.
     INCLUDE STRUCTURE BAPIRET2.
DATA:END OF IT_RETURN.

************************************************************************
*  SELECTION SCREEN
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETERS:P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1 .

************************************************************************
* AT SELECTION SCREEN
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      PROGRAM_NAME  = SYST-CPROG
      DYNPRO_NUMBER = SYST-DYNNR
      FIELD_NAME    = 'P_FILE'
    IMPORTING
      FILE_NAME     = P_FILE.



**********************************************************************
*                TO UPLOAD THE DATA                                  *
**********************************************************************

START-OF-SELECTION.
V_FILE = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = V_FILE
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  tables
    data_tab                      =  IT_MATMASTER
 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.
ENDIF.

**********************************************************************
*                DATA POPULATIONS                                    *
**********************************************************************


LOOP AT  IT_MATMASTER.
  BAPIMATHEAD-MATERIAL = IT_MATMASTER-MATNR.
  BAPIMATHEAD-IND_SECTOR = IT_MATMASTER-Mbrsh.
  BAPIMATHEAD-MATL_TYPE = IT_MATMASTER-Mtart.
  BAPIMATHEAD-BASIC_VIEW = 'X'.
  BAPIMATHEAD-PURCHASE_VIEW = 'X'.
  BAPIMATHEAD-ACCOUNT_VIEW = 'X'.
  BAPI_MARA-MATL_GROUP = IT_MATMASTER-MATKL.
  BAPI_MARA-OLD_MAT_NO = IT_MATMASTER-BISMT.
  BAPI_MARA-BASE_UOM = IT_MATMASTER-MEINS.
  BAPI_MARA-BASIC_MATL = IT_MATMASTER-WRKST.
  BAPI_MARA-MFR_NO = IT_MATMASTER-MFRNR.
  BAPI_MARAX-MATL_GROUP = 'X'.
  BAPI_MARAX-OLD_MAT_NO = 'X'.
  BAPI_MARAX-BASE_UOM = 'X'.
  BAPI_MARAX-BASIC_MATL = 'X'.
  BAPI_MARAX-MFR_NO = 'X'.
  BAPI_MARC-PLANT = IT_MATMASTER-WERKS.
  BAPI_MARC-PUR_GROUP = IT_MATMASTER-EKGRP.
  BAPI_MARCX-PLANT = IT_MATMASTER-WERKS.
  BAPI_MARCX-PUR_GROUP = 'X'.
  IT_MATERIALDESC-LANGU = 'EN'.
  IT_MATERIALDESC-MATL_DESC = IT_MATMASTER-MAKTX.
  append IT_materialdesc.
  CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
    EXPORTING
      headdata                   = BAPIMATHEAD
      CLIENTDATA                 = BAPI_MARA
      CLIENTDATAX                = BAPI_MARAx
     PLANTDATA                  = BAPI_MARc
     PLANTDATAX                 = BAPI_MARcx
*     FORECASTPARAMETERS         =
*     FORECASTPARAMETERSX        =
*     PLANNINGDATA               =
*     PLANNINGDATAX              =
*     STORAGELOCATIONDATA        =
*     STORAGELOCATIONDATAX       =
*     VALUATIONDATA              =
*     VALUATIONDATAX             =
*     WAREHOUSENUMBERDATA        =
*     WAREHOUSENUMBERDATAX       =
*     SALESDATA                  =
*     SALESDATAX                 =
*     STORAGETYPEDATA            =
*     STORAGETYPEDATAX           =
*     FLAG_ONLINE                = ' '
*     FLAG_CAD_CALL              = ' '
   IMPORTING
     RETURN                     = IT_RETURN
   TABLES
     MATERIALDESCRIPTION        = IT_MATERIALDESC
*     UNITSOFMEASURE             =
*     UNITSOFMEASUREX            =
*     INTERNATIONALARTNOS        =
*     MATERIALLONGTEXT           =
*     TAXCLASSIFICATIONS         =
*     RETURNMESSAGES             =
*     PRTDATA                    =
*     PRTDATAX                   =
*     EXTENSIONIN                =
*     EXTENSIONINX               =
            .

 WRITE:/    IT_RETURN-TYPE,
        2   IT_RETURN-ID,
        22  IT_RETURN-NUMBER,
        25  IT_RETURN-MESSAGE.
*            IT_RETURN-LOG_NO,
*            IT_RETURN-LOG_MSG_NO,
*            IT_RETURN-MESSAGE_V1,
*            IT_RETURN-MESSAGE_V2,
*            IT_RETURN-MESSAGE_V3,
*            IT_RETURN-MESSAGE_V4,
*            IT_RETURN-PARAMETER,
*            IT_RETURN-ROW,
*            IT_RETURN-FIELD,
*            IT_RETURN-SYSTEM.

ENDLOOP.

regards

vijay

0 Kudos

Hi,

for creating the vendor master you can use BAPI

<b>BAPI_VENDOR_CREATE</b> .

regards

vijay

0 Kudos

Hi

This BAPI useful to create a vendor in T.code XK01

but i want to create a vendor in FD01 for FI Transaction.

Ganesh

Former Member
0 Kudos

In order to use BAPI goto txn- BAPI.

u will find their BAPI according to your requirements.

ex- BAPI_MATERIAL_EDIT etc.

For BDC try to do a recording in SHDB and then genearte a sample program from there.

Hope it'll help.

Thanks & Regards,

Ankur

Former Member
0 Kudos

I am using the given BDC for ME22 for ME22N and is executing fine except that only one item for a PO is getting carried to the transaction . What needs to be done for multiple line items. Also i amnot uploading data from a file instead its ALV output in a table.