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: 

bdc program

Former Member
0 Kudos
79

hi friends.

i need 2-3 programs of any sd or mm tranctions with codeing or atleast mandatory fields

thanks&Regards

Babasish

2 REPLIES 2

Former Member
0 Kudos
39

Better get busy.

Rob

Former Member
0 Kudos
39

Hi

See the sample BDC codes for VA01(sales Order Creation in SD) and Pur requisition in MM module

Check the code :

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA : w_auart(4) TYPE c,

w_vkorg(4) TYPE c,

w_vtweg(2) TYPE c,

w_spart(2) TYPE c,

w_kunnr(10) TYPE c,

w_kunrg(10) TYPE c,

w_bstkd(35) TYPE c,

w_bstdk(10) TYPE c,

w_kwmeng(18) TYPE c,

w_zterm(4) TYPE c,

w_inco1(3) TYPE c,

w_inco2(28) TYPE c,

w_augru(3) TYPE c.

DATA : var1 TYPE string,

var2 TYPE c VALUE '(',

var3 TYPE c VALUE ')',

num(2) TYPE c,

flag(1) TYPE c.

DATA : BEGIN OF it_order, " Internal table Structure

auart(4) TYPE c, " Sales Order Type

vkorg(4) TYPE c, " Sales Organization

vtweg(2) TYPE c, " Distribution Channel

spart(2) TYPE c, " Division

kunnr(10) TYPE c, " Sold-to-Party

kunrg(10) TYPE c, " Ship-to-Party

bstkd(35) TYPE c, " Purchase Order No

bstdk(10) TYPE c, " Purchase Order Date

zterm(4) TYPE c, " Payment Terms

inco1(3) TYPE c, " Inco Terms1

inco2(20) TYPE c, " Inco Terms2

augru(3) TYPE c, " Order Reason

mabnr(18) TYPE c, " Material No

kwmeng(18) TYPE c, " Quantity

END OF it_order,

itab LIKE STANDARD TABLE OF it_order WITH HEADER LINE.

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

PARAMETER filename LIKE rlgrap-filename.

PARAMETER session LIKE apqi-groupid.

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

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

  • Get the file path

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

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = filename

def_path = ' '

mask = ',.,..'

mode = 'O'

title = 'Select File'

IMPORTING

filename = filename

EXCEPTIONS

selection_cancel = 1.

CHECK sy-subrc = 0.

START-OF-SELECTION.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

codepage = ' '

filename = filename

filetype = 'ASC'

headlen = ' '

line_exit = ' '

trunclen = ' '

user_form = ' '

user_prog = ' '

dat_d_format = ' '

  • IMPORTING

  • FILELENGTH =

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

OTHERS = 10.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

PERFORM open_group.

LOOP AT itab.

CLEAR : w_auart,w_vkorg,w_vtweg,w_spart,w_kunnr,w_kunrg,

w_bstkd,w_bstdk,w_zterm,w_inco1,w_inco2,w_augru.

w_auart = itab-auart.

w_vkorg = itab-vkorg.

w_vtweg = itab-vtweg.

w_spart = itab-spart.

w_kunnr = itab-kunnr.

w_kunrg = itab-kunrg.

w_bstkd = itab-bstkd.

w_bstdk = itab-bstdk.

w_zterm = itab-zterm.

w_inco1 = itab-inco1.

w_inco2 = itab-inco2.

w_augru = itab-augru.

ON CHANGE OF itab-kunnr OR itab-kunrg OR itab-bstkd .

flag = 0.

num = 1.

PERFORM bdc_dynpro USING 'SAPMV45A' '0101'.

PERFORM bdc_field USING 'BDC_CURSOR'

'VBAK-AUART'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'VBAK-AUART' " Order Type

itab-auart.

PERFORM bdc_field USING 'VBAK-VKORG' " Sales Organization

itab-vkorg.

PERFORM bdc_field USING 'VBAK-VTWEG' " Distribution Channel

itab-vtweg.

PERFORM bdc_field USING 'VBAK-SPART' " Division

itab-spart.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'VBKD-BSTKD' " PO Number

itab-bstkd.

PERFORM bdc_field USING 'VBKD-BSTDK' " PO Date

itab-bstdk.

PERFORM bdc_field USING 'KUAGV-KUNNR' " Sold to Party

itab-kunnr.

PERFORM bdc_field USING 'KUWEV-KUNNR' " Ship to Party

itab-kunrg.

PERFORM bdc_field USING 'VBKD-ZTERM' " Payment Terms

itab-zterm.

PERFORM bdc_field USING 'VBKD-INCO1' " Inco Terms1

itab-inco1.

PERFORM bdc_field USING 'VBKD-INCO2' " Inco Terms2

itab-inco2.

PERFORM bdc_field USING 'VBAK-AUGRU' " Order Reason

itab-augru.

ENDON.

IF flag = 0.

LOOP AT itab WHERE bstkd = itab-bstkd AND kunnr = itab-kunnr .

var1 = 'RV45A-MABNR'.

CONCATENATE var1 var2 num var3 INTO var1.

PERFORM bdc_field USING var1

itab-mabnr.

var1 = 'RV45A-KWMENG'.

CONCATENATE var1 var2 num var3 INTO var1.

PERFORM bdc_field USING var1

itab-kwmeng.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

num = 2.

ENDLOOP.

ELSE.

CONTINUE.

ENDIF.

flag = 1.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=SICH'.

PERFORM bdc_transaction USING 'VA01'.

ENDLOOP.

PERFORM close_group.

WRITE : / 'Session',session, 'was Created'.

FORM open_group.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = session

user = sy-uname

keep = 'X'.

ENDFORM.

FORM close_group.

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDFORM.

FORM bdc_transaction USING tcode.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = tcode

TABLES

dynprotab = bdcdata.

ENDFORM.

FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM.

FORM bdc_field USING fnam fval.

IF fval <> ' '.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDIF.

ENDFORM.

PR creation

REPORT zmm_pr_upload_mat

NO STANDARD PAGE HEADING

LINE-SIZE 255.

  • Standard Include for Selection Screen

INCLUDE bdcrecx1.

  • Internal Table for Upload Data

DATA: BEGIN OF i_pr OCCURS 0,

  • Header Screen

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

  • lpein(001), " Category of Del Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

  • Item Details

matnr(018), " Material No

menge(017), " Quantity

  • badat(010),

  • frgdt(010),

preis(014), " Valuation Price

  • waers(005), " Currency

  • peinh(005),

  • wepos(001),

  • repos(001),

sakto(010), " GL Account

kostl(010), " Cost Center

  • bnfpo(005),

END OF i_pr.

  • Internal Table for header Data

DATA: BEGIN OF it_header OCCURS 0,

sno(3), " SNo

bsart(004), " PR Type

epstp(001), " Item Category

knttp(001), " Account Assignment

eeind(010), " Delivery Date

werks(004), " Plant

lgort(004), " Storage Location

ekgrp(003), " Purchasing Group

matkl(009), " Material Group

bednr(010), " Tracking No

afnam(012), " Requisitioner

END OF it_header.

  • Internal Table for Item Data

DATA: BEGIN OF it_item OCCURS 0,

sno(3), " SNo

matnr(018), " Material No

menge(017), " Quantity

preis(014), " Valuation Price

sakto(010), " GL Account

kostl(010), " Cost Center

END OF it_item.

  • Data Variables & Constants

CONSTANTS : c_x VALUE 'X'. " Flag

DATA : v_l(2), " Counter

v_rowno(5), " Row No

v_2(2), " Counter

v_rows LIKE sy-srows, " Rows in TC

v_field(45). " String

  • Parameters

PARAMETERS: p_file LIKE ibipparms-path. " Filename

  • At selection-screen on Value Request for file Name

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Get the F4 Values for the File

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

  • Start of Selection

START-OF-SELECTION.

  • Open the BDC Session

PERFORM open_group.

  • Upload the File into internal Table

CALL FUNCTION 'UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = i_pr

EXCEPTIONS

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

OTHERS = 7.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SORT i_pr BY sno.

LOOP AT i_pr.

MOVE-CORRESPONDING i_pr TO it_item.

APPEND it_item.

CLEAR it_item.

AT END OF sno.

READ TABLE i_pr INDEX sy-tabix.

MOVE-CORRESPONDING i_pr TO it_header.

APPEND it_header.

CLEAR it_header.

ENDAT.

ENDLOOP.

SORT it_header BY sno.

SORT it_item BY sno.

v_rows = sy-srows - 6.

  • Upload the Data from Internal Table

LOOP AT it_header.

  • Header Data

PERFORM bdc_dynpro USING 'SAPMM06B' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-BEDNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-BSART'

it_header-bsart.

PERFORM bdc_field USING 'RM06B-EPSTP'

it_header-epstp.

PERFORM bdc_field USING 'EBAN-KNTTP'

it_header-knttp.

PERFORM bdc_field USING 'RM06B-EEIND'

it_header-eeind.

  • PERFORM bdc_field USING 'RM06B-LPEIN'

  • it_header-lpein.

PERFORM bdc_field USING 'EBAN-WERKS'

it_header-werks.

PERFORM bdc_field USING 'EBAN-LGORT'

it_header-lgort.

PERFORM bdc_field USING 'EBAN-EKGRP'

it_header-ekgrp.

PERFORM bdc_field USING 'EBAN-MATKL'

it_header-matkl.

PERFORM bdc_field USING 'EBAN-BEDNR'

it_header-bednr.

PERFORM bdc_field USING 'EBAN-AFNAM'

it_header-afnam.

  • Item Details

v_l = 0.

  • To add no. of rows

v_2 = 0 .

  • As the screen is showing 13 rows defaulted to 130

v_rowno = 130 .

LOOP AT it_item WHERE sno = it_header-sno.

v_l = v_l + 1.

IF v_l = 14 .

IF v_2 = 12 .

v_2 = 12 .

v_l = 2 .

  • From second time onwards it is displaying 12 rows only

v_rowno = v_rowno + 120 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ELSE.

  • V_2 initialized to 12 for second screen purpose

v_2 = 12 .

v_l = 2 .

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'RM06B-BNFPO'

v_rowno .

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

ENDIF.

ENDIF.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

CLEAR v_field.

CONCATENATE 'EBAN-MATNR(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-matnr.

CLEAR v_field.

CONCATENATE 'EBAN-MENGE(' v_l ')' INTO v_field.

PERFORM bdc_field USING v_field it_item-menge.

PERFORM bdc_dynpro USING 'SAPMM06B' '0102'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBAN-PREIS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'EBAN-PREIS'

it_item-preis.

PERFORM bdc_dynpro USING 'SAPMM06B' '0505'.

PERFORM bdc_field USING 'BDC_CURSOR'

'EBKN-SAKTO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'EBKN-SAKTO'

it_item-sakto.

  • Cost Center

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'

'COBL-KOSTL'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'COBL-KOSTL'

it_item-kostl.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

ENDLOOP.

PERFORM bdc_dynpro USING 'SAPMM06B' '0106'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RM06B-BNFPO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

  • Call The Transaction

PERFORM bdc_transaction USING 'ME51'.

ENDLOOP.

  • Close the BDC Session

PERFORM close_group.

Regards

Anji