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

How can delete Internal table column if its Initial.

Former Member
0 Likes
3,684

HI.

How can delete Internal table column if its Initial.

eg:I have one internal table its has 5. field1 ,field2,field3,field4 have values but field field5 have no value,that col is empty,

I want delete clo5( field5 ) from Internal table,Pls help me.

Regards.

Jay

Try this , it will work

loop at itab.

if itab-field5 is initial .

itab2-field1 = itab-field1

itab2-field2 = itab-field2

itab2-field3 = itab-field3

itab2-field4 = itab-field4

append itab2.

else.

itab2-field1 = itab-field1

itab2-field2 = itab-field2

itab2-field3 = itab-field3

itab2-field4 = itab-field4

itab2-field5 = itab-field5

append itab2

endif.

endloop.

Regards,

Ajay

12 REPLIES 12
Read only

Former Member
0 Likes
1,976

Hi Jay,

take 5 internal tables and send the data into them as follows.

itab1 - field1

itab2 - field2

itab3 - field3

itab4 - field4

itab5 - field5.

check the INITIALITY of these tables while printing the output.

Read only

Former Member
0 Likes
1,976

Hi,

You use one more itab and use move corresponding and pass only the 4 fields not field5

or append it to new one

regards

Shiva

Read only

Former Member
0 Likes
1,976

you cannot delete the column in an internal table. you need another table with 4 fields u want and assign this table to the table with 4 fields.

for initial you can check using this

loop at tab.

if tab-field5 is initial .

tab2-field1 = tab-field1

tab2-field2 = tab-field2

tab2-field3 = tab-field3

tab2-field4 = tab-field4

append tab2.

endif.

endloop.

<REMOVED BY MODERATOR>

varun

Edited by: Alvaro Tejada Galindo on Feb 26, 2008 12:29 PM

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,976

hi Jay,

why not follow your previous thread, probably you got answer already...

ec

Read only

0 Likes
1,976

HI..

Sorry Eric for duplicate threads, am using this internal table to display ALV, End user saying its seems not good if it has empty column while display. Already I got answers like it’s not possible at runtime, but again aim trying people who faced same problem.

Regards.

Jay

Read only

0 Likes
1,976

removing a field from internal table, and not displaying a coloumn in ALV list are completely different things! If you don't want to display a coloumn in ALV list, all you have to do is to turn off the field in the ALV field catalouge:

fieldcat-no_out = 'X'.

and the coloumn won't be displayed

Read only

0 Likes
1,976

Hi Eric.

yes, Its fine ,before hide the particular column I need to check whether it has any value or empty ,I need hide only if its empty else I need to display that column.

Pls help me.

Jay

Read only

Former Member
0 Likes
1,976

Try this , it will work

loop at itab.

if itab-field5 is initial .

itab2-field1 = itab-field1

itab2-field2 = itab-field2

itab2-field3 = itab-field3

itab2-field4 = itab-field4

append itab2.

else.

itab2-field1 = itab-field1

itab2-field2 = itab-field2

itab2-field3 = itab-field3

itab2-field4 = itab-field4

itab2-field5 = itab-field5

append itab2

endif.

endloop.

Regards,

Ajay

Read only

Former Member
0 Likes
1,976

If you already know which field in the internal table doesn't have any value, you can define a different internal table with the fields that you desire, and then do a move-corresponding for the same.

Read only

ravisankara_varaprasad
Active Participant
0 Likes
1,976

Hi,

You can do this by moving the data to target internal table with required fields / you need to create the dynamic internal table.

if you have only 5 fields then you can do this with the below approach.

try to have the internal table columns like Fld1 FLd2 Fld3 Fld4 Fld5 , and make another internal table for the actual column names like below.

for example,

  1. fld name

FLd1 Matnr

Fld2 ERSDA

Fld3 ERNAM

Fld4 LAEDA

Fld5 VPSTA

now consider fld3 is initial so now build the target table with fld1 , fld2 , fld4 , fld5.

but for output display you refer the above internal table for actual fields.

Hope this is clear.

Kind Regards,

Read only

Former Member
0 Likes
1,976

Hye jay,

Consider your internal table is having 3 fields… fld1 fld2 fld3.

Declare 3 characters of length 1 and initialize to 1.

Loop at itab into wa.

If wa-fld1 is not initial.

Clear fld1.

Endif.

If wa-fld2 is not initial.

Clear fld2.

Endif.

If wa-fld3 is not initial.

Clear fld3.

Endif.

If fld1 EQ space and fld2 EQ space fld3 EQ space.

Exit.

Endif.

Endloop.

No when you assign the colums to alv, add this statement.

if fld1 is intial.

fieldcat-no_out = 'X'.

endif.

like wise for all fields.

wa_fldcat-col_pos = 1.

wa_fldcat-fieldname = 'fld1'.

wa_fldcat-tabname = 'IT_PROJECT'.

wa_fldcat-seltext_l = field 1.

if fld1 is intial.

fieldcat-no_out = 'X'.

endif.

APPEND wa_fldcat TO it_fldcat.

CLEAR wa_fldcat.

may be this is helpful..

thanks,

Imran.

Read only

Former Member
0 Likes
1,976

Do not duplicate threads...

[;

Locking this one...

Greetings,

Blag.