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: 

Merge two cells

0 Kudos
124

Hi, dear friends, I need help with an alv.

Simplifying e.g.:

I have two fields, Quantity and Unit. Everyone in their corresponding column, but I want to see Quantity and Unit in only one column.

The alv is made with FM.

Is possible?

Thanks in advance for your help.

1 ACCEPTED SOLUTION

Former Member
9 REPLIES 9

Former Member

former_member181995
Active Contributor
0 Kudos
94

well jose u can do it by append statment.

take a both field in oterone which is new field and append in this one.

plz give points if helpfull.

regards amit.

gopi_narendra
Active Contributor
0 Kudos
94

Once you get the data in your final internal table which you are passing to the ALV Function module. just use a concatenate on the QTY and UNIT and move it into a field QTYUN(2) type C and pass this values to another internal table and pass the new internal table to the FM for ALV display.

Regards

Gopi

Former Member
0 Kudos
94

Hi Jose

Field catalog can be created automatically(using FM) or manually.

1. automatic - You can go for this option if you want to display all the fields in the internal table in the alv list. As i have explaned in the last post, it is done with FM 'REUSE_ALV_FIELDCATALOG_MERGE'.

2. Manual - You go for manual alv creation when you dont want to display all the fields in the internal table.This method can be the most time consuming but can also allow you more control of the final product. Please see the example code given below. subroutine build_fieldcatalog creates the field catalog.

 
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line.

*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15. 
fieldcatalog-do_sum = 'X'. "Display column total
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG

check this sample code

LINE-SIZE 150
LINE-COUNT 60(4)
MESSAGE-ID Z00.

*..Type Definitions for ALV Report
TYPE-POOLS SLIS.

*..Includes
*for ICONs
*INCLUDE <ICON>.

*----------------------------------------------------------------------*
* Table/Structure declarations. *
*----------------------------------------------------------------------*
TABLES: MARA,
MARC,
T134.

*----------------------------------------------------------------------*
* Internal Tables declaration *
*----------------------------------------------------------------------*
*..To store Basic Report fields
DATA:BEGIN OF IT_MARA OCCURS 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MATKL LIKE MARA-MATKL,
MEINS LIKE MARA-MEINS,
NTGEW LIKE MARA-NTGEW,
END OF IT_MARA.

*DATA:BEGIN OF IT_MATKL OCCURS 0,
* MATKL LIKE T023-MATKL,
* WGBEZ LIKE T023-WGBEZ,
* END OF IT_MATKL.

DATA:BEGIN OF IT_MARC OCCURS 0,
WERKS LIKE MARC-WERKS,
LADGR LIKE MARC-LADGR,
MTVFP LIKE MARC-MTVFP,
DISPR LIKE MARC-DISPR,
DISMM LIKE MARC-DISMM,
DISPO LIKE MARC-DISPO,
END OF IT_MARC.
*----------------------------------------------------------------------*
* ALV Type declaration *
*----------------------------------------------------------------------*
DATA:V_NO_DATA TYPE C.

*----------------------------------------------------------------------*
* ALV Type declaration *
*----------------------------------------------------------------------*
DATA:V_REPID TYPE SYREPID.

DATA: IT_FIELDCATALOG_MARA TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCATALOG_MARA TYPE SLIS_FIELDCAT_ALV,

IT_FIELDCATALOG_MARC TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCATALOG_MARC TYPE SLIS_FIELDCAT_ALV,

IT_FIELDCATALOG_MATKL TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCATALOG_MATKL TYPE SLIS_FIELDCAT_ALV,


WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

IT_EVENTS TYPE SLIS_T_EVENT,
WA_EVENTS TYPE SLIS_ALV_EVENT,

WA_KEYINFO TYPE SLIS_KEYINFO_ALV.
*----------------------------------------------------------------------*
* Selection Screen. *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-H01.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR ,
S_MTART FOR MARA-MTART .
SELECTION-SCREEN END OF BLOCK B1.
*----------------------------------------------------------------------*
* Event:Initialization *
*----------------------------------------------------------------------*
INITIALIZATION.
*Report Name
V_REPID = SY-REPID.

*----------------------------------------------------------------------*
* AT Selection Screen. *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.

*----------------------------------------------------------------------*
* Event: Start-of-Selection *
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM FETCH_DATA.

*----------------------------------------------------------------------*
* Event: End-of-Selection *
*----------------------------------------------------------------------*
END-OF-SELECTION.
IF V_NO_DATA = ''.
MESSAGE I010 WITH 'NO DATA TO DISPLAY ! '.
EXIT.
ELSE.
PERFORM FILL_FIELDCAT_MARA.
* PERFORM FILL_FIELDCAT_MAKT.
PERFORM FILL_FIELDCAT_MARC.
PERFORM FILL_LAYOUT.
PERFORM CALL_ALV_INIT.
PERFORM ADD_LISTS.
PERFORM DISPLAY_BLOCK_LIST.
ENDIF.
*//////////////////////////////////////////////////////////////////////*
*
* FORM DEFINITIONS *
*
*//////////////////////////////////////////////////////////////////////
*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FETCH_DATA.
SELECT MATNR
MTART
MATKL
MEINS
NTGEW
INTO CORRESPONDING FIELDS OF TABLE IT_MARA
FROM MARA
WHERE MATNR IN S_MATNR
AND MTART IN S_MTART.
IF SY-SUBRC <> 0.
V_NO_DATA = ''.
ELSE.
V_NO_DATA = 'X'.
SELECT WERKS
LADGR
MTVFP
DISPR
DISMM
DISPO
INTO CORRESPONDING FIELDS OF TABLE IT_MARC
FROM MARC
WHERE MATNR IN S_MATNR.
ENDIF.
ENDFORM. " FETCH_DATA
*
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT_MARA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCAT_MARA.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = V_REPID
* I_INTERNAL_TABNAME =
I_STRUCTURE_NAME = 'IT_MARA'
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = V_REPID
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = IT_FIELDCATALOG_MARA
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT IT_FIELDCATALOG_MARA INTO WA_FIELDCATALOG_MARA.
CASE WA_FIELDCATALOG_MARA-FIELDNAME.
WHEN 'MATNR'.
WA_FIELDCATALOG_MARA-COL_POS = '1'.
WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARA-SELTEXT_L = 'Material NO'.
WHEN 'MTART'.
WA_FIELDCATALOG_MARA-COL_POS = '2'.
WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARA-SELTEXT_L = 'Mat Type'.
WHEN 'MATKL'.
WA_FIELDCATALOG_MARA-COL_POS = '3'.
WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARA-SELTEXT_L = 'Mat Group'.
WHEN 'MEINS'.
WA_FIELDCATALOG_MARA-COL_POS = '4'.
WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARA-SELTEXT_L = 'Measure Unit'.
WHEN 'NTGEW'.
WA_FIELDCATALOG_MARA-COL_POS = '5'.
WA_FIELDCATALOG_MARA-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARA-SELTEXT_L = 'Net Wt'.
WA_FIELDCATALOG_MARA-DO_SUM = 'X'.
ENDCASE.
MODIFY IT_FIELDCATALOG_MARA FROM WA_FIELDCATALOG_MARA INDEX SY-TABIX.
ENDLOOP.
ENDFORM. " FILL_FIELDCAT_MARA
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT_MARC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCAT_MARC.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = V_REPID
I_INTERNAL_TABNAME = 'IT_MARC'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = V_REPID
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = IT_FIELDCATALOG_MARC
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT IT_FIELDCATALOG_MARC INTO WA_FIELDCATALOG_MARC.
CASE WA_FIELDCATALOG_MARC-FIELDNAME.
WHEN 'WERKS'.
WA_FIELDCATALOG_MARC-COL_POS = '1'.
WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARC-SELTEXT_L = 'PLANT NAME'.
WHEN 'LADGR'.
WA_FIELDCATALOG_MARC-COL_POS = '2'.
WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARC-SELTEXT_L = 'Loading Group'.
WHEN 'MTVFP'.
WA_FIELDCATALOG_MARC-COL_POS = '3'.
WA_FIELDCATALOG_MARC-OUTPUTLEN = '20'.
WA_FIELDCATALOG_MARC-SELTEXT_L = 'Checking group'.
WHEN 'DISPR'.
WA_FIELDCATALOG_MARC-COL_POS = '4'.
WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARC-SELTEXT_L = 'MRP PROFILE'.
WHEN 'DISMM'.
WA_FIELDCATALOG_MARC-COL_POS = '5'.
WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARC-SELTEXT_L = 'MRP TYPE'.
WHEN 'DISPO'.
WA_FIELDCATALOG_MARC-COL_POS = '6'.
WA_FIELDCATALOG_MARC-OUTPUTLEN = '15'.
WA_FIELDCATALOG_MARC-SELTEXT_L = 'MRP CONTROLLER'.
ENDCASE.
MODIFY IT_FIELDCATALOG_MARC FROM WA_FIELDCATALOG_MARC INDEX SY-TABIX.
ENDLOOP.


ENDFORM. " FILL_FIELDCAT_MARC
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT_MAKT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCAT_MAKT.

ENDFORM. " FILL_FIELDCAT_MAKT
*&---------------------------------------------------------------------*
*& Form CALL_ALV_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_ALV_INIT.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
.
ENDFORM. " CALL_ALV_INIT
*&---------------------------------------------------------------------*
*& Form ADD_LISTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ADD_LISTS.
*ADD IT_MARA TABLE TO THE OUTPUT
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FIELDCATALOG_MARA
I_TABNAME = 'IT_MARA'
IT_EVENTS = IT_EVENTS
* IT_SORT =
* I_TEXT = ' '
TABLES
T_OUTTAB = IT_MARA
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

**ADD IT_MARC TABLE TO THE OUTPUT
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FIELDCATALOG_MARC
I_TABNAME = 'IT_MARC'
IT_EVENTS = IT_EVENTS
* IT_SORT =
* I_TEXT = ' '
TABLES
T_OUTTAB = IT_MARC
* EXCEPTIONS
* PROGRAM_ERROR = 1
* MAXIMUM_OF_APPENDS_REACHED = 2
* OTHERS = 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. " ADD_LISTS
*&---------------------------------------------------------------------*
*& Form FILL_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_LAYOUT.
WA_LAYOUT-ZEBRA = 'X'.
WA_LAYOUT-TOTALS_TEXT = 'TOTAL'.


ENDFORM. " FILL_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_BLOCK_LIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_BLOCK_LIST.
* WA_KEYINFO-HEADER01 = 'MATNR'.
* WA_KEYINFO-ITEM01 = 'MATNR'.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* IS_PRINT =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " DISPLAY_BLOCK_LIST

check this links

http://www.howforge.com/abap-4-example-code-alv-list-by-fm-reuse-alv-list-display

Reward all helpfull answers

Regards

Pavan

0 Kudos
94

Second Step.

Well, I did it, but I'm doing a subtotals of Quantity field, I thought in not display these fields ( Quantity , Unit ) only the char field joined ( Quantity + Unit ) , but how can I take out the subtotal?

A lot of thanks

former_member375669
Participant
0 Kudos
94

hi jose

yes Definitely it is possible

take a temp. variable in the internal table structure fill this temp. with the concatinaion of quantity and unit and then paas this temp field to the field catelog

declare the data like this

DATA: begin of I_MSEG OCCURS 0.

include structure MSEG.

data temp(25).

data: end of i_MSEG.

create a loop after select query.

loop at i_mseg.

v_temp = I_MSEG-MENGE.

concatenate v_temp I_MSEG-MEINS into I_MSEG-temp separated by space.

modify i_mseg.

endloop.

and fill the field catelog like this

I_FTAB-COL_POS = 3.

  • I_FTAB-TABNAME = I_MSEG.

I_FTAB-FIELDNAME = 'TEMP'.

I_FTAB-SELTEXT_M = 'QUANTITY U-M-O'.

APPEND I_FTAB.

DONT FORGET TO REWARD THE POINTS

BUY

Message was edited by:

ashish gupta

0 Kudos
94

Ok!!! but now when I have the column Quantity + Unit, I'd like their subtotal, I did it with subtotal in catalog and sort but nothing, I set Quantity and Unit no_out in catalog, I only want to see the field Quantity + Unit with the subtotals below.

No way, I don't know what to do....

Any idea???

Best regards friends!

0 Kudos
94

Anyone know how to do it????? or if I can do it ????

Thanks in advance

0 Kudos
94

Hi, I' ll explain again the question:

I've two columns: | Quantity | Unit |

55

A

100

A

25

B

Subtotal client 155 | A |

25 | B |

-> I want to merge these columns in only one

Quantity Unit

-> I did it.

55 A

100 A

25 B

But I don' t know how to take out the subtotal of this one!!

Subtotal client

155 A

25 B

Please, can anybody help me?

Thanks in advance!!!