往事隨風:SAP檢視程式程式碼方式

一贴灵發表於2024-11-14

1、點“系統"--狀態

2、在狀態視窗中,”程式”文字框中為該事務碼的程式,雙擊可以開啟原始碼;,

4

*&---------------------------------------------------------------------*
*& Report ZFIRP0037
*&---------------------------------------------------------------------*
*&回款查詢表 2021-10-08 Create by Yitieling
*&---------------------------------------------------------------------*
REPORT zfirp0037.
TABLES :bseg,kna1.

**定義結構

TYPES: BEGIN OF gty_out,
         bukrs   LIKE bseg-bukrs,   "公司程式碼
         belnr   LIKE bseg-belnr,   "憑證編號
         gjahr   LIKE bseg-gjahr,   "年度
         h_bldat LIKE bseg-h_bldat, "票據日期
         hkont   LIKE bseg-hkont,   "借方科目
         shkzg   LIKE bseg-shkzg,   "借貸
         hkont1  LIKE bseg-hkont,   "貸方科目
         kunnr   LIKE bseg-kunnr,   "客戶號
         name1   LIKE kna1-name1,   "客戶名稱
         xref1   LIKE bseg-xref1,   "業務員
         wrbtr   LIKE bseg-wrbtr,   "金額
         sgtxt   LIKE bseg-sgtxt,   "摘要
         h_blart LIKE bseg-h_blart, "憑證型別
         prctr   LIKE bseg-prctr, "利潤中心
         h_budat LIKE bseg-h_budat, "過帳日期
         vtweg   TYPE vtweg,
       END OF gty_out.

*標準的ALV輸出
* slis 型別池 全域性變數 定義,多數沒用,
DATA: g_repid             TYPE sy-repid,
      g_line              TYPE slis_fieldcat_alv,
      gt_fieldcat         TYPE slis_t_fieldcat_alv,
      gt_layout           TYPE slis_layout_alv,
      gt_sortinfo         TYPE slis_sortinfo_alv,
      gt_lvc_title        TYPE lvc_title,
      gt_list_top_of_page TYPE slis_t_listheader,
      gt_events           TYPE slis_t_event,
      gt_fcat             TYPE lvc_t_fcat,
      gt_table            TYPE REF TO data,
      gs_settings         TYPE lvc_s_glay,
      f2code              LIKE sy-ucomm VALUE '&TEA'.
DATA g_status_set         TYPE slis_formname VALUE 'SET_STATUS'.


* 定義用於輸出的內表
DATA: gt_tab TYPE STANDARD TABLE OF gty_out WITH HEADER LINE.
DATA: gt_tab2 TYPE STANDARD TABLE OF gty_out WITH HEADER LINE.

**定義雙擊執行事務程式碼 用,  猜的
DATA ok_code LIKE sy-ucomm.

DATA: g_ucomm LIKE sy-ucomm VALUE '&IC1'.

DATA:   bdcdata LIKE bdcdata    OCCURS 0 WITH HEADER LINE."用來儲存螢幕欄位引數值,傳遞錄屏引數
*       messages of call transaction
DATA:   messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE."記錄執行BDC過程中產生的訊息
DATA: ls_mss LIKE bdcmsgcoll.

*選擇螢幕
SELECT-OPTIONS:
  s_kunnr FOR bseg-kunnr,"客戶號
  s_bukrs FOR bseg-bukrs,"公司程式碼
  s_prctr FOR bseg-prctr,"利潤中心
  s_xref1 FOR bseg-xref1,"業務員
  s_ktokd FOR kna1-ktokd,"客戶組
  s_pzlx FOR kna1-ktokd,"憑證型別
  s_rq FOR bseg-h_bldat OBLIGATORY.

AT SELECTION-SCREEN.
  PERFORM frm_chk_auth_prctr.
**功能 程式
** 1 正常回款
START-OF-SELECTION.
  SELECT DISTINCT
    b~bukrs,
    b~belnr,
    b~gjahr,
    b~h_bldat,
    a~hkont,
    b~shkzg,
    b~hkont,
    b~kunnr,
    c~name1,
    b~xref1,
    b~wrbtr,
    b~sgtxt,
    b~h_blart,
    b~prctr,
    b~h_budat,
b~xref2 AS vtweg
  INTO TABLE @gt_tab
  FROM   bseg AS a
  INNER JOIN  bseg AS b
      ON a~bukrs = b~bukrs AND a~belnr = b~belnr AND a~gjahr = b~gjahr
  INNER JOIN kna1 AS c
    ON b~kunnr = c~kunnr
  WHERE ( a~hkont LIKE '1002%' OR a~hkont LIKE '1121%'  OR a~hkont LIKE '1012%' )  "1002*銀行存款  1121 應收票據 1012 其它貨幣資金   1122* 應收帳款
       AND a~shkzg = 'S'
      AND ( b~hkont LIKE '1122%'  )
      AND b~shkzg = 'H'
       AND b~h_monat <> '000' AND b~kunnr <> ''
       AND c~ktokd IN @s_ktokd           "客戶類別
      AND b~bukrs IN @s_bukrs
      AND b~kunnr IN @s_kunnr
      AND b~xref1 IN @s_xref1
      AND b~h_blart IN @s_pzlx
      AND a~prctr IN @s_prctr         "利潤中心
      AND b~h_bldat IN  @s_rq.

**2 處理退款調款 ,需要變為負數
  SELECT DISTINCT
    b~bukrs,
    b~belnr,
    b~gjahr,
    b~h_bldat,
    a~hkont,
    b~shkzg,
    b~hkont,
    b~kunnr,
    c~name1,
    b~xref1,
    b~wrbtr,
    b~sgtxt,
    b~h_blart,
    b~prctr,
    b~h_budat,
    b~xref2 AS vtweg
  INTO TABLE @gt_tab2
  FROM        bseg AS a
  INNER JOIN  bseg AS b
  ON a~bukrs = b~bukrs AND a~belnr = b~belnr AND a~gjahr = b~gjahr
  INNER JOIN kna1 AS c
  ON b~kunnr = c~kunnr
  WHERE ( a~hkont LIKE '1002%' OR a~hkont LIKE '1121%'  OR a~hkont LIKE '1012%' )
       AND a~shkzg = 'H'
  AND ( b~hkont LIKE '1122%'   )
  AND b~shkzg = 'S'
   AND b~h_monat <> '000' AND b~kunnr <> ''
  AND c~ktokd IN @s_ktokd           "客戶類別
  AND b~bukrs IN @s_bukrs
  AND b~kunnr IN @s_kunnr
  AND b~xref1 IN @s_xref1
  AND b~h_blart IN @s_pzlx
  AND a~prctr IN @s_prctr         "利潤中心
  AND b~h_bldat IN  @s_rq.

**FIELD-SYMBOL 指標 可直接更改內表欄位的值 .
  LOOP AT gt_tab2 ASSIGNING FIELD-SYMBOL(<fs_out>).
    <fs_out>-wrbtr =  <fs_out>-wrbtr * -1.
  ENDLOOP.

  APPEND LINES OF  gt_tab2 TO gt_tab.

**去掉前導000
  LOOP AT gt_tab ASSIGNING FIELD-SYMBOL(<fs_out2>).
    SHIFT <fs_out2>-kunnr LEFT DELETING LEADING '0'.
    SHIFT <fs_out2>-belnr LEFT DELETING LEADING '0'.
    SHIFT <fs_out2>-prctr LEFT DELETING LEADING '0'.
  ENDLOOP.


END-OF-SELECTION.

**執行函式
  PERFORM frm_show_alv.


* 輸出 alv 報表
FORM frm_show_alv .

  DEFINE append_alv_field.
    CLEAR g_line.
    g_line-fieldname    = &1.
    g_line-tabname      = 'GT_ALV'.
    g_line-reptext_ddic = &2.
    g_line-seltext_l    = &2.
    g_line-seltext_m    = &2.
    g_line-seltext_s    = &2.
    g_line-cfieldname   = &3.
    g_line-ctabname     = &4.
    g_line-no_out       = &5.
    g_line-no_zero      = &6.
    g_line-outputlen    = &7.
    g_line-qfieldname   = &8.
    g_line-just         = &9.
    g_line-ddictxt      = 'L'.
    g_line-do_sum       = 'X'.
    APPEND g_line TO gt_fieldcat.
  END-OF-DEFINITION.

**ALV 顯示欄位
  REFRESH:gt_fieldcat.
  gt_layout-colwidth_optimize = 'X'. " 自適應寬度
  gt_layout-zebra = 'X'. " 自適應寬度
  append_alv_field 'BUKRS' '公司' '' '' '' '' '' '' ''.
  append_alv_field 'H_BLDAT' '票據日期' '' '' '' '' '' '' ''.
  append_alv_field 'BELNR' '憑證號' '' '' '' '' '' '' ''.
  append_alv_field 'KUNNR' '客戶號' '' '' '' '' '' '' ''.
  append_alv_field 'NAME1' '客戶名稱' '' '' '' '' '' '' ''.
  append_alv_field 'XREF1' '業務員' '' '' '' '' '' '' ''.
  append_alv_field 'HKONT' '借方科目' '' '' '' '' '' '' ''.
  append_alv_field 'SHKZG' '借貸' '' '' '' '' '' '' ''.
  append_alv_field 'HKONT1' '貸方科目' '' '' '' '' '' '' ''.
  append_alv_field 'WRBTR' '金額' '' '' '' '' '' '' ''.
  append_alv_field 'SGTXT' '摘要' '' '' '' '' '' '' ''.
  append_alv_field 'H_BLART' '型別' '' '' '' '' '' '' ''.
  append_alv_field 'PRCTR' '利潤中心' '' '' '' '' '' '' ''.
  append_alv_field 'H_BUDAT' '過帳日期' '' '' '' '' '' '' ''.
  append_alv_field 'VTWEG' '渠道' '' '' '' '' '' '' ''.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      "i_callback_pf_status_set = g_status_set "'FORM_PF_STATUS_SET'
      "i_callback_user_command 設定滑鼠或鍵盤事件, 雙擊呼叫其它事件的,FORM_USER_COMMAND 須在後面單獨定義
      i_callback_user_command = 'FORM_USER_COMMAND' "雙擊事件呼叫命令處,客戶命令指定子程式
      is_layout               = gt_layout
      it_fieldcat             = gt_fieldcat
    TABLES
      t_outtab                = gt_tab "指定要顯示的內表名稱
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDFORM.

***雙擊聯查原始憑證,引數:憑證號,公司程式碼,年度
FORM form_user_command USING i_ucomm LIKE sy-ucomm "雙擊
                           is_selfield TYPE slis_selfield.  "選擇的行數
  CASE i_ucomm .
    WHEN '&IC1'."雙擊事件
      READ TABLE gt_tab INDEX is_selfield-tabindex.
      IF sy-subrc = 0.
        IF is_selfield-value IS NOT INITIAL.
*          IF is_selfield-fieldname = 'belnr'."選中行的列名=憑證編號
          SET PARAMETER ID 'BLN' FIELD gt_tab-belnr.
          SET PARAMETER ID 'GJR' FIELD gt_tab-gjahr.
*          ENDIF.
          SET PARAMETER ID 'BUK' FIELD gt_tab-bukrs.
          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
        ENDIF.
      ENDIF.
  ENDCASE.
ENDFORM.

**許可權檢查
FORM frm_chk_auth_prctr.
  DATA: message      TYPE string.
  SELECT prctr,bukrs
    INTO TABLE @DATA(t_auth)
    FROM cepc_bukrs
    WHERE prctr IN @s_prctr AND bukrs IN @s_bukrs AND kokrs = '8000'.
  LOOP AT t_auth INTO DATA(wa_auth).
    AUTHORITY-CHECK OBJECT 'K_PCAR_REP'
     ID 'BUKRS' FIELD wa_auth-bukrs
     ID 'PRCTR' FIELD wa_auth-prctr
     ID 'KSTAR' DUMMY.
*  ID 'ACTVT' FIELD 'xxxxxxxx'.
    IF sy-subrc <> 0.
      message = '公司程式碼:' && wa_auth-bukrs && '利潤中心:' && wa_auth-prctr.
      MESSAGE e053(zmm) WITH  message.
    ENDIF.
  ENDLOOP.


ENDFORM.

*FORM form_pf_status_set  USING rt_extab TYPE slis_t_extab.
*
*  SET PF-STATUS 'STANDARD'.
*ENDFORM.
*FORM no_zero CHANGING clike.
*  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
*    EXPORTING
*      input  = clike
*    IMPORTING
*      output = clike.
*ENDFORM.
**********
*MODULE user_command_0100 INPUT.
*  CASE ok_code.
*    WHEN 'OK'.
*
*      LEAVE TO SCREEN 0.
*    WHEN 'CAN'.
*      LEAVE TO SCREEN 0.
*    WHEN OTHERS.
*  ENDCASE.
*ENDMODULE.
*在ACDOCA表中,公司程式碼RBUKRS,會計年度GJAHR,借貸標識DRCRK,期間POPER(排除期間為00),科目號RACCT,利潤中心PRCTR,客戶KUNNR,公司程式碼貨幣RHCUR,以公司程式碼貨幣計金額 HSL,
**1)以公司程式碼,年度,期間 為選擇條件,篩選出憑證編碼BELNR為集合一
*2)在集合一的基礎上,篩選出滿足:
*(借貸標識DRCRK=S,科目號RACCT=1002*或者1121*,借貸標識DRCRK=H,科目號RACCT=1122* )或者
*(借貸標識DRCRK=S,科目號RACCT=1122*,借貸標識DRCRK=H,科目號RACCT=1002*或者1121*)的憑證編碼為集合二
****************3)取集合二兩種情況的應收賬款RACCT=1122* 所在行的公司程式碼金額HSL,以及客戶KUNNR(客戶為空的排除掉),利潤中心PRCTR,金額求和之後乘以負一
****************舉例:借方1002*貸方1122*滿足,借方1121*貸方1122*滿足,借1002*借1121*貸1122*貸1122*多借多貸也滿足

相關文章