Max Popenker (mpopenker) wrote,
Max Popenker
mpopenker

классовый вопрос

непрограммеры могут не читать

вот скажите, коллеги, занахуа при наприсании даже самых простых отчетов использовать объектную модель? мне, как человеку выросшему на хардкорном С (и даже С-- :), а также Фортране и прочем турбо-паскакале, этого расово классово-верного дао ну никак не постичь...


REPORT demo_string_template_time_form.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: main.
  PRIVATE SECTION.
    CLASS-DATA: BEGIN OF result,
                  col1 TYPE string,
                  col2 TYPE string,
                  col3 TYPE string,
                  col4 TYPE string,
                  col5 TYPE string,
                  col6 TYPE string,
                  col7 TYPE string,
                END OF result,
                result_tab LIKE TABLE OF result.
    CLASS-METHODS: setup,
                   teardown,
                   display,
                   check_system.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

   DATA: seconds   TYPE i,
          timetable TYPE TABLE OF t,
          land      TYPE t005x-land,
          comp      TYPE i.

    CONSTANTS n     TYPE i VALUE 4.

    FIELD-SYMBOLS: <time> TYPE t,
                   <col>  TYPE string.

    setup( ).

    DO 24 / n TIMES.
      seconds = ( sy-index - 1 ) * 3600 * n.
      APPEND seconds TO timetable.
      seconds = seconds + 1.
      APPEND seconds TO timetable.
      seconds = seconds + ( n - 1 ) * 3600 + 59 * 60 + 58.
      APPEND seconds TO timetable.
    ENDDO.

    LOOP AT timetable ASSIGNING <time>.
      result-col1 = |{ <time> TIME = RAW }|.
      result-col2 = |{ <time> TIME = ISO }|.
      SELECT land
             FROM t005x
             INTO (land)
             WHERE land LIKE '@%'.
        comp = sy-dbcnt + 2.
        ASSIGN COMPONENT comp OF STRUCTURE result TO <col>.
        <col> = |{ <time> COUNTRY = land }|.
      ENDSELECT.
      APPEND result TO result_tab.
    ENDLOOP.

    teardown( ).

    display( ).


 ENDMETHOD.
  METHOD setup.
    DATA: t005x_wa TYPE t005x,
          descr    TYPE REF TO cl_abap_elemdescr,
          fixvals  TYPE ddfixvalues,
          fixval   LIKE LINE OF fixvals,
          ans      TYPE c LENGTH 1.
    check_system( ).
    SELECT SINGLE land
           FROM t005x
           INTO (t005x_wa-land)
           WHERE land LIKE '@%'.
    IF sy-subrc = 0.
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          titlebar                      = 'Confirmation'
          text_question                 = 'Delete existing' &
                                          ' entries with keys' &
                                          ' @1, @2, ...  in T005X?'
          text_button_1                 = 'Yes'
          text_button_2                 = 'No'
          display_cancel_button         = ' '
        IMPORTING
          answer                        = ans.
      IF ans = 1.
        teardown( ).
      ELSE.
        MESSAGE 'Execution not possible' TYPE 'I' DISPLAY LIKE 'E'.
        LEAVE PROGRAM.
      ENDIF.
    ENDIF.
    descr ?= cl_abap_elemdescr=>describe_by_name( 'T005X-TIMEFM' ).
    fixvals = descr->get_ddic_fixed_values( ).
    LOOP AT fixvals INTO fixval.
      IF fixval-low IS INITIAL.
        CONTINUE.
      ENDIF.
      t005x_wa-land = '@' && |{ fixval-low }|.
      t005x_wa-timefm = |{ fixval-low }|.
      INSERT t005x FROM t005x_wa.
    ENDLOOP.
    COMMIT WORK.
  ENDMETHOD.
  METHOD teardown.
    DELETE FROM t005x WHERE land LIKE '@%'.
    COMMIT WORK.
  ENDMETHOD.
  METHOD display.
    DATA: alv     TYPE REF TO cl_salv_table,
          exc     TYPE REF TO cx_salv_error.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table = alv
          CHANGING  t_table      = result_tab ).
        alv->get_columns( )->set_optimize( 'X' ).
        alv->get_columns( )->get_column( 'COL1'
                          )->set_short_text( 'raw' ).
        alv->get_columns( )->get_column( 'COL2'
                          )->set_short_text( 'iso' ).
        alv->get_columns( )->get_column( 'COL3'
                          )->set_short_text( '24h' ).
        alv->get_columns( )->get_column( 'COL4'
                          )->set_short_text( '12H (1-12)' ).
        alv->get_columns( )->get_column( 'COL5'
                          )->set_short_text( '12h (1-12)' ).
        alv->get_columns( )->get_column( 'COL6'
                          )->set_short_text( '12H (0-11)' ).
        alv->get_columns( )->get_column( 'COL7'
                          )->set_short_text( '12h (0-11)' ).
        alv->get_display_settings( )->set_striped_pattern( 'X' ).
        alv->display( ).
      CATCH cx_salv_error INTO exc.
        MESSAGE exc TYPE 'I' DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.
  METHOD check_system.
    IF cl_abap_demo_services=>is_production_system( ) = abap_true.
      MESSAGE 'This demo cannot be executed in a production system'
              TYPE 'I' DISPLAY LIKE 'E'.
      LEAVE PROGRAM.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 41 comments