需求及解决方案:
1,创建一个数据库表,例如两个字段:ID (char 5),STATUS(char 5),输入几条数据记录
2,创建一个ABAP程序实现屏幕上输入ID号及STATUS,执行时根据对应的ID号更新数据库表中的数据.功能实现后,为此程序创建一个T_code
3,创建一个BSP程序,实现call ABAP 程序的T_code来实现数据更新(因为发现不能直接使用call transcation 语句后面带两个参数的function,而用F1查得,可以有Call transcation using BDC_table的语法,所以想到在BSP里的call之前,先利用ABAP程序录制一个BDC文件并生成其自带的program,创建一个BAPI文件,利用BDC文件生成program里提到的call transaction的方法,实现call 我们自己的Transaction的功能,然后在BSP的OnInputprocessing里call 我们自建的Function.
解决过程.
1.创建数据库表,T_code: SE11,数据库名ZKBSP,两个字段:ID (char 5),STATUS(char 5),输入3条记录:1,open;2,close,3,new.
2,创建一个ABAP程序,T_code: SE80,程序名ZABAP_BSP,实现了根据对应的ID号更新数据库表中的数据功能.并给予其创建一个T_code:ZABAP_BSP程序如下 :
REPORT ZABAP_BSP.
DATA: BEGIN OF IT_OUT OCCURS 100,
ID(5) TYPE C,
Status(5) type C,
END OF IT_OUT.
DATA: WA_OUT LIKE IT_OUT.
SELECTION-SCREEN BEGIN OF BLOCK SEL WITH FRAME TITLE T-001.
PARAMETERS: P_ID(5) TYPE C,
P_STATUS(5) TYPE C.
SELECTION-SCREEN END OF BLOCK SEL.
SELECT SINGLE ID STATUS INTO WA_OUT FROM ZKBSP WHERE ID = P_ID.
IF SY-SUBRC = 0.
WA_OUT-STATUS = P_STATUS.
MODIFY ZKBSP FROM WA_OUT.
MESSAGE 'DATA HAS BEEN MODIFIED SUCCESSFUL!' TYPE 'S'.
ENDIF.
DATA: BEGIN OF IT_OUT OCCURS 100,
ID(5) TYPE C,
Status(5) type C,
END OF IT_OUT.
DATA: WA_OUT LIKE IT_OUT.
SELECTION-SCREEN BEGIN OF BLOCK SEL WITH FRAME TITLE T-001.
PARAMETERS: P_ID(5) TYPE C,
P_STATUS(5) TYPE C.
SELECTION-SCREEN END OF BLOCK SEL.
SELECT SINGLE ID STATUS INTO WA_OUT FROM ZKBSP WHERE ID = P_ID.
IF SY-SUBRC = 0.
WA_OUT-STATUS = P_STATUS.
MODIFY ZKBSP FROM WA_OUT.
MESSAGE 'DATA HAS BEEN MODIFIED SUCCESSFUL!' TYPE 'S'.
ENDIF.
3,利用BDC的方法生成一个call T_code的程序.
1)T_code: SHDB 进入BDC界面
2)录制一段先前做好的ABAP程序执行过程.New Recording->ZBSP->输入需要录制的Transaction code:ZABAP_BSP->Starting Recording->输入执行程序的两个参数->执行->退出->保存->recording 生成.
3)选中先前创建的recording 记录,点击Test Data button->create Test data for recording ->输入一个file name,这个文件将会成为后来生成程序中的BDCDATA dataset.
4)点击Program button,生成BDC的程序,分析程序,找到其中可以实现call T_ code的方法.
4.创建一个Function module ,命名为I_call_BSP,主要功能是利用BDC生成的程序,抽出其中的可以实现call T_code执行程序的方法.
其中Import 为:I_ID type CHAR5;I_STATUS type CHAR5.Export 为Output type I.Source code 部分程序如下:
FUNCTION Z_CALL_BSP.
perform bdc_dynpro using 'ZABAP_BSP' '1000'.
perform bdc_field using 'BDC_CURSOR'
'P_STATUS'.
perform bdc_field using 'BDC_OKCODE'
'=ONLI'.
perform bdc_field using 'P_ID'
I_ID.
perform bdc_field using 'P_STATUS'
I_STATUS.
perform bdc_dynpro using 'ZABAP_BSP' '1000'.
perform bdc_field using 'BDC_OKCODE'
'/EE'.
perform bdc_field using 'BDC_CURSOR'
'P_ID'.
perform bdc_transaction.
ENDFUNCTION.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL IS NOT INITIAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
FORM bdc_transaction.
CALL TRANSACTION 'ZABAP_BSP' USING BDCDATA
MODE 'N'
UPDATE 'L'.(最主要是这一句话实现了这一个BAPI调用T_code的功能)
ENDFORM.
perform bdc_dynpro using 'ZABAP_BSP' '1000'.
perform bdc_field using 'BDC_CURSOR'
'P_STATUS'.
perform bdc_field using 'BDC_OKCODE'
'=ONLI'.
perform bdc_field using 'P_ID'
I_ID.
perform bdc_field using 'P_STATUS'
I_STATUS.
perform bdc_dynpro using 'ZABAP_BSP' '1000'.
perform bdc_field using 'BDC_OKCODE'
'/EE'.
perform bdc_field using 'BDC_CURSOR'
'P_ID'.
perform bdc_transaction.
ENDFUNCTION.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL IS NOT INITIAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
FORM bdc_transaction.
CALL TRANSACTION 'ZABAP_BSP' USING BDCDATA
MODE 'N'
UPDATE 'L'.(最主要是这一句话实现了这一个BAPI调用T_code的功能)
ENDFORM.
5.创建BSP program, 程序名:ZK_BSP_TEST同样实现根据对应的ID号更新数据库表中的数据功能,
1),创建page1,命名为:first.htm.在Page Attribute tab 里定义两个attribute ,S_ID type ZKBSP-ID;S_STUTAS type ZKBSP-STATUS.记得将auto打上勾.
2),在layout tab里写上如下代码:
<%@page language="abap"%>
<html>
<head>
<title>First Page</title>
</head>
<body>
<form method="post" action="first.htm">
ID: <input name="S_ID"/><br>
STATUS: <input name="S_STATUS"/><br>
<input value="submit" type="submit" name="OnInputProcessing"/>
</form>
</body>
</html>
<html>
<head>
<title>First Page</title>
</head>
<body>
<form method="post" action="first.htm">
ID: <input name="S_ID"/><br>
STATUS: <input name="S_STATUS"/><br>
<input value="submit" type="submit" name="OnInputProcessing"/>
</form>
</body>
</html>
3)在event handler中OnInputProcessing事件中,进行call BAPI 实现功能的操作,代码如下
IF S_ID IS NOT INITIAL.
CALL FUNCTION 'Z_CALL_BSP'
EXPORTING
i_id = S_ID
i_status = S_STATUS
IMPORTING
OUTPUT = OUTPUT
.
ENDIF.
if output = 0.
MESSAGE 'sucessful!' type 'S'.
ENDIF.
CALL FUNCTION 'Z_CALL_BSP'
EXPORTING
i_id = S_ID
i_status = S_STATUS
IMPORTING
OUTPUT = OUTPUT
.
ENDIF.
if output = 0.
MESSAGE 'sucessful!' type 'S'.
ENDIF.