1. Buka t-code SE38 buat program baru dengan nama ZUPLOAD.
2. Buka SE38 baru lagi lalu display program 'SAPLKKBL'.
4. Pada GUI Status copy STANDARD ke program yang kita buat.
5. Kembali ke program kita ZUPLOAD.
6. Ke Menu Goto > Text Element > Selection Text.
7. Pada Tab Text Symbol isikan informasi seperti pada gambar berikut lalu simpan:
9. Pada Gui Status, double klik ZSTANDARD.
10. Expand pada Application Toolbar lalu buat menu baru dengan nama &UPL lalu Enter.
11. Isi seperti pada gambar berikut :
12. Simpan lalu kembali ke program utama lalu ketikkan source code seperti di bawah ini:
*&---------------------------------------------------------------------*
*& Report ZUPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zupload.
INCLUDE zupload_inc.
TABLES sscrfields.
DATA: t_excel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE. " itab representation of the excel file
TYPES: BEGIN OF ty_upload,
id_kab LIKE zkabupaten-id_kab,
des_kab LIKE zkabupaten-des_kab,
kd_pos LIKE zkabupaten-kd_pos,
END OF ty_upload.
DATA: BEGIN OF t_excel_record OCCURS 0,
id_kab LIKE zkabupaten-id_kab,
des_kab LIKE zkabupaten-des_kab,
kd_pos LIKE zkabupaten-kd_pos,
END OF t_excel_record.
DATA: t_upload TYPE STANDARD TABLE OF ty_upload WITH HEADER LINE,
t_insert LIKE STANDARD TABLE OF zkabupaten WITH HEADER LINE.
DATA : d_currentrow TYPE i.
DATA: BEGIN OF t_msgcoll OCCURS 0.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF t_msgcoll.
DATA l_mode VALUE 'N'.
DATA : lv_start_row TYPE i.
DATA : lv_end_row TYPE i.
DATA : d_counter TYPE i.
DATA: wa_excel_record LIKE t_excel_record.
type-pools : icon.
types : begin of ty_repot,
icon(4),
id_kab like zkabupaten-id_kab,
des_kab LIKE zkabupaten-des_kab,
kd_pos LIKE zkabupaten-kd_pos,
status type c length 10,
end of ty_repot.
data : t_repot type standard table of ty_repot with header line.
SELECTION-SCREEN BEGIN OF BLOCK frame1 WITH FRAME.
SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-002 FOR FIELD p_infile.
PARAMETER p_infile LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-003 FOR FIELD pa_row01.
PARAMETERS: pa_row01(4) TYPE n DEFAULT 1. " start row
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-004 FOR FIELD pa_row02.
PARAMETERS: pa_row02(4) TYPE n DEFAULT 100. " end row
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK c.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 15.
SELECTION-SCREEN PUSHBUTTON 1(10) text-006 USER-COMMAND tam.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN COMMENT /1(30) text-005.
SELECTION-SCREEN END OF BLOCK frame1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
PERFORM f_get_filename CHANGING p_infile.
AT SELECTION-SCREEN.
CASE sscrfields.
WHEN 'TAM'.
CLEAR : t_insert[],
t_excel_record[].
REFRESH t_insert[].
PERFORM f_gui_message USING 'Reading from excel file, please wait....' ''.
PERFORM f_excell_process.
PERFORM fm_alv_set_column.
PERFORM fm_display_data.
ENDCASE.
START-OF-SELECTION.
CLEAR : t_insert[],
t_excel_record[].
REFRESH t_insert[].
PERFORM f_gui_message USING 'Reading from excel file, please wait....' ''.
PERFORM f_excell_process.
* PERFORM process_bdc.
*&---------------------------------------------------------------------*
*& Form f_get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FC_FILE text
*----------------------------------------------------------------------*
FORM f_get_filename CHANGING fc_file.
DATA ld_loc LIKE dxfields-location.
DATA ld_path LIKE dxfields-longpath." value '/usr/sap'.
CALL FUNCTION '/SAPDMC/LSM_F4_FRONTEND_FILE'
CHANGING
pathfile = fc_file
EXCEPTIONS
canceled_by_user = 1
system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. " F_GET_FILENAME
*&---------------------------------------------------------------------*
*& Form f_gui_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FU_TEXT1 text
* -->FU_TEXT2 text
*----------------------------------------------------------------------*
FORM f_gui_message USING fu_text1 fu_text2.
DATA: ld_text1(100) TYPE c.
CONCATENATE fu_text1 fu_text2 INTO ld_text1
SEPARATED BY space.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 40
text = ld_text1.
ENDFORM. " F_GUI_MESSAGE
*&---------------------------------------------------------------------*
*& Form f_excell_process
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_excell_process .
CLEAR : lv_start_row, lv_end_row.
lv_start_row = pa_row01.
lv_end_row = pa_row02.
DATA: lv_tabix TYPE sy-tabix.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_infile
i_begin_col = '1'
i_begin_row = lv_start_row " Start at 8nd row used no heading
i_end_col = '43'
i_end_row = lv_end_row
TABLES
intern = t_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE e000(0k) WITH text-001. "Problem uploading Excel Spreadsheet
ENDIF.
* Sort table by rows and colums
SORT t_excel BY row col.
* Get first row retrieved
DELETE t_excel WHERE row EQ '0001'.
READ TABLE t_excel INDEX 1.
* Set first row retrieved to current row
d_currentrow = t_excel-row.
LOOP AT t_excel.
* Reset values for next row
IF t_excel-row NE d_currentrow.
APPEND wa_excel_record TO t_excel_record.
CLEAR wa_excel_record.
d_currentrow = t_excel-row.
ENDIF.
CASE t_excel-col.
WHEN '0001'.
wa_excel_record-id_kab = t_excel-value.
WHEN '0002'.
wa_excel_record-des_kab = t_excel-value.
WHEN '0003'.
wa_excel_record-kd_pos = t_excel-value.
ENDCASE.
ENDLOOP.
APPEND wa_excel_record TO t_excel_record.
d_counter = 0.
PERFORM f_gui_message USING 'Processing transaction...' ''.
LOOP AT t_excel_record.
MOVE-CORRESPONDING t_excel_record TO t_insert.
APPEND t_insert.
ENDLOOP.
ENDFORM. "f_excell_process
*&---------------------------------------------------------------------*
*& Form fm_display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fm_display_data.
PERFORM fm_alv_reset_data.
* Mengatur Parameter dan Data ALV
PERFORM fm_alv_set_layout USING 'Program Upload'.
PERFORM fm_alv_set_print.
PERFORM fm_alv_set_column.
gv_i_default = 'X'.
gv_i_save = 'A'.
PERFORM fm_alv_show TABLES t_insert.
ENDFORM. "fm_display_data
*&---------------------------------------------------------------------*
*& Form fm_alv_set_column
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fm_alv_set_column.
PERFORM fm_alv_add_fieldcat USING :
'ID_KAB' 'ZKABUPATEN' 'ID_KAB' 'KD Kab.' 'KD Kab.' 'KD Kab.' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',
'DES_KAB' 'ZKABUPATEN' 'DES_KAB' 'Deskripsi' 'Deskripsi' 'Deskripsi' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'KD_POS' 'ZKABUPATEN' 'KD_POS' 'KD POS' 'KD POS' 'KD POS' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.
ENDFORM. "fm_alv_set_column
*&--------------------------------------------------------------------*
*& Form FM_USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
*FORM fm_alv_user_command USING fu_ucomm LIKE sy-ucomm
* fu_selfield TYPE slis_selfield.
FORM fm_alv_user_command USING fu_ucomm LIKE sy-ucomm
fu_selfield TYPE slis_selfield.
DATA: lt_dynpread LIKE dynpread OCCURS 0 WITH HEADER LINE,
lv_ok_code LIKE sy-ucomm.
DATA: rspar_tab TYPE TABLE OF rsparams,
rspar_line LIKE LINE OF rspar_tab.
DATA: lv_dbcnt(10) VALUE '0'.
DATA: lv_tabix TYPE sy-tabix.
DATA: lv_messg(80).
DATA : count TYPE i,
gagal TYPE c LENGTH 255,
icount TYPE c LENGTH 4,
message_g TYPE c LENGTH 255,
message_s TYPE c LENGTH 255,
sukses TYPE c LENGTH 255.
MOVE fu_ucomm TO lv_ok_code.
CASE lv_ok_code.
WHEN '&IC1'.
* PERFORM fm_alv_event_double_click.
WHEN '&ETA'.
* PERFORM fm_alv_event_double_click.
WHEN '&F03' OR '&F15' OR '&F12'.
WHEN '&UPD'.
* BREAK-POINT.
clear t_repot[].
LOOP AT t_insert.
MODIFY zkabupaten FROM t_insert.
IF sy-subrc = 0.
move t_insert-id_kab to t_repot-id_kab.
move t_insert-des_kab to t_repot-des_kab.
move t_insert-kd_pos to t_repot-kd_pos.
move 'sukses' to t_repot-status.
move icon_green_light to t_repot-icon.
append t_repot.
else.
move t_insert-id_kab to t_repot-id_kab.
move t_insert-des_kab to t_repot-des_kab.
move t_insert-kd_pos to t_repot-kd_pos.
move 'gagal' to t_repot-status.
move icon_red_light to t_repot-icon.
append t_repot.
ENDIF.
ENDLOOP.
ENDCASE.
**
* MOVE 'X' TO fu_selfield-exit.
perform fm_display_report.
ENDFORM. "FM_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form FM_DISPLAY_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form FM_DISPLAY_REPORT .
PERFORM fm_alv_reset_data.
* Mengatur Parameter dan Data ALV
PERFORM fm_alv_set_layout USING 'Program Upload'.
PERFORM fm_alv_set_print.
PERFORM fm_alv_set_column2.
gv_i_default = 'X'.
gv_i_save = 'A'.
PERFORM fm_alv_show TABLES t_repot.
endform. " FM_DISPLAY_REPORT
*&---------------------------------------------------------------------*
*& Form FM_ALV_SET_COLUMN2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form FM_ALV_SET_COLUMN2 .
PERFORM fm_alv_add_fieldcat USING :
'ICON' '' '' '' '' 'Icon' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X' 'X',
'ID_KAB' 'ZKABUPATEN' 'ID_KAB' 'KD Kab.' 'KD Kab.' 'KD Kab.' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'DES_KAB' 'ZKABUPATEN' 'DES_KAB' 'Deskripsi' 'Deskripsi' 'Deskripsi' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'KD_POS' 'ZKABUPATEN' 'KD_POS' 'KD POS' 'KD POS' 'KD POS' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'STATUS' 'ZKABUPATEN' 'STATUS' 'Status' 'Status' 'Status' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.
endform. " FM_ALV_SET_COLUMN2
*& Report ZUPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zupload.
INCLUDE zupload_inc.
TABLES sscrfields.
DATA: t_excel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE. " itab representation of the excel file
TYPES: BEGIN OF ty_upload,
id_kab LIKE zkabupaten-id_kab,
des_kab LIKE zkabupaten-des_kab,
kd_pos LIKE zkabupaten-kd_pos,
END OF ty_upload.
DATA: BEGIN OF t_excel_record OCCURS 0,
id_kab LIKE zkabupaten-id_kab,
des_kab LIKE zkabupaten-des_kab,
kd_pos LIKE zkabupaten-kd_pos,
END OF t_excel_record.
DATA: t_upload TYPE STANDARD TABLE OF ty_upload WITH HEADER LINE,
t_insert LIKE STANDARD TABLE OF zkabupaten WITH HEADER LINE.
DATA : d_currentrow TYPE i.
DATA: BEGIN OF t_msgcoll OCCURS 0.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF t_msgcoll.
DATA l_mode VALUE 'N'.
DATA : lv_start_row TYPE i.
DATA : lv_end_row TYPE i.
DATA : d_counter TYPE i.
DATA: wa_excel_record LIKE t_excel_record.
type-pools : icon.
types : begin of ty_repot,
icon(4),
id_kab like zkabupaten-id_kab,
des_kab LIKE zkabupaten-des_kab,
kd_pos LIKE zkabupaten-kd_pos,
status type c length 10,
end of ty_repot.
data : t_repot type standard table of ty_repot with header line.
SELECTION-SCREEN BEGIN OF BLOCK frame1 WITH FRAME.
SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-002 FOR FIELD p_infile.
PARAMETER p_infile LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-003 FOR FIELD pa_row01.
PARAMETERS: pa_row01(4) TYPE n DEFAULT 1. " start row
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(10) text-004 FOR FIELD pa_row02.
PARAMETERS: pa_row02(4) TYPE n DEFAULT 100. " end row
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK c.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 15.
SELECTION-SCREEN PUSHBUTTON 1(10) text-006 USER-COMMAND tam.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN COMMENT /1(30) text-005.
SELECTION-SCREEN END OF BLOCK frame1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
PERFORM f_get_filename CHANGING p_infile.
AT SELECTION-SCREEN.
CASE sscrfields.
WHEN 'TAM'.
CLEAR : t_insert[],
t_excel_record[].
REFRESH t_insert[].
PERFORM f_gui_message USING 'Reading from excel file, please wait....' ''.
PERFORM f_excell_process.
PERFORM fm_alv_set_column.
PERFORM fm_display_data.
ENDCASE.
START-OF-SELECTION.
CLEAR : t_insert[],
t_excel_record[].
REFRESH t_insert[].
PERFORM f_gui_message USING 'Reading from excel file, please wait....' ''.
PERFORM f_excell_process.
* PERFORM process_bdc.
*&---------------------------------------------------------------------*
*& Form f_get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FC_FILE text
*----------------------------------------------------------------------*
FORM f_get_filename CHANGING fc_file.
DATA ld_loc LIKE dxfields-location.
DATA ld_path LIKE dxfields-longpath." value '/usr/sap'.
CALL FUNCTION '/SAPDMC/LSM_F4_FRONTEND_FILE'
CHANGING
pathfile = fc_file
EXCEPTIONS
canceled_by_user = 1
system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. " F_GET_FILENAME
*&---------------------------------------------------------------------*
*& Form f_gui_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FU_TEXT1 text
* -->FU_TEXT2 text
*----------------------------------------------------------------------*
FORM f_gui_message USING fu_text1 fu_text2.
DATA: ld_text1(100) TYPE c.
CONCATENATE fu_text1 fu_text2 INTO ld_text1
SEPARATED BY space.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 40
text = ld_text1.
ENDFORM. " F_GUI_MESSAGE
*&---------------------------------------------------------------------*
*& Form f_excell_process
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_excell_process .
CLEAR : lv_start_row, lv_end_row.
lv_start_row = pa_row01.
lv_end_row = pa_row02.
DATA: lv_tabix TYPE sy-tabix.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_infile
i_begin_col = '1'
i_begin_row = lv_start_row " Start at 8nd row used no heading
i_end_col = '43'
i_end_row = lv_end_row
TABLES
intern = t_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE e000(0k) WITH text-001. "Problem uploading Excel Spreadsheet
ENDIF.
* Sort table by rows and colums
SORT t_excel BY row col.
* Get first row retrieved
DELETE t_excel WHERE row EQ '0001'.
READ TABLE t_excel INDEX 1.
* Set first row retrieved to current row
d_currentrow = t_excel-row.
LOOP AT t_excel.
* Reset values for next row
IF t_excel-row NE d_currentrow.
APPEND wa_excel_record TO t_excel_record.
CLEAR wa_excel_record.
d_currentrow = t_excel-row.
ENDIF.
CASE t_excel-col.
WHEN '0001'.
wa_excel_record-id_kab = t_excel-value.
WHEN '0002'.
wa_excel_record-des_kab = t_excel-value.
WHEN '0003'.
wa_excel_record-kd_pos = t_excel-value.
ENDCASE.
ENDLOOP.
APPEND wa_excel_record TO t_excel_record.
d_counter = 0.
PERFORM f_gui_message USING 'Processing transaction...' ''.
LOOP AT t_excel_record.
MOVE-CORRESPONDING t_excel_record TO t_insert.
APPEND t_insert.
ENDLOOP.
ENDFORM. "f_excell_process
*&---------------------------------------------------------------------*
*& Form fm_display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fm_display_data.
PERFORM fm_alv_reset_data.
* Mengatur Parameter dan Data ALV
PERFORM fm_alv_set_layout USING 'Program Upload'.
PERFORM fm_alv_set_print.
PERFORM fm_alv_set_column.
gv_i_default = 'X'.
gv_i_save = 'A'.
PERFORM fm_alv_show TABLES t_insert.
ENDFORM. "fm_display_data
*&---------------------------------------------------------------------*
*& Form fm_alv_set_column
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fm_alv_set_column.
PERFORM fm_alv_add_fieldcat USING :
'ID_KAB' 'ZKABUPATEN' 'ID_KAB' 'KD Kab.' 'KD Kab.' 'KD Kab.' '' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X',
'DES_KAB' 'ZKABUPATEN' 'DES_KAB' 'Deskripsi' 'Deskripsi' 'Deskripsi' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'KD_POS' 'ZKABUPATEN' 'KD_POS' 'KD POS' 'KD POS' 'KD POS' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.
ENDFORM. "fm_alv_set_column
*&--------------------------------------------------------------------*
*& Form FM_USER_COMMAND
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
*FORM fm_alv_user_command USING fu_ucomm LIKE sy-ucomm
* fu_selfield TYPE slis_selfield.
FORM fm_alv_user_command USING fu_ucomm LIKE sy-ucomm
fu_selfield TYPE slis_selfield.
DATA: lt_dynpread LIKE dynpread OCCURS 0 WITH HEADER LINE,
lv_ok_code LIKE sy-ucomm.
DATA: rspar_tab TYPE TABLE OF rsparams,
rspar_line LIKE LINE OF rspar_tab.
DATA: lv_dbcnt(10) VALUE '0'.
DATA: lv_tabix TYPE sy-tabix.
DATA: lv_messg(80).
DATA : count TYPE i,
gagal TYPE c LENGTH 255,
icount TYPE c LENGTH 4,
message_g TYPE c LENGTH 255,
message_s TYPE c LENGTH 255,
sukses TYPE c LENGTH 255.
MOVE fu_ucomm TO lv_ok_code.
CASE lv_ok_code.
WHEN '&IC1'.
* PERFORM fm_alv_event_double_click.
WHEN '&ETA'.
* PERFORM fm_alv_event_double_click.
WHEN '&F03' OR '&F15' OR '&F12'.
WHEN '&UPD'.
* BREAK-POINT.
clear t_repot[].
LOOP AT t_insert.
MODIFY zkabupaten FROM t_insert.
IF sy-subrc = 0.
move t_insert-id_kab to t_repot-id_kab.
move t_insert-des_kab to t_repot-des_kab.
move t_insert-kd_pos to t_repot-kd_pos.
move 'sukses' to t_repot-status.
move icon_green_light to t_repot-icon.
append t_repot.
else.
move t_insert-id_kab to t_repot-id_kab.
move t_insert-des_kab to t_repot-des_kab.
move t_insert-kd_pos to t_repot-kd_pos.
move 'gagal' to t_repot-status.
move icon_red_light to t_repot-icon.
append t_repot.
ENDIF.
ENDLOOP.
ENDCASE.
**
* MOVE 'X' TO fu_selfield-exit.
perform fm_display_report.
ENDFORM. "FM_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form FM_DISPLAY_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form FM_DISPLAY_REPORT .
PERFORM fm_alv_reset_data.
* Mengatur Parameter dan Data ALV
PERFORM fm_alv_set_layout USING 'Program Upload'.
PERFORM fm_alv_set_print.
PERFORM fm_alv_set_column2.
gv_i_default = 'X'.
gv_i_save = 'A'.
PERFORM fm_alv_show TABLES t_repot.
endform. " FM_DISPLAY_REPORT
*&---------------------------------------------------------------------*
*& Form FM_ALV_SET_COLUMN2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form FM_ALV_SET_COLUMN2 .
PERFORM fm_alv_add_fieldcat USING :
'ICON' '' '' '' '' 'Icon' '' '' '' '' '' '' '' '' '' '' '' '' 'X' 'X' 'X',
'ID_KAB' 'ZKABUPATEN' 'ID_KAB' 'KD Kab.' 'KD Kab.' 'KD Kab.' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'DES_KAB' 'ZKABUPATEN' 'DES_KAB' 'Deskripsi' 'Deskripsi' 'Deskripsi' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'KD_POS' 'ZKABUPATEN' 'KD_POS' 'KD POS' 'KD POS' 'KD POS' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '',
'STATUS' 'ZKABUPATEN' 'STATUS' 'Status' 'Status' 'Status' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''.
endform. " FM_ALV_SET_COLUMN2
13. Simpan lalu double klik pada " INCLUDE zupload_inc." untuk membuat include.
14. Pada program include tersebut ketikkan source code seperti berikut:
*&---------------------------------------------------------------------*
*& Include ZCFIRU0102_UPDT_ALV
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.
DATA : gw_is_layout TYPE slis_layout_alv,
gi_it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gi_it_excluding TYPE slis_t_extab WITH HEADER LINE,
gi_it_special_groups TYPE slis_t_sp_group_alv WITH HEADER LINE,
gi_it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE,
gi_it_filter TYPE slis_t_filter_alv WITH HEADER LINE,
gw_is_sel_hide TYPE slis_sel_hide_alv,
gv_i_default,
gv_i_save,
gw_is_variant LIKE disvariant,
gi_it_events TYPE slis_t_event WITH HEADER LINE,
gi_it_event_exit TYPE slis_t_event_exit WITH HEADER LINE,
gw_is_print TYPE slis_print_alv,
gw_is_reprep_id TYPE slis_reprep_id.
*&--------------------------------------------------------------------*
*& Form fm_alv_show
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FT_ITAB text
*---------------------------------------------------------------------*
FORM fm_alv_show TABLES ft_itab.
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_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
i_callback_pf_status_set = 'FM_ALV_SET_PF_STATUS'
i_callback_user_command = 'FM_ALV_USER_COMMAND'
* I_STRUCTURE_NAME =
is_layout = gw_is_layout
it_fieldcat = gi_it_fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
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_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = ft_itab
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "fm_alv_show
*&--------------------------------------------------------------------*
*& Form fm_alv_reset_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_reset_data.
CLEAR : gw_is_layout,
gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gw_is_sel_hide,
gv_i_default,
gv_i_save,
gw_is_variant,
gi_it_events,
gi_it_event_exit,
gw_is_print,
gw_is_reprep_id.
REFRESH : gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gi_it_events,
gi_it_event_exit.
ENDFORM. "fm_alv_reset_data
*&--------------------------------------------------------------------*
*& Form fm_alv_set_layout
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
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. "fm_alv_set_layout
*&--------------------------------------------------------------------*
*& Form fm_alv_set_print
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_set_print.
gw_is_print-no_print_listinfos = 'X'.
gw_is_print-no_print_selinfos = 'X'.
gw_is_print-no_coverpage = 'X'.
gw_is_print-no_print_hierseq_item = 'X'.
ENDFORM. "fm_alv_set_print
*&--------------------------------------------------------------------*
*& Form fm_alv_add_fieldcat
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FU_1 text
* -->FU_2 text
* -->FU_3 text
* -->FU_4 text
* -->FU_5 text
* -->FU_6 text
* -->FU_7 text
* -->FU_8 text
* -->FU_9 text
* -->FU_10 text
* -->FU_11 text
* -->FU_12 text
* -->FU_13 text
* -->FU_14 text
* -->FU_15 text
* -->FU_16 text
* -->FU_17 text
* -->FU_18 text
* -->FU_19 text
* -->FU_20 text
* -->FU_21 text
*---------------------------------------------------------------------*
FORM fm_alv_add_fieldcat USING 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-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. "fm_alv_add_fieldcat
*&--------------------------------------------------------------------*
*& Form FM_ALV_SET_PF_STATUS
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->RT_EXTAB text
*---------------------------------------------------------------------*
FORM fm_alv_set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTANDARD'.
ENDFORM. "fm_alv_set_pf_status
*& Include ZCFIRU0102_UPDT_ALV
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.
DATA : gw_is_layout TYPE slis_layout_alv,
gi_it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gi_it_excluding TYPE slis_t_extab WITH HEADER LINE,
gi_it_special_groups TYPE slis_t_sp_group_alv WITH HEADER LINE,
gi_it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE,
gi_it_filter TYPE slis_t_filter_alv WITH HEADER LINE,
gw_is_sel_hide TYPE slis_sel_hide_alv,
gv_i_default,
gv_i_save,
gw_is_variant LIKE disvariant,
gi_it_events TYPE slis_t_event WITH HEADER LINE,
gi_it_event_exit TYPE slis_t_event_exit WITH HEADER LINE,
gw_is_print TYPE slis_print_alv,
gw_is_reprep_id TYPE slis_reprep_id.
*&--------------------------------------------------------------------*
*& Form fm_alv_show
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FT_ITAB text
*---------------------------------------------------------------------*
FORM fm_alv_show TABLES ft_itab.
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_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
i_callback_pf_status_set = 'FM_ALV_SET_PF_STATUS'
i_callback_user_command = 'FM_ALV_USER_COMMAND'
* I_STRUCTURE_NAME =
is_layout = gw_is_layout
it_fieldcat = gi_it_fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
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_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = ft_itab
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "fm_alv_show
*&--------------------------------------------------------------------*
*& Form fm_alv_reset_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_reset_data.
CLEAR : gw_is_layout,
gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gw_is_sel_hide,
gv_i_default,
gv_i_save,
gw_is_variant,
gi_it_events,
gi_it_event_exit,
gw_is_print,
gw_is_reprep_id.
REFRESH : gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gi_it_events,
gi_it_event_exit.
ENDFORM. "fm_alv_reset_data
*&--------------------------------------------------------------------*
*& Form fm_alv_set_layout
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
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. "fm_alv_set_layout
*&--------------------------------------------------------------------*
*& Form fm_alv_set_print
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_set_print.
gw_is_print-no_print_listinfos = 'X'.
gw_is_print-no_print_selinfos = 'X'.
gw_is_print-no_coverpage = 'X'.
gw_is_print-no_print_hierseq_item = 'X'.
ENDFORM. "fm_alv_set_print
*&--------------------------------------------------------------------*
*& Form fm_alv_add_fieldcat
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FU_1 text
* -->FU_2 text
* -->FU_3 text
* -->FU_4 text
* -->FU_5 text
* -->FU_6 text
* -->FU_7 text
* -->FU_8 text
* -->FU_9 text
* -->FU_10 text
* -->FU_11 text
* -->FU_12 text
* -->FU_13 text
* -->FU_14 text
* -->FU_15 text
* -->FU_16 text
* -->FU_17 text
* -->FU_18 text
* -->FU_19 text
* -->FU_20 text
* -->FU_21 text
*---------------------------------------------------------------------*
FORM fm_alv_add_fieldcat USING 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-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. "fm_alv_add_fieldcat
*&--------------------------------------------------------------------*
*& Form FM_ALV_SET_PF_STATUS
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->RT_EXTAB text
*---------------------------------------------------------------------*
FORM fm_alv_set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTANDARD'.
ENDFORM. "fm_alv_set_pf_status
15. Simpan lalu kembali ke program utama lagi.
16. Activate semua progam.
18. Jalankan program abap yang kita buat tadi.
Tidak ada komentar:
Posting Komentar