在ABAP程序中调用逻辑数据库

使用函数: LDB_PROCESS

关键参数:

ldbname:逻辑数据库名称

callback:逻辑数据库的NODE对应的处理函数

selections:调用逻辑数据库的输入条件

相关帮助:

Structure of Logical Databases

Calling a Logical Database Using a Function Module

Independent Calls and the Database Program

遗憾的是在测试逻辑数据库PNM的时候,没有解决在一个程序中多次调用的问题。

具体的例子:

*&---------------------------------------------------------------------**& Report
 Z_READ_ROUTINE_LDB*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*
REPORT
 z_read_routine_ldb.
*&---------------------------------------------------------------------**& 输出ALV格式的报表需要INCLUDE的文件*&---------------------------------------------------------------------*INCLUDE zreusealv.
DATA: callback TYPE TABLE OF ldbcb,

 seltab TYPE TABLE OF rsparams.
FIELD-SYMBOLS: <fs> TYPE rsparams.
DATA: BEGIN OF itab OCCURS 0,

 parent like mara-matnr,

 vornr LIKE plpod-plnfl,

 matnr LIKE plmzd-matnr,

 maktx LIKE plmzd-maktx,

 END OF itab.
DATA: BEGIN OF it_mara OCCURS 0,

 matnr LIKE mara-matnr,

 END OF it_mara.
************************************************************************* START-OF-SELECTION************************************************************************START-OF-SELECTION.
 it_mara-matnr = '7200-01601'.
 APPEND it_mara.
 it_mara-matnr = '7200-01602'.
 APPEND it_mara.
* 设置已分配工序的组件回调函数* 设置已分配工序的组件回调函数* 设置未分配工序的组件回调函数
 PERFORM set_callback_form

 USING: 'PLPOD' 'CALLBACK_PLPOD',

 'PLMZD' 'CALLBACK_PLMZD',

 'PLMZN' 'CALLBACK_PLMZN'.
 LOOP AT it_mara.

 IF seltab[] IS INITIAL.

 PERFORM set_selection_screen

 USING: 'P' 'PN_PLNTY' 'N',

 'S' 'PN_MATNR' it_mara-matnr,

 'S' 'PN_WERKS' '1000',

 'P' 'PN_DATUV' sy-datum,

 'P' 'MAT'

 'X',

 'P' 'PN_CAP'

 'X',

 'P' 'PN_CAPID' 'PP01',

 'P' 'PN_MEHRS' 'X'.

 ELSE.

 READ TABLE seltab ASSIGNING <fs> INDEX 2.

 IF sy-subrc = 0.

 <fs>-low = it_mara-matnr.

 ENDIF.

 ENDIF.

 CALL FUNCTION 'LDB_PROCESS'

 EXPORTING

 ldbname

 = 'PNM'

 variant

 = ' '

 TABLES

 callback

 = callback

 selections

 = seltab

 EXCEPTIONS

 ldb_not_reentrant

 = 1

 ldb_incorrect

 = 2

 ldb_already_running

 = 3

 ldb_error

 = 4

 ldb_selections_error

 = 5

 ldb_selections_not_accepted = 6

 variant_not_existent

 = 7

 variant_obsolete

 = 8

 variant_error

 = 9

 free_selections_error

 = 10

 callback_no_event

 = 11

 callback_node_duplicate

 = 12

 OTHERS

 = 13.

 IF sy-subrc <> 0.

 WRITE: 'Exception with SY-SUBRC', sy-subrc.

 ENDIF.
 ENDLOOP.
************************************************************************* END-OF-SELECTION************************************************************************END-OF-SELECTION.* 输出报表的抬头
 REFRESH it_fieldcat.
 PERFORM sub_fill_fieldcat_alv

 USING: 'TAB_1' 'MARC' 'PARENT' '成品物料',

 'TAB_1' 'MARC' 'MATNR' '物料号',

 'TAB_1' 'MAKT' 'MAKTX' '物料描述',

 'TAB_1' 'PLPO' 'VORNR' '工序'.
* 输出报表
 PERFORM print_report_alv TABLES itab.

*&---------------------------------------------------------------------**&

 Form
 callback_plpod*&---------------------------------------------------------------------**

 text*----------------------------------------------------------------------**

 -->NAME

 text*

 -->WA

 text*

 -->EVT

 text*

 -->CHECK

 text*----------------------------------------------------------------------*FORM callback_plpod USING name
 TYPE ldbn-ldbnode

 wa

 TYPE plpod

 evt

 TYPE c

 check TYPE c.
 CLEAR itab.
 itab-vornr = wa-vornr.ENDFORM.

 "callback_plpod
*&---------------------------------------------------------------------**&

 Form
 CALLBACK_PLMZD*&---------------------------------------------------------------------**

 text*----------------------------------------------------------------------**

 -->NAME

 text*

 -->WA

 text*

 -->EVT

 text*

 -->CHECK

 text*----------------------------------------------------------------------*FORM callback_plmzd USING name
 TYPE ldbn-ldbnode

 wa

 TYPE plmzd

 evt

 TYPE c

 check TYPE c.
 itab-parent = it_mara-matnr.
 itab-matnr = wa-matnr.
 itab-maktx = wa-maktx.
 APPEND itab.ENDFORM.

 "CALLBACK_PLMZD
*&---------------------------------------------------------------------**&

 Form
 CALLBACK_PLMZN*&---------------------------------------------------------------------**

 text*----------------------------------------------------------------------**

 -->NAME

 text*

 -->WA

 text*

 -->EVT

 text*

 -->CHECK

 text*----------------------------------------------------------------------*FORM callback_plmzn USING name
 TYPE ldbn-ldbnode

 wa

 TYPE plmzn

 evt

 TYPE c

 check TYPE c.
 CLEAR itab.
 itab-parent = it_mara-matnr.
 itab-matnr = wa-matnr.
 itab-maktx = wa-maktx.
 APPEND itab.ENDFORM.

 "CALLBACK_PLMZN
*&---------------------------------------------------------------------**&

 Form
 set_callback_form*&---------------------------------------------------------------------**

 text*----------------------------------------------------------------------**

 -->NODE

 text*

 -->FORM_NAME
 text*----------------------------------------------------------------------*FORM set_callback_form USING node_name form_name.
 DATA: callback_wa LIKE ldbcb.
 callback_wa-ldbnode

 = node_name.
 callback_wa-get

 = 'X'.* callback_wa-get_late

 = 'X'.
 callback_wa-cb_prog

 = sy-repid.
 callback_wa-cb_form

 = form_name.
 APPEND callback_wa TO callback.ENDFORM.

 "set_callback_form
*&---------------------------------------------------------------------**&

 Form
 set_selection_screen*&---------------------------------------------------------------------**

 text*----------------------------------------------------------------------**

 -->KIND

 text*

 -->NAME

 text*

 -->LOW

 text*----------------------------------------------------------------------*FORM set_selection_screen USING kind selname low.
 DATA: seltab_wa LIKE rsparams.
 seltab_wa-kind = kind.
 seltab_wa-selname = selname.
 seltab_wa-sign = 'I'.
 seltab_wa-option = 'EQ'.
 seltab_wa-low = low.
 APPEND seltab_wa TO seltab.ENDFORM.

 "set_callback_form

Comments are closed.