Tuesday 14 June 2016

Uploading the Master records(MM01) to SAP System using Session Method ( Excel flat file)

Steps :

  • Get the flat file from the customer. Flat file might be  Excel file.

  • Get a sample recording with the help of  transaction Code SHDB .




  • Screen look like this.


  • Click on new recording.

  •  Enter the recording name and enter the transaction code (MM01).

  • Click on Start Recording.





  • Create a master record without single error as per required fields.
  • Ex: MM01 .. 
  • Enter the Material number , Industry Sector , Material Type.





  • Press Enter.

  • Select the View and click on Continue.



  • Enter material description and base unit of measure.

  • Press Enter.

  • Click on Yes.

  • Note :This is similar structure of BDCDATA.





  •  Click on save and click on Back.

  • Select the recording and click on program.



  • Enter the program name starts with Z or Y <program name >.
  • Click on Transfer from recording .





  • Click on Continue.
  • Enter Title and select attribute type as Executable program.

  • Click on Source Code.
  • Save Package or Local package.





Source Code




report ZMM_MM01_SESSION
       no standard page heading line-size 255.

TYPES BEGIN OF TY_MAT,
        MATNR(18TYPE C,
        MBRSH TYPE C,
        MTART(4TYPE C,
        MAKTX(40TYPE C,
        MEINS(3TYPE C,

       END OF TY_MAT.


DATAWA_MAT TYPE TY_MAT,
      IT_MAT TYPE TABLE OF TY_MAT.

data:   bdcdata like bdcdata    occurs with header line.
*       messages of call transaction
data:   messtab like bdcmsgcoll occurs with header line.

PARAMETERS FILE(120TYPE 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'
 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



  • Click on F4 and choose the Tab delimited file.

  • Click on Execute.

  • Click on Allow.

Output

  • 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.


  • At the end of session,

  • Click on session overview.


  • To Analysis, Select session name and click on Analysis.

  • Click on Log Created on.







No comments:

Post a Comment