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

BDC CREATION USING CALL TRANSACTION

Former Member
0 Likes
863

Hi Guys,

I m trying to upload sales order data using BDC call transaction method and for this I have written the following code, program is syntactically correct and its perfectly working for a sales order that has only one line item, but its not uploading the sales order with multiple line items. In the case of the sales order with multiple line items its just saving the first line item and coming out from there.

Can you please help me out from this.

thanks in advance

Rajeev Gupta

&----


*& Report ZBDC_SORDER *

*& *

&----


*& *

*& *

&----


report zbdc_sorder .

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

  • Definition of Structures *

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

data: bdctab like bdcdata occurs 0 with header line.

data: messtab like bdcmsgcoll occurs 0 with header line.

data: begin of itab occurs 0,

ord_typ(2),

sales_org(4),

dist_chan(2),

divison(2),

po_no(35),

sp(10),

sh(10),

mat_no(18),

quant(15),

price(10),

end of itab.

data: itab2 like itab occurs 0 with header line.

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

    • Definition of Variables *

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

data: v_tabix like syst-tabix,

v_kunnr like vbak-kunnr,

v_vkorg like vbak-vkorg,

v_vtweg like vbak-vtweg,

v_spart like vbak-spart,

v_index like syst-index,

l1 like syst-tabix.

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

    • Definition of Constants *

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

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

  • START-OF-SELECTION *

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

start-of-selection.

perform get_data.

perform create_bdcdata.

end-of-selection.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_data .

call function 'WS_UPLOAD'

exporting

filename = 'C:\Documents and Settings\ekansh\Desktop\sales_ord.txt'

filetype = 'DAT'

tables

data_tab = itab

exceptions

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

gui_refuse_filetransfer = 8

others = 9.

  • write:/ itab-divison.

itab2[] = itab[].

endform. " get_data

*&----


**& Form create_bdcdata

*&----


    • text

*----


    • --> p1 text

    • <-- p2 text

*----


form create_bdcdata .

describe table itab lines l1.

loop at itab.

v_tabix = syst-tabix.

if v_tabix = 1.

perform bdc_dynpro using:

'X' 'SAPMV45A' '0101',

'' 'BDC_OKCODE' '/00',

'' 'VBAK-AUART' itab-ord_typ,

'' 'VBAK-VKORG' itab-sales_org,

'' 'VBAK-VTWEG' itab-dist_chan,

'' 'VBAK-SPART' itab-divison.

perform line_bdc_tab.

v_kunnr = itab-sp.

v_vkorg = itab-sales_org.

v_vtweg = itab-dist_chan.

v_spart = itab-divison.

else.

if v_kunnr = itab-sp and

v_vkorg = itab-sales_org and

v_vtweg = itab-dist_chan and

v_spart = itab-divison.

perform line_bdc_tab.

else.

perform bdc_dynpro using:

'X' 'SAPMV45A' '0101',

'' 'BDC_OKCODE' '/00',

'' 'VBAK-AUART' itab-ord_typ,

'' 'VBAK-VKORG' itab-sales_org,

'' 'VBAK-VTWEG' itab-dist_chan,

'' 'VBAK-SPART' itab-divison.

perform line_bdc_tab.

v_kunnr = itab-sp.

v_vkorg = itab-sales_org.

v_vtweg = itab-dist_chan.

v_spart = itab-divison.

endif.

endif.

read table itab2 with key sp = itab-sp

sales_org = itab-sales_org

dist_chan = itab-dist_chan

divison = itab-divison.

if v_tabix = 1.

move syst-tabix to v_index.

endif.

v_index = v_index + 1.

read table itab2 index v_index.

if itab2-sp = itab-sp and

itab2-sales_org = itab-sales_org and

itab2-dist_chan = itab-dist_chan and

itab2-divison = itab-divison.

if l1 = v_tabix.

call transaction 'Va01' using bdctab

mode 'N'

update 'S'

messages into messtab.

clear bdctab.

refresh bdctab.

endif.

else.

call transaction 'Va01' using bdctab

mode 'N'

update 'S'

messages into messtab.

clear bdctab.

refresh bdctab.

endif.

endloop.

endform. " create_bdcdata

*&----


**& Form line_bdc_tab

*&----


    • text

*----


    • --> p1 text

    • <-- p2 text

*----


form line_bdc_tab .

perform bdc_dynpro using:

'X' 'SAPMV45A' '4001',

'' 'BDC_OKCODE' '=T\02',

'' 'VBKD-BSTKD' itab-po_no,

'' 'KUAGV-KUNNR' itab-sp,

'' 'KUWEV-KUNNR' itab-sh,

'X' 'SAPMV45A' '4001',

'' 'BDC_OKCODE' '/00',

'' 'RV45A-MABNR(01)' itab-mat_no,

'' 'RV45A-KWMENG(01)' itab-quant,

'' 'KOMV-KBETR(01)' itab-price,

'X' 'SAPMV45A' '4001',

'' 'BDC_OKCODE' '=SICH'.

endform. " line_bdc_tab

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0382 text

  • -->P_0383 text

  • -->P_0384 text

----


form bdc_dynpro using p1

p2

p3.

if p1 = 'X'.

bdctab-dynbegin = p1.

bdctab-program = p2.

bdctab-dynpro = p3.

else.

bdctab-fnam = p2.

bdctab-fval = p3.

endif.

append bdctab.

clear bdctab.

6 REPLIES 6
Read only

Former Member
0 Likes
823

HI,

Here is the problem. YOu have hard coded for only one line item..

*&----


**& Form line_bdc_tab

*&----


    • text

*----


    • --> p1 text

    • <-- p2 text

*----


form line_bdc_tab .

perform bdc_dynpro using:

'X' 'SAPMV45A' '4001',

'' 'BDC_OKCODE' '=T\02',

'' 'VBKD-BSTKD' itab-po_no,

'' 'KUAGV-KUNNR' itab-sp,

'' 'KUWEV-KUNNR' itab-sh,

<b>'X' 'SAPMV45A' '4001',

'' 'BDC_OKCODE' '/00',

data : lv_count(2) type n.

loop at line item table.

lv_count = lv_count + 1.

data : lv_madnr(20),

lv_kwmeng(20,

lv_kbetr(20.

<b>concatenate 'RV45A-MABNR(' lv_count ')' into lv_mabnr.

'' lv_mabnr itab-mat_no,</b>

'' 'RV45A-KWMENG(01)' itab-quant,

'' 'KOMV-KBETR(01)' itab-price,</b>

endloop.

'X' 'SAPMV45A' '4001',

'' 'BDC_OKCODE' '=SICH'.

Thanks,

mahesh

Message was edited by:

I Can Solve It

Read only

0 Likes
823

Hey thnks for the reply.

Can you tell me how to do that.

Rajeev Gupta

Read only

0 Likes
823

Why don't you use BAPI_SALESORDER_CREATEFROMDAT2?

Read only

0 Likes
823

'RV45A-MABNR(01)' itab-mat_no,

'' 'RV45A-KWMENG(01)' itab-quant,

'' 'KOMV-KBETR(01)' itab-price,

The 01 refers to the line number therfore for more than one line the number needs to increase

Try doing the recording for multiple lines and you will see.

Use a varianle for eg. v_mabnr = 'RV45A-MABNR('

Inside a loop for numb er of line items

add 1 to the counter each time

concatenate v_mabnr lv_counter into v_mabnr

concatenate v_mabnr ')' into v_mabnr

Read only

0 Likes
823

Hey Alison,

Thanks for the reply that is helpful, but can you be more elaborate. I mean can you tell me the code.

Thanks

Rajeev Gupta

Read only

0 Likes
823

HI,

Here is the complete code for your reference under stand it. I have made it bold just check that part of the code

HANDLING TABLE CONTROL IN BDC

DATA : BEGIN OF IT_DUMMY OCCURS 0,

DUMMY(100) TYPE C,

END OF IT_DUMMY.

DATA : BEGIN OF IT_XK01 OCCURS 0,

LIFNR(10) TYPE C,

BUKRS(4) TYPE C,

EKORG(4) TYPE C,

KTOKK(4) TYPE C,

NAME1(30) TYPE C,

SORTL(10) TYPE C,

LAND1(3) TYPE C,

SPRAS(2) TYPE C,

AKONT(6) TYPE C,

FDGRV(2) TYPE C,

WAERS(3) TYPE C,

END OF IT_XK01,

BEGIN OF IT_BANK OCCURS 0,

BANKS(3) TYPE C,

BANKL(10) TYPE C,

BANKN(10) TYPE C,

KOINH(30) TYPE C,

LIFNR(10) TYPE C,

END OF IT_BANK.

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

IT_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = 'C:\VENDOR.TXT'

FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_DUMMY.

LOOP AT IT_DUMMY.

IF IT_DUMMY-DUMMY+0(2) = '11'.

IT_XK01-LIFNR = IT_DUMMY-DUMMY+2(10).

IT_XK01-BUKRS = IT_DUMMY-DUMMY+12(4).

IT_XK01-EKORG = IT_DUMMY-DUMMY+16(4).

IT_XK01-KTOKK = IT_DUMMY-DUMMY+20(4).

IT_XK01-NAME1 = IT_DUMMY-DUMMY+24(30).

IT_XK01-SORTL = IT_DUMMY-DUMMY+54(10).

IT_XK01-LAND1 = IT_DUMMY-DUMMY+64(3).

IT_XK01-SPRAS = IT_DUMMY-DUMMY+67(2).

IT_XK01-AKONT = IT_DUMMY-DUMMY+69(6).

IT_XK01-FDGRV = IT_DUMMY-DUMMY+75(2).

IT_XK01-WAERS = IT_DUMMY-DUMMY+77(3).

APPEND IT_XK01.

ELSE.

IT_BANK-BANKS = IT_DUMMY-DUMMY+2(3).

IT_BANK-BANKL = IT_DUMMY-DUMMY+5(10).

IT_BANK-BANKN = IT_DUMMY-DUMMY+15(10).

IT_BANK-KOINH = IT_DUMMY-DUMMY+25(30).

IT_BANK-LIFNR = IT_DUMMY-DUMMY+55(10).

APPEND IT_BANK.

ENDIF.

ENDLOOP.

LOOP AT IT_XK01.

REFRESH IT_BDCDATA.

perform bdc_dynpro using 'SAPMF02K' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-REF_LIFNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-LIFNR'

IT_XK01-LIFNR.

perform bdc_field using 'RF02K-BUKRS'

IT_XK01-BUKRS.

perform bdc_field using 'RF02K-EKORG'

IT_XK01-EKORG.

perform bdc_field using 'RF02K-KTOKK'

IT_XK01-KTOKK.

perform bdc_dynpro using 'SAPMF02K' '0110'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-TELX1'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'LFA1-NAME1'

IT_XK01-NAME1.

perform bdc_field using 'LFA1-SORTL'

IT_XK01-SORTL.

perform bdc_field using 'LFA1-LAND1'

IT_XK01-LAND1.

perform bdc_field using 'LFA1-SPRAS'

IT_XK01-SPRAS.

perform bdc_dynpro using 'SAPMF02K' '0120'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-KUNNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0130'.

perform bdc_field using 'BDC_CURSOR'

'LFBK-KOINH(02)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

DATA : FNAM(20) TYPE C,

IDX TYPE C.

MOVE 1 TO IDX.

<b>LOOP AT IT_BANK WHERE LIFNR = IT_XK01-LIFNR</b>.

<b>CONCATENATE 'LFBK-BANKS(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-BANKS.

CONCATENATE 'LFBK-BANKL(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-BANKL.

CONCATENATE 'LFBK-BANKN(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-BANKN.

CONCATENATE 'LFBK-KOINH(' IDX ')' INTO FNAM.

perform bdc_field using FNAM

IT_BANK-KOINH.

IDX = IDX + 1.

ENDLOOP.</b>

perform bdc_dynpro using 'SAPMF02K' '0130'.

perform bdc_field using 'BDC_CURSOR'

'LFBK-BANKS(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_dynpro using 'SAPMF02K' '0210'.

perform bdc_field using 'BDC_CURSOR'

'LFB1-FDGRV'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'LFB1-AKONT'

IT_XK01-AKONT.

perform bdc_field using 'LFB1-FDGRV'

IT_XK01-FDGRV.

perform bdc_dynpro using 'SAPMF02K' '0215'.

perform bdc_field using 'BDC_CURSOR'

'LFB1-ZTERM'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0220'.

perform bdc_field using 'BDC_CURSOR'

'LFB5-MAHNA'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0310'.

perform bdc_field using 'BDC_CURSOR'

'LFM1-WAERS'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'LFM1-WAERS'

IT_XK01-WAERS.

perform bdc_dynpro using 'SAPMF02K' '0320'.

perform bdc_field using 'BDC_CURSOR'

'WYT3-PARVW(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

CALL TRANSACTION 'XK01' USING IT_BDCDATA

MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_BDCMSGCOLL.

ENDLOOP.

FORM BDC_DYNPRO USING PROG SCR.

CLEAR IT_BDCDATA.

IT_BDCDATA-PROGRAM = PROG.

IT_BDCDATA-DYNPRO = SCR.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.

CLEAR IT_BDCDATA.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

ENDFORM.

thanks

Mahesh

Message was edited by:

I Can Solve It