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 First Program! Help Reqd

Former Member
0 Likes
1,251

Hello everyone,

This is sachin, New in ABAP and thus writing on this forum for some help/guidence.

I am trying to generate a ALV. Fetch some data from MARA and display it.

Code is syntactically correct and program runs. Not a dump but no data is displayed.

The code goes as follows. Seems like a minor mistake but I am not getting a way out of it.

===============CODE==========================

*&----


*

*& *

&----


& EG using customer control field *catalog *

*& *

*&----


REPORT Zsach_ALV3 .

*-- Global data definitions for ALV

*--- ALV Grid instance reference

DATA GRID1 TYPE REF TO cl_gui_alv_grid .

*--- Name of the custom control added on the screen

DATA G_CONTROL TYPE scrfname VALUE 'B1' .

*--- Custom container instance reference

DATA G_CUSTOM_CONTAINER TYPE REF TO cl_gui_custom_container .

*--- Field catalog table

DATA gt_fieldcat TYPE lvc_t_fcat .

*--- Layout structure

DATA gs_layout TYPE lvc_s_layo .

*

*

*--- Internal table holding list data

DATA : BEGIN OF gt_MARA OCCURS 0 ,

MATNR LIKE MARA-MATNR,

MBRSH LIKE MARA-MBRSH,

MTART LIKE MARA-MTART,

END OF gt_MARA .

SELECT MATNR MBRSH MTART up to 10 rows FROM MARA into TABLE GT_MARA.

CALL SCREEN 0100.

*----


  • MODULE PBO *OUTPUT *

----


----


*

MODULE PBO OUTPUT.

*MODULE STATUS_0100 OUTPUT.

*

IF G_CUSTOM_CONTAINER IS INITIAL.

  • OBJECT TO REPRESENT CONTAINER I.E CUSTOMER CONTROL

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTROL.

  • OBJECT FOR GRID TO BE PLACED IN CONTAINER

CREATE OBJECT GRID1

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout .

CALL METHOD GRID1->set_table_for_first_display

EXPORTING

is_layout = gs_layout

CHANGING

it_outtab = gt_MARA[]

it_fieldcatalog = gt_fieldcat .

ELSE .

CALL METHOD grid1->refresh_table_display .

ENDIF .

ENDMODULE.

FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .

DATA : LS_FCAT type lvc_s_fcat .

ls_fcat-fieldname = 'MATNR' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '18' .

ls_fcat-coltext = 'MATERIAL NO' .

ls_fcat-seltext = 'MATNR#' .

APPEND ls_fcat to pt_fieldcat .

CLEAR LS_FCAT.

ls_fcat-fieldname = 'MBRSH' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'MBRSH' .

ls_fcat-seltext = 'MBRSH ' .

APPEND ls_fcat to pt_fieldcat .

CLEAR LS_FCAT.

ls_fcat-fieldname = 'MTART' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'MTART' .

ls_fcat-seltext = 'MTART' .

APPEND ls_fcat to pt_fieldcat .

ENDFORM.

FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.

ps_layout-zebra = 'X' .

ps_layout-grid_title = 'MATERIALS' .

ps_layout-smalltitle = 'X' .

ENDFORM.

10 REPLIES 10
Read only

Former Member
0 Likes
1,178

Hi,

In ur code Pls call ALV function.

check this sample program

http://www.sapdevelopment.co.uk/reporting/alv/alvlist_code.htm

Regards,

Vijay

Read only

Former Member
0 Likes
1,178

Hi Sachin,

Module PBO output is not called from the screen and therefore nothng is displayed.

Replace the following code:

MODULE PBO OUTPUT.

*MODULE STATUS_0100 OUTPUT.

TO

*MODULE PBO OUTPUT.

MODULE STATUS_0100 OUTPUT.

Then it should work.

Regards,

Kris

Read only

Former Member
0 Likes
1,178

Hi,

In PBO

MODULE status_9001 OUTPUT.

IF G_CUSTOM_CONTAINER IS INITIAL

SET PF-STATUS 'ZSTATUS'.

SET TITLEBAR 'ZTITLE'.

Double click on the zstatus and create three option BACK, EXIT and CANC.

IF G_CUSTOM_CONTAINER IS INITIAL.

  • OBJECT TO REPRESENT CONTAINER I.E CUSTOMER CONTROL

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTROL.

  • OBJECT FOR GRID TO BE PLACED IN CONTAINER

CREATE OBJECT GRID1

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

ENDMODULE.

In PAI add these codes to set pf-status

DATA: i_return_code TYPE i .

CALL METHOD cl_gui_cfw=>dispatch

IMPORTING return_code = i_return_code.

save_ok = ok_code.

CASE save_ok.

WHEN 'BACK' OR 'END' OR 'CANC'.

PERFORM exit_program.

ENDCASE.

CLEAR save_ok.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form EXIT_PROGRAM

&----


  • text

----


FORM exit_program.

CALL METHOD G_CUSTOM_CONTAINER ->free.

CALL METHOD cl_gui_cfw=>flush.

IF sy-subrc NE 0.

  • Error in FLush

ENDIF.

LEAVE TO SCREEN 0.

ENDFORM. " EXIT_PROGRAM

U have refreshed the grid in PBO itself.

Do seperately.

Include this too.

Thanks & Regards,

Judith.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,178

Hi Sachin,

Hope you already created the screen 100 and placed custom container in screen 100

with name 'B1'.

Problem may be in flow logic of screen 100 you need to include the follwoing piece of code in PBO.

Module PBO.

Hope it helps.

If not,get back.

Read only

0 Likes
1,178

Hi,

I checked and got the output too for ur program

see the changes made

REPORT zzztest_1 .

Tables: mara.

*&----


*

*& *

&----


& EG using

*customer control field *catalog *

*& *

*&----


*-- Global data definitions for ALV

INCLUDE <icon>.

INCLUDE <symbol>.

CLASS cl_gui_cfw DEFINITION LOAD.

*--- ALV Grid instance reference

DATA GRID1 TYPE REF TO cl_gui_alv_grid .

*--- Name of the custom control added on the screen

DATA G_CONTROL TYPE scrfname VALUE 'B1' .

*--- Custom container instance reference

DATA G_CUSTOM_CONTAINER TYPE REF TO cl_gui_custom_container .

*--- Field catalog table

DATA gt_fieldcat TYPE lvc_t_fcat .

*--- Layout structure

DATA gs_layout TYPE lvc_s_layo .

*

DATA: save_ok TYPE sy-ucomm,

ok_code TYPE sy-ucomm.

ok_code = sy-ucomm.

*--- Internal table holding list data

DATA : BEGIN OF gt_MARA OCCURS 0 ,

MATNR LIKE MARA-MATNR,

MBRSH LIKE MARA-MBRSH,

MTART LIKE MARA-MTART,

END OF gt_MARA .

SELECT MATNR MBRSH MTART up to 10 rows FROM MARA into TABLE GT_MARA.

CALL SCREEN 0100.

*CALL METHOD grid1->refresh_table_display .

*

FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .

DATA : LS_FCAT type lvc_s_fcat .

ls_fcat-fieldname = 'MATNR' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '18' .

ls_fcat-coltext = 'MATERIAL NO' .

ls_fcat-seltext = 'MATNR#' .

APPEND ls_fcat to pt_fieldcat .

CLEAR LS_FCAT.

ls_fcat-fieldname = 'MBRSH' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'MBRSH' .

ls_fcat-seltext = 'MBRSH ' .

APPEND ls_fcat to pt_fieldcat .

CLEAR LS_FCAT.

ls_fcat-fieldname = 'MTART' .

ls_fcat-inttype = 'C' .

ls_fcat-outputlen = '10' .

ls_fcat-coltext = 'MTART' .

ls_fcat-seltext = 'MTART' .

APPEND ls_fcat to pt_fieldcat .

ENDFORM.

FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.

ps_layout-zebra = 'X' .

ps_layout-grid_title = 'MATERIALS' .

ps_layout-smalltitle = 'X' .

ENDFORM.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


module STATUS_0100 output.

*----


  • MODULE PBO *OUTPUT *

----


----


*

IF G_CUSTOM_CONTAINER IS INITIAL.

SET PF-STATUS 'ZSTATUS'.

SET TITLEBAR 'ZTITLE'.

  • OBJECT TO REPRESENT CONTAINER I.E CUSTOMER CONTROL

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTROL.

  • OBJECT FOR GRID TO BE PLACED IN CONTAINER

CREATE OBJECT GRID1

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

*----Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout .

CALL METHOD GRID1->set_table_for_first_display

EXPORTING

is_layout = gs_layout

CHANGING

it_outtab = gt_MARA[]

it_fieldcatalog = gt_fieldcat .

ENDIF.

endmodule. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


module USER_COMMAND_0100 input.

DATA: i_return_code TYPE i .

CALL METHOD cl_gui_cfw=>dispatch

IMPORTING return_code = i_return_code.

save_ok = ok_code.

CASE save_ok.

WHEN 'BACK' OR 'END' OR 'CANC'.

PERFORM exit_program.

ENDCASE.

CLEAR save_ok.

endmodule. " USER_COMMAND_0100 INPUT

************************************

FORM exit_program.

CALL METHOD G_CUSTOM_CONTAINER->free.

CALL METHOD cl_gui_cfw=>flush.

IF sy-subrc NE 0.

  • Error in FLush

ENDIF.

LEAVE TO SCREEN 0.

ENDFORM. " EXIT_PROGRAM

Thanks & Regards,

Judith.

Read only

nishanthbhandar
Contributor
0 Likes
1,178

Hi Sachin,

When creating an ALV it is very important to understand the flow of data and the communication parameters between your module pool program and the screen.There is nothing wrong with your code.In the PBO event of the screen the ALV grid display has to be called otherwise you will be displayed with a blank screen on executing the program.Call the PBO module present in your program at the screen level and the ALV will display properly with the data.

Read only

Former Member
0 Likes
1,178

Hello Everybody! Thanks a lot for such a prompt reply from everyone.

Now further to the discussion, I have called the following functions from PBO of screen 100.

PERFORM prepare_field_catalog CHANGING gt_fieldcat .

PERFORM prepare_layout CHANGING gs_layout .

perform display_alv_report.

===================

In form display_alv_report.

I have called reuse_alv_grid_display.

Now when I check for syst errors, I am getting importing is expected and not exporting.

If I change to importing, I get exporting is expected.

Here is the code ::

=======================================

form display_alv_report.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

TABLES

T_OUTTAB = gt_MARA

.

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.

==============================

Read only

0 Likes
1,178

Hi,

In PBO it's enough to write the following line for your previous code.

Module PBO.

If your problem is solved,close this thread.

Message was edited by: Jayanthi Jayaraman

Read only

0 Likes
1,178

Hi,

Try copy and paste the whole code i replied.

Goto screen 100 and in the flowlogic uncomment the modules and try executing the program, u will get the output.

Note: If any one the above replies solved or helpful then reward points and close the thread.

<b>Please Close the thread if ur problem got solved.</b>

Message was edited by: Judith Jessie Selvi

Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
1,178

Hi Sachin

You can make use of the tutorial <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/an%20easy%20reference%20for%20alv%20grid%20control.pdf">"An Easy Reference for ALV Grid Control"</a>.

As a second point, since you are new to this forum, let me introduce the portion of sytematic about assigning points. Not strictly relating with this specific thread, you can assign points to posts you find helpful while solving your questions. You can assign points by using the points scala at the left of each post. By giving a 10-point or choosing "Solved by own" at the left of your original post, you sign the thread as closed which makes SDNers save their time.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>