!/usr/bin/ksh
# whatfndlogmessage ()
#------------------------------------------------------------------------------#
#    Module Name:  whatfndlogmessage                                           #
#                                                                              #
#    Purpose:      Report on the FND_LOG_MESSAGES.                             #
#                  Support Note: 7593659.1                                     #
#                                                                              #
#    Update Profile Option:                                                    #
#        FND: Debug Log Enabled :   Yes                                        #
#        FND: Debug Log Filename :  <Null Value>                               #
#        FND: Debug Log Level :     Statement                                  #
#        FND: Debug Log Module :    %                                          #
#                                                                              #
#    Bounce AppsTier Services                                                  #
#                                                                              #
#    Truncate:  APPLSYS.FND_LOG_MESSAGES                                       #
#        truncate table APPLSYS.FND_LOG_MESSAGES;                              #
#                                                                              #
#    Reproduce the FND-OAFamework Issue.                                       #
#    Close the Browser.                                                        #
#    Upload APPLSYS.FND_LOG_MESSAGES                                           #
#                                                                              #
#    SELECT *                                                                  #
#    FROM    fnd_log_messages film,                                            #
#            fnd_user fu                                                       #
#    WHERE   flm.user_id=fu.user_id                                            #
#      AND   fu.user_name ='&app_user_name'                                    #
#    ORDER BY timestamp, log_sequence;                                         #
#                                                                              #
#    Maintenance                                                               #
#    Date          Author        Description                                   #
#    -----------   ------------  --------------------------------------------  #
#    05-Jan-2008   M.Barone      Module design/creation                        #
#------------------------------------------------------------------------------#
{
        DIRNAM=$(dirname $0)
        ORASID=$(echo $CONTEXT_NAME | cut -f1 -d'_')
        HNAME=$(uname -n)

        clear
        #----------------------------------------------------------------------#
        #  TEST:  Number ($#) of arguments passed to this function?            #
        #----------------------------------------------------------------------#
        if      [ $# = 0 ]
        then
            clear
            echo
            echo  " #--------------------------------------------------------#"
            echo  " # whatfndlogmessage:             Oracle FND LOG MESSAGES #"
            echo  " #--------------------------------------------------------#"
            echo
            #------------------------------------------------------------------#
            #  Trap:  Set CNTL-C CNTL-D CNTL-\ Before Password Protection      #
            #------------------------------------------------------------------#
            trap        "stty echo; return"     2
            trap        "stty echo; return"     3
            stty -echo

	    read -e -a PASSWD  -p " Please Enter Oracle APPS Passwd: "

            stty echo
            echo
            #------------------------------------------------------------------#
            #  Trap:  Reset CNTL-C CNTL-D CNTL-\ After Password Protection     #
            #------------------------------------------------------------------#
            trap        2
            trap        3

            clear
        else
            PASSWD=$1
            clear
        fi

        ORANAM=${ORASID}

#------------------------------------------------------------------------------#
#  SQL*Plus ("Here-Document")                                                  #
#------------------------------------------------------------------------------#
sqlplus  -s  /nolog  <<-END_FILE

        CONNECT  APPS/$PASSWD

        clear   BREAKS
        clear   BUFFER
        clear   COLUMNS
        clear   COMPUTES
        clear   SCREEN
        clear   SQL
        clear   TIMING

        set     feedback        off
        set     flush           on
        set     heading         on
        set     pause           off
        set     space           1
        set     termout         on
        set     verify          on
        set     linesize        80
        set     pagesize        999

        SPOOL /tmp/whatfndlogmessage_$$.txt

        COLUMN datevalue NOPRINT NEW_VALUE DATEVAR
        COLUMN timevalue NOPRINT NEW_VALUE TIMEVAR
        COLUMN modname  FORMAT A30      Heading 'FND|Module|Name'  WORD_WRAPPED
        COLUMN msgtext  FORMAT A29      Heading 'FND|Module|Error' WORD_WRAPPED
        COLUMN unixfnd  FORMAT A09      Heading 'UNIX|FNDLIB|Process'
        COLUMN dattime  FORMAT A09      Heading 'Date|Time'        WORD_WRAPPED

        TTITLE LEFT DATEVAR -
        RIGHT 'Page:' FORMAT 999 SQL.pno -
        CENTER '$(uname -n)  ${ORACLE_SID} DBA Report'                  skip 1 -
        LEFT TIMEVAR -
        CENTER  'Oracle (${ORACLE_SID}) Current FND Log Messages'       skip 1 -
        CENTER  'whatfndlogmessages'                                    skip 2

        SELECT  TO_CHAR(sysdate, 'DD-MON-YY') datevalue,
                TO_CHAR(sysdate, 'HH24:MI-SS') timevalue,
                module                                          modname,
                message_text                                    msgtext,
                process_id                                      unixfnd,
                TO_CHAR(timestamp, 'DD-MON-YY HH:MI:SS')        dattime
        FROM    APPLSYS.FND_LOG_MESSAGES
        ORDER   BY timestamp;
        REM WHERE   timestamp >  SYSDATE -2

EXIT;

END_FILE

echo
echo  "Please see /tmp/whatfndlogmessage_$$.txt"
echo
}
