Skip to Content
0
Aug 22, 2023 at 06:47 PM

How to CONCATENATE the multiple line into single row, while fetching the MM basic data text.

123 Views

Dear ABAP experts,

I have a custome program to fetch the Material master basic data text, Program is working fine but the issue is, Multiple lines of basic data text is exported in to multiple rows, I want that for each material code multiple lines should be combined in one row during output/export.

Please view the code below and kindly let me know the changes required in code to get the desired output. Thanks.

I have attached the current export/otput format, and the required format for reference.

Environment: S/4 Hana 2021 onpermise

output-sample.jpg

*&---------------------------------------------------------------------*
*& Report Z_FETCH_MATERIAL_ITEMTEXT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_FETCH_MATERIAL_ITEMTEXT.

.


tables: ekpo,MAKT.
TYPE-POOLS: slis.
DATA: thread LIKE thead.
DATA: l_index LIKE sy-tabix.


DATA: BEGIN OF INT_OUT OCCURS 0,
MATNR LIKE EKPO-MATNR,
MAKTX LIKE MAKT-MAKTX,
TDLINE LIKE TLINE-TDLINE,
WERKS LIKE EKPO-WERKS,
END OF INT_OUT.
DATA: BEGIN OF INT_OUT_new OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
TDLINE LIKE TLINE-TDLINE,
tline like tline occurs 0,
WERKS LIKE EKPO-WERKS,
END OF INT_OUT_new.




DATA: it_tlines LIKE tline OCCURS 10 WITH HEADER LINE.

************************
****ALV list definintion
***********************
DATA: ws_cat TYPE slis_fieldcat_alv ,
int_cat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA: g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
g_custom_container TYPE REF TO cl_gui_custom_container.




***************
*selection-screen
***************




SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*SELECTION-SCREEN SKIP 2.
*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(20) text-001.
**PARAMETERS: S_MATNR LIKE MAKT-MATNR obligatory.
*
SELECT-OPTIONS: S_MATNR FOR MAKT-MATNR .
*SELECTION-SCREEN END OF LINE.




*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(20) text-002.
**PARAMETERS:p_ebeln LIKE ekko-ebeln obligatory.
*SELECT-OPTIONS: S_WERKS FOR EKPO-WERKS OBLIGATORY.
*SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.


START-OF-SELECTION.
PERFORM get_data.
* PERFORM field_catalog.
* PERFORM display_data.

END-OF-SELECTION.
*FORM GET_DATA.


form get_data.




DATA: l_index LIKE sy-tabix.

*SELECT
* a~matnr
* a~werks
* b~maktx FROM ekpo AS a
* INNER JOIN makt AS b
* ON b~matnr = a~matnr
* INTO CORRESPONDING FIELDS OF TABLE int_out
* WHERE
** a~matnr = s_matnr and
* a~werks IN s_werks.



*To Fetch Data From Makt.

SELECT MATNR MAKTX FROM MAKT INTO CORRESPONDING FIELDS OF TABLE
int_out WHERE MAKT~MATNR IN S_MATNR.



LOOP AT int_out.



l_index = sy-tabix.

* read table int_out_new with key matnr = int_out-matnr.

int_out_new-matnr = int_out-matnr.
int_out_new-maktx = int_out-maktx.

*
thread-tdname = int_out-matnr.

CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
* id = 'BEST'
id = 'GRUN'

language = sy-langu
name = thread-tdname
object = 'MATERIAL'
TABLES
lines = it_tlines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.

*Loop on it_tlines where long text is coming .

loop at it_tlines.


IF sy-subrc = 0.

int_out_new-tdline = it_tlines-tdline.
append int_out_new.
clear int_out_new.
clear int_out_new-tdline.

ENDIF.

endloop.

delete adjacent duplicates from INT_OUT .
append int_out_new.
ENDLOOP.

* Field Catalog

***MATERIAL NO no
int_cat-tabname = 'INT_OUT_NEW'.
int_cat-fieldname = 'MATNR'.
int_cat-reptext_ddic = 'MATERIAL NO'.
int_cat-outputlen = '18'.
APPEND int_cat .

*material Short Description
int_cat-tabname = 'INT_OUT_NEW'.
int_cat-fieldname = 'MAKTX'.
int_cat-reptext_ddic = 'MATERIAL SHORT DESCRIPTION'.
int_cat-datatype = 'CHAR'.
int_cat-outputlen = '45'.

APPEND int_cat .

** Material Long Description
int_cat-tabname = 'INT_OUT_NEW'.
int_cat-fieldname = 'TDLINE'.
int_cat-reptext_ddic = 'MATERIAL LONG DESCRIPTION'.
int_cat-datatype = 'CHAR'.
int_cat-outputlen = '200'.

APPEND int_cat .


CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = int_cat[]

TABLES
t_outtab = int_out_NEW
EXCEPTIONS
program_error = 1
OTHERS = 2.



ENDFORM. "display_data

Attachments

output-sample.jpg (105.3 kB)