MM02 - Selection of views
Hi all,
I am writing a batch input to maintain the MRP2-view of materials. I had a problem selecting the right view because field SELKZ is dependent on the views created for a material.
How can I determine the right counter to select the MRP2-view.
Do I need to use table T130D and field MARA-PSTAT? Does somebody have a coding example?
Kris
Have a look at table MSTA. This defines the views for any given material:
*
* And the views
*
Select statm zhler lgort vkorg vtweg
into table t_views
from msta
where matnr = pu_material and
( werks = pu_source_plant or werks = '' )
order by statm zhler.
*
* Find the lowest counter for each view.
*
Describe table t_views lines w_lines.
While w_lines > 0.
Read Table t_views index 1.
Clear t_msta.
Move t_views to t_msta.
Loop at t_views where statm = t_msta-statm.
If t_views-zhler < t_msta-zhler.
Clear t_msta.
Move t_views to t_msta.
EndIf.
EndLoop.
Append t_msta.
Delete t_views where statm = t_msta-statm.
Describe table t_views lines w_lines.
EndWhile.
Then where you write your BDC, you need to translate the views into check boxes to tick. MSTA-STATM can be: one of
Constants: c_Select_Views Like sy-ucomm value 'AUSW',
c_confirm Like sy-ucomm value 'YES',
C_Work_scheduling Like T132-Statm value 'A',
C_Accounting Like T132-Statm value 'B',
C_Classification Like T132-Statm Value 'C',
C_MRP Like T132-Statm Value 'D',
C_Purchasing Like T132-Statm Value 'E',
C_Production_resources_tools Like T132-Statm Value 'F',
C_Costing Like T132-Statm Value 'G',
C_Basic_data Like T132-Statm Value 'K',
C_Storage Like T132-Statm Value 'L',
C_Forecasting Like T132-Statm Value 'P',
C_Quality_management Like T132-Statm Value 'Q',
C_Warehouse_management Like T132-Statm Value 'S',
C_Sales Like T132-Statm Value 'V',
C_Plant_stocks Like T132-Statm Value 'X',
C_Storage_location_stocks Like T132-Statm Value 'Z'.
Select the relevant views. You need to translate the view codes above as they can equate to more than one screen (for example MRP)
*
* Select views
*
Perform ZBDC_Screen using c_MM01_0070-Program c_MM01_0070-Screen.
Loop at t_msta.
*
* Translate the View codes to positions in the Select Views
* pick list.
*
Case t_msta-statm.
When C_Work_scheduling.
When C_Accounting.
Perform Select_View using 'MSICHTAUSW-KZSEL'
17
True
changing w_view_list.
Perform Select_View using 'MSICHTAUSW-KZSEL'
18
True
changing w_view_list.
When C_Classification.
When C_MRP.
Do 4 times.
Compute w_sub = 10 + sy-index.
Perform Select_View using 'MSICHTAUSW-KZSEL'
w_sub
True
changing w_view_list.
EndDo.
When C_Purchasing.
Perform Select_View using 'MSICHTAUSW-KZSEL'
8
True
changing w_view_list.
Perform Select_View using 'MSICHTAUSW-KZSEL'
And then during the actual BDC itself, you need to visit each of the tabs:
Do 18 times.
*
* w_view_list contains an asterisk at each screen position.
*
If w_view_list+sy-index(1) = c_plus.
Perform sy-index of View_4004_sp01 " Basic Data 1
View_4004_sp02 " Basic Data 2
View_4000_sp04 " Sales Org Data 1
View_4000_sp05 " Sales Org Data 2
View_4000_sp06 " Sales General/Plant
View_4004_sp07 " Foreign Trade
View_4040_sp08 " Sales Text
View_4000_sp09 " Purchasing
View_4000_sp10 " Foreign Trade/Imprt
View_4040_sp11 " Purchase Order text
View_4000_sp12 " MRP 1
View_4000_sp13 " MRP 2
View_4000_sp14 " MRP 3
View_4000_sp15 " MRP 4
View_4000_sp19 " Plant/Data Store 1
View_4000_sp20 " Plant/Data Store 2
View_4000_sp24 " Accounting 1
View_4000_sp25. " Accounting 2
EndIf.
EndDo.
As an example, some of these routines looks like:
*
* Select various tabs in MM01
*
Form View_4000 using pu_spcode like sy-ucomm.
Perform ZBDC_Field using c_okcode pu_spcode.
Perform ZBDC_Screen using c_mm01_4000-Program c_mm01_4000-screen.
EndForm.
*
Form View_4004 using pu_spcode like sy-ucomm.
Perform ZBDC_Field using c_okcode pu_spcode.
Perform ZBDC_Screen using c_mm01_4004-Program c_mm01_4004-screen.
EndForm.
Form View_4040 using pu_spcode like sy-ucomm.
Perform ZBDC_Field using c_okcode pu_spcode.
Perform ZBDC_Screen using c_mm01_4040-Program c_mm01_4040-screen.
EndForm.
Form View_4004_sp01.
*
* Basic data 1 is not selectable when extending
*
* Perform View_4004 using '=SP01'.
EndForm.
Form View_4004_sp02.
*
* Basic data 2 is not selectable when extending
*
* Perform View_4004 using '=SP02'.
EndForm.
Form View_4000_sp04.
Perform View_4000 using '=SP04'.
EndForm.
Form View_4000_sp05.
Perform View_4000 using '=SP05'.
EndForm.
Form View_4000_sp06.
Perform View_4000 using '=SP06'.
EndForm.
Form View_4004_sp07.
Perform View_4004 using '=SP07'.
EndForm.
Each view can be accessed using the Ok code '=SP' and the tab number assigned in the transaction.
Hope this gives you some pointers.
Regards
R[/code]
Get views related to material type and call functon 'SELECTION_VIEWS_FIND' to get the lsit of all valid views for the material type.
select single pstat from t134 into t134-pstat
where mtart = t_mat-mtart.
call function 'SELECTION_VIEWS_FIND'
exporting
bildsequenz = '01'
pflegestatus = t134-pstat
tables
bildtab = t_bildtab
exceptions
call_wrong = 1
empty_selection = 2
others = 3.
read table t_bildtab with key pstat = 'S'. "Key for view
if sy-subrc = 0.
z_index = sy-tabix. "position
endif.
Hope this helps !
This object allows you to load MRP data, just fill in the details required in the appropriate structure. Set the transaction to MM02 and your'e away.
Dr Sidewalk