2006 Sep 19 7:59 AM
Can any one please let me know the process of recording table control in BDC. If possible can any one send across the sample code for that.
Thanks and Regards,
Sawanth.
2006 Sep 19 8:00 AM
Hi,
you can search this Forum and you'll get lotsa code.
Regards
Nishant
2006 Sep 19 8:00 AM
hi,
Following is a sample code of 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.
rgds
anver
if hlped amrk points
2006 Sep 19 8:01 AM
Hi,
BDC recording provides a simple way to generate BDC code for executing transactions.
By running <b>SHDB</b> and recording a BDC, you can then simply convert it to program code. This prevents you from having to figure out all the function codes and screen numbers manually.
Regards,
Senthil
2006 Sep 19 8:06 AM
2006 Sep 20 12:12 PM
Table control has always x of x text field at bottom. which will tell how many records are there in control. E.g. me38 transaction displays schedule lines. if you 10 schedule lines it will display xx of 10 records where xx represents each line. When you enter any number between 1 to 10, that records appear at first row. This will help you in modifying or editing particular record. If you want to enter new record, you can enter 10 of 10 in text field that will display last record at first row and you can use second row to add new record. This way you can prevent by gettting modified existing record wrongly.
Hope it hepls. Reward points if it helps.
2006 Sep 20 12:22 PM
Hi,
As u r new to BDC jus try like this- BDC is Batch Data Communication which is used to transfer data frm SAP to SAP as well as SAP to NON-SAP system.
This is done using recording using TXN SHDB.
Just go in TXN SHDB write any TXN like FB50, VA01, ME21, ME41, MIGO, IW51, IW31, MM01, MB1A, VK11, VF01, VL01 so on... and enter ne name for it like ZFB50 start recording whatever steps u'll perform will return as a BDC with Prog and field names going back again on TXN SHDB u'll see a session of name
ZFB50 and also an option of program and Function Module written on the application toolbar jus click on ne of them it will create a prog or FM based on what u had clicked and hence u can run it...
Try this code-
TABLES: CTU_PARAMS.
DATA: L_ITM_MENGE LIKE V46R_ITEM-MENGE,
L_CHARGE LIKE EQUI-CHARGE,
L_V46RMATNR(24) TYPE C,
L_V46RMENGE(22) TYPE C,
L_V46RVAL(32) TYPE C,
L_V46CHARG(32) TYPE C,
L_V46LGORT(32) TYPE C,
L_PSTYV LIKE VBAP-PSTYV,
C_E TYPE C VALUE 'E', "Engine orders
W_BATCH LIKE MARA-XCHPF,
C_X TYPE C VALUE 'X',
ZINCUP LIKE TVAK-INCUP,
W_TEXT(30),
L_REC(2) TYPE C,
W_ITM_CAT LIKE ZMROPCC_CON-ZTVARV_VAL,
L_LINE TYPE I,
L_DATE(10).
CONSTANTS:C_ITM_CAT LIKE ZMROPCC_CON-ZRVARI_VNAM VALUE 'EX_STOCK_E'.
DATA: BEGIN OF T_VBAP OCCURS 0,
VBELN TYPE VBAP-VBELN,
PSTYV TYPE VBAP-PSTYV,
POSNR TYPE VBAP-POSNR,
END OF T_VBAP.
DATA: BEGIN OF T_QMEL OCCURS 0.
INCLUDE STRUCTURE VIQMEL.
DATA: END OF T_QMEL.
DATA: W_MATNR_BAT LIKE BAPIBATCHKEY-MATERIAL, "VJ0805
W_WERKS_BAT LIKE BAPIBATCHKEY-PLANT,
W_CHARG_BAT LIKE BAPIBATCHKEY-BATCH,
W_LGORT_BAT LIKE BAPIBATCHSTOLOC-STGE_LOC,
W_NEW_BATCH_BAT LIKE BAPIBATCHKEY-BATCH.
Report the progress to the user
W_TEXT = TEXT-115.
PERFORM REPORT_PROGRESS USING W_TEXT.
Get line items detail
SELECT VBELN PSTYV POSNR FROM VBAP INTO TABLE T_VBAP
WHERE VBELN = S_ORDER.
DESCRIBE TABLE T_VBAP LINES L_LINE.
Get Batch details
L_CHARGE = BATCH.
Enter VA02 information
CLEAR T_BDCTAB[].
PERFORM BDC_DYNPRO USING 'SAPMV45A' '0102'.
PERFORM BDC_FIELD USING 'VBAK-VBELN'
S_ORDER.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
Get into the Repair Screen
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=PREP'.
Press the switch button to show both lines on screen.
PERFORM BDC_DYNPRO USING 'SAPLV46R' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=RALL'.
Press the Plus button to add line items
PERFORM BDC_DYNPRO USING 'SAPLV46R' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=RINS'.
Set line counter
L_REC = 2.
L_REC = L_LINE - 1.
L_REC = L_REC + 1.
SHIFT L_REC RIGHT DELETING TRAILING ' '.
OVERLAY L_REC WITH '00'.
CLEAR L_V46RMATNR .
CONCATENATE 'V46R_ITEM-MATNR_G(' L_REC ')' INTO L_V46RMATNR.
CLEAR L_V46RMENGE .
CONCATENATE 'V46R_ITEM-MENGE(' L_REC ')' INTO L_V46RMENGE.
CLEAR L_V46RVAL.
CONCATENATE 'V46R_ITEM-VORGA_VAL_106(' L_REC ')'
INTO L_V46RVAL.
Update the values at the Repairs tab
PERFORM BDC_DYNPRO USING 'SAPLV46R' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
Pass the quantity
L_ITM_MENGE = T_QUAN.
PERFORM BDC_FIELD USING L_V46RMENGE
L_ITM_MENGE.
Update material number
PERFORM BDC_FIELD USING L_V46RMATNR
MATNR.
Update exchange flag
PERFORM BDC_FIELD USING L_V46RVAL
C_X.
Press the back button
PERFORM BDC_DYNPRO USING 'SAPLV46R' '4001'. "+KP0715 test
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=S\BACK'.
Show all sub line items on the sales order
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=UALL'.
Reset line counter
DESCRIBE TABLE T_VBAP LINES L_REC.
start of get vbap-posnr for update below "+KP071504
CLEAR: T_VBAP, ZINCUP.
SORT T_VBAP BY POSNR ASCENDING.
READ TABLE T_VBAP INDEX L_REC.
IF SY-SUBRC IS INITIAL.
SELECT SINGLE INCUP FROM TVAK INTO ZINCUP
WHERE AUART = ( SELECT AUART FROM VBAK
WHERE VBELN = S_ORDER ).
ENDIF.
Get the popup screen to position new posnr
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=POPO'.
Fill new POSNR
T_VBAP-POSNR = T_VBAP-POSNR + ZINCUP.
PERFORM BDC_DYNPRO USING 'SAPMV45A' '0251'.
PERFORM BDC_FIELD USING 'RV45A-POSNR' T_VBAP-POSNR.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=POSI'.
SELECT SINGLE ZTVARV_VAL
FROM ZMROPCC_CON
INTO W_ITM_CAT
WHERE ZRVARI_VNAM = C_ITM_CAT.
L_PSTYV = W_ITM_CAT.
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'VBAP-PSTYV(01)' L_PSTYV.
Double click on the new posnr to go to the detailed screen
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4001'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=ITEM'.
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4003'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
Update the Batch
PERFORM BDC_FIELD USING 'VBAP-CHARG'
L_CHARGE.
IF NOT SERNR IS INITIAL.
Press Extra-> technical Objects
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4003'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=POTO'.
Populate Serial Number
PERFORM BDC_DYNPRO USING 'SAPLIPW1' '0200'.
PERFORM BDC_FIELD USING 'RIPW0-SELKZ(1)'
C_X.
PERFORM BDC_FIELD USING 'RIPW0-SERNR(1)'
SERNR.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=RWS'.
ENDIF.
Press the save button
PERFORM BDC_DYNPRO USING 'SAPMV45A' '4003'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=SICH'.
CLEAR CTU_PARAMS.
CTU_PARAMS-DISMODE = 'E'.
CTU_PARAMS-UPDMODE = 'S'.
CTU_PARAMS-DEFSIZE = 'X'.
*
Call the transaction
CALL TRANSACTION 'VA02' USING T_BDCTAB OPTIONS FROM CTU_PARAMS
MESSAGES INTO T_BDCMSGCOLL.
Error processing
READ TABLE T_BDCMSGCOLL WITH KEY MSGTYP = C_E.
IF SY-SUBRC = 0.
MESSAGE ID T_BDCMSGCOLL-MSGID TYPE C_E
NUMBER T_BDCMSGCOLL-MSGNR.
ENDIF.
Hope this helps u.
Regards.
Seema.