‎2008 Apr 10 11:01 AM
hello everyone,
can anyone please help me with a sample code of BDC using call transaction method , actually i am not too much expert in bdc , i want to upload a data using T.code J3G(.
your reply is highly appreciated.
‎2008 Apr 10 11:04 AM
Hi,
report zbdc_j1id_ind
no standard page heading line-size 255.
tables : j_1imtchid.
data: begin of bdcdata occurs 0.
include structure bdcdata.
data: end of bdcdata.
data : begin of itab occurs 0,
matnr like mara-matnr,
werks like t001w-werks,
ind(1) type c,
end of itab,
fg(1),bg(1),typ(1).
*include bdcrecx1.
start-of-selection.
import fg bg from memory id 'UNBW'.
if fg = 'X'.
typ = 'A'.
else.
typ = 'E'.
endif.
call function 'UPLOAD'
exporting
filename = 'C:\'
filetype = 'DAT'
tables
data_tab = itab
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.
perform bdc_dynpro using 'SAPMJ1ID' '0200'.
perform bdc_field using 'BDC_CURSOR'
'RB1'.
perform bdc_field using 'BDC_OKCODE'
'=EX'.
perform bdc_field using 'RB11'
'X'.
*perform bdc_field using 'RB1'
* 'X'.
loop at itab.
*perform open_group.
if itab-matnr na sy-abcde and itab-matnr na '/*-_.'.
unpack itab-matnr to itab-matnr.
else.
translate itab-matnr to upper case.
endif.
select single * from j_1imtchid where matnr = itab-matnr and werks = itab-werks.
if sy-subrc ne 0.
continue.
endif.
perform bdc_dynpro using 'SAPLJ1I5' '0020'.
perform bdc_field using 'BDC_CURSOR'
'J_1IMTCHID-MATNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'=POSI'.
perform bdc_dynpro using 'SAPLSPO4' '0300'.
perform bdc_field using 'BDC_CURSOR'
'SVALD-VALUE(02)'.
perform bdc_field using 'BDC_OKCODE'
'=FURT'.
perform bdc_field using 'SVALD-VALUE(01)'
itab-matnr. "'940101'.
perform bdc_field using 'SVALD-VALUE(02)'
itab-werks. "'7200'.
perform bdc_dynpro using 'SAPLJ1I5' '0020'.
perform bdc_field using 'BDC_CURSOR'
'J_1IMTCHID-J_1ICAPIND(01)'.
perform bdc_field using 'J_1IMTCHID-J_1ICAPIND(01)'
itab-ind. "C'.
endloop.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_dynpro using 'SAPLJ1I5' '0020'.
perform bdc_field using 'BDC_CURSOR'
'J_1IMTCHID-J_1ICAPIND(01)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_dynpro using 'SAPMJ1ID' '0200'.
perform bdc_field using 'BDC_OKCODE'
'/EEXIT'.
perform bdc_field using 'BDC_CURSOR'
'EXCISE'.
**perform bdc_transaction using 'J1ID'.
**
**perform close_group.
call transaction 'J1ID' using bdcdata mode typ update 'S'.
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform. "bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
* if fval <> ' '. "NODATA.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
* endif.
endform. "bdc_fieldReward if usefull
‎2008 Apr 10 11:04 AM
Hi,
report zbdc_j1id_ind
no standard page heading line-size 255.
tables : j_1imtchid.
data: begin of bdcdata occurs 0.
include structure bdcdata.
data: end of bdcdata.
data : begin of itab occurs 0,
matnr like mara-matnr,
werks like t001w-werks,
ind(1) type c,
end of itab,
fg(1),bg(1),typ(1).
*include bdcrecx1.
start-of-selection.
import fg bg from memory id 'UNBW'.
if fg = 'X'.
typ = 'A'.
else.
typ = 'E'.
endif.
call function 'UPLOAD'
exporting
filename = 'C:\'
filetype = 'DAT'
tables
data_tab = itab
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.
perform bdc_dynpro using 'SAPMJ1ID' '0200'.
perform bdc_field using 'BDC_CURSOR'
'RB1'.
perform bdc_field using 'BDC_OKCODE'
'=EX'.
perform bdc_field using 'RB11'
'X'.
*perform bdc_field using 'RB1'
* 'X'.
loop at itab.
*perform open_group.
if itab-matnr na sy-abcde and itab-matnr na '/*-_.'.
unpack itab-matnr to itab-matnr.
else.
translate itab-matnr to upper case.
endif.
select single * from j_1imtchid where matnr = itab-matnr and werks = itab-werks.
if sy-subrc ne 0.
continue.
endif.
perform bdc_dynpro using 'SAPLJ1I5' '0020'.
perform bdc_field using 'BDC_CURSOR'
'J_1IMTCHID-MATNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'=POSI'.
perform bdc_dynpro using 'SAPLSPO4' '0300'.
perform bdc_field using 'BDC_CURSOR'
'SVALD-VALUE(02)'.
perform bdc_field using 'BDC_OKCODE'
'=FURT'.
perform bdc_field using 'SVALD-VALUE(01)'
itab-matnr. "'940101'.
perform bdc_field using 'SVALD-VALUE(02)'
itab-werks. "'7200'.
perform bdc_dynpro using 'SAPLJ1I5' '0020'.
perform bdc_field using 'BDC_CURSOR'
'J_1IMTCHID-J_1ICAPIND(01)'.
perform bdc_field using 'J_1IMTCHID-J_1ICAPIND(01)'
itab-ind. "C'.
endloop.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_dynpro using 'SAPLJ1I5' '0020'.
perform bdc_field using 'BDC_CURSOR'
'J_1IMTCHID-J_1ICAPIND(01)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_dynpro using 'SAPMJ1ID' '0200'.
perform bdc_field using 'BDC_OKCODE'
'/EEXIT'.
perform bdc_field using 'BDC_CURSOR'
'EXCISE'.
**perform bdc_transaction using 'J1ID'.
**
**perform close_group.
call transaction 'J1ID' using bdcdata mode typ update 'S'.
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform. "bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
* if fval <> ' '. "NODATA.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
* endif.
endform. "bdc_fieldReward if usefull
‎2008 Apr 10 11:10 AM
Hi, Refer this.
*Code used to create BDC
&----
*& Report ZBDC_EXAMPLE *
*& *
&----
*& Example BDC program, which updates net price of item 00010 of a *
*& particular Purchase order(EBELN). *
*& *
&----
REPORT ZBDC_EXAMPLE NO STANDARD PAGE HEADING
LINE-SIZE 132.
*----
Data declaration
TABLES: ekko, ekpo.
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekko-ebeln,
waers TYPE ekko-waers,
netpr TYPE ekpo-netpr,
err_msg(73) TYPE c,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko,
it_error TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_error TYPE t_ekko,
it_success TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_success TYPE t_ekko.
DATA: w_textout LIKE t100-text.
DATA: gd_update TYPE i,
gd_lines TYPE i.
*Used to store BDC data
DATA: BEGIN OF bdc_tab OCCURS 0.
INCLUDE STRUCTURE bdcdata.
DATA: END OF bdc_tab.
*Used to stores error information from CALL TRANSACTION Function Module
DATA: BEGIN OF messtab OCCURS 0.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF messtab.
*----
*Screen declaration
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME
TITLE text-001. "Purchase order Num
SELECT-OPTIONS: so_ebeln FOR ekko-ebeln OBLIGATORY.
SELECTION-SCREEN END OF BLOCK block1.
SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME
TITLE text-002. "New NETPR value
PARAMETERS: p_newpr(14) TYPE c obligatory. "LIKE ekpo-netpr.
SELECTION-SCREEN END OF BLOCK block2.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
Retrieve data from Purchase order table(EKKO)
SELECT ekkoebeln ekkowaers ekpo~netpr
INTO TABLE it_ekko
FROM ekko AS ekko INNER JOIN ekpo AS ekpo
ON ekpoebeln EQ ekkoebeln
WHERE ekko~ebeln IN so_ebeln AND
ekpo~ebelp EQ '10'.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
Check data has been retrieved ready for processing
DESCRIBE TABLE it_ekko LINES gd_lines.
IF gd_lines LE 0.
Display message if no data has been retrieved
MESSAGE i003(zp) WITH 'No Records Found'(001).
LEAVE TO SCREEN 0.
ELSE.
Update Customer master data (instalment text)
LOOP AT it_ekko INTO wa_ekko.
PERFORM bdc_update.
ENDLOOP.
Display message confirming number of records updated
IF gd_update GT 1.
MESSAGE i003(zp) WITH gd_update 'Records updated'(002).
ELSE.
MESSAGE i003(zp) WITH gd_update 'Record updated'(003).
ENDIF.
Display Success Report
**********************
Check Success table
DESCRIBE TABLE it_success LINES gd_lines.
IF gd_lines GT 0.
Display result report column headings
PERFORM display_column_headings.
Display result report
PERFORM display_report.
ENDIF.
Display Error Report
********************
Check errors table
DESCRIBE TABLE it_error LINES gd_lines.
If errors exist then display errors report
IF gd_lines GT 0.
Display errors report
PERFORM display_error_headings.
PERFORM display_error_report.
ENDIF.
ENDIF.
&----
*& Form DISPLAY_COLUMN_HEADINGS
&----
Display column headings
----
FORM display_column_headings.
WRITE:2 ' Success Report '(014) COLOR COL_POSITIVE.
SKIP.
WRITE:2 'The following records updated successfully:'(013).
WRITE:/ sy-uline(42).
FORMAT COLOR COL_HEADING.
WRITE:/ sy-vline,
(10) 'Purchase Order'(004), sy-vline,
(11) 'Old Netpr'(005), sy-vline,
(11) 'New Netpr'(006), sy-vline.
WRITE:/ sy-uline(42).
ENDFORM. " DISPLAY_COLUMN_HEADINGS
&----
*& Form BDC_UPDATE
&----
Populate BDC table and call transaction ME22
----
FORM bdc_update.
PERFORM dynpro USING:
'X' 'SAPMM06E' '0105',
' ' 'BDC_CURSOR' 'RM06E-BSTNR',
' ' 'RM06E-BSTNR' wa_ekko-ebeln,
' ' 'BDC_OKCODE' '/00', "OK code
'X' 'SAPMM06E' '0120',
' ' 'BDC_CURSOR' 'EKPO-NETPR(01)',
' ' 'EKPO-NETPR(01)' p_newpr,
' ' 'BDC_OKCODE' '=BU'. "OK code
Call transaction to update customer instalment text
CALL TRANSACTION 'ME22' USING bdc_tab MODE 'N' UPDATE 'S'
MESSAGES INTO messtab.
Check if update was succesful
IF sy-subrc EQ 0.
ADD 1 TO gd_update.
APPEND wa_ekko TO it_success.
ELSE.
Retrieve error messages displayed during BDC update
LOOP AT messtab WHERE msgtyp = 'E'.
Builds actual message based on info returned from Call transaction
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = messtab-msgid
msgnr = messtab-msgnr
msgv1 = messtab-msgv1
msgv2 = messtab-msgv2
msgv3 = messtab-msgv3
msgv4 = messtab-msgv4
IMPORTING
message_text_output = w_textout.
ENDLOOP.
Build error table ready for output
wa_error = wa_ekko.
wa_error-err_msg = w_textout.
APPEND wa_error TO it_error.
CLEAR: wa_error.
ENDIF.
Clear bdc date table
CLEAR: bdc_tab.
REFRESH: bdc_tab.
ENDFORM. " BDC_UPDATE
----
FORM DYNPRO *
----
stores values to bdc table *
----
--> DYNBEGIN *
--> NAME *
--> VALUE *
----
FORM dynpro USING dynbegin name value.
IF dynbegin = 'X'.
CLEAR bdc_tab.
MOVE: name TO bdc_tab-program,
value TO bdc_tab-dynpro,
'X' TO bdc_tab-dynbegin.
APPEND bdc_tab.
ELSE.
CLEAR bdc_tab.
MOVE: name TO bdc_tab-fnam,
value TO bdc_tab-fval.
APPEND bdc_tab.
ENDIF.
ENDFORM. " DYNPRO
&----
*& Form DISPLAY_REPORT
&----
Display Report
----
FORM display_report.
FORMAT COLOR COL_NORMAL.
Loop at data table
LOOP AT it_success INTO wa_success.
WRITE:/ sy-vline,
(10) wa_success-ebeln, sy-vline,
(11) wa_success-netpr CURRENCY wa_success-waers, sy-vline,
(11) p_newpr, sy-vline.
CLEAR: wa_success.
ENDLOOP.
WRITE:/ sy-uline(42).
REFRESH: it_success.
FORMAT COLOR COL_BACKGROUND.
ENDFORM. " DISPLAY_REPORT
&----
*& Form DISPLAY_ERROR_REPORT
&----
Display error report data
----
FORM display_error_report.
LOOP AT it_error INTO wa_error.
WRITE:/ sy-vline,
(10) wa_error-ebeln, sy-vline,
(11) wa_error-netpr CURRENCY wa_error-waers, sy-vline,
(73) wa_error-err_msg, sy-vline.
ENDLOOP.
WRITE:/ sy-uline(104).
REFRESH: it_error.
ENDFORM. " DISPLAY_ERROR_REPORT
&----
*& Form DISPLAY_ERROR_HEADINGS
&----
Display error report headings
----
FORM display_error_headings.
SKIP.
WRITE:2 ' Error Report '(007) COLOR COL_NEGATIVE.
SKIP.
WRITE:2 'The following records failed during update:'(008).
WRITE:/ sy-uline(104).
FORMAT COLOR COL_HEADING.
WRITE:/ sy-vline,
(10) 'Purchase Order'(009), sy-vline,
(11) 'Netpr'(010), sy-vline,
(73) 'Error Message'(012), sy-vline.
WRITE:/ sy-uline(104).
FORMAT COLOR COL_NORMAL.
ENDFORM. " DISPLAY_ERROR_HEADINGS
regards
Sourabh