REPORT ZUSRAPP NO STANDARD PAGE HEADING.
************************************************************************
*              AUTOMATED AUTHORIZATION APPROVAL SYSTEM
*
*The table zapprove has the following key fields: system, client, job
*    title, and ten data fields for approver name. The table has to
*    be maintained before using this program.
*When a person, permitted to approve a creation of users with certain
*     job titles in certain systems and clients (zapprove), runs the
*     program, he has to define a list of users as the first step.
*     Then in the second step, the program lists the job titles,
*     available to approve by the person. By selecting one
*     job title/system/client combination he appends this information
*     to a file in /usr/sap/trans. This file documents the request and
*     will be used by the user administrators to set up the appropriate
*     users in the requested systems.
*
************************************************************************
TABLES: USR02, SSCRFIELDS, ZAPPROVE.

DATA: OUTPUT_FILE(30) VALUE '/usr/sap/trans/users_appr'.
DATA: LIN TYPE I, T0(50), T1(50), T2(50), T3(50), T4(500), I TYPE I.

DATA: BEGIN OF RECORD,
SEP1(2) VALUE '# ',
DATE LIKE SY-DATUM,
SEP2 VALUE ' ',
TIME LIKE SY-UZEIT,
SEP3 VALUE ' ',
APPROUVER LIKE SY-UNAME,
SEP4 VALUE ' ',
SYSTEM LIKE ZAPPROVE-SAPSYSTEM,
SEP5 VALUE ' ',
CLIENT LIKE ZAPPROVE-CLIENT,
SEP6 VALUE ' ',
JTITLE LIKE ZAPPROVE-JTITLE,
END OF RECORD.
* Create a list of users
INITIALIZATION.
  RECORD-TIME = SY-UZEIT.
  RECORD-DATE = SY-DATUM.
  RECORD-APPROUVER = SY-UNAME.
  SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME.
  SELECTION-SCREEN SKIP 2.
  SELECTION-SCREEN COMMENT 1(35) TEXT-001.
  SELECTION-SCREEN SKIP 2.
  SELECT-OPTIONS USER FOR USR02-BNAME NO INTERVALS.
  SELECTION-SCREEN SKIP 3.
  SELECTION-SCREEN PUSHBUTTON 1(24) TEXT-000 USER-COMMAND AAA.
  SELECTION-SCREEN PUSHBUTTON 52(24) TEXT-002 USER-COMMAND BBB.
  SELECTION-SCREEN SKIP 1.
  SELECTION-SCREEN END OF BLOCK A.
* Finishing the first step
AT SELECTION-SCREEN.
  IF SSCRFIELDS-UCOMM = 'AAA'.
    DESCRIBE TABLE USER LINES LIN.
    IF LIN = 0.
      CALL FUNCTION 'POPUP_TO_INFORM'                  "No user selected
           EXPORTING
                TITEL = 'ERROR'
                TXT1  = 'No user selected'
                TXT2  = ' '.
    ELSE.
      SET SCREEN 0. LEAVE SCREEN.
    ENDIF.
  ELSEIF SSCRFIELDS-UCOMM = 'BBB'.
    LEAVE PROGRAM.
  ENDIF.
* Display the job title/system/client combinations
START-OF-SELECTION.
  SELECT * FROM ZAPPROUVE WHERE
    APPROUVER0 = SY-UNAME OR
    APPROUVER1 = SY-UNAME  OR
    APPROUVER2 = SY-UNAME  OR
    APPROUVER3 = SY-UNAME  OR
    APPROUVER4  = SY-UNAME OR
    APPROUVER5  = SY-UNAME OR
    APPROUVER6  = SY-UNAME OR
    APPROUVER7  = SY-UNAME OR
    APPROUVER8  = SY-UNAME OR
    APPROUVER9 = SY-UNAME .       "only the ones available for sy-uname!

    WRITE:   /2(22)  ZAPPROVE-JTITLE    COLOR 2,
              24(8)  ZAPPROVE-SAPSYSTEM COLOR 2,
              32(8)  ZAPPROVE-CLIENT    COLOR 2.

    HIDE: ZAPPROVE-JTITLE, ZAPPROVE-SAPSYSTEM, ZAPPROVE-CLIENT.
    CLEAR ZAPPROUVE.
  ENDSELECT.
* Page header
TOP-OF-PAGE.
  SKIP.
  WRITE: / 'STEP 2' COLOR 3.
  SKIP.
  WRITE: / 'You are an approver for the following job titles'.
  WRITE: 'in the corresponding systems and clients' NO-GAP.
  SKIP.
  WRITE: / 'Doubleclick on the job title to assign it to the users'.
  SKIP.
  WRITE:   /2(22) 'JOB TITLE' COLOR 4,
            24(8) 'SYSTEM'    COLOR 4,
            32(8) 'CLIENT'    COLOR 4.
  SKIP.
* When a job title is selected:
AT LINE-SELECTION.
  IF NOT ( ZAPPROVE-JTITLE IS INITIAL ).         "click on a valid line
    OPEN DATASET OUTPUT_FILE FOR APPENDING IN TEXT MODE.
    RECORD-JTITLE = ZAPPROVE-JTITLE.
    RECORD-SYSTEM = ZAPPROVE-SAPSYSTEM.
    RECORD-CLIENT = ZAPPROVE-CLIENT.
    TRANSFER RECORD TO OUTPUT_FILE.
    LOOP AT USER.
      TRANSFER USER-LOW TO OUTPUT_FILE.
    ENDLOOP.
* Approuval notice
    CLOSE DATASET OUTPUT_FILE.
    T0 = 'APPROVAL NOTICE'. T0+18 = SY-DATUM. T0+28 = SY-UZEIT.
    T1 = 'Approver: ________   System: ___  Client: ___'.
    T1+10(8) = SY-UNAME. T1+29(3) = ZAPPROVE-SAPSYSTEM.
    T1+42(3) = ZAPPROVE-CLIENT.
    T2 = 'Job Title:'. T2+13 = ZAPPROVE-JTITLE.
    T3 = ' '.
    T4 = 'Users:'.
    I = 2.
    LOOP AT USER.
      I = I + 10.
      T4+I(8) = USER-LOW.
    ENDLOOP.
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              TITEL = T0
              TXT1  = T1
              TXT2  = T2
              TXT3  = T3
              TXT4  = T4.
    LEAVE PROGRAM.
  ENDIF.