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 INTERNAL TABLE

Former Member
0 Kudos

THIS IS MY PRGRAM I AM NOT GETTTING IT PLESE HELP

----


  • Includes *

----


*INCLUDE : *

----


  • Tables *

----


TABLES : pernr.

----


  • Tables *

----


*type-pools : slis.

----


  • Types Begin with TY_ *

----


TYPES :BEGIN OF ty_comp,

pernr TYPE pernr-pernr,

bukrs TYPE p0001-bukrs,

persa TYPE p0001-werks,

btrtl TYPE p0001-btrtl,

name1 TYPE t500p-name1,

btext TYPE t001p-btext,

num TYPE i,

END OF ty_comp.

*types : begin of ty_finalit,

*

*

  • end of ty_finalit.

----


  • Constants Begin with C_ *

----


*CONSTANTS: *

----


  • Data Begin with W_ *

----


DATA : w_lines TYPE i.

----


  • work area Begin with Wa_ *

----


DATA : wa_count TYPE ty_comp.

DATA wa_final TYPE ty_comp.

DATA : wa_fieldcat TYPE lvc_s_fcat. " to display field cat

DATA : wa_fieldcat1 TYPE lvc_s_fcat. " to display field cat

----


  • Infotypes ( HR Module Specific) *

----


INFOTYPES : 0001.

----


  • Internal tables Begin with IT_ *

----


DATA : it_comp TYPE STANDARD TABLE OF ty_comp.

DATA it_count TYPE STANDARD TABLE OF ty_comp.

DATA it_count1 TYPE STANDARD TABLE OF ty_comp.

DATA it_count_f TYPE STANDARD TABLE OF ty_comp.

DATA it_final_data TYPE STANDARD TABLE OF ty_comp.

DATA : it_fieldcat TYPE lvc_t_fcat .

DATA it_final1 TYPE STANDARD TABLE OF ty_comp.

DATA: it_table TYPE REF TO data.

----


  • Field Symbols Begin with FS_ *

----


FIELD-SYMBOLS: <fs_comp> TYPE ty_comp,

<fs_add> TYPE ty_comp .

FIELD-SYMBOLS: <fs_data> TYPE REF TO data.

*FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE..

----


  • Insert *

----


*INSERT : *

----


  • Select Options Begin with SO_ *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.

SELECT-OPTIONS :so_date FOR sy-datum NO-EXTENSION NO INTERVALS OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

----


  • Parameters Begin with PR_ *

----


*PARAMETERS : *

DATA w_container TYPE REF TO cl_gui_custom_container.

DATA w_grid TYPE REF TO cl_gui_alv_grid.

----


  • Initialisation *

----


INITIALIZATION.

SET SCREEN 100.

CREATE OBJECT w_container EXPORTING container_name = 'ELEMENT'.

  • *create object container exporting container_name = 'AREA'.

CREATE OBJECT w_grid EXPORTING i_parent = w_container.

----


  • At selection-screen *

----


AT SELECTION-SCREEN.

IF pnpbukrs IS INITIAL.

MESSAGE e003(zhr).

ENDIF.

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

  • S T A R T O F S E L E C T I O N *

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

START-OF-SELECTION.

SELECT t500pbukrs t500ppersa t001p~btrtl INTO CORRESPONDING FIELDS OF TABLE it_comp FROM

t500p INNER JOIN t001p ON t001pwerks = t500ppersa

WHERE t500p~bukrs IN pnpbukrs AND

t500p~persa IN pnpwerks.

SORT it_comp BY bukrs persa btrtl.

GET pernr.

rp_provide_from_last p0001 space so_date-low so_date-low.

wa_count-bukrs = p0001-bukrs.

wa_count-persa = p0001-werks.

wa_count-btrtl = p0001-btrtl.

wa_count-pernr = p0001-pernr.

IF wa_count-bukrs IS NOT INITIAL

OR wa_count-persa IS NOT INITIAL

OR wa_count-btrtl IS NOT INITIAL

OR wa_count-pernr IS NOT INITIAL .

APPEND wa_count TO it_count.

ENDIF.

*break sarang.

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

  • E N D O F S E L E C T I O N *

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

END-OF-SELECTION.

  • break sarang.

SORT it_count BY bukrs persa btrtl.

CLEAR wa_count.

LOOP AT it_count INTO wa_final.

ON CHANGE OF wa_final-btrtl.

it_count1[] = it_count[].

SORT it_count1 BY bukrs persa btrtl.

DELETE it_count1 WHERE btrtl NE wa_final-btrtl.

DESCRIBE TABLE it_count1 LINES w_lines.

wa_final-num = w_lines.

APPEND wa_final TO it_count_f.

ENDON.

ENDLOOP.

CLEAR wa_count.

*break sarang.

SELECT t500pbukrs t500pname1 t500ppersa t001pbtrtl t001p~btext

INTO CORRESPONDING FIELDS OF TABLE it_final_data

FROM t500p INNER JOIN t001p ON

t001pwerks = t500ppersa

FOR ALL entries IN it_count_f

WHERE t500p~bukrs EQ it_count_f-bukrs AND

t500p~persa EQ it_count_f-persa.

*break sarang.

CLEAR wa_final.

LOOP AT it_count_f INTO wa_final.

READ TABLE it_final_data INTO wa_count WITH KEY btrtl = wa_final-btrtl

bukrs = wa_final-bukrs

persa = wa_final-persa.

IF sy-subrc = 0.

*break sarang.

*wa_count-num = wa_final-num.

wa_final-btext = wa_count-btext.

wa_final-name1 = wa_count-name1.

APPEND wa_final TO it_final1.

ENDIF.

ENDLOOP.

CLEAR wa_count.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'NAME1'.

wa_fieldcat-coltext = text-001.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

*break sarang.

SORT it_final1 BY btext.

LOOP AT it_final1 INTO wa_count.

PERFORM fieldcat USING wa_count..

ENDLOOP.

ASSIGN it_table TO <fs_data>.

*FIELD-SYMBOLS: <fs_data> TYPE REF TO data.

FIELD-SYMBOLS: <fs_1> ,<fs1>.

FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.

FIELD-SYMBOLS: <dyntable> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <dynline> TYPE ANY , <dyn_wa> TYPE ANY.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = <fs_data>.

ASSIGN <fs_data>->* TO <fs_1>.

ASSIGN <fs_1> TO <fs_2>.

ASSIGN <fs_1> TO <dyntable>.

DATA: new_line TYPE REF TO data.

DATA w_field TYPE TY_COMP.

BREAK SARANG.

*

  • CREATE DATA new_line LIKE LINE OF <dyntable>. "Work Area"

  • ASSIGN new_line->* TO <dyn_wa>.

*

  • LOOP AT it_final1 INTO WA_COUNT.

  • ASSIGN COMPONENT WA_COUNT-NUM OF STRUCTURE <dyn_wa> TO <fs1>.

    • <fs1> = w_field.

*ASSIGN WA_COUNT TO <fs1>.

  • APPEND <dyn_wa> TO <dyntable>.

*

*ENDLOOP.

break sarang.

PERFORM display_data.

&----


*& Form fieldcat

&----


  • text

----


  • -->P_WA_COUNT text

----


FORM fieldcat USING p_wa_count TYPE ty_comp.

TRANSLATE p_wa_count-btrtl TO UPPER CASE.

TRANSLATE p_wa_count-btext TO UPPER CASE.

CLEAR wa_fieldcat.

READ TABLE it_fieldcat TRANSPORTING NO FIELDS WITH KEY coltext = p_wa_count-btext.

IF sy-subrc NE 0.

wa_fieldcat-fieldname = p_wa_count-btext.

wa_fieldcat-coltext = p_wa_count-btext.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

CLEAR wa_fieldcat1.

ENDIF.

ENDFORM. " fieldcat

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data .

SET SCREEN 100.

CALL METHOD w_grid->set_table_for_first_display

*exporting is_layout = wa_layout

CHANGING it_outtab = <dyntable>

it_fieldcatalog = it_fieldcat.

ENDFORM. " display_data

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'MYGUI'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

DATA ls_ucomm TYPE sy-ucomm.

ls_ucomm = sy-ucomm.

CASE ls_ucomm.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

7 REPLIES 7

hymavathi_oruganti
Active Contributor
0 Kudos

********FIELD-SYMBOLS: <fs_data> TYPE REF TO data.

REPLACE ABOVE LIKE BELOW

DATA: FS_DATA TYPE REF TO DATA.

FIELD-SYMBOLS: <fs_1> ,<fs1>.

FIELD-SYMBOLS: <dyntable> TYPE STANDARD TABLE.

FIELD-SYMBOLS: <dyn_wa> TYPE ANY.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = fs_data.

ASSIGN fs_data->* TO <DYNTABLE>.

DATA: NEW_LINE TYPE REF TO DATA.

CREATE DATA new_line LIKE LINE OF <dyntable>. "Work Area"

ASSIGN new_line->* TO <dyn_wa>.

LOOP AT it_final1 INTO WA_COUNT.

MOVE-CORRESPONDING WA_COUNT TO <DYN_WA>.

ASSIGN COMPONENT WA_COUNT-BTEXT OF STRUCTURE <dyn_wa> TO <fs1>.

ASSIGN WA_COUNT-NUM TO <fs>.

<FS1> = <FS>.

APPEND <dyn_wa> TO <dyntable>.

ENDLOOP.

0 Kudos

dear Hymavathi Oruganti

what is <fs>

sarangan

0 Kudos

i mean <fs> field-symbol.

sorry it was declared <fs_1> above rt!.

replace <fs> by <fs_1>.

0 Kudos

dear Hymavathi Oruganti

in <dyntable> the num part is not getting updated

sarangan r

0 Kudos

dear Hymavathi Oruganti

how to link <FS_1> and so that i can get the text and the num<DYN_WA>

0 Kudos

make sure that wa_count-num is not initial.

LOOP AT it_final1 INTO WA_COUNT.

MOVE-CORRESPONDING WA_COUNT TO <DYN_WA>.

ASSIGN COMPONENT WA_COUNT-BTEXT OF STRUCTURE <dyn_wa> TO <fs1>.

*ASSIGN WA_COUNT-NUM TO <fs_1>.

*<FS1> = <FS_1>.

<FS1> = WA_COUNT-NUM. (TRY LIKE THIS)

APPEND <dyn_wa> TO <dyntable>.

ENDLOOP.

Former Member
0 Kudos

Did you check the code sample from this: /people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

&

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

They works good.

Thanks & Regards.,

Ankur