Wednesday, 6 August 2014

Meter Reading Upload

*&---------------------------------------------------------------------*
*& Report  ZVMASS_METER_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZVMASS_METER_UPLOAD.



SELECTION-SCREEN BEGIN OF BLOCK abc WITH FRAME TITLE text-001.
  SELECTION-SCREEN SKIP.
  PARAMETERS : p_file TYPE rlgrap-filename.
  SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK abc.

TYPES : BEGIN OF ty_tab,


        partner TYPE bu_partner,
        name_f TYPE bu_namep_f,
        name_l TYPE bu_namep_l,
        mru TYPE ableinh,
        ABLBELNR TYPE ABLBELNR,
        city TYPE ad_city1,
        street TYPE ad_street,
        house_num TYPE ad_hsnm1,
        haus TYPE tplma,
        vstelle TYPE vstelle,
        targetmrdate TYPE adatsoll,
        equipment TYPE equnr,
        device TYPE geraet,
        register TYPE e_zwnummer,
        actualmrdate TYPE adattats,
        prv_reading TYPE zpf_readingresult,
        readingresult TYPE zpf_readingresult,
        unit_billing TYPE e_massbill,
        mr_note TYPE ablhinw,


        END OF ty_tab.

DATA : it_tab TYPE STANDARD TABLE OF ty_tab,
       wa_tab TYPE ty_tab.

DATA : it_raw  TYPE truxs_t_text_data,
       it_data TYPE TABLE OF alsmex_tabline.

 DATA : lt_message   TYPE TABLE OF bapireturn1,
         lt_readings  TYPE STANDARD TABLE OF bapieablu,
         wa_readings  TYPE bapieablu,
         l_grid       TYPE REF TO cl_salv_table,
         lr_functions TYPE REF TO cl_salv_functions_list,
         l_display    TYPE REF TO cl_salv_display_settings,
         gc_true      TYPE sap_bool VALUE 'X'.                                                   "include for data declerations


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM GET_FILE.                                                               " Subroutine to Get file name

  PERFORM EXCEL_ITAB.                                                             "Subroutine to retrive data from excel to interanal tab
  PERFORM MR_UPLOAD.                                                              "Subroutine to upload data










*&---------------------------------------------------------------------*
*&      Form  excel_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM EXCEL_ITAB .
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      I_LINE_HEADER        = 'X'
      I_TAB_RAW_DATA       = IT_RAW       " WORK TABLE
      I_FILENAME           = P_FILE
    TABLES
      I_TAB_CONVERTED_DATA = IT_TAB[]    "ACTUAL DATA
    EXCEPTIONS
      CONVERSION_FAILED    = 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.
  ENDIF.

  LOOP AT IT_TAB INTO WA_TAB.


    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = WA_TAB-ABLBELNR
      IMPORTING
        OUTPUT = WA_TAB-ABLBELNR.

    WA_READINGS-MRIDNUMBER = WA_TAB-ABLBELNR .

    WA_READINGS-MRREASON         = '01'."wa_tab-MrReason.
    WA_READINGS-SERIALNO         = WA_TAB-DEVICE."serialno.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = WA_TAB-REGISTER
      IMPORTING
        OUTPUT = WA_TAB-REGISTER.
    WA_READINGS-REGISTER         = WA_TAB-REGISTER.
    WA_READINGS-READINGRESULT    = WA_TAB-READINGRESULT.
    WA_READINGS-TARGETMRDATE     = WA_TAB-TARGETMRDATE.
    WA_READINGS-ACTUALMRDATE     = WA_TAB-ACTUALMRDATE.
    WA_READINGS-MRDATEFORBILLING = WA_TAB-ACTUALMRDATE."mrdateforbilling.
    APPEND WA_READINGS TO LT_READINGS.
    CLEAR WA_READINGS.
  ENDLOOP.

ENDFORM.                    " excel_itab
*&---------------------------------------------------------------------*
*&      Form  mr_upload
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM MR_UPLOAD .
  CALL FUNCTION 'BAPI_MTRREADDOC_UPLOAD'
    TABLES
      METERREADINGRESULTS = LT_READINGS
      RETURN              = LT_MESSAGE.

  CALL METHOD CL_SALV_TABLE=>FACTORY
    IMPORTING
      R_SALV_TABLE = L_GRID
    CHANGING
      T_TABLE      = LT_MESSAGE.

  LR_FUNCTIONS = L_GRID->GET_FUNCTIONS( ).
  LR_FUNCTIONS->SET_ALL( GC_TRUE ).

  L_DISPLAY = L_GRID->GET_DISPLAY_SETTINGS( ).
  L_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ).
  L_GRID->DISPLAY( ).
ENDFORM.                    " mr_upload
*&---------------------------------------------------------------------*
*&      Form  get_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_FILE .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      FIELD_NAME = 'P_FILE'
    IMPORTING
      FILE_NAME  = P_FILE.
ENDFORM.                    " get_file

No comments:

Post a Comment