MM01 BDC Program in SAP ABAP.
*&---------------------------------------------------------------------*
*& Report ZRK_BDC_MM01
*&---------------------------------------------------------------------*
*& Created By :
*& Requested By :
*& Date :
*& TR No. :
*& TCode :
*& Description :
*&---------------------------------------------------------------------*
REPORT zrk_bdc_mm01.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
*&---------------------------------------------------------------------*
*& Internal Table Declaration
*&---------------------------------------------------------------------*
DATA:BEGIN OF i_tab OCCURS 0,
mbrsh TYPE rmmg1-mbrsh,
mtart TYPE rmmg1-mtart,
meins TYPE mara-meins,
matkl TYPE mara-matkl,
maktx TYPE makt-maktx,
END OF i_tab.
*----------------------------------------------------------------------*
* Selection Screen
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text_001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(20) text_1_1.
PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* Initialization Event
*----------------------------------------------------------------------*
INITIALIZATION.
text_001 = 'File path selection'.
text_1_1 = 'File Path'.
*----------------------------------------------------------------------*
* At Selection Screen Event
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = p_file.
*&---------------------------------------------------------------------*
*& Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM data_upload.
IF i_tab[] IS NOT INITIAL.
PERFORM open_group.
LOOP AT i_tab.
REFRESH bdcdata.
PERFORM bdcdata.
ENDLOOP.
PERFORM close_group.
ENDIF.
*&---------------------------------------------------------------------*
*& Form DATA_UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM data_upload.
DATA: loc_filename TYPE string.
loc_filename = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = loc_filename
filetype = 'DAT'
has_field_separator = 'X'
TABLES
data_tab = i_tab
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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " DATA_UPLOAD
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDFORM. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form OPEN_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM open_group .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'ZROHAN_MM01' "'Session_Name'
user = sy-uname
keep = 'X'.
ENDFORM. " OPEN_GROUP
*&---------------------------------------------------------------------*
*& Form CLOSE_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'.
CALL TRANSACTION 'SM35'.
ENDFORM. " CLOSE_GROUP
*&---------------------------------------------------------------------*
*& Form bdcdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM bdcdata .
*---->>> Insert Recording Here
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RMMG1-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'RMMG1-MBRSH' i_tab-mbrsh. "'P'. " this fields
PERFORM bdc_field USING 'RMMG1-MTART' i_tab-mtart. "'ROH'. " this fields
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.
PERFORM bdc_field USING 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(02)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)' 'X'.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(02)' 'X'.
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE' '=SP02'.
PERFORM bdc_field USING 'BDC_CURSOR' 'MARA-MATKL'.
PERFORM bdc_field USING 'MARA-MEINS' i_tab-meins. "'KG'. " unit of mesuremetns
PERFORM bdc_field USING 'MARA-MATKL' i_tab-matkl. "'00106'. " baisc unit
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
PERFORM bdc_field USING 'BDC_CURSOR' 'MAKT-MAKTX'.
PERFORM bdc_field USING 'MAKT-MAKTX' i_tab-maktx. "'Created by RHAN'. " material descrption
PERFORM bdc_insert.
ENDFORM. " bdcdata
*&---------------------------------------------------------------------*
*& Form bdc_insert
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM bdc_insert.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'MM01' "'TCODE'
TABLES
dynprotab = bdcdata.
ENDFORM. " bdc_insert
File Structure :
P ROH KG 00106 Created by RAH1
P ROH KG 00106 Created by RAH2
No comments:
Post a Comment