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 the header only once

Former Member
0 Likes
1,013

Hi,

I have the following code to create the credit memo. How can I seperate the loop to perform the header once and the itemdata as no of records from the itab.

Please help me.

LOOP AT gt2_zprice INTO gs_zprice1.

PERFORM headerdata.

PERFORM itemdata.

APPEND gs_zprice1 TO gt3_zprice.

PERFORM call_function.

  • PERFORM update_pricetable.

PERFORM errorcheckandcommit.

ENDLOOP.

Thanks,

Neelu.

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
867

Hi,

Check this


data : v_flg type c.

LOOP AT gt4_zprice INTO gs_zprice1.
AT NEW kunnr.
 move 'Y' to v_flg.
ENDAT.

if v_flg eq 'Y'.                  " Check these lines          
  PERFORM headerdata."
  clear v_flg.                   "
endif.                            "
  
PERFORM itemdata.
APPEND gs_zprice1 TO gt3_zprice.
ENDLOOP.
PERFORM call_function.
* PERFORM update_pricetable.
PERFORM errorcheckandcommit.

aRs

6 REPLIES 6
Read only

amit_khare
Active Contributor
0 Likes
867

Use AT NEW <Header Field>.

PERFORM HEADER.

END AT.

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
867

HI,

When you say header there will be only one record for the header right.

you can say

loop at gt2_zprice into gs_zprice1.

at new <Field>

PERFORM headerdata.

endat.

PERFORM itemdata.

APPEND gs_zprice1 TO gt3_zprice.

PERFORM call_function.

  • PERFORM update_pricetable.

PERFORM errorcheckandcommit.

endloop.

Message was edited by:

I Can Solve It

Read only

former_member194669
Active Contributor
0 Likes
867

Hi,

if you are using at new , then please remember to sort gt2_zprice by <header field>

aRs

Read only

0 Likes
867

Hi,

Thank you all.

I changed the code like this.

LOOP AT gt4_zprice INTO gs_zprice1.

AT NEW kunnr.

PERFORM headerdata.

ENDAT.

PERFORM itemdata.

APPEND gs_zprice1 TO gt3_zprice.

ENDLOOP.

PERFORM call_function.

  • PERFORM update_pricetable.

PERFORM errorcheckandcommit.

Now header is executing only once, but the problem is gs_zprice1 had data for all fields, after 'AT NEW KUNNR' only 'mandt vkorg vtweg spart kunnr' is having data and remaining all fields are having *'s. After ENDAT again data is comming in to gs_zprice1 automatically and item data is fine with it. Why is this happenning. Am I doing something wrong. Please help me.

gs_zprice1 has the following fields.

mandt vkorg vtweg spart kunnr matnr zcrdate zefdate

zprice3 zprice4 zquantity1 zquantity2 auart bstkd werks_d

augru xblnr vbeln

Thanks,

Neelu.

Read only

former_member194669
Active Contributor
0 Likes
868

Hi,

Check this


data : v_flg type c.

LOOP AT gt4_zprice INTO gs_zprice1.
AT NEW kunnr.
 move 'Y' to v_flg.
ENDAT.

if v_flg eq 'Y'.                  " Check these lines          
  PERFORM headerdata."
  clear v_flg.                   "
endif.                            "
  
PERFORM itemdata.
APPEND gs_zprice1 TO gt3_zprice.
ENDLOOP.
PERFORM call_function.
* PERFORM update_pricetable.
PERFORM errorcheckandcommit.

aRs

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
867

You don't really want to do the rest of it, if it is a new KUNNR, right, if that is the case, then put CONTINUE after the PERFORM inside the AT NEW.

LOOP AT gt2_zprice INTO gs_zprice1.

   at new kunnr.
     PERFORM headerdata.
     continue.     
  endat.

PERFORM itemdata.
APPEND gs_zprice1 TO gt3_zprice.
PERFORM call_function.
* PERFORM update_pricetable.
PERFORM errorcheckandcommit.

ENDLOOP.

Regards,

Rich Heilman