ABAP 通过LDB_PROCESS函数使用逻辑数据库

2020-11-27 10:37:04 浏览数 (1)

样例代码及说明 TABLES SPFLI. SELECT-OPTIONS S_CARR FOR SPFLI-CARRID. TYPE-POOLS: RSDS, RSFS.

DATA: CALLBACK TYPE TABLE OF LDBCB,    CALLBACK_WA LIKE LINE OF CALLBACK.

DATA: SELTAB TYPE TABLE OF RSPARAMS, SELTAB_WA LIKE LINE OF SELTAB.

DATA: TEXPR TYPE RSDS_TEXPR, FSEL TYPE RSFS_FIELDS.

*设置需要回调的数据节点和回调对应的子程序 CALLBACK_WA-LDBNODE = 'SPFLI'. CALLBACK_WA-GET = 'X'. CALLBACK_WA-GET_LATE = 'X'. CALLBACK_WA-CB_PROG = SY-REPID. CALLBACK_WA-CB_FORM = 'CALLBACK_SPFLI'. APPEND CALLBACK_WA TO CALLBACK.

CLEAR CALLBACK_WA. CALLBACK_WA-LDBNODE = 'SFLIGHT'. CALLBACK_WA-GET = 'X'. CALLBACK_WA-CB_PROG = SY-REPID. CALLBACK_WA-CB_FORM = 'CALLBACK_SFLIGHT'. APPEND CALLBACK_WA TO CALLBACK.

*设置对应的选择屏幕的参数的传入值 SELTAB_WA-KIND = 'S'. SELTAB_WA-SELNAME = 'CARRID'.

LOOP AT S_CARR. MOVE-CORRESPONDING S_CARR TO SELTAB_WA. APPEND SELTAB_WA TO SELTAB. ENDLOOP.

*调用函数 CALL FUNCTION 'LDB_PROCESS' EXPORTING LDBNAME = 'F1S' VARIANT = ' ' EXPRESSIONS = TEXPR FIELD_SELECTION = FSEL 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.

*SPFLI节点对应的回调处理函数 FORM CALLBACK_SPFLI USING NAME TYPE LDBN-LDBNODE WA TYPE SPFLI EVT TYPE C CHECK TYPE C. CASE EVT. WHEN 'G'. WRITE: / WA-CARRID, WA-CONNID, WA-CITYFROM, WA-CITYTO. ULINE. WHEN 'L'. ULINE. ENDCASE. ENDFORM.

*SFIGHT节点对应的回调处理函数 FORM CALLBACK_SFLIGHT USING NAME TYPE LDBN-LDBNODE WA TYPE SFLIGHT EVT TYPE C CHECK TYPE C. WRITE: / WA-FLDATE, WA-SEATSOCC, WA-SEATSMAX. ENDFORM.

注意:通过'LDB_PROCESS'函数访问逻辑数据库时,请不要在程序属性里绑定逻辑数据库,否则会出LDB_ALREADY_RUNNING错误。

0 人点赞