0

如何从报表中检索客户主数据并打印?

我有客户编号,但我不知道检索其他详细信息的最佳方法是什么,例如:

  • 姓名
  • 街道地址
  • 沟通
  • (未来还有联系人)

在我的研究中,我发现了以下选项:

  • 查询 KNA1 和其他客户主数据表

  • BAPI_CUSTOMER_GETLIST

  • BAPI_CUSTOMER_GETDETAIL2

我需要一段可以在报告中打印客户主数据的代码片段。

4

2 回答 2

2

你可以试试功能模块BAPI_CUSTOMER_GETDETAIL2,它会返回CUSTOMERADDRESS

更重要的是,我在不到一分钟的时间内发现了这个

  • 开始交易BAPI
  • 单击“按字母顺序”选项卡
  • 寻找客户(我的猜测不错,但不是太难猜测)
  • 盯着方法,发现只有 GETDETAIL、GETDETAIL1 和 GETDETAIL2 可能
  • 双击GETDETAIL2(末尾的数字表示版本)
  • 请注意右侧详细信息窗格中功能模块的名称。

我的肩冲浪伙伴编码器告诉我,您也可以简单地查询BAPI_CUSTOMER_*,因为您发现 BAPI 明显遵循一种模式。

至于片段,您至少应该尝试让我们知道您失败的地方。

DATA : wa_address TYPE bapicustomer_04.

PARAMETERS p_kunnr TYPE kunnr.

CALL FUNCTION 'BAPI_CUSTOMER_GETDETAIL2'
  EXPORTING
    customerno      = p_kunnr
  IMPORTING
    customeraddress = wa_address.

WRITE: wa_address-name , wa_address-name_2 , wa_address-city , wa_address-country.
于 2013-03-21T17:50:57.827 回答
0

我会使用查询,试试这个:

report  ZKNA1.

tables: kna1.

type-pools slis.

data gt_fieldcat type slis_t_fieldcat_alv with header line.

data: gs_layout type slis_layout_alv,
g_repid type sy-repid.

types: begin of st_output,
    kunnr type kna1-kunnr,
    name1 type kna1-name1,
    city1 type adrc-city1,
    city2 type adrc-city2,
    street type adrc-street,
    tel_number type adrc-tel_number, " If you need more fields add them here and in the field catalog
end of st_output,
gt_tbl_data type standard table of st_output.

data gt_output type standard table of st_output.

data g_count type i.

data  t_heading type slis_t_listheader.

selection-screen: begin of block b2 with frame title text-t01.

select-options s_kunnr for kna1-kunnr.

select-options s_name1 for kna1-name1.

selection-screen: end of block b2.

initialization.
  g_repid = sy-repid.

start-of-selection.

  perform get_data.

  perform build_alv.

form init_layout.
  gs_layout-zebra = 'X'.
  gs_layout-detail_popup = 'X'.
endform.                    "init_layout

form get_data.
  field-symbols <wa_gt_output> type st_output.
  data zlen type i.

  select
    kna1~kunnr
    kna1~name1
    adrc~city1
    adrc~city2
    adrc~street
    adrc~tel_number
    from kna1
    left join adrc on adrc~addrnumber = kna1~adrnr
    into corresponding fields of table gt_output
    where
    kna1~kunnr in s_kunnr and
    kna1~name1 in s_name1
    order by
     kna1~kunnr
    .

  g_count = sy-dbcnt.

endform. " GET DATA

form build_alv.

* ALV required data objects.
  data: w_title   type lvc_title,
        w_comm    type slis_formname,
        w_status  type slis_formname,
        x_layout  type slis_layout_alv,
        t_event    type slis_t_event,
        t_fieldcat type slis_t_fieldcat_alv,
        t_sort     type slis_t_sortinfo_alv.

  refresh t_fieldcat.
  refresh t_event.
  refresh t_sort.
  clear x_layout.
  clear w_title.

* Layout
  perform init_layout.

* Field Catalog
  perform set_fieldcat using:
 1 'KUNNR' 'KUNNR' 'KNA1'           25 space  space  space space  space space space space space space space t_fieldcat,
 2 'NAME1' 'NAME1' 'KNA1'           25 space  space  space space  space space space space space space space t_fieldcat,
 3 'CITY1' 'CITY1' 'ADRC'           25 space  space  space space  space space space space space space space t_fieldcat,
 4 'CITY2' 'CITY2' 'ADRC'           25 space  space  space space  space space space space space space space t_fieldcat,
 5 'STREET' 'STREET' 'ADRC'         25 space  space  space space  space space space space space space space t_fieldcat,
 6 'TEL_NUMBER' 'TEL_NUMBER' 'ADRC' 25 space  space  space space  space space space space space space space t_fieldcat.

* Top of page heading
  perform set_top_page_heading using t_heading[] t_event.

* Events
  perform set_events using t_event.

* GUI Status
  w_status = ''.
  g_repid = sy-repid.

* User commands
  w_comm   = 'USER_COMMAND'.

* Order
* Example
*  PERFORM set_order USING '<field>' 'IT_DATA' 'X' space space t_sort.

  call function 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = g_repid
      is_layout                = gs_layout
      it_fieldcat              = t_fieldcat
      it_sort                  = t_sort
      i_callback_pf_status_set = w_status
      i_callback_user_command  = w_comm
      i_save                   = 'X'
      it_events                = t_event
      i_grid_title             = w_title
    TABLES
      t_outtab                 = gt_output
    EXCEPTIONS
      program_error            = 1
      others                   = 2.
  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. " build_alv

form set_top_page_heading using t_heading type slis_t_listheader
                                t_events  type slis_t_event.

  data: x_heading type slis_listheader,
        x_event   type line of slis_t_event.

  clear x_heading.
  x_heading-typ = 'S'.
  x_heading-key = 'Count: '.
  x_heading-info = g_count.
  append x_heading to t_heading.

* Top of page event
  x_event-name = slis_ev_top_of_page.
  x_event-form = 'TOP_OF_PAGE'.
  append x_event to t_events.

endform.                    "set_top_page_heading

form set_events using t_events type slis_t_event.

  data: x_event   type line of slis_t_event.

**
* Example
* -------
*  clear x_event.
*  x_event-name = .
*  x_event-form = .
*  append x_event to t_event.
**

endform.                    "set_events

form set_order using p_fieldname p_tabname p_up p_down p_subtot
                     t_sort type slis_t_sortinfo_alv.

  data: x_sort type slis_sortinfo_alv.

  clear x_sort.
  x_sort-fieldname = p_fieldname.
  x_sort-tabname   = p_tabname.
  x_sort-up = p_up.
  x_sort-down = p_down.
  x_sort-subtot = p_subtot.
  append x_sort to t_sort.


endform.                    "set_order

form set_fieldcat using
      p_colpos          "Column position.
      p_fieldname       "Field of internal table
      p_ref_fieldname   "(Optional) Table field / data element
      p_ref_tabname     "(Optional) Table which holds the field referenced
      p_outputlen       "(Optional) Column width
      p_noout           "(Optional) If set to 'X', states that the field is not showed initially
      p_seltext_m       "(Optional) Medium label
      p_seltext_l       "(Optional) Long label
      p_seltext_s       "(Optional) Small label
      p_reptext_ddic    "(Optional) Extra small (heading) label
      p_ddictxt         "(Optional) Set to 'L', 'M', 'S' or 'R'
      p_hotspot         "(Optional) If set to 'X', this field will be used as a hotspot area for cursor
      p_showasicon      "(Optional) If set to 'X', this field will be shown as an icon
      p_checkbox        "(Optional) If set to 'X', this field will be shown as a checkbox
      p_edit            "(Optional) If set to 'X', this field will be editable.
      p_dosum           "(Optional) If set to 'X', this field will be summed (aggregation function)
      t_fieldcat type slis_t_fieldcat_alv. "Table which contains the whole fieldcat.

  data: wa_fieldcat type slis_fieldcat_alv.

  clear wa_fieldcat.

* General settings
  wa_fieldcat-fieldname = p_fieldname.
  wa_fieldcat-col_pos = p_colpos.
  wa_fieldcat-no_out = p_noout.
  wa_fieldcat-hotspot = p_hotspot.
  wa_fieldcat-checkbox = p_checkbox.
  wa_fieldcat-icon = p_showasicon.
  wa_fieldcat-do_sum = p_dosum.

  if p_ref_tabname is initial.
    wa_fieldcat-rollname =   p_ref_fieldname.
  else.
    wa_fieldcat-ref_tabname = p_ref_tabname.
    if p_ref_fieldname eq space.
      wa_fieldcat-ref_fieldname =   wa_fieldcat-fieldname.
    else.
      wa_fieldcat-ref_fieldname =   p_ref_fieldname.
    endif.
  endif.

* Set output length.
  if not p_outputlen is initial.
    wa_fieldcat-outputlen = p_outputlen.
  endif.

* Set text headers.
  if not p_seltext_m is initial.
    wa_fieldcat-seltext_m = p_seltext_m.
  endif.

  if not p_seltext_l is initial.
    wa_fieldcat-seltext_l = p_seltext_l.
  endif.

  if not p_seltext_s is initial.
    wa_fieldcat-seltext_s = p_seltext_s.
  endif.

  if not p_reptext_ddic is initial.
    wa_fieldcat-reptext_ddic = p_reptext_ddic.
  endif.

  if not p_ddictxt is initial.
    wa_fieldcat-ddictxt = p_ddictxt.
  endif.

* Set as editable or not.
  if not p_edit is initial.
    wa_fieldcat-input     = 'X'.
    wa_fieldcat-edit     = 'X'.
  endif.

  append wa_fieldcat to t_fieldcat.

endform.                   "set_fieldcat2

form top_of_page.
  call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
*     i_logo             = <<If you want to set a logo, please,
*                          uncomment and edit this line>>
      it_list_commentary = t_heading.
endform.                    " alv_top_of_page

form user_command using r_ucomm     like sy-ucomm
                        rs_selfield type slis_selfield.

* Executes a command considering the sy-ucomm.
  case r_ucomm.
    when '&IC1'.

      if rs_selfield-fieldname eq 'KUNNR'.

        set parameter id 'KUN' field rs_selfield-value.
        call transaction 'XD03' and skip first screen. " Call transaction

      else.
        message 'Wrong column' type 'I'.
      endif.

  endcase.
endform.                    "user_command

检查您是否可以双击客户端代码并且程序会向您发送事务“XD03”。

于 2013-03-21T13:52:51.547 回答