Create Simple ALV Hierarchy Report

Membuat Report

1.Buka SE38
2.Salin "YPRACTICE_501" menjadi "YPRACTICE_503"
3.Seleksi Semua Objek

ar0081

4.Klik "ar0076"
5.Salin program include dengan nama "YPRACTICE_503_ALV"

ar0268

6.Klik "ar0076" kemudian Simpan Program
7.Ubah Program "YPRACTICE_503"
8.Buka Goto > Attributes, dan ubah "Title" dengan "503 - Display List of Master Material"
9.Modifikasi Deklarasi Report

Before

REPORT ypractice_501.

After

REPORT ypractice_502.

10.Modifikasi Deklarasi Tabel

Before

TABLES : mara, makt, t006a.

After

TABLES : t023t, mara, makt, t006a.

11.Klik Ganda "YPRACTICE_503_ALV" pada kode sintak dibawah

...

TABLES : t023t, mara, makt, t006a.

INCLUDE YPRACTICE_503_ALV.

*INCLUDE ypractice_501_alv.

*----------------------------------------------------------------------*

*GLOBAL VARIABLE DECRALATION

*----------------------------------------------------------------------*

TYPES: BEGIN OF ty_header,

...

12.Modifikasi Deklarasi Global Variable

Before

TYPES: BEGIN OF ty_header,

matkl LIKE mara-matkl, " Material Group

matnr LIKE mara-matnr, " Material Number

maktx LIKE makt-maktx, " Material Description

bismt LIKE mara-bismt, " Old material number

meins LIKE mara-meins, " Base Unit of Measure

mseht LIKE t006a-mseht, " Unit of Measurement Text

END OF ty_header.

DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE,

gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE,

gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.

After

TYPES : BEGIN OF ty_header,

chbox,

exp,

matkl LIKE t023t-matkl,

wgbez LIKE t023t-wgbez,

END OF ty_header.

TYPES: BEGIN OF ty_detail,

matkl LIKE mara-matkl, " Material Group

matnr LIKE mara-matnr, " Material Number

maktx LIKE makt-maktx, " Material Description

bismt LIKE mara-bismt, " Old material number

meins LIKE mara-meins, " Base Unit of Measure

mseht LIKE t006a-mseht, " Unit of Measurement Text

END OF ty_detail.

DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE,

gi_detail TYPE STANDARD TABLE OF ty_detail WITH HEADER LINE,

gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE,

gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.

13.Modifikasi Subroutine "FM_COLLECT_DATA"

Before

* Collect Master Material

SELECT matnr matkl bismt meins

INTO CORRESPONDING FIELDS OF TABLE gi_header

FROM mara

WHERE

matkl IN so_matkl AND

matnr IN so_matnr.

* "For SAP 4.6C

* DATA : lv_total_data type i.

* DESCRIBE TABLE gi_header LINES lv_total_data.

* IF lv_total_data > 0.

IF LINES( gi_header ) > 0." For SAP 4.7 above

* Collect Material Decription

SELECT matnr maktx

INTO CORRESPONDING FIELDS OF TABLE gi_makt

FROM makt

FOR ALL ENTRIES IN gi_header

WHERE

matnr = gi_header-matnr AND

spras = sy-langu.

* Collect Measurement Text

SELECT msehi mseht

INTO CORRESPONDING FIELDS OF TABLE gi_t006a

FROM t006a

FOR ALL ENTRIES IN gi_header

WHERE

msehi = gi_header-meins AND

spras = sy-langu.

ENDIF.

* Notes :

* Avoid using inner join

After

*Collect Material Group

SELECT matkl wgbez

INTO CORRESPONDING FIELDS OF TABLE gi_header

FROM t023t

WHERE matkl IN so_matkl AND

spras = sy-langu.

* "For SAP 4.6C

* DATA : lv_total_data type i.

* DESCRIBE TABLE gi_header LINES lv_total_data.

* IF lv_total_data > 0.

IF LINES( gi_header ) > 0." For SAP 4.7 above

* Collect Master Material

SELECT matnr matkl bismt meins

INTO CORRESPONDING FIELDS OF TABLE gi_detail

FROM mara

FOR ALL ENTRIES IN gi_header

WHERE

matkl = gi_header-matkl AND

matnr IN so_matnr.

IF LINES( gi_detail ) > 0." For SAP 4.7 above

* Collect Material Decription

SELECT matnr maktx

INTO CORRESPONDING FIELDS OF TABLE gi_makt

FROM makt

FOR ALL ENTRIES IN gi_detail

WHERE

matnr = gi_detail-matnr AND

spras = sy-langu.

* Collect Measurement Text

SELECT msehi mseht

INTO CORRESPONDING FIELDS OF TABLE gi_t006a

FROM t006a

FOR ALL ENTRIES IN gi_detail

WHERE

msehi = gi_detail-meins AND

spras = sy-langu.

ENDIF.

ENDIF.

* Notes :

* Avoid using inner join

14.Modifikasi Subroutine "FM_PROCESS_DATA"

Before

*Get other requirement information

LOOP AT gi_header.

* Get Material Description

READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.

IF sy-subrc = 0.

gi_header-maktx = gi_makt-maktx.

ENDIF.

* Get Measurement Text

READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.

IF sy-subrc = 0.

gi_header-mseht = gi_t006a-mseht.

ENDIF.

MODIFY gi_header.

ENDLOOP.

After

*Get other requirement information

LOOP AT gi_detail.

* Get Material Description

READ TABLE gi_makt WITH KEY matnr = gi_detail-matnr.

IF sy-subrc = 0.

gi_detail-maktx = gi_makt-maktx.

ENDIF.

* Get Measurement Text

READ TABLE gi_t006a WITH KEY msehi = gi_detail-meins.

IF sy-subrc = 0.

gi_detail-mseht = gi_t006a-mseht.

ENDIF.

MODIFY gi_detail.

ENDLOOP.

15.Buat subroutine baru dengan nama "FM_BUILD_KEYINFO"

FORM fm_build_keyinfo USING fu_keyinfo TYPE slis_keyinfo_alv .

ENDFORM.

16.Tuliskan sintak berikut pada subroutine "FM_BUILD_KEYINFO"

fu_keyinfo-header01 = 'MATKL'.

* fu_keyinfo-header02 = 'VKORG'.

* fu_keyinfo-header03 = 'VTWEG'.

* fu_keyinfo-header04 = 'NETWR'.

* fu_keyinfo-header05 = 'WAERK'.

fu_keyinfo-item01 = 'MATKL'.

* fu_keyinfo-item02 = 'POSNR'.

* fu_keyinfo-item03 = 'VTWEG'.

* fu_keyinfo-item04 = 'SPART'.

* fu_keyinfo-item05 = 'NORM'.

17.Buka inlcude program "YPRACTICE_503_ALV"
18.Tambahkan variable "gw_is_reprep_id" pada deklarasi paling atas

Before

gw_is_print TYPE slis_print_alv,

gw_is_reprep_id TYPE slis_reprep_id.

After

gw_is_print TYPE slis_print_alv,

gw_is_reprep_id TYPE slis_reprep_id,

gw_alv_keyinfo TYPE slis_keyinfo_alv.

19.Modifikasi Subroutine "FM_ALV_SET_LAYOUT"

Before

FORM fm_alv_set_layout USING fu_title.

gw_is_layout-window_titlebar = fu_title.

gw_is_layout-zebra = 'X'.

gw_is_layout-colwidth_optimize = 'X'.

gw_is_layout-no_colhead = space.

gw_is_layout-group_change_edit = 'X'.

* gw_is_layout-box_fieldname = 'CHBOX'.

ENDFORM.

After

FORM fm_alv_set_layout USING fu_title.

gw_is_layout-window_titlebar = fu_title.

gw_is_layout-zebra = 'X'.

gw_is_layout-colwidth_optimize = 'X'.

gw_is_layout-no_colhead = space.

gw_is_layout-group_change_edit = 'X'.

* gw_is_layout-box_fieldname = 'CHBOX'.

gw_is_layout-BOX_FIELDNAME = 'CHBOX'.

gw_is_layout-BOX_TABNAME = 'GI_HEADER'.

gw_is_layout-EXPAND_FIELDNAME = 'EXP'.

gw_is_layout-EXPAND_ALL = 'X'.

ENDFORM.

20.Tuliskan sintak berikut pada subroutine "FM_ALV_SHOW_HIER"

PERFORM fm_build_keyinfo USING gw_alv_keyinfo.

CLEAR gi_it_event_exit.

gi_it_event_exit-ucomm = '&OUP'.

gi_it_event_exit-after = 'X'.

APPEND gi_it_event_exit.

CLEAR gi_it_event_exit.

gi_it_event_exit-ucomm = '&ODN'.

gi_it_event_exit-after = 'X'.

APPEND gi_it_event_exit.

CLEAR gi_it_event_exit.

gi_it_event_exit-ucomm = '&ETA'.

gi_it_event_exit-after = 'X'.

APPEND gi_it_event_exit.

CLEAR gi_it_event_exit.

gi_it_event_exit-ucomm = '&IC1'.

gi_it_event_exit-after = 'X'.

APPEND gi_it_event_exit.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

* I_INTERFACE_CHECK = ' '

i_callback_program = sy-repid

i_callback_pf_status_set = 'FM_ALV_SET_PF_STATUS'

i_callback_user_command = 'FM_ALV_USER_COMMAND'

is_layout = gw_is_layout

it_fieldcat = gi_it_fieldcat[]

it_sort = gi_it_sort[]

it_filter = gi_it_filter[]

is_sel_hide = gw_is_sel_hide

i_default = gv_i_default

i_save = gv_i_save

is_variant = gw_is_variant

it_events = gi_it_events[]

it_event_exit = gi_it_event_exit[]

is_print = gw_is_print

is_reprep_id = gw_is_reprep_id

* I_SCREEN_START_COLUMN = 0

i_tabname_header = 'GI_HEADER'

i_tabname_item = 'GI_DETAIL'

is_keyinfo = gw_alv_keyinfo

TABLES

t_outtab_header = ft_header

t_outtab_item = ft_detail.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

21.Tambahkan Parameter "fu_0" dan sisipkan sintak "tabname" pada subroutine "fm_alv_add_fieldcat"

form fm_alv_add_fieldcat using fu_0 fu_1 fu_2 fu_3 fu_4 fu_5 fu_6 fu_7 fu_8 fu_9 fu_10

fu_11 fu_12 fu_13 fu_14 fu_15 fu_16 fu_17 fu_18 fu_19 fu_20 fu_21.

clear: gi_it_fieldcat.

gi_it_fieldcat-tabname = fu_0. " Tablename <<>

gi_it_fieldcat-fieldname = fu_1. " Fieldname

gi_it_fieldcat-ref_tabname = fu_2. " Reference Tablename

gi_it_fieldcat-ref_fieldname = fu_3. " Reference Fieldname

gi_it_fieldcat-no_out = fu_4. " (O)blig.(X)no out

gi_it_fieldcat-outputlen = fu_5. " Output length

gi_it_fieldcat-seltext_l = fu_6. " long key word

gi_it_fieldcat-seltext_m = fu_7. " middle key word

gi_it_fieldcat-seltext_s = fu_8. " short key word

gi_it_fieldcat-reptext_ddic = fu_9. " heading (ddic)

gi_it_fieldcat-round = fu_10. " round in write statement

gi_it_fieldcat-do_sum = fu_11. " sum up

gi_it_fieldcat-hotspot = fu_12. " 'X' = hotspot is active -> Event click

gi_it_fieldcat-decimals_out = fu_13. " decimals in write statement

gi_it_fieldcat-currency = fu_14.

gi_it_fieldcat-quantity = fu_15.

gi_it_fieldcat-qfieldname = fu_16. " field with quantity unit

gi_it_fieldcat-cfieldname = fu_17. " field with currency unit

gi_it_fieldcat-checkbox = fu_18. " 'X' = checkbox or ' ' = not checkbox

gi_it_fieldcat-icon = fu_19. " 'X' = icon or ' ' = not icon

gi_it_fieldcat-fix_column = fu_20. " 'X' = Fix Column On or ' ' = Fix Column off gi_it_fieldcat-key = &21. "

gi_it_fieldcat-key = fu_21. " 'X' = Key or ' ' = not Key

append gi_it_fieldcat.

endform.

22.Kembali ke report "YPRACTICE_503"
23.Modifikasi sintak pada subroutine "FM_DISPLAY_DATA"

Before

...

PERFORM fm_alv_show TABLES gi_header.

..

After

...

PERFORM fm_alv_show_hier TABLES gi_header gi_detail.

...

24.Modifikasi sintak pada subroutine "FM_"

Before

* Displaying Column by Fieldname

PERFORM fm_alv_add_fieldcat USING :

'MATKL' 'MARA' 'MATKL' '' '' 'Mat. Group' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',

'MATNR' 'MARA' 'MATNR' '' '' 'Mat. Number' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',

'MAKTX' 'MAKT' 'MAKTX' '' '' 'Decription' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',

'BISMT' 'MARA' 'BISMT' '' '' 'Old Mat. No' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',

'MEINS' 'MARA' 'MEINS' '' '' 'Base Unit' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',

'MSEHT' 'T006A' 'MSEHT' '' '' 'Measure' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.

After

* Set Header Column

PERFORM fm_alv_add_fieldcat USING 'GI_HEADER':

'MATKL' 'T023T' 'MATKL' '' '' 'Mat. Group' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',

'WGBEZ' 'T023T' 'WGBEZ' '' '' 'Mat. Number' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_internal_tabname = 'GI_HEADER'

* i_structure_name = ''

CHANGING

ct_fieldcat = gi_it_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

* Set Detail Column

PERFORM fm_alv_add_fieldcat USING 'GI_DETAIL':

'MATKL' 'MARA' 'MATKL' '' '' 'Mat. Group' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',

'MATNR' 'MARA' 'MATNR' '' '' 'Mat. Number' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',

'MAKTX' 'MAKT' 'MAKTX' '' '' 'Decription' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',

'BISMT' 'MARA' 'BISMT' '' '' 'Old Mat. No' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',

'MEINS' 'MARA' 'MEINS' '' '' 'Base Unit' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',

'MSEHT' 'T006A' 'MSEHT' '' '' 'Measure' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_internal_tabname = 'GI_DETAIL'

* i_structure_name = ''

CHANGING

ct_fieldcat = gi_it_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

25.Aktivasi Semua Objek dan Jalankan Program

ar0269

27.Selesai

Result

Seleksi Input

ar0270

Output

ar0271

Comments