SAP Include Method

*&---------------------------------------------------------------------*
*&  Include           ZSAPINCLUDE01
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
*       CLASS zdate DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class zdate definition.
  public section .
    methods : set
                importing value(set_valuetype sy-datum,
              get_last_day,
              get
                exporting value(get_valuetype sy-datum.
  private section.
    data lv_date_fm type sy-datum.
    data lv_date_to type sy-datum.
endclass.                    "zdate DEFINITION
*----------------------------------------------------------------------*
*       CLASS zdate IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class zdate implementation.
  method set.
    lv_date_fm set_value.
  endmethod.                    "set
  method get_last_day.
    call function 'LAST_DAY_OF_MONTHS'
      exporting
        day_in            lv_date_fm
      importing
        last_day_of_month lv_date_to
      exceptions
        day_in_no_date    1
        others            2.
  endmethod.                    "increment
  method get.
    get_value lv_date_to.
  endmethod.                    "get
endclass.                    "zdate IMPLEMENTATION
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
      wa_hier type slis_fieldcat_alv .
define alv_field.
  clear:wa_hier.
  wa_hier-fieldname &1.
  wa_hier-seltext_m &2.
  wa_hier-seltext_l &3.
  wa_hier-outputlen &4.
  wa_hier-just &5.
  wa_hier-do_sum &6.
  wa_hier-ref_tabname &7 .
  wa_hier-ref_fieldname &8 .
  append wa_hier to fc_hier.
end-of-definition.
data: it_structure type lvc_t_fcat,
      wa_structure type lvc_s_fcat.
define create_stru.
  wa_structure-fieldname &1.
  wa_structure-inttype &2.
  wa_structure-intlen &3.
  wa_structure-datatype =  &4.
  wa_structure-decimals &5.
  append wa_structure to it_structure.
end-of-definition.
*&---------------------------------------------------------------------*
*&      Form  get_last_day
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FROM     text
*      -->P_TO       text
*----------------------------------------------------------------------*
form get_last_day using p_from
                  changing p_to.
  call function 'LAST_DAY_OF_MONTHS'
    exporting
      day_in            p_from
    importing
      last_day_of_month p_to
    exceptions
      day_in_no_date    1
      others            2.
  if sy-subrc <> 0.
  endif.
endform.                    "get_last_day
*&---------------------------------------------------------------------*
*&      Form  get_last_day
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FROM     text
*      -->P_TO       text
*----------------------------------------------------------------------*
form get_next_month using p_from
                          p_month
                  changing p_to.
  call function 'BKK_ADD_MONTH_TO_DATE'
    exporting
      months  p_month
      olddate p_from
    importing
      newdate p_to.
endform.                    "get_last_day
*&---------------------------------------------------------------------*
*&      Form  get_week
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DATE     text
*      -->P_WEEK     text
*----------------------------------------------------------------------*
form get_week using p_date
              changing p_week.
  call function 'GET_WEEK_INFO_BASED_ON_DATE'
    exporting
      date   p_date
    importing
      week   p_week
*     monday =
*     sunday =
    .
endform.                    "get_week
*&---------------------------------------------------------------------*
*&      Form  get_last_week
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_YEAR     text
*      -->P_WEEK     text
*----------------------------------------------------------------------*
form get_last_week using p_year
                   changing p_week .
  call function 'BKK_GET_LASTWEEK_OF_YEAR'
    exporting
      i_year p_year
    importing
      e_week p_week
    exceptions
      others 1.
endform.                    "get_last_week

*&---------------------------------------------------------------------*
*&      Form  get_first_date_by_week
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WEEK     text
*      -->P_DATE     text
*----------------------------------------------------------------------*
form get_first_date_by_week using p_week
                            changing p_date .
  call function 'HRIQ_WEEK_GET_FIRST_DAY'
    exporting
      week         p_week
    importing
      date         p_date
    exceptions
      week_invalid 1
      others       2.
endform.                    "get_first_date_by_week
*&---------------------------------------------------------------------*
*&      Form  convert_to_factorydate
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DATE     text
*      -->P_FACTID   text
*      -->P_DATE_OUT text
*----------------------------------------------------------------------*
form convert_to_factorydate using p_date
                                  p_factid
                            changing p_date_out.
  call function 'DATE_CONVERT_TO_FACTORYDATE'
    exporting
      date                         p_date
      factory_calendar_id          p_factid "VH"
    importing
      date                         p_date_out
    exceptions
      calendar_buffer_not_loadable 1
      correct_option_invalid       2
      date_after_range             3
      date_before_range            4
      date_invalid                 5
      factory_calendar_not_found   6
      others                       7.
endform.                    "convert_to_factorydate
*&---------------------------------------------------------------------*
*&      Form  Get_Add_day
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WEBAZ      text
*      -->P_CALENDAR1  text
*      -->P_EINDT      text
*----------------------------------------------------------------------*
form get_add_day  using    p_webaz
                           p_calendar1
                  changing p_eindt.
  data: l_days type i.

  l_days p_webaz.

  call function 'BKK_ADD_WORKINGDAY'
    exporting
      i_date      p_eindt
      i_days      l_days
      i_calendar1 p_calendar1 "'VH'
*     I_CALENDAR2 =
    importing
      e_date      p_eindt
*     E_RETURN    =
    .
endform.                    " PROCESS_PO_GR_DAY

*&---------------------------------------------------------------------*
*&      Form  get_all_factory_date
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IT_ETH_DATS  text
*      -->P_START_DAY  text
*      -->P_END_DAY    text
*      -->P_FACTID     text
*----------------------------------------------------------------------*
form get_all_factory_date tables it_eth_dats
                          using p_start_day
                                p_end_day
                                p_factid.
  call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
    exporting
      i_datab               p_start_day
      i_datbi               p_end_day
      i_factid              p_factid "VH"
    tables
      eth_dats              it_eth_dats
    exceptions
      date_conversion_error 1
      others                2.
endform.                    "get_all_factory_date
*&---------------------------------------------------------------------*
*&      Form  display_run_PROGRESS_text
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TEXT     text
*----------------------------------------------------------------------*
form display_run_progress_text using p_text.
  call function 'SAPGUI_PROGRESS_INDICATOR'
    exporting
      text p_text.
endform.                    "display_run_PROGRESS_text
*&---------------------------------------------------------------------*
*&      Form  Transform_amount
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WAERK    text
*      -->P_EXPAND   text
*      -->PE_NETWR   text
*----------------------------------------------------------------------*
form transform_amount  using  p_waerk
                              p_expand
                     changing p_netwr.
  check p_waerk <> 'HKD'.
  check p_waerk <> 'USD'.
  check p_waerk <> 'EUR'.
  check p_waerk <> 'CNY'.
  data : lv_netwr type bapicurr-bapicurr.
  if p_expand 'X'.
    call function 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
      exporting
        currency        p_waerk
        amount_internal p_netwr
      importing
        amount_external lv_netwr.

    p_netwr =  lv_netwr.
  else.
    data: fa like vbrp-kursk.
    lv_netwr p_netwr.
    call function 'BAPI_CURRENCY_CONV_TO_INTERNAL'
      exporting
        currency             p_waerk
        amount_external      lv_netwr
        max_number_of_digits 13
      importing
        amount_internal      fa.
    p_netwr =  fa.
  endif.
endform.                    " EXPAND_AMOUNT
*&---------------------------------------------------------------------*
*&      Form  convert_to_local_amount
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DATE       text
*      -->P_NETWR_FOR  text
*      -->P_WAERK_FOR  text
*      -->P_WAERK_LOC  text
*      -->P_NETWR_LOC  text
*----------------------------------------------------------------------*
form convert_to_local_amount using p_date p_netwr_for p_waerk_for p_waerk_loc
                             changing p_netwr_loc .
  if p_waerk_for ne  p_waerk_loc.
    call function 'CONVERT_TO_LOCAL_CURRENCY'
      exporting
        date             p_date
        foreign_amount   p_netwr_for
        foreign_currency p_waerk_for
        local_currency   p_waerk_loc
        type_of_rate     'M'
      importing
        local_amount     p_netwr_loc
      exceptions
        no_rate_found    1
        others           2.
  endif.
endform.                    "CONVERT_TO_LOCAL_AMOUNT
*&---------------------------------------------------------------------*
*&      Form  GET_EN_MONTH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_MONTH  text
*----------------------------------------------------------------------*
form get_en_month  using    p_month
                   changing p_en_month.
  case p_month.
    when '01'.
      p_en_month 'Jan'.
    when '02'.
      p_en_month 'Feb'.
    when '03'.
      p_en_month 'Mar'.
    when '04'.
      p_en_month 'Apr'.
    when '05'.
      p_en_month 'May'.
    when '06'.
      p_en_month 'Jun'.
    when '07'.
      p_en_month 'Jul'.
    when '08'.
      p_en_month 'Aug'.
    when '09'.
      p_en_month 'Sep'.
    when '10'.
      p_en_month 'Oct'.
    when '11'.
      p_en_month 'Nov'.
    when '12'.
      p_en_month 'Dec'.
  endcase.
endform.                    " GET_EN_MONTH
*&---------------------------------------------------------------------*
*&      Form  f4_filename
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILENAME text
*----------------------------------------------------------------------*
form f4_filename  using    p_filename.
  call function 'F4_FILENAME'
*    EXPORTING
*     PROGRAM_NAME        = SYST-CPROG
*     DYNPRO_NUMBER       = SYST-DYNNR
*     FIELD_NAME          =
    importing
      file_name           p_filename.
endform.                    " F4_FILENAME
*&---------------------------------------------------------------------*
*&      Form  get_select_filename
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILENAME text
*----------------------------------------------------------------------*
form get_select_filename_excel using p_filename.
  call function 'WS_FILENAME_GET'
    exporting
      def_path         'C:\'
      mask             ',Excel Files,*.xls,All Files,*.*.'(101)
      mode             'O'
      title            'Select file'(100)
    importing
      filename         p_filename
    exceptions
      selection_cancel 1
      selection_error  2
      others           3.
  if sy-subrc ne 0.
    "     .
  endif.
endform.                    "get_select_filename
*&---------------------------------------------------------------------*
*&      Form  get_select_filename_txt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILENAME text
*      -->P_MASK     text
*----------------------------------------------------------------------*
form get_select_filename_txt using p_filename.
  call function 'WS_FILENAME_GET'
    exporting
      def_path         'C:\'
      mask             ',Txt Files,*.txt,All Files,*.*.'(101)
      mode             'O'
      title            'Select file'(100)
    importing
      filename         p_filename
    exceptions
      selection_cancel 1
      selection_error  2
      others           3.
  if sy-subrc ne 0.
    "     .
  endif.
endform.                    "get_select_filename
*&---------------------------------------------------------------------*
*&      Form  manual_upld
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->LT_GT_DATA   text
*      -->P_FILENAME   text
*      -->P_BEGIN_COL  text
*      -->P_BEGIN_ROW  text
*      -->P_END_COL    text
*      -->P_END_ROW    text
*----------------------------------------------------------------------*
form manual_upld tables lt_gt_data
                 using p_filename
                       p_begin_col
                       p_begin_row
                       p_end_col
                       p_end_row.
  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
      filename    p_filename
      i_begin_col p_begin_col
      i_begin_row p_begin_row
      i_end_col   p_end_col
      i_end_row   p_end_row
    tables
      intern      lt_gt_data
    exceptions
      upload_ole  1.
  if sy-subrc ne 0.
    "     message i004(zmm)
  endif.
endform.                    "manual_upld

*&---------------------------------------------------------------------*
*&      Form  GET_STRING
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_TYPE  text
*      <--P_LV_STRING  text
*----------------------------------------------------------------------*
form get_string  using    p_type
                 changing p_string.
  data:lv_type type length 50.
  lv_type p_type.
  shift lv_type right deleting trailing space.
  shift lv_type left deleting leading space.
  if p_string is initial.
    p_string lv_type.
  else.
    concatenate p_string
           lv_type
          into p_string separated by cl_abap_char_utilities=>horizontal_tab.
  endif.

endform.                    " GET_STRING

*&---------------------------------------------------------------------*
*&      Form  get_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILENAME text
*      -->P_FILE     text
*      -->P_TEST     text
*      -->GV_FILE    text
*----------------------------------------------------------------------*
form get_file using p_filename p_file p_test p_ext
              changing gv_file .
  data: wa_key(30type c.
  data: lv_i type i.
  data: lv_c(1type c.
  data: wa_date(8type c.
  data: wa_time like sy-uzeit.
  data: lv_char type c.
  wa_date sy-datum.
  wa_time =  sy-uzeit.
  concatenate p_filename wa_date wa_time  into wa_key.
  concatenate wa_key p_ext  into wa_key. "'.txt'

  lv_i strlenp_file ).
  lv_i lv_i 1 .
  if lv_i > 1.
    lv_c p_file+lv_i(1).
  endif.
  if p_test 'X'.
    lv_char '\' .
  else.
    lv_char '/' .
  endif.
  if lv_c eq lv_char.
    concatenate p_file wa_key into gv_file.
  else.
    concatenate p_file lv_char wa_key into gv_file.
  endif.
endform.  "  get_file
*&---------------------------------------------------------------------*
*&      Form  download_local
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->GV_FILE    text
*----------------------------------------------------------------------*
form download_local  tables it_down
                     using  gv_file .
  data: lv_filename type string.
  lv_filename gv_file.

  call function 'GUI_DOWNLOAD'
    exporting
      filename                lv_filename
      filetype                'ASC'
      write_field_separator   'X'
    tables
      data_tab                it_down
    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 id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    " DOWNLOAD_LOCAL
*&---------------------------------------------------------------------*
*&      Form  download_server
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IT_DOWN    text
*      -->GV_FILE    text
*----------------------------------------------------------------------*
form download_server tables lt_down
                    using  gv_file .
  data: begin of it_down occurs 0,
        line type length 10000,
  end of it_down .
  it_down[] lt_down[].
  open dataset gv_file for output in text mode encoding default.
  loop at it_down.
    transfer it_down-line to gv_file.
  endloop.
  close dataset gv_file.
endform.                    " DOWNLOAD_SERVER

*&---------------------------------------------------------------------*
*&      Form  upload_local
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IT_UPLOAD  text
*      -->GV_FILE    text
*      -->P_SUBRC    text
*----------------------------------------------------------------------*
form upload_local tables it_upload
                  using  gv_file
                  changing p_subrc.
  data: lv_file  type string.

  lv_file gv_file.
  call function 'GUI_UPLOAD'
    exporting
      filename                lv_file
      filetype                'ASC'
      has_field_separator     'X'
    tables
      data_tab                it_upload
    exceptions
      file_open_error         1
      file_read_error         2
      no_batch                3
      gui_refuse_filetransfer 4
      invalid_type            5
      no_authority            6
      unknown_error           7
      bad_data_format         8
      header_not_allowed      9
      separator_not_allowed   10
      header_too_long         11
      unknown_dp_error        12
      access_denied           13
      dp_out_of_memory        14
      disk_full               15
      dp_timeout              16
      others                  17.
  p_subrc sy-subrc.
endform.                    "upload_local
*&---------------------------------------------------------------------*
*&      Form  upload_Server
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IT_UPLOAD  text
*      -->GV_FILE    text
*      -->P_SUBRC    text
*----------------------------------------------------------------------*
form upload_server tables lt_upload
                  using  gv_file
                  changing p_subrc.
  data: begin of it_upload  occurs 0,
        line type length 10000,
  end of it_upload  .
  it_upload[] lt_upload[].
  open dataset gv_file for input in text mode encoding default.
  p_subrc sy-subrc .
  if p_subrc 0.
    do.
      read dataset gv_file into it_upload.
      if sy-subrc ne 0.
        exit.
      endif.
      append it_upload.
    enddo.
    close dataset gv_file..
  endif.
endform.                    "upload_local

*&---------------------------------------------------------------------*
*&      Form  move_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FILENAME text
*      -->P_FULLNAME text
*      -->P_PATHBK   text
*      -->P_SUBRC    text
*----------------------------------------------------------------------*
form move_file  using    p_filename p_fullname p_pathbk
                changing p_subrc type sy-subrc.

  data: bak_filename type string,
        filename type string.

  data: str type string.

  filename p_fullname.
  condense filename.

  concatenate p_pathbk p_filename into bak_filename.

  open dataset p_fullname for input in text mode encoding default.
  p_subrc sy-subrc .
  if p_subrc 0.
    open dataset bak_filename for output in text mode encoding default.
    p_subrc sy-subrc .
    if p_subrc 0.
      do.
        read dataset p_fullname into str.
        if sy-subrc <> 0.
          exit.
        endif.

        transfer str to bak_filename.
      enddo.

      close dataset bak_filename.
*      write: 'File', filename,'has been moved to',bak_filename.
    else.
*      write: 'Backup directory is not valid'.
    endif.
    close dataset p_fullname.
  endif.

endform.                    " MOVE_FILE

*&---------------------------------------------------------------------*
*&      Form  select_DOWNLOAD_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PT_DATA    text
*      -->PT_HEADER  text
*----------------------------------------------------------------------*
form select_download_data using pt_data type standard table
                         pt_header type standard table.
  data: fullpath      type string,
        filename      type string,
        path          type string,
        user_action   type i,
        encoding      type abap_encoding.
* 路径
  call method cl_gui_frontend_services=>file_save_dialog
    exporting
      window_title         '导出'
      with_encoding        'X'
      initial_directory    'C:\'
    changing
      filename             filename
      path                 path
      fullpath             fullpath
      user_action          user_action
      file_encoding        encoding
    exceptions
      cntl_error           1
      error_no_gui         2
      not_supported_by_gui 3
      others               4.

  if sy-subrc <> 0.
    exit.
  endif.

  if user_action <> cl_gui_frontend_services=>action_ok.
    exit.
  endif.

  call function 'GUI_DOWNLOAD'
    exporting
      filename   fullpath
      filetype   'ASC'
    tables
      data_tab   pt_data
      fieldnames pt_header.
endform.                    "download_data
data:bdcdata like bdcdata occurs with header line.
data:bdcdata_wa like bdcdata.
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
  clear bdcdata.
  bdcdata-program  program.
  bdcdata-dynpro   dynpro.
  bdcdata-dynbegin 'X'.
  append bdcdata.
endform.                    "BDC_DYNPRO

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
  clear bdcdata.
  bdcdata-fnam fnam.
  bdcdata-fval fval.
  append bdcdata.
endform.                    "BDC_FIELD

define bdcdata_proj. " BDC数据准备--程序
  clear bdcdata_wa.
  bdcdata_wa-program  &1.
  bdcdata_wa-dynpro   &2.
  bdcdata_wa-dynbegin &3.
  append bdcdata_wa to bdcdata.
end-of-definition.

define bdcdata_fnam. " BDC数据准备--数据
  clear bdcdata_wa.
  bdcdata_wa-fnam  &1.
  bdcdata_wa-fval   &2.
  append bdcdata_wa to bdcdata.
end-of-definition.
*&---------------------------------------------------------------------*
*&      Form  change_date_format
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OLD_DATE text
*      -->P_EXTERNAL text
*      -->P_NEW_DATE text
*----------------------------------------------------------------------*
form change_date_format  using p_old_date
                              p_external
                        changing p_new_date.
  constants:c_chk_date like pa0001-ename value '0123456789/'.

  if p_external 'X'.
    call function 'CONVERT_DATE_TO_EXTERNAL'
      exporting
        date_internal            p_old_date
      importing
        date_external            p_new_date
      exceptions
        date_internal_is_invalid 1
        others                   2.
    if sy-subrc <> 0.
      clear:p_new_date.
    endif.
  else.
    check p_old_date is not initial.
    if p_old_date cn c_chk_date.
      p_new_date '00000000'.
    else.
      call function 'CONVERT_DATE_TO_INTERNAL'
        exporting
          date_external            p_old_date
        importing
          date_internal            p_new_date
        exceptions
          date_external_is_invalid 1
          others                   2.
      if sy-subrc ne 0.
        p_new_date '00000000'.
      endif.
    endif.
  endif.

endform.                    " CHANGE_DATE_FORMAT

*&---------------------------------------------------------------------*
*&      Form  convert_meins
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MATNR      text
*      -->P_MEINS_IN   text
*      -->P_MEINS_OUT  text
*      -->P_VAL        text
*----------------------------------------------------------------------*
form convert_meins using p_matnr type mchb-matnr
                         p_meins_in type meins
                         p_meins_out type meins
                   changing p_val type mseg-menge.

  if p_meins_in <> p_meins_out.

    call function 'MD_CONVERT_MATERIAL_UNIT'
      exporting
        i_matnr              p_matnr
        i_in_me              p_meins_in
        i_menge              p_val
        i_out_me             p_meins_out
      importing
        e_menge              p_val
      exceptions
        error_in_application 1
        error                2
        others               3.
  endif.
endform.                    "convert_meins

*&---------------------------------------------------------------------*
*&      Form  get_period
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DATE     text
*      -->P_COMP     text
*      -->P_LFGJA    text
*      -->P_LFMON    text
*----------------------------------------------------------------------*
form get_period using p_date  like bapi0002_4-posting_date
                      p_comp like bapi0002_2-comp_code
                changing p_lfgja like bapi0002_4-fiscal_year
                         p_lfmon like bapi0002_4-fiscal_period  .
  call function 'BAPI_COMPANYCODE_GET_PERIOD'
    exporting
      companycodeid p_comp
      posting_date  p_date
    importing
      fiscal_year   p_lfgja
      fiscal_period p_lfmon.
endform.                    " GET_PERIOD
*&---------------------------------------------------------------------*
*&      Form  transform_wbs
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OLD      text
*      -->P_OUTPUT   text
*      -->P_NEW      text
*----------------------------------------------------------------------*
form transform_wbs using p_old
                         p_output
                   changing p_new.
  check p_old is not initial.
  if p_output 'X'.
    call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
      exporting
        input  p_old
      importing
        output p_new.
  else.
    data:lv_input type length 50.
    lv_input p_old.
    translate   lv_input to upper case.
    call function 'CONVERSION_EXIT_ABPSP_INPUT'
      exporting
        input     lv_input
      importing
        output    p_new
      exceptions
        not_found 1
        others    2.
    if sy-subrc <> 0.
      clear:p_new.
    endif.
  endif.
endform.                    "transform_wbs
*&---------------------------------------------------------------------*
*&      Form  tranfer_material
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OLD      text
*      -->P_OUTPUT   text
*      -->P_NEW      text
*----------------------------------------------------------------------*
form  tranfer_material using    p_old
                                p_output
                       changing p_new  .
  if p_output 'X'.
    call function 'CONVERSION_EXIT_MATN1_OUTPUT'
      exporting
        input  p_old
      importing
        output p_new.
  else.
    data:lv_input type length 50.
    lv_input p_old.
    translate   lv_input to upper case.
    call function 'CONVERSION_EXIT_MATN1_INPUT'
      exporting
        input        lv_input
      importing
        output       p_new
      exceptions
        length_error 1
        others       2.
    if sy-subrc <> 0.
    endif.
  endif.
endform.                    "tranfer_material
*&---------------------------------------------------------------------*
*&      Form  ADD_PRE_ZERO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_RECORD_WEEKS_C  text
*      <--P_IT_RECORD_WEEKS_C  text
*----------------------------------------------------------------------*
form add_remove_pre_zero  using    p_old
                            p_output
                   changing p_new .
  if p_output 'X'.
    call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
      exporting
        input  p_old
      importing
        output p_new.
  else.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  p_old
      importing
        output p_new.
  endif.
endform.                    " ADD_PRE_ZERO
*&---------------------------------------------------------------------*
*&      Form  PROCESS_NUM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LT_GT_DATA_VALUE  text
*      <--P_IT_RECORD_KPEIN  text
*----------------------------------------------------------------------*
form process_num  using    p_value
                  changing p_change.
  data :lv_value type length 30 .
  constants:c_chk_num like pa0001-ename value '0123456789.,'.
  if p_value cn c_chk_num.
    p_change -1.
  else.
    lv_value  p_value.
    call function 'C14DG_CHAR_NUMBER_CONVERSION'
      exporting
        i_string                   lv_value
      importing
*       E_FLOAT                    =
        e_dec                      p_change
*       E_DECIMALS                 =
      exceptions
        wrong_characters           1
        first_character_wrong      2
        arithmetic_sign            3
        multiple_decimal_separator 4
        thousandsep_in_decimal     5
        thousand_separator         6
        number_too_big             7
        others                     8.
    if sy-subrc 7.
      p_change p_value.
    endif.
  endif.
endform.                    " PROCESS_NUM
*&---------------------------------------------------------------------*
*&      Form  Transform_order_type
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OLD      text
*      -->P_OUTPUT   text
*      -->P_NEW      text
*----------------------------------------------------------------------*
form transform_order_type  using    p_old
                                    p_output
                            changing p_new.
  if p_output 'X'.
    call function 'CONVERSION_EXIT_AUART_OUTPUT'
      exporting
        input  p_old
      importing
        output p_new.
  else.
    data:lv_input type length 50.
    lv_input p_old.
    translate   lv_input to upper case.
    call function 'CONVERSION_EXIT_AUART_INPUT'
      exporting
        input  lv_input
      importing
        output p_new.
  endif.
endform.                    " CONVERSION_ORDER_TYPE
*&---------------------------------------------------------------------*
*&      Form  get_pbdnr
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_PBDNR  text
*----------------------------------------------------------------------*
form get_pbdnr  changing p_p_pbdnr.
  data: begin of tab_pbdnr occurs 0.
          include structure cm60h.
  data:end of tab_pbdnr.

  data: begin of felder occurs 10.
          include structure help_value.
  data: end of felder.

  data: begin of xdynfields  occurs 10.
          include structure dynpread.
  data: end of xdynfields.

  data: xflag(1type value 'X'.
  data: l_index like sy-tabix.

  data: l_pbdnr like am60x-pbdnr,
        epbdnr like am60x-pbdnr,
        mpbdnr like am60x-pbdnr,
        it_cm60a like cm60a.

  clear felder. refresh felder.

*- Nummer  (Pick-Up)
  felder-tabname    'CM60H'.
  felder-fieldname  'PBDNR'.
  felder-selectflag xflag.
  append felder.

  clear felder.
*- Material
  felder-tabname    'CM60H'.
  felder-fieldname  'MATNR'.
  append felder.

*- Bedarfsart (Pick-Up)
  felder-tabname    'CM60H'.
  felder-fieldname  'BERID'.
  append felder.

*- Werk
  felder-tabname    'CM60H'.
  felder-fieldname  'WERKS'.
  append felder.

*- Bedarfsart (Pick-Up)
  felder-tabname    'CM60H'.
  felder-fieldname  'BEDAE'.
  append felder.

*- Version
  felder-tabname    'CM60H'.
  felder-fieldname  'VERSB'.
  append felder.

  call function 'REQUIREMENT_NUMBER'
    exporting
      icm60a    it_cm60a
    tables
      tab_pbdnr tab_pbdnr.

*--> Sort Result                                            "HW 665025
  sort tab_pbdnr by pbdnr matnr werks berid versb bedae.

  call function 'HELP_VALUES_GET_NO_DD_NAME'
    exporting
      display                      ' '
      selectfield                  'P_PBDNR'
*     TITEL                        = ' '
    importing
      ind                          l_index
    tables
      fields                       felder
      full_table                   tab_pbdnr
    exceptions
      full_table_empty             1
      no_tablestructure_given      2
      no_tablefields_in_dictionary 3
      more_then_one_selectfield    4
      no_selectfield               5
      others                       6.
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

  read table tab_pbdnr index l_index.
  if sy-subrc eq 0.
    p_p_pbdnr tab_pbdnr-pbdnr.
  endif.

endform.                    " GET_PBDNR
*&---------------------------------------------------------------------*
*&      Form  get_so_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OBJNR    text
*      -->P_STONR    text
*----------------------------------------------------------------------*
form get_so_status using p_objnr
                   changing p_stonr.
  call function 'STATUS_READ'
    exporting
      objnr            p_objnr
    importing
      stonr            p_stonr
    exceptions
      object_not_found 1
      others           2.
  if sy-subrc ne 0.
  endif.
endform.                    "get_so_STATUS
*&---------------------------------------------------------------------*
*&      Form  check_order_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OBJNR    text
*      -->P_LINE     text
*----------------------------------------------------------------------*
form check_order_status using p_objnr changing p_line.
  call function 'STATUS_TEXT_EDIT'
    exporting
      client            sy-mandt
*     FLG_USER_STAT     = ' '
      objnr             p_objnr
*     ONLY_ACTIVE       = 'X'
      spras             sy-langu
      bypass_buffer     'X'
    importing
*     ANW_STAT_EXISTING =
*     E_STSMA           =
      line              p_line
*     USER_LINE         =
*     STONR             =
    exceptions
      object_not_found  1
      others            2.
  if sy-subrc <> 0.
*    message 'Order Status error' type 'E'.
  endif.
endform.                    " CHECK_ORDER_STATUS
*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FC_HIER    text
*      -->ITAB       text
*      -->P_SAVE     text
*----------------------------------------------------------------------*
form display_alv tables fc_hier itab
                  using p_save .
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat        fc_hier[]
      i_save             p_save
      i_callback_program sy-repid
    tables
      t_outtab           itab[]
    exceptions
      program_error      1
      others             2.
endform.                    "display_alv
*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FC_HIER    text
*      -->ITAB       text
*      -->P_SAVE     text
*----------------------------------------------------------------------*
form display_alv2 tables fc_hier itab sort
                  using p_save .
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat        fc_hier[]
      i_save             p_save
      i_callback_program sy-repid
      sort               sort[]
    tables
      t_outtab           itab[]
    exceptions
      program_error      1
      others             2.
endform.                    "display_alv
*&---------------------------------------------------------------------*
*&      Form  zpopup_to_comfirm
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form zpopup_to_comfirm using p_text
                       changing  p_answer type c.
  call function 'POPUP_TO_CONFIRM'
    exporting
      text_question  p_text "'Delete or not ?'
    importing
      answer         p_answer
    exceptions
      text_not_found 1
      others         2.
endform.                    "zpopup_to_comfirm
*&---------------------------------------------------------------------*
*&      Form  get_text
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_text tables it_lines
              using p_id
                    p_langu
                    p_tdname type tdobname
                    p_object.
  call function 'READ_TEXT'
    exporting
      id                      p_id
      language                p_langu
      name                    p_tdname
      object                  p_object
    tables
      lines                   it_lines
    exceptions
      id                      1
      language                2
      name                    3
      not_found               4
      object                  5
      reference_check         6
      wrong_access_to_archive 7
      others                  8.
endform.                    "get_text
*&---------------------------------------------------------------------*
*&      Form  APPROVED_PO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_PO_REL_CODE1  text
*----------------------------------------------------------------------*
form approved_po  tables return
                  using  purchaseorder
                         p_po_rel_code.
  data:rel_status_new type bapimmpara-rel_status,
     rel_indicator_new type bapimmpara-po_rel_ind ,
     ret_code  type sy-subrc.

  call function 'BAPI_PO_RELEASE'
    exporting
      purchaseorder          purchaseorder
      po_rel_code            p_po_rel_code
    importing
      rel_status_new         rel_status_new
      rel_indicator_new      rel_indicator_new
      ret_code               ret_code
    tables
      return                 return
    exceptions
      authority_check_fail   1
      document_not_found     2
      enqueue_fail           3
      prerequisite_fail      4
      release_already_posted 5
      responsibility_fail    6
      others                 7.
  if sy-subrc eq 0.
    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait 'X'.
  endif.
endform.                    " APPROVED_PO
*&---------------------------------------------------------------------*
*&      Form  get_material_desc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MATNR    text
*      -->P_MAKTX    text
*----------------------------------------------------------------------*
form get_material_desc using p_matnr
                        changing p_maktx.
  select single maktx
    into p_maktx
    from makt
    where matnr eq p_matnr and
          spras eq sy-langu.
endform.                    "get_material_desc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值