2007 Jul 23 9:57 PM
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 but its not showing me the desired result. Moreover can you please tell me how to loop into message table and print the data which will in message table so you know what orders/errors occurred after execution.
thanks
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 'ME21' using bdctab
mode 'N'
update 'S'
messages into messtab.
clear bdctab.
refresh bdctab.
endif.
else.
call transaction 'ME21' 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.
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 but its not showing me the desired result. Moreover can you please tell me how to loop into message table and print the data which will in message table so you know what orders/errors occurred after execution.
thanks
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 'ME21' using bdctab
mode 'N'
update 'S'
messages into messtab.
clear bdctab.
refresh bdctab.
endif.
else.
call transaction 'ME21' 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.
2007 Jul 23 10:01 PM
Hi,
Just i gone through your code, you are capturing the errors in the table - messtab. Once you capture you can pass the captured information to 'FORMAT_MESSAGE' function module by keeping loop of messtab and you can capture the right message from the function module and display.
regards
dj
reward for all helpful answers.
2007 Jul 23 10:03 PM
Thanks for the reply...but can you be more specific. I mean what should be the code for this one.
Thanks
2007 Jul 23 10:05 PM
Hi,
You can try the below code...
loop at itab_message.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = itab_message-MSGID
LANG = 'EN'
NO = itab_message-msgnr
V1 = itab_message-MSGV1
V2 = itab_message-MSGV2
V3 = itab_message-MSGV3
V4 = itab_message-MSGV4
IMPORTING
MSG = message1
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write: message1.
endloop.
regards
*dj
reward for all helpful answers.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |