Application Development 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: 

code to modify

Former Member
0 Kudos
104

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.

7 REPLIES 7

Former Member
0 Kudos
66

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

viquar_iqbal
Active Contributor
0 Kudos
66

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

Former Member
0 Kudos
66

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.

naveen_inuganti2
Active Contributor
0 Kudos
66

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.

Former Member
0 Kudos
66

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

former_member480923
Active Contributor
0 Kudos
66

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.

Former Member
0 Kudos
66

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