Tuesday, December 25, 2018

Classical Interactive Report with Push Button




Classical Interactive Report with Push Button




REPORT  zabap_gui.

*-------Declaring database tables for using the line type--------------*
TABLES: lfa1, ekko, ekpo.

*------Declaring structures for work area & Internal table-------------*
TYPESBEGIN OF ty_lfa1,
         lifnr 
TYPE lfa1-lifnr,
         land1 
TYPE lfa1-land1,
         name1 
TYPE lfa1-name1,
         regio 
TYPE lfa1-regio,
       
END OF ty_lfa1,

       
BEGIN OF ty_ekko,
         ebeln 
TYPE ekko-ebeln,
         bukrs 
TYPE ekko-bukrs,
         aedat 
TYPE ekko-aedat,
         ernam 
TYPE ekko-ernam,
         lifnr 
TYPE ekko-lifnr,
       
END OF ty_ekko,

       
BEGIN OF ty_ekpo,
         ebeln 
TYPE ekpo-ebeln,
         ebelp 
TYPE ekpo-ebelp,
         matnr 
TYPE ekpo-matnr,
         werks 
TYPE ekpo-werks,
         lgort 
TYPE ekpo-lgort,
       
END OF ty_ekpo.

DATA:
*-----Declaring Work Areas---------------------------------------------*
      wa_lfa1 
TYPE ty_lfa1,
      wa_ekko 
TYPE ty_ekko,
      wa_ekpo 
TYPE ty_ekpo,

*-----Declaring Internal Tables----------------------------------------*
      it_lfa1 
TYPE TABLE OF ty_lfa1,
      it_ekko 
TYPE TABLE OF ty_ekko,
      it_ekpo 
TYPE TABLE OF ty_ekpo.

*---Event Initialization-----------------------------------------------*
INITIALIZATION.
  
SELECT-OPTIONS: s_lifnr FOR lfa1-lifnr.

*---Event Start of Selection-------------------------------------------*
START-OF-SELECTION.
  PERFORM get_data_lfa1.
  
SET PF-STATUS 'PUSH_BUTTON'"Setting PF status for Push Buttons

*---Event At User Command----------------------------------------------*
AT USER-COMMAND. "When user clicks any button

  
CASE sy-ucomm. "It contains the function code of any button
    
WHEN 'EKKO'"Push button Purchase Order
      
PERFORM get_data_ekko.

    
WHEN 'EKPO'"Push button Purchase Order Item
      
PERFORM get_data_ekpo.

    
WHEN 'EXIT'"Push button Exit
      
LEAVE TO SCREEN 0.
    
WHEN 'CANCEL'"Push button Cancel
      
LEAVE TO SCREEN 0.
  
ENDCASE.

*---Event Top of Page for Basic List-----------------------------------*
TOP-OF-PAGE.
  PERFORM top_basic_lfa1.

*---Event Top of Page During Line Selection for Drilled List-----------*
TOP-OF-PAGE DURING LINE-SELECTION.
  CASE sy-lsind. "It counts the drilled number
    
WHEN '1'.
      
PERFORM top_ekko.
    
WHEN '2'.
      
PERFORM top_ekpo.
  
ENDCASE.
*&---------------------------------------------------------------------*
*&      Form  get_data_lfa1
*&---------------------------------------------------------------------*
*       Select data from Vendor table
*----------------------------------------------------------------------*
FORM get_data_lfa1 .

  
REFRESH it_lfa1.

  
IF s_lifnr[] IS NOT INITIAL.
    
SELECT lifnr land1 name1 regio
      
FROM lfa1 INTO TABLE it_lfa1
      
WHERE lifnr IN s_lifnr.

    
IF sy-subrc = 0.
      
LOOP AT it_lfa1 INTO wa_lfa1.
        
WRITE: / wa_lfa1-lifnr,
              
20 wa_lfa1-land1,
              
25 wa_lfa1-name1,
              
65 wa_lfa1-regio.

        
HIDE wa_lfa1-lifnr. "Vendor is keeping Hide to store the data
                            "into system temporarily
        
AT LAST.
          
SKIP 2.
          
WRITE: /25 'End of Vendor Account List'.
        
ENDAT.
      
ENDLOOP.

    
ELSE.
      
MESSAGE 'Vendor doesn''t exist' TYPE 'I'.
    
ENDIF.
  
ELSE.
    
MESSAGE 'Please enter a valid Vendor Account Number' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " get_data_lfa1
*&---------------------------------------------------------------------*
*&      Form  get_data_ekko
*&---------------------------------------------------------------------*
*       Select data from Purchase Order Header table
*----------------------------------------------------------------------*
FORM get_data_ekko .

  
REFRESH it_ekko.

  
IF wa_lfa1-lifnr IS NOT INITIAL.
    
SELECT ebeln bukrs aedat ernam lifnr
      
FROM ekko INTO TABLE it_ekko
      
WHERE lifnr = wa_lfa1-lifnr.

    
IF sy-subrc = 0.
      
LOOP AT it_ekko INTO wa_ekko.
        
WRITE: / wa_ekko-ebeln,
              
15 wa_ekko-bukrs,
              
22 wa_ekko-aedat,
              
34 wa_ekko-ernam,
              
50 wa_ekko-lifnr.

        
HIDE wa_ekko-ebeln. "PO is keeping Hide to store the data
                            "into system temporarily
        
AT LAST.
          
SKIP 2.
          
WRITE: /20 'End of Purchase Order List'.
        
ENDAT.
      
ENDLOOP.
    
ELSE.
      
MESSAGE 'Purchase Order doesn''t exist' TYPE 'I'.
    
ENDIF.
  
ENDIF.

ENDFORM.                    " get_data_ekko
*&---------------------------------------------------------------------*
*&      Form  get_data_ekpo
*&---------------------------------------------------------------------*
*       Select data from Purchase Order Item Table
*----------------------------------------------------------------------*
FORM get_data_ekpo .

  
REFRESH it_ekpo.

  
IF wa_ekko-ebeln IS NOT INITIAL.
    
SELECT ebeln ebelp matnr werks lgort
      
FROM ekpo INTO TABLE it_ekpo
      
WHERE ebeln = wa_ekko-ebeln.

    
IF sy-subrc = 0.
      
LOOP AT it_ekpo INTO wa_ekpo.
        
WRITE: / wa_ekpo-ebeln,
              
15 wa_ekpo-ebelp,
              
22 wa_ekpo-matnr,
              
42 wa_ekpo-werks,
              
50 wa_ekpo-lgort.

        
AT LAST.
          
SKIP 2.
          
WRITE: /25 'End of Material List'.
        
ENDAT.
      
ENDLOOP.
    
ENDIF.
  
ELSE.
    
MESSAGE 'Select a Purchase Order' TYPE 'I'.
  
ENDIF.

ENDFORM.                    " get_data_ekpo
*&---------------------------------------------------------------------*
*&      Form  top_basic_lfa1
*&---------------------------------------------------------------------*
*       Top of page of basic list - Vendor list
*----------------------------------------------------------------------*
FORM top_basic_lfa1 .

  
WRITE: / 'Vendor Account List' COLOR 3.
  
WRITE: / 'Vendor Account',
        
20 'Land',
        
25 'Name',
        
65 'Region'.

ENDFORM.                    " top_basic_lfa1
*&---------------------------------------------------------------------*
*&      Form  top_ekko
*&---------------------------------------------------------------------*
*       Top of page for first secondary list - PO header list
*----------------------------------------------------------------------*
FORM top_ekko .

  
WRITE: / 'Purchase Order List' COLOR 5.
  
WRITE: / 'Po Number',
        
15 'Company',
        
22 'Date',
        
34 'Name',
        
50 'Vendor Account Number'.

ENDFORM.                    " top_ekko
*&---------------------------------------------------------------------*
*&      Form  top_ekpo
*&---------------------------------------------------------------------*
*       Top of page for second secondary list - PO item list
*----------------------------------------------------------------------*
FORM top_ekpo .

  
WRITE: / 'Purchase Order List' COLOR 1.
  
WRITE: / 'PO Number',
        
15 'PO Item',
        
22 'Material',
        
42 'Plant',
        
50 'Storage'.

ENDFORM.                    " top_ekpo

Classical Report of Multiple Tables in SAP ABAP.



Classical Report of Multiple Tables.


REPORT  ZABAP_GUISW.
*-------Declaring the line type of database tables---------------------*
TABLESmaramarcmard.
*------Declaring the types of work areas & internal tables-------------*
TYPESBEGIN OF ty_mara,
        matnr TYPE mara-matnr,
        mtart TYPE mara-mtart,
       END OF ty_mara,
       BEGIN OF ty_marc,
         matnr TYPE marc-matnr,
         werks TYPE marc-werks,
         xchar TYPE marc-xchar,
       END OF ty_marc,
       BEGIN OF ty_mard,
         matnr TYPE mard-matnr,
         werks TYPE mard-werks,
         lgort TYPE mard-lgort,
         pstat TYPE mard-pstat,
       END OF ty_mard,
       BEGIN OF ty_out,
         matnr TYPE marc-matnr"Material
         werks TYPE marc-werks"Plant
         lgort TYPE mard-lgort"Storage Location
         mtart TYPE mara-mtart"Material Type
         xchar TYPE marc-xchar"Batch number
         pstat TYPE mard-pstat"Maintenance Status
       END OF ty_out.
*-----Declaring work areas & internal tables---------------------------*
DATAwa_mara TYPE ty_mara,
      wa_marc TYPE ty_marc,
      wa_mard TYPE ty_mard,
      wa_out  TYPE ty_out,
      it_mara TYPE STANDARD TABLE OF ty_mara,
      it_marc TYPE STANDARD TABLE OF ty_marc,
      it_mard TYPE STANDARD TABLE OF ty_mard,
      it_out  TYPE STANDARD TABLE OF ty_out,
      v_prog TYPE sy-repid"Program name
      v_date TYPE sy-datum"Current date
      v_time TYPE sy-uzeit"Current time
*----------Declaring constants to avoid the hard codes-----------------*
CONSTANTSc_material TYPE char12 VALUE 'MATERIAL NO',
           c_plant    TYPE char5  VALUE 'PLANT',
           c_storage  TYPE char8  VALUE 'STORAGE',
           c_type     TYPE char6  VALUE 'M TYPE',
           c_batch    TYPE char6  VALUE 'BATCH',
           c_maint    TYPE char18 VALUE 'MAINTENANCE STATUS',
           c_end      TYPE char40 VALUE 'End of Material Details'.
*------Event initialization--------------------------------------------*
INITIALIZATION.
  v_prog sy-repid.
  v_date sy-datum.
  v_time sy-uzeit.
*-----------Declaring selection screen with select option for input----*
  SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  SELECT-OPTIONSs_matnr FOR mara-matnr.
  SELECTION-SCREEN END OF BLOCK b1.
*-----Event start of selection-----------------------------------------*
START-OF-SELECTION.
  PERFORM get_mara.
  PERFORM get_marc.
  PERFORM get_mard.
*---Event end of selection---------------------------------------------*
END-OF-SELECTION.
  PERFORM get_output.
  PERFORM display.
*---Event top of page--------------------------------------------------*
TOP-OF-PAGE.
  PERFORM top_of_page.
*&---------------------------------------------------------------------*
*&      Form  GET_MARA
*&---------------------------------------------------------------------*
*       Select data from MARA table
*----------------------------------------------------------------------*
FORM get_mara .
  IF s_matnr IS NOT INITIAL.
    SELECT matnr mtart
      

      FROM mara INTO TABLE it_mara
      

      WHERE matnr IN s_matnr.
    IF sy-subrc 0.
      SORT it_mara BY matnr.
    ELSE.
      MESSAGE 'Material doesn''t exist' TYPE 'I'.
    ENDIF.
  ENDIF.
ENDFORM.                    " GET_MARA
*&---------------------------------------------------------------------*
*&      Form  GET_MARC
*&---------------------------------------------------------------------*
*       Select data from MARC table
*----------------------------------------------------------------------*
FORM get_marc .
  IF it_mara IS NOT INITIAL"Prerequisite of FOR ALL ENTRIES IN
    SELECT matnr werks xchar
      

      FROM marc INTO TABLE it_marc
      

      FOR ALL ENTRIES IN it_mara
      

      WHERE matnr it_mara-matnr.
    IF sy-subrc 0.
      SORT it_marc BY matnr.
    ELSE.
      MESSAGE 'Plant doesn''t exist' TYPE 'I'.
    ENDIF.
  ENDIF.
ENDFORM.                    " GET_MARC
*&---------------------------------------------------------------------*
*&      Form  GET_MARD
*&---------------------------------------------------------------------*
*       Select data from MARD table
*----------------------------------------------------------------------*
FORM get_mard .
  IF it_marc IS NOT INITIAL"Prerequisite of FOR ALL ENTRIES IN
    SELECT matnr werks lgort pstat
      

      FROM mard INTO TABLE it_mard
      

      FOR ALL ENTRIES IN it_marc
      

      WHERE matnr it_marc-matnr
        

        AND werks it_marc-werks.
    IF sy-subrc 0.
      SORT it_mard BY matnr.
    ELSE.
      MESSAGE 'Storage Location doesn''t exist' TYPE 'I'.
    ENDIF.
  ENDIF.
ENDFORM.                    " GET_MARD
*&---------------------------------------------------------------------*
*&      Form  GET_OUTPUT
*&---------------------------------------------------------------------*
*       Preparing the output table by using Loop
*----------------------------------------------------------------------*
FORM get_output .
  IF it_mara IS NOT INITIAL.
    LOOP AT it_mara INTO wa_mara.
      wa_out-matnr wa_mara-matnr.
      wa_out-mtart wa_mara-mtart.
      LOOP AT it_marc INTO wa_marc
        

        WHERE matnr wa_mara-matnr.
        wa_out-werks wa_marc-werks.
        wa_out-xchar wa_marc-xchar.
        LOOP AT it_mard INTO wa_mard
          

          WHERE matnr wa_marc-matnr
            

            AND werks wa_marc-werks.
          wa_out-lgort wa_mard-lgort.
          wa_out-pstat wa_mard-pstat.
          APPEND wa_out TO it_out.
          CLEARwa_outwa_marawa_marcwa_mard.
        ENDLOOP.
      ENDLOOP.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " GET_OUTPUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       Displaying the classical output by using WRITE statement
*----------------------------------------------------------------------*
FORM display .
  IF it_out IS NOT INITIAL.
    LOOP AT it_out INTO wa_out.
      AT FIRST"Control break statement – display one time at first
        WRITE/  c_material,
               21 c_plant,
               27 c_storage,
               37 c_type,
               45 c_batch,
               54 c_maint.
        ULINE.
        SKIP.
      ENDAT.
      WRITE/  wa_out-matnr,
             21 wa_out-werks,
             27 wa_out-lgort,
             37 wa_out-mtart,
             45 wa_out-xchar,
             54 wa_out-pstat.
      IF wa_out-matnr IS INITIAL.
        AT END OF matnr"Control break statement
          SKIP.
        ENDAT.
      ENDIF.
      AT LAST"Control break statement – display one time at last
        ULINE.
        WRITE/ c_end.
      ENDAT.
    ENDLOOP.
  ENDIF.
ENDFORM.                    " DISPLAY
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       Top of page of Classical output
*----------------------------------------------------------------------*
FORM top_of_page .
  WRITE/ v_prog,
         / v_date DD/MM/YYYY,
         / v_time.
  ULINE.
ENDFORM.                    " TOP_OF_PAGE
x

Classical Report  of Multiple Tables