Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem in uploading the records ?

Hello,

I want to uplaod the material master records. I was given EXCEL sheet, where my cells are Material Number, Industry sector, Material group, Material description and Unit.

Please copy paste the code it is sytactically correct but only my first record from the excel sheet is coming to material number field even then it is asking to enter material number.

This is my code please helpme with my mistake...

TYPES: BEGIN OF TY_TABDATA,

MANDT LIKE SY-MANDT, " Client

MATNR LIKE RMMG1-MATNR,

MBRSH LIKE RMMG1-MBRSH,

MTART LIKE RMMG1-MTART, "

MAKTX LIKE MAKT-MAKTX,

MEINS LIKE MARA-MEINS,

END OF TY_TABDATA.

DATA: IT_TABDATA TYPE STANDARD TABLE OF TY_TABDATA INITIAL SIZE 0,

WA_TABDATA TYPE TY_TABDATA,

IT_BDCDATA TYPE STANDARD TABLE OF BDCDATA INITIAL SIZE 0,

IT_BDCMSGCOLL TYPE STANDARD TABLE OF BDCMSGCOLL INITIAL SIZE 0.

DATA: G_MESSAGE(70) TYPE C,

BDCDATA TYPE BDCDATA,

W_BDCMSG TYPE BDCMSGCOLL.

*Declaration of the Internal Table with Header Line comprising of the

*uploaded data.

DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.

INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data

DATA: END OF IT_FILE_UPLOAD.

*S E L E C T I O N - S C R E E N *

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,

BEGIN OF BLOCK B2 WITH FRAME.

PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN: END OF BLOCK B2,

END OF BLOCK B1.

*E V E N T : AT S E L E C T I O N - S C R E E N *

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

PROGRAM_NAME = SYST-REPID

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = ' '

STATIC = 'X'

MASK = '.'

CHANGING

FILE_NAME = P_FNAME

EXCEPTIONS

MASK_TOO_LONG = 1

OTHERS = 2

.

IF SY-SUBRC = 0.

ENDIF.

*S T A R T - O F - S E L E C T I O N

START-OF-SELECTION.

*Upload Excel file into Internal Table.

  • PERFORM UPLOAD_EXCEL_FILE.

*

*Organize the uploaded data into another Internal Table.

  • PERFORM ORGANIZE_UPLOADED_DATA.

  • POPULATE THE RECORDS IN WRITE STATEMENT

*PERFORM WRITE_RECORDS.

*E N D - O F - S E L E C T I O N

END-OF-SELECTION.

*&----


*& Form UPLOAD_EXCEL_FILE

*&----


*FORM UPLOAD_EXCEL_FILE .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FNAME

I_BEGIN_COL = 1

I_BEGIN_ROW = 2

I_END_COL = 5

I_END_ROW = 32000

TABLES

INTERN = IT_FILE_UPLOAD

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3

.

IF SY-SUBRC = 0.

*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*ENDFORM. " UPLOAD_EXCEL_FILE

*&----


*& Form ORGANIZE_UPLOADED_DATA

*&----


*FORM ORGANIZE_UPLOADED_DATA .

SORT IT_FILE_UPLOAD BY ROW COL.

LOOP AT IT_FILE_UPLOAD.

CASE IT_FILE_UPLOAD-COL.

WHEN 1.

WA_TABDATA-MATNR = IT_FILE_UPLOAD-VALUE.

WHEN 2.

WA_TABDATA-MBRSH = IT_FILE_UPLOAD-VALUE.

WHEN 3.

WA_TABDATA-MTART = IT_FILE_UPLOAD-VALUE.

WHEN 4.

WA_TABDATA-MAKTX = IT_FILE_UPLOAD-VALUE.

WHEN 5.

WA_TABDATA-MEINS = IT_FILE_UPLOAD-VALUE.

ENDCASE.

APPEND WA_TABDATA TO IT_TABDATA.

CLEAR: WA_TABDATA.

ENDLOOP.

*ENDFORM.

*perform open_group.

LOOP AT IT_TABDATA INTO WA_TABDATA.

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MTART'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RMMG1-MATNR'

WA_TABDATA-MATNR. "'S1'.

perform bdc_field using 'RMMG1-MBRSH'

WA_TABDATA-MBRSH. "'M'.

perform bdc_field using 'RMMG1-MTART'

WA_TABDATA-MTART. "'VKHM'

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

'X'.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'MAKT-MAKTX'

WA_TABDATA-MAKTX. " material

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.

perform bdc_field using 'MARA-MEINS'

WA_TABDATA-MEINS. "'KG'

.

perform bdc_field using 'MARA-MTPOS_MARA'

'NORM'.

*perform bdc_transaction using 'MM01'.

*

*ENDLOOP.

*

*perform close_group.

CALL TRANSACTION 'MM01' USING IT_BDCDATA MODE 'A' UPDATE 'S' MESSAGES

INTO IT_BDCMSGCOLL.

CLEAR W_BDCMSG.

READ TABLE IT_BDCMSGCOLL INTO W_BDCMSG INDEX 1.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = SY-MSGID

LANG = '-D'(001)

NO = SY-MSGNO

V1 = SY-MSGV1

V2 = SY-MSGV2

V3 = SY-MSGV3

V4 = SY-MSGV4

IMPORTING

MSG = G_MESSAGE

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

IF SY-SUBRC = 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*WRITE : / W_UPLOAD-NEWBS ,'-----' , G_MESSAGE.

*REFRESH IT_BDCMSGCOLL.

ENDIF.

ENDLOOP.

*----


*

  • Start new screen

*

*----


*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA TO IT_BDCDATA.

CLEAR BDCDATA.

ENDFORM.

*----


*

  • Insert field

*

*----


*

FORM BDC_FIELD USING FNAM FVAL.

  • IF FVAL <> NODATA.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA TO IT_BDCDATA.

CLEAR BDCDATA.

  • ENDIF.

ENDFORM.

Waiting for your answers.....

Former Member
Not what you were looking for? View more on this topic or Ask a question