Thursday 10 January 2008

ABAP Obtaining characteristics of a document from the classification system

In addition to a previous post regarding getting classification information for objects of type Material or Batch and thanks to additional info and feedback that I received from our MM specialist Ms Marilena Svolaki, I will be able to provide an example of how to do the same thing with documents.

Master information about documents is found in the DRAW table. (This is short for German Dokumentinformationssatz). The key fields for each document are displayed in the following image :

Creating the object key for BAPI_OBJCL_GETCLASSES is performed by concatenating the document type (field DRAW-DOKAR), the document number (field DRAW-DOKNR), the document version (field DRAW-DOKVR) and the document part (field DRAW-DOKTL). In code this can be expressed as follows

 DATA
    wa_draw TYPE draw, 
    cur_bapi_objectkey LIKE inob-objek,

    class_list TYPE STANDARD TABLE OF bapi1003_alloc_list,
    valueschar TYPE STANDARD TABLE OF bapi1003_alloc_values_char,
    valuescurr TYPE STANDARD TABLE OF bapi1003_alloc_values_curr,
    valuesnum  TYPE STANDARD TABLE OF bapi1003_alloc_values_num,
    return     TYPE STANDARD TABLE OF bapiret2.

*   Make wa_draw somehow correspond to a valid document entry ....     
    CONCATENATE wa_draw-dokar
                wa_draw-doknr
                wa_draw-dokvr
                wa_draw-doktl
                INTO cur_bapi_objectkey.

*   Call BAPI to get the list of characteristics
    CALL FUNCTION 'BAPI_OBJCL_GETCLASSES'
    EXPORTING
      objectkey_imp         = cur_bapi_objectkey
      objecttable_imp       = 'DRAW'
      classtype_imp         = '017'
      read_valuations       = 'X'
      keydate               = sy-datum
*     language              = 'E'
    TABLES
      alloclist             = class_list
      allocvalueschar       = valueschar
      allocvaluescurr       = valuescurr
      allocvaluesnum        = valuesnum
      return                = return.

    READ TABLE return INDEX 1 ASSIGNING <ret>.

*   Check that object allocations exist
    IF  sy-subrc = 0 AND
        <ret>-id = 'CL' AND
        <ret>-number = 741.

*      Read characteristic values
       ...
    ENDIF

No comments :