您的位置:首页 > 电脑网络 > 电脑配件 > 完整的SM01 BDC程序

完整的SM01 BDC程序

luyued 发布于 2011-04-26 23:15   浏览 N 次  
*&---------------------------------------------------------------------*
*& Report Z_LOCK_TCODE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT z_lock_tcode MESSAGE-ID z_mess_zhangcb
NO STANDARD PAGE HEADING.

TABLES: tstc.
DATA: BEGIN OF i_tcode OCCURS 0,
tcode LIKE tstc-tcode,
END OF i_tcode.
DATA: v_line TYPE i.
DATA p_mode(1) TYPE c.
DATA:p_msg(200) TYPE c.
DATA: BEGIN OF it_bdcdata OCCURS 0.
INCLUDE STRUCTURE bdcdata.
DATA: END OF it_bdcdata.
DATA: it_message TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.

DATA: it_zlocklog TYPE zlocklog OCCURS 0 WITH HEADER LINE.


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_tcode FOR tstc-tcode.
SELECTION-SCREEN SKIP.
PARAMETERS: p_lock RADIOBUTTON GROUP g1 DEFAULT 'X',
p_unlock RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK b1.



START-OF-SELECTION.
IF s_tcode[] IS INITIAL.
MESSAGE s000 WITH '请输入需要锁定/解锁的TCODE'.
EXIT.
ENDIF.
IF p_lock IS INITIAL AND p_unlock IS INITIAL.
MESSAGE s000 WITH '请选择需要的操作(锁定/解锁)'.
EXIT.
ENDIF.
SELECT tcode FROM tstc INTO TABLE i_tcode
WHERE tcode IN s_tcode.
IF sy-subrc <> 0.
MESSAGE s000 WITH '没有符合条件的TCODE'.
EXIT.
ENDIF.
DESCRIBE TABLE i_tcode LINES v_line.
IF v_line > 2000.
MESSAGE s000 WITH '最多一次锁定2000行'.
EXIT.
ENDIF.
p_mode = 'N'.
IF p_lock = 'X'.
WRITE: '开始锁定......'.
ELSEIF p_unlock = 'X'.
WRITE: '开始解锁......'.
ENDIF.

REFRESH: it_zlocklog.

LOOP AT i_tcode.

CLEAR: it_zlocklog.
it_zlocklog-erdat = sy-datum.
it_zlocklog-erzet = sy-uzeit.
it_zlocklog-tcode = i_tcode-tcode.
it_zlocklog-uname = sy-uname.
it_zlocklog-utcode = sy-tcode.
IF p_lock = 'X'.
it_zlocklog-zflag = '0'.
ELSE.
it_zlocklog-zflag = '1'.
ENDIF.
SELECT SINGLE tstc~cinfo INTO it_zlocklog-cinfo_begin FROM tstc
WHERE tstc~tcode = it_zlocklog-tcode.

REFRESH it_bdcdata.
REFRESH it_message.
PERFORM bdc_dynpro USING 'SAPMTSTC' '1010'.
PERFORM bdc_field USING 'BDC_CURSOR' '*TSTC-TCODE'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM bdc_field USING '*TSTC-TCODE' i_tcode-tcode.
PERFORM bdc_dynpro USING 'SAPMTSTC' '1010'.
PERFORM bdc_field USING 'BDC_CURSOR' 'TSTCF-FLAGS(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
IF p_lock = 'X'.
PERFORM bdc_field USING 'TSTCF-FLAGS(01)' 'X'.
ELSE.
PERFORM bdc_field USING 'TSTCF-FLAGS(01)' ''.
ENDIF.
PERFORM bdc_dynpro USING 'SAPMTSTC' '1010'.
PERFORM bdc_field USING 'BDC_CURSOR' '*TSTC-TCODE'.
PERFORM bdc_field USING 'BDC_OKCODE' '/E'.

CALL TRANSACTION 'SM01' USING it_bdcdata
MODE p_mode
UPDATE 'S'
MESSAGES INTO
it_message.

READ TABLE it_message WITH KEY msgtyp = 'E'.
IF sy-subrc = 0.
IF p_lock = 'X'.
WRITE: / i_tcode-tcode,'锁定失败:'.
ELSE.
WRITE: / i_tcode-tcode,'解锁失败:'.
ENDIF.
LOOP AT it_message WHERE msgtyp = 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = it_message-msgid
msgnr = it_message-msgnr
msgv1 = it_message-msgv1
msgv2 = it_message-msgv2
msgv3 = it_message-msgv3
msgv4 = it_message-msgv4
IMPORTING
message_text_output = p_msg.
WRITE: / ' ',p_msg.
ENDLOOP.

it_zlocklog-zres = 'N'.
it_zlocklog-zmes = p_msg.
APPEND it_zlocklog.
ELSE.
IF p_lock = 'X'.
WRITE: / i_tcode-tcode,'锁定成功!'.
ELSE.
WRITE: / i_tcode-tcode, '解锁成功!'.
ENDIF.
ENDIF.

it_zlocklog-zres = 'Y'.
APPEND it_zlocklog.
ENDLOOP.

LOOP AT it_zlocklog.
SELECT SINGLE tstc~cinfo INTO it_zlocklog-cinfo_after FROM tstc
WHERE tstc~tcode = it_zlocklog-tcode.
IF it_zlocklog-cinfo_begin <> it_zlocklog-cinfo_after.
it_zlocklog-zres = 'Y'.
ELSE.
it_zlocklog-zres = 'N'.
it_zlocklog-zmes = '状态未修改!'.
ENDIF.
MODIFY it_zlocklog.
ENDLOOP.
MODIFY zlocklog FROM TABLE it_zlocklog.
COMMIT WORK AND WAIT.
IF sy-subrc = 0.
WRITE: / '日志保存成功!'.
ELSE.
WRITE: / '日志保存失败!'.
ENDIF.


END-OF-SELECTION.
WRITE: / '执行完毕'.



*&---------------------------------------------------------------------*
*& bdc_dynpro
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
* -->PV_PROGRAM PROGRAM NAME
* -->PV_DYNPRO SCREEN NUMBER
*----------------------------------------------------------------------*
FORM bdc_dynpro USING pv_program pv_dynpro.
CLEAR it_bdcdata.
it_bdcdata-program = pv_program.
it_bdcdata-dynpro = pv_dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ENDFORM. "FRM_bdc_dynpro

*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PV_FNAM NAME
* -->PV_FVAL VALUE
*----------------------------------------------------------------------*
FORM bdc_field USING pv_fnam pv_fval.
CLEAR it_bdcdata.
it_bdcdata-fnam = pv_fnam.
it_bdcdata-fval = pv_fval.
APPEND it_bdcdata.
ENDFORM. "FRM_BDC_FIELD
图文资讯
广告赞助商