Tuesday, September 26, 2023

Interactive Report with field Expand

 *&---------------------------------------------------------------------*

*& Report ZALV_PRACTICE2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zalv_practice2.
TYPE-POOLSslis.
TABLES ekkoekpo.
TYPESBEGIN OF ty_ekko,
         ebeln    TYPE ekko-ebeln,
         bedat    TYPE ekko-bedat,
         lifnr    TYPE ekko-lifnr,
         checkbox TYPE c,
         expand,
       END OF ty_ekko.
DATA it_ekko TYPE TABLE OF ty_ekko,
       wa_ekko TYPE ty_ekko.

TYPES BEGIN OF ty_ekpo,
          ebeln TYPE ekpo-ebeln,
          ebelp TYPE ekpo-ebelp,
          menge TYPE ekpo-menge,
          meins TYPE ekpo-meins,
          netpr TYPE ekpo-netpr,
        END OF ty_ekpo.

DATA it_ekpo TYPE TABLE OF ty_ekpo,
       wa_ekpo TYPE ty_ekpo.

DATAit_fcat   TYPE slis_t_fieldcat_alv,
      wa_fcat   LIKE LINE OF it_fcat,
      wa_layout TYPE slis_layout_alv.
DATA wa_key TYPE slis_keyinfo_alv" DECLARE OF KEY INFORMATION

SELECT-OPTIONS s_ebeln FOR ekko-ebeln.

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM field_cat.
  PERFORM lay_out.
  PERFORM key_info.
  PERFORM display.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .
  SELECT ebeln bedat lifnr
      FROM ekko INTO TABLE it_ekko
  WHERE ebeln IN s_ebeln.

  SELECT ebeln ebelp menge meins netpr
    FROM ekpo INTO TABLE it_ekpo
  WHERE ebeln IN s_ebeln.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FIELD_CAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM field_cat .
  DATA lv_pos TYPE i.
  IF it_ekko IS NOT INITIAL.
    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'CHECKBOX'.
    wa_fcat-seltext_m 'CHXBOX'.
    wa_fcat-tabname 'IT_EKKO'.
    wa_fcat-input 'X'.
*  wa_fcat-no_zero = 'X'.
    wa_fcat-edit 'X'.
    wa_fcat-checkbox 'X'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'EBELN'.
    wa_fcat-tabname 'IT_EKKO'.
    wa_fcat-seltext_m 'PUR DOC'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'BEDAT'.
    wa_fcat-tabname 'IT_EKKO'.
    wa_fcat-seltext_m 'DOC DATE'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'LIFNR'.
    wa_fcat-tabname 'IT_EKKO'.
    wa_fcat-seltext_m 'VENDOR'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.
  ENDIF.
  IF it_ekpo IS NOT INITIAL.
    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'EBELN'.
    wa_fcat-tabname 'IT_EKPO'.
    wa_fcat-seltext_m 'PUR DOC'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'EBELP'.
    wa_fcat-tabname 'IT_EKPO'.
    wa_fcat-seltext_m 'ITEM'.
    wa_fcat-just 'C'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'MENGE'.
    wa_fcat-tabname 'IT_EKPO'.
    wa_fcat-seltext_m 'QTY'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'MEINS'.
    wa_fcat-tabname 'IT_EKPO'.
    wa_fcat-seltext_m 'UNIT'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.

    lv_pos lv_pos + 1.
    wa_fcat-col_pos lv_pos.
    wa_fcat-fieldname 'NETPR'.
    wa_fcat-tabname 'IT_EKPO'.
    wa_fcat-seltext_m 'NET PRICE'.
    wa_fcat-just 'C'.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.
  ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  LAY_OUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM lay_out .
  wa_layout-zebra             'X'"Zebra looks
  wa_layout-colwidth_optimize 'X'"Column width optimized
  wa_layout-expand_fieldname  'EXPAND'"Expand operation
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  KEY_INFO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM key_info .
  wa_key-header01 'EBELN'" FILLING OF KEY INFORMATION WA.
  wa_key-item01 'EBELN'.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display .
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' "OUT PUT
    EXPORTING
*     I_INTERFACE_CHECK  = ' '
      i_callback_program sy-repid
*     I_CALLBACK_PF_STATUS_SET       = ' '
*     I_CALLBACK_USER_COMMAND        = ' '
      is_layout          wa_layout
      it_fieldcat        it_fcat
*
      i_tabname_header   'IT_EKKO'
      i_tabname_item     'IT_EKPO'
*     I_STRUCTURE_NAME_HEADER        =
*     I_STRUCTURE_NAME_ITEM          =
      is_keyinfo         wa_key
*     IS_PRINT           =
*
*     I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
* IMPORTING
*     E_EXIT_CAUSED_BY_CALLER        =
*     ES_EXIT_CAUSED_BY_USER         =
    TABLES
      t_outtab_header    it_ekko
      t_outtab_item      it_ekpo
    EXCEPTIONS
      program_error      1
      OTHERS             2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.

Output:


Result Screen:





No comments:

Post a Comment

Translation of language in Smart Forms.

  Step by Step process to Translate English language to Spanish language in smart form. 1. Go to T-Code SE63 in command bar and then enter. ...