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 to delete null rows from an internal table.

Former Member
0 Likes
8,027

Hello,

In my Internal table few rows have null values and I want to delete them.

How can I do this....I am using specific Sturctures, based on them I had created

Internal tables

ex : In Itable 1st row has only 000000, it is null and I want to delete that entire row.

for ex : types : begin of ty_abc,

123 type q,

456 type p,

end of ty_abc.

data : t_abc type standard table of ty_abc.

This is my code.

LOOP AT T_PRCTSC INTO WA_PRCTSC.

WA_FINAL-GUID_PRCTSC = WA_PRCTSC-GUID_PRCTSC.

WA_FINAL-GUID_PR = WA_PRCTSC-GUID_PR.

WA_FINAL-STCTS = WA_PRCTSC-STCTS.

WA_FINAL-GUID_CTSNUMC = WA_PRCTSC-GUID_CTSNUMC.

READ TABLE T_CTSNUMC INTO WA_CTSNUMC WITH KEY GUID_CTSNUMC = WA_PRCTSC-GUID_CTSNUMC.

IF SY-SUBRC = 0.

WA_FINAL-GUID_MOBJ = WA_CTSNUMC-GUID_MOBJ.

WA_FINAL-CCNGN = WA_CTSNUMC-CCNGN.

ENDIF.

READ TABLE T_PRGEN INTO WA_PRGEN WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-GUID_PRGEN = WA_PRGEN-GUID_PRGEN.

WA_FINAL-ATTR20A = WA_PRGEN-ATTR20A.

WA_FINAL-ATTR05A = WA_PRGEN-ATTR05A.

WA_FINAL-ATTR10A = WA_PRGEN-ATTR10A.

WA_FINAL-ATTR05B = WA_PRGEN-ATTR05B.

ENDIF.

READ TABLE T_PNTPR INTO WA_PNTPR WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-PRVSY = WA_PNTPR-PRVSY.

WA_FINAL-GRVSY = WA_PNTPR-GRVSY.

ENDIF.

READ TABLE T_PR INTO WA_PR WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-CRTSP = WA_PR-CRTSP.

WA_FINAL-CHTSP = WA_PR-CHTSP.

ENDIF.

READ TABLE T_PRT INTO WA_PRT WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-PRTXT = WA_PRT-PRTXT.

ENDIF.

*&----


&*

**Since the report will display all the classifications **

    • based on the SubID's. We are removing the records where **

    • subid is initial **

*&----


& -->Here it will make values null in Itable

*IF WA_FINAL-ATTR20A IS INITIAL. but itable still*

CLEAR : WA_FINAL.

CLEAR T_FINAL[].

ENDIF.

APPEND WA_FINAL TO T_FINAL.

CLEAR WA_FINAL.

ENDLOOP.

Any suggestions will be apprecaited...

Regards,

Kittu

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
3,258

simply:

DELETE itab WHERE ... EQ '000000'.

this will delete the lines from the internal table where the condition is true. of coure the condition could be more complicated.

Hello,

In my Internal table few rows have null values and I want to delete them.

How can I do this....I am using specific Sturctures, based on them I had created

Internal tables

ex : In Itable 1st row has only 000000, it is null and I want to delete that entire row.

for ex : types : begin of ty_abc,

123 type q,

456 type p,

end of ty_abc.

data : t_abc type standard table of ty_abc.

This is my code.

LOOP AT T_PRCTSC INTO WA_PRCTSC.

WA_FINAL-GUID_PRCTSC = WA_PRCTSC-GUID_PRCTSC.

WA_FINAL-GUID_PR = WA_PRCTSC-GUID_PR.

WA_FINAL-STCTS = WA_PRCTSC-STCTS.

WA_FINAL-GUID_CTSNUMC = WA_PRCTSC-GUID_CTSNUMC.

READ TABLE T_CTSNUMC INTO WA_CTSNUMC WITH KEY GUID_CTSNUMC = WA_PRCTSC-GUID_CTSNUMC.

IF SY-SUBRC = 0.

WA_FINAL-GUID_MOBJ = WA_CTSNUMC-GUID_MOBJ.

WA_FINAL-CCNGN = WA_CTSNUMC-CCNGN.

ENDIF.

READ TABLE T_PRGEN INTO WA_PRGEN WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-GUID_PRGEN = WA_PRGEN-GUID_PRGEN.

WA_FINAL-ATTR20A = WA_PRGEN-ATTR20A.

WA_FINAL-ATTR05A = WA_PRGEN-ATTR05A.

WA_FINAL-ATTR10A = WA_PRGEN-ATTR10A.

WA_FINAL-ATTR05B = WA_PRGEN-ATTR05B.

ENDIF.

READ TABLE T_PNTPR INTO WA_PNTPR WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-PRVSY = WA_PNTPR-PRVSY.

WA_FINAL-GRVSY = WA_PNTPR-GRVSY.

ENDIF.

READ TABLE T_PR INTO WA_PR WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-CRTSP = WA_PR-CRTSP.

WA_FINAL-CHTSP = WA_PR-CHTSP.

ENDIF.

READ TABLE T_PRT INTO WA_PRT WITH KEY GUID_PR = WA_PRCTSC-GUID_PR.

IF SY-SUBRC = 0.

WA_FINAL-PRTXT = WA_PRT-PRTXT.

ENDIF.

*&----


&*

**Since the report will display all the classifications **

    • based on the SubID's. We are removing the records where **

    • subid is initial **

*&----


& -->Here it will make values null in Itable

*IF WA_FINAL-ATTR20A IS INITIAL. but itable still*

CLEAR : WA_FINAL.

CLEAR T_FINAL[].

ENDIF.

APPEND WA_FINAL TO T_FINAL.

CLEAR WA_FINAL.

ENDLOOP.

Any suggestions will be apprecaited...

Regards,

Kittu

7 REPLIES 7
Read only

JozsefSzikszai
Active Contributor
0 Likes
3,259

simply:

DELETE itab WHERE ... EQ '000000'.

this will delete the lines from the internal table where the condition is true. of coure the condition could be more complicated.

Read only

Former Member
0 Likes
3,258

HI,

Once you find the where values are gettting cleared write Continue...it will continue with next record in the loop.

*&----


&*

**Since the report will display all the classifications **

based on the SubID's. We are removing the records where **

subid is initial **

*&----


& -->Here it will make values null in Itable

IF WA_FINAL-ATTR20A IS INITIAL. but itable still

CLEAR : WA_FINAL.

CONTINUE. Continue's to next loop. Doesn't append the data t_final

ENDIF.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,258

Hello KIttu,

Modify your code to :


IF WA_FINAL-ATTR20A IS INITIAL.
CLEAR : WA_FINAL.
* CLEAR T_FINAL[].

ELSE.

APPEND WA_FINAL TO T_FINAL.

CLEAR WA_FINAL.
ENDIF.

* APPEND WA_FINAL TO T_FINAL.

* CLEAR WA_FINAL.

It will not populate the rows at all. No need to delete the empty rows.

BR,

Suhas

Read only

Former Member
0 Likes
3,258

Hi,

Try,

DELETE itab WHERE fname IS INITIAL.

Regards,

Pavan

Read only

Former Member
0 Likes
3,258

HI KITTU,

Use DELETE ADJUSTANT DUPLICATES COMPARING FIELDS<F1,>

Regards,

Flavya

Read only

Former Member
0 Likes
3,258

sort itab by field1.

DELETE ADJUSTANT DUPLICATES COMPARING FIELD1.

and anyhow one row will remain and that will be first row .

delete itab index 1.

Kiran

Read only

Former Member
0 Likes
3,258

Hello,

Thank you for your response!

The information porovided was helpful.

Have a great day!

Regards,

Kittu