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

Loop at ...

Former Member
0 Likes
1,485

Hello All,

I have declared 2 internal tables as

data : begin of i_bseg3 occurs 0,

bukrs like bseg-bukrs,

belnr like bseg-belnr,

gjahr like bseg-gjahr,

aedat like bwfi_aedat-aedat,

augdt like bseg-augdt,

augbl like bseg-augbl,

end of i_bseg3.

data : begin of i_tcode occurs 0,

bukrs like bkpf-bukrs,

aedat like bwfi_aedat-aedat,

tcode like bkpf-tcode,

gjahr like bkpf-gjahr,

belnr like bkpf-belnr,

count(4),

augbl like bseg-augbl,

usnam like bkpf-usnam,

end of i_tcode.

data : begin of i_bkpf occurs 0,

bukrs like bkpf-bukrs,

belnr like bkpf-belnr,

gjahr like bkpf-gjahr,

tcode like bkpf-tcode,

usnam like bkpf-usnam,

end of i_bkpf.

I have 2 records in i_bseg3

BUKRS BELNR GJAHR AEDAT AUGDT AUGBL

AU00 |0000000014|2004 |20040922|20040922|2000000007

AU00 |0000000014|2004 |20040922|00000000|

and 1 record in i_bkpf

AU00 |2000000007|2004 |F110 |647052

Loop at i_bseg3.

write:/i_bseg3-bukrs, i_bseg3-belnr etc etc

at end of belnr.

move-corresponding i_bseg3 to I_TCODE.

v_gjahr = i_bseg3-augdt(4).

read table i_BKPF with key bukrs = i_bseg3-bukrs

belnr = i_bseg3-augbl

gjahr = v_gjahr.

I_TCODE-TCODE = I_BKPF-TCODE.

I_TCODE-usnam = I_BKPF-usnam.

APPEND I_TCODE.

endloop.

Since, at end of BELNR is been used the 2 record comes into header line and when move-corresponding to I_TCODE is used i get all ****** .

16 REPLIES 16
Read only

FredericGirod
Active Contributor
0 Likes
1,439

Hi,

be carefull of the AT END command, that make * for all the column after the column you set in this commande (just for the block AT END).

Rgd

Frédéric

Read only

Former Member
0 Likes
1,439
Loop at i_bseg3.
write:/i_bseg3-bukrs, i_bseg3-belnr etc etc
at end of belnr.
<b>read table i_bseg index sy-tabix.</b>
move-corresponding i_bseg3 to I_TCODE.
v_gjahr = i_bseg3-augdt(4).
read table i_BKPF with key bukrs = i_bseg3-bukrs
belnr = i_bseg3-augbl
gjahr = v_gjahr.
I_TCODE-TCODE = I_BKPF-TCODE.
I_TCODE-usnam = I_BKPF-usnam.
APPEND I_TCODE.
endloop.

add the bold one..

Read only

Former Member
0 Likes
1,439

Hi Sravan

Plz complete your question.

regards

kishore

Read only

Former Member
0 Likes
1,439

Hi Sravan,

When you use AT END OF <col> .. All the character based fields to the right of <col> becomes * and numeric based fields are set to zero..

so you can just copy the Header into work area before

AT END OF .

and then copy the work area to your destination..

regards

satesh

Read only

0 Likes
1,439

also close your previous threads

Regards

Raja

Read only

0 Likes
1,439

Hi Sateesh,

Could you please provide the syntax for this.

I used the

read table i_bseg3 index sy-tabix.

and in this case the second record in the internal table comes into header and does not match with the i_BKPF record.

Regards,

- Sravan

Read only

Former Member
0 Likes
1,439

Hi sravan,

You need to pass the work area to another workarea before using 'at end of belnr' stmt.And use that new work area values in your program.I think this will helps you

Loop at i_bseg3.

write:/i_bseg3-bukrs, i_bseg3-belnr etc etc

w_bseg_dup = w_bseg3.

at end of belnr.

move-corresponding i_bseg3 to I_TCODE.

v_gjahr = i_bseg3-augdt(4).

read table i_BKPF with key bukrs = i_bseg3-bukrs

belnr = w_bseg_dup-augbl

gjahr = v_gjahr.

I_TCODE-TCODE = I_BKPF-TCODE.

I_TCODE-usnam = I_BKPF-usnam.

APPEND I_TCODE.

endloop.

Read only

Former Member
0 Likes
1,439

hi Sravan,

just see the modidfications made..

we can move it to a work area and thenm move it again to I_TCODE..

<b>data: wa_bseg3 like line of i_bseg3.</b>

Loop at i_bseg3.

write:/i_bseg3-bukrs, i_bseg3-belnr etc etc

<b>move i_bseg3 to wa_bseg3.</b>

at end of belnr.

<b>move-corresponding wa_bseg3 to I_TCODE.</b>

v_gjahr = i_bseg3-augdt(4).

read table i_BKPF with key bukrs = i_bseg3-bukrs

belnr = i_bseg3-augbl

gjahr = v_gjahr.

I_TCODE-TCODE = I_BKPF-TCODE.

I_TCODE-usnam = I_BKPF-usnam.

APPEND I_TCODE.

endloop.

regards

satesh

Read only

0 Likes
1,439

Hi Sateesh,

I implemented the same and as you can notice that the 2 records in the Internal table i_bseg3(which i have posted)

Since at end of BELNR is used the second record with AUGDT as 0 and augbl as 0 are matched with the I_BKPF which does not match and further processing is not done.

Regards,

- Sravan

i_bseg3:

BUKRS BELNR GJAHR AEDAT AUGDT AUGBL

AU00 |0000000014|2004 |20040922|20040922|2000000007

AU00 |0000000014|2004 |20040922|00000000|

i_bkpf:

BUKRS BELNR GJAHR TCODE USNAM

AU00 |2000000007|2004 |F110 |647052

Regards,

- Sravan

Read only

0 Likes
1,439

Hi Sravan,

This has a simple solution.

Loop at it.

at end of matnr.

flag = 'X'.

endat.

if flag = 'X'.

...do the operation desired

endif.

endloop.

Hope it'll help.

Thanks & Regards,

Ankur

Message was edited by: Ankur Jain

Message was edited by: Ankur Jain

Read only

0 Likes
1,439

hi Sravan,

Can you please give the complete code..

regards

satesh

Read only

0 Likes
1,439
    • Print Line item count

skip 2.

write:/02 'BSEG Listing'.

loop at i_bseg3.

LI_COUNT = LI_COUNT + 1.

CC_COUNT = CC_COUNT + 1.

GT_COUNT = GT_COUNT + 1.

DOC_CNT = DOC_CNT + 1.

v_aedat = i_bseg3-aedat.

t_gjahr = i_bseg3-gjahr.

move : i_bseg3-bukrs to wa_bseg3-bukrs,

i_bseg3-belnr to wa_bseg3-belnr,

i_bseg3-gjahr to wa_bseg3-gjahr,

i_bseg3-aedat to wa_bseg3-aedat,

i_bseg3-augdt to wa_bseg3-augdt,

i_bseg3-augbl to wa_bseg3-augbl.

at end of belnr.

write:/02 i_bseg3-bukrs,

08 i_bseg3-belnr,

20 t_gjahr,

26 v_aedat.

endat.

at end of aedat.

write:/ 'Line item count', LI_COUNT.

clear LI_COUNT.

endat.

at end of bukrs.

write:/ 'Company code count', CC_COUNT.

clear CC_COUNT.

endat.

at last.

write:/ 'Grand total count', GT_COUNT.

endat.

    • Gather data for line item by T-code

at end of belnr.

  • read table i_bseg3 index sy-tabix.

  • move-corresponding i_bseg3 to I_TCODE.

move-corresponding wa_bseg3 to i_tcode.

I_TCODE-COUNT = DOC_CNT.

v_gjahr = i_bseg3-augdt(4).

read table i_BKPF with key

bukrs = wa_bseg3-bukrs

belnr = wa_bseg3-augbl

gjahr = v_gjahr.

I_TCODE-TCODE = I_BKPF-TCODE.

I_TCODE-usnam = I_BKPF-usnam.

APPEND I_TCODE.

clear i_tcode.

endat.

endloop.

Read only

0 Likes
1,439

HI

    • Print Line item count

skip 2.

write:/02 'BSEG Listing'.

loop at i_bseg3.

LI_COUNT = LI_COUNT + 1.

CC_COUNT = CC_COUNT + 1.

GT_COUNT = GT_COUNT + 1.

DOC_CNT = DOC_CNT + 1.

v_aedat = i_bseg3-aedat.

t_gjahr = i_bseg3-gjahr.

move : i_bseg3-bukrs to wa_bseg3-bukrs,

i_bseg3-belnr to wa_bseg3-belnr,

i_bseg3-gjahr to wa_bseg3-gjahr,

i_bseg3-aedat to wa_bseg3-aedat,

i_bseg3-augdt to wa_bseg3-augdt,

i_bseg3-augbl to wa_bseg3-augbl.

at end of belnr.

<b>write:/02 wa_bseg3-bukrs,

08 wa_bseg3-belnr,</b>

20 t_gjahr,

26 v_aedat.

endat.

at end of aedat.

write:/ 'Line item count', LI_COUNT.

clear LI_COUNT.

endat.

at end of bukrs.

write:/ 'Company code count', CC_COUNT.

clear CC_COUNT.

endat.

at last.

write:/ 'Grand total count', GT_COUNT.

endat.

    • Gather data for line item by T-code

at end of belnr.

  • read table i_bseg3 index sy-tabix.

  • move-corresponding i_bseg3 to I_TCODE.

move-corresponding wa_bseg3 to i_tcode.

I_TCODE-COUNT = DOC_CNT.

<b>v_gjahr = wa_bseg3-augdt(4).</b>

read table i_BKPF with key

bukrs = wa_bseg3-bukrs

belnr = wa_bseg3-augbl

gjahr = v_gjahr.

I_TCODE-TCODE = I_BKPF-TCODE.

I_TCODE-usnam = I_BKPF-usnam.

APPEND I_TCODE.

clear i_tcode.

endat.

endloop.

regards

kishore

Read only

0 Likes
1,439

hi Sravan,

Since i_bseg3-augat is not visible inside AT END OF..

use wa_bseg3-augat..

regards

satesh

Read only

0 Likes
1,439

Hi Sateesh,

The main issue is with the records that are available in the internal table.

When we use at End of BELNR (by then we are in the Second and last record). The last record dows not have AUGDT and AUGBL that si the reason it is failing the I_BKPF (where as the First record matches with I-BKPF and ideally it should have given the TCODE and USNAM ).

Regards,

- Sravan

Read only

0 Likes
1,439

Hi Sravan,

Can you make this modification.. where you move the work area containing AUGDT and AUGBL into wa_bseg3..

and clear it at AT END OF..

Loop at i_bseg3.

write:/ i_bseg3-bukrs, i_bseg3-belnr .

LI_COUNT = LI_COUNT + 1.

CC_COUNT = CC_COUNT + 1.

GT_COUNT = GT_COUNT + 1.

DOC_CNT = DOC_CNT + 1.

v_aedat = i_bseg3-aedat.

t_gjahr = i_bseg3-gjahr.

move : i_bseg3-bukrs to wa_bseg3-bukrs,

i_bseg3-belnr to wa_bseg3-belnr,

i_bseg3-gjahr to wa_bseg3-gjahr,

i_bseg3-aedat to wa_bseg3-aedat,

i_bseg3-augdt to wa_bseg3-augdt,

i_bseg3-augbl to wa_bseg3-augbl.

<b>if i_bseg3-augdt is not initial and i_bseg3-augbl is not initial.

move i_bseg3 to wa_bseg3.

endif.</b>

......

at end of belnr.

move-corresponding wa_bseg3 to I_TCODE.

v_gjahr = wa_bseg3-augdt(4).

read table i_BKPF with key bukrs = wa_bseg3-bukrs

belnr = wa_bseg3-augbl

gjahr = v_gjahr.

I_TCODE-TCODE = I_BKPF-TCODE.

I_TCODE-usnam = I_BKPF-usnam.

APPEND I_TCODE.

<b>clear wa_bseg3.</b>

ENDAT.

regards

satesh