Top Banner
7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 1/16  ABAP Code Sample for Material Master Update Using BDC © 2005 SAP AG 1  Applies To:  ABAP By : Kavitha Bhuvaneswaran Company: Wipro Technologies Date: 21 Jan. 2004 Prerequisite This program uses the example flat file (SDN logon required to download) containing material details. Procedure From the BDC selection screen, press F4 to browse for file and select the example flat file you have downloaded as a prerequisite. Once the file is selected a confirmation popup appears asking whether the file can be uploaded.
16

ABAP Code Sample for Material Master Update Using BDC.doc

Feb 23, 2018

Download

Documents

vbak24
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 1/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 1

 Appl ies To:

 ABAP

By: Kavitha Bhuvaneswaran

Company: Wipro Technologies

Date: 21 Jan. 2004

Prerequisite

This program uses the example flat file (SDN logon required to download) containing material details.

Procedure

From the BDC selection screen, press F4 to browse for file and select the example flat file you havedownloaded as a prerequisite.

Once the file is selected a confirmation popup appears asking whether the file can be uploaded.

Page 2: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 2/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 2

Confirm with yes to update the material master data using ‘CALL TRANSACTION’ method. Material master isupdated in transaction MM02. After successful execution, BDC results are displayed in report layout.

Page 3: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 3/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 3

Code

Source Code of Main Program

*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

* . . . . . . . . . . . Devel oper : Kavi t ha Bhuvanes war an. . . . . . . . . . . . . . . . . . . . . . . . . . . . *

*. . Desc: Mat eri al mast er update(usi ng BDC) and resul t i n repor t l ayout . . *

r eport zbdc_c7 .

*dat a decl ar at i ons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

dat a : answer ,

  count 1 t ype i ,

  count 2 t ype i .

Page 4: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 4/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 4

* i ncl ude contai ni ng def i ni t i on of var i ous f unct i ons . . . . . . . . . . . . . . . . . . . . *

i ncl ude zbdci ncl ude.

*t ypes decl ar at i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

t ypes : begi n of t _f i nal ,

  mat _no( 10) ,

  mat _name( 50) ,

  ol d_mat _name( 20) ,

  gross_wt ( 10) ,

  wt _uni t ( 5) ,

end of t _f i nal .

*i nt er nal t abl e decl ar at i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

data : i _ f i nal t ype tabl e of t _ f i nal .

*wor kar ea decl ar at i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

dat a : wa_f i nal t ype t _f i nal .

*sel ect i on scr een par amet er s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

paramet ers : f i l e l i ke r l grap- f i l ename obl i gat ory.

*on f 4 , a di al og- box f or f i l e sel ect i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

at sel ecti on- screen on val ue- r equest f or f i l e.

Page 5: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 5/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 5

  cal l f unct i on ' WS_FI LENAME_GET'

  expor t i ng

  mask = ' , *. *, *. *. '

  i mpor t i ng

  f i l ename = f i l e

  except i ons

  i nv_wi nsys = 1

  no_bat ch = 2

  sel ect i on_cancel = 3

  sel ect i on_err or = 4

  other s = 5

  .

  i f sy- subr c <> 0.

* MESSAGE I D SY- MSGI D TYPE SY- MSGTY NUMBER SY- MSGNO

* WI TH SY- MSGV1 SY- MSGV2 SY- MSGV3 SY- MSGV4.

  endi f .

  .

*st ar t of sel ect i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

start - of - sel ect i on.

  cal l f unct i on ' POPUP_TO_CONFI RM'

  expor t i ng

  t i t l ebar = ' Conf i rm Pop- UP'

  t ext _quest i on = ' Woul d you l i ke t o pr oceed?'

  i mpor t i ng

  answer = answer .

Page 6: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 6/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 6

  i f sy- subr c <> 0.

* MESSAGE I D SY- MSGI D TYPE SY- MSGTY NUMBER SY- MSGNO

* WI TH SY- MSGV1 SY- MSGV2 SY- MSGV3 SY- MSGV4.

  endi f .

* i f t he user conf i rms t he f i l e name and cl i cks yes i n popup. . . . . . . . . . . . *

  i f answer = ' 1' .

  cal l f unct i on ' WS_UPLOAD'

  expor t i ng

  f i l ename = f i l e

  f i l etype = ' DAT'

  t abl es

  dat a_t ab = i _f i nal .

  i f sy- subr c <> 0.

* MESSAGE I D SY- MSGI D TYPE SY- MSGTY NUMBER SY- MSGNO

* WI TH SY- MSGV1 SY- MSGV2 SY- MSGV3 SY- MSGV4.

  endi f .

  l oop at i _f i nal i nt o wa_f i nal .

  per f orm bdc_dynpro usi ng ' SAPLMGMM' ' 0060' .

  per f orm bdc_f i el d usi ng ' BDC_CURSOR'

  ' RMMG1- MATNR' .

  per f orm bdc_f i el d usi ng ' BDC_OKCODE'

  ' =AUSW' .

  per f orm bdc_f i el d usi ng ' RMMG1- MATNR'

  wa_f i nal - mat_no.

Page 7: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 7/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 7

  move wa_f i nal - mat _no t o wa_r esul t - mat _no.

  per f orm bdc_dynpro usi ng ' SAPLMGMM' ' 0070' .

  per f orm bdc_f i el d usi ng ' BDC_CURSOR'

  ' MSI CHTAUSW- DYTXT( 01) ' .

  per f orm bdc_f i el d usi ng ' BDC_OKCODE'

  ' =ENTR' .

  per f orm bdc_f i el d usi ng ' MSI CHTAUSW- KZSEL( 01) '

  ' X' .

  per f orm bdc_dynpro usi ng ' SAPLMGMM' ' 4004' .

  per f orm bdc_f i el d usi ng ' BDC_OKCODE'

  ' =BU' .

  perf orm bdc_f i el d usi ng ' MAKT- MAKTX'

  wa_f i nal - mat _name.

  move wa_f i nal - mat _name t o wa_r esul t - mat _name.

  perf or m bdc_f i el d usi ng ' MARA- BI SMT'

  wa_f i nal - ol d_mat _name.

  move wa_f i nal - ol d_mat _name t o wa_r esul t - ol d_mat _name.

  per f orm bdc_f i el d usi ng ' MARA- BRGEW'

  wa_f i nal - gr oss_wt .

  move wa_f i nal - gr oss_wt t o wa_r esul t - gr oss_wt .

  perf orm bdc_f i el d usi ng ' MARA- GEWEI '

  wa_f i nal - wt _uni t .

  move wa_f i nal - wt _uni t t o wa_r esul t - wt _uni t .

  perf or m bdc_t r ansact i on usi ng ' MM02' .

Page 8: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 8/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 8

*col l ect t he cor r ect l y updat ed ent r i es and t hei r cor r espondi ng success. *

* mes sage and stor e i t i n i nt er nal t abl e r i ght . . . . . . . . . . . . . . . . . . . . . . . . . . *

  i f f l ag = 1.

  append wa_r esul t t o r i ght.

  count 1 = count 1 + 1.

  el se.

*col l ect t he i nval i d ent ri es and thei r cor respondi ng er ror massage. . . . . *

*. . . . . . . and st or e i t i n i nt er nal t abl e wr ong. . . . . . . . . . . . . . . . . . . . . . . . . . *

  append wa_r esul t t o wr ong.

  count 2 = count 2 + 1.

  endi f .

  cl ear wa_r esul t .

  endl oop.

*di spl ayi ng t he successf ul i t ems and t hei r success messages. . . . . . . . . . . . *

  wr i t e : / ' SUCCESS I TEMS' .

  ski p.

  wr i t e : / ' NUMBER OF SUCCESS I TEMS : ' , count1, ' I TEMS' .

  ski p.

  l oop at ri ght i nt o wa_resul t .

  wr i t e : / wa_resul t - mat_no ,

Page 9: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 9/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 9

  7 wa_r esul t - mat _name ,

  40 wa_r esul t - ol d_mat _name ,

  50 wa_r esul t - gross_wt ,

  60 wa_r esul t - wt _uni t ,

  70 wa_r esul t - message.

  cl ear wa_r esul t .

  endl oop.

  ski p.

  ski p.

*di spl ayi ng the i nval i d entr i es and thei r err or messages. . . . . . . . . . . . . . . *

  wr i t e : / ' ERROR I TEMS' .

  ski p.

  wr i t e : / ' NUMBER OF ERROR I TEMS : ' , count2, ' I TEMS' .

  ski p.

  l oop at wr ong i nt o wa_r esul t .

  wr i t e : / wa_resul t - mat_no ,

  7 wa_r esul t - mat _name ,

  40 wa_r esul t - ol d_mat _name ,

  50 wa_r esul t - gross_wt ,

  60 wa_r esul t - wt _uni t ,

  70 wa_r esul t - message.

  cl ear wa_r esul t .

  endl oop.

Page 10: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 10/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 10

Include Used in Main Program

*I NCLUDE ZBDCI NCLUDE .

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

* data def i ni t i on

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

* Bat chi nput dat a of si ngl e t ransact i on

data: bdcdata l i ke bdcdata occurs 0 wi t h header l i ne.

* messages of cal l t r ansacti on

data: messt ab l i ke bdcmsgcol l occurs 0 wi t h header l i ne.

* er ror sessi on opened ( ' ' or ' X' )

data: e_group_opened.

* message t ext s

t abl es: t 100.

*t ypes decl ar at i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

*f i nal t abl e st r ucture f or hol di ng mat er i al det ai l s and t hei r updat e. . .

*message( success or f ai l ur e) det ai l s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

t ypes : begi n of resul t ,

  mat _no( 10) ,

  mat _name( 50) ,

  ol d_mat _name( 20) ,

  gross_wt ( 10) ,

  wt _uni t ( 5) ,

  message( 250) ,

Page 11: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 11/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 11

end of r esul t .

*i nt er nal t abl e decl ar at i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

*success ent r i es. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

dat a : r i ght t ype t abl e of r esul t .

*f ai l ur e ent r i es. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

data : wr ong t ype tabl e of r esul t .

*wor kar ea decl ar at i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

data : wa_r esul t t ype resul t .

dat a : f l ag t ype i .

data : gr oup( 12) .

data : ct umode l i ke ctu_par ams- di smode val ue ' N' .

data : user l i ke sy- uname.

data : cupdate l i ke ctu_par ams- updmode val ue ' L' .

data : e_gr oup( 12) .

data : e_user l i ke sy- uname.

data : e_keep.

data : e_hdate l i ke sy- datum.

dat a : nodat a val ue ' / ' .

dat a : smal l l og val ue ' ' .

move sy- uname t o e_user .

move sy- uname t o user .

Page 12: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 12/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 12

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

* end batchi nput sessi on

* ( cal l tr ansacti on usi ng. . . : err or sessi on)

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

f orm cl ose_gr oup.

  i f e_gr oup_opened = ' X' .

  cal l f unct i on ' BDC_CLOSE_GROUP' .

  wr i te: / .

  wr i t e: / ( 30) ' Fehl er mappe wur de er zeugt ' ( i 06) .

  endi f .

endf or m.

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

* St art new t ransact i on accor di ng t o parameters

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

f orm bdc_t r ansact i on usi ng t code.

  data: l _mst r i ng( 480) .

  dat a: l _subr c l i ke sy- subr c.

  r ef r esh messt ab.

  cal l t r ansacti on t code usi ng bdcdata

  mode ct umode

  updat e cupdat e

Page 13: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 13/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 13

  messages i nto messt ab.

  l _subr c = sy- subr c.

  i f smal l l og <> ' X' .

  l oop at messt ab.

  sel ect si ngl e * f r omt 100 where sprs l = messt ab- msgspr a

  and ar bgb = messt ab- msgi d

  and msgnr = messt ab- msgnr .

  i f sy- subr c = 0.

  l _mst r i ng = t 100- t ext.

  i f l _mstr i ng cs ' &1' .

  r epl ace ' &1' wi t h messt ab- msgv1 i nto l _mst r i ng.

  r epl ace ' &2' wi t h messt ab- msgv2 i nto l _mst r i ng.

  r epl ace ' &3' wi t h messt ab- msgv3 i nto l _mst r i ng.

  r epl ace ' &4' wi t h messt ab- msgv4 i nto l _mst r i ng.

  el se.

  r epl ace ' &' wi t h messt ab- msgv1 i nt o l _mst r i ng.

  r epl ace ' &' wi t h messt ab- msgv2 i nt o l _mst r i ng.

  r epl ace ' &' wi t h messt ab- msgv3 i nt o l _mst r i ng.

  r epl ace ' &' wi t h messt ab- msgv4 i nt o l _mst r i ng.

  endi f .

  condense l _mst r i ng.

  i f messt ab- msgtyp = ' S' .

*successf ul updat i on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

  f l ag = 1.

  el se.

*i nval i d ent r y. . not updat ed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . *

Page 14: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 14/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 14

  f l ag = 2.

  endi f .

  move l _mst r i ng t o wa_r esul t - message.

  el se.

  wr i t e: / messt ab.

  endi f .

  endl oop.

  endi f .

  i f l _s ubr c <> 0 and e_gr oup <> space.

  i f e_gr oup_opened = ' ' .

  cal l f unct i on ' BDC_OPEN_GROUP'

  expor t i ng cl i ent = sy- mandt

  group = e_gr oup

  user = e_user

  keep = e_keep

  hol ddat e = e_hdat e.

  e_group_opened = ' X' .

  endi f .

  cal l f unct i on ' BDC_I NSERT'

  expor t i ng t code = t code

  t abl es dynpr otab = bdcdat a.

  endi f .

  r ef r esh bdcdat a.

endf or m.

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

* St art new scr een *

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

f orm bdc_dynpr o usi ng pr ogr am dynpr o.

Page 15: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 15/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 15

  cl ear bdcdata.

  bdcdat a- program = progr am.

  bdcdat a- dynpro = dynpro.

  bdcdata- dynbegi n = ' X' .

  append bdcdata.

endf or m.

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

* I nser t f i el d

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

f orm bdc_fi el d usi ng f nam f val .

  i f f val <> nodata.

  cl ear bdcdat a.

  bdcdata- f nam = f nam.

  bdcdat a- f val = f val .

  append bdcdata.

  endi f .

Endform.

Disclaimer & L iability Notice

This document may discuss sample coding, which does not include official interfaces and therefore is not

supported. Changes made based on this information are not supported and can be overwritten during anupgrade.

SAP will not be held liable for any damages caused by using or misusing of the code and methods suggestedhere, and anyone using these methods, is doing it under his/her own responsibility.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of the technical article, including any liability resulting from incompatibility between the content of the technicalarticle and the materials and services offered by SAP. You agree that you will not hold SAP responsible or liable with respect to the content of the Technical Article or seek to do so.

Page 16: ABAP Code Sample for Material Master Update Using BDC.doc

7/24/2019 ABAP Code Sample for Material Master Update Using BDC.doc

http://slidepdf.com/reader/full/abap-code-sample-for-material-master-update-using-bdcdoc 16/16

 ABAP Code Sample for MaterialMaster Update Using BDC

© 2005 SAP AG 16

Copyright © 2005 SAP AG, Inc. All Rights Reserved. SAP, mySAP, mySAP.com, xApps, xApp, and other SAP products and services

mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several othercountries all over the world. All other product, service names, trademarks and registered trademarks mentioned are the trademarks of their respective owners.