Application Development and Automation 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: 
Read only

alv output

Former Member
0 Likes
1,126

HI,

i want print all infotypes in my sap system as alv report using abap objects.

so, below is code.

i am not getting the screen output.it is showing blank.

please help me

____________________________________________________

&----


*& Report ZKRISHNA_INFOTYPE

*&

&----


*&

*&

&----


REPORT ZKRISHNA_INFOTYPE.

TYPE-POOLS : SLIS.

    • Structure declaration for Infotypes for customer

TYPES : BEGIN OF TY_TABLE,

INFTY TYPE INFTY,

PNNNN TYPE PNNNN_D,

END OF TY_TABLE.

    • *Structure for infotype text

TYPES : BEGIN OF TY_ITEXT,

INFTY TYPE INFTY,

ITEXT TYPE INTXT,

SPRSL TYPE SPRSL,

END OF TY_ITEXT.

    • *Structure for output display

TYPES : BEGIN OF TY_OUTPUT,

INFTY TYPE INFTY,

ITEXT TYPE INTXT,

PNNNN TYPE PNNNN_D,

END OF TY_OUTPUT.

    • *internal table and work area declarations

DATA : IT_TABLE TYPE STANDARD TABLE OF TY_TABLE INITIAL SIZE 0,

IT_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT INITIAL SIZE 0,

IT_ITTEXT TYPE STANDARD TABLE OF TY_ITEXT INITIAL SIZE 0,

WA_TABLE TYPE TY_TABLE,

WA_OUTPUT TYPE TY_OUTPUT,

WA_ITTEXT TYPE TY_ITEXT.

    • *Data declarations for ALV

DATA: C_CCONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER, "Custom container object

C_ALVGD TYPE REF TO CL_GUI_ALV_GRID, "ALV grid object

IT_FCAT TYPE LVC_T_FCAT, "Field catalogue

IT_LAYOUT TYPE LVC_S_LAYO. "Layout

INITIALIZATION.

START-OF-SELECTION.

**select the infotypes maintained

SELECT INFTY

PNNNN

FROM T582A

INTO TABLE IT_TABLE.

***Select the infotype texts

IF IT_TABLE[] IS NOT INITIAL.

SELECT ITEXT

INFTY

SPRSL

FROM T582S

INTO CORRESPONDING FIELDS OF TABLE IT_ITTEXT

FOR ALL ENTRIES IN IT_TABLE

WHERE INFTY = IT_TABLE-INFTY

AND SPRSL = 'EN'.

ENDIF.

***Appending the data to the internal table of ALV output

LOOP AT IT_TABLE INTO WA_TABLE.

WA_OUTPUT-INFTY = WA_TABLE-INFTY.

WA_OUTPUT-PNNNN = WA_TABLE-PNNNN.

    • * For texts

READ TABLE IT_ITTEXT INTO WA_ITTEXT WITH KEY INFTY = WA_TABLE-INFTY.

WA_OUTPUT-ITEXT = WA_ITTEXT-ITEXT.

APPEND WA_OUTPUT TO IT_OUTPUT.

CLEAR WA_OUTPUT.

ENDLOOP.

    • * Calling the ALV screen with custom container

CALL SCREEN 0600.

    • *On this statement double click it takes you to the screen painter SE51.

      • *ENTER THE ATTRIBUTES

*Create a Custom container and name it CC_CONT and OK code as OK_CODE.

*Save check and Activate the screen painter.

*Now a normal screen with number 600 is created which holds the ALV grid.

  • PBO of the actual screen , Here we can give a title and customized menus

&----


*& Module STATUS_0600 OUTPUT

&----


  • text

----


MODULE STATUS_0600 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0600 OUTPUT

        • calling the PBO module ALV_GRID.

&----


*& Module ALV_GRID OUTPUT

&----


  • text

----


MODULE ALV_GRID OUTPUT.

**creating custom container instance

CREATE OBJECT C_CCONT

EXPORTING

  • PARENT =

CONTAINER_NAME = 'CC_CONT'

  • STYLE =

  • LIFETIME = LIFETIME_DEFAULT

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_ERROR = 2

CREATE_ERROR = 3

LIFETIME_ERROR = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5

OTHERS = 6

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**creating ALV grid instance

CREATE OBJECT C_ALVGD

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

I_PARENT = C_CCONT

  • I_APPL_EVENTS = SPACE

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

  • I_FCAT_COMPLETE = space

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

      • SET FIELD FOR ALV

PERFORM ALV_BUILD_FIELDCAT.

      • Set ALV attributes FOR LAYOUT

PERFORM ALV_REPORT_LAYOUT.

CHECK NOT C_ALVGD IS INITIAL.

    • * Call ALV GRID

CALL METHOD C_ALVGD->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = IT_LAYOUT

CHANGING

IT_OUTTAB = IT_OUTPUT

IT_FIELDCATALOG = IT_FCAT

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDMODULE. " ALV_GRID OUTPUT

&----


*& Form alv_build_fieldcat

&----


  • text

----


  • <--P_IT_FCAT text

----


FORM ALV_BUILD_FIELDCAT.

DATA LV_FLDCAT TYPE LVC_S_FCAT.

CLEAR LV_FLDCAT.

LV_FLDCAT-ROW_POS = '1'.

LV_FLDCAT-COL_POS = '1'.

LV_FLDCAT-FIELDNAME = 'INFTY'.

LV_FLDCAT-TABNAME = 'IT_OUTPUT'.

LV_FLDCAT-OUTPUTLEN = 8.

LV_FLDCAT-SCRTEXT_M = 'Infotype'.

LV_FLDCAT-ICON = 'X'.

APPEND LV_FLDCAT TO IT_FCAT.

CLEAR LV_FLDCAT.

LV_FLDCAT-ROW_POS = '1'.

LV_FLDCAT-COL_POS = '2'.

LV_FLDCAT-FIELDNAME = 'PNNNN'.

LV_FLDCAT-TABNAME = 'IT_OUTPUT'.

LV_FLDCAT-OUTPUTLEN = 15.

LV_FLDCAT-SCRTEXT_M = 'Structure'.

LV_FLDCAT-ICON = ''.

APPEND LV_FLDCAT TO IT_FCAT.

CLEAR LV_FLDCAT.

LV_FLDCAT-ROW_POS = '1'.

LV_FLDCAT-COL_POS = '3'.

LV_FLDCAT-FIELDNAME = 'ITEXT'.

LV_FLDCAT-TABNAME = 'IT_OUTPUT'.

LV_FLDCAT-OUTPUTLEN = 60.

LV_FLDCAT-SCRTEXT_M = 'Description'.

LV_FLDCAT-ICON = ''.

APPEND LV_FLDCAT TO IT_FCAT.

CLEAR LV_FLDCAT.

ENDFORM. " alv_build_fieldcat

&----


*& Form alv_report_layout

&----


  • text

----


  • <--P_IT_LAYOUT text

----


FORM ALV_REPORT_LAYOUT.

IT_LAYOUT-CWIDTH_OPT = 'X'.

IT_LAYOUT-ZEBRA = 'X'.

ENDFORM. " alv_report_layout

  • PAI module of the screen created. In case we use an interactive ALV or

*for additional functionalities we can create OK codes

*and based on the user command we can do the coding.

&----


*& Module USER_COMMAND_0600 INPUT

&----


  • text

----


MODULE USER_COMMAND_0600 INPUT.

HI,

i want print all infotypes in my sap system as alv report using abap objects.

so, below is code.

i am not getting the screen output.it is showing blank.

please help me

____________________________________________________

&----


*& Report ZKRISHNA_INFOTYPE

*&

&----


*&

*&

&----


REPORT ZKRISHNA_INFOTYPE.

TYPE-POOLS : SLIS.

    • Structure declaration for Infotypes for customer

TYPES : BEGIN OF TY_TABLE,

INFTY TYPE INFTY,

PNNNN TYPE PNNNN_D,

END OF TY_TABLE.

    • *Structure for infotype text

TYPES : BEGIN OF TY_ITEXT,

INFTY TYPE INFTY,

ITEXT TYPE INTXT,

SPRSL TYPE SPRSL,

END OF TY_ITEXT.

    • *Structure for output display

TYPES : BEGIN OF TY_OUTPUT,

INFTY TYPE INFTY,

ITEXT TYPE INTXT,

PNNNN TYPE PNNNN_D,

END OF TY_OUTPUT.

    • *internal table and work area declarations

DATA : IT_TABLE TYPE STANDARD TABLE OF TY_TABLE INITIAL SIZE 0,

IT_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT INITIAL SIZE 0,

IT_ITTEXT TYPE STANDARD TABLE OF TY_ITEXT INITIAL SIZE 0,

WA_TABLE TYPE TY_TABLE,

WA_OUTPUT TYPE TY_OUTPUT,

WA_ITTEXT TYPE TY_ITEXT.

    • *Data declarations for ALV

DATA: C_CCONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER, "Custom container object

C_ALVGD TYPE REF TO CL_GUI_ALV_GRID, "ALV grid object

IT_FCAT TYPE LVC_T_FCAT, "Field catalogue

IT_LAYOUT TYPE LVC_S_LAYO. "Layout

INITIALIZATION.

START-OF-SELECTION.

**select the infotypes maintained

SELECT INFTY

PNNNN

FROM T582A

INTO TABLE IT_TABLE.

***Select the infotype texts

IF IT_TABLE[] IS NOT INITIAL.

SELECT ITEXT

INFTY

SPRSL

FROM T582S

INTO CORRESPONDING FIELDS OF TABLE IT_ITTEXT

FOR ALL ENTRIES IN IT_TABLE

WHERE INFTY = IT_TABLE-INFTY

AND SPRSL = 'EN'.

ENDIF.

***Appending the data to the internal table of ALV output

LOOP AT IT_TABLE INTO WA_TABLE.

WA_OUTPUT-INFTY = WA_TABLE-INFTY.

WA_OUTPUT-PNNNN = WA_TABLE-PNNNN.

    • * For texts

READ TABLE IT_ITTEXT INTO WA_ITTEXT WITH KEY INFTY = WA_TABLE-INFTY.

WA_OUTPUT-ITEXT = WA_ITTEXT-ITEXT.

APPEND WA_OUTPUT TO IT_OUTPUT.

CLEAR WA_OUTPUT.

ENDLOOP.

    • * Calling the ALV screen with custom container

CALL SCREEN 0600.

    • *On this statement double click it takes you to the screen painter SE51.

      • *ENTER THE ATTRIBUTES

*Create a Custom container and name it CC_CONT and OK code as OK_CODE.

*Save check and Activate the screen painter.

*Now a normal screen with number 600 is created which holds the ALV grid.

  • PBO of the actual screen , Here we can give a title and customized menus

&----


*& Module STATUS_0600 OUTPUT

&----


  • text

----


MODULE STATUS_0600 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0600 OUTPUT

        • calling the PBO module ALV_GRID.

&----


*& Module ALV_GRID OUTPUT

&----


  • text

----


MODULE ALV_GRID OUTPUT.

**creating custom container instance

CREATE OBJECT C_CCONT

EXPORTING

  • PARENT =

CONTAINER_NAME = 'CC_CONT'

  • STYLE =

  • LIFETIME = LIFETIME_DEFAULT

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_ERROR = 2

CREATE_ERROR = 3

LIFETIME_ERROR = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5

OTHERS = 6

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**creating ALV grid instance

CREATE OBJECT C_ALVGD

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

I_PARENT = C_CCONT

  • I_APPL_EVENTS = SPACE

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

  • I_FCAT_COMPLETE = space

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

      • SET FIELD FOR ALV

PERFORM ALV_BUILD_FIELDCAT.

      • Set ALV attributes FOR LAYOUT

PERFORM ALV_REPORT_LAYOUT.

CHECK NOT C_ALVGD IS INITIAL.

    • * Call ALV GRID

CALL METHOD C_ALVGD->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = IT_LAYOUT

CHANGING

IT_OUTTAB = IT_OUTPUT

IT_FIELDCATALOG = IT_FCAT

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDMODULE. " ALV_GRID OUTPUT

&----


*& Form alv_build_fieldcat

&----


  • text

----


  • <--P_IT_FCAT text

----


FORM ALV_BUILD_FIELDCAT.

DATA LV_FLDCAT TYPE LVC_S_FCAT.

CLEAR LV_FLDCAT.

LV_FLDCAT-ROW_POS = '1'.

LV_FLDCAT-COL_POS = '1'.

LV_FLDCAT-FIELDNAME = 'INFTY'.

LV_FLDCAT-TABNAME = 'IT_OUTPUT'.

LV_FLDCAT-OUTPUTLEN = 8.

LV_FLDCAT-SCRTEXT_M = 'Infotype'.

LV_FLDCAT-ICON = 'X'.

APPEND LV_FLDCAT TO IT_FCAT.

CLEAR LV_FLDCAT.

LV_FLDCAT-ROW_POS = '1'.

LV_FLDCAT-COL_POS = '2'.

LV_FLDCAT-FIELDNAME = 'PNNNN'.

LV_FLDCAT-TABNAME = 'IT_OUTPUT'.

LV_FLDCAT-OUTPUTLEN = 15.

LV_FLDCAT-SCRTEXT_M = 'Structure'.

LV_FLDCAT-ICON = ''.

APPEND LV_FLDCAT TO IT_FCAT.

CLEAR LV_FLDCAT.

LV_FLDCAT-ROW_POS = '1'.

LV_FLDCAT-COL_POS = '3'.

LV_FLDCAT-FIELDNAME = 'ITEXT'.

LV_FLDCAT-TABNAME = 'IT_OUTPUT'.

LV_FLDCAT-OUTPUTLEN = 60.

LV_FLDCAT-SCRTEXT_M = 'Description'.

LV_FLDCAT-ICON = ''.

APPEND LV_FLDCAT TO IT_FCAT.

CLEAR LV_FLDCAT.

ENDFORM. " alv_build_fieldcat

&----


*& Form alv_report_layout

&----


  • text

----


  • <--P_IT_LAYOUT text

----


FORM ALV_REPORT_LAYOUT.

IT_LAYOUT-CWIDTH_OPT = 'X'.

IT_LAYOUT-ZEBRA = 'X'.

ENDFORM. " alv_report_layout

  • PAI module of the screen created. In case we use an interactive ALV or

*for additional functionalities we can create OK codes

*and based on the user command we can do the coding.

&----


*& Module USER_COMMAND_0600 INPUT

&----


  • text

----


MODULE USER_COMMAND_0600 INPUT.

9 REPLIES 9
Read only

Former Member
0 Likes
1,088

Hi,

Which SAP GUI version are you using ?

Try it in GUI version 7.1

Read only

0 Likes
1,088

i am working on ecc 6.0

how do i know about version of gui

please tell me

Read only

0 Likes
1,088

Hi,

1. Check whether the Container name used in the report and

the one used in SE51 are same.

2. Check the GUI version of the SAP screen you are using.

When you click on the sap logon pad, you can view the

version on the pad.

Read only

Former Member
0 Likes
1,088

Check whether ur screen is active.

IF o_grid_container IS INITIAL.

    CREATE OBJECT o_grid_container
      EXPORTING
        container_name = 'CCONTAINER1'.

    CALL METHOD o_grid->set_table_for_first_display
      EXPORTING
        i_bypassing_buffer    =  space
        is_variant            =  ws_f_grid_disvar
        i_save                =  ws_c_grid_save
        is_layout             =  struct_grid_lset

      CHANGING
        it_outtab             =  i_grid_outs[]
        it_fieldcatalog       =  i_grid_fcat[]
        it_sort               =  i_sort_fcat. 

ENDIF....

Have you created the screen using CALL SCREEN 100.

In the screen painter have u created the Custom Container with the name mentione in ur program as CC_..

Read only

Former Member
0 Likes
1,088

Hi,

Check in debugging mode whether IT_OUTPUT table is holding the data or not at the time of passing it to the display function module.

Thanks & Regards,

Radha.

Read only

Former Member
0 Likes
1,088

Hi,

for a really neat and SAP recommended way of doing ALV grid use the cl_salv_table class if its available in your release.

data: r_alv       type ref to cl_salv_table,

      r_functions type ref to cl_salv_functions_list.

  • fill some output table ( i.e. xoutput )

try.

    cl_salv_table=>factory( importing r_salv_table = r_alv

                            changing  t_table      = xoutput ).

    r_functions = r_alv->get_functions( ).

    r_functions->set_all( ).

    r_alv->display( ).

  catch cx_salv_msg.

endtry.

You don't need to define a screen or a container ( although you can if you want ) and you dont need to create a fieldcat either.

Read only

Former Member
0 Likes
1,088

hi,

1) my sap logon pad shows 640

it is 6.4 v

2) i have checked the container's name.

it's correct and is in active state in se51

3) data is coming into table in debugging mode

Read only

0 Likes
1,088

Hi,

Are you getting any error or any warnings while you are executing your report? what are you getting exactly when you run your report?

If not Try and install SAP GUI version 7.1 and try to execute.

Regards,

Madan

Read only

0 Likes
1,088

hi,

Please check if the same codes are working on different client and on different system.

Thanks,

Sachin.