W Pub: ABAP Prog Standar Add Auto

  1. * Si se añade a pelo en la UST04 tambin cuela!!!
  2.  
  3. form ins_or_del_profile_in_user using user profile action ret.
  4.   data: fill type i.
  5. *
  6.   call function 'ENQUEUE_E_USR04'
  7.        exporting
  8.             bname          = user
  9.        exceptions
  10.             foreign_lock   = 1
  11.             system_failure = 2.
  12.   if sy-subrc <> 0.
  13.     ret = 1.
  14.     exit.
  15.   endif.
  16. * Benutzerstammsatz lesen und aktualisieren
  17.   perform read_usr04
  18.           using user rc fill.
  19.   if action = 'I'.                     "Aktion Hinzufuegen
  20.     perform add_prof_in_tabusr using profile.
  21.   elseif action1 = 'D'.                 "Aktion Loeschen
  22.     delete tabusr where profile = profile.
  23.   endif.
  24.   perform upd_usr04
  25.           using user.
  26.   call function 'DEQUEUE_E_USR04'
  27.        exporting
  28.             bname = user.
  29. endform.
  30.  
  31. *---------------------------------------------------------------------*
  32. *       FORM read_usr04                                               *
  33. *---------------------------------------------------------------------*
  34. *       ........                                                      *
  35. *---------------------------------------------------------------------*
  36. *  -->  VALUE(USER)                                                   *
  37. *  -->  RC                                                            *
  38. *  -->  USRFILL                                                       *
  39. *---------------------------------------------------------------------*
  40. form read_usr04 using value(user) rc usrfill.
  41.   clear usr04.
  42.   rc = 0.
  43.   select single * from usr04                  "Einen Rec. lesen
  44.          where bname   = user.
  45.   if sy-subrc = 0.                     "Den variablen Teil des Rec. auf-
  46.     "schluesseln u. in int. Tab.
  47.     "tabusr schreiben
  48.     perform fill_tabusr using usrfill.
  49.     loop at tabusr.
  50.       clear usr10.
  51.       select single * from usr10
  52.              where profn = tabusr-profile
  53.              and   aktps  = aktivated.
  54.       if usr10-typ = colectprof.
  55.         tabusr-samprof  = 'X'.
  56.       elseif usr10-typ = generprof.
  57.         tabusr-samprof = 'G'.
  58.       else.
  59.         clear tabusr-samprof.
  60.       endif.
  61.       modify tabusr.
  62.     endloop.
  63.   else.
  64.     refresh tabusr.
  65.     clear tabusr.
  66.     usrfill = 0.
  67.     rc = 4.
  68.   endif.
  69. endform.
  70.  
  71. *---------------------------------------------------------------------*
  72. *       FORM fill_tabusr                                              *
  73. *---------------------------------------------------------------------*
  74. *       ........                                                      *
  75. *---------------------------------------------------------------------*
  76. *  -->  USRFILL                                                       *
  77. *---------------------------------------------------------------------*
  78. form fill_tabusr using usrfill.
  79.   data: nrpro type i,
  80.         off   type i.
  81. *
  82.   refresh tabusr.
  83.   clear tabusr.
  84.   usrfill = 0.
  85.   off = 2.
  86.   nrpro = usr04-nrpro / 12.                                 "MBK0001
  87.   if nrpro > maxusr. nrpro = 0. endif.
  88.   do nrpro times.
  89.     assign usr04-profs+off(proflng) to <text>.
  90.     write <text> to tabusr-profile.
  91.     append tabusr.
  92.     usrfill = usrfill + 1.
  93.     off = off + proflng.
  94.   enddo.
  95. endform.
  96.  
  97. *---------------------------------------------------------------------*
  98. *       FORM add_prof_in_tabusr                                       *
  99. *---------------------------------------------------------------------*
  100. *       ........                                                      *
  101. *---------------------------------------------------------------------*
  102. *  -->  PROFILE                                                       *
  103. *---------------------------------------------------------------------*
  104. form add_prof_in_tabusr using profile.
  105.   read table tabusr with key profile = profile.
  106.   if sy-subrc = 0.
  107.     call function 'DEQUEUE_E_USR04'
  108.          exporting
  109.               bname = user.
  110.     raise profile_already_in_user.
  111.   endif.
  112.   tabusr-profile = profile.
  113.   append tabusr.
  114. endform.                               " ADD_PROF_IN_USER
  115.  
  116. *---------------------------------------------------------------------*
  117. *       FORM upd_usr04                                                *
  118. *---------------------------------------------------------------------*
  119. *       ........                                                      *
  120. *---------------------------------------------------------------------*
  121. *  -->  VALUE(USER)                                                   *
  122. *---------------------------------------------------------------------*
  123. form upd_usr04 using value(user).
  124.   data: off type i,
  125.         z   type i value 0,
  126.         max type i,
  127.         longstring(3750),
  128.         longstring1(3750).
  129.  
  130.   data: begin of intust04 occurs 50.
  131.           include structure ust04.
  132.   data: end of intust04.
  133. *
  134.   select single * from usr04
  135.          where bname = user.
  136.   if sy-subrc = 0.
  137.     longstring1 = usr04-profs.
  138.   endif.
  139.   rc = sy-subrc.
  140.   move-corresponding usr04 to *usr04.
  141.   clear usr04.
  142.   clear longstring.
  143.   usr04-bname = user.                  "Festteil des Userrec beschreiben
  144.   off = 2.
  145.   z = 0.
  146.   max = maxrec - proflng.
  147.   sort tabusr.
  148.   loop at tabusr.                      "Den var. Teil beschreiben
  149.     write tabusr-profile to longstring+off(proflng).
  150.     off = off + proflng.
  151.     z = z + 1.
  152.     if off > max.
  153. *      message w263 with user.
  154.       exit.
  155.     endif.
  156.   endloop.
  157.   usr04-nrpro = off.
  158.   usr04-profs = longstring.
  159.  
  160.   if rc = 0.
  161. * Aenderungsbeleg wegschreiben
  162.     if *usr04-profs(1) <> rec_type_create and               "MBK0002
  163.        *usr04-profs(1) <> rec_type_modify.                  "MBK0002
  164.       select * from ush04                                   "MBK0002
  165.              where bname = user.                            "MBK0002
  166.         exit.                                               "MBK0002
  167.       endselect.                                            "MBK0002
  168.       if sy-subrc <> 0.                                     "MBK0002
  169.         write rec_type_create to *usr04-profs(1).           "MBK0002
  170.       else.                                                 "MBK0002
  171.         move-corresponding *usr04 to ush04.                 "MBK0002
  172.         clear ush04-profs.                                  "MBK0002
  173.         insert ush04.         "Originaldatum wegschreiben  "MBK0002
  174.          *usr04-modda = sy-datum.                           "MBK0002
  175.          *usr04-modti = sy-uzeit - 1.                       "MBK0002
  176.          *usr04-modbe = sy-uname.                           "MBK0002
  177.       endif.                                                "MBK0002
  178.     endif.                                                  "MBK0002
  179.     move-corresponding *usr04 to ush04.
  180.     modify ush04.                                           "MS160398
  181.     usr04-modbe = sy-uname.                                 "MBK0002
  182.     usr04-modda = sy-datum.                                 "MBK0002
  183.     usr04-modti = sy-uzeit.                                 "MBK0002
  184.     write rec_type_modify to usr04-profs(1).                "MBK0002
  185.     update usr04.
  186.     insertflag = 0.
  187.   else.
  188.     usr04-modbe = sy-uname.                                 "MBK0002
  189.     usr04-modda = sy-datum.                                 "MBK0002
  190.     usr04-modti = sy-uzeit.                                 "MBK0002
  191.     write rec_type_create to usr04-profs(1).                "MBK0002
  192.     insert usr04.
  193.     insertflag = 1.
  194.   endif.
  195.   select * from ust04 into intust04
  196.          where bname = user.
  197.     append intust04.
  198.   endselect.
  199.   sort intust04.
  200.   loop at intust04.
  201.     read table tabusr with key profile = intust04-profile.
  202.     if sy-subrc <> 0.
  203.       delete from ust04
  204.              where bname = intust04-bname
  205.              and   profile = intust04-profile.
  206.     endif.
  207.   endloop.
  208.   ust04-bname = user.
  209.   loop at tabusr.
  210.     read table intust04 with key profile = tabusr-profile.
  211.     if sy-subrc <> 0.
  212.       ust04-profile = tabusr-profile.
  213.       insert ust04.
  214.     endif.
  215.   endloop.
  216.   call function 'SUSR_USER_BUFFER_AFTER_CHANGE'
  217.        exporting
  218.             username = user.
  219.  
  220. endform.