Steps :
- Get the flat file from the customer. Flat file might be text 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_BDC_CALL
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.
PERFORM DISPLAY_MESS USING messtab[].
*&---------------------------------------------------------------------*
*& 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 : FILENAME TYPE STRING.
FILENAME = p_file.
call function 'GUI_UPLOAD' * To upload Tab delimited data
exporting
filename = FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
tables
data_tab = p_it_mat
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.
* Implement suitable error handling here
endif.
endform. " GET_DATA_FROM_FILE
*----------------------------------------------------------------------*
* 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 BDC_OPERATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BDC_OPERATION .
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 TRANSACTION 'MM01' USING bdcdata[] UPDATE 'S'
MODE 'A'
MESSAGES INTO messtab.
ENDLOOP.
endform. " BDC_OPERATION
*&---------------------------------------------------------------------*
*& Form DISPLAY_MESS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_MESSTAB text
*----------------------------------------------------------------------*
form DISPLAY_MESS using p_messtab LIKE messtab[].
DATA : MSG TYPE STRING.
DATA : WA LIKE LINE OF p_messtab.
LOOP AT p_messtab INTO WA.
call function 'FORMAT_MESSAGE'
EXPORTING
ID = WA-MSGID
LANG = SY-LANGU
NO = WA-MSGNR
V1 = WA-MSGV1
V2 = WA-MSGV2
V3 = WA-MSGV3
V4 = WA-MSGV4
IMPORTING
MSG = MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
WRITE : / MSG.
CLEAR WA.
ENDLOOP.
endform. " DISPLAY_MESS
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.
PERFORM DISPLAY_MESS USING messtab[].
*& 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 : FILENAME TYPE STRING.
FILENAME = p_file.
call function 'GUI_UPLOAD' * To upload Tab delimited data
exporting
filename = FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
tables
data_tab = p_it_mat
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.
* Implement suitable error handling here
endif.
endform. " GET_DATA_FROM_FILE
*----------------------------------------------------------------------*
* 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 BDC_OPERATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BDC_OPERATION .
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 TRANSACTION 'MM01' USING bdcdata[] UPDATE 'S'
MODE 'A'
MESSAGES INTO messtab.
ENDLOOP.
endform. " BDC_OPERATION
*&---------------------------------------------------------------------*
*& Form DISPLAY_MESS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_MESSTAB text
*----------------------------------------------------------------------*
form DISPLAY_MESS using p_messtab LIKE messtab[].
DATA : MSG TYPE STRING.
DATA : WA LIKE LINE OF p_messtab.
LOOP AT p_messtab INTO WA.
call function 'FORMAT_MESSAGE'
EXPORTING
ID = WA-MSGID
LANG = SY-LANGU
NO = WA-MSGNR
V1 = WA-MSGV1
V2 = WA-MSGV2
V3 = WA-MSGV3
V4 = WA-MSGV4
IMPORTING
MSG = MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
WRITE : / MSG.
CLEAR WA.
ENDLOOP.
endform. " DISPLAY_MESS
- Save ->Check -> Activate -> Execute.
No comments:
Post a Comment