ALV Block

Untitled
Function yang digunakan adalah :

  1. REUSE_ALV_BLOCK_LIST_INIT untuk initialisasi block.
  2. REUSE_ALV_BLOCK_LIST_APPEND untuk menambahkan block. Bila ada lebih dari 1 block, panggil function ini berulang-ulang sesuai dengan jumlah internal table yang ingin ditampilkan pada screen.
  3. REUSE_ALV_BLOCK_LIST_DISPLAY digunakan untuk menampilkan alv block.
REPORT yalvblock LINE-SIZE 255.
TYPE-POOLS: slis.

DATA :t_fieldcat  TYPE slis_t_fieldcat_alv,
      w_fieldcat  TYPE slis_fieldcat_alv,
      layout      TYPE slis_layout_alv,
      t_sort      TYPE slis_t_sortinfo_alv,
      t_event1    TYPE slis_t_event,
      t_event2    TYPE slis_t_event,
      t_event3    TYPE slis_t_event,
      wa_event    TYPE slis_alv_event,
      key         TYPE slis_keyinfo_alv.

TYPES : BEGIN OF ty_data,
        store(15),
        book(30),
        author(30),
        amount(7) TYPE p,
        price TYPE dmbtr,
        total TYPE dmbtr, "(10) TYPE p DECIMALS 2,
        curr TYPE waers,
        END OF ty_data.

DATA : t_data TYPE ty_data OCCURS 0 WITH HEADER LINE,
       t_first TYPE ty_data OCCURS 0 WITH HEADER LINE,
       t_new TYPE ty_data OCCURS 0 WITH HEADER LINE.

INITIALIZATION.

START-OF-SELECTION.
  PERFORM f_process_data.
  PERFORM f_write_data.

*&---------------------------------------------------------------------*
*&      Form  F_PROCESS_DATA
*&---------------------------------------------------------------------*
FORM f_process_data .

*fill data t_data
  t_data-store = 'Gramedia'.
  t_data-book = 'Negeri 5 Menara'.
  t_data-author = 'A. Fuadi'.
  t_data-amount = 1000.
  t_data-price = 50000.
  t_data-total = t_data-amount * t_data-price.
  t_data-curr = 'IDR'.
  APPEND t_data.
  t_data-store = 'Eureka'.
  t_data-amount = 1000.
  t_data-price = 50000.
  t_data-total = t_data-amount * t_data-price.
  APPEND t_data.
  t_data-store = 'Leksikal'.
  t_data-amount = 500.
  t_data-price = 50000.
  t_data-total = t_data-amount * t_data-price.
  CLEAR t_data.

  t_data-store = 'Gramedia'.
  t_data-book = 'Marmut Merah Jambu'.
  t_data-author = 'Raditya Dhika'.
  t_data-amount = 3000.
  t_data-price = 30000.
  t_data-total = t_data-amount * t_data-price.
  t_data-curr = 'IDR'.
  APPEND t_data.
  t_data-store = 'Eureka'.
  APPEND t_data.
  t_data-store = 'Leksikal'.
  APPEND t_data.
  t_data-store = 'Gunung Agung'.
  APPEND t_data.
  CLEAR t_data.

  t_data-store = 'Gramedia'.
  t_data-book = 'Harry Potter'.
  t_data-author = 'J.K Rowling'.
  t_data-amount = 7000.
  t_data-price = 85000.
  t_data-total = t_data-amount * t_data-price.
  t_data-curr = 'IDR'.
  APPEND t_data.
  t_data-store = 'Gunung Agung'.
  t_data-amount = 1000.
  t_data-price = 85000.
  t_data-total = t_data-amount * t_data-price.
  APPEND t_data.
  CLEAR t_data.

  SORT t_data BY store.
  LOOP AT t_data.
    AT FIRST.
      SUM.
      MOVE-CORRESPONDING t_data TO t_first.
      APPEND t_first.
    ENDAT.

    AT NEW store.
      SUM.
      MOVE-CORRESPONDING t_data TO t_new.
      APPEND t_new.
    ENDAT.
  ENDLOOP.

  MOVE-CORRESPONDING t_first TO t_data.
  APPEND t_data.
ENDFORM.                    " F_PROCESS_DATA
*&---------------------------------------------------------------------*
*&      Form  F_WRITE_DATA
*&---------------------------------------------------------------------*
FORM f_write_data .
  PERFORM field_catalog.
  PERFORM build_layout.
  PERFORM build_event.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
    EXPORTING
      i_callback_program = sy-repid.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      is_layout                  = layout
      it_fieldcat                = t_fieldcat
      it_events                  = t_event1
      i_tabname                  = 'T_DATA'
    TABLES
      t_outtab                   = t_data
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 2
      OTHERS                     = 3.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      is_layout                  = layout
      it_fieldcat                = t_fieldcat
      it_events                  = t_event2
      i_tabname                  = 'T_FIRST'
    TABLES
      t_outtab                   = t_first
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 2
      OTHERS                     = 3.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      is_layout                  = layout
      it_fieldcat                = t_fieldcat
      it_events                  = t_event3
      i_tabname                  = 'T_NEW'
    TABLES
      t_outtab                   = t_new
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 2
      OTHERS                     = 3.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'.
ENDFORM.                    " F_WRITE_DATA
*&---------------------------------------------------------------------*
*&      Form  FIELD_CATALOG
*&---------------------------------------------------------------------*
FORM field_catalog .
  PERFORM f_fieldcats USING :
 'STORE'  'STORE'       '20' ''  ''     ''  ''  '',
 'BOOK'   'BOOK'        '20' ''  ''     ''  ''  '',
 'AUTHOR' 'AUTHOR'      '20' ''  ''     ''  ''  '',
 'AMOUNT' 'AMOUNT'      '10' ''  ''     ''  ''  '',
 'PRICE'  'PRICE'       '15' ''  ''     ''  ''  '',
 'TOTAL'  'TOTAL'       '20' 'X' ''     ''  ''  ''.
ENDFORM.                    " FIELD_CATALOG
*&---------------------------------------------------------------------*
*&      Form  F_FIELDCATS
*&---------------------------------------------------------------------*
FORM f_fieldcats USING fu_fname
                       fu_text
                       fu_len
                       fu_sum
                       fu_curr
                       fu_spot
                       fu_out
                       fu_sign.

  DATA : lt_fieldcat TYPE slis_fieldcat_alv.
  lt_fieldcat-fieldname      = fu_fname.  "field name
  lt_fieldcat-seltext_l      = lt_fieldcat-seltext_m =  "text
  lt_fieldcat-seltext_s      = fu_text.
  lt_fieldcat-reptext_ddic   = fu_text.
  lt_fieldcat-outputlen      = fu_len.  "text length
  lt_fieldcat-do_sum         = fu_sum.  "summing
  lt_fieldcat-cfieldname     = fu_curr. "currency
  lt_fieldcat-hotspot        = fu_spot.
  lt_fieldcat-no_out         = fu_out.
  lt_fieldcat-no_sign        = fu_sign.

  APPEND lt_fieldcat TO t_fieldcat.
  CLEAR: lt_fieldcat.

ENDFORM.                    " F_FIELDCATS
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
FORM build_layout .
  layout-colwidth_optimize = ''.
  layout-zebra = 'X'.

ENDFORM.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENT
*&---------------------------------------------------------------------*
FORM build_event .

  wa_event-form = 'TOP_PAGE1'.
  wa_event-name = 'TOP_OF_PAGE'.
  APPEND wa_event TO t_event1.
  CLEAR wa_event.

  wa_event-form = 'TOP_PAGE2'.
  wa_event-name = 'TOP_OF_PAGE'.
  APPEND wa_event TO t_event2.
  CLEAR wa_event.

  wa_event-form = 'TOP_PAGE3'.
  wa_event-name = 'TOP_OF_PAGE'.
  APPEND wa_event TO t_event3.
  CLEAR wa_event.
ENDFORM.                    " BUILD_EVENT

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_page1.
  uline.
  write: sy-vline, 'TABLE T_DATA', sy-vline.
  uline.
ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  top_page2
*&---------------------------------------------------------------------*
FORM top_page2.
  uline.
  write: sy-vline, 'TABLE T_FIRST', sy-vline.
  uline.
ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  top_page3
*&---------------------------------------------------------------------*
FORM top_page3.
  uline.
  write: sy-vline, 'TABLE T_NEW', sy-vline.
  uline.
ENDFORM.                    "top_of_page
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s