Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8526

Re: dynamic internal tables

$
0
0

Hi

Just observe this program ..

i thing it is useful to u.........

 

 

 

*&---------------------------------------------------------------------*
*& Report 
YVAMC_DYN_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YVAMC_DYN_TABLE.
TYPE-POOLS SLIS .
TYPES: BEGIN OF TY_VBAK,
         KUNNR TYPE KUNNR,
         VBELN TYPE VBELN,
         ERNAM TYPE ERNAM,
       END OF TY_VBAK.


DATA: T_VBAK TYPE TABLE OF TY_VBAK,
        W_VBAK TYPE TY_VBAK,
        W_FCAT TYPE LVC_S_FCAT,
        T_FCAT TYPE LVC_T_FCAT,
        G_KUNNR TYPE KNA1-KUNNR,
        DY_TABLE TYPE REF TO DATA ,
        IT_FCAT TYPE  SLIS_T_FIELDCAT_ALV .

FIELD-SYMBOLS: <DY_TABLE> TYPE  STANDARD TABLE,
                 <DY_WA> TYPE ANY,
                 <FIELD> TYPE ANY.

SELECT-OPTIONS S_KUNNR FOR  G_KUNNR NO INTERVALS.

START-OF-SELECTION.

   PERFORM GET_VBAK.
   PERFORM GET_FCAT.
   PERFORM POPULATE_DYN.
*&---------------------------------------------------------------------*
*&      Form  GET_VBAK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_VBAK .
   SELECT KUNNR
           VBELN
          ERNAM

          FROM VBAK
          INTO TABLE T_VBAK
         WHERE KUNNR IN S_KUNNR.
   IF SY-SUBRC <> 0.
     MESSAGE 'No Data' TYPE 'I'.
     LEAVE LIST-PROCESSING.
   ENDIF.
ENDFORM.                    " GET_VBAK
*&---------------------------------------------------------------------*
*&      Form  GET_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_FCAT .
   W_FCAT-FIELDNAME = 'KUNNR'.
   W_FCAT-SCRTEXT_L = 'Customer'.
*  W_FCAT-COLTEXT = 'Customer'.
   APPEND W_FCAT TO T_FCAT.
   CLEAR W_FCAT.

   LOOP AT T_VBAK INTO W_VBAK.

     W_FCAT-FIELDNAME = W_VBAK-VBELN.
     W_FCAT-COLTEXT = W_VBAK-VBELN.
     APPEND W_FCAT TO T_FCAT.
     CLEAR W_FCAT.

   ENDLOOP.

   CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
     EXPORTING
       IT_FIELDCATALOG = T_FCAT
     IMPORTING
       EP_TABLE        = DY_TABLE.
**************BREAK-POINT.
   ASSIGN DY_TABLE->* TO <DY_TABLE>.
   DATA WA TYPE REF TO DATA.
   CREATE DATA WA LIKE LINE OF <DY_TABLE>.
   ASSIGN WA->* TO <DY_WA>.
ENDFORM.                    " GET_FCAT
*&---------------------------------------------------------------------*
*&      Form  POPULATE_DYN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM POPULATE_DYN .
   ASSIGN COMPONENT  'KUNNR'  OF STRUCTURE <DY_WA> TO <FIELD>.
   IF SY-SUBRC = 0.
     <FIELD> = W_VBAK-KUNNR.
   ENDIF.

   LOOP AT T_VBAK INTO W_VBAK.
     ASSIGN COMPONENT  W_VBAK-VBELN OF STRUCTURE <DY_WA> TO <FIELD>.
     IF SY-SUBRC = 0.
       <FIELD> = W_VBAK-ERNAM.
     ENDIF.
     AT END OF KUNNR.
       APPEND <DY_WA> TO <DY_TABLE>.
     ENDAT.
   ENDLOOP.

   CALL FUNCTION 'LVC_TRANSFER_TO_SLIS'
     EXPORTING
       IT_FIELDCAT_LVC               = T_FCAT
*   IT_SORT_LVC                   =
*   IT_FILTER_LVC                 =
*   IS_LAYOUT_LVC                 =
    IMPORTING
      ET_FIELDCAT_ALV               = IT_FCAT
*   ET_SORT_ALV                   =
*   ET_FILTER_ALV                 =
*   ES_LAYOUT_ALV                 =
* TABLES
*   IT_DATA                       =
* EXCEPTIONS
*   IT_DATA_MISSING               = 1
*   IT_FIELDCAT_LVC_MISSING       = 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.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
      I_CALLBACK_PROGRAM                = SY-CPROG
*   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                         =
       IT_FIELDCAT                       = IT_FCAT
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
     TABLES
       T_OUTTAB                          <DY_TABLE> "T_VBAK
* 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.



ENDFORM.                    " POPULATE_DYN


Viewing all articles
Browse latest Browse all 8526

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>