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: 

ALV Report.

Former Member
0 Kudos
80

HI,

I have 2 tables marc, and makt and from marc i have to take werks as parameter

and from makt we have select options matnr and maktx, then i have to show that option on a single alv report. I am having problem with the fetching of data and displaying. Does anybody have a program for this.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
49

Hi,

here it is your program....


REPORT test.

TABLES:
marc,
makt.
DATA: BEGIN OF imat OCCURS 100,
matnr LIKE marc-matnr, "Material number
maktx LIKE makt-maktx, "Material short text
END OF imat.

DATA i_repid LIKE sy-repid.
DATA i_lines LIKE sy-tabix.

TYPE-POOLS: slis.
DATA int_fcat TYPE slis_t_fieldcat_alv.

PARAMETERS : p_werks LIKE marc-werks.
SELECT-OPTIONS: s_matnr FOR marc-matnr.

START-OF-SELECTION.

  SELECT marc~matnr makt~maktx INTO CORRESPONDING FIELDS OF
  TABLE imat FROM marc INNER JOIN makt ON
  marc~matnr EQ makt~matnr WHERE marc~werks EQ p_werks
  AND marc~matnr IN s_matnr.

* Check if material was found
  CLEAR i_lines.
  DESCRIBE TABLE imat LINES i_lines.
  IF i_lines LT 1.
*   Using hardcoded write here for easy upload
    WRITE: /
    'No materials found.'.
    EXIT.
  ENDIF.

END-OF-SELECTION.
* Store report name
  i_repid = sy-repid.

* Create Fieldcatalogue from internal table
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = i_repid
      i_internal_tabname     = 'IMAT'  "capital letters!
      i_inclname             = i_repid
    CHANGING
      ct_fieldcat            = int_fcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

  IF sy-subrc <> 0.
    WRITE: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = i_repid
      it_fieldcat        = int_fcat
      i_save             = 'A'
    TABLES
      t_outtab           = imat
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

  IF sy-subrc <> 0.
    WRITE: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
  ENDIF.

2 REPLIES 2

Former Member
0 Kudos
49

Hi,

select matnr werks from marc into table itab1.

select matnr maktx from makt into table itab2 for all entries in itab1 where matnr = itab1-matnr.

loop at itab1 into wa1.
 wa_final-matnr = wa1-matnr.
 wa_final-werks = wa1-werks.
 read table itab2 into wa2 with key matnr = wa1-matnr.
 if sy-subrc = 0.
  wa_final-maktx = wa2-maktx.
 endif.
 append wa_final to itab_final.
 clear wa_final.
endloop.
loop at final_itab to wa_final.
 write: wa_final-matnr, wa_final-werks, wa_final-maktx.
endloop.

FOR ALV:

build a field catalog with all the required fields

Use FM REUSE_ALV_GRID_DISPLAY, pass final internal table and field catalog.

<b>Reward points if it helps,</b>

Satish

Message was edited by:

Satish Panakala

Former Member
0 Kudos
50

Hi,

here it is your program....


REPORT test.

TABLES:
marc,
makt.
DATA: BEGIN OF imat OCCURS 100,
matnr LIKE marc-matnr, "Material number
maktx LIKE makt-maktx, "Material short text
END OF imat.

DATA i_repid LIKE sy-repid.
DATA i_lines LIKE sy-tabix.

TYPE-POOLS: slis.
DATA int_fcat TYPE slis_t_fieldcat_alv.

PARAMETERS : p_werks LIKE marc-werks.
SELECT-OPTIONS: s_matnr FOR marc-matnr.

START-OF-SELECTION.

  SELECT marc~matnr makt~maktx INTO CORRESPONDING FIELDS OF
  TABLE imat FROM marc INNER JOIN makt ON
  marc~matnr EQ makt~matnr WHERE marc~werks EQ p_werks
  AND marc~matnr IN s_matnr.

* Check if material was found
  CLEAR i_lines.
  DESCRIBE TABLE imat LINES i_lines.
  IF i_lines LT 1.
*   Using hardcoded write here for easy upload
    WRITE: /
    'No materials found.'.
    EXIT.
  ENDIF.

END-OF-SELECTION.
* Store report name
  i_repid = sy-repid.

* Create Fieldcatalogue from internal table
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = i_repid
      i_internal_tabname     = 'IMAT'  "capital letters!
      i_inclname             = i_repid
    CHANGING
      ct_fieldcat            = int_fcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

  IF sy-subrc <> 0.
    WRITE: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = i_repid
      it_fieldcat        = int_fcat
      i_save             = 'A'
    TABLES
      t_outtab           = imat
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

  IF sy-subrc <> 0.
    WRITE: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
  ENDIF.