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

Abap List Viewer

Former Member
0 Likes
1,242

I need the code and documentation for creating ALV list , as this is the first time I am creating the ALV reports and I need the clear picture of field catalog.

If u provide the clear documentation for me it will be very helpful and some dummy ALV list reports.

Further from mm there are around 5-6 reports to be generated and working with BDC's for changing of format of purchase order/purchase requisition and adding of two filed's .

please give me the code on BDC's so that I can start analyzing it.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,170

Hi ravi,

1. why field catalogue.

2. Bcos, when we want to display alv,

the alv program is passed just the internal table.

The alv fucntinoality should also

know what are the FIELD NAMES, their length

so that it can display these texts

in the header of the internal table.

3 For this, there is a FM,

in which we pass our internal table

and it returns a internal table (field catalog table)

which contains the required information

for all the field in the internal table.

4. Sample code :

REPORT abc.

TYPE-POOLS : slis.

*----


Data

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE t001.

DATA : END OF itab.

DATA : alvfc TYPE slis_t_fieldcat_alv.

*----


Select

SELECT * FROM t001 INTO TABLE itab.

*------- Field Catalogue

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'ITAB'

i_inclname = sy-repid

CHANGING

ct_fieldcat = alvfc

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

*----


Display

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

it_fieldcat = alvfc

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

OTHERS = 2.

regards,

amit m.

I need the code and documentation for creating ALV list , as this is the first time I am creating the ALV reports and I need the clear picture of field catalog.

If u provide the clear documentation for me it will be very helpful and some dummy ALV list reports.

Further from mm there are around 5-6 reports to be generated and working with BDC's for changing of format of purchase order/purchase requisition and adding of two filed's .

please give me the code on BDC's so that I can start analyzing it.

7 REPLIES 7
Read only

Former Member
0 Likes
1,171

Hi ravi,

1. why field catalogue.

2. Bcos, when we want to display alv,

the alv program is passed just the internal table.

The alv fucntinoality should also

know what are the FIELD NAMES, their length

so that it can display these texts

in the header of the internal table.

3 For this, there is a FM,

in which we pass our internal table

and it returns a internal table (field catalog table)

which contains the required information

for all the field in the internal table.

4. Sample code :

REPORT abc.

TYPE-POOLS : slis.

*----


Data

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE t001.

DATA : END OF itab.

DATA : alvfc TYPE slis_t_fieldcat_alv.

*----


Select

SELECT * FROM t001 INTO TABLE itab.

*------- Field Catalogue

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'ITAB'

i_inclname = sy-repid

CHANGING

ct_fieldcat = alvfc

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

*----


Display

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

it_fieldcat = alvfc

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

OTHERS = 2.

regards,

amit m.

Read only

Former Member
0 Likes
1,170

hi Ravi,

these ARE SOME links on ALV

<a href="http://www.sapdevelopment.co.uk/ reporting/alv/alvgrid_basic.htm">Basiv alv list</a>

<a href="http://www.sap-img.com/abap/what-is-alv-programming.htm">What is ALV</a>

<a href="http://www.sapgenie.com/abap/controls/alvgrid.htm">ALV Report</a>

<a href="http://www.sappoint.com/ppt/alv.ppt">ALV ppt</a>

lot more are avaliable..

if you want more.. on BDC also.. give your mail id..

regards

satesh

Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,170

REPORT z01_alv1 .

--


Data declarations--

TYPE-POOLS slis.

TABLES : spfli.

DATA : it_sflight LIKE STANDARD TABLE OF sflight WITH HEADER LINE.

DATA : it_spfl LIKE STANDARD TABLE OF spfli WITH HEADER LINE.

DATA : it_fldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

                • for creating secondary list

DATA : it_sflight1 LIKE STANDARD TABLE OF sflight WITH HEADER LINE.

DATA : it_fldcat1 TYPE slis_t_fieldcat_alv WITH HEADER LINE.

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

DATA : it_event TYPE slis_t_event WITH HEADER LINE.

DATA : it_keyinfo TYPE slis_keyinfo_alv.

                            • for top of page in Grid.

DATA : it_top TYPE slis_t_listheader,

wa_top LIKE LINE OF it_top.

*set pf-status 'ztest'.

----


SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE it_spfl.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_sflight.

LOOP AT it_spfl.

READ TABLE it_sflight WITH KEY connid = it_spfl-connid.

IF sy-subrc NE 0.

DELETE it_spfl.

ENDIF.

ENDLOOP.

*

                                      • FOR POPULATING FIELD CATLOG

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = 'Z01_ALV1'

  • i_internal_tabname = 'IT_SPFL'

i_structure_name = 'SPFLI'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_INCLNAME =

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

ct_fieldcat = it_fldcat[]

  • 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.

                                                      • FOR POPULATING EVENTS

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

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.

CASE it_event-name.

WHEN 'TOP_OF_PAGE'.

it_event-form = 'TOP_PAGE'.

WHEN 'END_OF_LIST'.

it_event-form = 'END_LIST'.

WHEN 'PF_STATUS_SET'.

it_event-form = 'PF_STATUS_SET'.

ENDCASE.

MODIFY it_event TRANSPORTING form.

ENDLOOP.

*

                                                      • FOR CREATING SIMPLE LIST

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = 'Z01_ALV1'

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

I_STRUCTURE_NAME = 'SPFLI'

  • IS_LAYOUT =

it_fieldcat = it_fldcat[]

  • 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_spfl

  • 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.

*

*

it_keyinfo-header01 = 'CARRID'.

it_keyinfo-item01 = 'CARRID'.

it_keyinfo-header02 = 'CONNID'.

it_keyinfo-item02 = 'CONNID'.

it_keyinfo-header03 = ' '.

it_keyinfo-item03 = 'FLDATE'.

                                                  • FOR CREATING HIERSEQ_LIST

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_callback_program = 'Z01_ALV1'

i_tabname_header = 'IT_SPFL'

i_tabname_item = 'IT_SFLIGHT'

i_structure_name_header = 'SPFLI'

i_structure_name_item = 'SFLIGHT'

is_keyinfo = it_keyinfo

TABLES

t_outtab_header = it_spfl

t_outtab_item = it_sflight.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

                                                  • FOR CREATING GRID DISPLAY

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = 'Z01_ALV1'

i_callback_pf_status_set = 'PF_STATUS_SET'

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = '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_fldcat[]

  • 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

  • IT_ALV_GRAPHICS =

  • IT_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = it_spfl

  • 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.

----


  • FORM user_command *

----


  • ........ *

----


  • --> UCOMM *

  • --> SELFIELD *

----


FORM user_command USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

CASE ucomm.

WHEN '&IC1'.

SELECT * FROM sflight

INTO CORRESPONDING FIELDS OF

TABLE it_sflight1

WHERE CARRID = selfield-value.

                                                                    • FOR CREATING SECONDARY LIST

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = 'Z01_ALV1'

i_internal_tabname = 'IT_SFLIGHT1'

i_structure_name = 'SFLIGHT'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_INCLNAME =

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

ct_fieldcat = it_fldcat1[]

  • 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.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = 'Z01_ALV1'

  • i_callback_pf_status_set = 'PF_STATUS_SET'

  • i_callback_user_command = '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_fldcat1[]

  • 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

  • IT_ALV_GRAPHICS =

  • IT_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = it_sflight1

  • 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.

WRITE 😕 'sdfs'.

WHEN 'MORE'.

WRITE 😕 'More'. "sy-lisel.

  • write sy-lsind.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDFORM.

*----


    • FORM pf_status_set *

*----


    • ........ *

*----


    • --> EXTAB *

*----


FORM pf_status_set USING extab TYPE slis_t_extab.

SET PF-STATUS 'SREPTASH' .

ENDFORM.

----


  • FORM top_page *

----


  • ........ *

----


FORM top_page.

WRITE /: 'This is to test top of page'.

NEW-LINE.

SKIP TO LINE 5.

WRITE : 'ALV List'.

ENDFORM.

*

----


  • FORM end_list *

----


  • ........ *

----


FORM end_list.

WRITE : 'This is to test End of List'.

NEW-LINE.

SKIP 5.

WRITE :'ALV List'.

ENDFORM.

                    • for creating field catlog manually

  • CLEAR it_fieldcat.

  • REFRESH it_fieldcat.

  • CLEAR wrk_fieldcat.

*

  • wrk_fieldcat-col_pos = 1.

  • wrk_fieldcat-tabname = 'IT_PRINTMASTER'.

  • wrk_fieldcat-fieldname = 'DOCNO'.

  • wrk_fieldcat-seltext_m = 'PROPOSAL'.

    • WRK_FIELDCAT-EMPHASIZE = 'C410'.

    • WRK_FIELDCAT-OUTPUTLEN = '25'.

  • wrk_fieldcat-hotspot = 'X'.

  • APPEND wrk_fieldcat TO it_fieldcat.

  • CLEAR wrk_fieldcat.

*

  • wrk_fieldcat-col_pos = 2.

  • wrk_fieldcat-tabname = 'IT_PRINTMASTER'.

  • wrk_fieldcat-fieldname = 'PENDNO'.

  • wrk_fieldcat-seltext_m = 'End No'.

    • WRK_FIELDCAT-EMPHASIZE = 'C410'.

    • WRK_FIELDCAT-OUTPUTLEN = '25'.

  • wrk_fieldcat-hotspot = 'X'.

  • APPEND wrk_fieldcat TO it_fieldcat.

  • CLEAR wrk_fieldcat.

**

FORM top_of_page.

  • WRITE : 'POLICY REGISTER : LIVE POLICIES' .

wa_top-typ = 'H'.

wa_top-info = 'POLICY REGISTER : LIVE POLICIES'.

APPEND wa_top TO it_top .

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = it_top

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

REFRESH it_top.

ENDFORM. "top_OF_page

<b>************BDC*****************************</b>

REPORT ZMM_BDC_CONFIRMATION_UPLOAD

NO STANDARD page heading

message-id ZV.

include bdcrecx1.

TABLES: EKPO,EKES.

data : begin of t_itab occurs 0,

ebeln like ekko-ebeln,

ebelp like ekpo-ebelp,

bstae like ekpo-bstae,

ebtyp like ekes-ebtyp ,

eindt(10),

menge like ekes-menge,

xblnr like ekes-xblnr,

end of t_itab.

DATA: BEGIN OF record,

ebeln type ebeln,

ebelp type ebelp,

END OF record.

      • creating an internal table containg the Items***

DATA : t_tab LIKE record OCCURS 0 WITH HEADER LINE.

PARAMETER : filename LIKE rlgrap-filename OBLIGATORY.

***declaring temporary variables

DATA :

v_cnt(2) TYPE n,

v_bst(2) TYPE n,

v_bn type i,

v_bstpo(25),

v_ebtyp(25),

v_menge(25),

v_eeind(25),

v_xblnr(25),

v_xblnr1(25),

v_ebelp(2) type n,

v_ebelpt(2),

v_menge1(11),

v_ebt type i,

v_vebtyp like ekes-ebtyp,

V_EB(2) TYPE N,

v_tcselflag(40),

v_tem(2) type n,

v_file type string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

field_name = filename

CHANGING

file_name = filename.

START-OF-SELECTION.

v_file = filename.

***uploading from flat file into internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = t_itab.

loop at t_itab.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = t_itab-ebeln

IMPORTING

OUTPUT = t_itab-ebeln

.

modify t_itab.

clear t_itab.

endloop.

      • checking the item numbers in the flat file.

loop at t_itab.

select ebeln ebelp from ekpo into table t_tab

where ebeln = t_itab-ebeln.

endloop.

IF t_tab[] is not initial.

perform open_group.

***looping at purchase order level.

LOOP at t_itab.

clear v_bn.

clear v_ebt.

perform bdc_dynpro using 'SAPMM06E' '0105'.

perform bdc_field using 'BDC_CURSOR'

'RM06E-BSTNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RM06E-BSTNR'

t_itab-ebeln.

**Changing alphanumeric fields and quantity fields to character type**

v_ebelp = t_itab-ebelp.

clear v_ebelpt.

v_menge1 = t_itab-menge.

v_ebelpt = v_ebelp.

**End Of Changing**

**Checking for the exact number of the item**

loop at t_tab where ebeln = t_itab-ebeln.

if t_tab-ebelp = t_itab-ebelp.

exit.

else.

v_bn = v_bn + 1.

endif.

endloop.

v_bst = v_bn + 1.

**End Of Checking**

**Mapping items**

v_tem = 1.

CONCATENATE 'RM06E-BSTPO(' v_bst ')' INTO v_bstpo.

CONCATENATE 'RM06E-TCSELFLAG(' v_tem ')' INTO v_tcselflag.

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

v_bstpo.

perform bdc_field using 'BDC_OKCODE'

'=DETA'.

perform bdc_field using 'RM06E-EBELP'

v_ebelpt.

perform bdc_dynpro using 'SAPMM06E' '0111'.

perform bdc_field using 'BDC_CURSOR'

'EKPO-BSTAE'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

v_bstpo.

perform bdc_field using 'BDC_OKCODE'

'=BSTA'.

perform bdc_field using 'RM06E-EBELP'

v_ebelpt.

perform bdc_field using v_tcselflag

'X'.

**Checking weather Confirmation category already exists**

select ebtyp from ekes into v_vebtyp where ebelp =

t_itab-ebelp and ebeln = t_itab-ebeln.

endselect.

if sy-dbcnt > 0.

v_ebt = sy-dbcnt.

endif.

V_EB = V_EBT + 1.

**End Of Checking**

**For Line items**

CONCATENATE 'EKES-EBTYP(' v_eb ')' INTO v_ebtyp.

CONCATENATE 'EKES-MENGE(' v_eb ')' INTO v_menge.

CONCATENATE 'RM06E-EEIND(' v_eb ')' INTO v_eeind.

CONCATENATE 'EKES-XBLNR(' v_eb ')' INTO v_xblnr.

**End**

perform bdc_dynpro using 'SAPLEINB' '0200'.

perform bdc_field using 'BDC_CURSOR'

v_xblnr.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using v_ebtyp

t_itab-ebtyp.

perform bdc_field using v_eeind

t_itab-eindt.

perform bdc_field using v_menge

v_menge1.

perform bdc_field using v_xblnr

t_itab-xblnr.

**End Of Mappings**

perform bdc_transaction using 'ME22'.

ENDLOOP.

**End Of Purchase Order Loop**

perform close_group.

ELSE.

MESSAGE I083(zv).

ENDIF.

Message was edited by: Hymavathi Oruganti

Read only

Former Member
0 Likes
1,170

HI

try this code

<b>in which the field catalog will be generated automatically.</b>

TABLES : mara.

TYPE-POOLS : slis.

DATA: gs_layout TYPE slis_layout_alv,

ct_fieldcat TYPE slis_t_fieldcat_alv,

g_repid LIKE sy-repid,

temp_cat TYPE slis_fieldcat_alv,

header_alv TYPE slis_t_listheader,

header_alv_wa TYPE slis_listheader.

DATA : BEGIN OF it OCCURS 0,

matnr LIKE mara-matnr,

mtart LIKE mara-mtart,

maktx LIKE makt-maktx,

mbrsh LIKE mara-mbrsh,

matkl LIKE mara-matkl,

END OF it.

SELECT-OPTIONS: p_matnr FOR mara-matnr.

INITIALIZATION.

g_repid = sy-repid.

START-OF-SELECTION.

SELECT

amatnr amtart ambrsh amatkl b~maktx

FROM mara AS a

JOIN makt AS b ON amatnr = bmatnr

INTO CORRESPONDING FIELDS OF TABLE it

WHERE a~matnr IN p_matnr.

END-OF-SELECTION.

PERFORM field_catalog.

PERFORM change_catalog.

PERFORM alv_display.

*&----


*& Form field_catalog

*&----


FORM field_catalog .

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = g_repid

i_internal_tabname = 'IT'

i_inclname = g_repid

CHANGING

ct_fieldcat = ct_fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

ENDFORM. " field_catalog

*&----


*& Form change_catalog

*&----


FORM change_catalog .

LOOP AT ct_fieldcat INTO temp_cat.

temp_cat-key = ' '.

CASE temp_cat-fieldname.

WHEN 'MATNR'.

temp_cat-seltext_m = 'Material #'.

temp_cat-ddictxt = 'M'.

temp_cat-outputlen = 10.

WHEN 'MAKTX'.

temp_cat-seltext_m = 'Material Desc'.

temp_cat-ddictxt = 'M'.

temp_cat-outputlen = 40.

WHEN OTHERS.

CONTINUE.

ENDCASE.

MODIFY ct_fieldcat FROM temp_cat.

ENDLOOP.

gs_layout-zebra = 'X'.

ENDFORM. " change_catalog

*&----


*& Form alv_display

*&----


FORM alv_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid

is_layout = gs_layout

it_fieldcat = ct_fieldcat

i_save = 'A'

TABLES

t_outtab = it

EXCEPTIONS

program_error = 1

OTHERS = 2.

<b>

there is another method in which we have to create the field catalog.</b>

&----


*& Report ZALVSAMP

*&

&----


*&

*&

&----


REPORT ZALVSAMP.

.

*Table declaration

tables: vbak,vbap.

*internal table

data: begin of i_sales occurs 0,

vbeln like vbak-vbeln,

erdat like vbak-erdat,

audat like vbak-audat,

kunnr like vbak-kunnr,

vkorg like vbak-vkorg,

matnr like vbap-matnr,

netpr like vbap-netpr,

check type c,

end of i_sales.

type-pools: slis.

data: v_fieldcat type slis_fieldcat_alv,

gt_fieldcat type slis_t_fieldcat_alv,

gt_layout type slis_layout_alv,

gt_sort type slis_sortinfo_alv,

fieldcat like line of gt_fieldcat.

*Selection screen

parameters: p_vkorg like vbak-vkorg.

select-options: s_vbeln for vbak-vbeln.

*start of selection.

start-of-selection.

perform get_data.

perform fill_fieldcatalog.

perform write_data.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data .

select avbeln aerdat aaudat akunnr avkorg bmatnr b~netpr into

corresponding fields of table i_sales from vbak

as a inner join vbap as b on avbeln = bvbeln

where a~vkorg = p_vkorg and

a~vbeln in s_vbeln.

ENDFORM. " get_data

&----


*& Form write_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM write_data .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = sy-repid

  • IS_LAYOUT = gt_layout

IT_FIELDCAT = gt_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = 'X'

  • 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

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = i_sales

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

&----


*& Form fill_fieldcatalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fill_fieldcatalog .

sort i_sales by vbeln.

clear v_fieldcat.

v_fieldcat-col_pos = 1.

v_fieldcat-fieldname = 'CHECK'.

v_fieldcat-seltext_m = 'chek'.

v_fieldcat-checkbox = 'X'.

v_fieldcat-input = 'X'.

v_fieldcat-edit = 'X'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

v_fieldcat-col_pos = 2.

v_fieldcat-fieldname = 'VBELN'.

v_fieldcat-seltext_m = 'Sales Document'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

v_fieldcat-col_pos = 3.

v_fieldcat-fieldname = 'ERDAT'.

v_fieldcat-seltext_m = 'Creation Date'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

v_fieldcat-col_pos = 4.

v_fieldcat-fieldname = 'AUDAT'.

v_fieldcat-seltext_m = 'Document Date'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

v_fieldcat-col_pos = 5.

v_fieldcat-fieldname = 'KUNNR'.

v_fieldcat-seltext_m = 'Customer'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

v_fieldcat-col_pos = 6.

v_fieldcat-fieldname = 'VKORG'.

v_fieldcat-seltext_m = 'Sales Organization'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

v_fieldcat-col_pos = 7.

v_fieldcat-fieldname = 'MATNR'.

v_fieldcat-seltext_m = 'Material'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

v_fieldcat-col_pos = 8.

v_fieldcat-fieldname = 'NETPR'.

v_fieldcat-seltext_m = 'Net Value'.

append v_fieldcat to gt_fieldcat.

clear v_fieldcat.

endform.

Read only

Former Member
0 Likes
1,170

Hi Ravi

see this sample sample for BDC in which the data from presentation server is uploaded into MARA table through MM01

report ZKISHMMPRG

no standard page heading line-size 255.

include bdcrecx1.

parameters: dataset(132) lower case.

      • DO NOT CHANGE - the generated data section - DO NOT CHANGE ***

*

  • If it is nessesary to change the data section use the rules:

  • 1.) Each definition of a field exists of two lines

  • 2.) The first line shows exactly the comment

  • '* data element: ' followed with the data element

  • which describes the field.

  • If you don't have a data element use the

  • comment without a data element name

  • 3.) The second line shows the fieldname of the

  • structure, the fieldname must consist of

  • a fieldname and optional the character '_' and

  • three numbers and the field length in brackets

  • 4.) Each field must be type C.

*

      • Generated data section with specific formatting - DO NOT CHANGE ***

data: begin of record OCCURS 0,

  • data element: MATNR

MATNR_001(018),

  • data element: MBRSH

MBRSH_002(001),

  • data element: MTART

MTART_003(004),

  • data element: XFELD

KZSEL_01_004(001),

  • data element: MAKTX

MAKTX_005(040),

  • data element: MEINS

MEINS_006(003),

  • data element: MATKL

MATKL_007(009),

  • data element: SPART

SPART_008(002),

end of record.

      • End generated data section ***

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'D:\Personal\material.txt'

  • FILETYPE = 'DAT'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = RECORD

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

*perform open_dataset using dataset.

perform open_group.

loop at record.

*read dataset dataset into record.

*if sy-subrc <> 0. exit. endif.

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MTART'.

perform bdc_field using 'BDC_OKCODE'

'=AUSW'.

perform bdc_field using 'RMMG1-MATNR'

record-MATNR_001.

perform bdc_field using 'RMMG1-MBRSH'

record-MBRSH_002.

perform bdc_field using 'RMMG1-MTART'

record-MTART_003.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

record-KZSEL_01_004.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'MAKT-MAKTX'

record-MAKTX_005.

perform bdc_field using 'BDC_CURSOR'

'MARA-SPART'.

perform bdc_field using 'MARA-MEINS'

record-MEINS_006.

perform bdc_field using 'MARA-MATKL'

record-MATKL_007.

perform bdc_field using 'MARA-SPART'

record-SPART_008.

perform bdc_transaction using 'MM01'.

endloop.

perform close_group.

*perform close_dataset using dataset.

regards

kishore

reward if helpful

Read only

Former Member
0 Likes
1,170

HI

CHECK THE FOLLOWING LINKS

WHAT IS ALV PROGRAMMING?

<a href="http://www.sap-img.com/abap/what-is-alv-programming.htm">http://www.sap-img.com/abap/what-is-alv-programming.htm</a>

SIMPLE ALV REPORT

<a href="http://www.sapgenie.com/abap/code/abap28.htm">http://www.sapgenie.com/abap/code/abap28.htm</a>

OR

<a href="http://www.sap-basis-abap.com/sapab033.htm">http://www.sap-basis-abap.com/sapab033.htm</a>

FOR BDC PROGRAMMING

ABOUT BDC

<a href="http://www.sap-img.com/ab001.htm">http://www.sap-img.com/ab001.htm</a>

SAMPLE BDC PROGRAMS

<a href="http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm">http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm</a>

OR

<a href="http://www.sapdevelopment.co.uk/bdc/bdchome.htm">http://www.sapdevelopment.co.uk/bdc/bdchome.htm</a>

IF THESE FINDS USEFUL PLEASE REWARD POINTS

REGARDS

ANOOP

Read only

0 Likes
1,170

Hi ,

After store the data in IT_OUTPUT[].

type-pool : Slis

data : IT_FIELDCAT type SLIS_T_FIELDCAT_ALV,

IS_FIELDCAT type SLIS_FIELDCAT_ALV,

IS_LAYOUT type SLIS_LAYOUT_ALV.

*-- This Perform statement Is used to decribe the Field catalog--

refresh IT_FIELDCAT.

perform FIELDCAT_BUILD_F06 changing IT_FIELDCAT.

*-- This Perform statement Is used to describe the Layout--

clear IS_LAYOUT.

perform SET_LAYOUT_F07 changing IS_LAYOUT.

*--- Calling the Fulction Module to display alv grid -


call function 'REUSE_ALV_GRID_DISPLAY'

exporting

I_CALLBACK_PROGRAM = SY-REPID

IS_LAYOUT = IS_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

I_SAVE = C_A

tables

T_OUTTAB = IT_OUTPUT[]

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.

form FIELDCAT_BUILD_F06 changing PT_FIELDCAT

type SLIS_T_FIELDCAT_ALV.

clear IS_FIELDCAT.

IS_FIELDCAT-FIELDNAME = 'KUNNR'.

IS_FIELDCAT-REF_TABNAME = 'KNA1'.

append IS_FIELDCAT to PT_FIELDCAT.

endform.

form SET_LAYOUT_F07 changing PS_LAYOUT

type SLIS_LAYOUT_ALV.

PS_LAYOUT-ZEBRA = C_X.

PS_LAYOUT-COLWIDTH_OPTIMIZE = C_X.

endform. "SET_LAYOUT_F04

This Program Is very simple alv program and useful to you , If you feel that give me reward Points .

Regards,

Ranadheer