------------------------------------------------------------------------
This code is to view internal table in ALV with dynamic internal table fields.
Step 1 : Create Main program
REPORT zuplbpjs MESSAGE-ID zhrmsg.
INCLUDE zuplbpjs_top. "Data Declaration
INCLUDE zuplbpjs_sel. "Selection Screen
INCLUDE zuplbpjs_xls. "Upload Excel Functions
INCLUDE zuplbpjs_alv. "Alv Functions
INCLUDE zuplbpjs_msg. "Show Message Function
INCLUDE zuplbpjs_f01. "Process Functions
INCLUDE zuplbpjs_main. "Main Include
Step 2 : Create zuplbpjs_top
TYPES:
BEGIN OF ty_data,
znomor TYPE char5,
znokk TYPE char20,
zkitas TYPE char20,
zname TYPE char20,
zp2ia TYPE char1,
ztplhr TYPE char20,
ztglhr TYPE char10,
zsex TYPE char1,
zstats TYPE char1,
zalm TYPE char40,
zrt TYPE char3,
zrw TYPE char3,
znopos TYPE char5,
zcdkec TYPE char10,
znmkec TYPE char20,
zcddes TYPE char10,
znmdes TYPE char20,
zcdfas TYPE char15,
znmfas TYPE char80,
zcdden TYPE char10,
znmden TYPE char20,
ztelp TYPE char20,
zemail TYPE char20,
zpernr TYPE char80,
zjabat TYPE char15,
zjobst TYPE char1,
zbecls TYPE char1,
ztmt TYPE char10,
zgaji TYPE char20,
znatio TYPE char1,
zpolis TYPE char20,
zoass TYPE char20,
znpwp TYPE char20,
zpassp TYPE char10,
zlevel TYPE char1,
zinfo TYPE char20,
zbpjsi TYPE char20,
znote TYPE string,
select TYPE c,
END OF ty_data.
TYPES: tt_data TYPE STANDARD TABLE OF ty_data.
DATA: t_data TYPE tt_data.
DATA: t_wa LIKE LINE OF t_data.
Step 3 : Create zuplbpjs_alv
*----------------------------------------------------------------------*
* INCLUDE ZUPLBPJS_F01 *
*----------------------------------------------------------------------*
*
TYPE-POOLS : slis.
DATA:ls_fieldcat TYPE slis_fieldcat_alv.
DATA:lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA:lt_layout TYPE slis_layout_alv.
DATA:lt_fields_text TYPE string.
DATA:lt_events TYPE slis_t_event.
CONSTANTS :
c_form_name_pf_status_set TYPE slis_formname VALUE 'F_PF_STATUS_SET',
c_form_name_user_command TYPE slis_formname VALUE 'F_USER_COMMAND',
c_form_name_top_of_page TYPE slis_formname VALUE 'F_TOP_OF_PAGE',
c_form_name_top_of_list TYPE slis_formname VALUE 'F_TOP_OF_LIST',
c_form_name_end_of_list TYPE slis_formname VALUE 'F_END_OF_LIST'.
TYPES: BEGIN OF ty_s_outtab,
text1(40).
TYPES: END OF ty_s_outtab.
*DATA: itext TYPE STANDARD TABLE OF ty_s_outtab.
DATA: itext TYPE ty_s_outtab OCCURS 0 WITH HEADER LINE.
*data: wtext like itext
DATA: n LIKE sy-tabix.
*
FORM displa_alv.
PERFORM build_catalog USING 'T_DATA'.
PERFORM build_event.
PERFORM build_layout.
PERFORM display_alv_report.
ENDFORM.
*
FORM build_event.
DATA: lv_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = lt_events.
* Form set pf status
READ TABLE lt_events WITH KEY name = slis_ev_pf_status_set
INTO lv_event.
IF sy-subrc = 0.
MOVE c_form_name_pf_status_set TO lv_event-form.
APPEND lv_event TO lt_events.
ENDIF.
* Form User Command
READ TABLE lt_events WITH KEY name = slis_ev_user_command
INTO lv_event.
IF sy-subrc = 0.
MOVE c_form_name_user_command TO lv_event-form.
APPEND lv_event TO lt_events.
ENDIF.
ENDFORM.
*
FORM f_pf_status_set USING ft_extab TYPE slis_t_extab.
SET PF-STATUS 'ZBPJS_ALV' OF PROGRAM gd_repid
EXCLUDING ft_extab.
ENDFORM.
*
FORM f_user_command USING fv_ucomm LIKE sy-ucomm
ft_selfield TYPE slis_selfield.
CASE fv_ucomm.
WHEN 'UPLOAD'.
PERFORM zprocess_upload.
PERFORM zshow_message.
WHEN 'MESSAGE'.
PERFORM zshow_message.
ENDCASE.
ENDFORM.
*
FORM build_catalog USING p_itabname.
DATA: l_tabledescr_ref TYPE REF TO cl_abap_tabledescr,
l_descr_ref TYPE REF TO cl_abap_structdescr,
wa_table TYPE abap_compdescr.
DATA: fl_table LIKE wa_table OCCURS 0 WITH HEADER LINE.
* read Text Field
CONCATENATE text-100 text-101 text-102 text-103 text-104
text-105 text-106 INTO lt_fields_text.
SPLIT lt_fields_text AT ',' INTO TABLE itext.
* read fields internal table
l_tabledescr_ref ?= cl_abap_typedescr=>describe_by_data( t_data ).
l_descr_ref ?= l_tabledescr_ref->get_table_line_type( ).
LOOP AT l_descr_ref->components INTO wa_table .
n = sy-tabix.
READ TABLE itext INDEX n.
IF sy-subrc EQ 0.
CLEAR ls_fieldcat.
ls_fieldcat-row_pos = '1'.
ls_fieldcat-col_pos = n.
ls_fieldcat-fieldname = wa_table-name.
ls_fieldcat-tabname = p_itabname.
ls_fieldcat-seltext_m = itext-text1.
APPEND ls_fieldcat TO lt_fieldcat.
ENDIF.
ENDLOOP.
ENDFORM.
*
FORM build_layout.
lt_layout-colwidth_optimize = 'X'.
lt_layout-zebra = 'X'.
lt_layout-box_fieldname = 'SELECT'.
ENDFORM. " BUILD_LAYOUT
*
FORM display_alv_report.
* Display data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_grid_title = 'Excell Data'
is_layout = lt_layout
it_fieldcat = lt_fieldcat[]
i_save = 'X'
it_events = lt_events[]
* i_screen_start_column = 10
* i_screen_start_line = 5
* i_screen_end_column = 100
* i_screen_end_line = 15
TABLES
t_outtab = t_data
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. " DISPLAY_ALV_REPORT
Step 4 : to Show the ALV create ZUPLBPJS_MAIN
*----------------------------------------------------------------------*
* INCLUDE ZUPLBPJS_MAIN *
*----------------------------------------------------------------------*
INITIALIZATION.
PERFORM set_period.
gd_repid = sy-repid.
START-OF-SELECTION.
LOOP AT filename_table INTO filename.
PERFORM flcl_excel_uploader
TABLES t_data USING hrow filename.
ENDLOOP.
END-OF-SELECTION.
PERFORM displa_alv.
No comments:
Post a Comment