Thursday, September 5, 2019

Field Symbol in Control Break Statement

If we use field symbol rather than normal work area then the value of the table remains unchanged. It means it doesn't convert into *** and zero into the corresponding fields.

TABLES ekpo.
FIELD-SYMBOLS<it_ekpo> TYPE STANDARD TABLE.

INITIALIZATION.
  
SELECT-OPTIONS s_ebeln FOR ekpo-ebeln.

CLASS pur DEFINITION.
  
PUBLIC SECTION.
    
TYPESBEGIN OF ts_ekpo,
             ebeln 
TYPE ekpo-ebeln,
             ebelp 
TYPE ekpo-ebelp,
             txz01 
TYPE ekpo-txz01,
             ktmng 
TYPE ekpo-ktmng,
             meins 
TYPE ekpo-meins,
             netpr 
TYPE ekpo-netpr,
             peinh 
TYPE ekpo-peinh,
           
END OF ts_ekpo.
    
DATA dref TYPE REF TO data.
    
METHODSekpooutput.
ENDCLASS.

CLASS pur IMPLEMENTATION.
  
METHOD ekpo.
    
CREATE DATA dref TYPE TABLE OF ts_ekpo.
    
ASSIGN dref->TO <it_ekpo>.

    
SELECT ebeln ebelp txz01
           ktmng meins netpr peinh
      
FROM ekpo INTO TABLE <it_ekpo>
      
WHERE ebeln IN s_ebeln.
  
ENDMETHOD.

  
METHOD output.
    
FIELD-SYMBOLS<wa_ekpo>  TYPE ts_ekpo,
                   <flag>     
TYPE char1,
                   <subtot>   
TYPE any,
                   <subprice> 
TYPE any,
                   <grandtot> 
TYPE any,
                   <grandpr>  
TYPE any.

    
IF <it_ekpo> IS ASSIGNED.
      
CREATE DATA dref TYPE DECIMALS 2.
      
ASSIGN dref->TO <subtot>.
      
CREATE DATA dref TYPE DECIMALS 2.
      
ASSIGN dref->TO <grandtot>.
      
CREATE DATA dref TYPE DECIMALS 2.
      
ASSIGN dref->TO <subprice>.
      
CREATE DATA dref TYPE DECIMALS 2.
      
ASSIGN dref->TO <grandpr>.
      
CREATE DATA dref TYPE char1.
      
ASSIGN dref->TO <flag>.

      
LOOP AT <it_ekpo> ASSIGNING <wa_ekpo>.

        
AT NEW ('EBELN').
          <flag> 
'X'.
        
ENDAT.

        
IF <flag> 'X'.
          
WRITE/ <wa_ekpo>-ebeln,
               
12  <wa_ekpo>-ebelp,
               
20  <wa_ekpo>-txz01,
               
45  <wa_ekpo>-ktmng,
               
60  <wa_ekpo>-meins,
               
65  <wa_ekpo>-netpr,
               
80  <wa_ekpo>-peinh.

        
ELSE.
          
WRITE/12 <wa_ekpo>-ebelp,
                 
20  <wa_ekpo>-txz01,
                 
45  <wa_ekpo>-ktmng,
                 
60  <wa_ekpo>-meins,
                 
65  <wa_ekpo>-netpr,
                 
80  <wa_ekpo>-peinh.
        
ENDIF.

        <subtot>   
<subtot>   + <wa_ekpo>-ktmng.
        <grandtot> 
<grandtot> + <wa_ekpo>-ktmng.
        <subprice> 
<subprice> + <wa_ekpo>-netpr.
        <grandpr>  
<grandpr>  + <wa_ekpo>-netpr.

        
AT END OF ('EBELN').
          
WRITE'==================================================',
                 / 
'Subtotal',
                 
50 <subtot>,
                 
70 <subprice>.
          
CLEAR<subtot><subprice>.
        
ENDAT.

        
AT LAST.
          
ULINE.
          
WRITE'Grand Total',
                 
50 <grandtot>,
                 
70 <grandpr>.
        
ENDAT.

        
CLEAR <flag>.
      
ENDLOOP.
    
ENDIF.
  
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  
DATA po TYPE REF TO pur.
  
CREATE OBJECT po.
  
CALL METHODpo->ekpo,
               po
->output.



No comments: