Skip to Content
0
Former Member
Jul 11, 2007 at 07:47 AM

Uploading material master in CSV file into MM01

85 Views

Hye all,

I am in the midst of doing upload program using BDC and recording. I managed to upload the first row of data resides in my CSV file. Unfortunately, the second row onwards failed to be uploaded into MM01.

Below is my coding:

REPORT ZMMR_MATMASTER_UPLOAD .

tables: mara, makt, mvke.

DATA: INFILE TYPE STANDARD TABLE OF STRING,

DATALINE TYPE STRING,

C1 TYPE BDCDATA-FVAL, "Material#

C2 TYPE BDCDATA-FVAL, "Industry Sect.

C3 TYPE BDCDATA-FVAL, "Material Type

C4 TYPE BDCDATA-FVAL, "Plant

C5 TYPE BDCDATA-FVAL, "Storage Loc.

C6 type bdcdata-fval, "Sales ORg.

C7 type bdcdata-fval, "Distr. Channel

C8 type bdcdata-fval, "Mat. Description

C9 type bdcdata-fval, "UoM

C10 type bdcdata-fval, "Mat. Grp.

C11 type bdcdata-fval, "Product Hier.

C12 type bdcdata-fval, "GenItemCatGrp

C13 type bdcdata-fval, "Gross Weight

C14 type bdcdata-fval, "Net Weight

C15 type bdcdata-fval, "Tax Class Material

C16 type bdcdata-fval, "Mat. Pricing Grp.

C17 type bdcdata-fval, "Acc. Assign. Grp.

C18 type bdcdata-fval, "Prod. Hier.

C19 type bdcdata-fval, "Gross Weight

C20 type bdcdata-fval, "Net Weight

C21 type bdcdata-fval, "Availability Check

C22 type bdcdata-fval, "Trans. Grp.

C23 type bdcdata-fval, "Loading Grp.

C24 type bdcdata-fval, "Profit Ctr.

C25 type bdcdata-fval, "Order Unit

C26 type bdcdata-fval, "Conversion Factor Order

C27 type bdcdata-fval, "Conversion Factor Base

C28 type bdcdata-fval, "Valuation Class

C29 type bdcdata-fval, "Price Control

C30 type bdcdata-fval, "Price Unit

C31 type bdcdata-fval, "Mvg. Avg. Price

C32 type bdcdata-fval. "Std. Price

TYPES: BEGIN OF T_DATA,

C1 TYPE BDCDATA-FVAL, "Material#

C2 TYPE BDCDATA-FVAL, "Industry Sect.

C3 TYPE BDCDATA-FVAL, "Material Type

C4 TYPE BDCDATA-FVAL, "Plant

C5 TYPE BDCDATA-FVAL, "Storage Loc.

C6 type bdcdata-fval, "Sales ORg.

C7 type bdcdata-fval, "Distr. Channel

C8 type bdcdata-fval, "Mat. Description

C9 type bdcdata-fval, "UoM

C10 type bdcdata-fval, "Mat. Grp.

C11 type bdcdata-fval, "Product Hier.

C12 type bdcdata-fval, "GenItemCatGrp

C13 type bdcdata-fval, "Gross Weight

C14 type bdcdata-fval, "Net Weight

C15 type bdcdata-fval, "Tax Class Material

C16 type bdcdata-fval, "Mat. Pricing Grp.

C17 type bdcdata-fval, "Acc. Assign. Grp.

C18 type bdcdata-fval, "Prod. Hier.

C19 type bdcdata-fval, "Gross Weight

C20 type bdcdata-fval, "Net Weight

C21 type bdcdata-fval, "Availability Check

C22 type bdcdata-fval, "Trans. Grp.

C23 type bdcdata-fval, "Loading Grp.

C24 type bdcdata-fval, "Profit Ctr.

C25 type bdcdata-fval, "Order Unit

C26 type bdcdata-fval, "Conversion Factor Order

C27 type bdcdata-fval, "Conversion Factor Base

C28 type bdcdata-fval, "Valuation Class

C29 type bdcdata-fval, "Price Control

C30 type bdcdata-fval, "Price Unit

C31 type bdcdata-fval, "Mvg. Avg. Price

C32 type bdcdata-fval, "Std. Price

END OF T_DATA.

DATA: IT_DATA TYPE STANDARD TABLE OF T_DATA,

WA_DATA TYPE T_DATA.

DATA: IT_BDCDATA TYPE STANDARD TABLE OF BDCDATA,

WA_BDCDATA TYPE BDCDATA.

data: path type string.

SELECTION-SCREEN: BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.

SELECTION-SCREEN SKIP 1.

PARAMETER: P_FNAME LIKE RLGRAP-FILENAME DEFAULT 'C:\*.csv'.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN: END OF BLOCK 1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.

PERFORM GET_FILENAME CHANGING P_FNAME.

START-OF-SELECTION.

move: p_fname to path.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = path

FILETYPE = 'ASC'

TABLES

DATA_TAB = INFILE

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

IF SY-SUBRC <> 0.

WRITE: / 'ERROR NO', SY-SUBRC.

EXIT.

ENDIF.

LOOP AT INFILE INTO DATALINE.

SPLIT DATALINE AT ',' INTO C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12

C13 C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 C27 C28 C29.

WA_DATA-C1 = C1.

WA_DATA-C2 = C2.

WA_DATA-C3 = C3.

WA_DATA-C4 = C4.

WA_DATA-C5 = C5.

wa_data-c6 = c6.

wa_Data-c7 = c7.

wa_data-c8 = c8.

wa_data-c9 = c9.

wa_Data-c10 = c10.

wa_data-c11 = c11.

wa_data-c12 = c12.

wa_data-c13 = c13.

wa_data-c14 = c14.

wa_data-c15 = c15.

wa_data-c16 = c16.

wa_data-c17 = c17.

wa_data-c18 = c18.

wa_data-c19 = c19.

wa_data-c20 = c20.

wa_data-c21 = c21.

wa_data-c22 = c22.

wa_data-c23 = c23.

wa_data-c24 = c24.

wa_data-c25 = c25.

wa_data-c26 = c26.

wa_data-c27 = c27.

wa_data-c28 = c28.

wa_data-c29 = c29.

APPEND WA_DATA TO IT_DATA.

ENDLOOP.

  • DATA: count TYPE i VALUE 1.

  • PERFORM begin USING 'SAPLMGMM' '0060' 'X'.

LOOP AT it_data INTO wa_data.

  • count = 1.

PERFORM begin USING 'SAPLMGMM' '0060' 'X'.

PERFORM info_tc USING 'RMMG1-MATNR' wa_data-c1.

PERFORM info_tc USING 'RMMG1-MBRSH' wa_data-c2.

PERFORM info_tc USING 'RMMG1-MTART' wa_data-c3.

PERFORM begin USING 'SAPLMGMM' '0070' 'X'.

perform info using 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)'.

perform info using 'MSICHTAUSW-KZSEL(01)' 'X'.

perform info using 'MSICHTAUSW-KZSEL(04)' 'X'.

perform info using 'MSICHTAUSW-KZSEL(05)' 'X'.

perform info using 'MSICHTAUSW-KZSEL(06)' 'X'.

perform info using 'MSICHTAUSW-KZSEL(09)' 'X'.

perform info using 'MSICHTAUSW-KZSEL(17)' 'X'.

  • PERFORM begin USING 'SAPLMGMM' '0070' 'X'.

  • perform info using 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(04)'.

  • perform info using 'BDC_OKCODE' '=ENTR'.

  • perform info using 'MSICHTAUSW-KZSEL(04)' 'X'.

perform info using 'BDC_OKCODE' '=ENTR'.

  • perform info using 'BDC_OKCODE' '=SELA'.

PERFORM begin USING 'SAPLMGMM' '0080' 'X'.

PERFORM info_tc USING 'RMMG1-WERKS' wa_data-c4.

PERFORM info_tc USING 'RMMG1-LGORT' wa_data-c5.

PERFORM info_tc USING 'RMMG1-VKORG' wa_data-c6.

PERFORM info_tc USING 'RMMG1-VTWEG' wa_data-c7.

**Basic data 1 tab

perform begin using 'SAPLMGMM' '4004' 'X'.

perform info using 'BDC_OKCODE' '=SP04'.

perform info_tc using 'MAKT-MAKTX' wa_data-c8.

perform info_tc using 'MARA-MEINS' wa_data-c9.

perform info_tc using 'MARA-MATKL' wa_data-C10.

perform info_tc using 'MARA-PRDHA' wa_data-c11.

perform info_tc using 'MARA-MTPOS_MARA' wa_data-c12.

perform info_tc using 'MARA-BRGEW' wa_data-C13.

perform info_tc using 'MARA-NTGEW' wa_data-c14.

**Sales: sales org. 1 tab

perform begin using 'SAPLMGMM' '4000' 'X'.

perform info using 'BDC_OKCODE' '=SP05'.

  • perform info using 'BDC_SUBSCR' 'SAPLMGD1'.

perform info using 'BDC_CURSOR' 'MG03STEUER-TAXKM(01)' .

perform info_tc using 'MG03STEUER-TAXKM(01)' wa_data-c15.

perform begin using 'SAPLMGMM' '4200' 'X'.

perform info using 'BDC_OKCODE' '=MAIN'.

**Sales: sales org. 2 tab

perform begin using 'SAPLMGMM' '4000' 'X'.

perform info using 'BDC_OKCODE' '=SP05'.

perform info_tc using 'MARA-MEINS' wa_data-c9.

perform info_tc using 'MARA-MATKL' wa_Data-c10.

perform info_tc using 'MVKE-SKTOF' 'X'.

perform begin using 'SAPLMGMM' '4000' 'X'.

perform info using 'BDC_OKCODE' '=SP06'.

perform info_tc using 'MVKE-KONDM' wa_data-c16.

perform info_tc using 'MVKE-KTGRM' wa_data-c17.

perform info_tc using 'MVKE-PRODH' wa_data-c18.

**Sales: general/plant tab

perform begin using 'SAPLMGMM' '4000' 'X'.

perform info using 'BDC_OKCODE' '=SP06'.

perform info_tc using 'MARA-BRGEW' wa_data-c19.

perform info_tc using 'MARA-NTGEW' wa_data-c20.

perform info_tc using 'MARC-MTVFP' wa_data-c21.

perform info_tc using 'MARA-TRAGR' wa_data-c22.

perform info_tc using 'MARC-LADGR' wa_data-c23.

perform info_tc using 'MARC-PRCTR' wa_data-c24.

  • perform info using 'BDC_OKCODE' '=SPXX'.

**Accounting 1 tab

perform info using 'BDC_OKCODE' '=SP24'.

perform begin using 'SAPLMGMM' '4000' 'X'.

perform info_tc using 'MBEW-BKLAS' wa_data-c25.

perform info_tc using 'MBEW-VPRSV' wa_data-c26.

perform info_tc using 'MBEW-PEINH' wa_data-c27.

perform info_tc using 'MBEW-VERPR' wa_Data-c28.

perform info_tc using 'MBEW-STPRS' wa_data-c29.

perform begin using 'SAPLSPO1' '0300' 'X'.

perform info using 'BDC_OKCODE' '=YES'.

CALL TRANSACTION 'MM01' USING it_bdcdata MODE 'A' UPDATE 'L'.

  • PERFORM info USING 'BDC_OKCODE' '=BU'.

ENDLOOP.

&----


*& Form GET_FILENAME

&----


  • text

----


  • <--P_P_FNAME text

----


FORM GET_FILENAME CHANGING P_P_FNAME.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

MASK = ',.,..'

TITLE = 'Open'

IMPORTING

FILENAME = P_FNAME

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

ENDFORM. " GET_FILENAME

&----


*& Form begin

&----


  • text

----


  • -->P_0462 text

  • -->P_0463 text

  • -->P_0464 text

----


FORM begin USING PROG TYPE BDCDATA-PROGRAM

DYNPRO TYPE BDCDATA-DYNPRO

DYNBEGIN TYPE BDCDATA-DYNBEGIN.

CLEAR WA_BDCDATA.

WA_BDCDATA-PROGRAM = PROG.

WA_BDCDATA-DYNPRO = DYNPRO.

WA_BDCDATA-DYNBEGIN = DYNBEGIN.

APPEND WA_BDCDATA TO IT_BDCDATA.

ENDFORM. " begin

&----


*& Form info

&----


  • text

----


  • -->P_0482 text

  • -->P_0483 text

----


FORM info USING FNAM TYPE BDCDATA-FNAM

FVAL TYPE BDCDATA-FVAL.

  • VALUE(LINNO) TYPE I.

CLEAR WA_BDCDATA.

WA_BDCDATA-FNAM = FNAM.

WA_BDCDATA-FVAL = FVAL.

APPEND WA_BDCDATA TO IT_BDCDATA.

ENDFORM. " info

&----


*& Form info_tc

&----


  • text

----


  • -->P_0487 text

  • -->P_WA_DATA_C1 text

  • -->P_COUNT text

----


FORM info_tc USING FNAM TYPE BDCDATA-FNAM

FVAL TYPE BDCDATA-FVAL.

  • VALUE(LINNO) TYPE I.

  • DATA: LINENO(2) TYPE N.

  • LINENO = LINNO.

  • CONCATENATE FNAM '(' LINENO ')' INTO FNAM.

CLEAR WA_BDCDATA.

WA_BDCDATA-FNAM = FNAM.

WA_BDCDATA-FVAL = FVAL.

APPEND WA_BDCDATA TO IT_BDCDATA.

ENDFORM. " info_tc

*****************************************************

Thanks in advance.