Application Development and Automation 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: 
Read only

Is it possible to make a transactional data only one row per customer number

Former Member
0 Kudos
1,280

How to make a transaction as one row only per customer? For example I have my internal table that needs to show the first order and the second order date of the customer. So my internal table details is like this:

But the outcome of my dynamic alv is like this:

For example in the customer no. "0001011111" row. Is it possible to just make it one row like:

Customer no.  1stOrder     LITERS1     2ndOrder     LITERS2 
0001011111    20180811       11        20180814       6

MY code is like this:

<code>DATA: new_table  TYPE REF TO data,
          new_line   TYPE REF TO data,
          alv_layout TYPE lvc_s_layo,
          alv        TYPE REF TO cl_gui_alv_grid.
    FIELD-SYMBOLS: <l_table> TYPE table,
                   <l_line>  TYPE any,
                   <l_field> TYPE any.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = it_fieldcat
      IMPORTING
        ep_table        = new_table.
    ASSIGN new_table->* TO <l_table>.
    CREATE DATA new_line LIKE LINE OF <l_table>.
    ASSIGN new_line->* TO <l_line>.
    SORT it_main2 BY kunnr.
    DATA(cpy_it_main) = it_main2.
    DATA(replicate_it_main) = it_main2.
    SORT replicate_it_main BY kunnr erdat1 vbeln.
    DELETE ADJACENT DUPLICATES FROM replicate_it_main COMPARING kunnr.
    SORT cpy_it_main BY kunnr vbeln.
    DELETE ADJACENT DUPLICATES FROM cpy_it_main COMPARING vbeln.
    LOOP AT replicate_it_main INTO DATA(wa_replicate).
      dateflag = wa_replicate-erdat1.
      DATA(cust) = wa_replicate-kunnr.
      DATA(x) = 0.
      DATA(y) = 0.
      LOOP AT it_main2 INTO wa_main2 WHERE kunnr = cust.
        DO 2 TIMES.
          dateflag2 = wa_main2-erdat1.
        ENDDO.
        ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <l_line> TO <l_field>.
        <l_field> = wa_main2-kunnr.
        ASSIGN COMPONENT 'NAME1' OF STRUCTURE <l_line> TO <l_field>.
        <l_field> = wa_main2-name1.
        ASSIGN COMPONENT 'KTEXT' OF STRUCTURE <l_line> TO <l_field>.
        <l_field> = wa_main2-ktext.
        ASSIGN COMPONENT 'MONTH' OF STRUCTURE <l_line> TO <l_field>.
        <l_field> = wa_main2-month.
        ASSIGN COMPONENT 'CGRP2' OF STRUCTURE <l_line> TO <l_field>.
        <l_field> = wa_main2-cgrp2.
        IF dateflag = dateflag2.
          ASSIGN COMPONENT 'ERDAT1' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-erdat1.
          ASSIGN COMPONENT 'BRAND1' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-brand1.
          ASSIGN COMPONENT 'LITER1' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-liter1.
          ASSIGN COMPONENT 'VOLUM1A' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-volum1a.
          ASSIGN COMPONENT 'VOLUM2A' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-volum2a.
          ASSIGN COMPONENT 'VOLUM3A' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-volum3a.
          x = 1.
        ELSE.
          ASSIGN COMPONENT 'ERDAT2' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-erdat1.
          ASSIGN COMPONENT 'BRAND2' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-brand1.
          ASSIGN COMPONENT 'LITER2' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-liter1.
          ASSIGN COMPONENT 'VOLUM1B' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-volum1a.
          ASSIGN COMPONENT 'VOLUM2B' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-volum2a.
          ASSIGN COMPONENT 'VOLUM3B' OF STRUCTURE <l_line> TO <l_field>.
          <l_field> = wa_main2-volum3a.
          y = 1.
        ENDIF.
        dateflag3 = wa_main2-erdat.
          INSERT <l_line> INTO TABLE <l_table>.
          CLEAR: <l_line>, wa_main2.
      ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Jelena_Perfiljeva
Active Contributor
1,121

The short answer is "you need to write the program accordingly".

For example, the screenshot shows for customer ....11 there are 2 records (2 top rows). One has "First Order Date" = 20180811 and second has a blank date. Then you're saying "oh, I just want one line" and show us a line with "First Order Date" = 20180811. Well, how did you decide that? You have 2 different records and based on some principle (not shared with us) you made a decision how they need to be combined into a single record.

Things get even more interesting with LITER1 field. The top screenshot shows 11 and 6. Then 6 simply disappears and the "desired line" shows 11. How did you arrive at this result?

So all you need to do is to write a program using whatever logic you've just applied. Collect the data in as many record as needed and then that's what's going to be displayed.

8 REPLIES 8
Read only

Jelena_Perfiljeva
Active Contributor
1,122

The short answer is "you need to write the program accordingly".

For example, the screenshot shows for customer ....11 there are 2 records (2 top rows). One has "First Order Date" = 20180811 and second has a blank date. Then you're saying "oh, I just want one line" and show us a line with "First Order Date" = 20180811. Well, how did you decide that? You have 2 different records and based on some principle (not shared with us) you made a decision how they need to be combined into a single record.

Things get even more interesting with LITER1 field. The top screenshot shows 11 and 6. Then 6 simply disappears and the "desired line" shows 11. How did you arrive at this result?

So all you need to do is to write a program using whatever logic you've just applied. Collect the data in as many record as needed and then that's what's going to be displayed.

Read only

0 Kudos
1,121

I'm trying to base it on the customer number. Since they have only one customer number.

Read only

Read only

0 Kudos
1,121

So? You've already mentioned that above. Not sure what this comment is supposed to mean, sorry... Is there a specific issue?

Read only

0 Kudos
1,121

For example in the customer no. "0001011111" row. The customer 0001011111 has two transaction, the first order and the second order. But the first row of the customer 0001011111 is only the first order and empty in the second order, then the 2nd row of the customer 0001011111 has empty 1st order but has 2nd order.How to make it one row like:

Customerno.1stOrder     LITERS1     2ndOrder     LITERS2 
0001011111 20180811       11        20180814      6
Read only

0 Kudos
1,121

Does my answer not explain how to do it? Is there a specific item that is not clear? Or do you just expect someone just to write the whole code for you? I'm confused...

Read only

matt
Active Contributor
0 Kudos
1,121

From the OP's second attempt at the question, which has now been removed:

Detailed Table

<code>customer   order date    price    matGrp
  1        01/01/18      100      001
  1        01/01/18      50       002
  1        02/02/18      50       003
  2        01/11/18      25       002
  2        02/22/18      50       002

The output table should be like this.

<code>customer   1st order   price    matGrp    2nd order   price   matGrp
   1       01/01/18    100      001       02/02/18    25      003
   1       01/01/18    50       002
   2       01/11/18    25       002       02/22/18    50      002

For example the customer no 1 has 3 transactions in the detailed table. In the first row of the output table is customer 1 then the 2nd column of the 1st row is the first order date of the customer in the detailed table which is "01/01/18" and the price and matgrp of that date. And in the 2nd order date column is the customer's second order date in the detailed table which is "02/02/18", the price and matgrp of the 2nd order is as follow as well. Next row will still be the customer 1 since he still has another transaction which falls at 1st order date, then the price and matGrp will just as follow. But since her doesn't have anymore 2nd order, it will just be blank. The 3rd row will be customer no. 2 and its first order will be the first order of its transaction in the detailed table, then the second order will also be the second order of the customer 2 from the detailed table.

Do you have any sample logic on how am i able to get the output table from the detailed table?

Read only

VenkatRamesh_V
Active Contributor
0 Kudos
1,121

Hi,

Try this logic.

TYPES: BEGIN OF ty_tab,
kunnr TYPE kna1-kunnr,
date1 TYPE sy-datum,
date2 TYPE sy-datum,
END OF ty_tab.
DATA: itab TYPE TABLE OF ty_Tab,
wa LIKE LINE OF itab,
lv_cycle TYPE i.

FIELD-SYMBOLS: <fs1> LIKE LINE OF itab,
<fs2> LIKE LINE OF itab.

START-OF-SELECTION.
DO 2 TIMES.
wa-kunnr = '1'.

IF sy-index ='2'.
wa-date2 = sy-datum.
ELSE.
wa-date1 = sy-datum.
ENDIF.
APPEND wa to itab.
CLEAR wa.
ENDDO.

LOOP AT itab ASSIGNING <fs2>.
AT NEW KUNNR.
CLEAR lv_cycle.
ENDAT.
ADD 1 to lv_cycle.

IF lv_cycle = '1'.
ASSIGN <fs2> TO <fs1>.
ELSE.
<fs1>-date2 = <fs2>-date2.
UNASSIGN <fs1>.
DELETE itab index sy-tabix.
ENDIF.

ENDLOOP.

Hope it helpful,

Regards,

Venkat.