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: 

Convert column into row for report display

Former Member
0 Kudos
355

My internal table data is like MATNR EBELN

41 140001

45 140001

45 140006

Now the requirement is to dispaly the data as below:

140001 140006

41 'A' 'B'

45

for comparsion analysis.

For material 41 and quot.140001 data needs to be dispalyed in 'A' area.Similarly for mat 41 and quot. 140006 data needs to displayed in 'B' area.Basically diagonally data shod match.Please suggest how to do it.

Thanks & regards.

24 REPLIES 24

Former Member
0 Kudos
204
DATA cnt TYPE i VALUE 10.

DATA : BEGIN OF i_data OCCURS 0,
matnr LIKE matnr,
END OF i_data.

SORT itab1 by EBELN MATNR.

cnt = 0.
LOOP AT itab1.
  AT NEW EBELN.
    cnt = cnt + 15.
    WRITE AT cnt itab1-EBELN.
  ENDAT.
ENDLOOP.

LOOP AT itab1.
  AT NEW MATNR.
    i_data-matnr = itab1-matnr.
    APPEND i_data.
    DELETE ADJACENT DUPLICATES FROM i_data.
  ENDAT.
ENDLOOP.


SKIP.

cnt = 0.
LOOP AT i_data.
  AT NEW MATNR.
    WRITE : 10 i_data-matnr.
    LOOP AT itab1 WHERE MATNR = i_data-matnr.
      cnt = cnt + 15.
      WRITE AT cnt itab1-ebeln.
    ENDLOOP.
    cnt = 0.
    SKIP.
  ENDAT.
ENDLOOP.

0 Kudos
204

Thanks for the prompt reply.As of now its solving my purpose,if any further help required will get back to you.Thanks u alot.

0 Kudos
204

Hi,

I have an additional requirement with this.Actually my internal table is like

EBELN MATNR KSCHl KBETR

140001 41 PB00 100

140001 45 PB00 80

140001 45 RA01 20

140001 45 FRA1 10

140006 45 PB00 30

140006 45 RA01 67

and so on.i.e with EBELN and matnr combination i need to get all the pricing conditions and amount.Now i need to display them as.

140001 140006

41 PB00-100 Null

45 PB00-80 PB00-30

RA01-20 RA01 -67

FRA1-10

I need to match EBELn with matnr then display the pricing conditions below that.I hope iam clear with the requirement.Plz help.

Message was edited by: Madhu Rana

0 Kudos
204

Try this:

DATA : BEGIN OF i_data OCCURS 0,
matnr LIKE matnr,
END OF i_data.

SORT itab1 by EBELN MATNR.

cnt = 0.
LOOP AT itab1.
  AT NEW EBELN.
    cnt = cnt + 15.
    WRITE AT cnt itab1-EBELN.
  ENDAT.
ENDLOOP.

LOOP AT itab1.
  AT NEW MATNR.
    i_data-matnr = itab1-matnr.
    APPEND i_data.
    DELETE ADJACENT DUPLICATES FROM i_data.
  ENDAT.
ENDLOOP.


SKIP.

cnt = 0.
cnt2 = 0.
LOOP AT i_data.
  AT NEW MATNR.
    WRITE : 10 i_data-matnr.
    LOOP AT itab1 WHERE MATNR = i_data-matnr.
      cnt = 15.
      AT NEW ebeln.
      IF cnt2 = 0.
        cnt2 = cnt2 + 1.
      ELSE.
         cnt = 45.
      ENDIF.
      ENDAT.
      SKIP.
      WRITE AT cnt itab1-kschi, '-' , itab1-kbetr.
    ENDLOOP.
    cnt = 0.
    SKIP.
  ENDAT.
ENDLOOP.

Ps: Reward points if helpful.

0 Kudos
204

hi

u can do it in alv in the following way

data: lt_fieldcat type lvc_t_fcat,

ls_fieldcat type lvc_s_fcat.

field-symbols: <dyn_tab> type table

data: ref_tab type ref to data

loop at itab

ls_fieldcat-fieldname = itab-ebeln.

ls_fieldcat-col_text = itab-ebeln.

append ls_fieldcat to lt_fieldcat.

endloop.

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = lt_fldcat

importing

ep_table = ref_tab.

assign ref_tab->* to <dyn_tab>.

*******filling dynamic table*******

field-symbols: <wa_tab> type any, <FS> TYPE ANY,

<FS1> TYPE ANY.

data: wa_ref type ref to data

CREATE OBJECT WA_REF LIKE LINE OF <DYN_TAB>.

ASSIGN WA_REF->* TO <WA_TAB>.

DATA VAR(30).

loop at itab into wa.

CONCATENATE WA-MATNR WA-KSCHI WA-KBETR INTO VAR

MOVE VAR TO <FS1>.

ASSIGN component itab-ebeln of <WA_TAB> TO <FS>.

<FS> = <FS1>.

APPEND WA TO ITAB.

END LOOP.

********FOR DISPLAY*********

REUSE_ALV_GRID_DISPLAY

(pass <dyn_tab> in the table).

0 Kudos
204

Hi,

Iam not well versed with object oriented concept in ABAP.when i tried to execute ur code,syntax error is coming: CREATE OBJECT WA_REF LIKE LINE OF <DYN_TAB>,like is not recognised.Plz suggest the change.

Thanks & Regards

0 Kudos
204

Try this...


DATA cnt TYPE i VALUE 10.
DATA cnt2 TYPE i VALUE 10.
DATA flag TYPE i VALUE 0.

DATA : BEGIN OF i_data OCCURS 0,
matnr LIKE matnr,
END OF i_data.

SORT itab1 by EBELN MATNR.

cnt = 0.
LOOP AT itab1.
  AT NEW EBELN.
    cnt = cnt + 20.
    WRITE AT cnt itab1-EBELN.
  ENDAT.
ENDLOOP.

LOOP AT itab1.
  AT NEW MATNR.
    i_data-matnr = itab1-matnr.
    APPEND i_data.
    DELETE ADJACENT DUPLICATES FROM i_data.
  ENDAT.
ENDLOOP.


SKIP.

cnt = 0.
cnt2 = 0.
LOOP AT i_data.
flag = 0.
  AT NEW MATNR.
    WRITE : 10 i_data-matnr.
    LOOP AT itab1 WHERE MATNR = i_data-matnr.
      cnt = 15.
      AT NEW ebeln.
      IF cnt2 = 0.
        cnt2 = cnt2 + 1.
      ELSE.
         cnt = 50.
      ENDIF.
      ENDAT.
      IF flag = 1 AND cnt = 50.
        BACK.
      ENDIF.
      WRITE AT cnt itab1-ebeln.
      IF flag = 0.
        RESERVE 1 LINES.
      ENDIF.
      flag = 1.
      SKIP.
      WRITE AT cnt itab1-kschi, '-' , itab1-kbetr.
    ENDLOOP.
    cnt = 0.
    SKIP.
  ENDAT.
ENDLOOP.

0 Kudos
204

sorry it is CREATE DATA not Create object

u can replace it like this

CREATE DATA WA_REF LIKE LINE OF <DYN_TAB>,

0 Kudos
204

The program is giving me dump in CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE.Is there any other parameter which needs to be apssed.

0 Kudos
204

can u tell me exactly what dump it is. description

0 Kudos
204

Hi Madhu,

Can you please tell what is the dump message?

Thanks & Regards,

Siri.

0 Kudos
204

Hi,

Error is Program " " not found. When i debug the prog ,inside the method there is perform statement( perform (l_form) in program (l_name)) which needs form name and prog name ,there prog name is blank so it gives dump.

0 Kudos
204

hi not a problem,

this error generally comes if u do some error in building fieldcat and trying to create dynamic int table.

pls check fieldcat that all the fields u r building should compulsorily from a table or structure.

or els u just post ur coding. i will check and correct the program and send it to u

0 Kudos
204

Hi,

I am mailing u the whole code.But when iam doing the same thing in other program method is working fine.Fieldcat i am buliding is same in both cases.

&----


*& Report ZMM_PC1 *

*& *

&----


*& *

*& *

&----


REPORT ZMM_PC1 NO STANDARD PAGE HEADING LINE-SIZE 255

.

TYPE-POOLS: SLIS.

&----


*& Type Declarations

&----


TYPES : BEGIN OF TY_EKKO,

EBELN LIKE EKKO-EBELN, "Purchase Order No.

SUBMI LIKE EKKO-SUBMI, "Collective No.

LIFNR LIKE EKKO-LIFNR, "Vendor

END OF TY_EKKO.

TYPES: BEGIN OF TY_EKPO,

EBELN LIKE EKKO-EBELN, "Purchase Order No.

EBELP LIKE EKPO-EBELP, "Item No.

SUBMI LIKE EKKO-SUBMI, "Collective No.

LIFNR LIKE EKKO-LIFNR, "Vendor

MATNR LIKE EKPO-MATNR, "Material No.

NETPR LIKE EKPO-NETPR, "Net Price

ZWERT LIKE EKPO-ZWERT, "Target value in document currency

TXZ01 LIKE EKPO-TXZ01, "Material text

KTMNG LIKE EKPO-KTMNG, "Quantity

MEINS LIKE EKPO-MEINS, "Unit of Quantity

END OF TY_EKPO.

TYPES: BEGIN OF TY_MATERIAL,

MATNR LIKE MARA-MATNR, "Material

MAKTX LIKE MAKT-MAKTX, "Material text

KTMNG LIKE EKPO-KTMNG, "Quantity

END OF TY_MATERIAL.

TYPES : BEGIN OF TY_PRICING,

EBELN LIKE EKPO-EBELN,

MATNR LIKE EKPO-MATNR,

KNUMH LIKE KONP-KNUMH,

KSCHL LIKE KONP-KNUMH,

KBETR LIKE KONP-KBETR,

END OF TY_PRICING.

TYPES : BEGIN OF TY_FINAL,

EBELN LIKE EKPO-EBELN,

SUBMI LIKE EKKO-SUBMI,

LIFNR LIKE EKKO-LIFNR,

MATNR LIKE EKPO-MATNR,

TXZ01 LIKE EKPO-TXZ01,

NETPR LIKE EKPO-NETPR,

ZWERT LIKE EKPO-ZWERT,

KTMNG LIKE EKPO-KTMNG,

MEINS LIKE EKPO-MEINS,

KNUMH LIKE KONP-KNUMH,

KSCHL LIKE KONP-KNUMH,

KBETR LIKE KONP-KBETR,

END OF TY_FINAL.

&----


*& FieldCatalog declarations

&----


DATA: LT_FIELDCAT TYPE LVC_T_FCAT,

LS_FIELDCAT TYPE LVC_S_FCAT.

FIELD-SYMBOLS: <DYN_TAB> TYPE TABLE.

DATA: REF_TAB TYPE REF TO DATA.

&----


*& Internal Table Declarations

&----


DATA: IT_EKKO TYPE STANDARD TABLE OF TY_EKKO WITH HEADER LINE.

DATA: IT_EKPO TYPE STANDARD TABLE OF TY_EKPO WITH HEADER LINE.

DATA: IT_MATERIAL TYPE STANDARD TABLE OF TY_MATERIAL WITH HEADER LINE.

DATA: IT_PRICING TYPE STANDARD TABLE OF TY_PRICING WITH HEADER LINE.

DATA: IT_FINAL TYPE STANDARD TABLE OF TY_FINAL WITH HEADER LINE.

DATA: WA TYPE TY_FINAL.

&----


*& Variable Declarations

&----


DATA: L_VAKEY LIKE KONH-VAKEY,

L_KNUMH LIKE KONH-KNUMH.

&----


*& Selection-Screen

&----


SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECTION-SCREEN: SKIP 1.

SELECTION-SCREEN: BEGIN OF LINE.

SELECTION-SCREEN : COMMENT 5(25) TEXT-T01.

PARAMETERS: P_EKORG LIKE EKKO-EKORG.

SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN: SKIP 1.

SELECTION-SCREEN: BEGIN OF LINE.

SELECTION-SCREEN : COMMENT 5(25) TEXT-T02.

PARAMETERS: P_SUBMI LIKE EKKO-SUBMI.

SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN: SKIP 1.

SELECTION-SCREEN: BEGIN OF LINE.

SELECTION-SCREEN : COMMENT 5(25) TEXT-T03.

PARAMETERS: P_EBELN LIKE EKKO-EBELN.

SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN: SKIP 1.

SELECTION-SCREEN: BEGIN OF LINE.

SELECTION-SCREEN : COMMENT 5(25) TEXT-T04.

PARAMETERS: P_LIFNR LIKE LFA1-LIFNR.

SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN: END OF BLOCK B1.

&----


*& Start of Selection

&----


START-OF-SELECTION.

SELECT EBELN SUBMI LIFNR FROM EKKO INTO CORRESPONDING FIELDS OF TABLE

IT_EKKO WHERE EKORG = P_EKORG AND SUBMI = P_SUBMI .

LOOP AT IT_EKKO.

SELECT EBELN EBELP MATNR NETPR ZWERT TXZ01 KTMNG MEINS FROM EKPO INTO

CORRESPONDING FIELDS OF IT_EKPO WHERE EBELN = IT_EKKO-EBELN.

MOVE-CORRESPONDING IT_EKKO TO IT_EKPO.

APPEND IT_EKPO.

CLEAR IT_EKPO.

ENDSELECT.

ENDLOOP.

SORT IT_EKPO BY EBELN MATNR.

LOOP AT IT_EKPO.

CONCATENATE IT_EKPO-EBELN IT_EKPO-EBELP INTO L_VAKEY.

SELECT SINGLE KNUMH FROM KONH INTO L_KNUMH WHERE VAKEY = L_VAKEY.

SELECT KNUMH KSCHL KBETR FROM KONP INTO CORRESPONDING FIELDS OF

IT_PRICING WHERE KNUMH = L_KNUMH.

MOVE IT_EKPO-EBELN TO IT_PRICING-EBELN.

MOVE IT_EKPO-MATNR TO IT_PRICING-MATNR.

APPEND IT_PRICING.

CLEAR IT_PRICING.

ENDSELECT.

CLEAR L_KNUMH.

CLEAR L_VAKEY.

ENDLOOP.

*************Build Final Table****************************

SORT IT_PRICING BY EBELN MATNR.

LOOP AT IT_PRICING.

READ TABLE IT_EKPO WITH KEY EBELN = IT_PRICING-EBELN MATNR =

IT_PRICING-MATNR.

IF SY-SUBRC = 0.

MOVE IT_EKPO-EBELN TO IT_FINAL-EBELN.

MOVE IT_EKPO-SUBMI TO IT_FINAL-SUBMI.

MOVE IT_EKPO-LIFNR TO IT_FINAL-LIFNR.

MOVE IT_EKPO-MATNR TO IT_FINAL-MATNR.

MOVE IT_EKPO-TXZ01 TO IT_FINAL-TXZ01.

MOVE IT_EKPO-NETPR TO IT_FINAL-NETPR.

MOVE IT_EKPO-ZWERT TO IT_FINAL-ZWERT.

MOVE IT_EKPO-KTMNG TO IT_FINAL-KTMNG.

MOVE IT_EKPO-MEINS TO IT_FINAL-MEINS.

MOVE IT_PRICING-KSCHL TO IT_FINAL-KSCHL.

MOVE IT_PRICING-KNUMH TO IT_FINAL-KNUMH.

MOVE IT_PRICING-KBETR TO IT_FINAL-KBETR.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDIF.

ENDLOOP.

*****************************************************************

*Your code starts from here

******************************************************************

LOOP AT IT_FINAL.

LS_FIELDCAT-FIELDNAME = IT_FINAL-EBELN.

LS_FIELDCAT-COLTEXT = IT_FINAL-EBELN.

APPEND LS_FIELDCAT TO LT_FIELDCAT.

ENDLOOP.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_FIELDCAT

IMPORTING

EP_TABLE = REF_TAB.

ASSIGN REF_TAB->* TO <DYN_TAB>.

******filling dynamic table*******

FIELD-SYMBOLS: <WA_TAB> TYPE ANY, <FS> TYPE ANY,

<FS1> TYPE ANY.

DATA: WA_REF TYPE REF TO DATA.

DATA: GD_LAYOUT TYPE SLIS_LAYOUT_ALV.

CREATE DATA WA_REF LIKE LINE OF <DYN_TAB>.

ASSIGN WA_REF->* TO <WA_TAB>.

DATA VAR(30).

LOOP AT IT_FINAL INTO WA.

CONCATENATE WA-MATNR WA-KSCHL INTO VAR.

MOVE VAR TO <FS1>.

*ASSIGN component itab1-ebeln of <WA_TAB> TO <FS>.

<FS> = <FS1>.

APPEND WA TO IT_FINAL.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

  • i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

  • i_callback_user_command = 'USER_COMMAND'

  • i_grid_title = outtext

  • is_layout = gd_layout

IT_FIELDCAT = LT_FIELDCAT

  • it_special_groups = gd_tabgroup

  • IT_EVENTS = GT_XEVENTS

I_SAVE = 'X'

  • is_variant = z_template

TABLES

T_OUTTAB = <DYN_TAB>

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.

  • " DISPLAY_ALV_REPORT

0 Kudos
204

u replace the following code in filling dynamic table.

also u declared it_final as table with header line. as u r declaring wa no need to give with header line. u just remove that. and try replacing with following code.

LOOP AT IT_FINAL INTO WA.

CONCATENATE WA-MATNR WA-KSCHL INTO VAR.

assign VAR TO <FS1>.

ASSIGN component wa-ebeln of structure <WA_TAB> TO <FS>.

<FS> = <FS1>.

APPEND WA TO IT_FINAL.

ENDLOOP.

0 Kudos
204

Hi,

Thanks for all your help,but there is still some problem.Nw the fieldcatalog is not compatible to ALV grid function module.Dump is coming : Type conflict when calling function module "REUSE_ALV_GRID_DISPLAY".

The system tried to pass internal table "LT_FIELDCAT" to

parameter "IT_FIELDCAT", but a type conflict occurred be

formal and the actual parameter.

Help from ur side is highly appreciable.

0 Kudos
204

call the fn module REUSE_SLV_GRID_DISPLAY_LVC

instead of above because the fieldcat is LVC type

0 Kudos
204

Hi,

Now the program is executing.But im not getting the desired result.

I am only getting EBELN as

1400005 1400006

My output needs to be

1400005 | 1400006

41 PB00 | 'Null'

45 PB00 | PB00

RA01 | RA01

FRA1

Mased on EBELN and matnr pricing comditons needs to be dispalyed under that EBELN and in front of that MATNR.

0 Kudos
204

LOOP AT IT_FINAL INTO WA.

CONCATENATE WA-MATNR WA-KSCHL INTO VAR.

assign VAR TO <FS1>.

ASSIGN component wa-ebeln of structure <WA_TAB> TO <FS>.

<FS> = <FS1>.

*********APPEND <WA_tab> TO <dyn_tab>.

ENDLOOP.

u replace the above statement in ur program.

0 Kudos
204

Sorry for troubling u so much but i am badly stuck with it.

See here is my code for dynamic table append:

fieldcat has 2 distinct EBELn i.e 1400005 and 1400006.

Now it_final2 has data like this:

EBELN MATNR KSCHL

140005 0041 PB00

140005 0045 PBOO

140005 0045 RA01

140005 0045 FRA1

140006 0045 PB00

140006 0045 FRA1.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_FIELDCAT

IMPORTING

EP_TABLE = REF_TAB.

ASSIGN REF_TAB->* TO <DYN_TAB>.

******filling dynamic table*******

FIELD-SYMBOLS: <WA_TAB> TYPE ANY, <FS> TYPE ANY,

<FS1> TYPE ANY.

DATA: WA_REF TYPE REF TO DATA.

DATA: GD_LAYOUT TYPE SLIS_LAYOUT_ALV.

CREATE DATA WA_REF LIKE LINE OF <DYN_TAB>.

ASSIGN WA_REF->* TO <WA_TAB>.

DATA VAR(30).

sort it_final2 by ebeln matnr.

LOOP AT IT_FINAL2 INTO WA.

CONCATENATE WA-MATNR WA-KSCHL INTO VAR.

assign VAR TO <FS1>.

ASSIGN component wa-ebeln of structure <WA_TAB> TO <FS>.

<FS> = <FS1>.

APPEND <WA_TAB> TO <dyn_tab>.

ENDLOOP.

0 Kudos
204

s it is correct, now excecute it and check

0 Kudos
204

I am not getting the results.

Its showing:

140005 | 140006

000000

000000

000000

000000

000000 000000

000000 000000

matnr is not getting displayed as well as the KSCHL

0 Kudos
204

u just put a break point at

loop at it_final2 to wa

and check whether data is coming ther or not

if matnr is ther in wa or not.

debug and see, o/p will come.

the main purpose to get columns as headings is solved no?

0 Kudos
204

Hi,

That solved the purpose to show the EBELN colun wise but main thing isstill left.To show MATNR row wise and then dispaly the pricing types based on the combination of MATNR and EBELN(Basically it would build a matrix kind of thing).But Thanks alot for ur help