Skip to Content

Business Case

When you look for a 3rd party vendor for error tolerant search, duplicate identification and postal address correction do a search at the SAP Partner Directory for Solution Category -> Address service. There are many vendors providing such services. They also provide it as a ASP solution where you upload your data and then get a list with identified duplicates. In our case this list had this format:

 

 

 

 

 

 

 

 

 

 

Case Partner Number
1 815
1 3974
2 3493
2 9784

Implementation

SAP provides the BAPI BAPI_CLEAR_CASE_CREATE_MULTI so it is straight forward to implement this program

REPORT  z_bup_create_cl_case.
 
PARAMETERS: p_infile  LIKE rlgrap-filename
                        OBLIGATORY.
 
DATA: gd_file TYPE string.
 
* internal table to upload data into
DATA: BEGIN OF it_datatab OCCURS 0,
        row(500) TYPE c,
      END OF it_datatab.
 
* internal tabe to store upload data
TYPES: BEGIN OF t_record,
         case TYPE comt_clear_number,
         partner TYPE bu_partner,
       END OF t_record.
*
* internal table for upload list and cleansing cases
*
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0 WITH NON-UNIQUE KEY case,
      wa_record TYPE t_record,
      wa_record_temp TYPE t_record,
      it_case TYPE STANDARD TABLE OF t_record INITIAL SIZE 0 WITH NON-UNIQUE KEY case,
      wa_case TYPE t_record.
*
* variables for BAPI BAPI_CLEAR_CASE_CREATE_MULTI
*
DATA: clearingcasedata    TYPE TABLE OF bapibus2132_clear_case_data,
      ls_clearingcasedata LIKE LINE OF clearingcasedata,
      targetlist          TYPE TABLE OF bapibus2132_targ_data,
      wa_targetlist       LIKE LINE OF targetlist,
      clearingcasenumbers TYPE TABLE OF bapibus2132_clear_case_key,
      wa_clearingcasenumbers LIKE LINE OF clearingcasenumbers,
      return              TYPE TABLE OF bapiret2,
      wa_return           LIKE LINE OF return.
* tab is seperator
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONSTANTS:
    con_tab  TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
* Some other variables
DATA: partner TYPE bu_partner.
*
* File Selector
*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      def_filename     = p_infile
      mask             = ',*.txt.'
      mode             = 'O'
      title            = 'Upload File'(078)
    IMPORTING
      filename         = p_infile
    EXCEPTIONS
      inv_winsys       = 1
      no_batch         = 2
      selection_cancel = 3
      selection_error  = 4
      OTHERS           = 5.
 
START-OF-SELECTION.
  gd_file = p_infile.
*
* Upload
*
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = gd_file
      has_field_separator     = 'X'  "file is TAB delimited
    TABLES
      data_tab                = it_record
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc NE 0.
    WRITE: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
    SKIP.
  ENDIF.
 
END-OF-SELECTION.
*
* Build tableit_case that only hase case numbers
*
  SORT it_record BY case.
  it_case[] = it_record[].
  DELETE ADJACENT DUPLICATES FROM it_case COMPARING case.
 
  LOOP AT it_case INTO wa_case.
    CLEAR: ls_clearingcasedata.
    LOOP AT it_record INTO wa_record WHERE case = wa_case-case.
      CLEAR: wa_targetlist.
*     Build up case table
      wa_targetlist-case_number = wa_case-case.
*     Add leading zeros to partner number
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_record-partner
        IMPORTING
          output = partner.
      wa_targetlist-object_appl_key = partner.
      CONCATENATE ls_clearingcasedata-note partner
        INTO ls_clearingcasedata-note SEPARATED BY space.
      APPEND wa_targetlist TO targetlist.
    ENDLOOP.
    ls_clearingcasedata-case_number = wa_case-case.
*   This cleasing case is for duplicates
    ls_clearingcasedata-case_type = 'D'.
    ls_clearingcasedata-application = 'BUPA'.
    ls_clearingcasedata-source = sy-title.
    APPEND ls_clearingcasedata TO clearingcasedata.
  ENDLOOP.
* Create Cleansing cases
  CALL FUNCTION 'BAPI_CLEAR_CASE_CREATE_MULTI'
    EXPORTING
      acceptduplicates          = 'X'
    TABLES
      clearingcasedata          = clearingcasedata
      targetlist                = targetlist
      clearingcasenumbers       = clearingcasenumbers
      return                    = return.
* Commit Transaction
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     wait          = 'X'.
  IF NOT return IS INITIAL.
    WRITE: / 'Error messages'.
    LOOP AT return INTO wa_return.
      WRITE:/     sy-vline,
             (10) wa_return-type, sy-vline,
             (10) wa_return-message, sy-vline.
    ENDLOOP.
  ENDIF.
* Output created cleansing cases
  WRITE:/     sy-vline,
         (10) 'Case No.', sy-vline,
         (10) 'Orig. No.', sy-vline.
  LOOP AT clearingcasenumbers INTO wa_clearingcasenumbers.
    WRITE:/     sy-vline,
           (10) wa_clearingcasenumbers-case_number, sy-vline,
           (10) wa_clearingcasenumbers-original_number, sy-vline.
  ENDLOOP.
To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Jagruti Singavi

    Hi Gregor,

    I tried to create a cleansing case using FM : BAPI_CLEAR_CASE_CREATE_MULTI and got the cleansing case no created too with  CASE_NUMBER , ORIGINAL_NUMBER and CASE_GUID.

    But i am unable to find the same when trying to view it from FM : BAPI_CLEAR_CASE_GET_DETAIL.

    I am unable to find the reason.

    Please can you help me.

    I am new to SAP.

    waiting for reply.

    (0) 

Leave a Reply