2018년 10월 30일 화요일

템플릿 - Z_COMMON

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

*&  Include           ZFI_COMMON

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

********************************************************

* 공통변수

********************************************************

TABLES: bdcmsgcoll, "* Collecting messages in the SAP System

        alsmex_tabline,   "* Rows for Table with Excel Data

        tbtco,            "* Job status overview table

        rfcdoc,

        rfcdes,

        dbcon,

        stxh.

TYPE-POOLS: kcde, vrm, icon, scp1, gseth, slis.



" Progress bar Message

DATA : gv_calc_i TYPE i. "* %

DATA : gv_progress_msg(100).           "* Display

DATA : gv_calc_c0(5).

DATA : gv_calc_c1(5).



" group select

DATA : gv_value_set TYPE gseth_val_line.

DATA : gt_value_set TYPE gseth_val_tab.



DATA : gt_detmsg TYPE TABLE OF scp1_general_error.

DATA : gt_heamsg TYPE TABLE OF scp1_general_error.



"도메인 가져오기

DATA : BEGIN OF gs_domain,

         domain LIKE dd07t-domname,

         value  LIKE dd07t-domvalue_l,

         ddtext LIKE dd07t-ddtext,

       END OF gs_domain.

DATA : gt_domain LIKE TABLE OF gs_domain.



" 엑셀 내보내기용

TYPES : BEGIN OF t_excel_export,

          excel_col TYPE string,

        END OF   t_excel_export.



DATA : gt_excel_export TYPE t_excel_export OCCURS 0 WITH HEADER LINE.



" 조회 권한

*-- 'X'일때에는 조회만 가능

DATA : gv_dip_mod     TYPE c.



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

* Company Code 정보.

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

DATA : gv_butxt_cm TYPE t001-butxt VALUE ''.
DATA : gv_kokrs_txt TYPE tkt09-txt VALUE ''.
DATA : gv_waers_cm TYPE t001-waers VALUE ''.
DATA : gv_ktopl_cm TYPE t001-ktopl VALUE ''.
DATA : gv_spras_cm TYPE t001-spras VALUE ''. " KO
DATA : gv_land1_cm TYPE t001-land1 VALUE ''.
DATA : gv_kbezei_cm LIKE tka01-bezei VALUE ''. "

*-----------------------------------------------
* BDC DEFINITION
* ----------------------------------------------
DATA: gs_bdc_option TYPE ctu_params.
DATA: gt_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: gt_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

****************************************
* POSTING_INTERFACE_DOCUMENT.
****************************************
DATA : ftpost LIKE ftpost  OCCURS 0  WITH HEADER LINE.
DATA : fttax  LIKE fttax   OCCURS 0  WITH HEADER LINE.
DATA : blntab LIKE blntab  OCCURS 0  WITH HEADER LINE.
DATA : gv_ftpost_type TYPE c.
DATA : gv_ftpost_cnt TYPE i.
DATA : gv_ftpost_waers LIKE t001-waers.

DATA : BEGIN OF gt_if_msg OCCURS 0,
         msgid   LIKE sy-msgid,
         msgno   LIKE sy-msgno,
         msgty   LIKE sy-msgty,
         msgv1   LIKE sy-msgv1,
         msgv2   LIKE sy-msgv2,
         msgv3   LIKE sy-msgv3,
         msgv4   LIKE sy-msgv4,
         subrc   LIKE sy-subrc,
         message LIKE bdcmsgcoll-msgv1,
       END OF gt_if_msg.

****************************************

" 값이 없으면 BDC를 태우지 않음.

DATA : BEGIN OF gt_excp_init_field OCCURS 0,

         fname TYPE fnam_____4,

       END OF gt_excp_init_field.



********************************************************

* 매크로

********************************************************
*-----------------------------------------------
* MACRO DEFINITION
* ----------------------------------------------
"SETNODE 내역을 RANGE 변수에 INSERT.
DEFINE macro_value_to_range.

  CLEAR : gv_value_set.
  CLEAR : &1. REFRESH : &1.

  LOOP AT &2 INTO gv_value_set.
    &1-low = gv_value_set-vfrom.
    &1-sign = 'I'.

    IF gv_value_set-vfrom NE gv_value_set-vto.
      &1-option = 'BT'.
      &1-high = gv_value_set-vto.
    ELSE.
      &1-option = 'EQ'.
    ENDIF.

    APPEND &1.
    CLEAR : &1.
  ENDLOOP.

  CLEAR : &2. REFRESH : &2.

END-OF-DEFINITION.

DEFINE add_range_eq.

  IF &2 NE space.
    CLEAR &1.
    &1-sign = 'I'.
    &1-option = 'EQ'.
    &1-low = &2.
    APPEND &1.
  ENDIF.

END-OF-DEFINITION.

DEFINE add_range_full.

  CLEAR &1.
  &1-sign = &2.
  &1-option = &3.
  &1-low = &4.
  &1-high = &5.
  APPEND &1.

END-OF-DEFINITION.

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

*&      Form  ADD_EXCP_FIELD_WHEN_INITIAL

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

*       text

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

*      -->P_FIELD    text

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

FORM add_excp_field_when_initial USING p_field.

  DATA : l_excp_field LIKE LINE OF gt_excp_init_field.

  CLEAR : l_excp_field.

  l_excp_field-fname = p_field.

  APPEND l_excp_field TO gt_excp_init_field.

ENDFORM.                    "ADD_EXCP_FIELD_WHEN_INITIAL

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

*&      Form  GET_INFO_LIKE_ITAB

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

*       text

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

*      -->PT_REF_FCAT  text

*      -->P_ITAB_NAME  text

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

FORM get_fcat_like_itab

         TABLES pt_ref_fcat STRUCTURE lvc_s_fcat

         USING p_itab_name TYPE dd03l-tabname.



  DATA : lt_table LIKE dd02l-tabname OCCURS 0 WITH HEADER LINE.

  DATA : lt_fieldcat   TYPE slis_t_fieldcat_alv.

  DATA : lt_alv_cat   TYPE TABLE OF lvc_s_fcat.



  CLEAR : lt_table, lt_table[].

  CLEAR : lt_fieldcat, lt_fieldcat[].

  CLEAR : lt_alv_cat, lt_alv_cat[].



  "Internal Table 데이터 구성-> Fieldcat mege로 부터

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

      i_program_name         = sy-repid

      i_internal_tabname     = p_itab_name

      i_inclname             = sy-repid

      i_structure_name       = ''

      i_bypassing_buffer     = 'X'

    CHANGING

      ct_fieldcat            = lt_fieldcat[]

    EXCEPTIONS

      inconsistent_interface = 1

      program_error          = 2.



  CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'

    EXPORTING

      it_fieldcat_alv = lt_fieldcat

    IMPORTING

      et_fieldcat_lvc = lt_alv_cat

    TABLES

      it_data         = lt_table[].



  CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'

    CHANGING

      ct_fieldcat = lt_alv_cat.



  pt_ref_fcat[] = lt_alv_cat[].

  CLEAR : lt_alv_cat, lt_alv_cat[].



ENDFORM.                    " GET_DD03_FCAT

*&---------------------------------------------------------------------*
*&      Form  SET_COMPANY_BASE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_company_base USING p_bukrs.

  DATA : l_t001 LIKE t001.

  CLEAR : l_t001.

  SELECT SINGLE *
    FROM t001
    INTO l_t001
    WHERE bukrs = p_bukrs.
  IF sy-subrc EQ 0.
    gv_waers_cm = l_t001-waers.
    gv_ktopl_cm = l_t001-ktopl.
    gv_spras_cm = l_t001-spras.
    gv_butxt_cm = l_t001-butxt.
    gv_land1_cm = l_t001-land1.
  ENDIF.

ENDFORM.                    " SET_COMPANY_BASE

*PERFORM GET_SETLEAF_VALUES USING
*           'BUDGET' '0102'. =>1. GT_VALUE_SET에 값이 담김.
*  MACRO_VALUE_TO_RANGE : => 2. 넘겨준 RANGE 변수에 값이 담김
*      GR_BUDGET_KSTAR => 로컬 변수
*      GT_VALUE_SET. => 매크로 이후 메모리에서 제거됨.

FORM get_setleaf_values
  USING p_kokrs p_setname TYPE any
   pv_class TYPE sethier-setclass.

  DATA : lt_node TYPE gseth_node_tab.
  DATA : l_class TYPE sethier-setclass.
  DATA : l_setid TYPE sethier-setid.
  DATA : lt_grphinfo TYPE grphinfo OCCURS 0 WITH HEADER LINE.
  DATA : l_message TYPE string.


  CLEAR : lt_node, lt_node[].
  CLEAR : l_class, l_setid.
  CLEAR : lt_grphinfo, lt_grphinfo[].
  CLEAR : gt_value_set, gt_value_set[].
  CLEAR : l_message.

  l_class = pv_class.

  CASE pv_class.
    WHEN '0101'. " 코스트센터
      CONCATENATE pv_class p_kokrs p_setname INTO l_setid.
    WHEN '0102'. " 원가요소
      CONCATENATE pv_class gv_ktopl_cm p_setname INTO l_setid.
    WHEN '0103'. " 오더
*      CONCATENATE PV_CLASS GC_KOKRS P_SETNAME INTO L_SETID.
      CONCATENATE pv_class p_setname INTO l_setid. " New GL/Segment
    WHEN '0106'. " 손익센터
      CONCATENATE pv_class p_kokrs p_setname INTO l_setid.
    WHEN '0109'. " 계정과목
      CONCATENATE pv_class gv_ktopl_cm p_setname INTO l_setid.
  ENDCASE.

  CALL FUNCTION 'K_HIERARCHY_TABLES_READ'
    EXPORTING
      e_class                     = l_class
      e_setid                     = l_setid
      e_kokrs                     = p_kokrs
      e_mandt                     = sy-mandt
    TABLES
      t_nodes                     = lt_node
      t_values                    = gt_value_set
    CHANGING
      c_info                      = lt_grphinfo
      c_overwrite                 = sy-datar
    EXCEPTIONS
      no_controlling_area         = 1
      no_chart_of_account         = 2
      different_controlling_areas = 3
      different_chart_of_accounts = 4
      set_not_found               = 5
      illegal_field_replacement   = 6
      illegal_table_replacement   = 7
      fm_raise                    = 8
      convert_error               = 9
      no_overwrite_standard_hier  = 10
      no_bukrs_for_kokrs          = 11
      OTHERS                      = 12.
  IF sy-subrc <> 0.
*    MESSAGE ID 'GS' TYPE 'E' NUMBER '004'
*         WITH P_SETNAME INTO L_MESSAGE.
*    MESSAGE S000(ZCOM1) DISPLAY LIKE 'E' WITH L_MESSAGE.
*    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    "GET_SET_VALUES



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

*&      Form  DYNPRO

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

*       text

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

*      -->PT_BDCTAB    text

*      -->PV_DYNBEGIN  text

*      -->PV_INPUT     text

*      -->PV_VALUE     text

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

FORM dynpro TABLES pt_bdctab

  USING pv_dynbegin pv_input pv_value.

  DATA : ls_bdctab TYPE bdcdata.



  CLEAR : ls_bdctab.



  IF pv_dynbegin = 'X'.

    WRITE : pv_input TO ls_bdctab-program LEFT-JUSTIFIED.

    WRITE : pv_value TO ls_bdctab-dynpro LEFT-JUSTIFIED.

    WRITE : 'X' TO ls_bdctab-dynbegin LEFT-JUSTIFIED.



    APPEND ls_bdctab TO pt_bdctab.

  ELSE.

    READ TABLE gt_excp_init_field TRANSPORTING NO FIELDS

      WITH KEY fname = pv_input BINARY SEARCH.



    IF sy-subrc EQ 0 AND pv_value IS INITIAL.

      EXIT.

    ENDIF.



    WRITE : pv_input TO ls_bdctab-fnam LEFT-JUSTIFIED.

    WRITE : pv_value TO ls_bdctab-fval LEFT-JUSTIFIED.



    APPEND ls_bdctab TO pt_bdctab.

  ENDIF.



ENDFORM.                    "SET_DYNPRO



*ZCOC9060 업데이트용 BDC

FORM dynpro_update TABLES pt_bdctab

  USING pv_dynbegin pv_input pv_value.

  DATA : ls_bdctab TYPE bdcdata.

  DATA : string_type(4) TYPE c.



  CLEAR : ls_bdctab.



  IF pv_dynbegin = 'X'.

    WRITE : pv_input TO ls_bdctab-program LEFT-JUSTIFIED.

    WRITE : pv_value TO ls_bdctab-dynpro LEFT-JUSTIFIED.

    WRITE : 'X' TO ls_bdctab-dynbegin LEFT-JUSTIFIED.



    APPEND ls_bdctab TO pt_bdctab.

  ELSE.

*    READ TABLE GT_EXCP_INIT_FIELD TRANSPORTING NO FIELDS

*      WITH KEY FNAME = PV_INPUT BINARY SEARCH.





    IF pv_value IS INITIAL.

      EXIT.

    ENDIF.



    CALL FUNCTION 'NUMERIC_CHECK'

      EXPORTING

        string_in = pv_value

      IMPORTING

        htype     = string_type.



    IF string_type = 'CHAR'.

      IF pv_value = '@'.

        WRITE : pv_input TO ls_bdctab-fnam LEFT-JUSTIFIED.

        WRITE : '' TO ls_bdctab-fval LEFT-JUSTIFIED.

        APPEND ls_bdctab TO pt_bdctab.

        EXIT.

      ENDIF.

    ENDIF.



    WRITE : pv_input TO ls_bdctab-fnam LEFT-JUSTIFIED.

    WRITE : pv_value TO ls_bdctab-fval LEFT-JUSTIFIED.



    APPEND ls_bdctab TO pt_bdctab.

  ENDIF.



ENDFORM.                    "SET_DYNPRO



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

*&      Form  SET_BDC_OPTION

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

*       text

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

*      -->PV_DEFSIZE     text

*      -->PV_UPDMODE     text

*      -->PV_CATTMODE    text

*      -->PV_DISMODE     text

*      -->PV_RACCOMMIT   text

*      -->PV_NOBINPT     text

*      -->PS_CTU_PARAMS  text

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

FORM set_bdc_option

   USING pv_defsize

                pv_updmode

            pv_cattmode

        pv_dismode

        pv_raccommit

        pv_nobinpt

  CHANGING ps_ctu_params STRUCTURE ctu_params.



  ps_ctu_params-defsize = pv_defsize.

  ps_ctu_params-updmode = pv_updmode.

  ps_ctu_params-cattmode = pv_cattmode.

  ps_ctu_params-dismode = pv_dismode.

  ps_ctu_params-racommit = pv_raccommit.

  ps_ctu_params-nobinpt = pv_nobinpt.

  ps_ctu_params-defsize = pv_defsize.



ENDFORM.                    "SET_BDC_OPTION

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

*&      Form  ZERO_O

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

*       text

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

*      -->P_IN       text

*      -->P_OUT      text

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

FORM zero_o USING p_in p_out.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

    EXPORTING

      input  = p_in

    IMPORTING

      output = p_out.

ENDFORM.                    "ZERO_O

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

*&      Form  ZERO_I

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

*       text

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

*      -->P_IN       text

*      -->P_OUT      text

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

FORM zero_i USING p_in p_out.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

    EXPORTING

      input  = p_in

    IMPORTING

      output = p_out.

ENDFORM.                    "ZERO_I



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

*&      Form  BAR_MSG

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

*       text

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

*      -->P_PER         text

*      -->VALUE(P_MSG)  text

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

FORM bar_msg USING p_per TYPE i VALUE(p_msg).

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

    EXPORTING

      percentage = p_per

      text       = p_msg.

ENDFORM.                    "BAR_MSG



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

*&      Form  BAR_MSG_PER

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

*       text

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

*      -->P_TEXT     text

*      -->P_CNT1     text

*      -->P_CNT2     text

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

" P_CNT1 : 현재 COUNT

" P_CNT2 : 총 COUNT

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

*&      Form  BAR_MSG_PER

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

*       text

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

*      -->P_TEXT     text

*      -->P_CNT1     text

*      -->P_CNT2     text

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

FORM bar_msg_per USING p_text p_cnt1 p_cnt2.

  DATA : l_ncnt1(5) TYPE n.

  DATA : l_ncnt2(5) TYPE n.



  CLEAR : l_ncnt1, l_ncnt2.



  l_ncnt1 = p_cnt1.

  l_ncnt2 = p_cnt2.



  gv_calc_i   = p_cnt1 * 100 / p_cnt2.

  gv_calc_c0  = gv_calc_i.



  IF l_ncnt1 IS INITIAL AND l_ncnt2 IS INITIAL.

    gv_progress_msg = p_text.

  ELSE.

    CONCATENATE p_text '(' gv_calc_c0 '% )'

           INTO gv_progress_msg SEPARATED BY space.

    CONDENSE gv_progress_msg.

  ENDIF.



  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

    EXPORTING

      percentage = gv_calc_i

      text       = gv_progress_msg.

ENDFORM. " process_bar



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

*&      Form  DISPLAY_SPOOL_BY_SALV

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

*       text

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

*      -->PT_TABLE   text

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

*FORM DISPLAY_SPOOL_BY_SALV TABLES PT_TABLE.

*  DATA : GR_TABLE TYPE REF TO CL_SALV_TABLE.

**  SORT GT_DISPLAY.

*  CL_SALV_TABLE=>FACTORY(

*    IMPORTING

*    R_SALV_TABLE = GR_TABLE

*  CHANGING

*    T_TABLE = PT_TABLE[] ).

*

*  GR_TABLE->DISPLAY( ).

*ENDFORM.                    "DISPLAY_SPOOL_BY_SALV



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

*&      Form  SET_FRONT_MINUS

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

*       text

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

*      -->P_NUM      text

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

FORM set_minus_front CHANGING p_num.



  CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'

    CHANGING

      value = p_num.



ENDFORM.                    " SET_FRONT_MINUS

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

*&      Form  F4_FNAME

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

*       text

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

*      -->P_NAME     text

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

FORM f4_fname CHANGING p_name.

  DATA: file_table TYPE filetable,

        rc         TYPE i,

        filedat    TYPE string.



  CALL METHOD cl_gui_frontend_services=>file_open_dialog

    EXPORTING

      default_filename  = space

      initial_directory = 'C:\'

    CHANGING

      file_table        = file_table

      rc                = rc

    EXCEPTIONS

      OTHERS            = 1.



  IF sy-subrc <> 0.

    EXIT.

  ENDIF.



  READ  TABLE  file_table INDEX 1 INTO filedat.



  CHECK NOT filedat IS INITIAL.

  p_name = filedat.



ENDFORM.                    " FILE_UPLOAD

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

*&      Form  UPLOAD_DATA

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

*       text

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

*      -->PT_EXCEL_TABLE     text

*      -->PS_EXCEL_STRUC     text

*      -->PV_EXCEL_FILENAME  text

*      -->PV_BEGIN_COL       text

*      -->PV_BEGIN_ROW       text

*      -->PV_END_COL         text

*      -->PV_END_ROW         text

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

FORM upload_data USING pt_excel_table

                       ps_excel_struc

                       pv_excel_filename

                       pv_begin_col TYPE i

                       pv_begin_row TYPE i

                       pv_end_col   TYPE i

                       pv_end_row   TYPE i.



  DATA : lt_intern LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.

  FIELD-SYMBOLS : <l_fs01>,

                  <l_fs02> TYPE STANDARD TABLE,

                  <l_fs03>.

  ASSIGN: (pt_excel_table) TO <l_fs02>,

          (ps_excel_struc) TO <l_fs03>.



  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

      filename                = pv_excel_filename

      i_begin_col             = pv_begin_col

      i_begin_row             = pv_begin_row

      i_end_col               = pv_end_col

      i_end_row               = pv_end_row

    TABLES

      intern                  = lt_intern

    EXCEPTIONS

      inconsistent_parameters = 1

      upload_ole              = 2

      OTHERS                  = 3.



  IF sy-subrc <> 0.

    IF sy-msgid IS INITIAL.

      MESSAGE i000 WITH 'No Selected File Exists or Too Long File path'.

      LEAVE LIST-PROCESSING.

    ELSE.

      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

  ENDIF.



  LOOP AT lt_intern.

    AT NEW row.

      CLEAR : <l_fs03>.

    ENDAT.



    ASSIGN COMPONENT lt_intern-col OF STRUCTURE <l_fs03> TO <l_fs01>.



    IF lt_intern-value CO '0123456789,.- '.

      REPLACE ALL OCCURRENCES OF ',' IN lt_intern-value WITH ''.

    ENDIF.



    MOVE lt_intern-value TO <l_fs01>.



    AT END OF row.

      APPEND <l_fs03> TO <l_fs02>.

    ENDAT.

  ENDLOOP.



ENDFORM.                    " UPLOAD_DATA



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

*&      Form  BDC_DATE

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

*       text

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

*      -->P_DATE     text

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

FORM bdc_date  CHANGING p_date.



  REPLACE ALL OCCURRENCES OF '.' IN p_date WITH ''.

  REPLACE ALL OCCURRENCES OF '-' IN p_date WITH ''.

  REPLACE ALL OCCURRENCES OF '/' IN p_date WITH ''.



ENDFORM.                    " CONVERT_TO_SAP_DATE



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

*&      Form  BDC_CURR

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

*       text

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

*      -->P_DMBTR    text

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

FORM bdc_curr  CHANGING p_dmbtr.



  REPLACE ALL OCCURRENCES OF ',' IN p_dmbtr WITH ''.



ENDFORM.                    " CONVERT_TO_DMBTR



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

*&      Form  BDC_CHECKBOX

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

*       text

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

*      -->P_VALUE    text

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

FORM bdc_checkbox  USING p_value.

  TRANSLATE p_value TO UPPER CASE.

ENDFORM.                    " BDC_CHECKBOX



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

*&      Form  BUILD_MESSAGE

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

*       text

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

*      -->PS_MESSAGE text

*      -->PV_TEXT    text

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

FORM build_message USING    ps_message STRUCTURE bdcmsgcoll

                   CHANGING pv_text.



  CLEAR pv_text.



  CALL FUNCTION 'MESSAGE_TEXT_BUILD'

    EXPORTING

      msgid               = ps_message-msgid

      msgnr               = ps_message-msgnr

      msgv1               = ps_message-msgv1

      msgv2               = ps_message-msgv2

      msgv3               = ps_message-msgv3

      msgv4               = ps_message-msgv4

    IMPORTING

      message_text_output = pv_text.



  REPLACE ALL OCCURRENCES OF '&' IN pv_text WITH ''.



*  CONCATENATE PS_MESSAGE-FLDNAME  PV_TEXT

*     INTO PV_TEXT SEPARATED BY SPACE.



ENDFORM.                    " MESSAGE_BUILD



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

*&      Form  BUILD_MESSAGE_BAPI

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

*       text

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

*      -->PS_MESSAGE text

*      -->PV_TEXT    text

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

FORM build_message_bapi USING ps_message STRUCTURE bapiret2

                   CHANGING pv_text.



  CLEAR pv_text.



  CALL FUNCTION 'MESSAGE_TEXT_BUILD'

    EXPORTING

      msgid               = ps_message-id

      msgnr               = ps_message-number

      msgv1               = ps_message-message_v1

      msgv2               = ps_message-message_v2

      msgv3               = ps_message-message_v3

      msgv4               = ps_message-message_v4

    IMPORTING

      message_text_output = pv_text.



  REPLACE ALL OCCURRENCES OF '&' IN pv_text WITH ''.



*  CONCATENATE PS_MESSAGE-FLDNAME  PV_TEXT

*     INTO PV_TEXT SEPARATED BY SPACE.



ENDFORM.                    " MESSAGE_BUILD



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

*&      Form  EXCEL_FORM_DOWNLOAD

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

*       text0

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

FORM excel_form_download TABLES pt_excel_export

     STRUCTURE gt_excel_export.

  DATA : lt_fcat TYPE TABLE OF lvc_s_fcat.

  DATA : ls_fcat TYPE lvc_s_fcat.

  DATA : l_cnt(2) TYPE n VALUE '01'.

  DATA : l_colname(20) TYPE c.

  DATA : l_size TYPE i.

  DATA : lf_data TYPE REF TO data.

  DATA : ll_data TYPE REF TO data.

  DATA : l_usr_act TYPE i.

  DATA : l_file_len TYPE i.

  DATA : l_fname TYPE string.

  DATA : l_ext_filename TYPE string.

  DATA : l_fullpath TYPE string.

  DATA : l_path TYPE string.



  FIELD-SYMBOLS : <fs_table> TYPE STANDARD TABLE.

  FIELD-SYMBOLS : <fs_line> TYPE any.

  FIELD-SYMBOLS : <fs_col> TYPE any.



  DEFINE add_excel_col.

    CLEAR : l_colname.

    l_size = strlen( &1 ) + 2.



    CONCATENATE 'COL' l_cnt INTO l_colname.

    ls_fcat-fieldname = l_colname.

    ls_fcat-col_pos = l_cnt.

    ls_fcat-coltext = &1.

    ls_fcat-inttype = 'C'.

    ls_fcat-intlen = l_size.

    APPEND ls_fcat TO lt_fcat.



    l_cnt = l_cnt + 1.

    CLEAR : ls_fcat, l_colname.

    CLEAR : l_size.

  END-OF-DEFINITION.



  CLEAR : l_fname, l_ext_filename, l_fullpath, l_path.

  CLEAR : l_usr_act, l_file_len.

  CLEAR : lt_fcat, lt_fcat[].

  CLEAR : ls_fcat.



  CHECK pt_excel_export[] IS NOT INITIAL.



  LOOP AT pt_excel_export.

    add_excel_col :   pt_excel_export-excel_col.

  ENDLOOP.



  " 동적 테이블 생성

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

      it_fieldcatalog = lt_fcat

    IMPORTING

      ep_table        = lf_data.



  ASSIGN lf_data->* TO <fs_table>.



  " 테이블 라인 생성

  CREATE DATA ll_data LIKE LINE OF <fs_table>.

  ASSIGN ll_data->* TO <fs_line>.



  " 템플릿 내용 단 한라인만 등록

  LOOP AT lt_fcat INTO ls_fcat.

    ASSIGN COMPONENT ls_fcat-col_pos

       OF STRUCTURE <fs_line> TO <fs_col>.



    IF sy-subrc EQ 0.

      <fs_col> = ls_fcat-coltext. " COLTEXT 의 내용을 그대로.

    ENDIF.

  ENDLOOP.



  " 테이블에 담기.

  APPEND <fs_line> TO <fs_table>.



  CHECK <fs_table> IS NOT INITIAL.



  CONCATENATE sy-repid '_UploadForm.xls' INTO l_fname.



  CALL METHOD cl_gui_frontend_services=>file_save_dialog

    EXPORTING

      default_extension = 'XLS'

      default_file_name = l_fname

      file_filter       = '*.XLS'

    CHANGING

      filename          = l_ext_filename

      path              = l_path

      fullpath          = l_fullpath

      user_action       = l_usr_act.



  IF l_usr_act = '0'.

    CALL METHOD cl_gui_frontend_services=>gui_download

      EXPORTING

        filename                = l_fullpath

        write_field_separator   = 'X'

      IMPORTING

        filelength              = l_file_len

      CHANGING

        data_tab                = <fs_table>

      EXCEPTIONS

        file_write_error        = 1

        no_batch                = 2

        gui_refuse_filetransfer = 3

        invalid_type            = 4

        no_authority            = 5

        unknown_error           = 6

        header_not_allowed      = 7

        separator_not_allowed   = 8

        filesize_not_allowed    = 9

        header_too_long         = 10

        dp_error_create         = 11

        dp_error_send           = 12

        dp_error_write          = 13

        unknown_dp_error        = 14

        access_denied           = 15

        dp_out_of_memory        = 16

        disk_full               = 17

        dp_timeout              = 18

        file_not_found          = 19

        dataprovider_exception  = 20

        control_flush_error     = 21

        OTHERS                  = 22.



    IF sy-subrc = 0.

      MESSAGE s000 WITH 'Success.'.

    ELSE.

      MESSAGE i000 WITH 'Failure'.

    ENDIF.

  ELSE.

    MESSAGE i000 WITH 'Cancled'.

  ENDIF.

ENDFORM.                    " EXCEL_FORM_DOWNLOAD



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

*&      Form  CONVERT_CURRENCY

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

*       text

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

*      -->P_BUDAT    text

*      -->P_FCURR    text

*      -->P_LCURR    text

*      -->P_FAMT     text

*      -->P_LAMT     text

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

FORM convert_currency USING p_budat p_fcurr p_lcurr

       p_famt p_lamt.



  IF p_fcurr = p_lcurr.

    p_lamt = p_famt.

  ELSE.

    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

      EXPORTING

        client           = sy-mandt

        date             = p_budat

        foreign_currency = p_fcurr

        foreign_amount   = p_famt

        local_currency   = p_lcurr

      IMPORTING

        local_amount     = p_lamt

      EXCEPTIONS

        no_rate_found    = 01.

  ENDIF.



ENDFORM.                    "CONVERT_CURRENCY

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

*&      Form  CONVERT_CHAR_TO_AMT

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

*       text

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

*      -->P_VALUE    text

*      -->P_WAERS    text

*      -->P_AMT      text

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

FORM convert_char_to_amt USING p_value p_waers p_amt.

  DATA : lv_amt(20) TYPE c.

  DATA : lv_ext TYPE bapicurr-bapicurr.



  CALL FUNCTION 'STRING_REPLACE'

    EXPORTING

      pattern    = ','

      substitute = ''

    CHANGING

      text       = p_value.



  IF sy-subrc NE 0.



  ENDIF.



  lv_ext = p_value.



  CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_INTERNAL'

    EXPORTING

      currency             = p_waers

      amount_external      = lv_ext

      max_number_of_digits = '11'

    IMPORTING

      amount_internal      = lv_amt.



  p_amt = lv_amt.



ENDFORM.                    "CONVERT_CHAR_TO_AMT

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

*&      Form  F4IF_INT_TABLE_VALUE_REQUEST

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

*       text

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

*      -->PT_VALUE_TAB   text

*      -->PT_FIELD_TAB   text

*      -->PT_RETURN_TAB  text

*      -->P_RETFIELD     text

*      -->P_DYNPROFIELD  text

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

FORM f4if_int_table_value_request TABLES pt_value_tab

                                         pt_field_tab

                                pt_return_tab STRUCTURE ddshretval

                        USING p_retfield    TYPE dfies-fieldname

                              p_dynprofield TYPE help_info-dynprofld.



  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

    EXPORTING

      retfield        = p_retfield

      dynpprog        = sy-cprog

      dynpnr          = sy-dynnr

      dynprofield     = p_dynprofield

      value_org       = 'S'

*     display         = 'X'

    TABLES

      value_tab       = pt_value_tab

      field_tab       = pt_field_tab

      return_tab      = pt_return_tab

    EXCEPTIONS

      parameter_error = 1

      no_values_found = 2

      OTHERS          = 3.



  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.                    " f4if_int_table_value_request

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

*&      Form  POPUP_TO_CONFIRM_02

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

*       text

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

*      -->PV_TITLE      text

*      -->PV_QUESTION1  text

*      -->PV_QUESTION2  text

*      -->PV_ANSWER     text

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

FORM popup_to_confirm_02  USING    pv_title

                                pv_question1

                                pv_question2

                       CHANGING pv_answer.



  CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'

    EXPORTING

      textline1 = pv_question1

      textline2 = pv_question2

      titel     = pv_title

    IMPORTING

      answer    = pv_answer. " J:예 N:아니오 A:취소



ENDFORM.                    " POPUP_TO_CONFIRM

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

*&      Form  POPUP_TO_CONFIRM

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

*       text

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

*      -->P_TITLE    text

*      -->P_TEXT     text

*      -->P_DEFAULT  text

*      -->P_CANC     text

*      -->P_ANSWER   text

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

FORM popup_to_confirm  USING    p_title

                                p_text

                                p_default

                                p_canc

                    CHANGING p_answer.



  CALL FUNCTION 'POPUP_TO_CONFIRM'

    EXPORTING

      titlebar              = p_title

      text_question         = p_text

      text_button_1         = 'Yes'

      text_button_2         = 'No'

      default_button        = p_default

      display_cancel_button = p_canc

    IMPORTING

      answer                = p_answer

    EXCEPTIONS

      text_not_found        = 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.

    CLEAR p_answer.

  ENDIF.



ENDFORM.                    " POPUP_TO_CONFIRM

*&---------------------------------------------------------------------*
*&      Form  GET_LAST_DAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DATE       text
*      -->P_LAST_DATE  text
*----------------------------------------------------------------------*
FORM get_last_day USING   p_date
                  CHANGING p_last_date.

  "월의 마지막날 구하는 function.
  CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
    EXPORTING
      day_in            = p_date
    IMPORTING
      last_day_of_month = p_last_date.

ENDFORM.                    " CHECK_VALIDATION

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

*&      Form  SET_DSMOD

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

*       text

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

*      -->PA_DSMOD   text

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

FORM set_dsmod USING pa_dsmod.



  TRANSLATE pa_dsmod TO UPPER CASE.



  IF pa_dsmod NA 'AEN'.

    MESSAGE s000 DISPLAY LIKE 'E' WITH 'BDC Mode Fail'.

    LEAVE LIST-PROCESSING.

  ENDIF.



ENDFORM.                    " SET_DSMOD

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

*&      Form  FILE_EXISTS

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

*       text

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

*      -->P_FNAME    text

*      -->P_EXISTS   text

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

FORM file_exists USING p_fname p_exists.



  DATA : l_result TYPE abap_bool.

  DATA : l_filenm TYPE string.



  CLEAR : p_exists.



  p_exists =  abap_false.



  CHECK p_fname IS NOT INITIAL.



  l_filenm = p_fname.



  CALL METHOD cl_gui_frontend_services=>file_exist

    EXPORTING

      file                 = l_filenm

    RECEIVING

      result               = l_result

    EXCEPTIONS

      cntl_error           = 1

      error_no_gui         = 2

      wrong_parameter      = 3

      not_supported_by_gui = 4

      OTHERS               = 5.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.



  p_exists = l_result.



ENDFORM.                    "FILE_EXISTS

*&---------------------------------------------------------------------*
*&      Form  AMT_CONV_TO_INTERNAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WAERS    text
*      -->P_AMOUNT   text
*----------------------------------------------------------------------*
FORM amt_conv_to_internal USING p_waers
                          CHANGING p_amount.

  DATA: l_internal TYPE bapicurr-bapicurr.


  l_internal = p_amount.

  CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_INTERNAL'
    EXPORTING
      currency             = p_waers
      amount_external      = l_internal
      max_number_of_digits = 22
    IMPORTING
      amount_internal      = l_internal.

  p_amount = l_internal.

ENDFORM.                    "amt_conv_to_external



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

*&      Form  GET_NEXT_NUMBER

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

*       text

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

*      -->P_NRRANG   text

*      -->P_OBJECT   text

*      -->P_DOCNO    text

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

FORM get_next_number USING p_nrrang p_object

                     CHANGING p_docno.



  DATA : lv_fldnam TYPE string,

         lv_nrrang LIKE inrdp-nrrangenr,

         lv_object LIKE nriv-object.



  lv_nrrang = p_nrrang.

  lv_object = p_object.



  CALL FUNCTION 'NUMBER_GET_NEXT'

    EXPORTING

      nr_range_nr             = lv_nrrang

      object                  = lv_object

    IMPORTING

      number                  = p_docno

    EXCEPTIONS

      interval_not_found      = 1

      number_range_not_intern = 2

      object_not_found        = 3

      quantity_is_0           = 4

      quantity_is_not_1       = 5

      interval_overflow       = 6

      buffer_overflow         = 7

      OTHERS                  = 8.

  IF sy-subrc <> 0.

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

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

    CLEAR p_docno.

  ENDIF.



ENDFORM.                    " F_GET_NEXT_NUMBER



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

*&      Form  GET_NEXT_NUMBER_YEAR

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

*       text

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

*      -->P_NRRANG   text

*      -->P_OBJECT   text

*      -->P_YEAR     text

*      -->P_DOCNO    text

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

FORM get_next_number_year USING p_nrrang p_object p_year

                     CHANGING p_docno.



  DATA : lv_fldnam TYPE string,

         lv_nrrang LIKE inrdp-nrrangenr,

         lv_object LIKE nriv-object,

         lv_year   LIKE inri-toyear.



  lv_nrrang = p_nrrang.

  lv_object = p_object.

  IF p_year IS NOT INITIAL.

    lv_year = p_year.

  ELSE.

    lv_year = '0000'.



  ENDIF.



  CALL FUNCTION 'NUMBER_GET_NEXT'

    EXPORTING

      nr_range_nr             = lv_nrrang

      object                  = lv_object

      toyear                  = lv_year

    IMPORTING

      number                  = p_docno

    EXCEPTIONS

      interval_not_found      = 1

      number_range_not_intern = 2

      object_not_found        = 3

      quantity_is_0           = 4

      quantity_is_not_1       = 5

      interval_overflow       = 6

      buffer_overflow         = 7

      OTHERS                  = 8.

  IF sy-subrc <> 0.

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

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

    CLEAR p_docno.

  ENDIF.



ENDFORM.                    " F_GET_NEXT_NUMBER_YEAR

*&---------------------------------------------------------------------*
*&      Form  GET_VALUE_LIST_DOM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TAB      text
*      -->P_DOMAIN   text
*----------------------------------------------------------------------*
FORM get_value_list_dom  TABLES   p_tab
                         USING    p_domain.

  SELECT domvalue_l ddtext
    INTO TABLE p_tab
    FROM dd07t
   WHERE domname    EQ p_domain
     AND ddlanguage EQ sy-langu
     AND as4local   EQ 'A'.
  IF sy-subrc EQ 0.
    SORT p_tab.
  ELSE.
    REFRESH p_tab.
  ENDIF.

ENDFORM.                    " GET_VALUE_LIST_DOM

*&---------------------------------------------------------------------*
*&      Form  get_value_text
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TAB      text
*      -->P_DOMAIN   text
*----------------------------------------------------------------------*
FORM get_value_text  USING    p_domain
                              p_value
                      CHANGING p_text.

  SELECT SINGLE ddtext
    INTO p_text
    FROM dd07t
   WHERE domname    EQ p_domain
     AND ddlanguage EQ sy-langu
     AND as4local   EQ 'A'
     AND domvalue_l EQ p_value.

ENDFORM.                    " get_value_text

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

*&      Form  GET_DOM_TEXT_LIST

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

*       text

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

*      -->P_DOMNA    text

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

FORM get_dom_text_list USING p_domna.



  SELECT domname domvalue_l ddtext

    APPENDING TABLE gt_domain

    FROM dd07t

   WHERE domname    = p_domna

     AND ddlanguage = sy-langu

     AND as4local   = 'A'.



  SORT : gt_domain.



ENDFORM.                    " GET_DOM_TEXT_LIST

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

*&      Form  GET_FILE_PATH

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

*       text

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

*      -->P_FILENM   text

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

FORM get_file_path CHANGING p_filenm.



  DATA: line_count   TYPE   i,

        user_action  TYPE   i,

        rtn_code     LIKE   sy-subrc,

        lt_filetable TYPE   filetable,

        ls_filetable TYPE   file_table.



  CALL METHOD cl_gui_frontend_services=>file_open_dialog

    EXPORTING

      window_title      = 'Upload'

      multiselection    = ' '

      default_extension = 'XLS'

      default_filename  = ' '

      file_filter       = '*.XLS'

    CHANGING

      file_table        = lt_filetable

      rc                = rtn_code

      user_action       = user_action.



  CALL METHOD cl_gui_cfw=>flush.



  CASE  user_action.

    WHEN  cl_gui_frontend_services=>action_ok.

      READ   TABLE lt_filetable INTO ls_filetable INDEX 1.

      CHECK  sy-subrc IS INITIAL.

      MOVE:  ls_filetable-filename      TO      p_filenm.



    WHEN  cl_gui_frontend_services=>action_cancel.

  ENDCASE.



ENDFORM.                    " GET_FILE_PATH



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

*&      Form  CHK_FILE_PATH

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

*       text

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

*      -->P_FNAME    text

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

FORM chk_file_path  USING    p_fname.



  DATA: lv_result TYPE  char1,

        lv_file   TYPE  string.



  MOVE: p_fname  TO  lv_file.



  CALL METHOD cl_gui_frontend_services=>file_exist

    EXPORTING

      file   = lv_file

    RECEIVING

      result = lv_result.



  IF NOT sy-subrc IS INITIAL.



    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.



  ELSEIF lv_result IS INITIAL.



    MESSAGE s001(00) WITH 'Please check your file path'.

    LEAVE LIST-PROCESSING.



  ENDIF.



ENDFORM.                    " CHK_FILE_PATH



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

*&      Form  SET_BUTTON_100

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

*       text

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

*      -->P_NO       text

*      -->P_ICON     text

*      -->P_TEXT     text

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

FORM set_button_100  USING p_no TYPE numc2

                            p_icon p_text.



  DATA : ls_functxt       TYPE smp_dyntxt,

         lv_fieldname(30).



  FIELD-SYMBOLS <fs_func> LIKE sscrfields-functxt_01.



  CONCATENATE 'SSCRFIELDS-FUNCTXT_' p_no INTO lv_fieldname.

  ASSIGN (lv_fieldname) TO <fs_func>.



  IF p_icon EQ space.

    MOVE p_text TO <fs_func> .

  ELSE.

    ls_functxt-icon_id    = p_icon.

    ls_functxt-icon_text  = p_text.



    <fs_func> = ls_functxt.



  ENDIF.





ENDFORM.                    " SET_BUTTON_100

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

*&      Form  GET_DYNP_VALUES_READ

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

*       text

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

*      -->P_FIELD    text

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

FORM get_dynp_values_read  USING  p_field.



  DATA : lt_dynpfields TYPE TABLE OF dynpread,

         ls_dynpfields TYPE dynpread,

         lv_dyname     TYPE sy-repid,

         lv_dynum      TYPE sy-dynnr.



  FIELD-SYMBOLS <fs_field> TYPE any.



  lv_dyname = sy-repid.

  lv_dynum  = sy-dynnr.



  ls_dynpfields-fieldname = p_field.

  APPEND ls_dynpfields TO lt_dynpfields.



  CALL FUNCTION 'DYNP_VALUES_READ'

    EXPORTING

      dyname               = lv_dyname

      dynumb               = lv_dynum

    TABLES

      dynpfields           = lt_dynpfields

    EXCEPTIONS

      invalid_abapworkarea = 1

      invalid_dynprofield  = 2

      invalid_dynproname   = 3

      invalid_dynpronummer = 4

      invalid_request      = 5

      no_fielddescription  = 6

      invalid_parameter    = 7

      undefind_error       = 8

      double_conversion    = 9

      stepl_not_found      = 10

      OTHERS               = 11.



  IF sy-subrc <> 0.

    EXIT.



  ELSE.

    READ TABLE lt_dynpfields INTO ls_dynpfields

                           WITH KEY fieldname = p_field.

    IF sy-subrc EQ 0.

      ASSIGN (p_field) TO <fs_field>.

      IF <fs_field> IS ASSIGNED.

        <fs_field> = ls_dynpfields-fieldvalue.

      ENDIF.

    ENDIF.



  ENDIF.



ENDFORM.                    " GET_DYNP_VALUES_READ



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

*&      Form  SET_DYNP_VALUES

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

*       text

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

*      -->P_FIELD    text

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

FORM set_dynp_values  USING  p_field.



  DATA : lt_dynpfields TYPE TABLE OF dynpread,

         ls_dynpfields TYPE dynpread,

         lv_dyname     TYPE sy-repid,

         lv_dynum      TYPE sy-dynnr.



  FIELD-SYMBOLS <fs_field> TYPE any.



  lv_dyname = sy-repid.

  lv_dynum  = sy-dynnr.



  ls_dynpfields-fieldname = p_field.



  ASSIGN (p_field) TO <fs_field>.

  IF <fs_field> IS ASSIGNED.

    ls_dynpfields-fieldvalue = <fs_field>.

  ENDIF.

  APPEND ls_dynpfields TO lt_dynpfields.



  CALL FUNCTION 'DYNP_VALUES_UPDATE'

    EXPORTING

      dyname               = lv_dyname

      dynumb               = lv_dynum

    TABLES

      dynpfields           = lt_dynpfields

    EXCEPTIONS

      invalid_abapworkarea = 1

      invalid_dynprofield  = 2

      invalid_dynproname   = 3

      invalid_dynpronummer = 4

      invalid_request      = 5

      no_fielddescription  = 6

      undefind_error       = 7

      OTHERS               = 8.



  IF sy-subrc <> 0.

    EXIT.



  ENDIF.



ENDFORM.                    " SET_DYNP_VALUES



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

*&      Form  SET_BTN_1000

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

*       text

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

*      -->P_0139   text

*      -->P_ICON_XXL  text

*      -->P_0141   text

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

FORM set_btn_1000  USING p_no TYPE numc2

                            p_icon p_text.



  DATA : ls_functxt       TYPE smp_dyntxt,

         lv_fieldname(30).



  FIELD-SYMBOLS <fs_func> LIKE sscrfields-functxt_01.



  CONCATENATE 'SSCRFIELDS-FUNCTXT_' p_no INTO lv_fieldname.

  ASSIGN (lv_fieldname) TO <fs_func>.



  IF p_icon EQ space.

    MOVE p_text TO <fs_func> .

  ELSE.

    ls_functxt-icon_id    = p_icon.

    ls_functxt-icon_text  = p_text.



    <fs_func> = ls_functxt.



  ENDIF.

ENDFORM.                    " SET_BTN_1000



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

*&      Form  F_PDF_DOWNLOAD

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

*       text

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

*      -->P_JOB      text

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

FORM f_pdf_download USING p_job TYPE ssfcrescl.



  DATA : lv_transfer_bin TYPE sx_boolean,

         lt_content_txt  TYPE soli_tab,

         lt_content_bin  TYPE solix_tab,

         lt_objhead      TYPE soli_tab,

         lv_len_in       LIKE sood-objlen,

         ls_otf          TYPE solisti1,

         lv_bin_filesize TYPE i,

         lv_bin_file     TYPE xstring,

         lt_lines        LIKE tline OCCURS 0 WITH HEADER LINE.

  DATA : lv_filesize TYPE i,

         lv_filename TYPE string.

  DATA : lt_otf          TYPE TABLE OF itcoo WITH HEADER LINE.



  lt_otf[] = p_job-otfdata.



  CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

      format                = 'PDF'

    IMPORTING

      bin_filesize          = lv_bin_filesize

      bin_file              = lv_bin_file

    TABLES

      otf                   = lt_otf

      lines                 = lt_lines

    EXCEPTIONS

      err_max_linewidth     = 1

      err_format            = 2

      err_conv_not_possible = 3

      err_bad_otf           = 4

      OTHERS                = 5.



  LOOP AT lt_otf.

    CONCATENATE lt_otf-tdprintcom lt_otf-tdprintpar INTO ls_otf.

    APPEND ls_otf TO lt_content_txt.

  ENDLOOP.



  CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'

    EXPORTING

      format_src      = 'OTF'

      format_dst      = 'PDF'

      devtype         = 'PRINTER'

    CHANGING

      transfer_bin    = lv_transfer_bin

      content_txt     = lt_content_txt

      content_bin     = lt_content_bin

      objhead         = lt_objhead

      len             = lv_len_in

    EXCEPTIONS

      err_conv_failed = 1

      OTHERS          = 2.



* pdf 다운로드

  lv_filesize = lv_len_in.

  PERFORM open_save_file_sel USING 'pdf' CHANGING lv_filename.



  CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

      bin_filesize = lv_filesize

      filename     = lv_filename

      filetype     = 'BIN'

    TABLES

      data_tab     = lt_content_bin.



ENDFORM.                    " F_PDF_DOWNLOAD

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

*&      Form  OPEN_SAVE_FILE_SEL

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

*       text

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

*      -->P_EXT      text

*      -->P_FILENAME text

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

FORM open_save_file_sel USING p_ext CHANGING p_filename.



  DATA: lv_subrc               LIKE sy-subrc,

        lv_has_field_separator TYPE char01,

        lv_filename            TYPE string,

        lv_path                TYPE string,

        lv_fullpath            TYPE string,

        lv_default_extension   TYPE string,

        lv_file_filter         TYPE string,

        lv_initial_directory   TYPE string,

        lv_default_file_name   TYPE string,

        lt_file_table          TYPE filetable,

        ls_file_table          TYPE LINE OF filetable,

        lv_user_action         TYPE i.



  CLEAR p_filename.



  lv_default_extension  = p_ext.

  CONCATENATE '*.' p_ext INTO lv_default_file_name.

  lv_initial_directory  = 'C:\'.

  CONCATENATE cl_gui_frontend_services=>filetype_all

*            CL_GUI_FRONTEND_SERVICES=>FILETYPE_TEXT

              cl_gui_frontend_services=>filetype_excel

         INTO lv_file_filter.



  CALL METHOD cl_gui_frontend_services=>file_save_dialog

    EXPORTING

*    WINDOW_TITLE

      default_extension    = lv_default_extension

      default_file_name    = lv_default_file_name

*     WITH_ENCODING        = ABAP_TRUE

      file_filter          = lv_file_filter

      initial_directory    = lv_initial_directory

    CHANGING

      filename             = lv_filename

      path                 = lv_path

      fullpath             = lv_fullpath

      user_action          = lv_user_action

    EXCEPTIONS

      cntl_error           = 2

      error_no_gui         = 3

      not_supported_by_gui = 4

      OTHERS               = 5.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    EXIT.

  ELSE.

    IF lv_user_action NE cl_gui_frontend_services=>action_ok.

      EXIT.

    ENDIF.



    p_filename = lv_filename.



  ENDIF.



ENDFORM.                    " OPEN_SAVE_FILE_SEL

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

*&      Form  ALSMEX_TAB_TO_ITAB

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

*       text

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

*      -->PT_INTERN       text

*      -->PT_EXCEL_TABLE  text

*      -->PS_EXCEL_STRUC  text

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

*FORM ALSMEX_TAB_TO_ITAB

*   TABLES PT_INTERN STRUCTURE ALSMEX_TABLINE

*   USING PT_EXCEL_TABLE PS_EXCEL_STRUC.

*  FIELD-SYMBOLS : <FIELD> TYPE ANY.

*  FIELD-SYMBOLS : <ITAB> TYPE STANDARD TABLE.

*  FIELD-SYMBOLS : <ILINE> TYPE ANY.

*

*  ASSIGN : (PT_EXCEL_TABLE) TO <ITAB>.

*  ASSIGN : (PS_EXCEL_STRUC) TO <ILINE>.

*

*  LOOP AT PT_INTERN.

*    AT NEW ROW.

*      CLEAR : <ILINE>.

*    ENDAT.

*

*    ASSIGN COMPONENT PT_INTERN-COL OF STRUCTURE <ILINE> TO <FIELD>.

*

*    IF PT_INTERN-VALUE CO '0123456789,.- '.

*      REPLACE ALL OCCURRENCES OF ',' IN PT_INTERN-VALUE WITH ''.

*    ENDIF.

*

*    MOVE PT_INTERN-VALUE TO <FIELD>.

*

*    AT END OF ROW.

*      APPEND <ILINE> TO <ITAB>.

*    ENDAT.

*  ENDLOOP.

*

*ENDFORM.                    " ALSMEX_TAB_TO_ITAB

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

**&      Form  START_INTERFACE_BDC

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

**       text

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

**      -->P_MODE     text

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

*FORM START_INTERFACE_BDC USING P_MODE.

*  CLEAR : FTPOST, FTPOST[].

*  CLEAR : FTTAX, FTTAX[].

*  CLEAR : BLNTAB, BLNTAB[].

*  CLEAR : GV_FTPOST_TYPE.

*  CLEAR : GV_FTPOST_CNT.

*

*  CALL FUNCTION 'POSTING_INTERFACE_START'

*    EXPORTING

*      I_FUNCTION         = 'C' " Using Call Transaction

*      I_KEEP             = 'Y'

*      I_MODE             = P_MODE

*      I_UPDATE           = 'S'

*    EXCEPTIONS

*      CLIENT_INCORRECT   = 1

*      FUNCTION_INVALID   = 2

*      GROUP_NAME_MISSING = 3

*      MODE_INVALID       = 4

*      UPDATE_INVALID     = 5

*      OTHERS             = 6.

*ENDFORM.                    " START_BDC

*

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

**&      Form  END_INTERFACE_BDC

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

**       text

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

*FORM END_INTERFACE_BDC.

*  CALL FUNCTION 'POSTING_INTERFACE_END'

*    EXPORTING

*      I_BDCIMMED = 'X'.

*

*  CLEAR : FTPOST, FTPOST[].

*  CLEAR : FTTAX, FTTAX[].

*  CLEAR : BLNTAB, BLNTAB[].

*  CLEAR : GV_FTPOST_TYPE.

*  CLEAR : GV_FTPOST_CNT.

*ENDFORM.                    "END_BDC



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

*&      Form  FILL_FIELD

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

*       text

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

*      -->FNAM       text

*      -->FVAL       text

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

FORM fill_field USING fnam fval fcurr_x.

  "USING 'BSEG-WRBTR'  GT_DATA-WRBTR_D 'X'.

  DATA : lv_curr(15) TYPE c.



  CHECK fval NE space.



  ftpost-fnam = fnam.

  ftpost-stype = gv_ftpost_type.

  ftpost-count = gv_ftpost_cnt.



  " 금액 필드일 경우.

  IF fcurr_x = 'X'.

    WRITE fval TO lv_curr CURRENCY

       gv_ftpost_waers LEFT-JUSTIFIED.

    CONDENSE lv_curr NO-GAPS.

    WRITE lv_curr TO ftpost-fval.

  ELSE.

    WRITE fval TO ftpost-fval.

  ENDIF.



  APPEND ftpost.

  CLEAR ftpost.



ENDFORM.                    "BUCHEN_FELD

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

*&      Form  BUILD_MESSGE_IF

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

*       text

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

*      -->PS_MESSAGE text

*      -->PV_TEXT    text

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

FORM  build_messge_if USING ps_message

      STRUCTURE gt_if_msg CHANGING pv_text.



  CLEAR pv_text.



  CALL FUNCTION 'MESSAGE_TEXT_BUILD'

    EXPORTING

      msgid               = ps_message-msgid

      msgnr               = ps_message-msgno

      msgv1               = ps_message-msgv1

      msgv2               = ps_message-msgv2

      msgv3               = ps_message-msgv3

      msgv4               = ps_message-msgv4

    IMPORTING

      message_text_output = pv_text.

ENDFORM.                    "BUILD_MESSGE_IF

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

*&      Form  GET_POST_PERIOD

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

*       text

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

*      -->PV_DATE    text

*      -->P_LFGJA    text

*      -->P_LFMON    text

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

FORM get_post_period USING pv_bukrs pv_date LIKE sy-datum

      CHANGING p_lfgja p_lfmon.



  CLEAR : p_lfgja, p_lfmon.



  CALL FUNCTION 'FI_PERIOD_DETERMINE'

    EXPORTING

      i_bukrs        = pv_bukrs

      i_budat        = pv_date

    IMPORTING

      e_gjahr        = p_lfgja

      e_monat        = p_lfmon

    EXCEPTIONS

      fiscal_year    = 1

      period         = 2

      period_version = 3

      posting_period = 4

      special_period = 5

      version        = 6

      posting_date   = 7

      OTHERS         = 8.



  IF sy-subrc NE 0.

    p_lfgja = pv_date(4).

    p_lfmon = pv_date+4(2).

  ENDIF.



ENDFORM.                    "GET_POST_PERIOD

*&---------------------------------------------------------------------*
*&      Form  GET_KOKRS_TXT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_KOKRS    text
*      -->P_BEZEI    text
*----------------------------------------------------------------------*
FORM set_kokrs_base USING p_kokrs.

  SELECT SINGLE bezei ktopl
    INTO (gv_kbezei_cm, gv_ktopl_cm)
    FROM tka01
    WHERE kokrs = p_kokrs.

ENDFORM.                    "GET_KOKRS_TXT

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

*&      Form  CONV_DB_WAERS

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

*       text

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

*      -->P_VALUE    text

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

FORM conv_db_waers USING p_value p_waers.

  CALL FUNCTION 'CURRENCY_AMOUNT_IDOC_TO_SAP'

    EXPORTING

      currency    = p_waers

      idoc_amount = p_value

    IMPORTING

      sap_amount  = p_value.

ENDFORM.                    "TO_KRW

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

*&      Form  CONV_VIEW_WAERS

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

*       text

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

*      -->P_VALUE      text

*      -->P_WAERS      text

*      -->P_DOC_VALUE  text

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

FORM conv_view_waers USING p_value p_waers

       CHANGING p_doc_value.

  CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_IDOC'

    EXPORTING

      currency    = p_waers

      sap_amount  = p_value

    IMPORTING

      idoc_amount = p_doc_value.

ENDFORM.                    "TO_KRW

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

*&      Form  CONVERT_1000

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

*       text

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

*      -->P_VALUE       text

*      -->P_VALUE_1000  text

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

*FORM CONVERT_1000_U USING P_VALUE

*      CHANGING P_VALUE_1000.

*  P_VALUE_1000 = P_VALUE * 1000.

*ENDFORM.                    "CONVERT_1000

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

*&      Form  CONVERT_1000_D

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

*       text

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

*      -->P_VALUE       text

*      -->P_VALUE_1000  text

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

*FORM CONVERT_1000_D USING P_VALUE

*      CHANGING P_VALUE_1000.

*  P_VALUE_1000 = P_VALUE / 1000.

*ENDFORM.                    "CONVERT_1000

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

*&      Form  GET_VERSN_TEXT

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

*       text

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

*      -->P_KOKRS      text

*      -->P_VERSN      text

*      -->P_VERSN_TXT  text

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

*FORM GET_VERSN_TEXT USING P_KOKRS P_VERSN

*      CHANGING P_VERSN_TXT.

*  CLEAR : P_VERSN_TXT.

*  SELECT SINGLE TXT

*    INTO P_VERSN_TXT

*    FROM TKT09

*    WHERE KOKRS = P_KOKRS

*    AND VERSN = P_VERSN

*    AND LANGU = SY-LANGU.

*ENDFORM.                    "GET_VERSN_TEXT



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

*&      Form  UPLOAD_XLS_STRUCT

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

*       text

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

*      -->P_TABLE    text

*      -->P_FILE     text

*      -->P_SCOL     text

*      -->P_SROW     text

*      -->P_ECOL     text

*      -->P_EROW     text

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

FORM upload_xls_struct TABLES   p_table

                       USING    p_file

                                p_scol

                                p_srow

                                p_ecol

                                p_erow.



  DATA : lt_intern TYPE  alsmex_tabline OCCURS 0 WITH HEADER LINE.



  DATA : lv_index TYPE i.

  FIELD-SYMBOLS : <fs_line>.



  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

      filename                = p_file

      i_begin_col             = p_scol

      i_begin_row             = p_srow

      i_end_col               = p_ecol

      i_end_row               = p_erow

    TABLES

      intern                  = lt_intern

    EXCEPTIONS

      inconsistent_parameters = 1

      upload_ole              = 2

      OTHERS                  = 3.



  IF sy-subrc <> 0.

    FORMAT COLOR COL_BACKGROUND INTENSIFIED.

    WRITE:/ 'Error Uploading file'.

    EXIT.

  ENDIF.



  IF lt_intern[] IS INITIAL.

    FORMAT COLOR COL_BACKGROUND INTENSIFIED.

    WRITE:/ 'No Data Uploaded'.

    EXIT.

  ELSE.

    SORT lt_intern BY row col.

    LOOP AT lt_intern.

      MOVE lt_intern-col TO lv_index.

      ASSIGN COMPONENT lv_index OF STRUCTURE p_table TO <fs_line>.



      IF lt_intern-value CO '0123456789,.- '.

        REPLACE ALL OCCURRENCES OF ',' IN lt_intern-value WITH ''.

      ENDIF.



      MOVE lt_intern-value TO <fs_line>.

      AT END OF row.

        APPEND p_table.

        CLEAR p_table.

      ENDAT.

    ENDLOOP.

  ENDIF.



ENDFORM.                    "UPLOAD_EXCEL_FILE

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

*&      Form  SET_PREV_MONTH

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

*       text

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

*      -->P_P_GJAHR  text

*      -->P_P_PERDE  text

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

FORM set_prev_month  USING  pv_gjahr

                              pv_perde.



  DATA : lv_date LIKE sy-datum.



  CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

    EXPORTING

      date      = sy-datum

      days      = '00'

      months    = '01'

      signum    = '-'

      years     = '00'

    IMPORTING

      calc_date = lv_date.



  pv_gjahr = lv_date+0(4).

  pv_perde = lv_date+4(2).



ENDFORM.                    " SET_PREV_MONTH
*&---------------------------------------------------------------------*
*& Form GET_CSKT_KTEXT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*      -->P_GS_ZTFICD10_ACC_CD  text
*      <--P_GS_ZTFICD10_KTEXT  text
*&---------------------------------------------------------------------*
FORM get_cskt_ktext  USING    pv_kostl
                     CHANGING pv_ktext.

  SELECT SINGLE ktext
    INTO pv_ktext
    FROM cskt
   WHERE spras EQ '3'
     AND kokrs EQ '1000'
     AND kostl EQ pv_kostl
     AND datbi EQ '99991231'.

ENDFORM.

댓글 없음:

댓글 쓰기