2008 Mar 11 3:42 AM
Hi SAP guys,
I have to create a BDC for material master.
Please give me some answers for my queries...
1. Can i use BAPI_MATERIAL_SAVEDATA?
2. What are the components i need to pass to this function module?
3. How can i select the views dinamically?
Note: Based on the input file i need to select the views so, i have to select the views based on the input file. Here the views selection is vary from material to material.
I am very new to using the BAPI. Please give me step by step approach to finish this object.
Points for sure.
Regards,
Kishore
2008 Mar 11 4:04 AM
Hi,
Use the below code to select the view dynamically.
FORM SET_VIEW_SELECT USING P_TCODE
P_SCR
P_MTART
P_MBRSH
P_VPSTA
CHANGING P_SEL_LINE
P_SEL_TEXT
P_PAGE.
TABLES T130M.
DATA: BEGIN OF FIELD,
NAME LIKE BDCDATA-FNAM,
PARENS(6) TYPE C VALUE '($)'.
DATA: END OF FIELD.
DATA: BEGIN OF XBILDTAB OCCURS 16.
INCLUDE STRUCTURE MBILDTAB.
DATA: END OF XBILDTAB.
DATA: NUM(2) TYPE N.
data: SEL_POS type i.
DATA: V_BILDSEQUENZ LIKE T133A-BILDS. "LRB041604
CLEAR: P_SEL_LINE, P_SEL_TEXT, P_PAGE.
P_SEL_LINE = 1.
CLEAR: T130M, V_BILDSEQUENZ.
SELECT SINGLE * FROM T130M
WHERE TCODE = P_TCODE.
CALL FUNCTION 'BILDSEQUENZ_IDENTIFY'
EXPORTING
BRANCHE = P_MBRSH
MATERIALART = P_MTART
TCODE_REF = T130M-TRREF
IMPORTING
BILDSEQUENZ = V_BILDSEQUENZ
EXCEPTIONS
WRONG_CALL = 1
NOT_FOUND = 2
OTHERS = 3.
CALL FUNCTION 'SELECTION_VIEWS_FIND'
EXPORTING
BILDSEQUENZ = V_BILDSEQUENZ "LRB041604
PFLEGESTATUS = P_VPSTA
TABLES
BILDTAB = XBILDTAB
EXCEPTIONS
CALL_WRONG = 1
EMPTY_SELECTION = 2
OTHERS = 3.
Determine Popup Selection
LOOP AT XBILDTAB.
AUTHORITY-CHECK OBJECT 'M_MATE_STA'
ID 'ACTVT' FIELD '02'
ID 'STATM' FIELD XBILDTAB-PSTAT.
IF SY-SUBRC NE 0.
DELETE XBILDTAB.
ENDIF.
ENDLOOP.
READ TABLE XBILDTAB WITH KEY AUSWG = P_SCR.
IF SY-SUBRC = 0.
SEL_POS = SY-TABIX.
ELSE.
SEL_POS = 0.
ENDIF.
Determine if on the first page or second
if SEL_POS <= 18.
move 1 to P_PAGE.
else.
move 2 to P_PAGE.
SEL_POS = SEL_POS - 18.
endif.
Build field name for correct view(s).
CLEAR: FIELD.
MOVE '($)' TO FIELD-PARENS.
MOVE: 'MSICHTAUSW-KZSEL' TO FIELD-NAME,
SEL_POS TO NUM.
REPLACE '$' WITH NUM INTO FIELD-PARENS.
CONDENSE FIELD NO-GAPS.
MOVE FIELD TO P_SEL_LINE.
CLEAR: FIELD.
MOVE '($)' TO FIELD-PARENS.
MOVE: 'MSICHTAUSW-DYTXT' TO FIELD-NAME,
SEL_POS TO NUM.
REPLACE '$' WITH NUM INTO FIELD-PARENS.
CONDENSE FIELD NO-GAPS.
MOVE FIELD TO P_SEL_TEXT.
ENDFORM. " SET_VIEW_SELECT
Hi SAP guys,
I have to create a BDC for material master.
Please give me some answers for my queries...
1. Can i use BAPI_MATERIAL_SAVEDATA?
2. What are the components i need to pass to this function module?
3. How can i select the views dinamically?
Note: Based on the input file i need to select the views so, i have to select the views based on the input file. Here the views selection is vary from material to material.
I am very new to using the BAPI. Please give me step by step approach to finish this object.
Points for sure.
Regards,
Kishore
2008 Mar 11 3:49 AM
hi,
Based on the material type the selction views will vary so check for the conditon, that while passing the internal table in loop check whether the MTART i.e., the material type if the material type is ROH give the condition that what are the select views u want else check for MTART is FERT then give the select views for this.
Thanks,
Arunprasad.P
Reward if useful.
2008 Mar 11 4:00 AM
Hi anurag,
Thanks for your input it will be useful for me..
I want to know some more things from you...
1. Can i use BAPI_MATERIAL_SAVEDATA?
2. What are the components i need to pass to this function module?
3. What will the be output from the function module?
4. What is the difference between using the FM and the recording?
5. Is there any FMs are there after using the BAPI_MATERIAL_SAVEDATA?
5. How can i select the views dinamically?
Regards,
Kishore
2008 Mar 11 4:04 AM
Hi,
Use the below code to select the view dynamically.
FORM SET_VIEW_SELECT USING P_TCODE
P_SCR
P_MTART
P_MBRSH
P_VPSTA
CHANGING P_SEL_LINE
P_SEL_TEXT
P_PAGE.
TABLES T130M.
DATA: BEGIN OF FIELD,
NAME LIKE BDCDATA-FNAM,
PARENS(6) TYPE C VALUE '($)'.
DATA: END OF FIELD.
DATA: BEGIN OF XBILDTAB OCCURS 16.
INCLUDE STRUCTURE MBILDTAB.
DATA: END OF XBILDTAB.
DATA: NUM(2) TYPE N.
data: SEL_POS type i.
DATA: V_BILDSEQUENZ LIKE T133A-BILDS. "LRB041604
CLEAR: P_SEL_LINE, P_SEL_TEXT, P_PAGE.
P_SEL_LINE = 1.
CLEAR: T130M, V_BILDSEQUENZ.
SELECT SINGLE * FROM T130M
WHERE TCODE = P_TCODE.
CALL FUNCTION 'BILDSEQUENZ_IDENTIFY'
EXPORTING
BRANCHE = P_MBRSH
MATERIALART = P_MTART
TCODE_REF = T130M-TRREF
IMPORTING
BILDSEQUENZ = V_BILDSEQUENZ
EXCEPTIONS
WRONG_CALL = 1
NOT_FOUND = 2
OTHERS = 3.
CALL FUNCTION 'SELECTION_VIEWS_FIND'
EXPORTING
BILDSEQUENZ = V_BILDSEQUENZ "LRB041604
PFLEGESTATUS = P_VPSTA
TABLES
BILDTAB = XBILDTAB
EXCEPTIONS
CALL_WRONG = 1
EMPTY_SELECTION = 2
OTHERS = 3.
Determine Popup Selection
LOOP AT XBILDTAB.
AUTHORITY-CHECK OBJECT 'M_MATE_STA'
ID 'ACTVT' FIELD '02'
ID 'STATM' FIELD XBILDTAB-PSTAT.
IF SY-SUBRC NE 0.
DELETE XBILDTAB.
ENDIF.
ENDLOOP.
READ TABLE XBILDTAB WITH KEY AUSWG = P_SCR.
IF SY-SUBRC = 0.
SEL_POS = SY-TABIX.
ELSE.
SEL_POS = 0.
ENDIF.
Determine if on the first page or second
if SEL_POS <= 18.
move 1 to P_PAGE.
else.
move 2 to P_PAGE.
SEL_POS = SEL_POS - 18.
endif.
Build field name for correct view(s).
CLEAR: FIELD.
MOVE '($)' TO FIELD-PARENS.
MOVE: 'MSICHTAUSW-KZSEL' TO FIELD-NAME,
SEL_POS TO NUM.
REPLACE '$' WITH NUM INTO FIELD-PARENS.
CONDENSE FIELD NO-GAPS.
MOVE FIELD TO P_SEL_LINE.
CLEAR: FIELD.
MOVE '($)' TO FIELD-PARENS.
MOVE: 'MSICHTAUSW-DYTXT' TO FIELD-NAME,
SEL_POS TO NUM.
REPLACE '$' WITH NUM INTO FIELD-PARENS.
CONDENSE FIELD NO-GAPS.
MOVE FIELD TO P_SEL_TEXT.
ENDFORM. " SET_VIEW_SELECT
2008 Mar 11 4:05 AM
Hai.
check the example codes.
REPORT zmm_mat_master_non_stock
NO STANDARD PAGE HEADING
LINE-SIZE 255.
Standard Include for Selection Screen
INCLUDE bdcrecx1.
Internal Table for Upload Data
DATA: BEGIN OF i_mat OCCURS 0,
mbrsh(001), " Industry Sector
mtart(004), " Material Type
Views
Organization Levels
werks(004), " Plant
Basic Data1 View
maktx(040), " Material Description
meins(003), " Unit of Measure
matkl(009), " Material Group
MTPOS_MARA(004), " Gen Item Category
Purchasing
ekgrp(003), " Purchasing Group
END OF i_mat.
Data Variables & Constants
CONSTANTS : c_x VALUE 'X'. " Flag
Parameters
PARAMETERS: p_file LIKE ibipparms-path. " Filename
At selection-screen on Value Request for file Name
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Get the F4 Values for the File
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file.
Start of Selection
START-OF-SELECTION.
Open the BDC Session
PERFORM open_group.
Upload the File into internal Table
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = i_mat
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Upload the Data from Internal Table
LOOP AT i_mat.
Basic Screen
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RMMG1-MBRSH'
'C'."i_mat-mbrsh.
PERFORM bdc_field USING 'RMMG1-MTART'
'NLAG'."i_mat-mtart.
Views Selection
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.
PERFORM bdc_field USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(08)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'
c_x."i_mat-kzsel_01.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(02)'
c_x."i_mat-kzsel_02.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(08)'
c_x."i_mat-kzsel_08.
Organization Levels
PERFORM bdc_dynpro USING 'SAPLMGMM' '0080'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-WERKS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field USING 'RMMG1-WERKS'
'2000'."i_mat-werks.
Basic data1 View
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'MAKT-MAKTX'
i_mat-maktx.
PERFORM bdc_field USING 'BDC_CURSOR'
'MARA-MTPOS_MARA'.
PERFORM bdc_field USING 'MARA-MEINS'
'EA'."i_mat-meins.
PERFORM bdc_field USING 'MARA-MATKL'
i_mat-matkl.
PERFORM bdc_field USING 'MARA-MTPOS_MARA'
'NLAG'."i_mat-mtpos_mara.
Basic data2 View
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'BDC_CURSOR'
'MAKT-MAKTX'.
Purchasing View
PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
PERFORM bdc_field USING 'MARC-EKGRP'
i_mat-ekgrp.
Call The Transaction
PERFORM bdc_transaction USING 'MM01'.
ENDLOOP.
Close the BDC Session
PERFORM close_group.
-
REPORT zmm_mat_master_non_stock
NO STANDARD PAGE HEADING
LINE-SIZE 255.
Standard Include for Selection Screen
INCLUDE bdcrecx1.
Internal Table for Upload Data
DATA: BEGIN OF i_mat OCCURS 0,
mbrsh(001), " Industry Sector
mtart(004), " Material Type
Views
Organization Levels
werks(004), " Plant
Basic Data1 View
maktx(040), " Material Description
meins(003), " Unit of Measure
matkl(009), " Material Group
MTPOS_MARA(004), " Gen Item Category
Purchasing
ekgrp(003), " Purchasing Group
END OF i_mat.
Data Variables & Constants
CONSTANTS : c_x VALUE 'X'. " Flag
Parameters
PARAMETERS: p_file LIKE ibipparms-path. " Filename
At selection-screen on Value Request for file Name
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Get the F4 Values for the File
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_file.
Start of Selection
START-OF-SELECTION.
Open the BDC Session
PERFORM open_group.
Upload the File into internal Table
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
TABLES
data_tab = i_mat
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Upload the Data from Internal Table
LOOP AT i_mat.
Basic Screen
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RMMG1-MBRSH'
'C'."i_mat-mbrsh.
PERFORM bdc_field USING 'RMMG1-MTART'
'NLAG'."i_mat-mtart.
Views Selection
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.
PERFORM bdc_field USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(08)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'
c_x."i_mat-kzsel_01.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(02)'
c_x."i_mat-kzsel_02.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(08)'
c_x."i_mat-kzsel_08.
Organization Levels
PERFORM bdc_dynpro USING 'SAPLMGMM' '0080'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-WERKS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field USING 'RMMG1-WERKS'
'2000'."i_mat-werks.
Basic data1 View
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'MAKT-MAKTX'
i_mat-maktx.
PERFORM bdc_field USING 'BDC_CURSOR'
'MARA-MTPOS_MARA'.
PERFORM bdc_field USING 'MARA-MEINS'
'EA'."i_mat-meins.
PERFORM bdc_field USING 'MARA-MATKL'
i_mat-matkl.
PERFORM bdc_field USING 'MARA-MTPOS_MARA'
'NLAG'."i_mat-mtpos_mara.
Basic data2 View
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'BDC_CURSOR'
'MAKT-MAKTX'.
Purchasing View
PERFORM bdc_dynpro USING 'SAPLMGMM' '4000'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
PERFORM bdc_field USING 'MARC-EKGRP'
i_mat-ekgrp.
Call The Transaction
PERFORM bdc_transaction USING 'MM01'.
ENDLOOP.
Close the BDC Session
PERFORM close_group.
Regards.
sowjanya.b
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |