Steps :
- Get the flat file from the customer. Flat file might be Excel file.
- Screen look like this.
- Click on new recording.
- Enter the recording name and enter the transaction code (MM01).
- Create a master record without single error as per required fields.
- Ex: MM01 ..
- Enter the Material number , Industry Sector , Material Type.
- Select the View and click on Continue.
report ZMM_MM01_SESSION
no standard page heading line-size 255.
TYPES : BEGIN OF TY_MAT,
MATNR(18) TYPE C,
MBRSH TYPE C,
MTART(4) TYPE C,
MAKTX(40) TYPE C,
MEINS(3) TYPE C,
END OF TY_MAT.
DATA: WA_MAT TYPE TY_MAT,
IT_MAT TYPE TABLE OF TY_MAT.
data: bdcdata like bdcdata occurs 0 with header line.
* messages of call transaction
data: messtab like bdcmsgcoll occurs 0 with header line.
PARAMETERS : FILE(120) TYPE C.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.
PERFORM SEARCH_FILE CHANGING FILE.
START-OF-SELECTION.
PERFORM GET_DATA_FROM_FILE USING FILE CHANGING IT_MAT.
*include bdcrecx1.
PERFORM BDC_OPERATION.
*&---------------------------------------------------------------------*
*& Form BDC_OPERATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BDC_OPERATION .
call function 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = 'MAT'
HOLDDATE = SY-DATUM
KEEP = 'X'
USER = SY-UNAME
* RECORD = FILLER1
PROG = SY-CPROG
* DCPFM = '%'
* DATFM = '%'
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
* OTHERS = 11
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
LOOP AT IT_MAT INTO WA_MAT.
REFRESH BDCDATA[].
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
WA_MAT-MATNR.
perform bdc_field using 'RMMG1-MBRSH'
WA_MAT-MBRSH.
perform bdc_field using 'RMMG1-MTART'
WA_MAT-MTART.
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'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
WA_MAT-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
WA_MAT-MEINS.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
call function 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
tables
dynprotab = BDCDATA[]
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
ENDLOOP.
call
function 'BDC_CLOSE_GROUP'no standard page heading line-size 255.
TYPES : BEGIN OF TY_MAT,
MATNR(18) TYPE C,
MBRSH TYPE C,
MTART(4) TYPE C,
MAKTX(40) TYPE C,
MEINS(3) TYPE C,
END OF TY_MAT.
DATA: WA_MAT TYPE TY_MAT,
IT_MAT TYPE TABLE OF TY_MAT.
data: bdcdata like bdcdata occurs 0 with header line.
* messages of call transaction
data: messtab like bdcmsgcoll occurs 0 with header line.
PARAMETERS : FILE(120) TYPE C.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.
PERFORM SEARCH_FILE CHANGING FILE.
START-OF-SELECTION.
PERFORM GET_DATA_FROM_FILE USING FILE CHANGING IT_MAT.
*include bdcrecx1.
PERFORM BDC_OPERATION.
*&---------------------------------------------------------------------*
*& Form BDC_OPERATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BDC_OPERATION .
call function 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = 'MAT'
HOLDDATE = SY-DATUM
KEEP = 'X'
USER = SY-UNAME
* RECORD = FILLER1
PROG = SY-CPROG
* DCPFM = '%'
* DATFM = '%'
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
* OTHERS = 11
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
LOOP AT IT_MAT INTO WA_MAT.
REFRESH BDCDATA[].
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'RMMG1-MATNR'
WA_MAT-MATNR.
perform bdc_field using 'RMMG1-MBRSH'
WA_MAT-MBRSH.
perform bdc_field using 'RMMG1-MTART'
WA_MAT-MTART.
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'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
WA_MAT-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
WA_MAT-MEINS.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
call function 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
tables
dynprotab = BDCDATA[]
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
ENDLOOP.
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
endform. " BDC_OPERATION
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endform.
*&---------------------------------------------------------------------*
*& Form SEARCH_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_FILE text
*----------------------------------------------------------------------*
form SEARCH_FILE changing p_file.
DATA : FILE_NAME TYPE IBIPPARMS-PATH.
call function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SY-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = FILE_NAME
.
P_FILE = FILE_NAME.
endform. " SEARCH_FILE
*&---------------------------------------------------------------------*
*& Form GET_DATA_FROM_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FILE text
* <--P_IT_MAT text
*----------------------------------------------------------------------*
form GET_DATA_FROM_FILE using p_file
changing p_it_mat LIKE IT_MAT.
DATA : I_TAB_RAW_DATA TYPE TRUXS_T_TEXT_DATA,
I_FILENAME TYPE RLGRAP-FILENAME .
I_FILENAME = p_file.
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =_
* I_LINE_HEADER =
i_tab_raw_data = I_TAB_RAW_DATA
i_filename = I_FILENAME
tables
i_tab_converted_data = p_it_mat
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
endform. " GET_DATA_FROM_FILE
- Save ->Check -> Activate -> Execute.
Input
- Go to Transaction Code : SM35 .
- Select the session name
- To unlock the session , click on unlock ( Shift + F9 ).
- To process Session , click on process.
- Select the processing Mode and click on process.
- Keep on Clicking Ok_code button.
No comments:
Post a Comment