第一个ABAP,感谢JOM_CH
加入双击跳转等功能,待加入权限控制
*&---------------------------------------------------------------------* *& Report ZFIRP0037 *&---------------------------------------------------------------------* *&回款查询表 2021-10-08 Create by z *&---------------------------------------------------------------------* 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, "过帐日期 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. **功能 程序 ** 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 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 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'. " 自适应宽度 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' '过帐日期' '' '' '' '' '' '' ''. 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 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*多借多贷也满足
活到老,学到老。