Skip to Content
0
Aug 23, 2020 at 08:42 PM

TOP-OF-PAGE Heder for lfa1

54 Views Last edit Aug 24, 2020 at 06:34 PM 4 rev

Dear All,

In my Executable report , i need to print city, District, postal code ,address in top of header and these fields i need to fetch from LFA1 table by passing Lifnr filed in selection screen and also i am using other two table bkpf , bseg for document number and vender .

when i am passing lifnr value in selection screen accordingly all address related fields like (ort01, ort02,pstlz,adrnr ) should be show in header for selected Vender 

REPORT ztest_sb.

INCLUDE ztest_top.
INCLUDE ztest_sel_scr.
START-OF-SELECTION.
PERFORM ztest_fetch.
perform ztest_manipulation.
END-OF-SELECTION.

PERFORM display.
TOP-OF-PAGE.
perform TOP-OF-PAGE.
INCLUDE ztest_f01.

*top include  
TYPES : BEGIN OF gty_bkpf,
         bukrs TYPE bukrs,
         belnr TYPE belnr_d,
         gjahr TYPE gjahr,
        END OF gty_bkpf,

        BEGIN OF gty_bseg,
         bukrs TYPE bukrs,
         belnr TYPE belnr_d,
         gjahr TYPE gjahr,
         lifnr TYPE lifnr,
        END OF gty_bseg,

        BEGIN OF gty_lfa1,
          LIFNR type lifnr ,
          ORT01 type ORT01,
          ORT02 type ORT02 ,
          PSTLZ type PSTLZ,
          ADRNR type ADRNR,

        end of gty_lfa1,

        BEGIN OF gty_final,
           belnr TYPE belnr_d,
           lifnr TYPE lifnr,
          ORT01 type ORT01,
          ORT02 type ORT02 ,
          PSTLZ type PSTLZ,
          ADRNR type ADRNR,

        END  OF   gty_final.

        DATA : gi_bkpf      TYPE STANDARD TABLE OF gty_bkpf,
               gi_bseg      TYPE STANDARD TABLE OF gty_bseg,
                gi_LFA1      TYPE STANDARD TABLE OF gty_LFA1,

               gi_final     TYPE STANDARD TABLE OF gty_final,
               gwa_final    TYPE gty_final,
               gv_col_pos   TYPE i,
               gi_fieldcat  TYPE slis_t_fieldcat_alv,
               gwa_fieldcat TYPE slis_fieldcat_alv,
               gwa_layout   TYPE slis_layout_alv,
               gi_top       type slis_t_listheader,
               gwa_top      type slis_listheader,
               gi_line like gwa_top-info,
               ld_lines type i,
               ld_linesc(10) type c.
*Selection Screen Include
SELECTION-SCREEN : BEGIN OF BLOCK b1 .
  PARAMETERS : p_bukrs TYPE bukrs OBLIGATORY,
               p_gjahr TYPE gjahr OBLIGATORY,
               p_lifnr TYPE lifnr OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK b1.

**Data fetch and manipulation include 
FORM ztest_fetch .
  SELECT bukrs
         belnr
         gjahr
  FROM bkpf INTO TABLE gi_bkpf
    WHERE bukrs = p_bukrs
    AND   gjahr = p_gjahr.
  IF gi_bkpf IS NOT INITIAL.

    SORT gi_bkpf BY bukrs belnr gjahr.

    SELECT bukrs
           belnr
           gjahr
           lifnr
      FROM bseg INTO TABLE gi_bseg
      FOR ALL ENTRIES IN gi_bkpf
      WHERE bukrs = gi_bkpf-bukrs
      AND   belnr = gi_bkpf-belnr
      AND   gjahr = gi_bkpf-gjahr.

      SORT gi_bseg BY bukrs belnr gjahr.
      DELETE gi_bseg WHERE lifnr IS INITIAL.

      IF  p_lifnr IS NOT INITIAL .

         SELECT  lifnr
          ort01
          ort02
          pstlz
          adrnr  FROM lfa1 INTO TABLE gi_lfa1
*           FOR ALL ENTRIES IN gi_bseg
           WHERE lifnr = p_lifnr.

           ENDIF.

  ENDIF.
ENDFORM.

FORM ztest_manipulation .

  LOOP AT gi_bseg INTO DATA(wa_bseg).

    READ TABLE gi_bkpf INTO DATA(wa_bkpf) WITH KEY bukrs = wa_bseg-bukrs belnr = wa_bseg-belnr gjahr = wa_bseg-gjahr BINARY SEARCH.
    read table gi_lfa1 into data(wa_lfa1) with key lifnr = wa_bseg-lifnr BINARY SEARCH.
    IF sy-subrc IS INITIAL.
      gwa_final-belnr = wa_bkpf-belnr.
    ENDIF.
    gwa_final-lifnr = wa_bseg-lifnr.
    gwa_final-ort01 = wa_lfa1-ort01.
     gwa_final-ort02 = wa_lfa1-ort02.
     gwa_final-pstlz = wa_lfa1-pstlz.
     gwa_final-adrnr = wa_lfa1-adrnr.
     APPEND gwa_final TO gi_final.
    CLEAR gwa_final.

  ENDLOOP.

  IF p_lifnr IS NOT INITIAL.
    DELETE gi_final WHERE lifnr NE p_lifnr.

  ENDIF.

ENDFORM.

FORM display .

  PERFORM build_fcat USING 'BELNR'    'GI_FINAL'  'Document Number' .
  PERFORM build_fcat USING 'LIFNR'    'GI_FINAL'  'Vendor' .

   gwa_layout-colwidth_optimize = 'X'.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      i_callback_top_of_page = 'TOP-OF-PAGE'
      is_layout          = gwa_layout
      it_fieldcat        = gi_fieldcat
      i_default          = 'X'
      i_save             = 'A'
    TABLES
      t_outtab           = gi_FINAL
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
    MESSAGE TEXT-003 TYPE 'I' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM.

FORM build_fcat  USING    fp_fieldname TYPE slis_fieldname
                          fp_tabname   TYPE slis_tabname
                          fp_seltext   TYPE dd03p-scrtext_l.


 gv_col_pos = gv_col_pos  + 1.

  gwa_fieldcat-col_pos = gv_col_pos.
  gwa_fieldcat-fieldname = fp_fieldname.
  gwa_fieldcat-tabname = fp_tabname.
  gwa_fieldcat-seltext_l = fp_seltext.

  APPEND gwa_fieldcat TO gi_fieldcat.
  CLEAR gwa_fieldcat.

FORM TOP-OF-PAGE .

  gwa_top-typ = 'S'.
  gwa_top-info = 'city'.
  APPEND gwa_TOP TO gi_TOP.
  CLEAR gwa_TOP.
  gwa_top-typ = 'S'.
  gwa_top-info = 'District'.
  APPEND gwa_TOP TO gi_TOP.
  CLEAR gwa_TOP.
  gwa_top-typ = 'S'.
  gwa_top-info = 'Postal code'.
  APPEND gwa_TOP TO gi_TOP.
  CLEAR gwa_TOP.
  gwa_top-typ = 'S'.
  gwa_top-info = 'Address'.
  APPEND gwa_TOP TO gi_TOP.
  CLEAR gwa_TOP.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  EXPORTING
    it_list_commentary       = gi_top .
*   I_LOGO                   =
*   I_END_OF_LIST_GRID       =
*   I_ALV_FORM               =

ENDFORM.

Attachments

output-screen.png (11.7 kB)