*&---------------------------------------------------------------------*
*& 모듈풀 ZCBO *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
INCLUDE zCBOtop.
INCLUDE zCBOf01.
INITIALIZATION.
CLEAR: gp_tabnm.
START-OF-SELECTION.
IF gp_tabnm(1) <> 'Z'.
MESSAGE s001 WITH 'CBO테이블만 작업 가능합니다.'.
EXIT.
ENDIF.
PERFORM check_exist_for_table USING gv_tabnm.
IF gv_tabnm IS INITIAL.
MESSAGE s001 WITH '존재하지 않는 테이블 입니다.'.
EXIT.
ENDIF.
PERFORM read_stucture_of_table.
PERFORM upload_data_from_excel.
*----------------------------------------------------------------------*
* INCLUDE ZCBOTOP
*----------------------------------------------------------------------*
REPORT zCBO MESSAGE-ID zpp1.
DATA: gv_tabnm TYPE char30.
DATA: gt_ref TYPE REF TO data,
gt_fcat TYPE lvc_t_fcat,
gt_fldcat LIKE lvc_s_fcat OCCURS 0 WITH HEADER LINE.
DATA: gw_data TYPE REF TO data.
FIELD-SYMBOLS: <data> TYPE table.
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-000.
PARAMETERS: gp_tabnm TYPE char30 OBLIGATORY.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-001.
SELECTION-SCREEN POSITION 33.
PARAMETERS: p_r01 RADIOBUTTON GROUP r0.
SELECTION-SCREEN COMMENT 35(15) text-002 FOR FIELD p_r01.
SELECTION-SCREEN POSITION 52.
PARAMETERS: p_r02 RADIOBUTTON GROUP r0.
SELECTION-SCREEN COMMENT 53(18) text-003 FOR FIELD p_r02.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK blk.
*----------------------------------------------------------------------*
* INCLUDE ZCBOF01 *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form check_exist_for_table
*&---------------------------------------------------------------------*
FORM check_exist_for_table USING p_tabnm.
SELECT SINGLE tabname
INTO p_tabnm
FROM dd02l
WHERE tabname = gp_tabnm.
ENDFORM. " check_exist_for_table
*&---------------------------------------------------------------------*
*& Form read_stucture_of_table
*&---------------------------------------------------------------------*
FORM read_stucture_of_table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = gp_tabnm
CHANGING
ct_fieldcat = gt_fcat.
IF sy-subrc <> 0.
MESSAGE e000 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fcat
IMPORTING
ep_table = gt_ref.
ASSIGN gt_ref->* TO <data>.
ENDFORM. " read_stucture_of_table
*&---------------------------------------------------------------------*
*& Form upload_data_from_excel
*&---------------------------------------------------------------------*
FORM upload_data_from_excel.
DATA: lv_filenm TYPE rlgrap-filename.
lv_filenm = 'C:'.
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = lv_filenm
filetype = 'DAT'
TABLES
data_tab = <data>
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
IF sy-subrc = 1.
MESSAGE s001 WITH 'Data conversion 오류.'.
RETURN.
ELSEIF sy-subrc > 1.
MESSAGE s001 WITH '기타 오류.'.
RETURN.
ENDIF.
IF <data>[] IS INITIAL.
EXIT.
ENDIF.
IF p_r01 = 'X'. " 추가/수정
MODIFY (gp_tabnm) FROM TABLE <data>.
ELSE.
DELETE (gp_tabnm) FROM TABLE <data>.
ENDIF.
COMMIT WORK.
MESSAGE s010.
ENDFORM. " upload_data_from_excel
*& 모듈풀 ZCBO *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
INCLUDE zCBOtop.
INCLUDE zCBOf01.
INITIALIZATION.
CLEAR: gp_tabnm.
START-OF-SELECTION.
IF gp_tabnm(1) <> 'Z'.
MESSAGE s001 WITH 'CBO테이블만 작업 가능합니다.'.
EXIT.
ENDIF.
PERFORM check_exist_for_table USING gv_tabnm.
IF gv_tabnm IS INITIAL.
MESSAGE s001 WITH '존재하지 않는 테이블 입니다.'.
EXIT.
ENDIF.
PERFORM read_stucture_of_table.
PERFORM upload_data_from_excel.
*----------------------------------------------------------------------*
* INCLUDE ZCBOTOP
*----------------------------------------------------------------------*
REPORT zCBO MESSAGE-ID zpp1.
DATA: gv_tabnm TYPE char30.
DATA: gt_ref TYPE REF TO data,
gt_fcat TYPE lvc_t_fcat,
gt_fldcat LIKE lvc_s_fcat OCCURS 0 WITH HEADER LINE.
DATA: gw_data TYPE REF TO data.
FIELD-SYMBOLS: <data> TYPE table.
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-000.
PARAMETERS: gp_tabnm TYPE char30 OBLIGATORY.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-001.
SELECTION-SCREEN POSITION 33.
PARAMETERS: p_r01 RADIOBUTTON GROUP r0.
SELECTION-SCREEN COMMENT 35(15) text-002 FOR FIELD p_r01.
SELECTION-SCREEN POSITION 52.
PARAMETERS: p_r02 RADIOBUTTON GROUP r0.
SELECTION-SCREEN COMMENT 53(18) text-003 FOR FIELD p_r02.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK blk.
*----------------------------------------------------------------------*
* INCLUDE ZCBOF01 *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form check_exist_for_table
*&---------------------------------------------------------------------*
FORM check_exist_for_table USING p_tabnm.
SELECT SINGLE tabname
INTO p_tabnm
FROM dd02l
WHERE tabname = gp_tabnm.
ENDFORM. " check_exist_for_table
*&---------------------------------------------------------------------*
*& Form read_stucture_of_table
*&---------------------------------------------------------------------*
FORM read_stucture_of_table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = gp_tabnm
CHANGING
ct_fieldcat = gt_fcat.
IF sy-subrc <> 0.
MESSAGE e000 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fcat
IMPORTING
ep_table = gt_ref.
ASSIGN gt_ref->* TO <data>.
ENDFORM. " read_stucture_of_table
*&---------------------------------------------------------------------*
*& Form upload_data_from_excel
*&---------------------------------------------------------------------*
FORM upload_data_from_excel.
DATA: lv_filenm TYPE rlgrap-filename.
lv_filenm = 'C:'.
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = lv_filenm
filetype = 'DAT'
TABLES
data_tab = <data>
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
IF sy-subrc = 1.
MESSAGE s001 WITH 'Data conversion 오류.'.
RETURN.
ELSEIF sy-subrc > 1.
MESSAGE s001 WITH '기타 오류.'.
RETURN.
ENDIF.
IF <data>[] IS INITIAL.
EXIT.
ENDIF.
IF p_r01 = 'X'. " 추가/수정
MODIFY (gp_tabnm) FROM TABLE <data>.
ELSE.
DELETE (gp_tabnm) FROM TABLE <data>.
ENDIF.
COMMIT WORK.
MESSAGE s010.
ENDFORM. " upload_data_from_excel