..3 Printing program

Here is the nugget to install objects via SAPLINK .

Create a report Z_SUBTOTALS and paste below code into it:


REPORT z_subtotals .

* declare the context
DATA gt_context  TYPE zcontext_subtotals .

* fill the context
PERFORM fill_context .

* call the form
CALL FUNCTION 'ZXLWB_CALLFORM'
  EXPORTING
    iv_formname        = 'SUBTOTALS'
    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 .
  FIELD-SYMBOLS:
    <rowset>            TYPE ty_s_rowset ,
    <level_1>           TYPE zcontext_subtotals_lvl_1_row ,
    <level_2>           TYPE zcontext_subtotals_lvl_2_row ,
    <level_3>           TYPE zcontext_subtotals_lvl_3_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> .
      <level_1>-cityfrom  = <rowset>-cityfrom .
      <level_1>-landxfrom = <rowset>-landxfrom .
      <level_1>-cityto    = <rowset>-cityto .
      <level_1>-landxto   = <rowset>-landxto .
    ENDAT .

    AT NEW carrname .
      APPEND INITIAL LINE TO <level_1>-level_2_tab
      ASSIGNING <level_2> .
      <level_2>-carrname  = <rowset>-carrname .
      <level_2>-connid    = <rowset>-connid .
    ENDAT .

    APPEND INITIAL LINE TO <level_2>-level_3_tab
    ASSIGNING <level_3> .
    <level_3>-fldate      = <rowset>-fldate .
    <level_3>-price       = <rowset>-price .
    <level_3>-currency    = <rowset>-currency .
    <level_3>-seatsmax    = <rowset>-seatsmax .
    <level_3>-seatsocc    = <rowset>-seatsocc .
  ENDLOOP .

ENDFORM .                    "fill_context


 

Result of the printing program execution: