1

My program simply put the locks on users if the 'LOCK' checkbox is selected.

Everything works and the users records are updated in the USR02. When this change occurs I want that it also be reflected in IT_USR02, i.e. DB table USR02 and itab it_usr02 should be identical.

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.

  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.

Essentially after BAPI_USER_LOCK function is called I want that change to be made in the IT_USR02 table as well. From there I copy the contents of IT_USR02 to my custom table ZATO_LOCK_UNLOCK.

Everything here seems to work fine I just can't figure out how to update my internal table. Any help would be appreciated.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
oceanlab1
  • 21
  • 1
  • 9
  • The code is incomplete - where does LOCK come from, and what kind of change do you want to write back to the table? You're not changing anything in the loop. – vwegert Jul 31 '17 at 04:24
  • The 'LOCK' refers to a check box, and what i wanted to store was the BNAME, USTYP and UFLAG values in my custom table (ZATO_LOCK_UNLOCK). After the program is run it doesnt update the value in the IT_USR02 which in turn doesnt update the custom table. It makes the change how ever im stumped on how to copy that change from USR02 to my IT_USR02. – oceanlab1 Jul 31 '17 at 04:32
  • 1
    You're not changing either BNAME or USTYP, so no need to update it, right? And you're not determining the new value of UFLAG for yourself, so you need to read that either from the database or through BAPI_USER_GETDETAIL. – vwegert Jul 31 '17 at 04:34
  • Yep, sorry :) Reverted back my comment. – Suncatcher Jul 31 '17 at 15:27

1 Answers1

1

If I understand your problem correctly then something like this is what you need:

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

Note that you still need to code the condition to check if all was OK with the BAPI call. I am not familiar with the BAPI so do not know if no entries is good news or if you need to check if there are any errors in the returned table.

Gert Beukema
  • 2,510
  • 1
  • 17
  • 18