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: 

Interactive ALV Report.

Former Member
0 Kudos

Pl. help me regarding Interactive ALV Report. Thanx in Advance.

-Rupesh.

1 ACCEPTED SOLUTION

dhorions
Contributor
0 Kudos

[Removed by moderator.]

Then you will see you were not the first to think of asking this question here.

5 REPLIES 5

Former Member
0 Kudos

Hi,

Go thru this sample ALV Interactive report.

&----


*& Report : ZASSG_ALV_JAYARAM2

*& Title : Interactive ALV report

*& Author : Jayarama Sarma

*& Created on : 04/05/2004

*& Request :

*& Desription : Generates a Interactive ALV report to list out

  • Billing details.

&----


*& Modification Log

&----


*& Mod # Author Date Requested by

*& Reason for Change

&----


*& 00 #

*&

&----


REPORT ZASSG_ALV_JAYARAM2 NO STANDARD PAGE HEADING

LINE-SIZE 132

LINE-COUNT 64

MESSAGE-ID Z00.

*..Type Definitions for ALV Report

TYPE-POOLS SLIS.

----


  • Table/Structure declarations. *

----


TABLES : VBRK, " Billing: Header Data

VBRP, " Billing: Item Data

T001, " Comapny Codes

TVKOT, " Sales Organizations: Texts

MAKT. " Material Descriiptions

----


*.. Internal Tables declaration *

----


*----- Internal table to store billing docs which are not cancelled

DATA : BEGIN OF IT_VBRK OCCURS 0,

VBELN LIKE VBRK-VBELN, " Billing document

WAERK LIKE VBRK-WAERK, " SD document currency

VKORG LIKE VBRK-VKORG, " Sales organization

VTEXT LIKE TVKOT-VTEXT, " Sales organization text

FKDAT LIKE VBRK-FKDAT, " Billing date

BUKRS LIKE VBRK-BUKRS, " Company Code

BUTXT LIKE T001-BUTXT, " Company Code text

NETWR LIKE VBRK-NETWR, " Net value in document currency

END OF IT_VBRK.

*-----Internal table to stroe ITEM DETAILS

DATA: BEGIN OF IT_VBRP OCCURS 0,

POSNR LIKE VBRP-POSNR, " Billing item

FKIMG LIKE VBRP-FKIMG, " Actual billed quantity

VRKME LIKE VBRP-VRKME, " Sales unit

NETWR LIKE VBRP-NETWR, " Net value of the billing item

MATNR LIKE VBRP-MATNR, " Material number

ARKTX LIKE VBRP-ARKTX, " Short text for sales order item

END OF IT_VBRP.

----


  • Variable / Flag Declerations *

----


DATA : FG_COLOR VALUE ' ', " FLAG TO CHANGE THE COLOR OF THE RECORD

FG_NO_DATA VALUE ' '. " FLAG TO CHECK THE DATA

DATA : V_REPID TYPE SYREPID.

----


  • ALV Type declaration *

----


DATA : IT_FIELDCAT TYPE STANDARD TABLE OF

SLIS_FIELDCAT_ALV WITH HEADER LINE.

DATA : IT_SORT TYPE SLIS_T_SORTINFO_ALV,

WA_SORT TYPE SLIS_SORTINFO_ALV.

DATA : IT_EVENT TYPE SLIS_T_EVENT,

WA_EVENT LIKE LINE OF IT_EVENT.

DATA : IT_HEADINGS TYPE STANDARD TABLE OF

SLIS_LISTHEADER WITH HEADER LINE.

DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA : WA_KEYINFO TYPE SLIS_KEYINFO_ALV.

----


  • Selection Screen. *

----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_VBELN FOR VBRK-VBELN, " Billing doc no

S_FKDAT FOR VBRK-FKDAT OBLIGATORY, " Billing date

S_MATNR FOR VBRP-MATNR. " Material no

SELECTION-SCREEN END OF BLOCK B1.

----


  • Event:Initialization *

----


INITIALIZATION.

V_REPID = SY-REPID.

S_FKDAT-LOW = SY-DATUM - 200.

S_FKDAT-HIGH = SY-DATUM.

APPEND S_FKDAT.

----


  • AT Selection Screen. *

----


AT SELECTION-SCREEN.

PERFORM VALIDATE_VBELN.

PERFORM VALIDATE_MATNR.

----


  • Event: Start-of-Selection *

----


START-OF-SELECTION.

PERFORM GET_VBRK_DATA.

----


  • Event: End-of-Selection *

----


END-OF-SELECTION.

PERFORM GET_EVENTS.

PERFORM FIELDCATALOG.

PERFORM LIST_DISPLAY.

//////////////////////////////////////////////////////////////////////

*

  • FORM DEFINITIONS *

*

*//////////////////////////////////////////////////////////////////////

&----


*& Form list_display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM LIST_DISPLAY.

WA_LAYOUT-INFO_FIELDNAME = 'COLOR'.

WA_LAYOUT-TOTALS_TEXT = 'GRAND TOTAL'.

WA_LAYOUT-ZEBRA = 'X'.

WA_LAYOUT-KEY_HOTSPOT = 'X'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_STRUCTURE_NAME =

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = IT_EVENT

  • 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

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = IT_VBRK

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. " list_display

&----


*& Form fieldcatalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FIELDCATALOG.

REFRESH IT_FIELDCAT.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

I_INTERNAL_TABNAME = 'IT_VBRK'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = V_REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = IT_FIELDCAT[]

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.

*..Changing the fieldcatlog as required

LOOP AT IT_FIELDCAT.

CASE IT_FIELDCAT-FIELDNAME.

WHEN 'VBELN'.

IT_FIELDCAT-SELTEXT_L = 'Billing doc no'.

IT_FIELDCAT-SELTEXT_M = 'Bill No'.

IT_FIELDCAT-SELTEXT_S = 'Bill'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

OUTPUTLEN

WHERE FIELDNAME = 'VBELN'.

WHEN 'WAERK'.

IT_FIELDCAT-SELTEXT_L = 'SD document Currency'.

IT_FIELDCAT-SELTEXT_M = 'Document Currency'.

IT_FIELDCAT-SELTEXT_S = 'Currency'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'WAERK'.

WHEN 'VKORG'.

IT_FIELDCAT-SELTEXT_L = 'Sales Organisation'.

IT_FIELDCAT-SELTEXT_M = 'Sales Org'.

IT_FIELDCAT-SELTEXT_S = 'S,Org'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'VKORG'.

WHEN 'VTEXT'.

IT_FIELDCAT-SELTEXT_L = 'Sales Organisation Name'.

IT_FIELDCAT-SELTEXT_M = 'Sales Org Text'.

IT_FIELDCAT-SELTEXT_S = 'S,Org'.

IT_FIELDCAT-OUTPUTLEN = '30'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'VTEXT'.

WHEN 'FKDAT'.

IT_FIELDCAT-SELTEXT_L = 'Billing Date'.

IT_FIELDCAT-SELTEXT_M = 'Bill.Date'.

IT_FIELDCAT-SELTEXT_S = 'BDate'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'FKDAT'.

WHEN 'BUKRS'.

IT_FIELDCAT-SELTEXT_L = 'Company Code'.

IT_FIELDCAT-SELTEXT_M = 'Company'.

IT_FIELDCAT-SELTEXT_S = 'Comp'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'BUKRS'.

WHEN 'BUTXT'.

IT_FIELDCAT-SELTEXT_L = 'Company Name'.

IT_FIELDCAT-SELTEXT_M = 'Comp Text'.

IT_FIELDCAT-SELTEXT_S = 'Comp'.

IT_FIELDCAT-OUTPUTLEN = '25'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'BUTXT'.

WHEN 'NETWR'.

IT_FIELDCAT-SELTEXT_L = 'Net value in docu currency'.

IT_FIELDCAT-SELTEXT_M = 'Net value in currency'.

IT_FIELDCAT-SELTEXT_S = 'Net Value'.

IT_FIELDCAT-OUTPUTLEN = '20'.

IT_FIELDCAT-DO_SUM = 'X'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

DO_SUM

WHERE FIELDNAME = 'NETWR'.

ENDCASE.

ENDLOOP.

ENDFORM. " fieldcatalog

&----


*& Form sort_tab

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SORT_TAB.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'VBELN'.

WA_SORT-SPOS = '1'.

WA_SORT-UP = 'X'.

WA_SORT-SUBTOT = 'X'.

APPEND WA_SORT TO IT_SORT.

ENDFORM. " sort_tab

&----


*& Form get_events

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_EVENTS.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 1

IMPORTING

ET_EVENTS = IT_EVENT

EXCEPTIONS

LIST_TYPE_WRONG = 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.

LOOP AT IT_EVENT INTO WA_EVENT.

CASE WA_EVENT-NAME.

WHEN 'TOP_OF_PAGE'.

WA_EVENT-FORM = 'DISPLAY_HEADER'.

WHEN 'USER_COMMAND'.

WA_EVENT-FORM = 'GENERATE_SECLIST'.

ENDCASE.

MODIFY IT_EVENT FROM WA_EVENT INDEX SY-TABIX.

ENDLOOP.

ENDFORM. " get_events

&----


*& Form DISPLAY_HEADER

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY_HEADER.

WRITE : /3 'Date : ',

10 SY-DATUM USING EDIT MASK '__/__/____',

35 'Intelligroup Asia Pvt. Ltd',

80 'Time : ',

90 SY-UZEIT,

/3 'User : ',

10 SY-UNAME,

30 SY-TITLE,

80 'Page : ',

90 SY-PAGNO.

ENDFORM. " DISPLAY_HEADER

&----


*& Form VALIDATE_VBELN

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_VBELN.

  • Validating Billing doc no

SELECT VBELN

INTO VBRK-VBELN

UP TO 1 ROWS

FROM VBRK

WHERE VBELN IN S_VBELN.

ENDSELECT.

IF SY-SUBRC NE 0.

MESSAGE E010. " Invalid billing doc no

ENDIF.

ENDFORM. " VALIDATE_VBELN

&----


*& Form VALIDATE_MATNR

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_MATNR.

  • Validating material no

SELECT MATNR

INTO VBRP-MATNR

UP TO 1 ROWS

FROM VBRP

WHERE MATNR IN S_MATNR.

ENDSELECT.

IF SY-SUBRC NE 0.

MESSAGE E018. " Invalid material number

ENDIF.

ENDFORM. " VALIDATE_MATNR

&----


*& Form GET_VBRK_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_VBRK_DATA.

  • To get Billing doc detials based on selections

SELECT V~VBELN

V~WAERK

V~VKORG

V~FKDAT

V~BUKRS

V~NETWR

T~VTEXT

C~BUTXT

INTO CORRESPONDING FIELDS OF TABLE IT_VBRK

FROM VBRK AS V

INNER JOIN VBRP AS P

ON VVBELN = PVBELN

INNER JOIN TVKOT AS T

ON VVKORG = TVKORG

INNER JOIN T001 AS C

ON VBUKRS = CBUKRS

WHERE V~VBELN IN S_VBELN

AND V~FKDAT IN S_FKDAT

AND P~MATNR IN S_MATNR.

SORT IT_VBRK.

DELETE ADJACENT DUPLICATES FROM IT_VBRK COMPARING VBELN.

IF SY-SUBRC NE 0.

FG_NO_DATA = 'X'.

ENDIF.

ENDFORM. " GET_VBRK_DATA

&----


*& Form GENERATE_SECLIST

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GENERATE_SECLIST USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

CASE R_UCOMM.

WHEN '&IC1'. "DOUBLE CLICK

READ TABLE IT_VBRK INDEX RS_SELFIELD-TABINDEX.

SELECT POSNR

FKIMG

VRKME

NETWR

MATNR

ARKTX

INTO TABLE IT_VBRP

FROM VBRP

WHERE VBELN EQ IT_VBRK-VBELN.

SORT IT_VBRP.

PERFORM FIELDCAT_SECLIST.

PERFORM DISPLY_SECLIST.

ENDCASE.

ENDFORM. " GENERATE_SECLIST

&----


*& Form FIELDCAT_SECLIST

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FIELDCAT_SECLIST.

REFRESH IT_FIELDCAT.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

I_INTERNAL_TABNAME = 'IT_VBRP'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = V_REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = IT_FIELDCAT[]

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.

*..Changing the fieldcatlog as required

LOOP AT IT_FIELDCAT.

CASE IT_FIELDCAT-FIELDNAME.

WHEN 'POSNR'.

IT_FIELDCAT-SELTEXT_L = 'Billing Iem no'.

IT_FIELDCAT-SELTEXT_M = 'Bill Item No'.

IT_FIELDCAT-SELTEXT_S = 'Item No'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

OUTPUTLEN

WHERE FIELDNAME = 'POSNR'.

WHEN 'FKIMG'.

IT_FIELDCAT-SELTEXT_L = 'Actual billed quantity'.

IT_FIELDCAT-SELTEXT_M = 'Billed Quantity'.

IT_FIELDCAT-SELTEXT_S = 'Bill.Qty'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'FKIMG'.

WHEN 'VRKME'.

IT_FIELDCAT-SELTEXT_L = 'Sales Unit'.

IT_FIELDCAT-SELTEXT_M = 'Sale unit'.

IT_FIELDCAT-SELTEXT_S = 'S.Unit'.

IT_FIELDCAT-OUTPUTLEN = '15'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'VRKME'.

WHEN 'NETWR'.

IT_FIELDCAT-SELTEXT_L = 'Net value in docu currency'.

IT_FIELDCAT-SELTEXT_M = 'Net value in currency'.

IT_FIELDCAT-SELTEXT_S = 'Net Value'.

IT_FIELDCAT-OUTPUTLEN = '20'.

IT_FIELDCAT-DO_SUM = 'X'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

DO_SUM

WHERE FIELDNAME = 'NETWR'.

WHEN 'MATNR'.

IT_FIELDCAT-SELTEXT_L = 'Material Number'.

IT_FIELDCAT-SELTEXT_M = 'Mat. Number'.

IT_FIELDCAT-SELTEXT_S = 'Mat. No'.

IT_FIELDCAT-OUTPUTLEN = '30'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'MATNR'.

WHEN 'ARKTX'.

IT_FIELDCAT-SELTEXT_L = 'Text for sales order item'.

IT_FIELDCAT-SELTEXT_M = 'Sale Order Text'.

IT_FIELDCAT-SELTEXT_S = 'SO Item text'.

IT_FIELDCAT-OUTPUTLEN = '30'.

MODIFY IT_FIELDCAT TRANSPORTING SELTEXT_L

SELTEXT_M

SELTEXT_S

WHERE FIELDNAME = 'ARKTX'.

ENDCASE.

ENDLOOP.

ENDFORM. " FIELDCAT_SECLIST

&----


*& Form DISPLY_SECLIST

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLY_SECLIST.

CLEAR WA_LAYOUT.

WA_LAYOUT-INFO_FIELDNAME = 'COLOR'.

WA_LAYOUT-TOTALS_TEXT = 'GRAND TOTAL'.

WA_LAYOUT-ZEBRA = 'X'.

WA_LAYOUT-F2CODE = '&ETA'.

WA_LAYOUT-DETAIL_POPUP = 'X'.

WA_LAYOUT-DETAIL_INITIAL_LINES = 'X'.

WA_LAYOUT-GET_SELINFOS = 'X'.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_STRUCTURE_NAME =

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT = IT_SORT

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = IT_EVENT

  • 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

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = IT_VBRP

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. " DISPLY_SECLIST

Regards,

Jayaram...

0 Kudos

Jayaram,

please use the CODE Button above to keep this web interface from removing all formatting.

See this sample for building a field catalog from a n y internal table (Something SAP can't do):


*&---------------------------------------------------------------------*
*&      Form  ALV_FIELDCAT_FOR_ITAB
*&---------------------------------------------------------------------*
*       Feldkatalog from (arbitrary) internal Table (c) Clemens Li
*       * build field catalog from        type description
*----------------------------------------------------------------------*
FORM alv_fieldcat_for_itab                                  "#EC *
  TABLES   pt_outtab                      TYPE table        "#EC *
  CHANGING pt_alv_fieldcat                TYPE slis_t_fieldcat_alv."#EC *
  DATA:
    l_desc                                TYPE sydes_desc,
    l_alv_fieldcat                        TYPE slis_fieldcat_alv,
    l_longfield                           TYPE fname.
  FIELD-SYMBOLS:
    <typeinfo>                            TYPE sydes_typeinfo,
    <nameinfo>                            TYPE sydes_nameinfo.
  DESCRIBE FIELD pt_outtab INTO l_desc.                     "#EC *

  LOOP AT l_desc-types
      ASSIGNING <typeinfo>
      WHERE NOT idx_name IS INITIAL
        AND table_kind IS INITIAL "no entries for deep table like color
        AND back                          = 1. "top-level-entries only.
    READ TABLE l_desc-names INDEX <typeinfo>-idx_name
      ASSIGNING <nameinfo>.
    CHECK <nameinfo>-name                 <> 'INCLUDE'.
    l_alv_fieldcat-fieldname              = <nameinfo>-name.
    WHILE NOT <nameinfo>-continue IS INITIAL.
      ADD 1 TO <typeinfo>-idx_name.
      READ TABLE l_desc-names INDEX <typeinfo>-idx_name
        ASSIGNING <nameinfo>.
      CONCATENATE
        l_alv_fieldcat-fieldname
        <nameinfo>-name
        INTO l_alv_fieldcat-fieldname.
    ENDWHILE." not <nameinfo>-continue IS INITIAL.
    READ TABLE l_desc-names INDEX <typeinfo>-idx_help_id
      ASSIGNING <nameinfo>.
    IF sy-subrc                           = 0.

* Caution: Help-ID may be Tablename-Fieldname and thus longer
* than 30 Chars; l_alv_fieldcat-rollname is 30 Chars only
      l_alv_fieldcat-rollname             = <nameinfo>-name.
      l_longfield                         = <nameinfo>-name.
      WHILE NOT <nameinfo>-continue IS INITIAL.
        ADD 1 TO <typeinfo>-idx_help_id.
        READ TABLE l_desc-names INDEX <typeinfo>-idx_help_id
          ASSIGNING <nameinfo>.
        CONCATENATE
          l_longfield
          <nameinfo>-name
          INTO l_longfield.
      ENDWHILE." not l_desc-continue is initial.

* help id may be data element or <table>-<field>
      IF l_longfield CA '-'.

* get data                                type for table field
        PERFORM get_rollname_4_tabfield
          USING l_longfield CHANGING l_alv_fieldcat.
      ENDIF." l_longfield ca '-'.
    ELSE.

* No Help-ID: Use Fieldname as text
      l_alv_fieldcat-seltext_s =
      l_alv_fieldcat-seltext_m =
      l_alv_fieldcat-seltext_l =
      l_alv_fieldcat-reptext_ddic =
      <nameinfo>-name.
    ENDIF." sy-subrc                      = 0.

* Starting 4.7: get edit mask
    IF NOT <typeinfo>-idx_edit_mask IS INITIAL.
      READ TABLE l_desc-names INDEX <typeinfo>-idx_edit_mask
        ASSIGNING <nameinfo>.
      l_alv_fieldcat-edit_mask            = <nameinfo>-name.
      IF NOT <nameinfo>-continue IS INITIAL.
        ADD 1 TO <typeinfo>-idx_edit_mask.
        READ TABLE l_desc-names INDEX <typeinfo>-idx_edit_mask
          ASSIGNING <nameinfo>.
        CONCATENATE
          l_alv_fieldcat-edit_mask
          <nameinfo>-name
          INTO l_alv_fieldcat-edit_mask.
      ENDIF." not <nameinfo>-continue IS INITIAL.
    ENDIF." not <typeinfo>-IDX_EDIT_MASK is initial.

* assign length, output length and decimals
    l_alv_fieldcat-intlen                 = <typeinfo>-length.
    l_alv_fieldcat-outputlen              = <typeinfo>-output_length.
    l_alv_fieldcat-decimals_out           = <typeinfo>-decimals.
    l_alv_fieldcat-inttype                = <typeinfo>-type.
    APPEND l_alv_fieldcat TO pt_alv_fieldcat.
    CLEAR:  "prevent anything 2 B  taken for subsequent fields
      l_alv_fieldcat.
  ENDLOOP." at l_desc-types where not IDX_NAME is in initial.
ENDFORM.                    " ALV_FIELDCAT_FOR_ITAB

*&---------------------------------------------------------------------
*&      Form  get_rollname_4_tabfield
*&---------------------------------------------------------------------
*       Get Data                          type for Table field
*----------------------------------------------------------------------
FORM get_rollname_4_tabfield
  USING    p_fname                        TYPE fname
  CHANGING p_alv_fieldcat                 TYPE slis_fieldcat_alv.
  FIELD-SYMBOLS:
    <dfies>                               TYPE dfies.
  DATA:
    l_tabname                             TYPE tabname,
     lt_dfies                             TYPE TABLE OF dfies,
    l_fieldname                           TYPE fieldname.
  SPLIT p_fname AT '-'
    INTO l_tabname l_fieldname.
  CLEAR p_alv_fieldcat-rollname.
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      tabname                             = l_tabname
      fieldname                           = l_fieldname
*   LANGU                                 = SY-LANGU
*   LFIELDNAME                            = ' '
*   ALL_TYPES                             = ' '
* IMPORTING
*   X030L_WA             =
*   DDOBJTYPE            =
*   DFIES_WA             =
*   LINES_DESCR          =
   TABLES
     dfies_tab                            =  lt_dfies
*   FIXED_VALUES         =
   EXCEPTIONS
     not_found                            = 1
     internal_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.
  ELSE.
    READ TABLE   lt_dfies ASSIGNING <dfies> INDEX 1.
    p_alv_fieldcat-rollname               = <dfies>-rollname.
* Und wenn keinerlei Twexte gepflegt sind?
    IF <dfies>-reptext IS INITIAL AND
       <dfies>-scrtext_s IS INITIAL AND
       <dfies>-scrtext_m IS INITIAL AND
       <dfies>-scrtext_l IS INITIAL.
* No Text: Use Fieldname as text
      p_alv_fieldcat-seltext_s =
      p_alv_fieldcat-seltext_m =
      p_alv_fieldcat-seltext_l =
      p_alv_fieldcat-reptext_ddic =
      p_alv_fieldcat-fieldname.
    ENDIF." <dfies>-reptext IS INITIAL AND
  ENDIF.
ENDFORM.                    " get_rollname_4_tabfield

Regards,

Clemens

Former Member
0 Kudos

Hi,

check the SLIS development class for examples.

Regards

dhorions
Contributor
0 Kudos

[Removed by moderator.]

Then you will see you were not the first to think of asking this question here.

Former Member
0 Kudos

Yes, I got the correct answer.