Tuesday, August 7, 2012

aufnr_not_found error

When one runs transaction CO88 (Actual Settlement: Production/Process Orders), and after a while the transaction errors out and dumps, a probable cause could be that there is some kind of inconsistency in the tables involved.

Let me describe the error first. Figure 1 shows the short text displayed by the dump. It displays the peculiar "AUFNR_NOT_FOUND" message, which leaves us completely lost on what the error is all about.

|Short text
|    Exception condition "AUFNR_NOT_FOUND" raised.
Figure 1. Short text found in the CO88 error log.

Figure 2 describes the error analysis given by the log. It gives us a clue that the error was caused or raised by some code in the SAPLCOSE program. Furthermore, it gives a more straightforward clue that the error is caused because an order was not found in an internal table that contains some of the contents of the AFPO table.

|Error analysis
|    A RAISE statement in the program "SAPLCOSE" raised the exception
|    condition "AUFNR_NOT_FOUND".
|    Since the exception was not intercepted by a superior
|    program, processing was terminated.
|                                                                                                  |
|    Short description of exception condition:                                                     |
|                                                                                                  |
|    Order not in buffered AFPO table                                                              |
|                                                                                                  |
|    For detailed documentation of the exception condition, use                                    |
|    Transaction SE37 (Function Library). You can take the called                                  |
|    function module from the display of active calls.                                             |
|    -                                                                                             |
------------------------------
----------------------------------------------------------------------
Figure 2. Error analysis found in the CO88 error log.

In Figure 3, we see that the error exception was issued after calling a function called K_AFPO_READ. Based from the name of the function, the function's sole role must just be to read some record in the AFPO table. But since it could not find a record, the error was issued.

----------------------------------------------------------------------------------------------------
|Source Code Extract                                                                               |
------------------------------
----------------------------------------------------------------------
|Line |SourceCde                                                                                   |
------------------------------
----------------------------------------------------------------------
|   14|*"             VALUE(LEAD_AUFNR_HAS_
COPRODUCTS_EXP)                                         |
|   15|*"                             LIKE  DATATYPE-CHAR0001                                      |
|   16|*"             VALUE(SRULE_GENERATE_EXP) LIKE  DATATYPE-CHAR0001                            |
|   17|*"       EXCEPTIONS                                                                         |
|   18|*"              AUFNR_NOT_FOUND                                                             |
|   19|*"-------------------------
---------------------------------------------                    |
|   20|                                                                                            |
|   21|  FIELD-SYMBOLS:                                                                            |
|   22|     LIKE AFPO.                                                                   |
|   23|                                                                                            |
|   24|  DATA:                                                                                     |
|   25|     LD_TABIX LIKE SY-TABIX,                                                                |
|   26|     LD_AUFK  LIKE AUFK,                                                                    |
|   27|     LD_AFKO  LIKE AFKO,                                                                    |
|   28|     LD_AFPO  LIKE AFPO.                                                                    |
|   29|                                                                                            |
|   30|* If no order position, assume 1st position                                                 |
|   31|  IF POSNR_IMP IS INITIAL.                                                                  |
|   32|    POSNR_IMP = CON_POSNR_0001.                                                             |
|   33|  ENDIF.                                                                                    |
|   34|                                                                                            |
|   35|  CALL FUNCTION 'K_AFPO_READ'                                                               |
|   36|       EXPORTING                                                                            |
|   37|            I_AUFNR   = AUFNR_IMP                                                           |
|   38|            I_POSNR   = POSNR_IMP                                                           |
|   39|       IMPORTING                                                                            |
|   40|            E_AFPO    = LD_AFPO                                                             |
|   41|       EXCEPTIONS                                                                           |
|   42|            NOT_FOUND = 1.                                                                  |
|   43|  IF NOT SY-SUBRC IS INITIAL.                                                               |
|>>>>>|    RAISE AUFNR_NOT_FOUND.                                                                  |
|   45|  ENDIF.                                                                                    |
|   46|                                                                                            |
|   47|* Collective orders only exist for order type 10 and 40                                     |
|   48|  IF   LD_AFPO-DAUTY = '10'            "PP-FA                                               |
|   49|    OR LD_AFPO-DAUTY = '40'.           "PP-PI                                               |
|   50|    CALL FUNCTION 'K_AFKO_READ'                                                             |
|   51|         EXPORTING                                                                          |
|   52|              I_AUFNR   = AUFNR_IMP                                                         |
|   53|         IMPORTING                                                                          |
|   54|              E_AFKO    = LD_AFKO                                                           |
|   55|         EXCEPTIONS                                                                         |
|   56|              NOT_FOUND = 1.                                                                |
|   57|    IF SY-SUBRC <> 0.                                                                       |
|   58|      CLEAR LD_AFKO.                                                                        |
|   59|    ENDIF.                                                                                  |
|   60|  ENDIF.                                                                                    |
|   61|                                                                                            |
|   62|  IF LD_AFPO-RTP03 = 'X' AND LD_AFPO-KZBWS = 'M'.                                           |
|   63|    SRULE_GENERATE_EXP = 'X'.                                                               |
------------------------------
----------------------------------------------------------------------
Figure 3. Source code extract found in the CO88 error log.

In Figure 4, we look at some of the system variables. From here, we are able to see that the process order involved has number 1910081 from the SY-MSGV1 variable.

----------------------------------------------------------------------------------------------------
|Contents of system fields                                                                         |
------------------------------
----------------------------------------------------------------------
|Name    |Val.                                                                                     |
------------------------------
----------------------------------------------------------------------
|SY-SUBRC|1                                                                                        |
|SY-INDEX|318                                                                                      |
|SY-TABIX|0                                                                                        |
|SY-DBCNT|0                                                                                        |
|SY-FDPOS|44                                                                                       |
|SY-LSIND|0                                                                                        |
|SY-PAGNO|0                                                                                        |
|SY-LINNO|1                                                                                        |
|SY-COLNO|1                                                                                        |
|SY-PFKEY|IMAG                                                                                     |
|SY-UCOMM|AUSF                                                                                     |
|SY-TITLE|Actual Settlement: Production/Process Orders                                             |
|SY-MSGTY|S                                                                                        |
|SY-MSGID|KD                                                                                       |
|SY-MSGNO|202                                                                                      |
|SY-MSGV1|ORD 1910081                                                                              |
|SY-MSGV2|84981364      PAMP CRUIS S3 ECONO+ 1/  1                                                      |
|SY-MSGV3|                                                                                         |
|SY-MSGV4|                                                                                         |
|SY-MODNO|0                                                                                        |
|SY-DATUM|20090112                                                                                 |
|SY-UZEIT|002655                                                                                   |
|SY-XPROG|SAPLKKIO                                                                                 |
|SY-XFORM|CONVERSION_EXIT                                                                          |
------------------------------
----------------------------------------------------------------------
Figure 5. Contents of some system fields found in the CO88 error log.

Analysis: As a general rule, every process order in the AUFK table (Order master data) should have at least one corresponding entry in the AFPO (Order item) table. What happened in the error above was that there was a process order with number 1910081. This can be verified via the SE16 transaction. In the AUFK table selection, type in 1910081 in the AUFNR field (Order), then press F8 to execute. If a record comes out, then there is a process order with number 1910081.

We do the same for the AFPO table. In transaction SE16, we type in AFPO to query the AFPO table. In the selection screen, we type in 1910081 in the AUFNR field (Order). Press F8. If no records are found, that is, if a status message of "No table entries found for specified key", then there are no records in the AFPO table that correspond to the process order 1910081. If this is the case, then our general rule is broken, which causes the dump.

To avoid this error, there should be consistency between the AUFK and AFPO tables. For every AUFK process order, there should be at least one corresponding AFPO entry with the same order number (AUFNR).

No comments:

Post a Comment