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

Cannot Get Material Description Data to Display

keega1
Participant
0 Likes
4,012

Hi All,

I really need some guidance. I've worked on this issue for a good 4 hours and have yet to produce results.

I'm having a difficult time getting the material description column to populate in my report. I've researched, tried, copied, flipped it upside down, backward, forward, and still cannot get it to work.

What am I doing wrong?

TABLES: MARA,
        MAKT,
        ZISELECTEXIG.

*& SELECTION SCREEN AND SELECT OPTIONS FOR USER INPUT

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME.
PARAMETERS: P_RAD1 RADIOBUTTON GROUP RAD DEFAULT 'X' USER-COMMAND flag, "/ SAP GUI
            P_RAD2 RADIOBUTTON GROUP RAD.                               "/ CDS View
SELECTION-SCREEN END OF BLOCK BLK1.

SELECT-OPTIONS: mats FOR mara-matnr OBLIGATORY.

TYPES:
BEGIN OF itab,
  matnr TYPE mara-matnr,
  matkl TYPE mara-matkl,
  meins TYPE mara-meins,
  mtart TYPE mara-mtart,
END OF itab.

*& Initialization of Events

INITIALIZATION.
*mats-low = ''.
*mats-high = ''.

APPEND mats.
AT SELECTION-SCREEN.
  IF mats-low = ' '.
    MESSAGE I000(ZKMESSAGE).
    ELSEIF mats-high = ' '.
      MESSAGE I001(ZKMESSAGE).
      ENDIF.

*& TOP OF PAGE EVENT

TOP-OF-PAGE.
WRITE: /20 'List:', SY-DBCNT CENTERED.
ULINE.
END-OF-PAGE.

TYPE-POOLS: slis.                               " SLIS contains all the ALV data types

*& Data Declaration

*DATA: it_mara     TYPE TABLE OF mara.

DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.

DATA: BEGIN OF it_mara OCCURS 0,
  matnr LIKE mara-matnr,
  maktx LIKE makt-maktx,
  meins LIKE mara-meins,
  mtart LIKE mara-mtart,
END OF it_mara.

*& START-OF-SELECTION

START-OF-SELECTION.

*Fetching data from database

IF P_RAD1 = 'X'.
*  SELECT mara~matnr, maktx, meins, mtart FROM mara
*      INNER JOIN makt on makt~matnr = mara~matnr
*      INTO TABLE @it_mara
*      WHERE matnr IN @mats.
    SELECT mara~matnr, maktx, meins, mtart FROM mara
      INTO TABLE @it_mara
      WHERE matnr IN @mats.
  ELSEIF P_RAD2 = 'X'.
    SELECT * FROM ZI_SELECTEXIG
      INTO TABLE @it_mara.
ENDIF.

INITIALIZATION.       "to set titlebar on selection screen

START-OF-SELECTION.  "to set it once list is displayed

   IF P_RAD1 = 'X'.
    sy-title = 'SAP GUI'.
      ELSE. P_RAD2 = 'X'.
      sy-title = 'CDS View'.
      ENDIF.

END-OF-SELECTION.

*      WRITE: /12 'Number of records returned:', SY-DBCNT CENTERED.
*CONCATENATE <STRING1> <STRING2> <STRING3>... INTO <STRING>.

*Build field catalog

  wa_fieldcat-fieldname  = 'MATNR'.             " Fieldname in the data table - Material Number
  wa_fieldcat-seltext_m  = 'Material Number'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

  wa_fieldcat-fieldname  = 'MAKTX'.             " Fieldname in the data table - Material Description
  wa_fieldcat-seltext_m  = 'Material Desc'.     " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

  wa_fieldcat-fieldname  = 'MEINS'.             " Fieldname in the data table - Base Unit of Measure
  wa_fieldcat-seltext_m  = 'Unit'.              " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

  wa_fieldcat-fieldname  = 'MTART'.             " Fieldname in the data table - Material
  wa_fieldcat-seltext_m  = 'Material Type'.    " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

*Pass data and field catalog to ALV function module to display ALV list

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_mara
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
1 ACCEPTED SOLUTION
Read only

Abdul_Waheed
Contributor
3,490

Dear keega

Text Table of MARA is MAKT.

Join MARA with MAKT to get material description as shown below.

SELECT mr~matnr, mk~maktx, mr~meins, mr~mtart FROM mara as mr inner join makt as mk on mr~matnr eq mk~matnr
      INTO TABLE @it_mara WHERE mr~matnr IN @mats.
7 REPLIES 7
Read only

sveabecker
Product and Topic Expert
Product and Topic Expert
0 Likes
3,490

Welcome and Thank you for visiting SAP Community to get answers to your questions. I would recommend adding a picture to your profile if you're hoping to connect with readers. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

Regards, Svea

SAP Community moderator


----- Stay up-to-date with SAP Community and subscribe to What's New today! -----
Read only

jakob_steen-petersen
Contributor
0 Likes
3,490

Hi Ingrid

First of all make sure you have data in your itab. And then i will suggest that you use SALV with this Class cl_salv_table

It is quite simple. Se program SALV_DEMO_TABLE_SIMPLE

Read only

jakob_steen-petersen
Contributor
0 Likes
3,490

By the way: you use this:

    SELECT mara~matnr, maktx, meins, mtart FROM mara
      INTO TABLE @it_mara
      WHERE matnr IN @mats.

What version of ERP are you in where MAKTX is included in table MARA? MAKTX is in table MAKT as you also tried with you marked out code....

Read only

Abdul_Waheed
Contributor
3,491

Dear keega

Text Table of MARA is MAKT.

Join MARA with MAKT to get material description as shown below.

SELECT mr~matnr, mk~maktx, mr~meins, mr~mtart FROM mara as mr inner join makt as mk on mr~matnr eq mk~matnr
      INTO TABLE @it_mara WHERE mr~matnr IN @mats.
Read only

0 Likes
3,490

Thank you, Abdul! I've not been exposed to using the tilde in select statements as yet, but this is awesome. The query does work now. Wondering if it can be used in CDS view? I will give it a shot.

Thanks again!

Read only

0 Likes
3,490

Yes. You can create CDS view. Example below for reference.

@AbapCatalog.sqlViewName: 'MATTEXT' 
@AbapCatalog.compiler.CompareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Material with description'
define view ZI_MaterialText as select from makt
inner join mara on makt.matnr = mara.matnr
{
key mara.matnr as MaterialNum,
makt.maktx as MaterialName
}
Read only

keega1
Participant
0 Likes
3,490

Hi Jakob,

Thank you for your response. I truly appreciate it.

Right now I'm trying ANYTHING to get this to work, hence the commented-out lines. It shouldn't be this difficult, but apparently, it is for me 🙂

I'm not entirely sure what version I am using. 760, I think.

I'll try your suggestion a little later and let you know.