2008 Feb 07 8:22 AM
Hi gurus,
plz give me a bdc programm with call transaction with the use of an internal tables.
its urgent.
2008 Feb 07 8:24 AM
Check the following code:
..
REPORT Z_B1_ADV_BDC .
*reference to DB tables
TABLES: CAUFVD, AUFPAR.
PARAMETER:
*path of the flat file
FNAME LIKE RLGRAP-FILENAME .
DATA:
FLENGTH TYPE I,REC_CNT TYPE I VALUE 1, FLAG TYPE I VALUE 0,
CONTINUE_FLAG TYPE I VALUE 0.
*import parameter from ws_upload
DATA: TAB(80) OCCURS 5 WITH HEADER LINE.
*internal table:
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE CAUFVD-MATNR,
DNAME LIKE CAUFVD-WERKS,
ORDER LIKE AUFPAR-PP_AUFART,
QTY(31) TYPE C,
UNITS(3) TYPE C,
FIN_DATE LIKE CAUFVD-GLTRP,
BGN_DATE LIKE CAUFVD-GSTRP,
SCH_TYPE LIKE CAUFVD-TERKZ,
END OF ITAB.
DATA: BEGIN OF ERR_TAB OCCURS 0,
ERROR(20) TYPE C,
VALIDATION(50) TYPE C,
END OF ERR_TAB.
*BDCDATA STRUCTURE
DATA: BEGIN OF BDCDATA OCCURS 0.
INCLUDE STRUCTURE BDCDATA.
DATA:END OF BDCDATA.
*MESSTAB STRUCTURE
DATA: BEGIN OF MESSTAB OCCURS 10.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA: END OF MESSTAB.
constants: c_08 type X value '08'.
START-OF-SELECTION.
*CHECK IF FILE NAME IS NOT ENTERED
IF FNAME CO ' '.
MESSAGE I214(ZZ).
CONTINUE_FLAG = 1.
ENDIF.
IF CONTINUE_FLAG = 0.
*upload the file contents to tab.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = 'IBM '
FILENAME = FNAME
FILETYPE = 'ASC'
IMPORTING
FILELENGTH = FLENGTH
TABLES
DATA_TAB = TAB
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5.
*VALIDATIONS
IF SY-SUBRC = 0.
MESSAGE I225(ZZ).
ELSEIF SY-SUBRC = 1.
MESSAGE I217(ZZ).
ELSEIF SY-SUBRC = 2.
MESSAGE I218(ZZ).
ELSEIF SY-SUBRC = 3.
MESSAGE I219(ZZ).
ELSEIF SY-SUBRC = 4.
MESSAGE I220(ZZ).
ELSEIF SY-SUBRC = 5.
MESSAGE I223(ZZ).
ENDIF.
*split the file into the required fields.
LOOP AT TAB.
SPLIT TAB AT c_08 INTO ITAB-MATNR ITAB-DNAME ITAB-ORDER ITAB-QTY
ITAB-UNITS ITAB-FIN_DATE ITAB-BGN_DATE ITAB-SCH_TYPE.
APPEND ITAB.
CLEAR ITAB.
ENDLOOP.
* VALIDATIONS
LOOP AT ITAB.
FLAG = 0.
IF ITAB-MATNR CO ' '.
ERR_TAB-ERROR = 'MATERIAL'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF ITAB-DNAME CO ' '.
ERR_TAB-ERROR = 'PLANT'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF ITAB-ORDER CO ' '.
ERR_TAB-ERROR = 'ORDER'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF ITAB-QTY CO ' '.
ERR_TAB-ERROR = 'QUANTITY'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF ITAB-UNITS CO ' '.
ERR_TAB-ERROR = 'UNITS'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF ITAB-FIN_DATE CO ' '.
ERR_TAB-ERROR = 'FINISH DATE'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF ITAB-BGN_DATE CO ' '.
ERR_TAB-ERROR = 'BEGIN DATE'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF ITAB-SCH_TYPE CO ' '.
ERR_TAB-ERROR = 'SCHEDULE TYPE'.
ERR_TAB-VALIDATION = 'VALUE LEFT BLANK'.
APPEND ERR_TAB.
CLEAR ERR_TAB.
FLAG = 1.
ENDIF.
IF FLAG = 0.
*call functions to populate the BDCDATA structure.
PERFORM INSERT_SCREEN USING 'SAPLCOKO1' '0100' 'X'.
PERFORM INSERT_FIELD USING 'BDC_CURSOR' 'CAUFVD-WERKS'.
PERFORM INSERT_FIELD USING 'CAUFVD-MATNR' ITAB-MATNR.
PERFORM INSERT_FIELD USING 'CAUFVD-WERKS' ITAB-DNAME.
PERFORM INSERT_FIELD USING 'AUFPAR-PP_AUFART' ITAB-ORDER.
PERFORM INSERT_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM INSERT_SCREEN USING 'SAPLCOKO1' '0115' 'X'.
PERFORM INSERT_FIELD USING 'BDC_SUBSCR' 'SAPLCOKO1'.
PERFORM INSERT_FIELD USING 'BDC_SUBSCR' '0120SUBSCR_0115'.
PERFORM INSERT_FIELD USING 'BDC_CURSOR' 'CAUFVD-GLTRP'.
PERFORM INSERT_FIELD USING 'CAUFVD-GAMNG' ITAB-QTY.
PERFORM INSERT_FIELD USING 'CAUFVD-GMEIN' ITAB-UNITS.
PERFORM INSERT_FIELD USING 'CAUFVD-GLTRP' ITAB-FIN_DATE.
PERFORM INSERT_FIELD USING 'CAUFVD-GSTRP' ITAB-BGN_DATE.
PERFORM INSERT_FIELD USING 'CAUFVD-TERKZ' ITAB-SCH_TYPE.
PERFORM INSERT_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM INSERT_FIELD USING 'BDC_OKCODE' '=BU'.
*CALL TRANSACTION TO INSERT THE DATA IN TO THE TABLE
CALL TRANSACTION 'CO01' USING BDCDATA MODE 'N' UPDATE 'S' MESSAGES
INTO MESSTAB.
REFRESH BDCDATA.
*OUTPUT THE RESULTS
SKIP 2.
WRITE : / 'Record ', REC_CNT LEFT-JUSTIFIED.
*OBTAIN MESSAGES FROM MESSAGE STRUCTURE
LOOP AT MESSTAB.
IF MESSTAB-MSGTYP = 'E'.
WRITE : / 'Input to field ', 17 MESSTAB-FLDNAME, 30' is invalid'.
ELSEIF MESSTAB-MSGNR = 100.
WRITE : / 'Order NO:', 11 MESSTAB-MSGV1, 20 'is created successfully'.
ENDIF.
ENDLOOP.
REFRESH MESSTAB.
ADD 1 TO REC_CNT.
SKIP 2.
ELSE.
SKIP.
WRITE: 'ERROR AT', 25 'VALIDATION'.
LOOP AT ERR_TAB.
WRITE:/ ERR_TAB-ERROR, ERR_TAB-VALIDATION.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
*---------------------------------------------------------------------
** FORM insert_Screen
**---------------------------------------------------------------------
** ........
**---------------------------------------------------------------------
** --> PROGRAM
** --> DYNPRO
** --> DYNBEGIN
**---------------------------------------------------------------------
FORM INSERT_SCREEN USING PROGRAM DYNPRO DYNBEGIN.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = DYNBEGIN.
APPEND BDCDATA.
ENDFORM.
*
**---------------------------------------------------------------------
** FORM insert_field
**---------------------------------------------------------------------
** ........
**---------------------------------------------------------------------
** --> FNAM
** --> FVAL
**---------------------------------------------------------------------
FORM INSERT_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.
Edited by: Abhishek Sarkar on Feb 7, 2008 9:25 AM
2008 Feb 07 8:24 AM
hi,
chk this...
*&---------------------------------------------------------------------*
*& Report ZP_CALL_TRANS_1 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZP_CALL_TRANS_1 .
*&---------------------------------------------------------------------*
*& internal table declaration
**&---------------------------------------------------------------------
*
data: begin of record,
* data element: BUKRS
BUKRS_001(004),
* data element: KTOKK
KTOKK_002(004),
* data element: NAME1_GP
NAME1_003(035),
* data element: SORTL
SORTL_004(010),
* data element: LAND1_GP
LAND1_005(003),
end of record.
data: it_vendor like recOrd occurs 0 with header line.
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
***************************************************
*selection screen.
***************************************************
selection-screen: begin of block b1 with frame.
parameters: p_file like rlgrap-filename default 'c:/vendor.txt'
obligatory.
selection-screen: end of block b1.
***************************************************
*at selection screen.
***************************************************
at selection-screen on value-request for p_file.
perform f4_help using p_file.
***************************************************
*start of selection
***************************************************
start-of-selection.
*******uploading file
perform upload_file using p_file.
******open session.
perform POPULATE_DATA.
*&---------------------------------------------------------------------*
*& Form f4_help
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_FILE text
*----------------------------------------------------------------------*
form f4_help using p_p_file.
data: l_file type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = l_file.
p_file = l_file.
endform. " f4_help
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_FILE text
*----------------------------------------------------------------------*
form upload_file using p_p_file.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
* CODEPAGE = ' '
FILENAME = p_p_file
FILETYPE = 'dat'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
TABLES
data_tab = it_vendor
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
NO_AUTHORITY = 10
OTHERS = 11
.
IF sy-subrc <> 0.
message i000(zz) with p_p_file.
ENDIF.
endform. " upload_file
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form POPULATE_DATA .
LOOP AT IT_VENDOR.
perform bdc_dynpro using 'SAPMF02K' '0105'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-BUKRS'
IT_VENDOR-BUKRS_001.
perform bdc_field using 'RF02K-KTOKK'
IT_VENDOR-KTOKK_002.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-NAME1'
IT_VENDOR-NAME1_003.
perform bdc_field using 'LFA1-SORTL'
IT_VENDOR-SORTL_004.
perform bdc_field using 'LFA1-LAND1'
IT_VENDOR-LAND1_005.
******CALL TRANSACTION.
CALL TRANSACTION 'FK01' USING IT_BDCDATA MODE 'A'
UPDATE 'S'
MESSAGES INTO IT_MESSAGES.
WRITe:/ SY-SUBRC.
PERFORM FORMAT_MESSAGES.
CLEAR IT_BDCDATA.
REFRESH IT_BDCDATA.
ENDLOOP.
endform. " POPULATE_DATA
*&---------------------------------------------------------------------*
*& Form FORMAT_MESSAGES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form FORMAT_MESSAGES .
DATA: L_MSG(100).
LOOP AT IT_MESSAGES.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = IT_MESSAGES-MSGID
LANG = SY-LANGU
NO = IT_MESSAGES-MSGNR
V1 = IT_MESSAGES-MSGV1
V2 = IT_MESSAGES-MSGV2
V3 = IT_MESSAGES-MSGV3
V4 = IT_MESSAGES-MSGV4
IMPORTING
MSG = L_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
write:/ l_msg.
endloop.
endform. " FORMAT_MESSAGES
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0173 text
* -->P_0174 text
*----------------------------------------------------------------------*
form bdc_dynpro using value(p_PROGRAM)
value(p_SCREEN).
IT_BDCDATA-PROGRAM = P_PROGRAM.
IT_BDCDATA-DYNPRO = P_SCREEN.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
endform. " bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0178 text
* -->P_0179 text
*----------------------------------------------------------------------*
form bdc_field using value(p_FNAM)
value(p_FVAL).
IT_BDCDATA-FNAM = P_FNAM.
IT_BDCDATA-FVAL = P_FVAL.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
endform. " bdc_field
regards,
priya.
2008 Feb 07 8:24 AM
Following is a sample code with call transaction and handling table control in BDC.
REPORT Y730_BDC5 .
*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.
LOOP AT IT_BANK WHERE LIFNR = IT_XK01-LIFNR.
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.
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.
Reward points if useful.
2008 Feb 07 8:26 AM
HI,
Definition
DATA: BEGIN OF lt_data_new OCCURS 0,
kunwe LIKE komb-kunwe,
vstel LIKE yvert538-vstel,
parvw LIKE nach-parvw,
parnr LIKE rv13b-parnr,
nacha LIKE nach-nacha,
vsztp LIKE nach-vsztp,
spras LIKE nach-spras,
ldest LIKE nach-ldest,
anzal TYPE num2, "nach-anzal,
dimme LIKE nach-dimme, "sofort Ausgeben
END OF lt_data_new.
DATA: lt_data_change LIKE TABLE OF lt_data_new.
DATA: ls_data LIKE LINE OF lt_data_new.
DATA: lt_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,
l_mode TYPE c VALUE 'N'.
Call transaction
LOOP AT lt_data_new INTO ls_data.
REFRESH lt_bdcdata.
set_dyn_bi 'SAPMV13B' '1612'.
set_var_bi 'BDC_OKCODE' '=MARK'.
set_var_bi 'BDC_CURSOR' 'KOMB-KUNWE(01)'.
set_var_bi 'KOMB-VSTEL' ls_data-vstel.
set_var_bi 'KOMB-KUNWE(01)' ls_data-kunwe.
set_var_bi 'NACH-PARVW(01)' ls_data-parvw.
set_var_bi 'NACH-NACHA(01)' ls_data-nacha.
set_var_bi 'NACH-VSZTP(01)' ls_data-vsztp.
set_dyn_bi 'SAPMV13B' '1612'.
set_var_bi 'BDC_OKCODE' '=KOMM'.
set_dyn_bi 'SAPMV13B' '0211'.
set_var_bi 'BDC_OKCODE' '=SICH'.
set_var_bi 'NACH-LDEST' ls_data-ldest.
set_var_bi 'NACH-DIMME' ls_data-dimme.
set_var_bi 'NACH-ANZAL' ls_data-anzal.
create
CALL TRANSACTION 'VV21' USING lt_bdcdata
MODE l_mode
UPDATE 'S'
MESSAGES INTO gt_messtab.
ENDLOOP. "LT_DATA_NEW
2008 Feb 07 9:30 AM
*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
2008 Feb 07 9:38 AM
Hi
BDC using Call transaction involves calling an SAP transaction in back ground from within the ABAP
program. The process involves building an Internal BDC table containing the screen information needed to
execute the required transaction and then passing this to the Call transaction command (See code example).
The full procedure for creating a BDC program is as follows:
STEP 1
Create recording using SM35(or SHDB).
STEP 2
Use recording as a basis to populate the Internal BDC table. See
'FORM bdc_update' within the code example
http://www.sapdev.co.uk/bdc/bdc_recording.htm
*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