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: 

Dynamic Field catalouge

rthoodi
Active Participant
0 Kudos

hi,

I am having data in the final itab like this.

___________________________

4111 1 a 3

2 b 4

3 c 5

4 d 6

4112 x 1 a

y 2 b

z 3 c

____________________________

i want to display this data in ALV like

________________________________________________________

4111 1 a 3 2 b 4 3 c 5 4 d 6

________________________________________________________

4112 x 1 a y 2 b z 3 c

___________________________________________________________

Whatever the data that 4111 header contain must be display in the same row of 4111 row dynamically in different columns, I have been trying since yesterday

Can anybody give with an example.

Iam very thankful to those who answered.

Reward points for every answer.

Thanks & Regards

RK

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello,

You first have to loop over your table to find the maximal number of columns.

Is this number known?

Then for each column you create a entry in the field catalog.

But the problem will be to create the new table for display...

Why don't you want to display it like that ?

4111 1 a 3

4111 2 b 4

4111 3 c 5

4111 4 d 6

Regards,

Walter

9 REPLIES 9

Former Member
0 Kudos

Hello,

You first have to loop over your table to find the maximal number of columns.

Is this number known?

Then for each column you create a entry in the field catalog.

But the problem will be to create the new table for display...

Why don't you want to display it like that ?

4111 1 a 3

4111 2 b 4

4111 3 c 5

4111 4 d 6

Regards,

Walter

0 Kudos

Hi,

4111 1 a 3

4111 2 b 4

4111 3 c 5

4111 4 d 6

display like above is not the actual requiremnt, because there are lot of header values, each having multiple items values, So one header values in one row along with its items details in column by column is required, like

4111 1 a 3 2 b 4 3 c 5 4 d 6

4112 x y z 1 2 3 4 r

4113 r k t u d i

output should be like this

Thanks & Regards

RK

0 Kudos

Hi RK,

First you have to calculate maximum columns/Fields in every execution of your program then you can use <b>cl_alv_table_create=>create_dynamic_table</b> to create your dynamic internal table.

Regards,

Hendy

0 Kudos

Hi,

As per my understanding, each header have multiple items. For example i have One shipment number and it has different packaging materials suppose 1003518 have two packaging materials 5001 and 5002 and another shipment 1003519 have 5002 and 5003. Quantity to be displayed in the packaging materials fields. U want to have the display as:

ShipmentNo. 5001 5002 5003

1003518 12 13

1003519 12 13

Please correct me if i am wrong.

If the requirement is same as the above, i can send u the code.

Regards

Kannaiah

0 Kudos

hi,

For every shipment no. there are pacaking materials like

1003518 5001

5002

1003519 5003

5004

5005

Then output should be like this

1003518 5001 5002

1003519 5003 5004 5005

this mean for every shipment packaging materials should be displayed in the same row of its shipment no.

Hope you understand the requirement.

Thanks & Regards

RK

0 Kudos

Hi,

Here u mean that for every new shipment number u want the packaging materials and shipment number in a row and their details in the columns.

Just check in SE38 with search term BCALVDND*TREE.

I hope this would suffice ur requirement.

Regards

Kannaiah

Former Member
0 Kudos

Hi,

you could also use the fm REUSE_ALV_HIERSEQ_LIST_DISPLAY and use two itabs. The one will be the final itab you have and the other will be a new itab containing only the values "4111" etc.

Therefore each entry of the final itab will be displayed under the "4111" value. If this helps inform me so that i can write in more detail.

More or less will be like:

___________________________

4111

1 a 3

2 b 4

3 c 5

___________________________

4112

x 1 a

y 2 b

___________________________

Regards,

Alexandros.

Former Member
0 Kudos

Hi,

U need to use the Field symbols for building the dynamic ALV.

Write the code like this:

<b>First select the data from the table for which u want to build the field catalog.</b>

<b>Loop that internal table and take one common field.</b>

SORT g_itab BY tknum vhilm.

DELETE ADJACENT DUPLICATES FROM g_itab COMPARING vhilm.

DESCRIBE TABLE g_itab LINES l_var.

l_i = '2'.

ls_alv_cat1-fieldname = 'TKNUM'.

ls_alv_cat1-col_pos = 1.

ls_alv_cat1-coltext ='ShipmentNo.'.

APPEND ls_alv_cat1 TO i_alv_cat1.

DATA: l_var4(10) TYPE c,

l_var5(10) TYPE c,

l_fieldname(20) TYPE c..

LOOP AT g_itab INTO wa_itab.

IF l_var >= 1.

CONDENSE wa_itab-vhilm NO-GAPS.

ls_alv_cat1-fieldname = wa_itab-vhilm. "l_fieldname.

ls_alv_cat1-col_pos = l_i.

ls_alv_cat1-coltext = wa_itab-vhilm.

ls_alv_cat1-do_sum ='X'.

APPEND ls_alv_cat1 TO i_alv_cat1.

CLEAR : ls_alv_cat1, l_fieldname.

l_i = l_i + 1.

ENDIF.

AT LAST.

ls_alv_cat1-fieldname = 'TOTAL'. "l_fieldname.

ls_alv_cat1-col_pos = l_i.

ls_alv_cat1-coltext = 'TOTAL'.

ls_alv_cat1-do_sum ='X'.

APPEND ls_alv_cat1 TO i_alv_cat1.

CLEAR : ls_alv_cat1, l_fieldname.

ENDAT.

SORT i_alv_cat1 BY fieldname.

DELETE ADJACENT DUPLICATES FROM i_alv_cat1.

ENDLOOP.

SORT i_alv_cat1 BY col_pos.

<b>Then create a dynamic table like below:</b>

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_alv_cat1

IMPORTING

ep_table = d_ref.

ASSIGN d_ref->* TO <f_fs>.

<b>Create a work area similar to field catalog.</b>

CREATE DATA gv_wa LIKE LINE OF <f_fs>.

ASSIGN gv_wa->* TO <fs_wa>.

<b>Put the data in final internal table to field catalog.</b>

LOOP AT g_final ASSIGNING <f_fs2>.

ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <f_fs2> TO <f_fs6>.

ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <fs_wa> TO <f_fs7>.

<f_fs7> = <f_fs6>.

CONDENSE <f_fs2>-vhilm NO-GAPS.

ASSIGN COMPONENT 'VHILM' OF STRUCTURE <f_fs2> TO <f_fs3>.

ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.

MOVE <f_fs3> TO l_var1.

ASSIGN COMPONENT l_var1 OF STRUCTURE <fs_wa> TO <f_fs5>.

<f_fs5> = <f_fs4>.

CLEAR total_tab-quantity.

READ TABLE total_tab WITH KEY tknum = <f_fs6>.

IF sy-subrc = 0.

ASSIGN total_tab-quantity TO <f_fs12>.

ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.

<f_fs13> = <f_fs12>.

ENDIF.

L_FILL = L_FILL + 1.

IF L_FILL = L_TOT.

ASSIGN L_TOTAL TO <f_fs12>.

ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.

<f_fs13> = <f_fs12>.

ENDIF.

AT END OF <f_fs2>-tknum.

<b>*Append the work area to final structure</b>

APPEND <fs_wa> TO <f_fs>.

CLEAR <fs_wa>.

ENDAT.

ENDLOOP.

<b>Display the field catalog using:</b>

CALL SCREEN 0100.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'ZVKS'.

SET TITLEBAR 'ZVKS'.

CHECK sy-ucomm IS INITIAL.

  • SET PF-STATUS 'LIST'.

  • SET TITLEBAR 'LIST'.

SORT g_scandata_tab BY tknum vhilm.

CREATE OBJECT g_custom_container_0100

EXPORTING container_name = g_container_0100

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5.

CREATE OBJECT g_alv_grid_0100

EXPORTING i_parent = g_custom_container_0100.

g_mylayout-grid_title = 'Display Scanning data'.

CALL METHOD g_alv_grid_0100->set_table_for_first_display

  • EXPORTING

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

it_outtab = <f_fs>

it_fieldcatalog = i_alv_cat1

  • IT_SORT =

  • IT_FILTER =

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

.

IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

CALL METHOD cl_gui_cfw=>dispatch.

CASE sy-ucomm.

WHEN 'EXIT'.

LEAVE TO SCREEN 0.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'CANCEL'.

LEAVE PROGRAM.

WHEN OTHERS.

ENDCASE.

CLEAR ok_code.

ENDMODULE. " USER_COMMAND_0100 INPUT

Regards

Kannaiah

rthoodi
Active Participant
0 Kudos

This message was moderated.