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

populate values in data tab

Former Member
0 Likes
529

Hi, I have a table type: Ztable_type which has structure of Ztable_type_struct.

Ztable_type_struct has two fields:

fieldname type syuname

range_table type data. (this is table)

how could I insert data into this table type.

any snippets of code is appreciated.

4 REPLIES 4
Read only

Former Member
0 Likes
502

Hi Bijay ,

I think you are talking about Nested internal tables....

First enter data into the table range_table i.e. append some records into that table..

then add record in the table Ztable_type .

this is the way you enter records..

Below is sample example of nested internal table...It will help you to solve your problem...

TYPE-POOLS icon.

*Declaring Variables.
DATA :
   w_counter TYPE i VALUE 1.                             "Counter.

*Declaring Structure.
DATA :
   BEGIN OF fs_subject,
     subject(15) TYPE c,
     marks       TYPE i,
   END OF fs_subject,

   BEGIN OF fs_student,
     student_id  TYPE i,
     student_name(10) TYPE c,
     subjectall LIKE TABLE OF fs_subject,          " Nested table
   END OF fs_student.


*Creating Internal Table.
DATA :
  t_subject  LIKE STANDARD TABLE OF fs_subject,
  t_student  LIKE STANDARD TABLE OF fs_student.


*Inserting Records in nested Internal Table.
fs_subject-subject = 'HINDI'.
fs_subject-marks = '55'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'English'.
fs_subject-marks                   = '65'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Mathematics'.
fs_subject-marks  = '80'.
APPEND fs_subject TO t_subject.

fs_subject-subject           = 'Physics'.
fs_subject-marks  = '60'.
APPEND fs_subject TO t_subject.

fs_subject-subject             = 'Chemistry'.
fs_subject-marks  = '72'.
APPEND fs_subject TO t_subject.


*Inserting Records in outer Internal Table.
fs_student-student_id           = '0001'.
fs_student-student_name         = 'RAVI'.
fs_student-subjectall           = t_subject.
APPEND fs_student TO t_student.



*Inserting Records in nested Internal Table.
CLEAR fs_student.
fs_subject-subject              = 'Hindi'.
fs_subject-marks  = '30'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'English'.
fs_subject-marks  = '39'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Mathematics'.
fs_subject-marks  = '69'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Physics'.
fs_subject-marks  = '35'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Chemistry'.
fs_subject-marks  = '56'.
APPEND fs_subject TO t_subject.

*Inserting Records in outer Internal Table.
fs_student-student_id           = '0002'.
fs_student-student_name         = 'RADHA'.
fs_student-subjectall           = t_subject.
APPEND fs_student TO t_student.


*Inserting Records in nested Internal Table.
CLEAR fs_student.
fs_subject-subject              = 'Hindi'.
fs_subject-marks  = '78'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'English'.
fs_subject-marks  = '84'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Mathematics'.
fs_subject-marks  = '99'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Physics'.
fs_subject-marks   = '89'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Chemistry'.
fs_subject-marks   = '90'.
APPEND fs_subject TO t_subject.


*Inserting Records in outer Internal Table.
fs_student-student_id           = '0003'.
fs_student-student_name         = 'RAMA'.
fs_student-subjectall           = t_subject.
APPEND fs_student TO t_student.


*Inserting Records in nested Internal Table.
CLEAR fs_student.
fs_subject-subject              = 'Hindi'.
fs_subject-marks  = '45'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'English'.
fs_subject-marks  = '39'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Mathematics'.
fs_subject-marks   = '38'.
APPEND fs_subject TO t_subject.

fs_subject-subject              = 'Physics'.
fs_subject-marks   = '53'.
APPEND fs_subject TO t_subject.


fs_subject-subject              = 'Chemistry'.
fs_subject-marks  = '67'.
APPEND fs_subject TO t_subject.

*Inserting Records in outer Internal Table.
fs_student-student_id           = '0004'.
fs_student-student_name         = 'RAJESH'.
fs_student-subjectall           = t_subject.
APPEND fs_student TO t_student.



*Displying Records.
LOOP AT t_student INTO fs_student.
  WRITE :/ fs_student-student_id,
           fs_student-student_name.

  DO 5 TIMES.
    READ TABLE fs_student-subjectall INDEX w_counter INTO fs_subject.
    WRITE : 50 fs_subject-subject,
            80 fs_subject-marks.
    IF fs_subject-marks < 40.
      WRITE icon_led_red AS ICON .
    ELSE.
      WRITE icon_led_green AS ICON .
    ENDIF.                                        "IF fs_subject-marks
    WRITE :/.
    w_counter = w_counter + 1.
  ENDDO.

ENDLOOP.                                          "LOOP AT t_student

Best regards,

Brijesh

Read only

former_member156446
Active Contributor
0 Likes
502

Hi you can do it this way..


Ztable_type-range_table-<field1> = 'Value'.

modify/append  Ztable_type.

Read only

Former Member
0 Likes
502

Hi,

This might help you.

Data lv_tabname type string.

lv_tabname = 'SFLIGHT'.

create data range_table type table of (lv_tabname).

Read only

Former Member
0 Likes
502

Hi,

I think this code will help you to understand the nested internal table.

DATA: BEGIN OF WA,

WERKS TYPE WERKS_D,

END OF WA.

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR TYPE MATNR,

ITAB_NESTED LIKE WA OCCURS 0,

END OF ITAB1.

DATA: ITAB2 LIKE WA OCCURS 0 WITH HEADER LINE.

ITAB1-MATNR = 'TEST'.

ITAB2-WERKS = 'ASDF'.APPEND ITAB2.

ITAB2-WERKS = 'ADDD'.APPEND ITAB2.

ITAB1-ITAB_NESTED] = ITAB2[.

APPEND ITAB1.

LOOP AT ITAB1.

LOOP AT ITAB1-ITAB_NESTED INTO WA.

WRITE: / WA-WERKS.

ENDLOOP.

ENDLOOP.

Thanks,

Khushbu.