‎2009 May 07 7:10 AM
hi all,
i need to fetch the data from bseg table. i have written the following select query
SELECT BUKRS BELNR GJAHR BUZEI KUNNR LIFNR
INTO CORRESPONDING FIELDS OF TABLE GT_BSEG1
FROM BSEG
FOR ALL ENTRIES IN GT_BKPF
WHERE
BUKRS = GT_BKPF-BUKRS AND
BELNR = GT_BKPF-BELNR AND
GJAHR = GT_BKPF-GJAHR AND
BUZEI = '1'.(i need to select first line item only)
for the belnrs i need to check it consists vendor(lifnr) and customer(kunnr) or not for any other line items for
that particular belnr.
so i have written the following select query.
SELECT BUKRS BELNR GJAHR BUZEI KUNNR LIFNR
INTO CORRESPONDING FIELDS OF TABLE GT_BSEG
FROM BSEG
FOR ALL ENTRIES IN GT_BSEG1
WHERE BUKRS = GT_BSEG1-BUKRS AND
BELNR = GT_BSEG1-BELNR AND
GJAHR = GT_BSEG1-GJAHR AND
( LIFNR NE ' ' OR KUNNR NE ' ' ).
if LIFNR and KUNNR exists this internal table i need to take to loop, if it does not contains any data then
i need to modify gt_bseg table with gt_bseg1.
could you please help how to modify if gt_bseg is inital then gt_bseg1 values should come under gt_bseg table.
‎2009 May 07 7:21 AM
Hi neethu,
If GT_BSEG[] is initial.
append lines of GT_BSEG1 to GT_BSEG .
or the other stmt is
GT_BSEG[ ] = GT_BSEG1[ ] .
endif.
regards,
ajit.
Edited by: AJIT THAKUR on May 7, 2009 8:22 AM
‎2009 May 07 7:25 AM
Hi
you could write like this
If gt_bseg is initial.
loop at gt_bseg1 into fs_gt_bseg1 .
fs_gt_bseg = fs_gt_bseg1
append fs_gt_bseg to gt_bseg.
endloop.
endif.
Thanks
Viquar Iqbal
‎2009 May 07 7:26 AM
SELECT BUKRS BELNR GJAHR BUZEI KUNNR LIFNR
INTO CORRESPONDING FIELDS OF TABLE GT_BSEG1
FROM BSEG
FOR ALL ENTRIES IN GT_BKPF
WHERE
BUKRS = GT_BKPF-BUKRS AND
BELNR = GT_BKPF-BELNR AND
GJAHR = GT_BKPF-GJAHR AND
BUZEI = '1'.(i need to select first line item only)
SELECT BUKRS BELNR GJAHR BUZEI KUNNR LIFNR
INTO CORRESPONDING FIELDS OF TABLE GT_BSEG
FROM BSEG
FOR ALL ENTRIES IN GT_BSEG1
WHERE BUKRS = GT_BSEG1-BUKRS AND
BELNR = GT_BSEG1-BELNR AND
GJAHR = GT_BSEG1-GJAHR . ..........................
(REMOVE AND
( LIFNR NE ' ' OR KUNNR NE ' ' )
LOOP AT GT_BSEG.
if LIFNR EQ ' ' OR KUNNR EQ ' '.
GT_BSEG-FIELD1 = GT_BSEG-FIELD1.
....
....
APPEND GT_BSEG.
ENDIF.
.........
..........
ENDLOOP.
TRY THIS HOPE IT WILL SOLVE UR PROBLEM.
‎2009 May 07 7:29 AM
As you written both the select statements for IT_BSEG1.
There are no entries in the IT_BSEG now.
So what do you mean by modifying the IT_BESG table here.
If you want to fetch all the records for which KUNNR, LIFNR is initial and not initial.
Use one select query for the both. Later move the records into two separate internal tables.
Your question should be more clear without error to got good answers.
Thanks,
Naveen Inuganti.
‎2009 May 07 7:36 AM
Hi neethu,
could you please help how to modify if gt_bseg is inital then gt_bseg1 values should come under gt_bseg table.
For this if both the internal table have same Structure then u can do this
GT_BSEG1 = GT_BSEG.
else
u need to do this
Loop at GT_BSEG1
here transfer th valuse from Work Area of GT_BSEG1 to the Work Area of GT_BSEG
and noe
Append GT_BSEG.
endoop .
Cheersss....
Snehi Chouhan
‎2009 May 07 7:41 AM
Try this after the select:
SELECT BUKRS BELNR GJAHR BUZEI KUNNR LIFNR
INTO CORRESPONDING FIELDS OF TABLE GT_BSEG1
FROM BSEG
FOR ALL ENTRIES IN GT_BKPF
WHERE
BUKRS = GT_BKPF-BUKRS AND
BELNR = GT_BKPF-BELNR AND
GJAHR = GT_BKPF-GJAHR AND
BUZEI = '1'.(i need to select first line item only)
if sy-subrc = 0.
delete gt_bseg1 where kunnr = space or
lifnr = space.
endif.
if gt_bseg1 is initial.
message 'No data found' type 'E'.
endif.
hope that Helps
Anirban M.
‎2009 May 07 7:48 AM
Hi neethu,
hitting the database twice for the same table and almost similar records will hit on the performance of your program.... you just copy and paste the code given below... this will resolve your issue....
data gs_bseg like line of gt_bseg.
SELECT BUKRS BELNR GJAHR BUZEI KUNNR LIFNR
INTO CORRESPONDING FIELDS OF TABLE GT_BSEG1
FROM BSEG
FOR ALL ENTRIES IN GT_BKPF
WHERE
BUKRS = GT_BKPF-BUKRS AND
BELNR = GT_BKPF-BELNR AND
GJAHR = GT_BKPF-GJAHR AND
BUZEI = '1'.
" after this select query removing the other select query and putting a loop for it to update gt_bseg internal
" table this will work even if none of the records of kunnr and lifnr is initial.....
if gt_bseg1 is not initial.
loop at gt_bseg1 into fs_bseg where lifnr ne space or kunnr ne space.
append fs_bseg to gt_bseg.
endloop.
endif.Regards,
Siddarth