Shared Top Border

Enterprise Resource
Planning Portal

 

Advertise | Founder BLOG

ERPGenie.COM ABAP Tips and Tricks Database

THE ultimate
ERP website

 

Forums | Vote for us |

Google    Other Search Options

Login

Login to view more content!!!





Lost Password?
No account yet? Register

Registered Access

Poll

What area of ABAP are you interested in?
 
Home arrow Sample Code arrow BDC arrow Batch Input: Updating Material Master via BDC
Batch Input: Updating Material Master via BDC PDF Print E-mail
User Rating: / 2
PoorBest 
Written by Anon.   
Monday, 19 March 2007
This skeleton displays how to:
  1. Determine all selection views available for user in the given transaction (MM01, MM02);
  2. Prepare BDC to access required view;
report z.

constants: c_rows(2) type n value '18', " rows in view selection
" window
c_linen(20) type c value 'MSICHTAUSW-KZSEL( )'.
data: w_tcode like sy-tcode, " Transaction code
w_tkstatus like t130m-pstat, " SAP Transaction status
w_anzgstatus like t130m-pstat, " Summary Display status
w_t130m like t130m, " Transaction control: mat.master
w_bilds like t133a-bilds, " Screen sequence
w_dytxt like t133b-dytxt, " View description
w_linex like sy-tabix, " View # in table
w_line like sy-tabix, " View # on selection screen
w_num like sy-tabix,
w_matnr like mara-matnr, " Material
w_mtart like mara-mtart, " Material type
w_vpsta like mara-vpsta, " Material maintenance status
w_pstat like t134-pstat. " Material type maintenance status
data: begin of it_views occurs 30.
include structure mbildtab. " Selection Views
data: end of it_views.
data: w_alnum(20) type c, " TC line
f_pgdn. " PgDn Flag
data: begin of i_bdc occurs 0.
include structure bdcdata.
data: end of i_bdc.

parameters:
material like mara-matnr obligatory memory id mat,
view like t133a-auswg obligatory default '21',
mm01 radiobutton group radi,
mm02 radiobutton group radi,
show_bdc as checkbox,
showview as checkbox.

*******************
start-of-selection.
*******************
if not mm01 is initial.
w_tcode = 'MM01'. "Create view
else.
w_tcode = 'MM02'. "Change view
endif.

* 1. Get Transaction Status and Transaction Screen Reference
call function 'MATERIAL_INIT'
exporting
tcode = w_tcode
kz_berprf = 'X'
importing
it130m = w_t130m
tkstatus = w_tkstatus
exceptions
no_authority = 1
wrong_call = 2
kstatus_empty = 3
tkstatus_empty = 4
aktyp_tcode_mismatch = 5
tcode_not_found = 6
material_article_mismatch = 7
others = 8.
if sy-subrc <> 0.
write: 'MATERIAL_INIT error code =', sy-subrc.
exit.
endif.

* 2. Get Material type and maintenance statuses
select single matnr mtart vpsta from mara
into (w_matnr, w_mtart, w_vpsta)
where matnr = material.
if sy-subrc <> 0.
write: 'Material', material, 'not in material master'.
exit.
endif.
select single pstat from t134 into w_pstat
where mtart = w_mtart.
if sy-subrc <> 0.
write: 'Material type', w_mtart, 'not found'.
endif.


* 3. Get Screen Sequence for Tcode/Material
call function 'BILDSEQUENZ_IDENTIFY'
exporting
materialart = w_mtart
tcode_ref = w_t130m-trref
importing
bildsequenz = w_bilds
exceptions
wrong_call = 1
not_found = 2
others = 3.
if sy-subrc <> 0.
write: 'BILDSEQUENZ_IDENTIFY error code =', sy-subrc.
exit.
endif.

* 4. Get Summary status (Transaction+Material+Material Type)
call function 'ANZGSTATUS_SETZEN'
exporting
aktyp = w_t130m-aktyp
marastatus = w_vpsta
t134status = w_pstat
tkstatus = w_tkstatus
importing
anzgstatus = w_anzgstatus
exceptions
anzgstatus_empty = 1
wrong_call = 2
others = 3.
if sy-subrc <> 0.
write: 'ANZGSTATUS_SETZEN error code =', sy-subrc.
exit.
endif.

* 5. Get all selection views:
call function 'SELECTION_VIEWS_FIND'
exporting
bildsequenz = w_bilds
pflegestatus = w_anzgstatus
tables
bildtab = it_views
exceptions
call_wrong = 1
empty_selection = 2
others = 3.
if sy-subrc <> 0.
write: 'SELECTION_VIEWS_FIND error code =', sy-subrc.
exit.
endif.

* 5. Get view #:
read table it_views with key auswg = view.
if sy-subrc = 0.
w_linex = sy-tabix.
else.
write: 'View', view, 'not found'.
exit.
endif.

* 6. Prepare BDC:
if w_linex gt c_rows.
w_line = w_linex - c_rows.
f_pgdn = 'X'.
endif.
w_alnum = c_linen.
w_alnum+17(2) = w_line.

if not mm01 is initial.
perform bdc_mm01.
else.
perform bdc_mm02.
endif.


*******************
end-of-selection.
*******************
select single dytxt into w_dytxt from t133b
where spras = sy-langu
and bilds = w_bilds
and auswg = view.
if sy-subrc <> 0.
clear w_dytxt.
endif.
describe table it_views lines w_num.
write: / 'Screen sequence =', w_bilds,
/ 'Selection view', view, w_dytxt,
/ 'View Number = ', w_linex,
/ 'Selection views:', w_num.
if not showview is initial.
write: / '********* Table of views: *********'.
loop at it_views.
write / it_views.
endloop.
endif.
if not show_bdc is initial.
write: / '********* Table of BDC: *********'.
loop at i_bdc.
write / i_bdc.
endloop.
endif.

*&---------------------------------------------------------------------*
*& Form bdc_mm02
*&---------------------------------------------------------------------*
form bdc_mm02.
* for example, Accounting View 1 (21)

perform dynpro using:
*goto MM02 - Change Mateial (Initial screen)
'X' 'SAPLMGMM' '0060',
' ' 'BDC_CURSOR' 'RMMG1-MATNR',
' ' 'RMMG1-MATNR' w_matnr,
*goto Select View(s) screen
' ' 'BDC_OKCODE' '=AUSW'.

if f_pgdn = 'X'.
perform dynpro using:
*goto Select View(s) screen
'X' 'SAPLMGMM' '0070',
*scroll down
' ' 'BDC_OKCODE' '=P+'.
endif.

perform dynpro using:
*goto Select View(s) screen
'X' 'SAPLMGMM' '0070',
' ' w_alnum 'X',
*Select Accounting1 view
' ' 'BDC_OKCODE' '=ENTR'.

perform dynpro using:
*goto Select Plant screen
'X' 'SAPLMGMM' '0080',
' ' 'BDC_CURSOR' 'RMMG1-WERKS',
' ' 'RMMG1-WERKS' 'P123', "for example
' ' 'BDC_OKCODE' '=ENTR'.

perform dynpro using:
*goto Accounting1 view
'X' 'SAPLMGMM' '4000',
*
* change data fields here ....
*
*save
' ' 'BDC_OKCODE' 'BU'.

endform. " bdc_mm02

*&---------------------------------------------------------------------*
*& Form bdc_mm01
*&---------------------------------------------------------------------*
form bdc_mm01.
* for example, Accounting View 1 (21)

perform dynpro using:
*goto MM01 - Create Mateial (Initial screen)
'X' 'SAPLMGMM' '0060',
' ' 'RMMG1-MATNR' w_matnr,
' ' 'RMMG1-MBRSH' 'H', "for example
' ' 'RMMG1-MTART' w_mtart,
*goto Select View(s) screen
' ' 'BDC_OKCODE' '=AUSW'.

* Selection of views
perform dynpro using:
'X' 'SAPLMGMM' '70',
' ' 'BDC_OKCODE' '=RESA', "Deselect all
'X' 'SAPLMGMM' '70'. "continue selection screen

if f_pgdn = 'X'.
perform dynpro using:
' ' 'BDC_OKCODE' '=P+', "Page select screen forward
'X' 'SAPLMGMM' '70'. "continue selection screen
endif.
perform dynpro using:
' ' w_alnum 'X', "Accounting 1
' ' 'USRM1-SISEL' 'X', "Create Views
' ' 'BDC_OKCODE' '=ENTR'.

perform dynpro using:
*goto Select Plant screen
'X' 'SAPLMGMM' '080',
' ' 'RMMG1-WERKS' 'P123', "for example
' ' 'BDC_OKCODE' '=ENTR'.

perform dynpro using:
*goto Accounting1 view
'X' 'SAPLMGMM' '4000',
*
* populate data fields here ....
*
*Save
' ' 'BDC_OKCODE' '=BU'.

endform. " bdc_mm01

*---------------------------------------------------------------------*
* FORM DYNPRO *
*---------------------------------------------------------------------*
* Fills BDC data table *
*---------------------------------------------------------------------*
* --> PI_DYNBEGIN Screen start flag in *
* --> PI_NAME Field name in *
* --> PI_VALUE Field value in *
*---------------------------------------------------------------------*
form dynpro using pi_dynbegin
pi_name
pi_value.

clear i_bdc.
if pi_dynbegin = 'X'.
move: pi_name to i_bdc-program,
pi_value to i_bdc-dynpro,
'X' to i_bdc-dynbegin.
else.
move: pi_name to i_bdc-fnam,
pi_value to i_bdc-fval.
endif. "pi_dynbegin
append i_bdc.
endform. "dynpro

Related Items:

 
< Prev   Next >

Google Search

Statistics

Contribution Activity
Utilities: 38
Tips and Tricks: 332
Sample Code: 164
Total Contributions: 548

Member Activity
Members: 6081 since 2/1/2007!
New: 7 since yesterday!
Visitors: 964832
We have 2 guests online

Newest Members

Welcome our newest members:

Google Ads

Shared Bottom Border

Contact Us | Polls | Add URL | Contribute | Privacy | Terms | Feedback

Discussion Forum | BLOG | Consultants: Post your resume | Companies: Advertise on ERPGenie.COM | Post Job
Financials Consultant | Consultant Review | Gallia Consulting | Supply Chain Project | SAP Financials Forum
GenieHoldings.COM, Inc. | Genie Press | WorkflowGenie | ESAGenie | ERPTopSites | ABAP Tips and Tricks | SAP Solutions Database

EDIGenie | Searching Survivor