Some more technical details about SAP note

I use this note 2184333 which I am responsible for as an example:

Some more technical details about SAP note

In order to research the technical design of SAP note, I write a simple tool for analysis.

How to use this tool

paste the following source code to create a report and run:

REPORT znote.

PARAMETERS: note TYPE cwbntkeylg-numm OBLIGATORY DEFAULT '2184333'.
DATA: lv_insta           TYPE cwbntinsta,
      ls_note_key        TYPE cwbntkeylg,
      lv_full_length     TYPE i,
      lt_comp            TYPE abap_compdescr_tab,
      lv_data_bin        TYPE xstring,
      lv_code_delta_bin  TYPE xstring,
      lt_object_data_bin TYPE cwbci_t_objdelta,
      lv_rfcmsg          LIKE scwbrfcmsg-text,
      lv_key             TYPE hash160,
      lv_check_key       TYPE hash160,
      lv_offset          TYPE i,
      lv_max_length      TYPE i,
      lv_data            TYPE xstring,
      lv_chunk_data      TYPE xstring,
      lv_unzipped_size   TYPE i,
      lt_cwbnthead       LIKE cwbnthead OCCURS 0,
      lt_cwbntstxt       LIKE cwbntstxt OCCURS 0,
      lt_cwbntdata       TYPE bcwbn_note_text OCCURS 0,
      lt_cwbntdata_html  TYPE bcwbn_notehtml_text OCCURS 0,
      lt_cwbntvalid      LIKE cwbntvalid OCCURS 0,
      lt_cwbntci         LIKE cwbntci OCCURS 0,
      lt_cwbntfixed      LIKE cwbntfixed OCCURS 0,
      lt_cwbntgattr      LIKE cwbntgattr OCCURS 0,
      lt_cwbcihead       LIKE cwbcihead OCCURS 0,
      lt_cwbcidata       TYPE bcwbn_cinst_delta OCCURS 0,
      lt_cwbcidata_ref   TYPE cwb_deltas,
      lt_cwbcivalid      LIKE cwbcivalid OCCURS 0,
      lt_cwbciinvld      LIKE cwbciinvld OCCURS 0,
      lt_cwbcifixed      LIKE cwbcifixed OCCURS 0,
      lt_cwbcidpndc      LIKE cwbcidpndc OCCURS 0,
      lt_cwbciobj        LIKE cwbciobj OCCURS 0,
      lt_cwbcmpnt        LIKE cwbcmpnt OCCURS 0,
      lt_cwbcmtext       LIKE cwbcmtext OCCURS 0,
      lt_cwbcmlast       LIKE cwbcmlast OCCURS 0,
      lt_cwbdehead       LIKE cwbdehead OCCURS 0,
      lt_cwbdeprdc       LIKE cwbdeprdc OCCURS 0,
      lt_cwbdetrack      LIKE cwbdetrack OCCURS 0,
      lt_cwbdeequiv      LIKE cwbdeequiv OCCURS 0,
      lt_cwbcinstattr    TYPE cwbci_t_attr.

START-OF-SELECTION.
  PERFORM main.
FORM main.

  ls_note_key-langu = 'E'.
  ls_note_key-numm = note.

  CALL FUNCTION 'SLIC_GET_LICENCE_NUMBER'
    IMPORTING
      license_number = lv_insta.

  CALL FUNCTION 'BHREM_SAPNOTE_RFC_GET_CHUNKED' DESTINATION 'SAPSNOTE'
    EXPORTING
      is_note_key_lg        = ls_note_key
      iv_check_status       = 'X'
      iv_insta_cust         = lv_insta
      iv_na_fmt_id          = 3
    IMPORTING
      ev_full_length        = lv_full_length
      ev_chunk_data         = lv_chunk_data
    CHANGING
      cv_key                = lv_key
      cv_chunk_offset       = lv_offset
      cv_chunk_max_length   = lv_max_length
    EXCEPTIONS
      system_failure        = 1 MESSAGE lv_rfcmsg
      communication_failure = 2 MESSAGE lv_rfcmsg
      note_not_exist        = 3
      note_not_released     = 4
      note_langu_not_exist  = 5
      pack_error            = 6
      note_incomplete       = 7
      note_format_error     = 8
      protocol_error        = 9
      OTHERS                = 10.

  IF sy-subrc <> 0.
    WRITE: / 'note download failed: ', lv_rfcmsg.
    RETURN.
  ENDIF.

  WRITE: / 'size ( compressed ):', lv_full_length.

  lv_data = lv_chunk_data.

  CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
    EXPORTING
      alg            = 'SHA1'
      data           = lv_data
    IMPORTING
      hash           = lv_check_key
    EXCEPTIONS
      unknown_alg    = 1
      param_error    = 2
      internal_error = 3
      OTHERS         = 4.
  IF lv_check_key <> lv_key.
    WRITE:/ 'note key verification failed.'.
    RETURN.
  ENDIF.

  cl_abap_gzip=>decompress_binary( EXPORTING gzip_in   = lv_data
                                   IMPORTING raw_out   = lv_data ).

  CALL TRANSFORMATION id SOURCE XML lv_data
                         RESULT xml_data_bin         = lv_data_bin
                                xml_code_delta_bint  = lv_code_delta_bin
                                xml_object_data_bin  = lt_object_data_bin.

  CALL FUNCTION 'SCWN_NOTE_UNPACK_XML'
    EXPORTING
      iv_data_bin           = lv_data_bin
      iv_code_delta_bin     = lv_code_delta_bin
      it_object_data_bin    = lt_object_data_bin
    IMPORTING
      et_cwbnthead          = lt_cwbnthead
      et_cwbntstxt          = lt_cwbntstxt
      et_htmltext           = lt_cwbntdata_html
      et_cwbntdata          = lt_cwbntdata
      et_cwbntvalid         = lt_cwbntvalid
      et_cwbntci            = lt_cwbntci
      et_cwbntfixed         = lt_cwbntfixed
      et_cwbntgattr         = lt_cwbntgattr
      et_cwbcihead          = lt_cwbcihead
      et_cwbcidata          = lt_cwbcidata
      et_cwbcidata_ref      = lt_cwbcidata_ref
      et_cwbcivalid         = lt_cwbcivalid
      et_cwbciinvld         = lt_cwbciinvld
      et_cwbcifixed         = lt_cwbcifixed
      et_cwbcidpndc         = lt_cwbcidpndc
      et_cwbciobj           = lt_cwbciobj
      et_cwbcmpnt           = lt_cwbcmpnt
      et_cwbcmtext          = lt_cwbcmtext
      et_cwbcmlast          = lt_cwbcmlast
      et_cwbdehead          = lt_cwbdehead
      et_cwbdeprdc          = lt_cwbdeprdc
      et_cwbdetrack         = lt_cwbdetrack
      et_cwbdeequiv         = lt_cwbdeequiv
      et_cwbcinstattr       = lt_cwbcinstattr
    EXCEPTIONS
      corrupt_data_file     = 1
      incompatible_versions = 2
      OTHERS                = 3.

  PERFORM cal_obj_data_bin_size USING lt_object_data_bin CHANGING lv_unzipped_size.
  WRITE: / 'uncompressed size: (byte): ' , lv_unzipped_size.
  BREAK-POINT.

ENDFORM.

FORM cal_obj_data_bin_size USING it_obj_data TYPE cwbci_t_objdelta CHANGING iv_total_size TYPE i.
  DATA(lo_tab_type) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_name( 'CWBCI_T_OBJDELTA' ) ).

  DATA(lo_line_type) = CAST cl_abap_structdescr( lo_tab_type->get_table_line_type( ) ).
  lt_comp = lo_line_type->components.
  LOOP AT it_obj_data ASSIGNING FIELD-SYMBOL(<obj_data_bin>).
    PERFORM calculate_line_size USING <obj_data_bin> CHANGING iv_total_size.
  ENDLOOP.
ENDFORM.

FORM calculate_line_size USING is_line_data TYPE cwbciobjdelta CHANGING iv_total_size TYPE i.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE is_line_data TO FIELD-SYMBOL(<data>).
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

    READ TABLE lt_comp ASSIGNING FIELD-SYMBOL(<line_type>) INDEX sy-index.
    CASE <line_type>-type_kind.

      WHEN cl_abap_typedescr=>typekind_char OR cl_abap_typedescr=>typekind_num.
        iv_total_size = iv_total_size + strlen( <data> ) * 2.
      WHEN cl_abap_typedescr=>typekind_xstring.
        iv_total_size = iv_total_size + xstrlen( <data> ).
      WHEN OTHERS.
        ASSERT 1 = 0.
    ENDCASE.

  ENDDO.
ENDFORM. 

Once executed, the report will download the note as a compressed binary stream, display the size of this compressed stream and then uncompress it, allow you to view the building block of the note in detail. In the end the size of uncompressed data is displayed as well.
Take note 2184333 for example, around 137 KB is downloaded and after it is decompressed, the size inflates to around 742 KB.

Some more technical details about SAP note

Please note that this tool just gives you a draft estimation about the static size of note. The runtime overhead for memory management against deep data object such as internal table and string are not considered.

Some more technical details about SAP note

Note building blocks

The decompressed content of note is actually a xml file and could be parsed by function module SCWN_NOTE_UNPACK_XML

Some more technical details about SAP note

et_cwbnthead

Note header data. See below picture to find how the note header information is maintained in exporting parameter et_cwbnthead of FM SCWN_NOTE_UNPACK_XML.

Some more technical details about SAP note

et_cwbntstxt

Note tilte in multi language.

Some more technical details about SAP note

et_htmltext

Contains note body in html format in multi language. Content for each language is stored in a single line.

Some more technical details about SAP note

et_cwbntdata

Contains note body in multiple language. Content of each language is stored in a seperate internal table.

Some more technical details about SAP note

et_cwbntvalid

Contains note validity information. In this information, component key: 16929, we can find its description from table CWBCMPNT. And 63 for BBPCRM.

Some more technical details about SAP note

And how to understand DEALEID_V 244 for BBPCRM?
From this table we can know “244” represents 713.

Some more technical details about SAP note

detailed code delta change contained in variable LV_CODE_DELTA_BIN

The area below marked with blue rectangle is the code delta change our customer could see in the note browser, and the red area is part of variable lv_code_delta_bin inspected via XML Browser. The delta code change consists of two parts:
deletion of keyword “IMPORTING”;
insertion of two lines “it_customer_h = it_customer_h” and “IMPORTING”.
From the picture we can see clearly that the code fragment for insertion or deletion has corresponding XML tag ( I prefer to call it as “directive” ) maintained so that the node tool can know WHAT operation should be performed on these fragment. Meanwhile the context ( line number 38 ) is also known so that node tool can also know WHERE the delta change should be applied.

Some more technical details about SAP note 要获取更多Jerry的原创文章,请关注公众号"汪子熙": Some more technical details about SAP note
上一篇:Technical support(URL)


下一篇:WebService 入门