SAP License:如何建立应付暂估明细查询

SAP License:如何建立应付暂估明细查询 图1

应付暂估的明细查询还是很麻烦的一件事情,系统本身并不提供相关功能。其开发源代码如下:

*———————————————————————*
* Report  ZRFI0950
* Created By : SAP方丈                                                   *
* Created On : 2008/04/17                                              *
* Description: 1、查询暂估帐       *
*———————————————————————-*
* Modification Log                                                     *
*———————————————————————-*
* 01 Changed By  :                                                     *
*    Changed On  :                                                     *
*    Description :                                                     *
************************************************************************

REPORT  ZRFI0950.
***********************************************************************
* TABLES
***********************************************************************
tables:
  bkpf,
  kna1, “客户**
  knb1, “公司代码
  knc1, “会计年度
  bsid. “凭证日期

***********************************************************************
* ALV ABOUT
***********************************************************************
type-pools:
  slis.

DATA: i_events    TYPE slis_t_event          WITH HEADER LINE,
      i_fieldcat  TYPE slis_t_fieldcat_alv   WITH HEADER LINE,
      i_listcomm  TYPE slis_t_listheader     WITH HEADER LINE,
      i_layout    TYPE slis_layout_alv.
***********************************************************************
* GLOBAL VARIABLES
***********************************************************************
data: begin of gt_detail occurs 0,  ” 暂估入库列表
        hkont like bsis-hkont,  ” 科目号
        belnr like bsis-belnr,  ” 凭证编号
        buzei like bsis-buzei,  ” 凭证行项目
        shkzg like bsis-shkzg,  ” 借贷标识
        budat like bsis-budat,  ” 过帐日期
        dmbtr like bsis-dmbtr,  ” 发生金额
        ebeln like bseg-ebeln,  ” 采购凭证
        lifnr like ekko-lifnr,  ” 供应商号
        lname LIKE lfa1-name1,
        dnume type i,           ” 帐龄
      end of gt_detail,
      BEGIN OF gt_out OCCURS 0,
        id    type i, ” 序号
        lifnr LIKE ekko-lifnr, “供应商号
        lname like lfa1-name1, “供应商名
        ncdat like bsis-dmbtr, “年初余额
        qmdat like bsis-dmbtr, “期末余额
        qjone like bsis-dmbtr, “0-90天
        qjtwo like bsis-dmbtr, “91-180
        qjthr like bsis-dmbtr, “181-270
        qjfou like bsis-dmbtr, “271-360
        qjfiv like bsis-dmbtr, “>360
      END OF gt_out.
data: gt_ebeln LIKE STANDARD TABLE OF gt_detail WITH HEADER LINE,
      wa_lname LIKE lfa1-name1.

***********************************************************************
* INTERNAL TABLES AND WORK AREAS
***********************************************************************
selection-screen begin of block count with frame title text-001.
  parameters: p_budat like bsis-budat obligatory default sy-datum.
selection-screen end of block count.
***********************************************************************
* EVENT
***********************************************************************

start-of-selection.
  perform get_data.
  perform process_data.
end-of-selection.
  perform data_output.

***======>>>>>> End of main program <<<<<<======***

************************************************************************
* FORM 子程序
************************************************************************
form get_data.
  select a~hkont a~belnr a~buzei a~shkzg a~budat a~dmbtr b~txt50
    from bsis as a join GL_ACCT_CA_TEXT as b on a~hkont = b~SAKNR
    into CORRESPONDING FIELDS OF table gt_detail
   where hkont = “2202980000”
     and budat <= p_budat.

  select a~hkont a~belnr a~buzei a~shkzg a~budat a~dmbtr b~txt50
    from bsas as a join GL_ACCT_CA_TEXT as b on a~hkont = b~SAKNR
    appending CORRESPONDING FIELDS OF table gt_detail
   where hkont = “2202980000”
     and budat <= p_budat.
endform.

form process_data.
  data year(4) type n VALUE “0000”.
  year = p_budat+0(4) – 1.
  loop at gt_detail.
    if gt_detail-shkzg = “S”.
      gt_detail-dmbtr = 0 – gt_detail-dmbtr.
    endif.

    select single ebeln from bseg
      into gt_detail-ebeln
     where belnr = gt_detail-belnr
       and buzei = gt_detail-buzei
       and gjahr = gt_detail-budat+0(4).
    select single lifnr from ekko
      into gt_detail-lifnr
     where ebeln = gt_detail-ebeln.

    gt_detail-dnume = p_budat – gt_detail-budat.
    gt_out-lifnr = gt_detail-lifnr.

    IF gt_detail-budat+0(4) <= year.
      gt_out-ncdat = gt_detail-dmbtr.
    ENDIF.
    gt_out-qmdat = gt_detail-dmbtr.
    if gt_detail-dnume <= 90.
      gt_out-qjone = gt_detail-dmbtr.
    elseif gt_detail-dnume <= 180.
      gt_out-qjtwo = gt_detail-dmbtr.
    elseif gt_detail-dnume <= 270.
      gt_out-qjthr = gt_detail-dmbtr.
    elseif gt_detail-dmbtr <= 360.
      gt_out-qjfou = gt_detail-dmbtr.
    else.
      gt_out-qjfiv = gt_detail-dmbtr.
    endif.

    COLLECT gt_out.
    CLEAR gt_out.

    modify gt_detail.
    clear gt_detail.
  endloop.
  sort gt_out by lifnr.
  loop at gt_out.
    gt_out-id = sy-tabix.
    SELECT SINGLE NAME1 FROM LFA1
      INTO GT_OUT-LNAME
     WHERE LIFNR = GT_OUT-LIFNR.
    MODIFY gt_out.
    clear gt_out.
  ENDLOOP.

endform.

FORM data_output.
  PERFORM events_build.
  PERFORM layout_build.
  PERFORM fields_build.
  CALL FUNCTION “REUSE_ALV_GRID_DISPLAY”
    EXPORTING
      i_callback_program = sy-repid
      i_save             = “”
      i_callback_user_command  = “USER_COMMAND”
      is_layout          = i_layout
      it_events          = i_events[]
      it_fieldcat        = i_fieldcat[]
    TABLES
      t_outtab           = gt_out.

ENDFORM.                    “data_output

FORM events_build .
  CALL FUNCTION “REUSE_ALV_EVENTS_GET”
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = i_events[].
  READ TABLE i_events WITH KEY name = slis_ev_top_of_page.
  IF sy-subrc = 0.
    i_events-form = “ALV_TOP_OF_PAGE”.
    MODIFY i_events INDEX sy-tabix.
  ENDIF.
ENDFORM.                    “events_build

*&———————————————————————*
*&      Form  alv_top_of_page
*&———————————————————————*
*       text
*———————————————————————-*
FORM alv_top_of_page.
  DATA itoc(10) TYPE c.
  DATA: lv_temp(60).
  CLEAR: i_listcomm,i_listcomm[].
  i_listcomm-typ = “H”.
  i_listcomm-key = “”.
  i_listcomm-info = “材料暂估表”.
  APPEND i_listcomm.
  CLEAR i_listcomm.

  i_listcomm-typ = “S”.
  lv_temp = “编制单位:”.
  APPEND i_listcomm.
  CLEAR  i_listcomm.

  i_listcomm-typ = “S”.
  CONCATENATE “查询时间: ” p_budat+0(4) “年” p_budat+4(2) “月” p_budat+6(2) “日”
         INTO lv_temp.
  i_listcomm-info = lv_temp.
  APPEND i_listcomm.
  CLEAR  i_listcomm.

  CALL FUNCTION “REUSE_ALV_COMMENTARY_WRITE”
    EXPORTING
      it_list_commentary = i_listcomm[].
ENDFORM.                    “alv_top_of_page

*&———————————————————————*
*&      Form  layout_build
*&———————————————————————*
*       text
*———————————————————————-*
FORM layout_build .
  i_layout-zebra                = “X”.
  i_layout-detail_popup         = “X”.
  i_layout-no_vline             = “”.
  i_layout-colwidth_optimize    = “X”.
  i_layout-detail_initial_lines = “X”.
  i_layout-detail_titlebar      = “物料暂估明细”.
ENDFORM.                    ” layout_build

* alv ??
FORM fields_build.
  i_fieldcat-key = “X”.
  PERFORM alv_field_column USING “ID” “序号”.
  i_fieldcat-key = “X”.
  PERFORM alv_field_column USING “LIFNR” “供应商号”.
  i_fieldcat-key = “X”.
  PERFORM alv_field_column USING “LNAME” “供应商名称”.
  i_fieldcat-key = “X”.
  PERFORM alv_field_column USING “NCDAT” “年初余额”.
  i_fieldcat-key = “X”.
  PERFORM alv_field_column USING “QMDAT” “期末余额”.
  PERFORM alv_field_column USING “QJONE” “0-90天”.
  PERFORM alv_field_column USING “QJTWO” “91-180天”.
  PERFORM alv_field_column USING “QJTHR” “181-270天”.
  PERFORM alv_field_column USING “QJFOU” “271-360天”.
  PERFORM alv_field_column USING “QJFIV” “大于360天”.
ENDFORM.                    “fields_build

*&———————————————————————*
*&      Form  alv_field_column
*&———————————————————————*
*       text
*———————————————————————-*
*      –>VALUE(P_FIELDNAME)  text
*      –>VALUE(P_SELTEXT_L)  text
*———————————————————————-*
FORM alv_field_column USING value(p_fieldname)
      value(p_seltext_l).

  i_fieldcat-fieldname   = p_fieldname.
  i_fieldcat-seltext_l   = p_seltext_l.
  IF p_fieldname+0(2) CP “QJ” OR p_fieldname+0(2) CP “NC” OR p_fieldname+0(2) = “QM”.
    i_fieldcat-edit_mask   = “==Z001”.
  ENDIF.
  APPEND i_fieldcat.
  CLEAR  i_fieldcat.
ENDFORM.                    “alv_field_column

FORM user_command USING r_ucomm LIKE sy-ucomm
      rs_selfield TYPE slis_selfield.

  CASE r_ucomm.
    WHEN “&IC1”.
      if rs_selfield-fieldname = “LIFNR”. “供应商.
          CLEAR gt_ebeln[].
          PERFORM data_reapp using rs_selfield-value.
          perform data_outputb.
      endif.

  ENDCASE.
ENDFORM.

form data_reapp using lifnr.
  SELECT single name1 from lfa1 into wa_lname.
  loop at gt_detail where lifnr = lifnr.
    select single aedat from ekko into gt_ebeln-budat WHERE ebeln = gt_detail-ebeln.
    gt_ebeln-lifnr = lifnr.
    gt_ebeln-lname = wa_lname.
    gt_ebeln-ebeln = gt_detail-ebeln.
    gt_ebeln-dmbtr = gt_detail-dmbtr.
    COLLECT gt_ebeln.
    CLEAR: gt_detail, gt_ebeln.
  ENDLOOP.
  sort gt_ebeln by ebeln.
endform.
FORM data_outputb.
  CLEAR: i_layout,i_events[],i_fieldcat[].
  PERFORM events_buildb.
  PERFORM layout_buildb.
  PERFORM fields_buildb.
  CALL FUNCTION “REUSE_ALV_GRID_DISPLAY”
    EXPORTING
      i_callback_program = sy-repid
      i_save             = “”
      i_callback_user_command  = “USER_COMMANDB”
      is_layout          = i_layout
      it_events          = i_events[]
      it_fieldcat        = i_fieldcat[]
    TABLES
      t_outtab           = gt_ebeln.

ENDFORM.                    “data_output

FORM events_buildb .
  CALL FUNCTION “REUSE_ALV_EVENTS_GET”
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = i_events[].
  READ TABLE i_events WITH KEY name = slis_ev_top_of_page.
  IF sy-subrc = 0.
    i_events-form = “ALV_TOP_OF_PAGEB”.
    MODIFY i_events INDEX sy-tabix.
  ENDIF.
ENDFORM.                    “events_build

*&———————————————————————*
*&      Form  alv_top_of_page
*&———————————————————————*
*       text
*———————————————————————-*
FORM alv_top_of_pageb.
  DATA itoc(10) TYPE c.
  DATA: lv_temp(60).
  CLEAR: i_listcomm,i_listcomm[].
  i_listcomm-typ = “H”.
  i_listcomm-key = “”.
  i_listcomm-info = “材料暂估表-供应商明细”.
  APPEND i_listcomm.
  CLEAR i_listcomm.

  i_listcomm-typ = “S”.
  lv_temp = “编制单位:”.
  APPEND i_listcomm.
  CLEAR  i_listcomm.

  i_listcomm-typ = “S”.
  CONCATENATE “供应商:” wa_lname  “. 查询时间: ” p_budat+0(4) “年” p_budat+4(2) “月” p_budat+6(2) “日”
         INTO lv_temp.
  i_listcomm-info = lv_temp.
  APPEND i_listcomm.
  CLEAR  i_listcomm.

  CALL FUNCTION “REUSE_ALV_COMMENTARY_WRITE”
    EXPORTING
      it_list_commentary = i_listcomm[].
ENDFORM.                    “alv_top_of_page

*&———————————————————————*
*&      Form  layout_build
*&———————————————————————*
*       text
*———————————————————————-*
FORM layout_buildb .
  i_layout-zebra                = “X”.
  i_layout-detail_popup         = “X”.
  i_layout-no_vline             = “”.
  i_layout-colwidth_optimize    = “X”.
  i_layout-detail_initial_lines = “X”.
  i_layout-detail_titlebar      = “采购凭证明细”.
ENDFORM.                    ” layout_build

* alv ??
FORM fields_buildb.
  PERFORM alv_field_columnb USING “LIFNR” “供应商”.
  PERFORM alv_field_columnb USING “LNAME” “供应名称”.
  PERFORM alv_field_columnb USING “EBELN” “采购凭证”.
  PERFORM alv_field_columnb USING “BUDAT” “订单创建时间”.
  PERFORM alv_field_columnb USING “DMBTR” “采购成交金额”.
ENDFORM.                    “fields_build

*&———————————————————————*
*&      Form  alv_field_column
*&———————————————————————*
*       text
*———————————————————————-*
*      –>VALUE(P_FIELDNAME)  text
*      –>VALUE(P_SELTEXT_L)  text
*———————————————————————-*
FORM alv_field_columnb USING value(p_fieldname)
      value(p_seltext_l).

  i_fieldcat-fieldname   = p_fieldname.
  i_fieldcat-seltext_l   = p_seltext_l.
  IF p_fieldname+0(2) CP “DM”.
    i_fieldcat-edit_mask   = “==Z001”.
  ENDIF.
  APPEND i_fieldcat.
  CLEAR  i_fieldcat.
ENDFORM.                    “alv_field_column

FORM user_commandb USING r_ucomm LIKE sy-ucomm
      rs_selfield TYPE slis_selfield.

  CASE r_ucomm.
    WHEN “&IC1”.
      if rs_selfield-fieldname = “EBELN”. “供应商.
          SET PARAMETER ID “BES” FIELD rs_selfield-value.
          CALL TRANSACTION “ME23N” AND SKIP FIRST SCREEN.
      endif.

  ENDCASE.
ENDFORM.

关于赛锐信息

河南赛锐信息科技有限公司(简称“赛锐信息”)是一家致力于SAP ERP系统应用的服务商,公司立足打造基于AMS产品套件的企业信息化解决方案,结合前沿技术追求最佳用户体验、企业信息化优秀解决方案和企业级产品应用的供应商。公司自主研发的AMS系列软件产品是国内首个用于SAP权限风险识别的增强系统,也是同行业用户精益化管理解决方案中最优的解决方案,作为用户管理、风险规避和信息审计的辅助工具,其有助于规范企业的管理行为,帮助建立合规的管控流程,有效提高企业IT资产投资回报率;AMS系列产品在各项技术指标上拥有完全的、独立的领先优势,可以满足市场竞争、技术许可和标准制定等方面的需要。

作者:SAP权限管理 QQ:2651000673

相关新闻

联系我们

联系我们

130-0752-1773

在线咨询:点击这里给我发消息

邮件:info@sapzx.com

工作时间:周一至周五9:00-18:00,节假日正常休息

关注微信
关注微信
分享本页
返回顶部