I’m starting the SAP blog page with a report. In this report, we will try to show the characteristic values entered under the material class in the material master data to the user in the form of a report.

I am working as an ABAP developer in a company that uses SAP. The reason why we need this report is that our production planning department wants to see the characteristics they defined for the materials collectively. Material characteristics can be obtained with the CLAF_CLASSIFICATION_OF_OBJECTS function. Since we will query the materials collectively, we will read directly from the tables to gain performance.

In our report, we will query the characteristics in the “Material Class” class.

 

 

The values we will query are the values in the “General” tab of the screen below.

 

 

 

As seen in the screens above, it is a problem to go around the materials in order to see the characteristics entered in the material master data. As a solution to this problem, taking the following entry;

 

As a result, we will write the report that outputs as follows.

 

 

As a first step, let’s make the variables and definitions that we will use in our report.

 

TYPE-POOLS: SLIS.
TABLES: MARA, MAKT, CABNT, CABN, T006A, AUSP.

DATA: BEGIN OF GT_METADATAS OCCURS 0,
  MATNR LIKE MARA-MATNR, " material no.
  MAKTX LIKE MAKT-MAKTX, " Material description
  atinn LIKE AUSP-ATINN, " characteristic
  ATBEZ LIKE CABNT-ATBEZ, " Characteristic description
  MSEHI LIKE CABN-MSEHI, " Measurement unit
  ATWRT LIKE AUSP-ATWRT, " Character characteristic value
  ATFLV LIKE AUSP-ATFLV, " Numeric Lower value
  ATFLB LIKE AUSP-ATFLB, " numeric upper value
  MSEH6 LIKE T006A-MSEH6, " Unit of measure technical definition
  SPRAS LIKE T006A-SPRAS, " language
  ATFOR LIKE CABN-ATFOR, " data type
  ANZST LIKE CABN-ANZST, " character length
  ANZDZ LIKE CABN-ANZDZ, " number of decimal characters
  VAL1 TYPE C LENGTH 10, " numeric value sub
  VAL2 TYPE C LENGTH 10, " numerical value upper
  END OF GT_METADATAS.

DATA: FCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: VARYANT TYPE DISVARIANT.
VARYANT-REPORT = SY-REPID.
VARYANT-USERNAME = SY-UNAME.

 

After making the definitions, let’s make the parameter definitions that we will get from the user.

 

SELECTION-SCREEN BEGIN OF BLOCK PARAMETERS WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
P_MATNR FOR MARA-MATNR,
  P_MATKL FOR MARA-MATKL.
SELECTION-SCREEN END OF BLOCK PARAMETERS.

START-OF-SELECTION.
  IF P_MATNR[] IS INITIAL AND P_MATKL[] IS INITIAL.
    MESSAGE 'Material number or one of the Goods Group must be entered'
    TYPE 'S' DISPLAY LIKE 'E'.
    CHECK 1 EQ 2.
  ENDIF.

 

Here, in the START-OF-SELECTION section, we are questioning the condition of filling in the material number or one of the goods groups. If both are empty, the transaction is canceled with CHECK. If both parameters are empty, the report will query all the parameters registered in the system and will cause it to work with a very low performance. Therefore, it is very important to enter parameters.

Then, with the following query, the necessary data is queried and transferred to the GT_METADATAS table.

 

 SELECT
    MR~MATNR MT~MAKTX AP~ATWRT
    AP~ATFLV AP~ATFLB AP~ATINN
    CN~ATFOR CN~ANZST CN~ANZDZ
    CN~MSEHI CT~ATBEZ TA~MSEH6
    TA~SPRAS
    FROM MARA AS MR
    JOIN MAKT AS MT ON MR~MATNR EQ MT~MATNR
    JOIN AUSP AS AP ON MR~MATNR EQ AP~OBJEK
  JOIN CABN AS CN ON AP~ATINN EQ CN~ATINN
    JOIN CABNT AS CT ON CN~ATINN EQ CT~ATINN
  LEFT JOIN T006A AS TA ON CN~MSEHI EQ TA~MSEHI
  INTO CORRESPONDING FIELDS OF TABLE GT_METADATAS
  WHERE AP~OBJEK IN P_MATNR
  AND MR~MATKL IN P_MATKL.

  DELETE GT_METADATAS WHERE SPRAS IS NOT INITIAL AND SPRAS NE SY-LANGU.

 

As a result of the query, T006A table is used to get the measurement unit definition of the characteristic value. However, since all characteristic values are not units of measurement, they must be connected with LEFT JOIN. As per the LEFT JOIN rule, only the definition of a language cannot be specified, so we delete the definitions other than the language in which the user has entered from the GT_METADATAS table in line 17, whose language definition is not empty.

 

Since the numerical value is in scientific notation as 1.2000000000000000E+00 after receiving the data, these values must first be converted to values such as 12.,00 that the user can read. We use the FLTP_CHAR_CONVERSION function for this process. The DECIM parameter in the function specifies the number of characters after the comma.

 

  LOOP AT GT_METADATAS WHERE ATFOR EQ 'NUM'.

    CALL FUNCTION 'FLTP_CHAR_CONVERSION'
      EXPORTING
      DECIM = GT_METADATAS-ANZDZ
        EXPON = 0
        INPUT = GT_METADATAS-ATFLV
        IVALU = 'X'
*       MASKN = ' '
      IMPORTING
        FLSTR = GT_METADATAS-VAL1.

    " Assigned to see values in a single column
    GT_METADATAS-ATWRT = GT_METADATAS-VAL1.

    CALL FUNCTION 'FLTP_CHAR_CONVERSION'
      EXPORTING
        DECIM = GT_METADATAS-ANZDZ
        EXPON = 0
        INPUT = GT_METADATAS-ATFLB
        IVALU = 'X'
*       MASKN = ' '
      IMPORTING
        FLSTR = GT_METADATAS-VAL2.

    MODIFY GT_METADATAS.

  ENDLOOP.

 

After these operations, we show the data to the screen. We use the following code for this process.

 

FORM SHOWDATA .
  DATA: I_SORT TYPE SLIS_SORTINFO_ALV,
        IT_SORT TYPE  SLIS_T_SORTINFO_ALV.
  I_SORT-SPOS  = 1.
  I_SORT-FIELDNAME = 'MATNR'.
  APPEND I_SORT TO IT_SORT.

  I_SORT-SPOS  = 2.
  I_SORT-FIELDNAME = 'MAKTX'.
  APPEND I_SORT TO IT_SORT.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME     = SY-REPID
      I_INTERNAL_TABNAME = 'GT_METADATAS'
      I_INCLNAME         = SY-REPID
    CHANGING
      CT_FIELDCAT        = FCAT[].

  PERFORM SET_FCAT.

  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IS_LAYOUT          = LAYOUT
      IT_FIELDCAT        = FCAT[]
      I_SAVE             = 'A'
      IS_VARIANT         = VARYANT
      IT_SORT            = IT_SORT
    TABLES
      T_OUTTAB           = GT_METADATAS.

ENDFORM.                    " SHOWDATA


*&---------------------------------------------------------------------*
*&      Form  SET_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SET_FCAT .
  DATA: FCATROW LIKE LINE OF FCAT.

  LOOP AT FCAT INTO FCATROW.
    CASE FCATROW-FIELDNAME.
      WHEN 'MSEHI'.
        FCATROW-TECH = 'X'.
      WHEN 'SPRAS'.
        FCATROW-TECH = 'X'.
      WHEN 'ATFOR'.
        FCATROW-TECH = 'X'.
      WHEN 'ANZST'.
        FCATROW-TECH = 'X'.
      WHEN 'ANZDZ'.
        FCATROW-TECH = 'X'.
      WHEN 'ATFLB'.
        FCATROW-TECH = 'X'.
      WHEN 'ATFLV'.
        FCATROW-TECH = 'X'.
      WHEN 'VAL1'.
        FCATROW-SELTEXT_S = 'Lower Value'.
        FCATROW-SELTEXT_M = 'Lower Value'.
        FCATROW-SELTEXT_L = 'Lower Value'.
        FCATROW-REPTEXT_DDIC = 'Lower Value'.
        FCATROW-TECH = 'X'.

      WHEN 'VAL2'.
        FCATROW-SELTEXT_S = 'Upper Value'.
        FCATROW-SELTEXT_M = 'Upper Value'.
        FCATROW-SELTEXT_L = 'Upper Value'.
        FCATROW-REPTEXT_DDIC = 'Upper Value'.
        FCATROW-TECH = 'X'.
    ENDCASE.

    MODIFY FCAT FROM FCATROW.

  ENDLOOP.

ENDFORM.                    " SET_FCAT

 

With the fields added to the IT_SORT table, we are telling you how to sort by default in the ALV to be displayed.

FCATROW-TECH = ‘X’ that we use in the SET_FCAT function. We say that the field related to the line will not be displayed.

 

Here is the whole code for the report.

 

*&---------------------------------------------------------------------*
*& Report  ZMaterialCharacteristic
*&
*&---------------------------------------------------------------------*
*& Note for Turkish speakers:
*& You can visit the link below to access my ABAP 
*& and other courses at a discount.
*& https://saitorhan.com/udemy-kurslarim/
*&---------------------------------------------------------------------*

REPORT ZMaterialCharacteristic.
TYPE-POOLS: SLIS.
TABLES: MARA, MAKT, CABNT, CABN, T006A, AUSP.

DATA: BEGIN OF GT_METADATAS OCCURS 0,
  MATNR LIKE MARA-MATNR, " material no.
  MAKTX LIKE MAKT-MAKTX, " Material description
  atinn LIKE AUSP-ATINN, " characteristic
  ATBEZ LIKE CABNT-ATBEZ, " Characteristic description
  MSEHI LIKE CABN-MSEHI, " Measurement unit
  ATWRT LIKE AUSP-ATWRT, " Character characteristic value
  ATFLV LIKE AUSP-ATFLV, " Numeric Lower value
  ATFLB LIKE AUSP-ATFLB, " numeric upper value
  MSEH6 LIKE T006A-MSEH6, " Unit of measure technical definition
  SPRAS LIKE T006A-SPRAS, " language
  ATFOR LIKE CABN-ATFOR, " data type
  ANZST LIKE CABN-ANZST, " character length
  ANZDZ LIKE CABN-ANZDZ, " number of decimal characters
  VAL1 TYPE C LENGTH 10, " numeric value sub
  VAL2 TYPE C LENGTH 10, " numerical value upper
  END OF GT_METADATAS.

DATA: FCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: VARYANT TYPE DISVARIANT.
VARYANT-REPORT = SY-REPID.
VARYANT-USERNAME = SY-UNAME.


SELECTION-SCREEN BEGIN OF BLOCK PARAMETERS WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
P_MATNR FOR MARA-MATNR,
  P_MATKL FOR MARA-MATKL.
SELECTION-SCREEN END OF BLOCK PARAMETERS.

START-OF-SELECTION.
  IF P_MATNR[] IS INITIAL AND P_MATKL[] IS INITIAL.
    MESSAGE 'Material number or one of the Goods Group must be entered'
    TYPE 'S' DISPLAY LIKE 'E'.
    CHECK 1 EQ 2.
  ENDIF.

  PERFORM GETDATA.
  PERFORM SHOWDATA.



*&---------------------------------------------------------------------*
*&      Form  GETDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GETDATA .
  SELECT
    MR~MATNR
    MT~MAKTX
    AP~ATWRT
    AP~ATFLV
    AP~ATFLB
    AP~ATINN
    CN~ATFOR
    CN~ANZST
    CN~ANZDZ
    CN~MSEHI
    CT~ATBEZ
    TA~MSEH6
    TA~SPRAS
    FROM MARA AS MR
    JOIN MAKT AS MT ON MR~MATNR EQ MT~MATNR
    JOIN AUSP AS AP ON MR~MATNR EQ AP~OBJEK
  JOIN CABN AS CN ON AP~ATINN EQ CN~ATINN
    JOIN CABNT AS CT ON CN~ATINN EQ CT~ATINN
  LEFT JOIN T006A AS TA ON CN~MSEHI EQ TA~MSEHI
  INTO CORRESPONDING FIELDS OF TABLE GT_METADATAS
  WHERE AP~OBJEK IN P_MATNR
  AND MR~MATKL IN P_MATKL.

  DELETE GT_METADATAS WHERE SPRAS IS NOT INITIAL AND SPRAS NE SY-LANGU.

  LOOP AT GT_METADATAS WHERE ATFOR EQ 'NUM'.

    CALL FUNCTION 'FLTP_CHAR_CONVERSION'
      EXPORTING
      DECIM = GT_METADATAS-ANZDZ
        EXPON = 0
        INPUT = GT_METADATAS-ATFLV
        IVALU = 'X'
*       MASKN = ' '
      IMPORTING
        FLSTR = GT_METADATAS-VAL1.

    " Assigned to see values in a single column
    GT_METADATAS-ATWRT = GT_METADATAS-VAL1.

    CALL FUNCTION 'FLTP_CHAR_CONVERSION'
      EXPORTING
        DECIM = GT_METADATAS-ANZDZ
        EXPON = 0
        INPUT = GT_METADATAS-ATFLB
        IVALU = 'X'
*       MASKN = ' '
      IMPORTING
        FLSTR = GT_METADATAS-VAL2.

    MODIFY GT_METADATAS.

  ENDLOOP.

ENDFORM.                    " GETDATA


*&---------------------------------------------------------------------*
*&      Form  SHOWDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SHOWDATA .
  DATA: I_SORT TYPE SLIS_SORTINFO_ALV,
        IT_SORT TYPE  SLIS_T_SORTINFO_ALV.
  I_SORT-SPOS  = 1.
  I_SORT-FIELDNAME = 'MATNR'.
  APPEND I_SORT TO IT_SORT.

  I_SORT-SPOS  = 2.
  I_SORT-FIELDNAME = 'MAKTX'.
  APPEND I_SORT TO IT_SORT.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME     = SY-REPID
      I_INTERNAL_TABNAME = 'GT_METADATAS'
      I_INCLNAME         = SY-REPID
    CHANGING
      CT_FIELDCAT        = FCAT[].

  PERFORM SET_FCAT.

  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      IS_LAYOUT          = LAYOUT
      IT_FIELDCAT        = FCAT[]
      I_SAVE             = 'A'
      IS_VARIANT         = VARYANT
      IT_SORT            = IT_SORT
    TABLES
      T_OUTTAB           = GT_METADATAS.

ENDFORM.                    " SHOWDATA


*&---------------------------------------------------------------------*
*&      Form  SET_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM SET_FCAT .
  DATA: FCATROW LIKE LINE OF FCAT.

  LOOP AT FCAT INTO FCATROW.
    CASE FCATROW-FIELDNAME.
      WHEN 'MSEHI'.
        FCATROW-TECH = 'X'.
      WHEN 'SPRAS'.
        FCATROW-TECH = 'X'.
      WHEN 'ATFOR'.
        FCATROW-TECH = 'X'.
      WHEN 'ANZST'.
        FCATROW-TECH = 'X'.
      WHEN 'ANZDZ'.
        FCATROW-TECH = 'X'.
      WHEN 'ATFLB'.
        FCATROW-TECH = 'X'.
      WHEN 'ATFLV'.
        FCATROW-TECH = 'X'.
      WHEN 'VAL1'.
        FCATROW-SELTEXT_S = 'Lower Value'.
        FCATROW-SELTEXT_M = 'Lower Value'.
        FCATROW-SELTEXT_L = 'Lower Value'.
        FCATROW-REPTEXT_DDIC = 'Lower Value'.
        FCATROW-TECH = 'X'.

      WHEN 'VAL2'.
        FCATROW-SELTEXT_S = 'Upper Value'.
        FCATROW-SELTEXT_M = 'Upper Value'.
        FCATROW-SELTEXT_L = 'Upper Value'.
        FCATROW-REPTEXT_DDIC = 'Upper Value'.
        FCATROW-TECH = 'X'.
    ENDCASE.

    MODIFY FCAT FROM FCATROW.

  ENDLOOP.

ENDFORM.                    " SET_FCAT

 

After we start using the report in our system, we aim to increase the analysis ability by seeing the material characteristics collectively, especially in the production planning department.

So what do you think about what this report can add to production and what can be added to the report? We will enrich the report with your valuable feedback.
Thank you for giving a time.

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x