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 table control in va01

Former Member
0 Kudos

hi Experts ,

pls give me the code for table control in va01 transaction and logic of insert new records in table control .

1 ACCEPTED SOLUTION

Former Member
0 Kudos

See the following 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.

2 REPLIES 2

Former Member
0 Kudos

See the following 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.

0 Kudos

can you please tell me the logic how to handle table control in va01

and also tell me how to handle view in mm01 in bdc