Skip to Content

Sometimes,there is a unique requirement in the project – we have a report which will call an another report in background.The first report shall transport the data to the called report and after computation ,the second report shall throw back the results to the first report.This can be easily achieved by using ABAP memory and Submit statement.Let us check,how :

The first report shall pass the data to ABAP Memory using Export statement and then call the second report using SUBMIT statement:

   DATA: lv_number           TYPE tbtcjob-jobcount,
       lv_name                    TYPE tbtcjob-jobname VALUE ‘JOB_TEST’,
       lt_print_parameters    TYPE pri_params ,
       lv_valid_flag(1)           TYPE c.

  DATA : lit_joblist  TYPE TABLE OF tbtcstep,
             wa_joblist TYPE tbtcstep.

  CALL FUNCTION ‘JOB_OPEN’
    EXPORTING
      jobname          = lv_name
    IMPORTING
      jobcount         = lv_number
    EXCEPTIONS
      cant_create_job  = 1
      invalid_job_data = 2
      jobname_missing  = 3
      OTHERS           = 4.
  IF sy-subrc = 0 .

    CALL FUNCTION ‘GET_PRINT_PARAMETERS’
      EXPORTING
        mode                 = ‘BATCH’
        no_dialog            = ‘X’
        destination          = ‘LOCL’
        new_list_id          = ‘X’
      IMPORTING
        out_parameters       = lt_print_parameters
        valid                = lv_valid_flag
      EXCEPTIONS
        invalid_print_params = 2
        OTHERS               = 4.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    PERFORM export_to_memory.

    SUBMIT zqma_archive_create
    TO SAP-SPOOL
    VIA JOB lv_name NUMBER lv_number
    WITHOUT SPOOL DYNPRO
    SPOOL PARAMETERS lt_print_parameters
    AND RETURN.

    IF sy-subrc = 0.

      CALL FUNCTION ‘JOB_CLOSE’
        EXPORTING
          jobcount             = lv_number
          jobname              = lv_name
          strtimmed            = ‘X’
        EXCEPTIONS
          cant_start_immediate = 1
          invalid_startdate    = 2
          jobname_missing      = 3
          job_close_failed     = 4
          job_nosteps          = 5
          job_notex            = 6
          lock_failed          = 7
          OTHERS               = 8.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

      ENDIF.
    ENDIF.
  ENDIF.

===================================================================================================================

   FORM export_to_memory .

  EXPORT gt1_certificate_data[]
         vbak-vbeln
         vbap-posnr
         objk-sernr
         gv_charg
         t001w-werks
         zqma_cert_adm_11-brand
         sy-repid
         g_cpack
         gv_flg
         afpo-aufnr
         gs_crane-sernr
         mara-matnr
         gs_crane-vbeln
         gs_crane-matnr
         gs_crane-ppaufnr TO MEMORY ID ‘ZQMA_ARCHIVE’.

ENDFORM.                    ” EXPORT_TO_MEMORY

====================================================================================================================

  REPORT  zqma_archive_create.

INITIALIZATION.

* Types decleration
  TYPES: BEGIN OF ty_certificate_data,
         checkbox     TYPE char1,         ” for selection.
         certpack     TYPE zqma_certpack, ” Certificate Package
         certtype     TYPE zqma_certtype, ” Certificate Type
         certdesc     TYPE zqma_certdesc, ” Certificate Description
         matnr        TYPE mara-matnr,    ” Material number
         maktx        TYPE makt-maktx,    ” Material description
         sernr        TYPE gernr,         ” serial number
         langkey      TYPE spras,         ” Language Key
         quantity     TYPE i,             ” no. of copies to be printed.
         langdone     TYPE char1,
         END OF ty_certificate_data.

* Internal Tables decleration
  DATA: gt_cert_data_memory          TYPE STANDARD TABLE OF ty_certificate_data,
        gt1_certificate_data         TYPE STANDARD TABLE OF ty_certificate_data,
        lt_zqma_cert_adm_06          TYPE STANDARD TABLE OF zqma_cert_adm_06,
        ls_zqma_cert_adm_06          TYPE zqma_cert_adm_06,
        lt_tfdir                     TYPE STANDARD TABLE OF tfdir.

*Local Data
  DATA:  lv_okay                     TYPE         char1,
         l_report                    LIKE         sy-repid,
         wa_cert_data_memory         LIKE LINE OF gt_cert_data_memory,
         lv_count                    TYPE         i,
         lv_langkey                  TYPE         zqma_cert_adm_14-lang,
         lt_cert_data_memory_temp    LIKE         gt_cert_data_memory,
         lv_message                  TYPE         string,
         gv_total                    TYPE         i,
         gv_curr                     TYPE         i.

*Local Data
  DATA: l_vbeln                      TYPE        vbak-vbeln,
        l_posnr                      TYPE        vbap-posnr,
        l_sernr                      TYPE        gernr,
        l_charg                      TYPE        charg_d,
        l_werks                      TYPE        t001w-werks,
        l_brand                      TYPE        zqma_cert_adm_11-brand,
        l_repid                      TYPE        sy-repid,
        l_aufnr                      TYPE        afpo-aufnr,
        l_crane_sernr                TYPE        gernr,
        l_matnr                      TYPE        mara-matnr,
        l_crane_vbeln                TYPE        vbeln_va,
        l_crane_matnr                TYPE        matnr,
        l_crane-ppaufnr              TYPE        afpo-aufnr.

  DATA: l_cpack                      TYPE        zqma_certpack,
        l_flg                        TYPE        c.

*Constants
  CONSTANTS:
     lc_x                            TYPE c      VALUE  ‘X’,
     lc_a                            TYPE c      VALUE  ‘A’.

* Importing required Data
IMPORT
       gt1_certificate_data[]
       vbak-vbeln             = l_vbeln
       vbap-posnr             = l_posnr
       objk-sernr             = l_sernr
       gv_charg               = l_charg
       t001w-werks            = l_werks
       zqma_cert_adm_11-brand = l_brand
       sy-repid               = l_repid
       g_cpack                = l_cpack
       gv_flg                 = l_flg
       afpo-aufnr             = l_aufnr
       gs_crane-sernr         = l_crane_sernr
       mara-matnr             = l_matnr
       gs_crane-vbeln         = l_crane_vbeln
       gs_crane-matnr         = l_crane_matnr
       gs_crane-ppaufnr       = l_crane-ppaufnr

       from memory id ‘ZQMA_ARCHIVE’.

  IF gt1_certificate_data[] IS NOT INITIAL.

* may be no lines are selected.
    CLEAR: lv_okay.
    LOOP AT gt1_certificate_data TRANSPORTING NO FIELDS WHERE checkbox = lc_x.
      lv_okay = lc_x.
    ENDLOOP.

    IF lv_okay <> lc_x.
    ELSE.
      CLEAR: gt_cert_data_memory.
      gt_cert_data_memory[] = gt1_certificate_data[].
      DELETE gt_cert_data_memory WHERE checkbox NElc_x.

* filter certificate records as per users wish considering language
* records maintained.
      CLEAR lt_cert_data_memory_temp[].

      LOOP AT gt_cert_data_memory INTO wa_cert_data_memory.

        CALL FUNCTION ‘CONVERSION_EXIT_ISOLA_OUTPUT’
          EXPORTING
            input  = wa_cert_data_memory-langkey
          IMPORTING
            output = lv_langkey.

        SELECT SINGLE COUNT( * ) INTO lv_count
          FROM zqma_cert_adm_14
          WHERE certtype = wa_cert_data_memory-certtype
            AND lang = lv_langkey.                          “#EC WARNOK

        IF sy-subrc = 0.
          APPEND wa_cert_data_memory TO lt_cert_data_memory_temp.
          CONTINUE.
        ELSE.
          APPEND wa_cert_data_memory TO lt_cert_data_memory_temp.
        ENDIF.
      ENDLOOP.

      CLEAR: wa_cert_data_memory,
             gt_cert_data_memory[].

      gt_cert_data_memory[] = lt_cert_data_memory_temp[].

      EXPORT gt_certificate_data
      FROM gt_cert_data_memory TO MEMORY ID ‘CERTDATA’.

      DESCRIBE TABLE gt_cert_data_memory LINES gv_total.
      CLEAR:  gv_curr.

      EXPORT gv_total TO MEMORY ID  ‘TOTAL’.
      EXPORT gv_curr  TO MEMORY ID  ‘CURR’.

      IF gt_cert_data_memory IS NOT INITIAL.
        SELECT
           certtype
           certtypeprg FROM zqma_cert_adm_06
          INTO CORRESPONDING FIELDS OF TABLE  lt_zqma_cert_adm_06
          FOR ALL ENTRIES IN gt_cert_data_memory
          WHERE certtype = gt_cert_data_memory-certtype
          AND  werks = l_werks.
        IF sy-subrc = 0.

          SORT lt_zqma_cert_adm_06 BY
          certtype
          werks.

          SELECT * FROM tfdir INTO TABLE lt_tfdir
          FOR ALL ENTRIES IN lt_zqma_cert_adm_06
          WHERE  funcname = lt_zqma_cert_adm_06-certtypeprg. “#EC CI_GENBUFF

          IF sy-subrc = 0.
            SORT lt_tfdir BY funcname.
          ENDIF.
        ENDIF.
      ENDIF.

      LOOP AT gt_cert_data_memory INTO wa_cert_data_memory.

        READ TABLE lt_zqma_cert_adm_06
        WITH KEY certtype = wa_cert_data_memory-certtype
        INTO ls_zqma_cert_adm_06
        BINARY SEARCH.

        IF sy-subrc EQ 0.
          l_report = ls_zqma_cert_adm_06-certtypeprg.
        ELSE.
          MESSAGE text-009 TYPE ‘E’ DISPLAY LIKE ‘I’.
        ENDIF.

*check FM maintained exists in the system.
*
        READ TABLE lt_tfdir
        WITH KEY funcname = l_report TRANSPORTING NO FIELDS BINARY SEARCH.
        IF sy-subrc <> 0.
          CONCATENATE text-010 l_report text-011
            INTO lv_message SEPARATED BY space.
          MESSAGE lv_message TYPE ‘E’ DISPLAY LIKE ‘I’.
        ENDIF.

        IMPORT gv_curr_1 TO gv_curr FROM MEMORY ID ‘CURR’.
        gv_curr = gv_curr + 1.
        EXPORT gv_curr TO MEMORY ID ‘CURR’.

        l_charg = wa_cert_data_memory-sernr.
        l_flg = lc_a.

* calling the driver programs for certificates
        CALL FUNCTION l_report
          EXPORTING
            pp_vbeln           = l_vbeln
            pp_posnr           = l_posnr
            pp_sernr           = l_sernr
            pp_charg           = l_charg
            pp_werks           = l_werks
            pp_matnr           = wa_cert_data_memory-matnr
            pp_brand           = l_brand
            pp_langu           = wa_cert_data_memory-langkey
            pp_callpr          = l_repid
            pp_certty          = wa_cert_data_memory-certtype
            pp_quanty          = wa_cert_data_memory-quantity
            pp_flag            = l_flg
            pp_certpack        = l_cpack
            pp_aufnr           = l_aufnr
            pp_gernr           = wa_cert_data_memory-sernr
            pp_crane_sernr     = l_crane_sernr
            pp_mara_matnr      = l_matnr
            pp_crane_vbeln     = l_crane_vbeln
            pp_crane_matnr     = l_crane_matnr
            pp_syrepid         = l_repid
            pp_assembled_order = l_crane-ppaufnr.

      ENDLOOP.

      FREE MEMORY ID : ‘TOTAL’, ‘CURR’, ‘TABLE’, ‘CERTIFICATE_DATA’.

    ENDIF.
  ENDIF.

****Do not forget to place all the code in the called report after the initialization event.

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