Tuesday, 20 May 2014

Meter Order

*&---------------------------------------------------------------------*
*& Report  ZMRDOC_GETLIST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zmrdoc_getlist.
DATA: it_eabl TYPE STANDARD TABLE OF bapieabl,
      it_eabl_mru TYPE STANDARD TABLE OF bapieablg ,
      l_grid TYPE REF TO cl_salv_table,
      lt_mru TYPE TABLE OF ableinh,
      l_mru TYPE ableinh,
      lr_functions TYPE REF TO cl_salv_functions_list.

CONSTANTS: gc_true  TYPE sap_bool VALUE 'X'.

SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
SELECT-OPTIONS
s_mru FOR l_mru.
SELECTION-SCREEN END OF BLOCK a1.

SELECT termschl INTO TABLE lt_mru FROM te422 WHERE termschl IN s_mru.
LOOP AT lt_mru INTO l_mru.
  CALL FUNCTION 'BAPI_MTRREADDOC_GETLIST'
    EXPORTING
*   PORTION                 =
     meterreadingunit        = l_mru
*   CONTRACT                =
*   MATERIAL                =
*   SERIALNO                =
*   REGISTER                =
*   TARGETMRDATEFROM        =
*   TARGETMRDATETO          =
*   MRDATEFROM              =
*   MRDATETO                =
*   MRREASON                =
      mrdocumenttype          = '1'
*   NO_REG_RELSHIP          = ' '
* IMPORTING
*   RETURN                  =
   TABLES
  mrdocumentdata          = it_eabl
  mrdocumentreasons = it_eabl_mru.
ENDLOOP.

TYPES:
  BEGIN OF addrs,
  city TYPE ad_mc_city,
  street TYPE ad_mc_strt,
  house_num TYPE ad_hsnm1,
    END OF addrs.
TYPES:
BEGIN OF t_name,
name_f TYPE bu_namep_f,
name_l TYPE bu_namep_l,
  END OF t_name.


types:
BEGIN OF final,
partner TYPE bu_partner,
name_f TYPE bu_namep_f,
name_l TYPE bu_namep_l,
mru TYPE ableinh,
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 final.

TYPESBEGIN OF t_mr_previous,
  v_zwstand TYPE v_zwstand,
  n_zwstand TYPE n_zwstand,
  END OF t_mr_previous.


DATA: l_eabl TYPE bapieabl,
      l_eabl_mru TYPE bapieablg,
      l_vstelle TYPE vstelle,
      l_haus TYPE tplnr,
      l_adrnr TYPE adrnr,
      l_addrs TYPE addrs,
      l_final TYPE final,
      l_name TYPE t_name,
      l_partner TYPE gpart_kk ,
      l_reading TYPE zpf_readingresult,
      l_vkonto TYPE vkont_kk,
      l_mr_previous TYPE t_mr_previous,
      lt_columns TYPE REF TO cl_salv_columns_table,
      l_column TYPE REF TO cl_salv_column,
      l_display TYPE REF TO cl_salv_display_settings,
      l_heading TYPE lvc_title,
      lt_final TYPE TABLE OF final.




LOOP AT it_eabl INTO l_eabl .
  READ TABLE it_eabl_mru INTO l_eabl_mru WITH KEY mridnumber = l_eabl-mridnumber.
  IF sy-subrc = 0.
    SELECT vstelle FROM eanl INTO l_vstelle WHERE anlage = l_eabl_mru-installation.
      IF sy-subrc = 0 .
        SELECT haus FROM evbs INTO l_haus WHERE vstelle = l_vstelle.
          IF sy-subrc = 0 .
            SELECT adrnr FROM iloa INTO l_adrnr WHERE tplnr = l_haus.
              IF sy-subrc = 0 .
                SELECT  mc_city1 mc_street house_num1 FROM adrc INTO l_addrs WHERE addrnumber = l_adrnr.
                  IF sy-subrc = 0 .
                    SELECT vkonto FROM ever INTO l_vkonto WHERE anlage = l_eabl_mru-installation.
                      IF sy-subrc = 0 .
                        SELECT gpart FROM fkkvkp INTO l_partner WHERE vkont = l_vkonto.
                          IF sy-subrc = 0 .
                            SELECT name_first name_last FROM but000 INTO l_name  WHERE partner = l_partner.
                            ENDSELECT.
                            IF sy-subrc = 0.
                              SELECT v_zwstand n_zwstand FROM eabl INTO l_mr_previous WHERE adat = l_eabl-targetmrdate.
                                l_reading = l_mr_previous-v_zwstand + l_mr_previous-n_zwstand.
                              ENDSELECT.
                            ENDIF.
                          ENDIF.
                          ENDSELECT.
                        ENDIF.
                      ENDSELECT.
                    ENDIF.
                  ENDSELECT.
                ENDIF.
              ENDSELECT.
            ENDIF.
          ENDSELECT.
        ENDIF.
      ENDSELECT.
    ENDIF.



    l_final-partner = l_partner.
    l_final-name_f = l_name-name_f.
    l_final-name_l = l_name-name_l.
    l_final-vstelle = l_vstelle.
    l_final-haus = l_haus.
    l_final-readingresult = l_eabl-readingresult.
    l_final-city = l_addrs-city.
    l_final-street = l_addrs-street.
    l_final-house_num = l_addrs-house_num.
    l_final-unit_billing = l_eabl-unit_billing.
    l_final-prv_reading = l_reading.
    l_final-device = l_eabl-device.
    l_final-register = l_eabl-register.
    l_final-equipment = l_eabl-equipment.
    l_final-targetmrdate = l_eabl-targetmrdate.
    l_final-mru = l_eabl_mru-meterreadingunit.
    APPEND l_final TO lt_final.

  ENDLOOP.



  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = l_grid
    CHANGING
      t_table      = lt_final.

  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_heading = 'meter reading order'.
  l_display->set_list_header( l_heading ).
  lt_columns = l_grid->get_columns( ).
  l_column ?= lt_columns->get_column('PRV_READING').
  l_column->set_long_text( 'previous meter reading' ).
  l_column->set_medium_text( 'prev mr read ' ).
  l_column->set_short_text( 'prv mt rd' ).

  lt_columns = l_grid->get_columns( ).
  l_column ?= lt_columns->get_column('READINGRESULT').
  l_column->set_long_text( 'Current meter reading' ).
  l_column->set_medium_text( 'Curt mr read ' ).
  l_column->set_short_text( 'Curr mt rd' ).

  l_grid->display( ).

No comments:

Post a Comment