Hello all,

In DMS LSMW when upload more than 12 characteristics( in screen)  need next page and many time i  can not upload characteristics my best friend Reza Mohammadi write ABAP program to upload characteristics this program is Dynamic and upload 30 characteristics.

 

step 1: create excel file and type characteristics in first row similar this table

Doc Type Document number ( 25 char) version Part Characteristics Code 1 ( *) Characteristics Code 1 Characteristics Code 30
ENG 000000000010000000000001 00 000 IFA DW
ENG 000000000010000000000001 01 000 AFC IR

 

*Characteristics Code ( Name of Characteristics when you create Characteristics in t.code : ct04 )


**&---------------------------------------------------------------------*
**& Report  ZDMS_MASS_CHARACTERISTICS_UPDATE
**&
**&---------------------------------------------------------------------*
**&
**&
**&---------------------------------------------------------------------*
REPORT  ZDMS_MASS_CHAR_UPDATE.
*
*CONSTANTS DIR_COUNT TYPE i VALUE 4.
TYPES:
      BEGIN OF ST_DIR,
        DOKAR TYPE DOKAR,
        DOKNR TYPE DOKNR,
        DOKVR TYPE DOKVR,
        DOKTL TYPE DOKTL_D,
        CHAR1 TYPE CHAR30,
        CHAR2 TYPE CHAR30,
        CHAR3 TYPE CHAR30,
        CHAR4 TYPE CHAR30,
        CHAR5 TYPE CHAR30,
        CHAR6 TYPE CHAR30,
        CHAR7 TYPE CHAR30,
        CHAR8 TYPE CHAR30,
        CHAR9 TYPE CHAR30,
        CHAR10 TYPE CHAR30,
        CHAR11 TYPE CHAR30,
        CHAR12 TYPE CHAR30,
        CHAR13 TYPE CHAR30,
        CHAR14 TYPE CHAR30,
        CHAR15 TYPE CHAR30,
        CHAR16 TYPE CHAR30,
        CHAR17 TYPE CHAR30,
        CHAR18 TYPE CHAR30,
        CHAR19 TYPE CHAR30,
        CHAR20 TYPE CHAR30,
        VISITED TYPE CHAR1,
      END OF ST_DIR.
*
DATA: it_documents TYPE TABLE OF st_dir,
      wa_documents TYPE st_dir.
DATA it_CharNames TYPE TABLE OF ATNAM WITH HEADER LINE.
DATA: it_tab TYPE filetable,
      gd_subrc TYPE i.
*Selection screen definition
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS:
            CL_NAME TYPE TDWA-KLASSE DEFAULT 'CL_SP19',
            CL_TYPE TYPE TDWA-KLASSENART DEFAULT '017',
            BEG_ROW TYPE i DEFAULT 2,
            END_ROW TYPE i DEFAULT 101,
            p_file LIKE rlgrap-filename
                DEFAULT 'c:\test.xls' OBLIGATORY.  " File Name
SELECTION-SCREEN END OF BLOCK b1.
***********************************************************************
* AT SELECTION-SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  REFRESH: it_tab.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title    = 'Select File'
      default_filename = '*.xls'
      multiselection  = ' '
    CHANGING
      file_table      = it_tab
      rc              = gd_subrc.
  LOOP AT it_tab INTO p_file.
*    so_fpath-sign = 'I'.
*    so_fpath-option = 'EQ'.
*    append so_fpath.
  ENDLOOP.
************************************
* START-OF-SELECTION.
START-OF-SELECTION.
  PERFORM read_char_names USING p_file.
  PERFORM upload_excel_file TABLES  it_documents
                              USING  p_file
                                      1
                                      BEG_ROW
                                      40
                                      END_ROW.
  PERFORM UPDATE_CHARS.
***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
FORM upload_excel_file TABLES  p_table
                        USING    p_file
                                p_scol
                                p_srow
                                p_ecol
                                p_erow.
  DATA : lt_intern TYPE  Zkcde_cells OCCURS 0 WITH HEADER LINE.
  DATA : ld_index TYPE i.
  FIELD-SYMBOLS : <fs>.
* Note: Alternative function module - 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  CALL FUNCTION 'ZKCD_EXCEL_OLE_TO_INT_CONVERT'
    EXPORTING
      filename                = p_file
      i_begin_col            = p_scol
      i_begin_row            = p_srow
      i_end_col              = p_ecol
      i_end_row              = p_erow
    TABLES
      intern                  = lt_intern
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  IF sy-subrc <> 0.
    FORMAT COLOR COL_BACKGROUND INTENSIFIED.
    WRITE:/ 'Error Uploading file'.
    EXIT.
  ENDIF.
  IF lt_intern[] IS INITIAL.
    FORMAT COLOR COL_BACKGROUND INTENSIFIED.
    WRITE:/ 'No Data Uploaded'.
    EXIT.
  ELSE.
    SORT lt_intern BY row col.
    LOOP AT lt_intern.
      MOVE lt_intern-col TO ld_index.
      ASSIGN COMPONENT ld_index OF STRUCTURE p_table TO <fs>.
      MOVE lt_intern-value TO <fs>.
      AT END OF row.
        APPEND p_table.
        CLEAR p_table.
      ENDAT.
    ENDLOOP.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  READ_HEADER_LINE
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*      -->P_FILEPATH  text
*----------------------------------------------------------------------*
FORM READ_CHAR_NAMES  USING    P_FILEPATH.
  REFRESH IT_CHARNAMES.
  DATA it_file_content TYPE TABLE OF ZKCDE_CELLS WITH HEADER LINE.
  CALL FUNCTION 'ZKCD_EXCEL_OLE_TO_INT_CONVERT'
    EXPORTING
      FILENAME                      = P_FILEPATH
      I_BEGIN_COL                  = 5
      I_BEGIN_ROW                  = 1
      I_END_COL                    = 40 "MAX no of cols
      I_END_ROW                    = 1
    TABLES
      INTERN                        = it_file_content
  EXCEPTIONS
    INCONSISTENT_PARAMETERS      = 1
    UPLOAD_OLE                    = 2
    OTHERS                        = 3
            .
  IF SY-SUBRC <> 0.
    FORMAT COLOR COL_BACKGROUND INTENSIFIED.
    WRITE:/ 'Error Uploading file'.
    EXIT.
  ENDIF.
  DATA: rowCount TYPE i.
  rowCount = LINES( it_file_content ).
  IF rowCount > 0.
    LOOP AT it_file_Content. "Read char names from Row 1
      it_CharNames = it_file_content-VALUE.
      APPEND IT_CHARNAMES.
    ENDLOOP.
  ELSE.
    RETURN.
  ENDIF.
ENDFORM.                    " READ_HEADER_LINE
*&---------------------------------------------------------------------*
*&      Form  UPDATE_CHARS
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM UPDATE_CHARS .
  FIELD-SYMBOLS : <fs>.
  DATA:
        ret TYPE BAPIRET2,
        ls_doc    LIKE bapi_doc_draw2,
        ls_docx  LIKE bapi_doc_drawx2,
        it_char TYPE TABLE OF BAPI_CHARACTERISTIC_VALUES WITH HEADER LINE,
        it_classallocation TYPE TABLE OF bapi_class_allocation WITH HEADER LINE,
        char_count TYPE i,
        char_index TYPE i VALUE 4.
  char_count = LINES( IT_CHARNAMES ).
  it_classallocation-CLASSNAME = CL_NAME.
  it_classallocation-CLASSTYPE = CL_TYPE.
  APPEND it_classallocation.
  LOOP AT IT_DOCUMENTS INTO WA_DOCUMENTS.
    ls_doc-DOCUMENTNUMBER = wa_documents-doknr.
    ls_doc-DOCUMENTPART = wa_documents-doktl.
    ls_doc-DOCUMENTTYPE = wa_documents-dokar.
    ls_doc-DOCUMENTVERSION = wa_documents-dokvr.
    REFRESH: it_char.
    "Read charachteristics values
    char_index = 4.
    DO char_count TIMES.
      ADD 1 TO char_index.
      READ TABLE IT_CHARNAMES INDEX char_index - 4. " Characteristic Name
      it_char-CHARNAME = IT_CHARNAMES.
      ASSIGN COMPONENT char_index OF STRUCTURE WA_DOCUMENTS TO <fs>. "Characteristic Value
      it_char-CHARVALUE = <fs>.
      it_char-CLASSNAME = CL_NAME.
      it_char-CLASSTYPE = CL_TYPE.
      APPEND it_char.
    ENDDO.
    CALL FUNCTION 'BAPI_DOCUMENT_CHANGE2'
      EXPORTING
        DOCUMENTTYPE        = ls_doc-DOCUMENTTYPE
        DOCUMENTNUMBER      = ls_doc-DOCUMENTNUMBER
        DOCUMENTPART        = LS_DOC-DOCUMENTPART
        DOCUMENTVERSION      = ls_doc-DOCUMENTVERSION
        DOCUMENTDATA        = LS_DOC
        DOCUMENTDATAX        = LS_DOCX
*      HOSTNAME            =
*      DOCBOMCHANGENUMBER  =
*      DOCBOMVALIDFROM      =
*      DOCBOMREVISIONLEVEL  =
*      SENDCOMPLETEBOM      = ' '
*      PF_FTP_DEST          = ' '
*      PF_HTTP_DEST        = ' '
*      CAD_MODE            = ' '
*      ACCEPT_EMPTY_BOM    = ' '
      IMPORTING
        RETURN              = ret
      TABLES
        CHARACTERISTICVALUES = IT_CHAR
        CLASSALLOCATIONS    = it_classallocation
*      DOCUMENTDESCRIPTIONS =
*      OBJECTLINKS          =
*      DOCUMENTSTRUCTURE    =
*      DOCUMENTFILES        =
*      LONGTEXTS            =
*      COMPONENTS          =
      .
*
    DATA msg TYPE char100.
    IF ret-type CA 'EA'.
      ROLLBACK WORK.
*      MESSAGE ID '26' TYPE 'I' NUMBER '000'
*              WITH ret-message.
      CONCATENATE 'ERROR: ' ret-MESSAGE ' :: ' INTO msg SEPARATED BY SPACE.
      WRITE:/ msg.
      CONCATENATE 'Document: ' ls_doc-DOCUMENTNUMBER ls_doc-DOCUMENTTYPE  ls_doc-DOCUMENTPART  ls_doc-DOCUMENTVERSION ' NOT Updated!.' INTO msg SEPARATED BY SPACE.
      WRITE:/ msg.
    ELSE.
      COMMIT WORK.
      CONCATENATE 'Document: ' ls_doc-DOCUMENTNUMBER ls_doc-DOCUMENTTYPE ls_doc-DOCUMENTPART ls_doc-DOCUMENTVERSION ' Updated.' INTO msg SEPARATED BY SPACE.
      WRITE:/ msg.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " UPDATE_CHARS
To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply