Skip to Content
Author's profile photo Former Member

Downloading a file from EDMS

This report  shows , downloading a file from EDMS through ABAP Program ,

REPORT  ZEDMS .
TABLES : DRAW ,MKPF , BKPF , DMS_DOC2LOIO , DMS_PH_CD1.

TYPES : BEGIN OF TY_DATA .
         INCLUDE STRUCTURE DRAD.
TYPES : END OF TY_DATA.

TYPES : BEGIN OF TY_URL ,
            DOCNO  TYPE CHAR25,
            DOCTYP TYPE CHAR3,
            DOCPT  TYPE CHAR3 ,
            DOCVER TYPE CHAR2,
            FILE   TYPE CHAR35,
            URL    TYPE DMS_URL ,
            fin    TYPE BKPFBELNR,
            com    TYPE BKPFBUKRS,
            year1  TYPE BKPFGJAHR,
            mat    TYPE  MKPFMBLNR ,
            year   TYPE MKPFMJAHR ,
            stat(2) ,
            stat1(16) ,
         END OF TY_URL .

TYPES : BEGIN OF orgin .
         INCLUDE STRUCTURE CVAPI_DOC_FILE .
TYPES : END OF orgin .

DATA : LV_URL        TYPE DMS_URL,
        LS_DOC        TYPE BAPI_DOC_KEYS,
        IT_DATA       TYPE TABLE OF TY_DATA,
        WA_DATA       TYPE TY_DATA,
        IT_URL        TYPE TABLE OF TY_URL ,
        WA_URL        TYPE TY_URL ,
        LT_ORIGINALS  TYPE CVAPI_DOC_FILE OCCURS 0 ,
        LS_DRAW       TYPE DRAW,
        FIN           TYPE BKPFBELNR,
        COM           TYPE BKPFBUKRS,
        YEAR3         TYPE BKPFGJAHR,
        MAT           TYPE  MKPFMBLNR ,
        YEAR2         TYPE MKPFMJAHR ,
        IT_ORG        TYPE TABLE OF ORGIN ,
        WA_ORG        TYPE ORGIN ,
        STATUS(2) ,
        STAT1(16) ,
        FILE          TYPE CHAR35,
        F(10),
        OFF           TYPE I,
        LIN           TYPE I,
        VAL(150),
        LEN           TYPE I,

  LINK TYPE STRING.
DATA :BEGIN OF TEXT1 OCCURS 0 ,
          sign(1)   TYPE c,
          option(2) TYPE c,
          low(50)   TYPE C ,
          high(50TYPE C,
       END OF TEXT1 .

SELECTION-SCREEN BEGIN OF BLOCK RK100 WITH FRAME TITLE TEXT001.
PARAMETERS : R1 RADIOBUTTON GROUP G1 USER-COMMAND AAA DEFAULT ‘X’,
              R2 RADIOBUTTON GROUP G1 .
SELECTION-SCREEN END OF BLOCK RK100.

“””””””””””””””””””””””Select Option for Material Document”””””””
SELECTION-SCREEN BEGIN OF BLOCK RK101 WITH FRAME TITLE TEXT002.
SELECT-OPTIONS : MATERIAL FOR MKPFMBLNR MODIF ID QQQ.
PARAMETERS : YEAR    TYPE  MKPFMJAHR MODIF ID QQQ.
SELECTION-SCREEN END OF BLOCK RK101.

“””””””””””””””””””””Select Option for Financial Document””””””””
SELECTION-SCREEN BEGIN OF BLOCK RK102 WITH FRAME TITLE TEXT003.
SELECT-OPTIONS : FINANCE FOR BKPFBELNR MODIF ID KKK.
PARAMETERS : COMP  TYPE BKPFBUKRS MODIF ID KKK.
PARAMETERS : YEAR1  TYPE BKPFGJAHR MODIF ID KKK.
SELECTION-SCREEN END OF BLOCK RK102.

AT SELECTION-SCREEN OUTPUT .

   LOOP AT SCREEN .
     IF SCREENGROUP1 = ‘QQQ’ AND R2 = ‘X’ .
       SCREENACTIVE = ‘0’.
       MODIFY SCREEN.
       CONTINUE.
     ENDIF .
     IF R1 = ‘X’ AND SCREENGROUP1 = ‘KKK’ .
       SCREENACTIVE = ‘0’.
       MODIFY SCREEN.
       CONTINUE.
     ELSE.

     ENDIF.
   ENDLOOP .

START-OF-SELECTION .

   IF R1 = ‘X’ .
     “* FOR MATERIAL DOCUMENT                                                         *”
     “* TEXT1 CONTAINS THE COMBINATION OF MATERIAL DOCUMENT NUMBER AND MATERIAL YEAR .*”
     CONCATENATE MATERIALLOW  YEAR  INTO TEXT1LOW .
     IF MATERIALHIGH IS NOT INITIAL .
       CONCATENATE MATERIALHIGH YEAR INTO TEXT1HIGH .
       TEXT1OPTION = ‘BT’.
     ELSE.
       TEXT1OPTION = ‘EQ’.
     ENDIF.
     TEXT1SIGN = ‘I’.
     APPEND TEXT1 .
   ELSEIF R2 = ‘X’ .
     “* FOR FINANCIAL DOCUMENT                                                        *”
     “* TEXT1 CONTAINS THE COMBINATION OF COMPANY CODE ,FINANCIAL DOCUMENT NUMBER     *”
     “* AND FINANCIAL YEAR                                                            *”
     CONCATENATE COMP  FINANCELOW  YEAR1  INTO TEXT1LOW .
     IF FINANCEHIGH IS NOT INITIAL .
       CONCATENATE COMP FINANCEHIGH YEAR1 INTO TEXT1HIGH .
       TEXT1OPTION = ‘BT’.
     ELSE.
       TEXT1OPTION = ‘EQ’.
     ENDIF.
     TEXT1SIGN = ‘I’.
     APPEND TEXT1 .
   ENDIF .

   “* TO FIND THE LIST OF DOCUMENTS WHICH SAVED IN CV01N CONTAINS THE FINANCIAL AND   *”
   “* MATERIAL DOCUMENT .                                                             *”
   SELECT * FROM DRAD INTO TABLE IT_DATA WHERE OBJKY IN TEXT1 .

   LOOP AT IT_DATA INTO WA_DATA .
     ls_docdocumenttype    = WA_DATAdokar.
     ls_docdocumentnumber  = WA_DATAdoknr.
     ls_docdocumentpart    = WA_DATAdoktl.
     ls_docdocumentversion = WA_DATAdokvr.

     “* TO GET THE DOCUMENT INFO RECORDS                                                *”
     SELECT SINGLE * FROM draw INTO ls_draw WHERE DOKAR = WA_DATAdokar
                                              AND DOKNR = WA_DATAdoknr
                                              AND DOKVR = WA_DATAdokvr
                                              AND DOKTL = WA_DATAdoktl .
     “* TO FIND THE FILE NAME OF THE DOCUMENT                                           *”
     SELECT SINGLE FILENAME INTO FILE FROM DMS_DOC_FILES WHERE DOKAR = WA_DATAdokar
                                              AND DOKNR = WA_DATAdoknr
                                              AND DOKVR = WA_DATAdokvr
                                              AND DOKTL = WA_DATAdoktl .

     “* TO FIND THE URL FOR THE DOCUMENT WHICH IS ATTACHED FROM CV01N OR CV02N          *”
     CALL FUNCTION ‘CVAPI_DOC_GETDETAIL’
       DESTINATION ‘NONE’
       EXPORTING
         pf_batchmode    = ‘X’
         pf_dokar        = ls_docdocumenttype
         pf_doknr        = ls_docdocumentnumber
         pf_dokvr        = ls_docdocumentversion
         pf_doktl        = ls_docdocumentpart
         pf_active_files = ‘X’
         pf_read_comp    = ‘X’
         pf_read_kpro    = ‘X’
       IMPORTING
         psx_draw        = ls_draw
       TABLES
         pt_files        = It_orG
       EXCEPTIONS
         not_found       = 1
         no_auth         = 2
         error           = 3
         OTHERS          = 4.

     IF R1 = ‘X’ .
       MAT  = WA_DATAOBJKY+0(10) .
       YEAR2 = WA_DATAOBJKY+10(4) .
     ELSEIF R2 = ‘X’ .
       COM   = WA_DATAOBJKY+0(4) .
       FIN   = WA_DATAOBJKY+4(10) .
       YEAR3 = WA_DATAOBJKY+14(4) .
     ENDIF.
     “* FINAL INTERNAL TABLE                                                             *”
     LOOP AT  IT_ORG INTO WA_ORG.
       if WA_ORGFILENAME = ‘ ‘.
       ELSE .
         WA_URLDOCVER WA_DATAdokvr .
         WA_URLDOCPT  WA_DATAdoktl .
         WA_URLDOCTYP WA_DATAdokar .
         WA_URLDOCNO  WA_DATAdoknr .
         WA_URLFILE   FILE .
         WA_URLURL    WA_ORGFILENAME.
         WA_URLMAT    MAT.
         WA_URLYEAR   YEAR2 .
         WA_URLFIN    FIN .
         WA_URLCOM    COM .
         WA_URLYEAR1  YEAR3.
         WA_URLSTAT   ls_drawDOKST .
         APPEND WA_URL TO IT_URL .
         CLEAR WA_URL .
       endif.
     ENDLOOP.
     REFRESH IT_ORG .
     CLEAR LV_URL.
   ENDLOOP.

   IF R1 = ‘X’ .
     DELETE IT_URL WHERE YEAR NE YEAR .
   ELSEIF R2 = ‘X’ .
     DELETE IT_URL WHERE YEAR1 NE YEAR1 .
   ENDIF .

   IF R1 = ‘X’ .
     “* R1 –> REPORTS WILL DISPLAYS MATERIAL DOCUMENT NO                                 *”
     “* TEXT TO BE DISPLAY IN HEADER FIELD                                                *”
     WRITE : /1(265) SYULINE.
     FORMAT COLOR 1 INTENSIFIED on .
     WRITE : /1  syvline ,   2(15‘Material-Doc No’ CENTERED ,
             17  syvline 18(4)   ‘Year’ CENTERED ,
             22  SYVLINE 23(25‘Doc Number’ CENTERED ,
             48  syvline 49(8)   ‘Doc Type  ‘ CENTERED ,
             57  SYVLINE 58(4)   ‘Part’ CENTERED  ,
             62  SYVLINE 63(8)   ‘Version’ CENTERED  ,
             71  SYVLINE 72(16‘Status’ CENTERED ,
             88  SYVLINE 89(25‘File Name’ CENTERED ,
            114  SYVLINE , 115(150) ‘URL’ CENTERED ,
            265 syvline .
     FORMAT RESET .
     LOOP AT IT_URL INTO WA_URL .
       “* FOR STATUS FIELD WHICH DISPLAYED IN THE REPORT                                   *”
       IF     WA_URLSTAT = ‘ZA’ .
         STAT1 = ‘Approved (Final)’.
       ELSEIF WA_URLSTAT = ‘ZD’ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZE’ .
         STAT1 = ‘Rejected Level 2’ .
       ELSEIF WA_URLSTAT = ‘ZF’ .
         STAT1 = ‘Approve 2 Final’ .
       ELSEIF WA_URLSTAT = ‘ZI’ .
         STAT1 = ‘Reviewer Level 1’ .
       ELSEIF WA_URLSTAT = ‘ZL’ .
         STAT1 = ‘Approved Level 1’ .
       ELSEIF WA_URLSTAT = ‘ZR’ .
         STAT1 = ‘Rejected’ .
       ELSEIF WA_URLSTAT = ‘ZT’ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZU’ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZV’ .
         STAT1 = ‘Review’ .
       ELSEIF WA_URLSTAT = ‘ ‘ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZW’ .
         STAT1 = ‘Deleted’ .
       ENDIF .

       AT NEW MAT.
         WRITE : /1(265) SYULINE.
       ENDAT .

       WRITE : /1  syvline 2(15)   WA_URLMAT,
               17  syvline 18(4)   WA_URLYEAR,
               22  SYVLINE 23(25WA_URLDOCNO ,
               48  syvline 49(8)   WA_URLDOCTYP,
               57  SYVLINE 58(4)   WA_URLDOCPT ,
               62  SYVLINE 63(8)   WA_URLDOCVER ,
               71  SYVLINE 72(16STAT1,
               88  SYVLINE 89(25WA_URLFILE ,
              114  SYVLINE , 115(150) WA_URLURL HOTSPOT ON  ,
              265 syvline .
     ENDLOOP .
     WRITE : /1(265) SYULINE.
   ELSEIF R2 = ‘X’ .
     “* R2 –> REPORTS WILL DISPLAYS THE FINANCIAL DOCUMENT NOS                         *”
     WRITE : /1(276) SYULINE.
     FORMAT COLOR 1 INTENSIFIED on .
     WRITE : /1  syvline ,   2(15‘Finance-Doc No’ CENTERED ,
             17  syvline 18(10‘Comp Code’ CENTERED ,
             28  syvline 29(4)   ‘Year’ CENTERED ,
             33  SYVLINE 34(25‘Doc Number’ CENTERED ,
             59  syvline 60(8)   ‘Doc Type  ‘ CENTERED ,
             68  SYVLINE 69(4)   ‘Part’ CENTERED  ,
             73  SYVLINE 74(8)   ‘Version’ CENTERED  ,
             82  SYVLINE 83(16‘Status’ CENTERED ,
             99  SYVLINE , 100(25‘File Name’ CENTERED ,
            125  SYVLINE , 126(150) ‘URL’ CENTERED ,
            276 syvline .
     FORMAT RESET .
     LOOP AT IT_URL INTO WA_URL .
       IF     WA_URLSTAT = ‘ZA’ .
         STAT1 = ‘Approved (Final)’.
       ELSEIF WA_URLSTAT = ‘ZD’ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZE’ .
         STAT1 = ‘Rejected Level 2’ .
       ELSEIF WA_URLSTAT = ‘ZF’ .
         STAT1 = ‘Approve 2 Final’ .
       ELSEIF WA_URLSTAT = ‘ZI’ .
         STAT1 = ‘Reviewer Level 1’ .
       ELSEIF WA_URLSTAT = ‘ZL’ .
         STAT1 = ‘Approved Level 1’ .
       ELSEIF WA_URLSTAT = ‘ZR’ .
         STAT1 = ‘Rejected’ .
       ELSEIF WA_URLSTAT = ‘ZT’ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZU’ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZV’ .
         STAT1 = ‘Review’ .
       ELSEIF WA_URLSTAT = ‘ ‘ .
         STAT1 = ‘Draft’ .
       ELSEIF WA_URLSTAT = ‘ZW’ .
         STAT1 = ‘Deleted’ .
       ENDIF .
       WRITE : /1(276) SYULINE.
       WRITE : /1  syvline ,   2(15WA_URLFIN,
               17  syvline 18(10WA_URLCOM,
               28  syvline 29(4)   WA_URLYEAR1,
               33  SYVLINE 34(25WA_URLDOCNO ,
               59  syvline 60(8)   WA_URLDOCTYP,
               68  SYVLINE 69(4)   WA_URLDOCPT ,
               73  SYVLINE 74(8)   WA_URLDOCVER ,
               82  SYVLINE 83(16STAT1 ,
               99  SYVLINE , 100(25WA_URLFILE ,
              125  SYVLINE , 126(150) WA_URLURL HOTSPOT ON  ,
              276 syvline.

     ENDLOOP .
     WRITE : /1(276) SYULINE.
   ENDIF.

AT LINE-SELECTION  .

   “* TO GET THE CURSOR FIELD WHERE IT IS DOUBLE CLICKED IN THE REPORT                  *”
   GET CURSOR FIELD F OFFSET OFF
                LINE LIN VALUE VAL LENGTH LEN.
   LINK = VAL .
   LOOP AT IT_URL INTO WA_URL .
     IF WA_URLurl = VAL .
       SELECT SINGLE * FROM draw   WHERE DOKAR = WA_URLDOCTYP
                                                 AND DOKNR = WA_URLDOCNO
                                                 AND DOKVR = WA_URLDOCVER
                                                 AND DOKTL = WA_URLDOCPT .

       STATUS = DRAWDOKST .
     ENDIF .
   ENDLOOP .
   IF STATUS = ‘ ‘ .
     “* TO EXECUTE THE DOCUMENT WHICH IS PRESENT IN THE PRESENTATION SERVER               *”
     CALL METHOD cl_gui_frontend_services=>execute
       EXPORTING
         document               = LINK
       EXCEPTIONS
         cntl_error             = 1
         error_no_gui           = 2
         bad_parameter          = 3
         file_not_found         = 4
         path_not_found         = 5
         file_extension_unknown = 6
         error_execute_failed   = 7
         synchronous_failed     = 8
         not_supported_by_gui   = 9
         others                 = 10.
     IF sysubrc <> 0.
     ENDIF.
   ELSE.
     “* TO EXCEUTE THE DOCUMENT PRESENT IN THE APPLICATION SERVER                         *”
     PERFORM file_display .
   ENDIF .

*&———————————————————————*
*&      Form  FILE_DISPLAY
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM FILE_DISPLAY .
   DATA: lf_exit1               TYPE REF TO if_ex_document_storage01,
         lf_exit2               TYPE REF TO if_ex_document_files01,
         ls_doc_file            LIKE dms_doc_file,
         ls_cout_def            LIKE dms_checkout_def,
         lf_appl_name           LIKE tdwxappfd,
         lf_func_type           LIKE tdwxapptp,
         lf_appl_type(2)        TYPE c,
         lf_error(1)            TYPE c,
         lf_check_file(1)       TYPE c,
         lf_use_url(1)          TYPE c,
         lf_use_last(1)         TYPE c,
         lf_file_type(2)        TYPE c,
         lf_ph_index            TYPE i,
         lf_lo_index            TYPE i,
         lf_suppress_dlg(1)     TYPE c,
         lf_use_control(1)      TYPE c,
         lf_no_checkout(1)      TYPE c,
         lf_dummy(1)            TYPE c,
         gs_draw                LIKE draw,
         ls_phio                LIKE dms_phio,
         ls_main_file           TYPE dms_rec_file,
         ls_phio_file           TYPE dms_rec_phio,
         ls_phio_x              TYPE dms_rec_phio,
         lt_components          TYPE dms_rec_comp OCCURS 0 WITH HEADER LINE,
         lt_draz                LIKE draz         OCCURS 0 WITH HEADER LINE,
         lf_act_imp_existing(1) TYPE c,
         tmp_node_key           TYPE tv_nodekey,
         gf_transaction         LIKE systtcode,
         pf_node_key            TYPE tv_nodekey,
         gs_frontend            LIKE dms_frontend_data,
         FILENAME(100) ,
         FILE(100) ,
         A1(50) ,
         A2(3) .

   SPLIT VAL AT ‘.’ INTO A1 A2 .
   TRANSLATE A2 TO UPPER CASE .
   ls_cout_defKPRO_USE = ‘X’ .
   ls_cout_defCOMP_GET = ‘X’ .
   gf_transaction = ‘CV03’ .

   LOOP AT IT_URL INTO WA_URL where url = val .
     SELECT SINGLE * FROM draw INTO gs_draw WHERE DOKAR = WA_URLDOCTYP
                                               AND DOKNR = WA_URLDOCNO
                                               AND DOKVR = WA_URLDOCVER
                                               AND DOKTL = WA_URLDOCPT .

     SELECT SINGLE * FROM DMS_DOC2LOIO WHERE DOKAR = WA_URLDOCTYP
                                               AND DOKNR = WA_URLDOCNO
                                               AND DOKVR = WA_URLDOCVER
                                               AND DOKTL = WA_URLDOCPT .

     SELECT SINGLE * from DMS_PH_CD1 WHERE LOIO_ID = DMS_DOC2LOIOLO_OBJID .
     FILE = WA_URLDOCNO .
   ENDLOOP.
   “* FILENAME –> TEMPORARY STORAGE FILE PATH IN THE PRESENTATION SYSTEM              *”
   “* FILE PATH IS C:\DOCUME~1\(USER ID)\LOCALS~1\Temp\(FILENAME.FILETYPE)             *”
   FILENAME = ‘C:\DOCUME~1\’ .
   CONCATENATE FILENAME SYUNAME INTO FILENAME.
   CONCATENATE FILENAME ‘\LOCALS~1\Temp\’ INTO FILENAME .
   CONCATENATE FILE A2 INTO FILE SEPARATED BY ‘.’ .
   CONCATENATE FILENAME FILE INTO FILENAME .
   LS_DOC_FILEFILENO = ‘1’.
   LS_DOC_FILELANGU  = ‘E’ .
   LS_DOC_FILEFILENAME = FILENAME .
   LS_DOC_FILEDAPPL   = A2 .

   LS_PHIOLO_INDEX           = DMS_DOC2LOIOLO_INDEX .
   LS_PHIOLO_OBJID           = DMS_DOC2LOIOLO_OBJID .
   LS_PHIOPH_OBJID           = DMS_PH_CD1PHIO_ID .
   LS_PHIOLANGU              = DMS_PH_CD1LANGU .
   LS_PHIOSTATUS             = DMS_PH_CD1PROP04 .
   LS_PHIOSTATUS_NR          = DMS_PH_CD1PROP05 .
   LS_PHIOFILENAME           = VAL .
   LS_PHIOACTIVE_VERSION     = DMS_PH_CD1PROP01 .
   LS_PHIODELETE_FLAG        = DMS_PH_CD1PROP02 .
   LS_PHIOPROTECTED          = DMS_PH_CD1PROP03 .
   LS_PHIODEFAULT_LANGU      = DMS_PH_CD1PROP06 .
   LS_PHIOFILE_ID            = DMS_PH_CD1PROP08 .
   LS_PHIOCREATE_AUDIT       = ‘X’.
   LS_PHIOCREATE_NEW_VERSION = ‘X’.
   LS_PHIOSTORAGE_CAT        = DMS_PH_CD1STOR_CAT .
   LS_PHIOCREATED_BY         = DMS_PH_CD1CREA_USER .
   LS_PHIOCREATED_AT         = DMS_PH_CD1CREA_TIME .
   LS_PHIOCHANGED_BY         = DMS_PH_CD1CHNG_USER .
   LS_PHIOCHANGED_AT         = DMS_PH_CD1CHNG_TIME .

   GS_FRONTENDFRONTEND_TYPE = ‘PC’ .
   GS_FRONTENDHOSTNAME = ‘DEFAULT’ .
   GS_FRONTENDWINSYS   = ‘WN32’ .

   “* CREATES THE FILE IN THE TEMPORARY LOCATION                                        *”
   CALL FUNCTION ‘CV120_DOC_CHECKOUT_VIEW’
        EXPORTING: ps_cout_def   = ls_cout_def
                   pf_tcode      = gf_transaction
                   ps_doc_file   = ls_doc_file
                   ps_draw       = gs_draw
                   ps_phio       = ls_phio
                   ps_frontend   = gs_frontend
       IMPORTINGpfx_file      = ls_doc_filefilename
                   pfx_url       = ls_doc_fileurl
                   pfx_use_last  = lf_use_last
       TABLES:     pt_components = lt_components
       EXCEPTIONS: error         = 1
                   OTHERS        = 2.
   lf_func_type = 1 .
   lf_check_file = ‘X’.

   “* EXECUTES THE FILE FROM THE TEMPORORY LOCATION                                     *”
   CALL FUNCTION ‘CV120_START_APPLICATION’
            EXPORTING: pf_dappl       = ls_doc_filedappl
                       ps_frontend    = gs_frontend
                       pf_apptp       = lf_func_type
                       pf_file        = ls_doc_filefilename
                       pf_check_file  = lf_check_file
                       ps_draw        = gs_draw
                       pf_url         = ls_doc_fileurl
                       pf_appnr       = ls_doc_filefileno“Note 1454086
           TABLES:     pt_draz        = lt_draz
                       pt_components  = lt_components
           EXCEPTIONS: error          = 1
                       file_not_found = 2.

ENDFORM.                    ” FILE_DISPLAY

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.