Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

DISPLAYING THE SELECTED CONTENT.

Former Member
0 Kudos

HI THIS IS A PROGRAM FOR DISPLAYING THE ITEM NO,ITEM DESCRIPTION AND PO QUANTITY AND PO NUMBER FROM TABLES EKPO AND EKKO RESPECTIVELY WITH SELECTION CRITERIA AS POSTING DATE. I WANT TO KNOW IF THIS PROGRAM IS RIGHT.

IF IT IS RIGHT THEN CAN YOU PLEASE HELP ME WITH THE DISPLAYING PART OF THE PROGRAM. IF THERE ARE ANY CHANGES PLEASE LET ME KNOW. thank you.

TABLES : EKKO,

EKPO.

DATA : BEGIN OF ITAB1 OCCURS 0,

EBELN LIKE EKKO-EBELN.

DATA : END OF ITAB1.

DATA : BEGIN OF ITAB2 OCCURS 0,

EBELP LIKE EKPO-EBELP,

MENGE LIKE EKPO-MENGE,

TXZ01 LIKE EKPO-TXZ01.

DATA : END OF ITAB2.

SELECT-OPTIONS : S_EBELN FOR EKKO-EBELN,

S_AEDAT FOR EKKO-AEDAT.

START-OF-SELECTION.

SELECT EBELN FROM EKKO INTO TABLE ITAB1 WHERE EBELN IN S_EBELN AND AEDAT IN S_AEDAT.

IF SY-SUBRC = 0.

ENDIF.

IF NOT ITAB1[] IS INITIAL.

SELECT EBELP MENGE TXZ01 FROM EKPO INTO ITAB2 FOR ALL ENTRIES IN ITAB1 WHERE EBELN = ITAB1-EBELN.

ENDSELECT.

ENDIF.

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello

There is some improvement possible. You may have a look at the sample report ZUS_SDN_SELECT_CONTENT:


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_SELECT_CONTENT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_select_content.


TABLES : ekko,
         ekpo.

DATA: gt_fcat     TYPE lvc_t_fcat,
      gs_layout   type lvc_s_layo,
      gs_variant  type disvariant.


DATA : BEGIN OF itab1 OCCURS 0,

ebeln LIKE ekko-ebeln.

DATA : END OF itab1.

DATA : BEGIN OF itab2 OCCURS 0,

ebelp LIKE ekpo-ebelp,

menge LIKE ekpo-menge,

txz01 LIKE ekpo-txz01.

DATA : END OF itab2.

SELECT-OPTIONS : s_ebeln FOR ekko-ebeln,

s_aedat FOR ekko-aedat.

START-OF-SELECTION.

  SELECT ebeln FROM ekko INTO TABLE itab1
    WHERE ebeln IN s_ebeln
    AND   aedat IN s_aedat.

  IF sy-subrc = 0.

  ENDIF.

  IF NOT itab1[] IS INITIAL.
    SELECT ebelp menge txz01 FROM ekpo INTO TABLE itab2
      FOR ALL ENTRIES IN itab1 WHERE ebeln = itab1-ebeln.
  ENDIF.


  PERFORM build_fieldcatalog.
  perform SET_LAYOUT_AND_VARIANT.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                =
*     I_BUFFER_ACTIVE                   =
*     I_CALLBACK_PROGRAM                = ' '
*     I_CALLBACK_PF_STATUS_SET          = ' '
*     I_CALLBACK_USER_COMMAND           = ' '
*     I_CALLBACK_TOP_OF_PAGE            = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME                  =
*     I_BACKGROUND_ID                   = ' '
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
      IS_LAYOUT_LVC                     = gs_layout
      IT_FIELDCAT_LVC                   = gt_fcat
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS_LVC             =
*     IT_SORT_LVC                       =
*     IT_FILTER_LVC                     =
*     IT_HYPERLINK                      =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = 'X'
      I_SAVE                            = 'A'
      IS_VARIANT                        = gs_variant
*     IT_EVENTS                         =
*     IT_EVENT_EXIT                     =
*     IS_PRINT_LVC                      =
*     IS_REPREP_ID_LVC                  =
*     I_SCREEN_START_COLUMN             = 0
*     I_SCREEN_START_LINE               = 0
*     I_SCREEN_END_COLUMN               = 0
*     I_SCREEN_END_LINE                 = 0
*     I_HTML_HEIGHT_TOP                 =
*     I_HTML_HEIGHT_END                 =
*     IT_EXCEPT_QINFO_LVC               =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           =
*     ES_EXIT_CAUSED_BY_USER            =
    TABLES
      t_outtab                          = itab2[]
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
* define local data
  DATA: ls_fcat   TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'EKPO'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  LOOP AT gt_fcat INTO ls_fcat.
    CASE ls_fcat-fieldname.
      WHEN 'EBELP'  OR
           'MENGE'  OR
           'TXZ01'.

      WHEN OTHERS.
        ls_fcat-tech = 'X'.  " hide columns
    ENDCASE.

    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDLOOP.


ENDFORM.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form SET_LAYOUT_AND_VARIANT .

  clear: gs_layout,
         gs_variant.

  gs_layout-zebra = 'X'.
  gs_layout-cwidth_opt = 'X'.

  gs_variant-report = syst-repid.
  gs_variant-handle = 'GRID'.

endform.                    " SET_LAYOUT_AND_VARIANT

Regards

Uwe

1 REPLY 1

uwe_schieferstein
Active Contributor
0 Kudos

Hello

There is some improvement possible. You may have a look at the sample report ZUS_SDN_SELECT_CONTENT:


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_SELECT_CONTENT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_select_content.


TABLES : ekko,
         ekpo.

DATA: gt_fcat     TYPE lvc_t_fcat,
      gs_layout   type lvc_s_layo,
      gs_variant  type disvariant.


DATA : BEGIN OF itab1 OCCURS 0,

ebeln LIKE ekko-ebeln.

DATA : END OF itab1.

DATA : BEGIN OF itab2 OCCURS 0,

ebelp LIKE ekpo-ebelp,

menge LIKE ekpo-menge,

txz01 LIKE ekpo-txz01.

DATA : END OF itab2.

SELECT-OPTIONS : s_ebeln FOR ekko-ebeln,

s_aedat FOR ekko-aedat.

START-OF-SELECTION.

  SELECT ebeln FROM ekko INTO TABLE itab1
    WHERE ebeln IN s_ebeln
    AND   aedat IN s_aedat.

  IF sy-subrc = 0.

  ENDIF.

  IF NOT itab1[] IS INITIAL.
    SELECT ebelp menge txz01 FROM ekpo INTO TABLE itab2
      FOR ALL ENTRIES IN itab1 WHERE ebeln = itab1-ebeln.
  ENDIF.


  PERFORM build_fieldcatalog.
  perform SET_LAYOUT_AND_VARIANT.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                =
*     I_BUFFER_ACTIVE                   =
*     I_CALLBACK_PROGRAM                = ' '
*     I_CALLBACK_PF_STATUS_SET          = ' '
*     I_CALLBACK_USER_COMMAND           = ' '
*     I_CALLBACK_TOP_OF_PAGE            = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME                  =
*     I_BACKGROUND_ID                   = ' '
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
      IS_LAYOUT_LVC                     = gs_layout
      IT_FIELDCAT_LVC                   = gt_fcat
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS_LVC             =
*     IT_SORT_LVC                       =
*     IT_FILTER_LVC                     =
*     IT_HYPERLINK                      =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = 'X'
      I_SAVE                            = 'A'
      IS_VARIANT                        = gs_variant
*     IT_EVENTS                         =
*     IT_EVENT_EXIT                     =
*     IS_PRINT_LVC                      =
*     IS_REPREP_ID_LVC                  =
*     I_SCREEN_START_COLUMN             = 0
*     I_SCREEN_START_LINE               = 0
*     I_SCREEN_END_COLUMN               = 0
*     I_SCREEN_END_LINE                 = 0
*     I_HTML_HEIGHT_TOP                 =
*     I_HTML_HEIGHT_END                 =
*     IT_EXCEPT_QINFO_LVC               =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           =
*     ES_EXIT_CAUSED_BY_USER            =
    TABLES
      t_outtab                          = itab2[]
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
* define local data
  DATA: ls_fcat   TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'EKPO'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  LOOP AT gt_fcat INTO ls_fcat.
    CASE ls_fcat-fieldname.
      WHEN 'EBELP'  OR
           'MENGE'  OR
           'TXZ01'.

      WHEN OTHERS.
        ls_fcat-tech = 'X'.  " hide columns
    ENDCASE.

    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDLOOP.


ENDFORM.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form SET_LAYOUT_AND_VARIANT .

  clear: gs_layout,
         gs_variant.

  gs_layout-zebra = 'X'.
  gs_layout-cwidth_opt = 'X'.

  gs_variant-report = syst-repid.
  gs_variant-handle = 'GRID'.

endform.                    " SET_LAYOUT_AND_VARIANT

Regards

Uwe