How To Use Subscreen In Sap ABAP

In this guide, I will explain to you how to make a subscreen in sap ABAP with examples.

I can explain with an example of mini project , we use tables sbook, sflight and spfli -sbook to fetch carrid , connid , fldate, and lugguage weight , sflight- to fetch occupied for the economy, first and business class and spfli – is to fetch cityto and cityfrom.

this is very simple find the sum, weight, and average of flight, it triggers when a particular key is pressed.

step 1: you need to create 2 screens – Main Screen ‘9001’ and Subscreen ‘9002’.

Step 2: you need to define the variable ‘dynp’ and set the default value empty screen ‘9003’

PROGRAM yxex_airline_mp_copy.

TABLES : sbook, Yrex_FFINAL.

DATA: gt_sbook TYPE TABLE OF sbook,
      gt_sflight  TYPE TABLE OF sflight,
      gt_spfli     TYPE TABLE OF spfli.

DATA: wa_sbook TYPE  sbook,
      wa_sflight  TYPE  sflight,
      wa_spfli     TYPE  spfli.

Data: gt_ffinal type TABLE OF Yrex_FFINAL,
      wa_ffinal type Yrex_FFINAL.

Data : dynp TYPE sy-dynnr VALUE '9003'.

Step 3 : Screen 9001, you need to call subscreen in both PBO and PAI and make input screen

PROCESS BEFORE OUTPUT.
 MODULE STATUS_9001.
   Call SUBSCREEN SUBS1 INCLUDING sy-repid dynp.

PROCESS AFTER INPUT.
MODULE back_command.
 MODULE USER_COMMAND_9001.
  CALL SUBSCREEN SUBS1.



Step 4: GO inside the module USER_COMMAND_9001, to call the subscreen at any condition

  IF sy-ucomm = 'CALCS'.
    PERFORM getflight.
    dynp = '9002'.
  ELSEIF SY-UCOMM = 'GETPLAT'.
  ENDIF.

Step 5: Inside the getflight subroutine you need to write logic that finds the sum, and an average of the flight.

FORM getflight .
  select * from sbook INTO TABLE gt_sbook
    where carrid = sbook-carrid
    AND   connid = sbook-connid
    AND   fldate = sbook-fldate.
    IF sy-subrc = 0.
      SELECT * From sflight INTO TABLE gt_sflight
        FOR ALL ENTRIES IN gt_sbook
        WHERE carrid = gt_sbook-carrid
        AND   connid = gt_sbook-connid
        AND   fldate = gt_sbook-fldate.
        IF sy-subrc = 0.
          SELECT * FROM spfli INTO TABLE gt_spfli
            FOR ALL ENTRIES IN gt_sbook
            WHERE carrid = gt_sbook-carrid
            AND   connid = gt_sbook-connid.
            IF sy-subrc = 0 .
*                sum =lugguage
*                avg = sum/ seats
               LOOP AT gt_sbook INTO wa_sbook.
                 READ TABLE gt_sflight INTO wa_sflight
                 WITH KEY carrid = wa_sbook-carrid
                          connid = wa_sbook-connid
                          fldate = wa_sbook-fldate.
                 IF sy-subrc = 0.
                   READ TABLE gt_spfli INTO wa_spfli
                   WITH KEY carrid = wa_sbook-carrid
                            connid = wa_sbook-connid.
                   IF sy-subrc = 0.

                     // sum
                     IF wa_sbook-class = 'Y'.
                       wa_ffinal-sum_e = wa_ffinal-sum_e + wa_sbook-luggweight.
                     ELSEIF wa_sbook-class = 'C'.
                       wa_ffinal-sum_b = wa_ffinal-sum_b + wa_sbook-luggweight.
                     ELSEIF wa_sbook-class = 'F'.
                       wa_ffinal-sum_f = wa_ffinal-sum_f + wa_sbook-luggweight.

                     ENDIF.

//economy class
                     IF wa_ffinal-economy is INITIAL.
                     wa_ffinal-economy = wa_sflight-seatsocc. 
                     ENDIF.
//first class
                     IF wa_ffinal-firstclass IS INITIAL.
                     wa_ffinal-firstclass = wa_sflight-seatsocc_f. 
                     ENDIF.
//business class
                     IF wa_ffinal-business IS INITIAL.
                     wa_ffinal-business = wa_sflight-seatsocc_b. 
                     ENDIF.

                     AT END OF fldate.
                       wa_ffinal-avgweight_e = wa_ffinal-sum_e / wa_ffinal-economy.
                       wa_ffinal-avgweight_b = wa_ffinal-sum_b / wa_ffinal-business.
                       wa_ffinal-avgweight_f = wa_ffinal-sum_f / wa_ffinal-firstclass.
                       ENDAT.

                   ENDIF.
                 ENDIF.

               ENDLOOP.
               move-CORRESPONDING wa_ffinal TO yrex_ffinal.
            ENDIF.
        ENDIF.
    ENDIF.
ENDFORM.

Step 6: In a subscreen ‘9002’ you need to make an output field (go to layout- get from a dictionary or get from the program )where your output will be displayed – In my case, I use the yrex_ffinal table that has attributes sum_e, sum_f, sum_b, and avg_f,avg_e, avg_b.

In the subscreen, you can add validation but in my case, I am not adding that much functionality, this is for giving a subscreen overview.

PROCESS BEFORE OUTPUT.
* MODULE STATUS_9002.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_9002.

Leave a Comment