Converting rows to horizontal display
Dear all,
I am displaying the values of material usage monthwise.These are being displayed vertically.Could you please tell me how to display this horizontally.
Also i want to sum up the usage.
Also i want to dispaly the count ,where count is the number of times that material has been used in that given period. i am also posting my code.
currently it is as follows:- (eg)
Material Period Quantity
Mat A 02.2007 2.000
Mat A 04.2007 1.000
Mat B 05.2007 3.000
Mat B 08.2007 1.000
Mat B 09.2007 2.000 and so on.....
I want it as follows:-
Material 02.2007 04.2007 05.2007 08.2007 09.2007 Total Count
Mat A 2.000 1.000 0 0 0 3 2
Mat B 0 0 3.000 1.000 2.000 6 3
*& Report ZMM_MATERIAL_USAGE
MODULE : Material Management *
Objective - To show Monthly Report for Material Usage * *
Program - Updates Tables ( ) Downloads data ( ) *
- Outputs List ( ) * *
Date Created - 22-11-2007 *
Request ID - EC2K913084 *
Author - Rahul Bhat *
Location - Mumbai *
LDB - NA *
REPORT ZMM_MATERIAL_USAGE.
Types Begin with TY_ *
Internal Table Structure
*TYPES: BEGIN OF TY_MARC , "Plant Data for Material
MATNR TYPE MARC-MATNR, "Material Number
WERKS TYPE MARC-WERKS, "Plant
END OF TY_MARC .
*TYPES: BEGIN OF TY_MARA ,
MATNR TYPE MARA-MATNR, "Material Number
MTART TYPE MARA-MTART, "Material type
SPART TYPE MARA-SPART, "Division
WERKS TYPE MARC-WERKS, "Plant
END OF TY_MARA .
TYPES: BEGIN OF TY_ZV_OLR3_MARACKT , "Plant Material: Search Help with Short Text
MATNR TYPE MARA-MATNR , "Material Number
WERKS TYPE MARC-WERKS , "Plant
MTART TYPE MARA-MTART , "Material Type
MAKTX TYPE MAKT-MAKTX , "Material Description
SPART TYPE MARA-SPART , "Division
END OF TY_ZV_OLR3_MARACKT .
TYPES: BEGIN OF TY_MBEW , "Material Valuation
MATNR TYPE MBEW-MATNR , "Material Number
BWKEY TYPE MBEW-BWKEY , "Valuation area
BWTAR TYPE MBEW-BWTAR , "Valuation type
VERPR TYPE MBEW-VERPR , "Moving Average Price/Periodic Unit Price
END OF TY_MBEW .
*TYPES: BEGIN OF TY_MKPF , "Header: Material Document
MBLNR TYPE MKPF-MBLNR , "Number of Material Document
MJAHR TYPE MKPF-MJAHR , "Material Document Year
BUDAT TYPE MKPF-BUDAT , "Posting Date in the Document
END OF TY_MKPF .
*TYPES: BEGIN OF TY_MSEG , "Document Segment: Material
MBLNR TYPE MSEG-MBLNR , "Number of Material Document
MJAHR TYPE MSEG-MJAHR , "Document Segment: Material
ZEILE TYPE MSEG-ZEILE , "Item in Material Document
BWART TYPE MSEG-BWART , "Movement Type (Inventory Management)
MENGE TYPE MSEG-MENGE , "Quantity
MEINS TYPE MSEG-MEINS , "Base Unit of Measure
MATNR TYPE MSEG-MATNR , "Material Number
END OF TY_MSEG .
TYPES: BEGIN OF TY_WB2_V_MKPF_MSEG2 , "Data Selection from Material Documents
MBLNR TYPE MSEG-MBLNR , "Number of Material Document
MJAHR TYPE MSEG-MJAHR , "Document Segment: Material
BUDAT TYPE MKPF-BUDAT , "Posting Date in the Document
ZEILE_I TYPE MSEG-ZEILE , "Item in Material Document
BWART_I TYPE MSEG-BWART , "Movement Type (Inventory Management)
MENGE_I TYPE MSEG-MENGE , "Quantity
MEINS_I TYPE MSEG-MEINS , "Base Unit of Measure
MATNR_I TYPE MSEG-MATNR , "Material Number
WERKS_I TYPE MSEG-WERKS , "Plant
END OF TY_WB2_V_MKPF_MSEG2 .
TYPES: BEGIN OF TY_WB2_V_MKPF_MSEG2_COPY , "Copy of Data Selection from Material Documents
MATNR_I TYPE MSEG-MATNR , "Material Number
FYEAR(4) TYPE C , "Fiscal Year
MONTH(2) TYPE C , "Month
BWART_I TYPE MSEG-BWART , "Movement Type (Inventory Management)
MBLNR TYPE MSEG-MBLNR , "Number of Material Document
MJAHR TYPE MSEG-MJAHR , "Document Segment: Material
BUDAT TYPE MKPF-BUDAT , "Posting Date in the Document
ZEILE_I TYPE MSEG-ZEILE , "Item in Material Document
MENGE_I TYPE MSEG-MENGE , "Quantity
MEINS_I TYPE MSEG-MEINS , "Base Unit of Measure
WERKS_I TYPE MSEG-WERKS ,
COUNT TYPE I ,
USAGE TYPE MSEG-MENGE ,
END OF TY_WB2_V_MKPF_MSEG2_COPY .
Internal Tables Begin with IT_
Work Area Begin with WA_ *
*Internal Table Declaration.
*DATA: IT_MARC TYPE STANDARD TABLE OF TY_MARC ,
WA_MARC TYPE TY_MARC .
*DATA: IT_MARA TYPE STANDARD TABLE OF TY_MARA ,
WA_MARA TYPE TY_MARA .
DATA: IT_MATERIAL TYPE STANDARD TABLE OF TY_ZV_OLR3_MARACKT ,
WA_MATERIAL TYPE TY_ZV_OLR3_MARACKT .
DATA: IT_MBEW TYPE STANDARD TABLE OF TY_MBEW ,
WA_MBEW TYPE TY_MBEW .
*DATA: IT_MKPF TYPE STANDARD TABLE OF TY_MKPF ,
WA_MKPF TYPE TY_MKPF .
*DATA: IT_MSEG TYPE STANDARD TABLE OF TY_MSEG ,
WA_MSEG TYPE TY_MSEG .
DATA: IT_VIEW TYPE STANDARD TABLE OF TY_WB2_V_MKPF_MSEG2 ,
WA_VIEW TYPE TY_WB2_V_MKPF_MSEG2 .
DATA: IT_VIEW_COPY TYPE STANDARD TABLE OF TY_WB2_V_MKPF_MSEG2_COPY ,
WA_VIEW_COPY TYPE TY_WB2_V_MKPF_MSEG2_COPY ,
IT_VIEW_TMP TYPE STANDARD TABLE OF TY_WB2_V_MKPF_MSEG2_COPY ,
WA_VIEW_TMP TYPE TY_WB2_V_MKPF_MSEG2_COPY .
Data(Workfield) Begin with W_ *
Data Declaration
Work field declaration - used in program
DATA: W_PERIOD TYPE S031-SPMON.
DATA: W_INDEX TYPE SY-TABIX .
DATA: W_QTY_TOT TYPE MENGE_D .
DATA: TOT_USE_TMP TYPE MENGE_D ,
TOT_USE TYPE MENGE_D ,
W_COUNT TYPE I .
RANGES: RO_DATE FOR SY-DATUM .
Parameters Begin with PR_ *
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS: PR_WERKS TYPE MARC-WERKS OBLIGATORY ,
PR_MTART TYPE MARA-MTART OBLIGATORY ,
PR_SPART TYPE MARA-SPART OBLIGATORY ,
PR_MATNR TYPE MARA-MATNR .
Select Options Begin with SO_ *
SELECT-OPTIONS: SO_SPMON FOR W_PERIOD .
SELECTION-SCREEN END OF BLOCK blk1 .
At selection-screen *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_SPMON-LOW.
PERFORM F4_HELP.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR SO_SPMON-HIGH.
PERFORM F4_HELP.
*& Form F4_HELP
Text-F4 Help for Month
-Taken from standard SAP program RMCS0F0M.
FORM F4_HELP .
DATA: BEGIN OF MF_DYNPFIELDS OCCURS 1 .
INCLUDE STRUCTURE DYNPREAD .
DATA: END OF MF_DYNPFIELDS .
DATA: MF_RETURNCODE LIKE SY-SUBRC ,
MF_MONTH LIKE ISELLIST-MONTH,
MF_HLP_REPID LIKE SY-REPID .
FIELD-SYMBOLS: <MF_FELD> .
*Worth reading screen
GET CURSOR FIELD MF_DYNPFIELDS-FIELDNAME.
APPEND MF_DYNPFIELDS.
MF_HLP_REPID = SY-REPID.
DO 2 TIMES.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = MF_HLP_REPID
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = MF_DYNPFIELDS
EXCEPTIONS
INVALID_ABAPWORKAREA = 01
INVALID_DYNPROFIELD = 02
INVALID_DYNPRONAME = 03
INVALID_DYNPRONUMMER = 04
INVALID_REQUEST = 05
NO_FIELDDESCRIPTION = 06
UNDEFIND_ERROR = 07.
IF SY-SUBRC = 3.
*Current screen is a range image
MF_HLP_REPID = 'SAPLALDB'.
ELSE.
READ TABLE MF_DYNPFIELDS INDEX 1.
*Underscores replaced by Blanks
TRANSLATE MF_DYNPFIELDS-FIELDVALUE USING '_ '.
EXIT.
ENDIF.
ENDDO.
IF SY-SUBRC = 0.
*The internal format conversion
CALL FUNCTION 'CONVERSION_EXIT_PERI_INPUT'
EXPORTING
INPUT = MF_DYNPFIELDS-FIELDVALUE
IMPORTING
OUTPUT = MF_MONTH
EXCEPTIONS
ERROR_MESSAGE = 1.
IF MF_MONTH IS INITIAL.
*Initial month => Proposal value of akt. Date deduced
MF_MONTH = SY-DATLO(6).
ENDIF.
CALL FUNCTION 'POPUP_TO_SELECT_MONTH'
EXPORTING
ACTUAL_MONTH = MF_MONTH
IMPORTING
SELECTED_MONTH = MF_MONTH
RETURN_CODE = MF_RETURNCODE
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 01
HOLIDAY_CALENDAR_NOT_FOUND = 02
MONTH_NOT_FOUND = 03.
IF SY-SUBRC = 0 AND MF_RETURNCODE = 0.
CALL FUNCTION 'CONVERSION_EXIT_PERI_OUTPUT'
EXPORTING
INPUT = MF_MONTH
IMPORTING
OUTPUT = MF_DYNPFIELDS-FIELDVALUE.
COLLECT MF_DYNPFIELDS.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
DYNAME = MF_HLP_REPID
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = MF_DYNPFIELDS
EXCEPTIONS
INVALID_ABAPWORKAREA = 01
INVALID_DYNPROFIELD = 02
INVALID_DYNPRONAME = 03
INVALID_DYNPRONUMMER = 04
INVALID_REQUEST = 05
NO_FIELDDESCRIPTION = 06
UNDEFIND_ERROR = 07.
ENDIF.
ENDIF.
ENDFORM. " F4_HELP
S T A R T O F S E L E C T I O N *
START-OF-SELECTION .
PERFORM CONVERT_MMYYYY_TO_DDMMYYY.
PERFORM GET_DATA.
*& Form CONVERT_MMYYYY_TO_DDMMYYY
Text-In Selection Screen we give date in MM.YYYY format
This cannot be passed to standard table.
Hence first convert it to DD.MM.YYYY format.
FORM CONVERT_MMYYYY_TO_DDMMYYY .
DATA: LW_VAR TYPE I . "LW-Local Workfield
DATA: LW_DATE1 TYPE SY-DATUM ,
LW_DATE2 TYPE SY-DATUM .
DATA: LW_STR_LOW TYPE STRING,
LW_STR_LOW1 TYPE STRING,
LW_STR_LOW2 TYPE STRING.
DATA: LW_STR_HIGH TYPE STRING,
LW_STR_HIGH1 TYPE STRING,
LW_STR_HIGH2 TYPE STRING.
LW_STR_LOW1 = SO_SPMON-LOW+0(4).
LW_STR_LOW2 = SO_SPMON-LOW+4(2).
CONCATENATE LW_STR_LOW1 LW_STR_LOW2 '01' INTO LW_STR_LOW.
LW_DATE1 = LW_STR_LOW.
*WRITE LW_DATE1.
LW_STR_HIGH1 = SO_SPMON-HIGH+0(4).
LW_STR_HIGH2 = SO_SPMON-HIGH+4(2).
IF LW_STR_HIGH2 = '01' OR
LW_STR_HIGH2 = '03' OR
LW_STR_HIGH2 = '05' OR
LW_STR_HIGH2 = '07' OR
LW_STR_HIGH2 = '08' OR
LW_STR_HIGH2 = '10' OR
LW_STR_HIGH2 = '12'.
CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '31' INTO LW_STR_HIGH.
LW_DATE2 = LW_STR_HIGH.
WRITE LW_DATE2.
ELSEIF LW_STR_HIGH2 = '04' OR
LW_STR_HIGH2 = '06' OR
LW_STR_HIGH2 = '09' OR
LW_STR_HIGH2 = '11'.
CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '30' INTO LW_STR_HIGH.
LW_DATE2 = LW_STR_HIGH.
WRITE LW_DATE2.
*Logic to check for Leap Year:-
*For all years that are multiples of 100,we need to test if its divisible by 400
*(instead of 4).If yes, then we can be sure that the year is a Leap Year.
ELSEIF LW_STR_HIGH2 = '02'.
*Begin:-To check for Leap Year when February.
LW_VAR = LW_STR_HIGH1 MOD 100.
IF LW_VAR EQ 0.
LW_VAR = LW_STR_HIGH1 MOD 400.
IF LW_VAR EQ 0.
CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '29' INTO LW_STR_HIGH.
LW_DATE2 = LW_STR_HIGH.
WRITE LW_DATE2.
ELSE.
CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '28' INTO LW_STR_HIGH.
LW_DATE2 = LW_STR_HIGH.
WRITE LW_DATE2.
ENDIF.
ELSEIF LW_VAR NE 0.
LW_VAR = LW_STR_HIGH1 MOD 4.
IF LW_VAR EQ 0.
CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '29' INTO LW_STR_HIGH.
LW_DATE2 = LW_STR_HIGH.
WRITE LW_DATE2.
ELSE.
CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '28' INTO LW_STR_HIGH.
LW_DATE2 = LW_STR_HIGH.
WRITE LW_DATE2.
ENDIF.
ENDIF.
*End:-To check for Leap Year when February.
ENDIF.
*Since we have low and high dates in two different strings,they directly
*cannot be passed to standard table (MSEG).So we first get them into RO_DATE.
RO_DATE-SIGN = 'I'.
RO_DATE-OPTION = 'BT'.
RO_DATE-LOW = LW_DATE1.
RO_DATE-HIGH = LW_DATE2.
APPEND RO_DATE.
ENDFORM. " CONVERT_MMYYYY_TO_DDMMYYY
*& Form GET_DATA
Text
FORM GET_DATA .
**Select fired on MARC to get only those materials of whose plant has been
**given on Selection Screen.
IF PR_MATNR EQ ''.
SELECT MATNR WERKS
FROM MARC
INTO TABLE IT_MARC
WHERE WERKS EQ PR_WERKS.
ELSE.
SELECT MATNR WERKS
FROM MARC
INTO TABLE IT_MARC
WHERE MATNR EQ PR_MATNR AND
WERKS EQ PR_WERKS.
ENDIF.
**If records are found then get material type and division from MARA for
**materials got from MARC.
IF SY-SUBRC = 0.
SELECT MATNR MTART SPART
FROM MARA
INTO TABLE IT_MARA
FOR ALL ENTRIES IN IT_MARC
WHERE MATNR EQ IT_MARC-MATNR.
ENDIF.
**Filtering out those materials on the basis of material type and division
**that is given on Selection Screen.
LOOP AT IT_MARA INTO WA_MARA.
W_INDEX = SY-TABIX.
IF WA_MARA-MTART NE PR_MTART OR WA_MARA-SPART NE PR_SPART.
DELETE IT_MARA INDEX W_INDEX.
ELSE.
MOVE: PR_WERKS TO WA_MARA-WERKS.
MODIFY IT_MARA FROM WA_MARA TRANSPORTING WERKS.
CLEAR: WA_MARA.
ENDIF.
ENDLOOP.
*Select fired on view ZV_OLR3_MARACKT which results in above 3 steps together
IF PR_MATNR EQ ''.
SELECT MATNR WERKS MTART MAKTX SPART
FROM ZV_OLR3_MARACKT
INTO TABLE IT_MATERIAL
WHERE WERKS EQ PR_WERKS AND
MTART EQ PR_MTART AND
SPART EQ PR_SPART.
ELSE.
SELECT MATNR WERKS MTART MAKTX SPART
FROM ZV_OLR3_MARACKT
INTO TABLE IT_MATERIAL
WHERE MATNR EQ PR_MATNR AND
WERKS EQ PR_WERKS AND
MTART EQ PR_MTART AND
SPART EQ PR_SPART.
ENDIF.
SORT IT_MARA BY MATNR.
SORT IT_MATERIAL BY MATNR.
*Select fired on MBEW to get Rate (VERPR) on basis of material and plant
*in IT_MARA.
SELECT MATNR BWKEY BWTAR VERPR
FROM MBEW
INTO TABLE IT_MBEW
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR EQ IT_MARA-MATNR AND
BWKEY EQ IT_MARA-WERKS.
SELECT MATNR BWKEY BWTAR VERPR
FROM MBEW
INTO TABLE IT_MBEW
FOR ALL ENTRIES IN IT_MATERIAL
WHERE MATNR EQ IT_MATERIAL-MATNR AND
BWKEY EQ IT_MATERIAL-WERKS.
IF SY-SUBRC = 0.
Do Nothing.
ENDIF.
**Select fired on MKPF to get Document Number on basis of period given on
**selection screen.
SELECT MBLNR MJAHR BUDAT
FROM MKPF
INTO TABLE IT_MKPF
WHERE BUDAT IN RO_DATE.
**If records are found then pass Document Number (MBLNR) to MSEG Table.
IF SY-SUBRC = 0.
SELECT MBLNR MJAHR ZEILE BWART MENGE MEINS MATNR
FROM MSEG
INTO TABLE IT_MSEG
FOR ALL ENTRIES IN IT_MKPF
WHERE MBLNR EQ IT_MKPF-MBLNR AND
BWART IN ('261','262','601','602').
SORT IT_MSEG BY BWART MATNR.
ENDIF.
*Select fired on View WB2_V_MKPF_MSEG2 to get required common fields of
*Table MKPF and MSEG.Also above commented coded is thus avoided.
SELECT MBLNR
MJAHR
BUDAT
ZEILE_I
BWART_I
MENGE_I
MEINS_I
MATNR_I
WERKS_I
FROM WB2_V_MKPF_MSEG2
INTO TABLE IT_VIEW
WHERE BUDAT IN RO_DATE AND
BWART_I IN ('261','262','601','602') AND
WERKS_I EQ PR_WERKS.
*If records are found then read table MARA for which existing records
*are moved to copy table.
IF SY-SUBRC EQ 0.
SORT IT_VIEW BY MATNR_I.
LOOP AT IT_VIEW INTO WA_VIEW.
W_INDEX = SY-TABIX.
READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = WA_VIEW-MATNR_I.
READ TABLE IT_MATERIAL INTO WA_MATERIAL WITH KEY MATNR = WA_VIEW-MATNR_I.
IF SY-SUBRC NE 0.
DELETE IT_VIEW INDEX W_INDEX.
ELSE.
MOVE-CORRESPONDING: WA_VIEW TO WA_VIEW_COPY.
MOVE: WA_VIEW-BUDAT+0(4) TO WA_VIEW_COPY-FYEAR,
WA_VIEW-BUDAT+4(2) TO WA_VIEW_COPY-MONTH.
APPEND WA_VIEW_COPY TO IT_VIEW_COPY.
CLEAR WA_VIEW_COPY.
ENDIF.
CLEAR: WA_VIEW,WA_MARA.
CLEAR: WA_VIEW,WA_MATERIAL.
ENDLOOP.
ENDIF.
*Sorting on basis of material year and month,processing event will be triggered
*at end of month.
SORT IT_VIEW_COPY BY MATNR_I FYEAR MONTH.
*On basis of movement type (BWART),calculation of exact quantity of material
*used in a particular month.(Processing Event used here)
LOOP AT IT_VIEW_COPY INTO WA_VIEW_COPY.
MOVE WA_VIEW_COPY TO WA_VIEW_TMP.
IF WA_VIEW_COPY-BWART_I = '261' OR WA_VIEW_COPY-BWART_I = '601'.
W_QTY_TOT = W_QTY_TOT + WA_VIEW_COPY-MENGE_I.
ENDIF.
IF WA_VIEW_COPY-BWART_I = '262' OR WA_VIEW_COPY-BWART_I = '602'.
W_QTY_TOT = W_QTY_TOT - WA_VIEW_COPY-MENGE_I.
ENDIF.
AT END OF MONTH.
W_COUNT = W_COUNT + 1.
TOT_USE = TOT_USE + W_QTY_TOT.
MOVE: W_QTY_TOT TO WA_VIEW_TMP-MENGE_I,
W_COUNT TO WA_VIEW_TMP-COUNT .
TOT_USE TO WA_VIEW_TMP-USAGE .
APPEND WA_VIEW_TMP TO IT_VIEW_TMP.
CLEAR: WA_VIEW_TMP,W_QTY_TOT,W_COUNT."TOT_USE.
ENDAT.
CLEAR: WA_VIEW_COPY,WA_VIEW_TMP.
ENDLOOP.
SORT IT_VIEW_TMP BY MATNR_I.
IF PR_MTART EQ 'FERT'.
SELECT MATNR BWKEY BWTAR VERPR
FROM MBEW
INTO TABLE IT_MBEW
FOR ALL ENTRIES IN IT_VIEW_TMP
WHERE MATNR EQ IT_VIEW_TMP-MATNR_I AND
BWTAR EQ 'NEW VEH' AND
BWKEY EQ IT_VIEW_TMP-WERKS_I.
ELSEIF PR_MTART EQ 'HALB'.
SELECT MATNR BWKEY BWTAR VERPR
FROM MBEW
INTO TABLE IT_MBEW
FOR ALL ENTRIES IN IT_VIEW_TMP
WHERE MATNR EQ IT_VIEW_TMP-MATNR_I AND
BWTAR EQ 'M&M' AND
BWKEY EQ IT_VIEW_TMP-WERKS_I.
ELSEIF PR_MTART EQ 'ZHLB'.
SELECT MATNR BWKEY BWTAR VERPR
FROM MBEW
INTO TABLE IT_MBEW
FOR ALL ENTRIES IN IT_VIEW_TMP
WHERE MATNR EQ IT_VIEW_TMP-MATNR_I AND
BWTAR EQ 'LOCAL' AND
BWKEY EQ IT_VIEW_TMP-WERKS_I.
ENDIF.
DATA: STRING TYPE STRING.
IF SY-SUBRC = 0.
SORT IT_MBEW BY MATNR.
WRITE: 20 SY-VLINE,49 SY-VLINE,70 SY-VLINE COLOR 4.
WRITE: 05'MATNR' ,40'PERIOD',60'QUANTITY'.
WRITE:SY-ULINE.
LOOP AT IT_VIEW_TMP INTO WA_VIEW_TMP.
WRITE: 20 SY-VLINE, 49 SY-VLINE,70 SY-VLINE.
CONCATENATE WA_VIEW_TMP-MONTH '.' WA_VIEW_TMP-FYEAR INTO STRING.
TOT_USE_TMP = WA_VIEW_TMP-MENGE_I.
AT END OF MONTH.
TOT_USE = TOT_USE + TOT_USE_TMP.
W_COUNT = W_COUNT + 1.
WRITE: / WA_VIEW_TMP-MATNR_I,STRING,TOT_USE_TMP,W_COUNT.
CLEAR W_COUNT.
ENDAT.
AT END OF MATNR_I.
WRITE: SY-ULINE.
W_COUNT = W_COUNT + 1.
WRITE: / WA_VIEW_TMP-MATNR_I,STRING,TOT_USE,W_COUNT.
CLEAR TOT_USE.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " GET_DATA
Above the way i want the output has not come properly so am sending it again:
Material 2.2007 4.2007 5.2007 8.2007 9.2007 Total Count
Mat A 2 1 0 0 0 3 2
Mat B 0 0 3 1 2 7 3
Message was edited by:
Rahul Bhat
Message was edited by:
Rahul Bhat
Similar Messages
-
How do you display the horizontal display button in iMovie 11
Can anybody tell me how to display the horizontal display button in Imovie 11 to display the project in one horizontal timeline as opposed to multiple rows?
It is in the top right corner of the Project pane - next to the Marker Buttons. It looks like 3 gray squares.
-
CONVERT ROWS INTO COLUMNS IN INTERNAL TABLE
Hi Experts,
I want to convert rows into coloumns in final internal table.
How to do that one. Can any one help me its very urgent.
Regards,
PBS.hi,
Find the below code for changing rows into colums.
data: begin of itab1 occurs 0,
fld,
end of itab1.
data: begin of itab2 occurs 0,
fld1,
fld2,
fld3,
end of itab2.
itab1-fld = 1.
append itab1.
itab1-fld = 2.
append itab1.
itab1-fld = 3.
append itab1.
read table itab1 index 1.
if sy-subrc eq 0.
itab2-fld1 = itab1-fld.
endif.
read table itab1 index 2.
if sy-subrc eq 0.
itab2-fld2 = itab1-fld.
endif.
read table itab1 index 3.
if sy-subrc eq 0.
itab2-fld3 = itab1-fld.
endif.
append itab2.
loop at itab1.
write:/ itab1.
endloop.
loop at itab2.
write:/ itab2.
endloop.
refer the below link for further information
internal table rows to columns
in the final display list how can i change rows to columns and vice versa -
How to determine the number of rows to be displayed in a report
hello experts,
Has anyone ever come across this requirement before? Before a report finishes being executed and before it displays the results, is there a way to determine the number of rows to be displayed as the result?
Many thanks in advance.
Regards,
InmaHello Arun,
Thanks for your reply but do you know which method I should use for this purpose if I use the table interface?
Thanks,
Inma -
Is it possible to change the number of rows to be displayed in adf query ?
Hello,
is it possible to change the number of rows that are displayed in an adf query similar to an adf form ?
I need to display approx 5 rows per column instead of displaying all the fields in a single column ? Thanks.Thanks , how do you add in the code ,is it something like follows :
<af:query id="qryId1" headerText="Search" disclosed="true"
value="#{bindings.ImplicitViewCriteriaQuery.queryDescriptor}"
model="#{bindings.ImplicitViewCriteriaQuery.queryModel}"
queryListener="#{bindings.ImplicitViewCriteriaQuery.processQuery}"
queryOperationListener="#{bindings.ImplicitViewCriteriaQuery.processQueryOperation}">
<af:inputText value="#{bindings.PrtDesc.inputValue}" label="Desc"
required="#{bindings.PrtDesc.hints.mandatory}"
columns="#{bindings.PrtDesc.hints.displayWidth}"
maximumLength="#{bindings.PrtDesc.hints.precision}"
shortDesc="#{bindings.PrtDesc.hints.tooltip}" id="it3">
<f:validator binding="#{bindings.PrtDesc.validator}"/>
</af:inputText>
<af:column>
<af:outputtext/>
<af:outputtext/>
</af:column>
</af:query> -
Query to convert Row to column - Re-posting
Hi all,
i am re-posting the same requirement, please do the needful.
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarMost repeated question in the forum..
SQL> select id,max(ltrim(sys_connect_by_path(val,','),',')) res
2 from (select id,val,
3 row_number() over(partition by id order by val) rn
4 from tb_row_2_col)
5 start with rn = 1
6 connect by prior rn = rn -1
7 and prior id = id
8 group by id;
ID RES
1 col1,col2,col3
2 col4,col5<br>
Message was edited by:
jeneesh
Check here for variations.. -
Query to convert Row to column
Hi all,
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarOr look for aggregation techniques against the forum helping by the search feature (top-right of the current page).
Nicolas. -
Converting Rows into Column in Oracle 10g
Hi All,
I m using Oracle Version 10.1.0.2.0 - Production
I have requirement to convert rows into column wise as per the following:
My Query is:
WITH t
AS ( SELECT 'A' AS x, 100 AS y FROM DUAL
UNION ALL
SELECT 'B',200 FROM DUAL
SELECT X, Y
FROM t;
X Y
A 100
B 200
My Requirement is
A B
100 200
So any one could help me that how I resolve this.
Regards,
PrasantaDear frank,
Thanks for your support,.
It's working fine for static cases.If the first column is dynamic then how come i will resolve it.
Example:
Create table mytab (ID_C Varchar2(15),Value_N Number);
Records Population into MyTab table is dynamic.
Insert into mytab values('HO',5000);
Insert Into mytab values('PG1',2400);
Insert Into mytab values('PG2',3000);
Insert Into mytab values('PG3',800);
Commit;
SQL> Select * From MyTab;
IDC_ ValueN_
HO 5000
PG1 2400
PG2 3000
PG3 800
Then My expected result will be as follows
HO PG1 PG2 PG3
5000 2400 3000 800
Thanks and Regards,
Prasanta -
How to convert row into column
Hi All,
My oracle apps version is r12 and db is 10 and i am using Bi publisher version 10g.
Is it possible to convert row into column in Rtf template,
My Query is
SELECT distinct pvs.vendor_site_code,sum(aia.invoice_amount)
FROM ap_invoices_all aia, po_vendors po, po_vendor_sites_all pvs
WHERE aia.org_id = pvs.org_id
AND aia.vendor_id = po.vendor_id
AND aia.vendor_site_id = pvs.vendor_site_id
AND aia.org_id=204
group by pvs.vendor_site_code
And output is like this
Vendor sitecode Invoiceamt
EAM-ERS 79240
STAR GATE - PAY 3245902.31
UPS - HQ 10792040.9
Like this
So in template i need the output like this
Vendor sitecode EAM-ERS STAR GATE - PAY UPS - HQ
Invoiceamt 79240 3245902.31 10792040.9
I tried to achieve the output using sql query but by hardcoding only i have achieved it, so i have tried to convert directly in RTF template.
can any one tell me is it possible.
And if new project is added from the front end ie(now the query will produce 4 rows but now in template i have created only three columns)
Is it possible to add a new column dynamically.
Can any one please guide me and tell me is there any example.
Thanks & regards
SrikkanthTake a look at this post: http://blogs.oracle.com/roller-ui/bsc/spider.jsp?entry=MT%3aENTRY%3a5001
Thanks,
Bipuser -
Number of rows to be displayed in Compensation Planning iView in ECM
Hi Experts,
I want to increase a number of rows to be displayed in the Compensation Planning iView in ECM from 5 to 10. How do I do that? Thanks!
AnthonyWe can set the numnber of rows to be displayed by using the standard table UI of java web dynpro. Thanks!
-
How to convert rows into columns with decode function
Hi,
How to convert rows into columns with the help of decode function in oracle.
thanks and regards
P Prakashsay
col1 col2
1 10
2 20
3 30
then use
select col1,
sum(decode(col2,10,10)) "new1"
sum(decode(col2,20,20))"new2"
sum(decode(col2,30,30))"new3"
from table_name
group by col1;
we used sum u can use ny function if wont u have to give the column name i.e col2 name also
so i think u got it nw
regards -
Convert rows into columns nad vice versa in 10g
how to convert rows into columns in 10g??
Qwerty wrote:
see below for rows to column case
SQL> WITH t as
2 (
3 SELECT 'US' test_string FROM DUAL UNION
4 SELECT 'AMERICA' FROM DUAL UNION
5 SELECT'HOLLYWOOD' FROM DUAL UNION
6 SELECT 'WASHINGTON' FROM DUAL
7 )
8 select ltrim (sys_connect_by_path(test_string,','),',') test_string
9 from (
10 SELECT row_number() over(order by test_string) rno, test_string
11 FROM t)
12 WHERE connect_by_isleaf = 1 and rownum=1
13 connect by rno = prior rno+1;
TEST_STRING
AMERICA,HOLLYWOOD,US,WASHINGTONI hope you can do it for column to rows now.That's not really rows to columns. That's rows to a column, which is more commonly called string aggregation.
Rows to columns (or pivot) is more like:
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' test_string FROM DUAL UNION
4 SELECT 'AMERICA' FROM DUAL UNION
5 SELECT'HOLLYWOOD' FROM DUAL UNION
6 SELECT 'WASHINGTON' FROM DUAL
7 )
8 --
9 select max(decode(rn,1,test_string)) as col_1
10 ,max(decode(rn,2,test_string)) as col_2
11 ,max(decode(rn,3,test_string)) as col_3
12 ,max(decode(rn,4,test_string)) as col_4
13* from (select test_string, row_number() over (order by test_string) as rn from t)
SQL> /
COL_1 COL_2 COL_3 COL_4
AMERICA HOLLYWOOD US WASHINGTON
SQL>And columns to rows (or unpivot) is like:
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
4 )
5 --
6 select col_1 as col from t union all
7 select col_2 from t union all
8 select col_3 from t union all
9* select col_4 from t
SQL> /
COL
US
AMERICA
HOLLYWOOD
WASHINGTONor...
SQL> ed
Wrote file afiedt.buf
1 WITH t as
2 (
3 SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
4 )
5 --
6 select decode(rownum,1,col_1,2,col_2,3,col_3,4,col_4) as col
7* from t, (select * from dual connect by rownum <= 4)
SQL> /
COL
US
AMERICA
HOLLYWOOD
WASHINGTON
SQL> -
When I display the view-formula command , the information in the cell displays vertically and it is very hard to read. I want it to go back to the horizontal display I have had all along. Thanks
Allan:
Sorry, I forgot to mention that I am working with Excel for Mac. -
Converting rows to collums with out using pivot ?
Hi,
Is it possible to convert the rows to collums ,and collums to rows wit out using pivot table?
Tqhi,
Its not possible to convert rows to columns, columns to rows out of pivot.
In table view ther will be column and measure only.
Regards,
VG -
Converting rows to columns using t-sql
Hi All,
I have a table with 3 columns, let say ID1 , ID2, Flag
My Source data looks like this..
ID1 ID2 Flag
1 1 0
1 2 0
1 3 0
2 7 0
2 8 1
2 9 0
4 5 0
Now My output should look like this..
ID1 Newcol1 NewFlag1 Newcol2 NewFlag2 Newcol3 NewFlag3
1 1 0
2 0 3
0
2 7 0
8 1 9
0
4 5 0
null null null null
Basically I want to convert rows to columns and to get above output I need t-SQL query.
Thanks in advance
RH
sqlYou can do it by this query:
declare @table table ( ID1 int, ID2 int, Flag int)
insert @table values ( 1,1,0 ),( 1,2,0 ),( 1,3,0 ),( 2,7,0 ),( 2,8,1 ),( 2,9,0 ),( 4,5,0 )
WITH cte1
AS ( SELECT Id1 ,
ROW_NUMBER() over (partition by ID1 order by ID1 ) as Sequence ,
ID2 ,
Flag
FROM @table
cte2
AS ( SELECT Id1 ,
ColumnTitle + LTRIM(RTRIM(STR(Sequence))) AS ColumnTitle ,
ColumnData
FROM cte1 UNPIVOT ( ColumnData FOR ColumnTitle IN ( [ID2], [Flag] ) ) AS UP
SELECT Id1 ,
[ID21] FirstID2 ,
[Flag1] FirstFlag ,
[ID22] SecondID2 ,
[Flag2] SecondFlag ,
[ID23] ThirdID2 ,
[Flag3] ThirdFlag
FROM cte2 PIVOT ( MAX(ColumnData) FOR ColumnTitle IN ( [ID21],
[Flag1],
[ID22],
[Flag2],
[ID23],
[Flag3] ) ) PV
If you want to know more detail, please visit my old article about this method:
T-SQL: PIVOT Ordered pair Columns
T-SQL e-book by TechNet Wiki Community
My Blog
My Articles
Maybe you are looking for
-
Cant get data from text file to print into Jtable
Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get th
-
Please add a no-sign-in feature for Muse in Enterprise
We install Muse in a multimedia lab for our university, in order to provide a wonderfully easy web design tool. Our students and faculty are put off and confused by the login screen and the inconvenience of needing to create an adobe ID before access
-
Forum Disclaimer: Please read this first
COMMUNITY FORUM CONTENT DISCLAIMER "Forum" means a discussion group, chat area, news group, blog, wiki, letter to SAP, its webmaster or employees or other service in connection with which you can upload, post, publish or otherwise transmit Content. Y
-
Journe air 1000 - video playback lags after converting to mjpeg
Hello, i have bought 2 journe air 1000 photo frames, and i'm trying to play video on them. To convert the video files i'm using the provided software that was in CD that came with the frame - ArcSoft video converter 2.5, which converts the video to a
-
Haskell State Monad Tutorial: looking for feedback
I've written a tutorial of sorts for the Haskell state monad because I found it hard to grok at first (at least as a Haskell noob coming from an imperative background) and none of the explanations that I've found dissect it this way. You can find it