Skip to end of metadata
Go to start of metadata
*----------------------------------------------------------------------*
* Program Title : E-signature on ER Invoices                           |
* Description of Program: This program will convert spools to PDF      |
*                         formats for all the invoices (ZD00) created  |
*                         in specific period.                          |
*----------------------------------------------------------------------*
*                               : To save the .pdf in diff directories
*                                 depending upon the server it is executed
*          If executed in DR1 it will save in
*                                             /DR1/interfaces/Elemica |
*                                          FR1 it will save in
*                                             /FR1/interfaces/Elemica |
*                                          PR1 it will save in
*                                             /PR1/interfaces/Elemica |
*
*                           : To validate against the specific partnert ID to send .pdf|
** DATA DECLARATION*
*&-----------------------------------&*
*& Table Declaration                *
*&--------------------------------------&
TABLES : tsp01 , nast , vbrk, ztval1.
*-------------------------*
* Ranges                   *
*--------------------------*
RANGES: r_kschl FOR tnati-kschl.
*&--------------------------------&*
*&    Internal Tables             *
*----------------------------------*
DATA : BEGIN OF t_tsp01 OCCURS 0.
        INCLUDE STRUCTURE tsp01.
DATA : END OF t_tsp01.
DATA : BEGIN OF t_buffer OCCURS 0.
        INCLUDE STRUCTURE soli.
DATA : END OF t_buffer.
DATA : BEGIN OF t_tnati OCCURS 0.
        INCLUDE STRUCTURE tnati.
DATA : END OF t_tnati.
DATA : BEGIN OF t_errorlog OCCURS 0,
        spool LIKE tsp01-rqident,
        desc(100) TYPE c,
       END OF t_errorlog.
DATA : BEGIN OF t_success OCCURS 0,
        spool LIKE tsp01-rqident,
        vbeln LIKE vbrk-vbeln,
       END OF t_success.
*&---------------------------------------*
*&     Varaible Declaration              *
*&----------------------------------------*
DATA : w_fkschl TYPE c.
DATA : w_char(14) TYPE c VALUE 'Invoice Number'.
DATA : w_tabix LIKE sy-tabix.
DATA: mtab_pdf LIKE tline OCCURS 0 WITH HEADER LINE,
      mc_filename TYPE string.
DATA: mstr_print_parms LIKE pri_params,
      mc_valid(1) TYPE c,
      mi_bytecount TYPE i.
*&----------------------------------*
*&         SELECTION SCREEN         *
*&-----------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1.
SELECTION-SCREEN END OF BLOCK b1.
*&------------------------------------*
*&          START OF SELECTION        *
*&------------------------------------*
START-OF-SELECTION.
* Select the spool number for the latest print by the user.
  DATA : w_date LIKE tsp01-rqcretime.
  PERFORM get_spools.
  PERFORM print_errors.
*&---------------------------------------------------------------------*
*&      Form  test
*&---------------------------------------------------------------------*
FORM get_spools.
  CONCATENATE sy-datum '00000000' INTO w_date.
* Select Output types for billing application
  SELECT * FROM tnati INTO TABLE t_tnati
                      WHERE spras EQ 'EN'
                      AND   kappl EQ 'V3'.
* Select spools
  SELECT * FROM tsp01 INTO TABLE t_tsp01
                      WHERE rqclient EQ sy-mandt
                      AND   rq0name EQ 'SMART'
*                      AND   rqowner EQ sy-uname
                      AND   rqarchtype EQ '1'
                      AND   rqcretime GE w_date.
  IF sy-subrc NE 0 .
    CONCATENATE text-004 ' TIME : ' sy-uzeit ' & DATE :'
                      sy-datum INTO t_errorlog-desc.
    APPEND t_errorlog.
    CLEAR t_errorlog.
  ENDIF.
  SORT t_tsp01 BY rqcretime DESCENDING.
* Fill range.
*  r_kschl-sign = 'I'.
*  r_kschl-option = 'EQ'.
*  r_kschl-low = 'ZD00'.
*  APPEND r_kschl.
*  CLEAR r_kschl.
* This program will validate if the output type is ZDOP
  r_kschl-sign = 'I'.
  r_kschl-option = 'EQ'.
  r_kschl-low = 'ZD0P'.
  APPEND r_kschl.
  CLEAR r_kschl.
  LOOP AT t_tsp01.
    REFRESH mtab_pdf.
** Check For Billing Output types.
*    CLEAR w_fkschl.
*    LOOP AT t_tnati WHERE objdes EQ t_tsp01-rqtitle.
*      IF t_tnati-kschl IN r_kschl.
*        w_fkschl = 'X'.
*      ENDIF.
*    ENDLOOP.
*    CHECK w_fkschl EQ 'X'.
    CONCATENATE 'C:\' 'P_PDFILE' '.PDF' INTO mc_filename.
    CALL FUNCTION 'GET_PRINT_PARAMETERS'
      EXPORTING
        copies                 = '1'
        cover_page             = space
        destination            = space
        expiration             = '1'
        immediately            = space
        layout                 = space
        mode                   = space
        new_list_id            = 'X'
        no_dialog              = 'X'
        user                   = sy-uname
      IMPORTING
        out_parameters         = mstr_print_parms
        valid                  = mc_valid
      EXCEPTIONS
        archive_info_not_found = 1
        invalid_print_params   = 2
        invalid_archive_params = 3
        OTHERS                 = 4.
    IF sy-subrc EQ 0.
      CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid              = t_tsp01-rqident
          no_dialog                = space
          dst_device               = mstr_print_parms-pdest
        IMPORTING
          pdf_bytecount            = mi_bytecount
        TABLES
          pdf                      = mtab_pdf
        EXCEPTIONS
          err_no_otf_spooljob      = 1
          err_no_spooljob          = 2
          err_no_permission        = 3
          err_conv_not_possible    = 4
          err_bad_dstdevice        = 5
          user_cancelled           = 6
          err_spoolerror           = 7
          err_temseerror           = 8
          err_btcjob_open_failed   = 9
          err_btcjob_submit_failed = 10
          err_btcjob_close_failed  = 11
          OTHERS                   = 12.
      IF sy-subrc <> 0.
        t_errorlog-spool = t_tsp01-rqident.
        t_errorlog-desc = text-001.
        APPEND t_errorlog.
        CLEAR t_errorlog.
        CONTINUE.
      ELSE.
        CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
          EXPORTING
            rqident = t_tsp01-rqident
          TABLES
            buffer  = t_buffer.
        IF sy-subrc <> 0.
          t_errorlog-spool = t_tsp01-rqident.
          t_errorlog-desc = text-003.
          APPEND t_errorlog.
          CLEAR t_errorlog.
          CONTINUE.
        ENDIF.
        SEARCH t_buffer FOR w_char.
        w_tabix = sy-tabix.
        w_tabix = w_tabix + 2.
        READ TABLE t_buffer INDEX w_tabix. "To read the Billing Doc No.
*        READ TABLE t_buffer INDEX 204.
        DATA : w_invno LIKE vbrk-vbeln.
        w_invno = t_buffer-line+9.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            input  = w_invno
          IMPORTING
            output = w_invno.
        SELECT SINGLE * FROM vbrk WHERE vbeln EQ w_invno.
        IF sy-subrc NE 0.
*          t_errorlog-spool = t_tsp01-rqident.
*          t_errorlog-desc = text-002.
*          APPEND t_errorlog.
*          CLEAR t_errorlog.
*          CONTINUE.
        ELSE.
          DATA : file LIKE authb-filename.
          DATA : w_time(50) TYPE c.
          CONCATENATE sy-datum sy-uzeit INTO w_time.
          CONDENSE w_time.
*&----------------------------------------------------------------&
*& To select the Patrner Id to send .pdf file                     &
*& To validate the valid Partner ID in the NAST against the        &
*& Invoice number.
*&----------------------------------------------------------------&
          DATA : w_datum TYPE sy-datum.
          MOVE sy-datum TO w_datum.
          DATA : BEGIN OF t_vbrk OCCURS 0,
                  vbeln LIKE vbrk-vbeln,
                  kunag LIKE vbrk-kunag,
                 END OF t_vbrk.
          DATA : BEGIN OF t_nast OCCURS 0,
                  kschl LIKE nast-kschl,
                  parnr LIKE nast-parnr,
                 END OF t_nast.
          SELECT vbeln kunag FROM vbrk
                      INTO TABLE t_vbrk
                      WHERE vbeln EQ w_invno.
          DATA : w_parnr LIKE nast-parnr.
          LOOP AT t_vbrk.
            SELECT SINGLE parnr FROM nast
                      INTO CORRESPONDING FIELDS OF t_nast
                       WHERE kschl EQ 'ZD0P'
                         AND  parnr EQ t_vbrk-kunag.
            MOVE t_nast-parnr TO w_parnr.
*&----------------------------------------------------------------&
*& To save the pdf file in a specified directory.
*&----------------------------------------------------------------&
            DATA : w_sysid TYPE sysid.
            MOVE sy-sysid TO w_sysid.
            CONCATENATE  '/' w_sysid '/interfaces' '/' 'Elemica' '/'
                    w_parnr '' w_invno '' w_time '.pdf' INTO file.
            CLEAR w_parnr.
            CLEAR w_invno.
*&-----------------------------------------------------------------&
            REFRESH t_buffer.
            OPEN DATASET file  FOR OUTPUT IN BINARY MODE.
            IF sy-subrc NE 0.
              t_errorlog-spool = t_tsp01-rqident.
              t_errorlog-desc = text-002.
              APPEND t_errorlog.
              CLEAR t_errorlog.
              CONTINUE.
            ELSE.
              LOOP AT mtab_pdf.
                TRANSFER mtab_pdf TO file.
              ENDLOOP.
              t_success-spool = t_tsp01-rqident.
              t_success-vbeln = vbrk-vbeln.
              APPEND t_success.
              CLEAR t_success.
              CLOSE DATASET file.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " test
*&---------------------------------------------------------------------*
*&      Form  print_errors
*&---------------------------------------------------------------------*
FORM print_errors.
  CALL FUNCTION 'Z_ZS01_REPORT_HEADER'
    EXPORTING
      ip_confidential = ''
      ip_pagewidth    = 100
      ip_title        = text-005.
  IF NOT t_errorlog[] IS INITIAL.
    WRITE : / text-006.
    WRITE : / text-008 , 30 text-010.
  ENDIF.
  LOOP AT t_errorlog.
    WRITE : / t_errorlog-spool , 30 t_errorlog-desc.
  ENDLOOP.
  IF NOT t_success[] IS INITIAL.
    WRITE : / text-007.
    WRITE : / text-008 , 30 text-009.
  ENDIF.
  LOOP AT t_success.
    WRITE : / t_success-spool , 30 t_success-vbeln.
  ENDLOOP.
ENDFORM.                    " print_errors
 
  • No labels