..3 Программа печати

Создайте отчет Z_SUBTOTALS_2 и скопируйте в него этот код:


REPORT z_subtotals_2 .

* declare the context
DATA gt_context  TYPE zcontext_subtotals_2 .

* fill the context
PERFORM fill_context .

* call the form
CALL FUNCTION 'ZXLWB_CALLFORM'
  EXPORTING
    iv_formname        = 'SUBTOTALS_2'
    iv_context_ref     = gt_context
  EXCEPTIONS
    process_terminated = 1
    OTHERS             = 2.
IF sy-subrc NE 0 .
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
ENDIF .

*&---------------------------------------------------------------------*
*&      Form  fill_context
*&---------------------------------------------------------------------*

FORM fill_context .
  TYPES:
    BEGIN OF ty_s_rowset ,
      cityfrom          TYPE spfli-cityfrom ,
      landxfrom         TYPE t005t-landx ,
      cityto            TYPE spfli-cityto ,
      landxto           TYPE t005t-landx ,

      carrname          TYPE scarr-carrname ,
      connid            TYPE spfli-connid ,
      fldate            TYPE sflight-fldate ,
      price             TYPE sflight-price ,
      currency          TYPE sflight-currency ,
      seatsmax          TYPE sflight-seatsmax ,
      seatsocc          TYPE sflight-seatsocc ,
    END   OF ty_s_rowset ,
    ty_t_rowset         TYPE STANDARD TABLE OF ty_s_rowset .

  DATA:
    lt_rowset           TYPE ty_t_rowset ,
    lv_total_seatsmax   TYPE i ,
    lv_num              TYPE char10 .
  FIELD-SYMBOLS:
    <rowset>            TYPE ty_s_rowset ,
    <level_1>           TYPE zcontext_subtotals_2_lvl_1_row ,
    <level_2>           TYPE zcontext_subtotals_2_lvl_2_row .

  SELECT pf~cityfrom
         cf~landx       AS landxfrom
         pf~cityto
         ct~landx       AS landxto

         cr~carrname
         pf~connid
         fl~fldate
         fl~price
         fl~currency
         fl~seatsmax
         fl~seatsocc
    INTO CORRESPONDING FIELDS OF TABLE lt_rowset
    FROM spfli          AS pf
   INNER JOIN sflight   AS fl
      ON pf~carrid      EQ fl~carrid
     AND pf~connid      EQ fl~connid
   INNER JOIN scarr     AS cr
      ON pf~carrid      EQ cr~carrid
   INNER JOIN t005t     AS cf
      ON pf~countryfr   EQ cf~land1
     AND cf~spras       EQ sy-langu
   INNER JOIN t005t     AS ct
      ON pf~countryto   EQ ct~land1
     AND ct~spras       EQ sy-langu
   ORDER
      BY cf~landx
         pf~cityfrom
         ct~landx
         pf~cityto
         cr~carrname
         pf~connid
         fl~fldate .
 
  LOOP AT lt_rowset ASSIGNING <rowset> .
    AT NEW landxto .
      APPEND INITIAL LINE TO gt_context ASSIGNING <level_1> .
 
      CLEAR lv_total_seatsmax .
      CLEAR lv_num .
 
      CONCATENATE 'From:~' <rowset>-cityfrom '~(' <rowset>-landxfrom ')~'
                  'To:~'   <rowset>-cityto   '~(' <rowset>-landxto   ')~'
             INTO <level_1>-from_to .
      TRANSLATE <level_1>-from_to USING '~ ' .
    ENDAT .
 
    ADD <rowset>-seatsmax TO lv_total_seatsmax .
    ADD 1                 TO lv_num .
 
    APPEND INITIAL LINE TO <level_1>-level_2_tab
    ASSIGNING <level_2> .
    <level_2>-carrname    = <rowset>-carrname .
    <level_2>-connid      = <rowset>-connid .
    <level_2>-fldate      = <rowset>-fldate .
    <level_2>-price       = <rowset>-price .
    <level_2>-currency    = <rowset>-currency .
    <level_2>-seatsmax    = <rowset>-seatsmax .
    <level_2>-seatsocc    = <rowset>-seatsocc .

    AT END OF landxto .
      <level_1>-total_seatsmax = lv_total_seatsmax .
 
      CONDENSE lv_num NO-GAPS .
      CONCATENATE '=SUM(R[-1]C:R[-' lv_num ']C)' INTO <level_1>-total_seatsocc .
    ENDAT .
  ENDLOOP

ENDFORM .                    "fill_context




Результат работы программы: