Membuat ALV Grid SAP ABAP

Pada postingan ini saya akan share cara membuat ALV grid di SAP - ABAP, ALV biasanya digunakan untuk menampilkan data dalam bentuk table atau grid dalam web programming atau programming yang lain seperti .Net, java dll.

Ok langsung saja, untuk contoh ini saya akan menampilkan data Purchase Order, berikut source code nya :

 *&---------------------------------------------------------------------*

*& Report ZALVEXMP

*&---------------------------------------------------------------------*

*&

*&---------------------------------------------------------------------*

report zalvexmp.


tables : ekpo, ekko, lfa1.


types :

  begin of t_data,

    ebeln type ebeln,

    ebelp type ebelp,

    matnr type matnr,

    maktx type maktx,

    werks type werks_d,

    lgort type lgort_d,

    menge type menge_d,

    meins type meins,

    netpr type bprei,

    waers type waers,

    lifnr type lifnr,

    name1 type name1,

  end of t_data.


data : it_data type table of t_data,

       wa_data type t_data.



data :it_fldcat          type lvc_t_fcat,

      wa_fldcat          type lvc_s_fcat,

      wa_layout          type lvc_s_layo,

      it_list_commentary type slis_t_listheader,

      wa_list_commentary type slis_listheader.


selection-screen begin of block b0 with frame title text-001.

"Parameter

*parameters : p_ebeln type ebeln.


"select option

select-options:

  s_ebeln for ekpo-ebeln,

  s_matnr for ekpo-matnr,

  s_lgort for ekpo-lgort,

  s_werks for ekpo-werks.

selection-screen end of block b0.



start-of-selection.

  perform getdata.

  perform setfieldcat.

  perform build_alv_header.

  perform display_alv.


form getdata.

  refresh it_data.

  select ekpo~ebeln ekpo~ebelp ekpo~matnr makt~maktx ekpo~menge ekpo~meins ekko~lifnr

         ekpo~werks ekpo~lgort ekpo~netpr ekko~waers lfa1~name1 into corresponding fields of table it_data

    from ekko inner join ekpo on ekko~ebeln = ekpo~ebeln inner join lfa1 on ekko~lifnr = lfa1~lifnr

         inner join makt on ekpo~matnr = makt~matnr

    where ekko~ebeln in s_ebeln and ekpo~matnr in s_matnr and ekpo~lgort in s_lgort and ekpo~werks in s_werks

          and ekpo~menge > 0.


  sort it_data by ebeln ebelp.

endform.


form setfieldcat.

  clear wa_fldcat.

  wa_fldcat-col_pos = 1.

  wa_fldcat-fieldname = 'EBELN'.

  wa_fldcat-scrtext_l = 'Purchase Order'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 16.

  wa_fldcat-outputlen = 16.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 2.

  wa_fldcat-fieldname = 'EBELP'.

  wa_fldcat-scrtext_l = 'Item'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 10.

  wa_fldcat-outputlen = 10.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 3.

  wa_fldcat-fieldname = 'MATNR'.

  wa_fldcat-scrtext_l = 'Material'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 40.

  wa_fldcat-outputlen = 40.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 4.

  wa_fldcat-fieldname = 'MAKTX'.

  wa_fldcat-scrtext_l = 'Material Description'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 40.

  wa_fldcat-outputlen = 40.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 5.

  wa_fldcat-fieldname = 'WERKS'.

  wa_fldcat-scrtext_l = 'Plant'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 10.

  wa_fldcat-outputlen = 10.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 6.

  wa_fldcat-fieldname = 'LGORT'.

  wa_fldcat-scrtext_l = 'Str. Loc'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 10.

  wa_fldcat-outputlen = 10.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 7.

  wa_fldcat-fieldname = 'MENGE'.

  wa_fldcat-scrtext_l = 'Quantity'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 15.

  wa_fldcat-outputlen = 15.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 8.

  wa_fldcat-fieldname = 'MEINS'.

  wa_fldcat-scrtext_l = 'Unit'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 10.

  wa_fldcat-outputlen = 10.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 9.

  wa_fldcat-fieldname = 'NETPR'.

  wa_fldcat-scrtext_l = 'Net Price'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 15.

  wa_fldcat-outputlen = 15.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 10.

  wa_fldcat-fieldname = 'WAERS'.

  wa_fldcat-scrtext_l = 'Currency'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 10.

  wa_fldcat-outputlen = 10.

  append wa_fldcat to it_fldcat .


  clear wa_fldcat.

  wa_fldcat-col_pos = 11.

  wa_fldcat-fieldname = 'NAME1'.

  wa_fldcat-scrtext_l = 'Vendor'.

  wa_fldcat-ref_table = 'IT_DATA'.

  wa_fldcat-intlen = 30.

  wa_fldcat-outputlen = 30.

  append wa_fldcat to it_fldcat .


endform.


form build_alv_header .

* Type H is used to display headers i.e. big font

  clear wa_list_commentary.

  wa_list_commentary-typ  = 'H'.

  wa_list_commentary-info = 'Contoh Report PO'.

  append wa_list_commentary to it_list_commentary.


  clear wa_list_commentary.

  wa_list_commentary-typ = 'H'.

  wa_list_commentary-info = 'PT. PErusahaan SAYA'.

  append wa_list_commentary to it_list_commentary.


* Type S is used to display key and value pairs

  clear wa_list_commentary.

  wa_list_commentary-typ = 'S'.

  wa_list_commentary-key = 'Date :' .

  concatenate sy-datum+6(2) sy-datum+4(2) sy-datum(4) into wa_list_commentary-info separated by '/'.

  append wa_list_commentary to it_list_commentary.


* Type A is used to display italic font

  clear wa_list_commentary.

  wa_list_commentary-typ = 'A'.

  concatenate 'Refresh on' sy-uzeit+0(2) into wa_list_commentary-info separated by space.

  concatenate wa_list_commentary-info sy-uzeit+2(2) sy-uzeit+4(2) into wa_list_commentary-info separated by ':'.

  append wa_list_commentary to it_list_commentary.

endform.


form top_of_page.

  call function 'REUSE_ALV_COMMENTARY_WRITE'

    exporting

      it_list_commentary = it_list_commentary

      i_logo             = 'ENJOYSAP_LOGO'. "ENJOYSAP_LOGO

endform.


form display_alv.
  wa_layout-stylefname = 'FIELD_STYLE'.
  wa_layout-zebra      = 'X'.
  call function 'REUSE_ALV_GRID_DISPLAY_LVC'
    exporting
      i_callback_program     = sy-repid
*     i_callback_pf_status_set = 'SET_PF_STATUS'
      i_callback_top_of_page = 'TOP_OF_PAGE'
      is_layout_lvc          = wa_layout
      it_fieldcat_lvc        = it_fldcat[]
      i_save                 = 'X'
    tables
      t_outtab               = it_data
    exceptions
      program_error          = 1
      others                 = 2.
endform.

 
Jika dijalankan tampilan programnya seperti berikut :

tampilan diatas adalah untuk memasukkan paramter filter data yang akan di tampilkan, jika tidak ada yang diisi maka akan menampilkan semua data. Berikut tampilan ALV Grid nya :

Sekian Semoga Bermanfaat. :D

Comments

Popular posts from this blog

PHP MySql CRUD Dengan Konsep MVC

Laravel - Sistem Informasi Perpustakaan Sederhana Laravel

IT Asset Management Dengan PHP MySQL