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

SELECTING FIELDS

former_member713390
Participant
0 Likes
3,664

HI EXPERT

I want to display all their statuses in one row for each FGRU1(Table CRFH-FGRU1)

We have different status in the CRFH table for each FGRU1 I want to display all the different status that exist for each FGRU1 in a row And to know how many of each status there are

For example, for each FGRU1 = 1000 we have 4 to status 03, we have 2 to status 01, a status of 02 and none of status 04.

Thank you for your help

14 REPLIES 14
Read only

Sandra_Rossi
Active Contributor
3,567

Do you mind telling us what FGRU1 is? Any table name, any transaction code, any name of business object to help us understand your question?

Read only

former_member1716
Active Contributor
3,567

afsane_salehi,

Spend some time in the details of Question which can improve your chances of getting appropriate answers.

Regards!

Read only

former_member713390
Participant
3,567

im sorry satishkumarbalasubramanian sandra.rossi

I edited my question

We have different status in the CRFH table for each FGRU1 I want to display all the different status that exist for each FGRU1 in a row And to know how many of each status there are

For example, for each FGRU1 = 1000 we have 4 to status 03, we have 2 to status 01, a status of 02 and none of status 04.

Grouping key1 status01 status02 status03 status04

1000 2 1 4 0

Read only

Sandra_Rossi
Active Contributor
3,567

You may at least first use

select FGRU1, STATUS, count(*) as count from CRFH group by FGRU1, STATUS ...

to obtain something like

FGRU1  STATUS  COUNT
1000   03      4
1000   01      2
1000   02      1

and then transpose by ABAP to obtain

Grouping key1  status01  status02  status03  status04
1000           2         1         4         0

Is there any issue with this approach?

Read only

former_member713390
Participant
0 Likes
3,567

sandra.rossi

Thank you, can you explain more about how to display this in its final form?

Read only

Sandra_Rossi
Active Contributor
3,567

You loop at the lines, and depending on the value of STATUS, you fill the corresponding column:

CHECK select_result IS NOT INITIAL.
sort select_result by FGRU1.
DATA(previous_line) = select_result[ 1 ].
alv_line = VALUE #( FGRU1 = previous_line-FGRU1 ).
LOOP AT select_result REFERENCE INTO DATA(line)
  IF line->FGRU1 <> previous_line-FGRU1.
    APPEND alv_line TO alv_table.
    alv_line = VALUE #( FGRU1 = line->FGRU1 ).
  ENDIF.
  CASE line->status.
    WHEN '03'.
      alv_line-status03 = line->count.
    WHEN '01'.
      alv_line-status01 = line->count.
...
Read only

former_member713390
Participant
0 Likes
3,567

Sandra Rossi

Honestly, this is very hard for me, I did not understand much It can be written in a simpler way

Read only

former_member713390
Participant
0 Likes
3,567

Sandra Rossi

I can not understand these parts. What is previous_line? What is line? What is alv_line? And where do these come from and what do they do?

DATA(previous_line) = select_result[ 1 ].
alv_line = VALUE #( FGRU1 = previous_line-FGRU1 ).
LOOP AT select_result REFERENCE INTO DATA(line)
  IF line->FGRU1 <> previous_line-FGRU1.
    APPEND alv_line TO alv_table.
    alv_line = VALUE #( FGRU1 = line->FGRU1 ).
Read only

Sandra_Rossi
Active Contributor
3,567

Where is COUNT(*)?

I was supposing you wanted to output the result to an ALV. But you are outputting data to a tree (ABAP List). So rename ALV_LINE and ALV_TABLE to WA_NODE and IT_NODE.

Let's write it in obsolete ABAP (of the importance to provide all information with the initial question, because I have now to spend time to rewrite my first answer):

CHECK it_final IS NOT INITIAL.
sort it_final by FGRU1.
DATA(previous_final) = it_final[ 1 ].
wa_node = VALUE #( ).
LOOP AT it_final INTO wa_final.
  IF wa_node IS NOT INITIAL.
    wa_node-name = 'XXXX'.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
  ENDIF.
  IF wa_final-FGRU1 <> previous_line-FGRU1.
    wa_node-text = wa_final-FGRU1.
    wa_node-level = 2.
    wa_node-name = 'XXXX'.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
    wa_node-level = 3.
  ENDIF.
  CASE wa_final-status.
    WHEN 'Z1'.
      wa_node-text = wa_final-count.
    WHEN 'Z2'.
      wa_node-text1 = wa_final-count.
    WHEN 'Z3'.
      wa_node-text2 = wa_final-count.
  ...
  previous_final = wa_final.
ENDLOOP.
IF wa_node IS NOT INITIAL.
  wa_node-name = 'XXXX'.
  APPEND wa_node TO it_node.
  CLEAR wa_node.
ENDIF.

NB: do you really need to use this obsolete technology RS_TREE_LIST_DISPLAY? See that later, first solve your current issue.

Read only

former_member713390
Participant
0 Likes
3,567

HI sandra.rossi

Thank you for posting I changed the code as follows. But I get an error and the code does not execute (error photo attached)pic.png

DATA :IT_FINAL TYPE STANDARD TABLE OF ZFINAL ,
      WA_FINAL TYPE ZFINAL.

DATA:  IT_NODE TYPE STANDARD TABLE OF SNODETEXT,
       WA_NODE TYPE SNODETEXT.


SELECT-OPTIONS : S_FGRU1 FOR WA_FINAL-FGRU1,
                 S_FGRTXT FOR WA_FINAL-FGRTXT,
                 S_STOWK FOR WA_FINAL-STOWK .


START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM CRATE_NODE .
PERFORM CONSTRUCT_TREE.
FORM GET_DATA.


  SELECT FGRU1 FGRTXT  STATUS COUNT(*)
       INTO TABLE IT_FINAL
    FROM CRFH
    INNER JOIN TCF13 ON CRFH~FGRU1 = TCF13~FGRUA
    WHERE FGRU1 IN S_FGRU1
    AND FGRTXT IN S_FGRU1
    AND STOWK IN S_STOWK
    GROUP BY FGRU1 FGRTXT  STATUS.

  ENDFORM.
 FORM CRATE_NODE .

 CHECK IT_FINAL IS NOT INITIAL.
SORT IT_FINAL BY FGRU1.
DATA(PREVIOUS_FINAL) = IT_FINAL[ 1 ].
WA_NODE = VALUE #( ).
LOOP AT IT_FINAL INTO WA_FINAL.
  IF WA_NODE IS NOT INITIAL.
    WA_NODE-NAME = 'GROUPING KEY1'.
    APPEND WA_NODE TO IT_NODE.
    CLEAR WA_NODE.
  ENDIF.
  IF WA_FINAL-FGRU1 <> PREVIOUS_FINAL-FGRU1.
    WA_NODE-TEXT = WA_FINAL-FGRU1.
    WA_NODE-TLEVEL = 2.
    WA_NODE-NAME = WA_FINAL-FGRU1.
    APPEND WA_NODE TO IT_NODE.
    CLEAR WA_NODE.
    WA_NODE-TLEVEL = 3.
  ENDIF.
  CASE WA_FINAL-STATUS.
    WHEN 'Z1'.
      WA_NODE-TEXT = WA_FINAL-COUNT1.
    WHEN 'Z2'.
      WA_NODE-TEXT1 = WA_FINAL-COUNT1.
    WHEN 'Z3'.
      WA_NODE-TEXT2 = WA_FINAL-COUNT1.
    WHEN 'Z3'.
      WA_NODE-TEXT2 = WA_FINAL-COUNT1.
    ENDCASE.
  PREVIOUS_FINAL = WA_FINAL.
ENDLOOP.
IF WA_NODE IS NOT INITIAL.
  WA_NODE-NAME = 'XXXX'.
  APPEND WA_NODE TO IT_NODE.
  CLEAR WA_NODE.
ENDIF.

ENDFORM.


FORM CONSTRUCT_TREE.
  CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
      NODETAB            = IT_NODE .


  ENDFORM.
Read only

Sandra_Rossi
Active Contributor
3,567

I just tested the algorithm and the debug shows that it's not what you expect.

I'd like to know why you are interested to know why RS_TREE_CONSTRUCT fails if the data is wrong anyway.

Please adjust the algorithm.

If other people are interested to answer, here is the missing code to test the code autonomously:

TYPES: BEGIN OF zfinal,
         fgru1  TYPE crfh-fgru1,
         fgrtxt TYPE tcf13-fgrtxt,
         status TYPE crfh-status,
         count1 TYPE i,
         stowk  TYPE crfh-stowk,
       END OF zfinal.

...

  it_final = VALUE #(
      ( fgru1 = '1000' fgrtxt = 'aaaa' status = 'Z3' count1 = 4 )
      ( fgru1 = '1000' fgrtxt = 'aaaa' status = 'Z1' count1 = 2 )
      ( fgru1 = '1000' fgrtxt = 'aaaa' status = 'Z2' count1 = 1 )
      ).
Read only

Sandra_Rossi
Active Contributor
3,567

For information, concerning RS_TREE_LIST_DISPLAY (although it's not your primary question), I can make it produce this:

Grouping key1                  Status01   Status02   Status03   Status04
│
│
├──────1000                           2          1          4          0
└──────2000                           2          1          4          0

With this code:

DATA: it_node TYPE STANDARD TABLE OF snodetext.

it_node = VALUE #(
( name = 'XXXX' tlevel = 1 text = 'Grouping key1' tlength = 30 text1 = 'Status01' tlength1 = 10
  text2 = 'Status02' tlength2 = 10 text3 = 'Status03' tlength3 = 10 text4 = 'Status04' tlength4 = 10 )
( name = 'XXXX' tlevel = 2 text = '1000'          tlength = 30 text1 = '2'        tlength1 = 10
  text2 = '1'        tlength2 = 10 text3 = '4'        tlength3 = 10 text4 = '0'        tlength4 = 10 )
( name = 'XXXX' tlevel = 2 text = '2000'          tlength = 30 text1 = '2'        tlength1 = 10
  text2 = '1'        tlength2 = 10 text3 = '4'        tlength3 = 10 text4 = '0'        tlength4 = 10 )
).

CALL FUNCTION 'RS_TREE_CONSTRUCT'
  TABLES
    nodetab = it_node.

CALL FUNCTION 'RS_TREE_LIST_DISPLAY'.
Read only

former_member713390
Participant
3,567

Thank you for all your help.sandra.rossi

I wrote it, the problem was solved, but I do not know why my Level 3 data is not displayed, even though I debugged it, it will be ENTRI in IT_NODE, but when I exit, my Level 3 is completely empty.

DATA :IT_FINAL TYPE STANDARD TABLE OF ZFINAL ,
      WA_FINAL TYPE ZFINAL ,
      WA_OUT TYPE ZFINAL,
      WA_MV TYPE ZFINAL.

DATA :IT_DATA  TYPE STANDARD TABLE OF ZCRFHF,
      WA_DATA  TYPE  ZCRFHF.

TYPES: BEGIN OF TY_GRP_KEY,
         FGRU1 TYPE CRFH-FGRU1,
       END OF TY_GRP_KEY.
DATA :IT_GRPKEY TYPE TABLE OF TY_GRP_KEY,
      WA_GRPKEY TYPE TY_GRP_KEY.



DATA:  IT_NODE TYPE STANDARD TABLE OF SNODETEXT,
       WA_NODE TYPE SNODETEXT.

SELECT-OPTIONS : S_FGRU1 FOR WA_FINAL-FGRU1,
                 S_FGRTXT FOR WA_FINAL-FGRTXT,
                 S_STOWK FOR WA_FINAL-STOWK .

START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM CRATE_NODE .
PERFORM CONSTRUCT_TREE.
PERFORM DISPLAY_TREE.



FORM GET_DATA.



    SELECT DISTINCT FGRU1
      FROM CRFH
      INTO TABLE IT_GRPKEY
      WHERE FGRU1 NE ' ' AND FGRU1 IN S_FGRU1.

  SELECT FGRU1 FGRTXT  STATUS
       INTO TABLE IT_DATA
    FROM CRFH
    INNER JOIN TCF13 ON CRFH~FGRU1 = TCF13~FGRUA
    WHERE FGRU1 IN S_FGRU1
    AND FGRTXT IN S_FGRU1
    AND STOWK IN S_STOWK.
    SORT IT_FINAL BY FGRU1.


DATA V_INDEX TYPE SY-TABIX.

    SORT IT_GRPKEY.

    LOOP AT IT_GRPKEY INTO WA_GRPKEY.
      READ TABLE IT_DATA INTO WA_DATA WITH KEY FGRU1 = WA_GRPKEY-FGRU1 BINARY SEARCH.
      IF WA_GRPKEY-FGRU1 = WA_DATA-FGRU1.
        MOVE-CORRESPONDING WA_DATA TO WA_MV.
        APPEND WA_MV TO IT_FINAL.
      ENDIF.
      IF SY-SUBRC = 0.
        V_INDEX = SY-TABIX.

        LOOP AT IT_DATA INTO WA_DATA WHERE FGRU1 = WA_GRPKEY-FGRU1.
          CASE WA_DATA-STATUS.
            WHEN 'Z1'.
              WA_OUT-STAUSZ1 = WA_OUT-STAUSZ1 + 1.
            WHEN 'Z2'.
              WA_OUT-STAUSZ2 = WA_OUT-STAUSZ2 + 1.
            WHEN 'Z3'.
              WA_OUT-STAUSZ3 = WA_OUT-STAUSZ3 + 1.
            WHEN 'Z4'.
              WA_OUT-STAUSZ4 = WA_OUT-STAUSZ4 + 1.
          ENDCASE.

          MODIFY IT_FINAL FROM WA_OUT INDEX V_INDEX TRANSPORTING STAUSZ1 STAUSZ2 STAUSZ3 STAUSZ4.
        ENDLOOP.

      ENDIF.

      CLEAR: WA_GRPKEY, WA_DATA, WA_OUT.
  ENDFORM.
 FORM CRATE_NODE .



  WA_NODE-TLEVEL = 1.
  WA_NODE-NAME   = 'PM TREE REPORT' .
  WA_NODE-NLENGTH = 20.
  APPEND WA_NODE TO IT_NODE.
    CLEAR WA_NODE.

      LOOP AT IT_FINAL INTO WA_FINAL.


  WA_NODE-TLEVEL = 2.
  WA_NODE-NAME   = WA_FINAL-FGRU1 .
  WA_NODE-NLENGTH = 20.

      WA_NODE-TEXT = ' 01'.
      WA_NODE-TLENGTH = 20.

      WA_NODE-TEXT1 = '02'.
      WA_NODE-TLENGTH1 = 20.


      WA_NODE-TEXT2  = '03'.
      WA_NODE-TLENGTH2 = 20.

      WA_NODE-TEXT3  = '04'.
      WA_NODE-TLENGTH3 = 20.


  APPEND WA_NODE TO IT_NODE.
    CLEAR WA_NODE.


    WA_NODE-TLEVEL = 3.
    WA_NODE-NAME   = WA_FINAL-STAUSZ1.
    WA_NODE-NLENGTH = 20.

    WA_NODE-TEXT1   = WA_FINAL-STAUSZ2.
    WA_NODE-TLENGTH1 = 20.

    WA_NODE-TEXT2   = WA_FINAL-STAUSZ3.
    WA_NODE-TLENGTH2 = 20.

    WA_NODE-TEXT3   = WA_FINAL-STAUSZ4.
    WA_NODE-TLENGTH3 = 20.

 APPEND WA_NODE TO IT_NODE.
    ENDLOOP.

ENDFORM.

FORM CONSTRUCT_TREE.
  CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
      NODETAB            = IT_NODE .

  ENDFORM.
FORM DISPLAY_TREE.
  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
      CALLBACK_PROGRAM = SY-REPID.
ENDFORM.<br>
Read only

Sandra_Rossi
Active Contributor
0 Likes
3,567

Nice, well played, and thanks for the feedback!

In debug, at level 3, look carefully at the contents of TEXT1, TEXT2. The numbers are right-adjusted and so the total length is above 20! (something like 75 = maximum possible).

To left-adjust, one way is to use a String Template:

    wa_node-tlevel = 3.
    wa_node-name   = |{ wa_final-stausz1 }|.
    wa_node-nlength = 20.

    wa_node-text1   = |{ wa_final-stausz2 }|.
    wa_node-tlength1 = 20.

    wa_node-text2   = |{ wa_final-stausz3 }|.
    wa_node-tlength2 = 20.

    wa_node-text3   = |{ wa_final-stausz4 }|.
    wa_node-tlength3 = 20.