Tuesday, 11 April 2017

INBOUND ABAP TYPE- INTF (interface) and service provider -part2



  METHOD zii_si_biometric_ib_async~si_biometric_ib_async.
*** **** INSERT IMPLEMENTATION HERE **** ***
    DATA lv_file    TYPE rptaxxxx-rfile,
           lv_time    TYPE t,
           lv_mess    TYPE string,
           lv_num     TYPE qfranint,
           lv_string  TYPE string,
           lv_string1 TYPE string,
           lv_lock    TYPE c,
           lv_target  TYPE btcsrvname.

    TYPES BEGIN OF gty_final,
              string(85TYPE c,
            END OF gty_final,

            BEGIN OF gty_input,
              pernr TYPE pernr_d,
              satza TYPE retyp,
              ldate TYPE ldate,
              ltime TYPE ltime,
              erdat TYPE phdat,
              ertim TYPE phtim,
              zausw TYPE dzausw,
            END OF gty_input,

            BEGIN OF ty_even,
              pernr TYPE persno,
              ldate TYPE ldate,
              satza TYPE retyp,
            END OF ty_even.

    DATA gs_final  TYPE gty_final,
           gs_input  TYPE gty_input,
           gs_even   TYPE ty_even,
           gt_even   TYPE STANDARD TABLE OF ty_even,
           gt_input  TYPE STANDARD TABLE OF gty_input,
           gt_final  TYPE STANDARD TABLE OF gty_final,
           it_header TYPE zdt_biometric_recordset_tab,
           ls_tvarvc TYPE tvarvc,
           wa_header LIKE LINE OF it_header,
           gs_record LIKE LINE OF wa_header-header.

    DATA lv_sec       TYPE i,
           lv_leng      TYPE i,
           lv_jobnumber TYPE tbtcjob-jobcount,
           lv_jobname   TYPE tbtcjob-jobname,
           lv_msg       TYPE string,
           lv_finish,
           lv_stop,
           l_valid,
           ls_params    TYPE pri_params.

    CLEAR it_header.
    MOVE input-mt_biometric-recordset TO it_header.

    CLEAR :gt_finallv_string1.
    LOOP AT it_header INTO wa_header.
      LOOP AT wa_header-header INTO gs_record.
        gs_final-string gs_record-satza.
        gs_final-string+3(4)  space.
        gs_final-string+7(8)  gs_record-ldate.
        lv_leng strlengs_record-ltime ).
        DO TIMES.
          IF lv_leng >= 6.
            EXIT.
          ELSE.
            CONCATENATE '0' gs_record-ltime INTO gs_record-ltime.
            lv_leng lv_leng + 1.
          ENDIF.
        ENDDO.
        gs_final-string+15(6lv_time gs_record-ltime.
        gs_final-string+21(8gs_record-erdat.
        gs_final-string+29(6gs_record-ertim.
        gs_final-string+35(8gs_record-zausw.
        gs_final-string+43(8gs_record-pernr.
        APPEND gs_final TO gt_final.
        CLEAR gs_final.
      ENDLOOP.
      AT LAST.
        CONCATENATE gs_record-ldate gs_record-ltime INTO lv_string1.
      ENDAT.
    ENDLOOP.

    IF gt_final IS NOT INITIAL.
      SELECT SINGLE FROM tvarvc INTO ls_tvarvc
             WHERE name 'ZHR_BIOMETRIC'.
      CLEAR lv_lock.
      WHILE lv_lock IS INITIAL.
        CALL FUNCTION 'ENQUEUE_EZ_BIO'
          EXCEPTIONS
            foreign_lock   1
            system_failure 2
            OTHERS         3.
        IF sy-subrc 0.
          lv_lock 'X'.
          TRY.
              lv_file '/usr/sap/tmp'.
              CONCATENATE lv_file '/biomatric1.txt' INTO lv_file" Can see in AL11
              OPEN DATASET lv_file FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
              LOOP AT gt_final INTO gs_final.
                TRANSFER gs_final-string TO lv_file.
              ENDLOOP.
              CLOSE DATASET lv_file.

              CALL FUNCTION 'QF05_RANDOM_INTEGER'
                EXPORTING
                  ran_int_max   1000
                  ran_int_min   1
                IMPORTING
                  ran_int       lv_num
                EXCEPTIONS
                  invalid_input 1
                  OTHERS        2.
              IF sy-subrc <> 0.
                lv_num '99'.
              ENDIF.

              CLEAR lv_filelv_string.
              lv_file '/usr/sap/tmp'.
              lv_string lv_num.
              CONCATENATE lv_file '/bio_' lv_string '_' lv_string1 '_'
                          sy-datum sy-uzeit '.txt' INTO lv_file.
              CONDENSE lv_file NO-GAPS.
*              OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE MESSAGE lv_mess.
*              IF sy-subrc NE 0.
*                MESSAGE lv_mess TYPE 'E'.
*              ENDIF.
*              LOOP AT gt_final INTO gs_final.
*                TRANSFER gs_final-string TO lv_file.
*              ENDLOOP.
*              CLOSE DATASET lv_file.
*              IF sy-subrc NE 0.
*                MESSAGE 'File not closed' TYPE 'E'.
*              ENDIF.
*              COMMIT WORK AND WAIT.
*              lv_sec = ls_tvarvc-low.
*              WAIT UP TO lv_sec SECONDS. " For upload the data into OS
              IF sy-sysid 'CPH'.
                lv_target 'AWSERPSLES040_CPH_01'.
              ELSE.
                lv_target space.
              ENDIF.

              CALL FUNCTION 'GET_PRINT_PARAMETERS'
                EXPORTING
                  no_dialog      'X'
                IMPORTING
                  valid          l_valid
                  out_parameters ls_params.
              lv_jobname  'BIOMETRIC'.
              CALL FUNCTION 'JOB_OPEN'
                EXPORTING
                  jobname          lv_jobname
                IMPORTING
                  jobcount         lv_jobnumber
                EXCEPTIONS
                  cant_create_job  1
                  invalid_job_data 2
                  jobname_missing  3
                  OTHERS           4.

              EXPORT gt_final gt_final TO DATABASE indx(stID 'FINAL'.
              EXPORT lv_file lv_file TO DATABASE indx(stID 'FILE'.

              SUBMIT zhr_biometric_dummy
                              VIA JOB lv_jobname
                              NUMBER lv_jobnumber
                              USER sy-uname
                              TO SAP-SPOOL WITHOUT SPOOL DYNPRO
                              SPOOL PARAMETERS ls_params
                              AND RETURN.

*              SUBMIT rpteup10 WITH upload   = 'X'
*                              WITH post     = 'X'
*                              WITH dataset  = 'X'
*                              WITH workstn  = space
*                              WITH file     = lv_file
*                              VIA JOB lv_jobname
*                              NUMBER lv_jobnumber
*                              USER sy-uname
*                              TO SAP-SPOOL WITHOUT SPOOL DYNPRO
*                              SPOOL PARAMETERS ls_params
*                              AND RETURN.

              CALL FUNCTION 'JOB_CLOSE'
                EXPORTING
                  jobcount     lv_jobnumber
                  jobname      lv_jobname
                  strtimmed    'X'
                  targetserver lv_target
                EXCEPTIONS
                  OTHERS       0.
              COMMIT WORK AND WAIT.

              CLEAR lv_finish.
              WHILE lv_finish IS INITIAL.
                CALL FUNCTION 'SHOW_JOBSTATE'
                  EXPORTING
                    jobcount         lv_jobnumber
                    jobname          lv_jobname
                  IMPORTING
                    aborted          lv_stop
                    finished         lv_finish
                    other            lv_stop
                  EXCEPTIONS
                    jobcount_missing 1
                    jobname_missing  2
                    job_notex        3
                    OTHERS           4.
                IF sy-subrc NE 0.
                  lv_stop 'X'.
                ENDIF.
                IF lv_stop IS NOT INITIAL.
                  EXIT.
                ENDIF.
                WAIT UP TO SECONDS.
              ENDWHILE.
              IF lv_finish IS NOT INITIAL.
                DELETE  DATASET lv_file.
              ENDIF.
            CATCH cx_sy_file_open.
              MESSAGE 'File is already open in another program. Parallel process not possible' TYPE 'E'.
            CATCH cx_sy_file_close.
              MESSAGE 'The File could not be closed. Insufficient memory space is a possible' TYPE 'E'.
          ENDTRY.
        ENDIF.
      ENDWHILE.
    ENDIF.

    CALL FUNCTION 'DEQUEUE_EZ_BIO'.

  ENDMETHOD.












Since you want to upload from the application server, please make sure that your csv file is present in the right destination in the server by using t-code Al11. 
Also to read from the application server use '/' and not '\'. 
Also if you are using cg3z to upload the file to application server then please ensure that its in ACII format and not in binary format.


REPORT zhr_biometric_dummy.

TYPES BEGIN OF gty_final,
          string(85TYPE c,
        END OF gty_final.

DATAlv_file  TYPE rptaxxxx-rfile,
      lv_mess  TYPE string,
      gs_final TYPE gty_final,
      ls_list  TYPE abaplist,
      lt_list  LIKE abaplist OCCURS WITH HEADER LINE,
      gt_final TYPE STANDARD TABLE OF gty_final.

IMPORT gt_final gt_final FROM DATABASE indx(stID 'FINAL'.
IMPORT lv_file lv_file FROM DATABASE indx(stID 'FILE'.

DELETE FROM DATABASE indx(stID 'FINAL'.
DELETE FROM DATABASE indx(stID 'FILE'.

IF lv_file IS NOT INITIAL
  AND gt_final IS NOT INITIAL.
  OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE MESSAGE lv_mess.
  IF sy-subrc NE 0.
    MESSAGE lv_mess TYPE 'E'.
  ENDIF.
  LOOP AT gt_final INTO gs_final.
    TRANSFER gs_final-string TO lv_file.
  ENDLOOP.
  CLOSE DATASET lv_file.
  IF sy-subrc NE 0.
    MESSAGE 'File not closed' TYPE 'E'.
  ENDIF.
  WAIT UP TO 60 SECONDS" For upload the data into OS
  SUBMIT rpteup10 WITH upload   'X'
                              WITH post     'X'
                              WITH dataset  'X'
                              WITH workstn  space
                              WITH file     lv_file
                              EXPORTING LIST TO MEMORY
                              AND RETURN.
  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      listobject lt_list
    EXCEPTIONS
      not_found  1
      OTHERS     2.
  IF sy-subrc 0.
    CALL FUNCTION 'WRITE_LIST'
      TABLES
        listobject lt_list
      EXCEPTIONS
        empty_list 1
        OTHERS     2.
  ELSE.
    WRITE 'Log not found'.
  ENDIF.

ELSE.
  MESSAGE 'Data is not there' TYPE 'E'.
ENDIF.

COMMIT WORK AND WAIT.


No comments:

Post a Comment