欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ABAP 报表程序模板

程序员文章站 2024-01-01 09:30:22
...

主要在report程序中划分了四个不同内容的include程序,方便代码整理和排查,同时简化开发过程。

Report

********************************************************************
* 事务代码:*****                                                *
* 程序名称:*****                                     *
* 使用变式:                                                       *
* 设 计 人:SEELE                                                  *
* 设计时间:2021-06-07                                             *
* 程序类型: REPORT                                                 *
* 应用类型: **                                                     *
* 描    述: *****                                 *
*(修改日志)--------------------------------------------------------*
*                                                                  *
* 日志号   修改人  修改时间       修改说明                         *
*  ----    ------   ------       -----------                       *
* 001      SEELE   2021-06-07     创建报表                         *
********************************************************************

"TOP: 包含变量和常量的声明
INCLUDE ZWMR_STORAGE_PRINT_top.

"S01: 包含选择屏幕元素
INCLUDE ZWMR_STORAGE_PRINT_s01.

"E01: 包含所有选择屏幕事件
INCLUDE ZWMR_STORAGE_PRINT_e01.

"F01: 包含所有子例程
INCLUDE ZWMR_STORAGE_PRINT_f01.

INCLUDE ZWMR_STORAGE_PRINT_top.

*&---------------------------------------------------------------------*
*& 包含               ZWMR_STORAGE_PRINT_TOP
*&---------------------------------------------------------------------*

REPORT: ZWMR_STORAGE_PRINT.

"---------------->> Define global constants
CONSTANTS:
  gc_flag_x          TYPE char1     VALUE 'X',                     "Flag: X
  gc_f_set_status    TYPE char30    VALUE 'F_SET_STATUS',          "Callback routine for PF status
  gc_f_user_command  TYPE char30    VALUE 'F_USER_COMMAND',        "Callback routine for user command
  gc_frm_caller_exit TYPE char30    VALUE 'FRM_CALLER_EXIT',       "Callback routine event
*  gc_uc_back         TYPE sy-ucomm  VALUE '&BACK',                 "Command for back
*  gc_uc_exit         TYPE sy-ucomm  VALUE '&EXIT',                 "Command for exit
*  gc_uc_cancel       TYPE sy-ucomm  VALUE '&CANCEL',               "Command for cancel
*  gc_uc_print        TYPE sy-ucomm  VALUE '&PRINT',                "Command for cancel
  gc_mode_a          TYPE char1     VALUE 'A',                     "Mode: A
  gc_mode_e          TYPE char1     VALUE 'E',                     "Mode: A
  gc_formname        TYPE tdsfname  VALUE 'ZWM_SF_STORAGE_PRINT',  "Form: ZWM_SF_STORAGE_PRINT
  gc_structure       TYPE tabname   VALUE 'ZWMS_STORAGE_ALV'.    "Structure: ZWMS_STORAGE_ALV



*"---------------->> Define global types
TYPES:BEGIN OF gty_data.
        INCLUDE TYPE ZWMS_STORAGE_ALV.
TYPES:END OF gty_data.                        "type to create main table


"---------------->> Define global variables
DATA:
  BEGIN OF gs_select,
    RSNUM     TYPE ZWMS_STORAGE_ALV-RSNUM,
    MATNR     TYPE RESB-MATNR,
    CHARG     TYPE ZWMS_STORAGE_ALV-CHARG,
    GERNR     TYPE ZWMS_STORAGE_ALV-GERNR,
    LGORT     TYPE RESB-LGORT,
    UMLGO     TYPE RESB-UMLGO,
    NAME_TEXT TYPE ZWMS_STORAGE_ALV-NAME_TEXT,
    RSDAT     TYPE ZWMS_STORAGE_ALV-RSDAT,
  END OF gs_select,                           "structure for selection fields

  gt_data     TYPE TABLE OF gty_data,         "table to display
  gs_data     TYPE  gty_data,                 "table to display
  gr_grid     TYPE REF TO cl_gui_alv_grid,    "ALV Grid
  gs_layout   TYPE lvc_s_layo,                "ALV Layout
  gt_fieldcat TYPE lvc_t_fcat.                "ALV Fieldcat

ZWMR_STORAGE_PRINT_S01

*&---------------------------------------------------------------------*
*& 包含               ZWMR_STORAGE_PRINT_S01
*&---------------------------------------------------------------------*

SELECT-OPTIONS:
    s_rsnum  FOR gs_select-rsnum ,      "调拨单
    s_matnr  FOR gs_select-matnr,       "物料编码
    s_charg  FOR gs_select-charg,       "批次
    s_gernr  FOR gs_select-gernr,      "***
    s_lgort  FOR gs_select-lgort,       "发出仓库
    s_umlgo  FOR gs_select-umlgo,       "收货仓库
    s_name   FOR gs_select-name_text,   "制单人
    s_rsdat  FOR gs_select-rsdat.       "制单日期

PARAMETERS p_rk   RADIOBUTTON GROUP rd USER-COMMAND flag2 DEFAULT 'X'.
PARAMETERS p_ck RADIOBUTTON GROUP rd.

INCLUDE ZWMR_STORAGE_PRINT_e01.

*&---------------------------------------------------------------------*
*& 包含               ZWMR_STORAGE_PRINT_E01
*&---------------------------------------------------------------------*

START-OF-SELECTION.

  PERFORM frm_auth_check.
  PERFORM frm_get_data.
  IF sy-subrc = 4 OR gt_data[] IS INITIAL.
    MESSAGE s001(zmm01) DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.
  PERFORM frm_process_data.

END-OF-SELECTION.

  PERFORM frm_display_data.

ZWMR_STORAGE_PRINT_F01

*&---------------------------------------------------------------------*
*& 包含               ZWMR_STORAGE_PRINT_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_init_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_init_data .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_auth_check
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_auth_check .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .
  DATA: BEGIN OF lw_rq,
          rsnum LIKE resb-rsnum,
          matnr LIKE resb-matnr,
          scrq  LIKE zwms_storage_alv-scrq,
          dqr   LIKE zwms_storage_alv-dqr,
        END OF lw_rq.
  DATA lt_rq LIKE TABLE OF lw_rq.
  RANGES s_bwart FOR resb-bwart.
  DATA ls_bwart LIKE LINE OF s_bwart.

*移动类型RESB-BWART=301/311的行项目
  ls_bwart-sign = 'I'.
  ls_bwart-option = 'EQ'.
  ls_bwart-low = '301'.
  APPEND ls_bwart TO s_bwart.
  ls_bwart-sign = 'I'.
  ls_bwart-option = 'EQ'.
  ls_bwart-low = '311'.
  APPEND ls_bwart TO s_bwart.

* 获取主表数据
  SELECT
    resb~rsnum,
    resb~rspos,
    resb~matnr,
*    makt~maktx,
*    mara~groes,
    rkpf~rsdat,
    resb~bdmng - resb~enmng AS fnmng,
    resb~charg,
    zppt_res_seqnr~gernr,
    resb~meins,
    resb~lgort,
    resb~umlgo
  FROM resb
  LEFT JOIN rkpf ON resb~rsnum = rkpf~rsnum
  LEFT JOIN zppt_res_seqnr ON resb~rsnum = zppt_res_seqnr~rsnum
  INTO TABLE @DATA(lt_data)
  WHERE
    resb~rsnum IN @s_rsnum AND
    resb~matnr IN @s_matnr AND
    resb~charg IN @s_charg AND
    rkpf~rsdat IN @s_rsdat AND
    zppt_res_seqnr~gernr IN @s_gernr AND
    resb~lgort IN @s_lgort AND
    resb~umlgo IN @s_umlgo AND
    resb~xloek = '' AND
    resb~xwaok = 'X' AND
    resb~kzear = ''  AND
    resb~bwart IN @s_bwart.

* 没查询到数据,避免后续使用for all entries in
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.

* 获取物料数据
  SELECT
    resb~rsnum,
    makt~maktx,
    mara~groes,
    mara~matnr
  FROM resb
  LEFT JOIN makt ON resb~matnr = makt~matnr
  LEFT JOIN mara ON resb~matnr = mara~matnr
  FOR ALL ENTRIES IN @lt_data
  WHERE
    resb~rsnum = @lt_data-rsnum AND
    makt~matnr = @lt_data-matnr
  INTO TABLE @DATA(lt_makt).

* 获取批次和***标识
  SELECT
    resb~rsnum,
    resb~matnr,
    marc~xchpf,
    marc~sernp
  FROM resb
  LEFT JOIN marc ON resb~matnr = marc~matnr AND resb~werks = marc~werks
  FOR ALL ENTRIES IN @lt_data
  WHERE
    resb~matnr = @lt_data-matnr AND
    resb~rsnum = @lt_data-rsnum
  INTO TABLE @DATA(lt_con).

  DATA: lt_con1 LIKE lt_con,
        lt_con2 LIKE lt_con.

  LOOP AT lt_con INTO DATA(lw_con).
    IF lw_con-xchpf = 'X' AND lw_con-sernp = ''.
      APPEND lw_con TO lt_con1.
    ELSEIF lw_con-xchpf = '' AND lw_con-sernp = 'Z001'.
      APPEND lw_con TO lt_con2.
    ENDIF.
  ENDLOOP.

*获取生产日期和有效期
  "若批次标识MARC-XCHPF=X,***标识MARC-SERNP=“”获取两个日期
  IF lt_con1[] IS NOT INITIAL.
    SELECT
      resb~rsnum,
      resb~matnr,
      mch1~hsdat AS scrq,
      mch1~vfdat AS dqr
    FROM resb
    INNER JOIN mch1 ON resb~matnr = mch1~matnr AND resb~charg = mch1~charg
    FOR ALL ENTRIES IN @lt_con1
    WHERE
      resb~matnr = @lt_con1-matnr AND
      resb~rsnum = @lt_con1-rsnum
    INTO TABLE @DATA(lt_rq1).

    LOOP AT lt_rq1 INTO DATA(lw_rq1).
      CLEAR lw_rq.
*   第一种情况的到期日需要查询
      lw_rq-rsnum = lw_rq1-rsnum.
      lw_rq-matnr = lw_rq1-matnr.
      lw_rq-scrq  = lw_rq1-scrq.
      lw_rq-dqr   = lw_rq1-dqr.
      APPEND lw_rq TO lt_rq.
    ENDLOOP.
  ENDIF.

  "若批次标识MARC-XCHPF=“”,***标识MARC-SERNP=Z001获取两个日期
  IF lt_con2[] IS NOT INITIAL.
    SELECT
      resb~rsnum,
      resb~matnr,
      equi~sernr,
      equi~erdat AS scrq,
      zppt_res_seqnr~gernr
    FROM resb
    LEFT JOIN equi ON equi~matnr = resb~matnr
    LEFT JOIN zppt_res_seqnr ON equi~sernr = zppt_res_seqnr~gernr
    FOR ALL ENTRIES IN @lt_con2
    WHERE
      resb~matnr = @lt_con2-matnr AND
      resb~rsnum = @lt_con2-rsnum
      INTO TABLE @DATA(lt_rq2).

  ENDIF.

* 制单人
  SELECT
    resb~rsnum,
    rkpf~usnam,
    usr21~persnumber,
    adrp~name_text
  FROM rkpf
  LEFT JOIN resb  ON resb~rsnum = rkpf~rsnum
  LEFT JOIN usr21 ON rkpf~usnam = usr21~bname
  LEFT JOIN adrp  ON usr21~persnumber = adrp~persnumber
  FOR ALL ENTRIES IN @lt_data
  WHERE
    adrp~name_text IN @s_name AND
    resb~rsnum = @lt_data-rsnum
  INTO TABLE @DATA(lt_name).

* 入库部门
  SELECT
    resb~rsnum,
    rkpf~usnam,
    usr21~persnumber,
    adcp~department
  FROM resb
  LEFT JOIN rkpf  ON resb~rsnum = rkpf~rsnum
  LEFT JOIN usr21 ON rkpf~usnam = usr21~bname
  LEFT JOIN adcp  ON usr21~persnumber = adcp~persnumber
  FOR ALL ENTRIES IN @lt_data
  WHERE
    resb~rsnum = @lt_data-rsnum
  INTO TABLE @DATA(lt_depart).

* 发货库存地点名称
  SELECT
    resb~rsnum,
    t001l~lgobe AS FHDD
  FROM resb
  LEFT JOIN t001l ON resb~lgort = t001l~lgort
  FOR ALL ENTRIES IN @lt_data
  WHERE
    resb~rsnum = @lt_data-rsnum
  INTO TABLE @DATA(lt_fhdd).

* 收货库存地点名称
  SELECT
    resb~rsnum,
    t001l~lgobe AS SHDD
  FROM resb
  LEFT JOIN t001l ON resb~umlgo = t001l~lgort
  FOR ALL ENTRIES IN @lt_data
  WHERE
    resb~rsnum = @lt_data-rsnum
  INTO TABLE @DATA(lt_shdd).

  SORT: lt_rq     BY rsnum,
        lt_rq2    BY rsnum sernr,
        lt_name   BY rsnum,
        lt_makt   BY rsnum matnr,
        lt_depart BY rsnum,
        lt_fhdd   BY rsnum,
        lt_shdd   BY rsnum.


  LOOP AT lt_data INTO DATA(lw_data).
    CLEAR gs_data.

    MOVE-CORRESPONDING lw_data TO gs_data.

    READ TABLE lt_makt INTO DATA(lw_makt) WITH KEY rsnum = lw_data-rsnum matnr = lw_data-matnr BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING lw_makt TO gs_data.
    ENDIF.

*   lt_rq是第一种情况的生产日期和到期日
    READ TABLE lt_rq INTO lw_rq WITH KEY rsnum = lw_data-rsnum BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING lw_rq TO gs_data.
    ENDIF.

*   lt_rq2是第二种情况的生产日期和到期日,需要加上主键***相同
    READ TABLE lt_rq2 INTO DATA(lw_rq2) WITH KEY rsnum = lw_data-rsnum sernr = lw_data-gernr BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING lw_rq2 TO gs_data.
      gs_data-dqr = gs_data-scrq + 3652.
    ENDIF.

    READ TABLE lt_name INTO DATA(lw_name) WITH KEY rsnum = lw_data-rsnum BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING lw_name TO gs_data.
    ENDIF.
    IF gs_data-name_text NOT IN s_name.
      CONTINUE.
    ENDIF.
    CLEAR lw_name.

    READ TABLE lt_depart INTO DATA(lw_depart) WITH KEY rsnum = lw_data-rsnum BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING lw_depart TO gs_data.
    ENDIF.

    READ TABLE lt_fhdd INTO DATA(lw_fhdd) WITH KEY rsnum = lw_data-rsnum BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING lw_fhdd TO gs_data.
    ENDIF.

    READ TABLE lt_shdd INTO DATA(lw_shdd) WITH KEY rsnum = lw_data-rsnum BINARY SEARCH.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING lw_shdd TO gs_data.
    ENDIF.

*   生产调拨入库申请单,限制收货库存地点=3001/3002;
    IF p_rk = 'X' AND ( gs_data-umlgo EQ '3001' OR gs_data-umlgo EQ '3002' ).
      APPEND gs_data TO gt_data.
    ENDIF.

*   仓库调拨申请单,限制收货地点≠3001/3002
    IF p_ck = 'X' AND ( gs_data-umlgo NE '3001' AND gs_data-umlgo NE '3002' ).
      APPEND gs_data TO gt_data.
    ENDIF.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_process_data
*&---------------------------------------------------------------------*
*& 处理获取到的数据
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_process_data .

  LOOP AT gt_data INTO gs_data.
    IF gs_data-gernr IS NOT INITIAL.
      gs_data-fnmng = '1'.
    ENDIF.
    MODIFY gt_data FROM gs_data.
  ENDLOOP.

  SORT gt_data BY RSNUM RSPOS LGORT UMLGO RSDAT NAME_TEXT.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_display_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_display_data .
  PERFORM frm_set_layout.
  PERFORM frm_set_fieldcat.

  "Display ALV
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      is_layout_lvc            = gs_layout
      it_fieldcat_lvc          = gt_fieldcat
      i_callback_user_command  = gc_f_user_command      "F_USER_COMMAND
      i_callback_pf_status_set = gc_f_set_status        "F_SET_STATUS
      i_save                   = gc_mode_a              "A
    TABLES
      t_outtab                 = gt_data
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_layout
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_set_layout .
  "Set Layout
  gs_layout = VALUE #(
                       SEL_MODE   = 'D'
                       cwidth_opt = gc_flag_x                   "Optimize column width
                       zebra      = gc_flag_x                   "Alternating line color
                       no_toolbar = gc_flag_x                   "Hide toolbar
    ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_set_fieldcat .
  "Generate fieldcat dynamically
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name   = gc_structure                         "Table name
      i_bypassing_buffer = gc_flag_x
    CHANGING
      ct_fieldcat        = gt_fieldcat.                         "Field Catalog

  LOOP AT gt_fieldcat ASSIGNING FIELD-SYMBOL(<fs_fieldcat>).

    CASE <fs_fieldcat>-fieldname.
      WHEN 'RSNUM'.
        <fs_fieldcat>-coltext = '调拨单号'.
        <fs_fieldcat>-key     = gc_flag_x.
      WHEN 'RSPOS'.
        <fs_fieldcat>-coltext = '行号'.
        <fs_fieldcat>-key     = gc_flag_x.
*      WHEN 'GERNR'.
*        <fs_fieldcat>-coltext = '***'.
*        <fs_fieldcat>-key     = gc_flag_x.
      WHEN 'MATNR'.
        <fs_fieldcat>-coltext = '物料编码'.
      WHEN 'MEINS'.
        <fs_fieldcat>-coltext = '单位'.
      WHEN 'NAME_TEXT'.
        <fs_fieldcat>-coltext = '制单人'.
      WHEN 'RSDAT'.
        <fs_fieldcat>-coltext = '制单时间'.
      WHEN 'DEPARTMENT'.
        <fs_fieldcat>-coltext = '入库部门'.
      WHEN 'LGORT'.
        <fs_fieldcat>-coltext = '发货库存地点'.
      WHEN 'FHDD'.
        <fs_fieldcat>-coltext = '发货库存地点名称'.
      WHEN 'UMLGO'.
        <fs_fieldcat>-coltext = '收货库存地点'.
      WHEN 'SHDD'.
        <fs_fieldcat>-coltext = '收货库存地点名称'.
      WHEN OTHERS.
    ENDCASE.

  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_SET_STATUS
*&---------------------------------------------------------------------*
*& This subroutine is used to set PF status.
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_set_status USING it_extab TYPE slis_t_extab.
  "Customizing pf_status

  SET PF-STATUS 'Z_PF_STATUS'.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_USER_COMMAND
*&---------------------------------------------------------------------*
*& This subroutine is used to process user command event.
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_user_command USING iv_ucomm    LIKE sy-ucomm
                          is_selfield TYPE slis_selfield.
  "Get ALV grid
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = gr_grid.

  "Refresh Internal Table after ALV changed
  gr_grid->check_changed_data( ).

  "React to command
  CASE iv_ucomm.
    WHEN 'PRT'.     "&PRINT

      gr_grid->get_selected_rows( IMPORTING et_row_no = DATA(lt_selected_rows) ).
      IF lt_selected_rows IS NOT INITIAL.
        PERFORM frm_print_form USING lt_selected_rows.
      ELSE.
        MESSAGE s001(zqm01) DISPLAY LIKE gc_mode_e.
      ENDIF.
  ENDCASE.

  "Refresh ALV
  PERFORM f_refresh_alv.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_REFRESH_ALV
*&---------------------------------------------------------------------*
*& This subroutine is used to refresh ALV.
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_refresh_alv.
  "Reset the layout
  gr_grid->set_frontend_layout( is_layout = gs_layout ).

  "Refresh ALV display
  gr_grid->refresh_table_display( is_stable = VALUE lvc_s_stbl( row = gc_flag_x
                                                                col = gc_flag_x ) ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_PRINT_FORM
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_print_form USING it_rows TYPE lvc_t_roid.
  DATA: lv_fname           TYPE tdsfname,
        ls_control_param   TYPE ssfctrlop,
        ls_composer_param  TYPE ssfcompop,
        ls_outopt          TYPE ssfcresop,
        ls_job_output_info TYPE ssfcrescl.
  DATA: lt_sf_i TYPE TABLE OF ZWMS_STORAGE_SFI,         "table to display
        lw_sf_i LIKE LINE OF lt_sf_i,
        ls_sf_h TYPE ZWMS_STORAGE_SFH,
        lt_data LIKE gt_data,
        lt_data_temp LIKE gt_data,  "存放选中相同调拨单号的所有行项目
        lv_index TYPE I VALUE 1,
        lv_flag  TYPE C VALUE '',
        lv_title TYPE CHAR20.


  CALL FUNCTION 'SSF_OPEN'
    EXPORTING
      control_parameters = ls_control_param
      output_options     = ls_composer_param
    IMPORTING
      job_output_options = ls_outopt
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.

  "Get form name
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname = gc_formname
    IMPORTING
      fm_name  = lv_fname.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  ls_control_param-langu    = sy-langu.
  ls_control_param-no_open  = gc_flag_x.
  ls_control_param-no_close = gc_flag_x.

  lt_data  = VALUE #( FOR ls_row IN it_rows
                   ( CORRESPONDING #( VALUE #( gt_data[ ls_row-row_id ] OPTIONAL ) ) ) ).
  SORT lt_data BY RSNUM RSPOS LGORT UMLGO RSDAT NAME_TEXT.

*选中一个行项目也可打印所有调拨单号相同的行项目
  LOOP AT lt_data INTO DATA(lw_data).
    READ TABLE gt_data TRANSPORTING NO FIELDS WITH KEY rsnum = lw_data-rsnum  BINARY SEARCH.
    IF sy-subrc = 0.
      lv_index = sy-tabix.

      SORT lt_data_temp.
      READ TABLE lt_data_temp TRANSPORTING NO FIELDS WITH KEY rsnum = lw_data-rsnum BINARY SEARCH.
      IF sy-subrc = 0.
        CONTINUE.
      ENDIF.

      LOOP AT gt_data FROM lv_index INTO gs_data.
        IF lw_data-rsnum <> gs_data-rsnum.
          EXIT.
        ENDIF.
        APPEND gs_data TO lt_data_temp.
        CLEAR gs_data.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

  CLEAR lt_data[].
  MOVE lt_data_temp TO lt_data.
  SORT lt_data BY RSNUM RSPOS LGORT UMLGO RSDAT NAME_TEXT.
  lv_index = 1.

  LOOP AT lt_data INTO DATA(lw_data_this).
    lv_index = lv_index + 1.
    READ TABLE lt_data INTO DATA(lw_data_next) INDEX lv_index.
    IF sy-subrc <> 0.
      READ TABLE lt_data INTO lw_data_next INDEX lv_index - 2.
      MOVE-CORRESPONDING lw_data_this TO ls_sf_h.
      lv_flag = 'X'.
    ENDIF.

    IF lw_data_this-rsnum EQ lw_data_next-rsnum AND
        lw_data_this-lgort EQ lw_data_next-lgort AND
        lw_data_this-umlgo EQ lw_data_next-umlgo AND
        lw_data_this-rsdat EQ lw_data_next-rsdat AND
        lw_data_this-name_text EQ lw_data_next-name_text.

      MOVE-CORRESPONDING lw_data_this TO lw_sf_i.
      APPEND lw_sf_i TO lt_sf_i.
    ELSE.
      MOVE-CORRESPONDING lw_data_this TO lw_sf_i.
      APPEND lw_sf_i TO lt_sf_i.
      MOVE-CORRESPONDING lw_data_this TO ls_sf_h.
      lv_flag = 'X'.
    ENDIF.

    IF lv_flag EQ 'X'.
      IF p_rk = 'X'.
        lv_title = '成品入库调拨申请单'.
      ELSE.
        lv_title = '仓库调拨申请单'.
      ENDIF.

      CALL FUNCTION lv_fname
        EXPORTING
          control_parameters = ls_control_param
          output_options     = ls_composer_param
*         user_settings      = ''
          gs_head            = ls_sf_h
          gv_title           = lv_title
        TABLES
          gt_item            = lt_sf_i
        EXCEPTIONS
          formatting_error   = 1
          internal_error     = 2
          send_error         = 3
          user_canceled      = 4
          OTHERS             = 5.
      IF sy-subrc <> 0.

      ENDIF.
      CLEAR lt_sf_i[].
      CLEAR ls_sf_h.
      lv_flag = ''.
    ENDIF.

  ENDLOOP.

*  LOOP AT gt_data INTO DATA(ls_data) .
**    MOVE-CORRESPONDING ls_data TO is_data.

*  ENDLOOP.

  CALL FUNCTION 'SSF_CLOSE'
    IMPORTING
      job_output_info  = ls_job_output_info
    EXCEPTIONS
      formatting_error = 1
      internal_error   = 2
      send_error       = 3
      OTHERS           = 4.
ENDFORM.
相关标签: sap abap

上一篇:

下一篇: