01-09-2007 11:31 AM
Dear experts
I have a internal table like below
F1 F2 F3 F4
1 SA 01 1
2 SA 02 2
3 SA 03 3
4 SA 06 4
5 SA 05 5
2 08
4 09
4 11
My requirement is i need to fill the empty fields of F2 and F4
of below 3 records with same value in above (see there is different values in F3)
like below internal table i need it
F1 F2 F3 F4
1 SA 01 1
2 SA 02 2
3 SA 03 3
4 SA 06 4
5 SA 05 5
2 SA 08 2
4 SA 09 4
4 SA 11 4
can anyone give me the CODE for this.
thnaks in advance.
regards
karthik
01-09-2007 11:37 AM
Hi karthik,
loop at itab.
if itab-f2 eq ' ' and itab-f4 eq ' '.
itab-f2 = 'SA'.
itab-f4 = itab-f1.
modify itab.
clear itab.
else.
clear itab.
continue.
endif.
endloop.
01-09-2007 11:37 AM
Hello Kathick,
Try like this.
DATA: var like f2(Ref to the field F2)
Loop at itab.
if itab-f2 is initial.
<b>itab-f2 = var.</b>
else.
<b>var = itab-f2.</b>
endif.
if itab-f4 is initial.
itab-f4 = itab-f1.
endif.
Modify itab.
endloop.
Hope this code helps u.
If useful reward.
Vasanth
01-09-2007 11:37 AM
Hi Karthik,
Do one thing:
loop at itab into wa_itab.
if wa_itab-F2 is initial.
wa_itab-F2 = 'SA'.
endif.
if wa_itab-F4 is initial.
wa_itab-F4 = wa_itab-F1.
endif.
modify itab.
endloop.
Reward points if this Helps.
Manish
01-09-2007 11:43 AM
Hi,
loop at itab into wa where f2 is initial and f4 is initial.
wa-f2 = 'SA'.
wa-f4 = wa-f1.
modify itab from wa transporting f2 f4 where f1 = wa-f1 and f3 = wa-f3.
endloop.
01-09-2007 11:46 AM
Hi Karthik ,
Here is the sample code
Types : begin of ty_1 ,
f1(2) ,
f2(2) ,
f3(2) ,
f4(2) ,
End of ty_1.
Data : it_1 type table of ty_1 ,
wa_1 type ty_1.
start-of-selection.
wa_1-f1 = '1'.
wa_1-f2 = 'SA'.
wa_1-f3 = '01'.
WA_1-F4 = '1'.
append wa_1 to it_1.
wa_1-f1 = '2'.
wa_1-f2 = 'SA'.
wa_1-f3 = '02'.
WA_1-F4 = '2'.
append wa_1 to it_1.
wa_1-f1 = '3'.
wa_1-f2 = 'SA'.
wa_1-f3 = '03'.
WA_1-F4 = '3'.
append wa_1 to it_1.
wa_1-f1 = '4'.
wa_1-f2 = 'SA'.
wa_1-f3 = '06'.
WA_1-F4 = '4'.
append wa_1 to it_1.
wa_1-f1 = '5'.
wa_1-f2 = 'SA'.
wa_1-f3 = '05'.
WA_1-F4 = '5'.
append wa_1 to it_1.
clear wa_1.
wa_1-f1 = '2'.
*wa_1-f2 = 'SA'.
wa_1-f3 = '01'.
*WA_1-F4 = '1'.
append wa_1 to it_1.
clear wa_1.
wa_1-f1 = '4'.
*wa_1-f2 = 'SA'.
wa_1-f3 = '09'.
*WA_1-F4 = '1'.
append wa_1 to it_1.
clear wa_1.
wa_1-f1 = '4'.
*wa_1-f2 = 'SA'.
wa_1-f3 = '11'.
*WA_1-F4 = '1'.
append wa_1 to it_1.
clear wa_1.
*" Portion of code relevent to you
wa_1-f2 ='SA'.
modify it_1 from wa_1 transporting f2 where f2 is initial.
loop at it_1 into wa_1 where f4 is initial.
wa_1-f4 = wa_1-f1.
modify it_1 from wa_1 index sy-tabix.
endloop.
Please do revert back if you have any further queries
Regards
Arun
01-09-2007 12:03 PM
Copy and execute this program.
data : begin of it occurs 0,
f1(5),
f2(5),
f3(5),
f4(5),
end of it.
data : flag(5) .
it-f1 = '1' .
it-f2 = 'SA'.
it-f3 = '01'.
it-f4 = '1' .
append it.CLEAR IT.
it-f1 = '2' .
it-f2 = 'SA'.
it-f3 = '02'.
it-f4 = '2' .
append it.CLEAR IT.
it-f1 = '3' .
it-f2 = 'SA'.
it-f3 = '03'.
it-f4 = '3' .
append it.CLEAR IT.
it-f1 = '4' .
it-f2 = 'SA'.
it-f3 = '06'.
it-f4 = '4' .
append it.CLEAR IT.
it-f1 = '5' .
it-f2 = 'SA'.
it-f3 = '05'.
it-f4 = '5' .
append it.CLEAR IT.
it-f1 = '2' .
it-f3 = '08'.
append it.CLEAR IT.
it-f1 = '4' .
it-f3 = '09'.
append it.CLEAR IT.
it-f1 = '4' .
it-f3 = '11'.
append it.CLEAR IT.
sort it DESCENDING by f2 .
loop at it.
if it-f4 is initial.
it-f4 = it-f1.
modify it transporting f4.
endif.
if it-f2 is initial.
move flag to it-f2.
modify it transporting f2.
endif.
move it-f2 to flag.
endloop.
LOOP AT IT.
WRITE : / IT-F1 , IT-F2 , IT-F3 , IT-F4.
ENDLOOP.
Dont forget to reward points.
Regards,
barath.
01-09-2007 12:04 PM
Just copy paste and execute
REPORT ABC.
DATA: BEGIN OF ITAB OCCURS 0,
F1(2),
F2(2),
F3(2),
F4(2),
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 0,
F1(2),
F2(2),
F3(2),
F4(2),
END OF ITAB1.
ITAB-F1 = '1'.
ITAB-F2 = 'SA'.
ITAB-F3 = '01'.
ITAB-F4 = '1'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = '2'.
ITAB-F2 = 'SA'.
ITAB-F3 = '02'.
ITAB-F4 = '2'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = '3'.
ITAB-F2 = 'SA'.
ITAB-F3 = '03'.
ITAB-F4 = '3'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = '4'.
ITAB-F2 = 'SA'.
ITAB-F3 = '06'.
ITAB-F4 = '4'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = '5'.
ITAB-F2 = 'SA'.
ITAB-F3 = '05'.
ITAB-F4 = '5'.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = '2'.
ITAB-F2 = ''.
ITAB-F3 = '08'.
ITAB-F4 = ''.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = '4'.
ITAB-F2 = ''.
ITAB-F3 = '09'.
ITAB-F4 = ''.
APPEND ITAB.
CLEAR ITAB.
ITAB-F1 = '4'.
ITAB-F2 = ''.
ITAB-F3 = '11'.
ITAB-F4 = ''.
APPEND ITAB.
CLEAR ITAB.
LOOP AT ITAB WHERE F2 EQ SPACE AND F4 EQ SPACE.
MOVE-CORRESPONDING ITAB TO ITAB1.
APPEND ITAB1.
CLEAR ITAB1.
DELETE ITAB.
ENDLOOP.
LOOP AT ITAB.
READ TABLE ITAB1 WITH KEY F1 = ITAB-F1.
IF SY-SUBRC EQ 0.
ITAB1-F2 = ITAB-F2.
ITAB1-F4 = ITAB-F1.
MODIFY ITAB1 TRANSPORTING F2 F4 WHERE F1 = ITAB-F1.
ENDIF.
CLEAR :ITAB , ITAB1.
ENDLOOP.
APPEND LINES OF ITAB1 TO ITAB.
LOOP AT ITAB.
WRITE : / ITAB-F1 , ITAB-F2 , ITAB-F3 , ITAB-F4.
ENDLOOP.
01-09-2007 8:37 PM
Hi,
Hi Karthik,
Do one thing:
loop at itab into wa_itab.
if wa_itab-F2 is initial.
wa_itab-F2 = 'SA'.
endif.
if wa_itab-F4 is initial.
wa_itab-F4 = wa_itab-F1.
endif.
modify itab.
endloop.
Thanks
Venkat Ch