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

itab logic

Former Member
0 Likes
913

Hi,

My itab like this.

-


Name

ABC

Age

34

Sal

4000

Name

PQR

Age

53

Sal

9000

but i want like this

|Name| |Age | |Sal |

-


ABC 34 4000

PQE 53 9000

-


How to do that ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
889

Hi,

I suppose itab is like

data : beging of itab,

field1 type...,

field2 type.....,

end of itab.

declare itab1 as,

data : begin of itab occurs 100,

name type....,

age type....,

sal type....,

end of itab1.

data flag type c.

clear flag.

loop at itab.

flag = 0.

case field1.

when 'name'.

itab1-name = itab-field1.

flag = 0.

when 'age'.

itab1-age = itab-field1.

flag = 0.

when 'sal'.

itab1-sal = itab-field1.

flag = 1.

endcase.

if flag = 1.

append itab1.

endif.

endloop.

regards,

Dhan

9 REPLIES 9
Read only

Former Member
0 Likes
889

Hi,,,,,,

use......


data: begin of itab occurs 0,
        Name  type string,  
        Age     type string,
       Sal       type string,
       end of itab. 

itab-name = 'ABC'.
ITAB-AGE = '50'.
ITAB-SAL = '4000'.
APPEND ITAB.
CLEAR ITAB.

 itab-name = 'PQR'.
ITAB-AGE = '60'.
ITAB-SAL = '5000'.
APPEND ITAB.
CLEAR ITAB. 

LOOP AT ITAB.
WRITE:/ ITAB-NAME, ITAB-AGE, ITAB-SAL.
ENDLOOP.  

Read only

Former Member
0 Likes
889

hi,

write:/ name, age, sal.

loop at itab.

write:/ itab-name, itab-age, itab-sal.

endloop.

Read only

Former Member
0 Likes
889

Hi Jim,

It seems that you are not declaring the itab the right way at first place. "Name", "Age" and "Sal" should be the fields in the itab structure, but not the value in the itab.

You may try declaring your itab like this:


DATA:
    BEGIN of wa_emp,
        name(30),
        age(3) TYPE n,
        sal(10) TYPE n,
    END OF wa_emp,
    it_emp LIKE TABLE OF wa_emp.

Then utilize the work area (wa_emp) to store content of each employee, and later append the work area to the itab (it_emp).

Hope this helps, thanks.

Regards,

Anfernee

Read only

Former Member
0 Likes
889

Hi,

Add one more thing in SAURABH's post.

Put the following lines of codes before LOOP AT statement.

WRITE 'NAME'.

WRITE 'AGE'.

WRITE 'SALARY' .

Thanks.

Nitesh

Read only

Former Member
0 Likes
889

Hi,

while displaying your data write in the below format:

Write:/ name, age, sal.

loop at itab.

write:/ itab-name, itab-age, itab-sal.

endloop.

It will solve your problem

Thanks & Regards

Read only

Former Member
0 Likes
889

Name Age Sal

ABC 34 4000

PQR 53 9000

To get the report like this use position numbers.

WRITE : 10 'NAME' , 30 'AGE' 50 'SAL'.

LOOP AT itab.

WRITE : 10 itab-name, 30 itab-age, 50 itab-sal.

ENDLOOP.

Read only

Former Member
0 Likes
889

Hi,

Do it like this....

TYPES: BEGIN OF ty_data,

name(10) TYPE c,

age(2) TYPE c,

sal(10) TYPE c,

END OF ty_data.

DATA: it_data TYPE STANDARD TABLE OF ty_data,

wa_data TYPE ty_data.

wa_data-name = 'abc'.

wa_data-age = '34'.

wa_data-sal = '4000'.

APPEND wa_data to it_data.

wa_data-name = 'pqr'.

wa_data-age = '54'.

wa_data-sal = '9000'.

APPEND wa_data to it_data.

WRITE /8 'NAme'.

WRITE 13 'age'.

WRITE 17 'sal'.

clear wa_data.

loop at it_data INTO wa_data.

write /8 wa_data-name.

WRITE 13 wa_data-age.

WRITE 17 wa_data-sal.

ENDLOOP.

Hope it is helpful.

Regards,

Sasi.

Read only

Former Member
0 Likes
889

REPORT ZSRK_038 .

DATA : BEGIN OF ITAB OCCURS 0,

F1(4),

F2(10),

END OF ITAB.

ITAB-F1 = 'Name'.

ITAB-F2 = 'ABC'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 'Age'.

ITAB-F2 = '34'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 'Sal'.

ITAB-F2 = '4000'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 'Name'.

ITAB-F2 = 'PQR'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 'Age'.

ITAB-F2 = '53'.

APPEND ITAB.

CLEAR ITAB.

ITAB-F1 = 'Sal'.

ITAB-F2 = '9000'.

APPEND ITAB.

CLEAR ITAB.

WRITE : 'Name' , 12 'Age' , 23 'Sal'.

NEW-LINE.

LOOP AT ITAB.

WRITE : ITAB-F2 .

IF ITAB-F1 EQ 'Sal'.

NEW-LINE.

ENDIF.

ENDLOOP.

Read only

Former Member
0 Likes
890

Hi,

I suppose itab is like

data : beging of itab,

field1 type...,

field2 type.....,

end of itab.

declare itab1 as,

data : begin of itab occurs 100,

name type....,

age type....,

sal type....,

end of itab1.

data flag type c.

clear flag.

loop at itab.

flag = 0.

case field1.

when 'name'.

itab1-name = itab-field1.

flag = 0.

when 'age'.

itab1-age = itab-field1.

flag = 0.

when 'sal'.

itab1-sal = itab-field1.

flag = 1.

endcase.

if flag = 1.

append itab1.

endif.

endloop.

regards,

Dhan