Read classifications

In these examples we are looking up the export control number for the classification countries Germany and USA. In the first tab we read the material data for a specific plant, in the second one we collect all export control numbers for all plants of the material.
The third tab shows an example for reading individual classifications.

DATA:
  smat_read_bc        TYPE REF TO /aeb/cl_ta_pb_smat_read_bc,
  smat_mo             TYPE REF TO /aeb/if_ta_pb_smat_mo,
  tt_smat_cls_mo      TYPE /aeb/if_ta_pb_smat_cls_mo=>tt_smat_cls_mo,
  smat_cls_mo         TYPE REF TO /aeb/if_ta_pb_smat_cls_mo,
  country_iso_code_nv TYPE REF TO /aeb/cl_01_char_2_nv,
  tt_smat_val_mo      TYPE /aeb/if_ta_pb_smat_val_mo=>tt_smat_val_mo,
  smat_val_mo         TYPE REF TO /aeb/if_ta_pb_smat_val_mo,
  ident_code_nv       TYPE REF TO /aeb/cl_01_char_20_nv,
  value_nv            TYPE REF TO /aeb/cl_01_string_nv,
  eccn                TYPE string,
  al_no               TYPE string.

smat_read_bc = /aeb/cl_ta_pb_smat_read_bc=>new_for( im_material_no    = 'MAT_NO'
                                                    im_material_plant = 'PLANT' ).
smat_mo = smat_read_bc->get_material( ).
tt_smat_cls_mo = smat_mo->get_classifications( ).

LOOP AT tt_smat_cls_mo INTO smat_cls_mo.
  country_iso_code_nv = smat_cls_mo->get_ctry_iso_code( ).
  CASE country_iso_code_nv->v.
    WHEN 'US'.
      tt_smat_val_mo = smat_cls_mo->get_values( ).
      LOOP AT tt_smat_val_mo INTO smat_val_mo.
        ident_code_nv = smat_val_mo->get_ident_code( ).
        IF ident_code_nv->v = /aeb/if_ta_pb_smat_val_mo=>c_export_control_no_identcode.
          value_nv = smat_val_mo->get_value( ).
          eccn = value_nv->v.
          EXIT.
        ENDIF.
      ENDLOOP.
    WHEN 'DE'.
      tt_smat_val_mo = smat_cls_mo->get_values( ).
      LOOP AT tt_smat_val_mo INTO smat_val_mo.
        ident_code_nv = smat_val_mo->get_ident_code( ).
        IF ident_code_nv->v = /aeb/if_ta_pb_smat_val_mo=>c_export_control_no_identcode.
          value_nv = smat_val_mo->get_value( ).
          al_no = value_nv->v.
          EXIT.
        ENDIF.
      ENDLOOP.
  ENDCASE.
ENDLOOP.
DATA:
  tt_werks            TYPE plants,
  smat_read_bc        TYPE REF TO /aeb/cl_ta_pb_smat_read_bc,
  smat_mo             TYPE REF TO /aeb/if_ta_pb_smat_mo,
  tt_smat_cls_mo      TYPE /aeb/if_ta_pb_smat_cls_mo=>tt_smat_cls_mo,
  smat_cls_mo         TYPE REF TO /aeb/if_ta_pb_smat_cls_mo,
  country_iso_code_nv TYPE REF TO /aeb/cl_01_char_2_nv,
  tt_smat_val_mo      TYPE /aeb/if_ta_pb_smat_val_mo=>tt_smat_val_mo,
  smat_val_mo         TYPE REF TO /aeb/if_ta_pb_smat_val_mo,
  ident_code_nv       TYPE REF TO /aeb/cl_01_char_20_nv,
  value_nv            TYPE REF TO /aeb/cl_01_string_nv,
  eccns               TYPE STANDARD TABLE OF string WITH DEFAULT KEY,
  al_nos              TYPE STANDARD TABLE OF string WITH DEFAULT KEY.
FIELD-SYMBOLS:
  <curr_plant>        TYPE werks_d.

SELECT werks FROM t001w GROUP BY werks INTO TABLE @tt_werks.

LOOP AT tt_werks ASSIGNING <curr_plant>.
  smat_read_bc = /aeb/cl_ta_pb_smat_read_bc=>new_for( im_material_no    = 'MAT_NO'
                                                      im_material_plant = <curr_plant> ).
  smat_mo = smat_read_bc->get_material( ).

  IF smat_mo IS NOT INITIAL.
    tt_smat_cls_mo = smat_mo->get_classifications( ).

    LOOP AT tt_smat_cls_mo INTO smat_cls_mo.
      country_iso_code_nv = smat_cls_mo->get_ctry_iso_code( ).
      CASE country_iso_code_nv->v.
        WHEN 'US'.
          tt_smat_val_mo = smat_cls_mo->get_values( ).
          LOOP AT tt_smat_val_mo INTO smat_val_mo.
            ident_code_nv = smat_val_mo->get_ident_code( ).
            IF ident_code_nv->v = /aeb/if_ta_pb_smat_val_mo=>c_export_control_no_identcode.
              value_nv = smat_val_mo->get_value( ).
              IF value_nv->v IS NOT INITIAL.
                COLLECT value_nv->v INTO eccns.
              ENDIF.
              EXIT.
            ENDIF.
          ENDLOOP.
        WHEN 'DE'.
          tt_smat_val_mo = smat_cls_mo->get_values( ).
          LOOP AT tt_smat_val_mo INTO smat_val_mo.
            ident_code_nv = smat_val_mo->get_ident_code( ).
            IF ident_code_nv->v = /aeb/if_ta_pb_smat_val_mo=>c_export_control_no_identcode.
              value_nv = smat_val_mo->get_value( ).
              IF value_nv->v IS NOT INITIAL.
                COLLECT value_nv->v INTO al_nos.
              ENDIF.
              EXIT.
            ENDIF.
          ENDLOOP.
      ENDCASE.
    ENDLOOP.
  ENDIF.
ENDLOOP.
CONSTANTS:
  cc_ident_cde_tares TYPE /aeb/01_char50 VALUE 'TARES_CH'.
DATA:
  smat_read_bc        TYPE REF TO /aeb/cl_ta_pb_smat_read_bc,
  smat_mo             TYPE REF TO /aeb/if_ta_pb_smat_mo,
  smat_cc_mos         TYPE /aeb/if_ta_pb_smat_cc_mo=>tt_smat_cc_mo,
  curr_smat_cc_mo     TYPE REF TO /aeb/if_ta_pb_smat_cc_mo,
  country_iso_code_nv TYPE REF TO /aeb/cl_01_char_2_nv,
  ident_code_nv       TYPE REF TO /aeb/cl_01_char_50_nv,
  value_nv            TYPE REF TO /aeb/cl_01_char_255_nv,
  tares_ch_value      TYPE string.

smat_read_bc = /aeb/cl_ta_pb_smat_read_bc=>new_for( im_material_no    = 'MAT_NO'
                                                    im_material_plant = 'PLANT' ).
smat_mo = smat_read_bc->get_material( ).

IF smat_mo IS NOT INITIAL.
  smat_cc_mos = smat_mo->get_classification_codes( ).
ENDIF.

LOOP AT smat_cc_mos INTO curr_smat_cc_mo.
  country_iso_code_nv = curr_smat_cc_mo->get_country_iso_code( ).
  ident_code_nv = curr_smat_cc_mo->get_identcode( ).
  IF ( country_iso_code_nv IS INITIAL
    OR country_iso_code_nv->v IS INITIAL )
    AND ident_code_nv IS NOT INITIAL
    AND ident_code_nv->v = cc_ident_cde_tares.
    value_nv = curr_smat_cc_mo->get_value( ).
    IF value_nv IS NOT INITIAL.
      tares_ch_value = value_nv->v.
    ENDIF.
  ENDIF.
ENDLOOP.