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: 

Loop controls

Former Member
0 Kudos
111

Hi,

I have an internal table like below :

HKONT BLART PRCTR DMBE2

123 ZC 5855 1985

123 ZC 5855 9855

124 AB 5842 10000

124 AB 5842 20000

I need the output as below :

HKONT BLART PRCTR DMBE2

123 ZC 5855 11840

124 AB 5842 30000

Please let me know how to achieve this?

Thanks,

Pavan.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
72

Hi

You should use the COLLECT statament but you should consider the sign of the item, if I remember u've picked up these informations by accounting items.

U should check the field SHKZG (Debit/Credit Indicator) to determine the sign:

DATA: BEGIN OF GT_HKONT OCCURS 0,

HKONT LIKE BSIS-HKONT,

PRCTR LIKE BSIS-PRCTR,

BEWAR LIKE BSIS-BEWAR,

SHKZG LIKE BSIS-SHKZG,

DMBE2 LIKE BSIS-DMBE2,

END OF GT_HKONT.

DATA: BEGIN OF GT_HKONT2 OCCURS 0,

HKONT LIKE BSIS-HKONT,

PRCTR LIKE BSIS-PRCTR,

BEWAR LIKE BSIS-BEWAR,

DMBE2 LIKE BSIS-DMBE2,

END OF GT_HKONT2.

LOOP AT GT_HKONT.

GT_HKONT2-HKONT = GT_HKONT-HKONT.

GT_HKONT2-PRCTR = GT_HKONT-PRCTR.

GT_HKONT2-BEWAR = GT_HKONT-BEWAR.

GT_HKONT2-DMBE2 = GT_HKONT-DMBE2.

IF GT_HKONT-SHKZG = 'H'.

GT_HKONT2-DMBE2 = - GT_HKONT2-DMBE2.

ENDIF.

COLLECT GT_HKONT2.

ENDLOOP.

If you've solved your previous post:

close it please! and reward the posts were helfull for u

Max

6 REPLIES 6

Former Member
0 Kudos
73

Hi

You should use the COLLECT statament but you should consider the sign of the item, if I remember u've picked up these informations by accounting items.

U should check the field SHKZG (Debit/Credit Indicator) to determine the sign:

DATA: BEGIN OF GT_HKONT OCCURS 0,

HKONT LIKE BSIS-HKONT,

PRCTR LIKE BSIS-PRCTR,

BEWAR LIKE BSIS-BEWAR,

SHKZG LIKE BSIS-SHKZG,

DMBE2 LIKE BSIS-DMBE2,

END OF GT_HKONT.

DATA: BEGIN OF GT_HKONT2 OCCURS 0,

HKONT LIKE BSIS-HKONT,

PRCTR LIKE BSIS-PRCTR,

BEWAR LIKE BSIS-BEWAR,

DMBE2 LIKE BSIS-DMBE2,

END OF GT_HKONT2.

LOOP AT GT_HKONT.

GT_HKONT2-HKONT = GT_HKONT-HKONT.

GT_HKONT2-PRCTR = GT_HKONT-PRCTR.

GT_HKONT2-BEWAR = GT_HKONT-BEWAR.

GT_HKONT2-DMBE2 = GT_HKONT-DMBE2.

IF GT_HKONT-SHKZG = 'H'.

GT_HKONT2-DMBE2 = - GT_HKONT2-DMBE2.

ENDIF.

COLLECT GT_HKONT2.

ENDLOOP.

If you've solved your previous post:

close it please! and reward the posts were helfull for u

Max

0 Kudos
72

Hi,

Thanks for your help.

Can please let know where to use the write statement.

Thanks,

Pavan.

0 Kudos
72

Hi

After selecting the data, you have used INTO TABLE option so you need to use another internal table to collect the data.

I don't know which solution to select the data (from BSEG? or BSAS/BSIS?) you have adopted, anyway in your previuos post you wrote this code:

SELECT hkont prctr bewar dmbe2 FROM bseg INTO CORRESPONDING

FIELDS OF table gt_hkont for all entries

in gt_tr_t030hb

WHERE bukrs IN so_bukrs

AND prctr IN so_prctr

AND saknr = gt_tr_t030hb-hkont

AND vbund IN so_vbund

and gjahr in so_gjahr

and xauto = 'X'.

Here you colletc the data using the code I wrote above

Max

0 Kudos
72

Thanks.

Message was edited by: Pavan Panduru

0 Kudos
72

Hi

IF gt_lkorr-gjahr EQ lv_year.

Change this piece:

<b>*gt_lkorr-hkont = wa_lkorr-hkont.

*gt_lkorr-prctr = wa_lkorr-prctr.

*gt_lkorr-bewar = wa_lkorr-bewar.

*gt_lkorr-dmbe2 = wa_lkorr-dmbe2.</b>

IF gt_lkorr-gjahr EQ lv_year.

wa_lkorr-hkont = gt_lkorr-hkont.

wa_lkorr-prctr = gt_lkorr-prctr.

wa_lkorr-bewar = gt_lkorr-bewar.

wa_lkorr-dmbe2 = gt_lkorr-dmbe2.

COLLECT wa_lkorr.

endif.

Max

0 Kudos
72

Thanks MAX,