Skip to Content
Technical Articles
Author's profile photo Muhammad Ashar Azhar

Material Purchase order view text report

Hi,

In many organizations there is a requirement in reports related to data extraction of text from text views. Like material purchase order text view,  many organizations are using frequently these text views to save important information.

In this blog I am sharing abap report from which users can easily extract this data. Also it provides an option to search materials having text in search parameter field.

All Long Texts are Stored in STXH and STXL Tables. But the best way to extract text data is by using standard function module READ_TEXT. Only challenge in using this function module is to find the parameter ID & OBJECT.

I have create a test case as keeping one material text simple as follows.

Material%20PO%20text%20view

Material PO text view

 Report selection parameters are as follows:

Selection%20Parameter

Selection Parameter

User will give the material numbers range as per requirement and in selection parameter enter the required parameter text.

Report output will be as follows:

Output

Output

For more info please follow: https://blogs.sap.com/

S/4 HANA Topic.

 

Report Source Code:

REPORT ZASA_PO_MM_TEXT.

TABLES: MARA.

DATA: BEGIN OF MATERIALTAB OCCURS 0,
MATNR  TYPE MATNR,
MTART  TYPE MTART,
MATKL  TYPE MATKL,
MAKTX  TYPE MAKTX,
STRING TYPE STRING,
END OF MATERIALTAB.

DATA: WA LIKE LINE OF MATERIALTAB.
DATA: WA1 LIKE LINE OF MATERIALTAB.

DATA: BEGIN OF MATRESULT OCCURS 0,
MATNR TYPE MATNR,
MTART TYPE MTART,
MATKL TYPE MATKL,
MAKTX TYPE MAKTX,
END OF MATRESULT.

DATA: MATTEXT TYPE TABLE OF TLINE WITH HEADER LINE,
TEXTSTR TYPE STRING,
MATNAME TYPE THEAD-TDNAME.

DATA: RESULT_TAB   TYPE MATCH_RESULT_TAB,
LinTxt       TYPE STRING,
CheckFlag(5) TYPE C VALUE ‘False’,
MATNR1       TYPE THEAD-TDNAME.

FIELD-SYMBOLS: <WA>     LIKE LINE OF MATRESULT,
<WATEXT> TYPE TLINE,
<RESULT> LIKE LINE OF MATRESULT.

DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,
GD_LAYOUT    TYPE SLIS_LAYOUT_ALV,
GD_REPID     LIKE SY-REPID.

DATA: V_PROG TYPE SY-REPID,
V_NAME TYPE SY-UNAME.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: MATNR FOR MARA-MATNR,
MTART FOR MARA-MTART,
MATKL FOR MARA-MATKL.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETERS: SELTEXT TYPE CRITX.
SELECTION-SCREEN END OF BLOCK B2.

DATA: SELECT(20).

AT SELECTION-SCREEN.
IF MATNR[] IS INITIAL AND
MTART[] IS INITIAL AND
MATKL[] IS INITIAL .
MESSAGE ‘Please provide at-least one selection parameter’ TYPE ‘E’.
ENDIF.

INITIALIZATION.
SELECT = ‘Selection Criteria’.
V_PROG = SY-REPID.
V_NAME = SY-UNAME.

START-OF-SELECTION.
SELECT MARA~MATNR
MARA~MATKL
MARA~MTART
MAKT~MAKTX
FROM MARA INNER JOIN MAKT ON MARA~MATNR = MAKT~MATNR
INTO CORRESPONDING FIELDS OF TABLE MATERIALTAB
WHERE MARA~MATNR IN MATNR AND
MARA~MTART IN MTART AND
MARA~MATKL IN MATKL.

IF NOT MATERIALTAB[] IS INITIAL.
LOOP AT MATERIALTAB.
PERFORM READTEXT.
ENDLOOP.
ENDIF.

PERFORM BUILD_FIELDCATALOG.
PERFORM DISPLAY_ALV_REPORT.
*&———————————————————————*
*&      Form  READTEXT
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM READTEXT .

FREE MATTEXT.
MATNAME = MATERIALTAB-MATNR.

CALL FUNCTION ‘READ_TEXT’
EXPORTING
*     CLIENT                  = SY-MANDT
ID                      = ‘BEST’
LANGUAGE                = ‘E’
NAME                    = MATNAME
OBJECT                  = ‘MATERIAL’
*     ARCHIVE_HANDLE          = 0
*     LOCAL_CAT               = ‘ ‘
*   IMPORTING
*     HEADER                  =
TABLES
LINES                   = MATTEXT
EXCEPTIONS
ID                      = 1
LANGUAGE                = 2
NAME                    = 3
NOT_FOUND               = 4
OBJECT                  = 5
REFERENCE_CHECK         = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS                  = 8.
IF SY-SUBRC = 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
DATA : WA_MATTEXT TYPE TLINE.
DATA: MAT_STRING TYPE STRING.
LOOP AT MATTEXT INTO WA_MATTEXT.
CONCATENATE MAT_STRING WA_MATTEXT INTO MAT_STRING.
CLEAR WA_MATTEXT.
ENDLOOP.

WA1-MATNR = MATERIALTAB-MATNR.
WA1-MTART = MATERIALTAB-MTART.
WA1-MATKL = MATERIALTAB-MATKL.
WA1-MAKTX = MATERIALTAB-MAKTX.

REPLACE ALL OCCURRENCES OF ‘/’ IN MAT_STRING WITH `!! `.

WA1-STRING =  MAT_STRING.

MODIFY MATERIALTAB FROM WA1 TRANSPORTING STRING.

ENDIF.

MATNR1 = MATERIALTAB-MATNR.
LOOP AT Mattext.

FIND SELTEXT IN Mattext-TDLINE RESULTS Result_Tab IGNORING CASE.
IF SY-SUBRC = 0.

CheckFlag = ‘True’.
EXIT.

ENDIF.

ENDLOOP.

IF CheckFlag = ‘True’.

CheckFlag = ‘False’.

ELSEIF CheckFlag = ‘False’.
FREE Mattext.
DELETE MATERIALTAB WHERE MATNR = MATNAME.
CLEAR MATNR1.
ENDIF.
ENDFORM.                    ” READTEXT

AT LINE-SELECTION. “Event executed when the line is selected(double clicked)

DATA: M(55)   TYPE C,
VAL(18) TYPE C.

GET CURSOR FIELD MATERIALTAB-MATNR VALUE VAL.
*CONCATENATE ‘00000000’ val INTO val.   ” Concatenating leading zeros to the service number
SET PARAMETER ID ‘MAT’ FIELD VAL.

CALL TRANSACTION ‘MM03’ AND SKIP FIRST SCREEN. ” Calling MM03 transaction
FORM BUILD_FIELDCATALOG .
FIELDCATALOG-FIELDNAME   = ‘MATNR’.
FIELDCATALOG-KEY   = ‘X’.
FIELDCATALOG-SELTEXT_M   = ‘Material’.
FIELDCATALOG-OUTPUTLEN   = 20.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOG-FIELDNAME   = ‘maktx’.
FIELDCATALOG-SELTEXT_M   = ‘Description’.
FIELDCATALOG-OUTPUTLEN   = 30.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOG-FIELDNAME   = ‘MTART’.
FIELDCATALOG-SELTEXT_M   = ‘Material Type’.
FIELDCATALOG-OUTPUTLEN   = 10.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOG-FIELDNAME   = ‘MATKL’.
FIELDCATALOG-SELTEXT_M   = ‘Material Group’.
FIELDCATALOG-OUTPUTLEN   = 13.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOG-FIELDNAME   = ‘STRING’.
FIELDCATALOG-SELTEXT_M   = ‘PO Text’.
FIELDCATALOG-OUTPUTLEN   = 150.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

CLEAR  FIELDCATALOG.
ENDFORM.

*
*
**&———————————————————————*
**&      Form  DISPLAY_ALV_REPORT
**&———————————————————————*
**       text
**———————————————————————-*
**  –>  p1        text
**  <–  p2        text
**———————————————————————-*
FORM DISPLAY_ALV_REPORT .
GD_REPID = SY-REPID.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM      = GD_REPID
I_CALLBACK_TOP_OF_PAGE  = ‘TOP-OF-PAGE’  “see FORM
I_CALLBACK_USER_COMMAND = ‘USER_COMMAND’
IT_FIELDCAT             = FIELDCATALOG[]
I_SAVE                  = ‘X’
*     IS_VARIANT              = G_VARIANT
TABLES
T_OUTTAB                = MATERIALTAB
EXCEPTIONS
PROGRAM_ERROR           = 1
OTHERS                  = 2.

IF SY-SUBRC EQ 0.
REFRESH FIELDCATALOG.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.

FORM TOP-OF-PAGE.
*ALV Header declarations
DATA: T_HEADER      TYPE SLIS_T_LISTHEADER,
WA_HEADER     TYPE SLIS_LISTHEADER,
T_LINE        LIKE WA_HEADER-INFO,
LD_LINES      TYPE I,
LD_LINESC(10) TYPE C.
*  * Title
WA_HEADER-TYP  = ‘H’.
WA_HEADER-INFO = ‘Material Purchase Order Text’.
APPEND WA_HEADER TO T_HEADER.
CLEAR WA_HEADER.
” Date
WA_HEADER-TYP  = ‘S’.
WA_HEADER-KEY = ‘Date: ‘.
CONCATENATE  SY-DATUM+6(2) ‘.’
SY-DATUM+4(2) ‘.’
SY-DATUM(4) INTO WA_HEADER-INFO.   “todays date
APPEND WA_HEADER TO T_HEADER.
CLEAR: WA_HEADER.

* Total No. of Records Selected
DESCRIBE TABLE MATERIALTAB LINES LD_LINES.
LD_LINESC = LD_LINES.
CONCATENATE ‘Total No. of Records Selected: ‘ LD_LINESC
INTO T_LINE SEPARATED BY SPACE.
WA_HEADER-TYP  = ‘A’.
WA_HEADER-INFO = T_LINE.
APPEND WA_HEADER TO T_HEADER.
CLEAR: WA_HEADER, T_LINE.

CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE’
EXPORTING
IT_LIST_COMMENTARY = T_HEADER.
ENDFORM.

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
* Check function code
CASE R_UCOMM.
WHEN ‘&IC1’.
*           Check field clicked on within ALVgrid report
IF RS_SELFIELD-FIELDNAME = ‘MATNR’.
*           Read data table, using index of row user clicked on
READ TABLE MATERIALTAB INTO WA1 INDEX RS_SELFIELD-TABINDEX.
*           Set parameter ID for transaction screen field
SET PARAMETER ID ‘MAT’ FIELD WA1-MATNR.
*           Sxecute transaction ME23N, and skip initial data entry screen
CALL TRANSACTION ‘MM03’ AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.

 

 

 

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.