Abap 获取客户主信息
如何从报告中检索客户主数据并打印 我有客户编号但我不知道检索其他详细信息的最佳方法,例如:Abap 获取客户主信息,abap,sap-erp,Abap,Sap Erp,如何从报告中检索客户主数据并打印 我有客户编号但我不知道检索其他详细信息的最佳方法,例如: 名字 街道地址 沟通 (将来也可联系联系人) 在我的研究中,我发现了以下选项: 查询KNA1和其他客户主数据表 BAPI_客户_获取列表 BAPI_客户_获取详细信息2 我需要一段代码,可以在报告中打印Customer master。我要使用查询,请尝试以下操作: report ZKNA1. tables: kna1. type-pools slis. data gt_fieldca
- 名字
- 街道地址
- 沟通
- (将来也可联系联系人)
- 查询KNA1和其他客户主数据表
- BAPI_客户_获取列表
- BAPI_客户_获取详细信息2
我需要一段代码,可以在报告中打印Customer master。我要使用查询,请尝试以下操作:
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
报告ZKNA1。
表:1。
键入池SLI。
数据gt_fieldcat类型slis_t_fieldcat_alv,带标题行。
数据:gs\U布局类型slis\U布局\U alv,
g_repid类型sy repid。
类型:开始st_输出,
KUNR型kna1 KUNR,
名称1类型kna1-name1,
city1型adrc-city1,
city2型adrc-city2,
街道类型adrc街,
电话号码键入adrc-tel号码,“如果需要更多字段,请在此处和字段目录中添加它们
st_输出结束,
gt_tbl_st_输出的数据类型标准表。
数据gt_输出类型st_输出的标准表。
数据g_计数类型i。
数据标题类型slis\U t\U listheader。
选择屏幕:以框标题文本-t01开始块b2。
为kna1 KUNR选择选项s_KUNR。
为kna1-name1选择选项s_name1。
选择屏幕:b2区结束。
初始化。
g_repid=sy repid。
开始选择。
执行获取数据。
执行build_alv。
形成初始布局。
gs_布局-zebra='X'。
gs_布局-详细信息_弹出窗口='X'。
endform.“初始布局”
表单获取数据。
字段符号类型st_输出。
数据类型i。
选择
kna1~KUNR
kna1~name1
adrc~城市1
adrc~city2
adrc街
adrc~电话号码
来自kna1
adrc~addrnumber=kna1~adrnr上的左连接adrc
进入表格gt_输出的相应字段
哪里
s_kunnr中的kna1~kunnr和
s_name1中的kna1~name1
订购人
kna1~KUNR
.
g_计数=sy dbcnt。
尾型。“获取数据
表单build_alv。
*ALV所需的数据对象。
数据:w_标题类型lvc_标题,
w_通信类型slis_formname,
w_状态类型slis_formname,
x_布局类型slis_布局\u alv,
t_事件类型slis_t_事件,
t_fieldcat型slis_t_fieldcat_alv,
分拣类型slis\U t\U sortinfo\U alv。
刷新t_fieldcat。
刷新t_事件。
刷新t_排序。
清除x_布局。
清除w_标题。
*布局
执行初始布局。
*字段目录
使用以下工具执行set_fieldcat:
1“KUNNR”KUNNR“KNA1”25空间t_fieldcat,
2'名称1''名称1''KNA1'25空间t_fieldcat,
3“城市1”城市1“ADRC”25空间t_fieldcat,
4“CITY2”CITY2“ADRC”25空间t_fieldcat,
5“街道”“街道”“ADRC”25空间t_fieldcat,
6‘电话号码’‘电话号码’‘ADRC’25太空猫。
*页首标题
使用t_heading[]t_事件执行设置页面标题。
*事件
使用t_事件执行set_事件。
*图形用户界面状态
w_状态=“”。
g_repid=sy repid。
*用户命令
w_comm='USER_COMMAND'。
*命令
*范例
*使用“”IT_数据“”X“”空间t_排序执行集合顺序。
调用函数“重用\u ALV\u网格\u显示”
出口
i_callback_program=g_repid
is_布局=gs_布局
it_fieldcat=t_fieldcat
it_sort=t_sort
i\u回调\u pf\u状态\u集=w\u状态
i_回调_用户_命令=w_命令
i_save='X'
it_事件=t_事件
i_网格_标题=w_标题
桌子
t_outtab=gt_输出
例外情况
程序错误=1
其他=2。
如果sy subrc为0。
消息id sy msgid类型sy msgty编号sy msgno和sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4。
恩迪夫。
endform.“build_alv”
使用标题类型slis\U t\U listheader形成集合\U顶部\U页面\U标题
t_事件类型slis_t_事件。
数据:x_标题类型slis_列表标题,
slis\U t\U事件的x\U事件类型行。
清除x_标题。
x_heading-typ='S'。
x_heading-key='Count:'。
x_heading-info=g_count。
将x_标题附加到t_标题。
*页面顶部事件
x_event-name=slis_ev_页面顶部。
x_event-form=‘页面顶部’。
将x_事件附加到t_事件。
尾型。“设置页面顶部标题”
使用t_事件类型slis_t_事件形成集合_事件。
数据:slis\U t\U事件的x\U事件类型行。
**
*范例
* -------
*清除x_事件。
*x_事件名称=。
*x_事件形式=。
*将x_事件附加到t_事件。
**
endform.“设置事件”
使用p_字段名p_选项卡名p_向上p_向下p_小计形成集合顺序
分拣类型slis\U t\U sortinfo\U alv。
数据:x_排序类型slis_sortinfo_alv。
清除x_排序。
x_sort-fieldname=p_fieldname。
x_sort-tabname=p_tabname。
x_排序=p_排序。
x_排序=p_排序。
x_sort-subtot=p_subtot。
将x_排序附加到t_排序。
尾型。“定秩序
表单集\u fieldcat使用
p_colpos“列位置。
p_fieldname“内部表的字段
p_ref_fieldname”(可选)表格字段/数据元素
p_ref_tabname”(可选)表,其中包含引用的字段
p_outputlen“(可选)列宽
p_noout”(可选)如果设置为“X”,则表示最初未显示该字段
p_seltext_m“(可选)介质标签
p_seltext_l“(可选)长标签
p_seltext
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.