如何在更改另一个表后更新内部表?

时间:2017-07-31 01:43:04

标签: sap abap opensql

如果' LOCK'选中复选框。 这一切都可以工作并更新USR02表中的用户记录。当发生这种变化时,我想更新我的内部表" IT_USR02"模仿对USR02所做的更改。

SELECT-OPTIONS: USER_ID FOR USR02-BNAME.
  START-OF-SELECTION.
  SELECT BNAME
         USTYP
         UFLAG
  FROM USR02
  INTO TABLE IT_USR02
  WHERE BNAME IN USER_ID.
**  WHERE UFLAG EQ P_UFLAG.

  IF IT_USR02[] IS NOT INITIAL.

    LOOP AT IT_USR02 INTO ST_USR02.

      IF LOCK = 'X'.
        CALL FUNCTION 'BAPI_USER_LOCK'
          EXPORTING
            USERNAME = ST_USR02-BNAME
          TABLES
            RETURN   = I_BAPI_RETURN.

        MOVE-CORRESPONDING IT_USR02[] TO IT_ZATO_LOCK_UNLOCK[].
        MODIFY ZATO_LOCK_UNLOCK FROM TABLE IT_ZATO_LOCK_UNLOCK.

      ENDIF.
  ENDLOOP.

基本上是在' BAPI_USER_LOCK'函数被调用我想要在IT_USR02表中进行更改。从那里我将IT_USR02的内容复制到我的自定义表ZATO_LOCK_UNLOCK。这里的一切似乎都运行正常我只是无法弄清楚如何更新我的内部表。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:1)

如果我理解你的问题,那么你需要这样的东西:

LOOP AT IT_USR02 ASSIGNING FIELD-SYMBOL(<USR02>).
  " Using field symbol for performance and so the entry can be changed

  IF LOCK = 'X'.
    CALL FUNCTION 'BAPI_USER_LOCK'
      EXPORTING
        USERNAME = ST_USR02-BNAME
      TABLES
        RETURN   = I_BAPI_RETURN.
    IF "All is OK in I_BAPI_RETURN
      " Change the table entry
      <USR02>-UFLAG = 32. " Not sure if this is the right value
    ENDIF.
  ENDIF.
ENDLOOP.
" This needs to be outside the loop since you are handling the complete table
MOVE-CORRESPONDING IT_USR02[] TO IT_ZATO_LOCK_UNLOCK[].
MODIFY ZATO_LOCK_UNLOCK FROM TABLE IT_ZATO_LOCK_UNLOCK.
" A commit work might be needed here

请注意,您仍然需要对条件进行编码,以检查BAPI调用是否一切正常。我不熟悉BAPI所以不知道条目是否是好消息,或者你是否需要检查返回表中是否有任何错误。