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

Subroutine pool

Former Member
0 Likes
1,506

Hello guys,

i have one more problem.

Please take a look at my code..

FORM get_unit_price TABLES in_par STRUCTURE itcsy

out_par STRUCTURE itcsy.

DATA : lv_fkimg TYPE i,

lv_netwr TYPE i,

lv_netpr TYPE i.

*-- Initialize the values

CLEAR : lv_fkimg,

lv_netwr,

lv_netpr.

*-- Get the Incoming Values

READ TABLE in_par WITH KEY 'VBDPR-NETWR'.

TRANSLATE in_par-value USING ', '.

CONDENSE in_par-value NO-GAPS.

IF sy-subrc EQ 0.

lv_netwr = in_par-value.

ENDIF.

READ TABLE in_par WITH KEY 'VBDPR-FKIMG'.

TRANSLATE in_par-value USING ', '.

CONDENSE in_par-value NO-GAPS.

IF sy-subrc EQ 0.

lv_fkimg = in_par-value.

ENDIF.

lv_netpr = lv_netwr / lv_fkimg.

READ TABLE out_par WITH KEY 'W_PRICE'.

IF sy-subrc EQ 0.

out_par-value = lv_netpr.

APPEND out_par .

ENDIF.

ENDFORM. "get_unit_price

Here.. lv_netpr does have a value 20

but is not being assigned to out_par-value. It remains empty. any suggestions would be welcome.

Regards

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,462

You logic is a bit off, you should not be appending to the out_par table, you need to modify it.

READ TABLE out_par WITH KEY 'W_PRICE'.
IF sy-subrc EQ 0.
out_par-value = lv_netpr.
<b>Modify out_par index sy-index.</b>
ENDIF.

Regards,

Rich Heilman

16 REPLIES 16
Read only

Former Member
0 Likes
1,462

Well,

out_par-value = lv_netpr

sets the value of lv_netpr to teh value of out_par-value, not vice versa!!!

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,463

You logic is a bit off, you should not be appending to the out_par table, you need to modify it.

READ TABLE out_par WITH KEY 'W_PRICE'.
IF sy-subrc EQ 0.
out_par-value = lv_netpr.
<b>Modify out_par index sy-index.</b>
ENDIF.

Regards,

Rich Heilman

Read only

0 Likes
1,462

Hi Rich,

I had already tried uSing MODIFY .. It didnt work either.

Regards

Message was edited by: Nishant Gupta

Read only

0 Likes
1,462

Can you please make sure that 'W_PRICE' is a CHANGING parameter in your PERFORM statement in your sapscript.

Regards,

Rich Heilman

Read only

0 Likes
1,462

it is a changing parameter Rich

Regards

Read only

0 Likes
1,462

Can you verify that that SY-SUBRC = 0 after this read statement?




<b>READ TABLE out_par WITH KEY 'W_PRICE'.</b>
IF sy-subrc EQ 0.
out_par-value = lv_netpr.
MODIFY out_par index sy-index .
ENDIF.

Read only

0 Likes
1,462

Try this.


DATA: l_index LIKE sy-tabix.
READ TABLE out_par WITH KEY 'W_PRICE'.
IF sy-subrc EQ 0.
  l_index = sy-tabix.
  out_par-value = lv_netpr.
  MODIFY out_par INDEX l_index.
ENDIF.

I meant l_index instead of sy-index and lost some points in the process!!!

Message was edited by: Srinivas Adavi

Read only

0 Likes
1,462

i checked it in debugging mode....

Sy-subrc is 0.

and i used sy-tabix, not sy-index..

Out_par table has no value in its value field.

Read only

0 Likes
1,462

Oh yes, SY-TABIX. This should be working for you then. Can you verify that lv_netpr is actually moving to the out_par-value field in this statement?



READ TABLE out_par WITH KEY 'W_PRICE'.
IF sy-subrc EQ 0.
<b>out_par-value = lv_netpr.</b>
Modify out_par index sy-tabix.
ENDIF.


Regards,

Rich HEilman

Read only

0 Likes
1,462

no it is not moving....

regards

Message was edited by: Nishant Gupta

Read only

0 Likes
1,462

The problem is that you can see it. It is there, but to the right a bit. The reason is because the out_par-value field is 255 characters. You can use the SHIFT statement to get rid of all of the blank spaces. then you will be able to see the value for l_netpr.

Please add the following code.

READ TABLE out_par WITH KEY 'W_PRICE'.
IF sy-subrc EQ 0.
out_par-value = lv_netpr.
<b>shift out_par-value left deleting leading space.</b>
Modify out_par index sy-tabix.
ENDIF.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Read only

0 Likes
1,462

!!!!! thanks Rich..why was this happening? have given u 26 points for this.

Message was edited by: Nishant Gupta

Read only

0 Likes
1,462

Because the target is 255 characters, moving an INT to this field will put it at the end of the field. You could have done this as well.

This will put the value in the first 15 characters of the field.

out_par-value+0(10) = l_netpr.

Regards,

Rich Heilman

Read only

0 Likes
1,462

Here is a sample program to better illistrate.




report zrich_0001 line-size 255.

data: out_par type table of  itcsy with header line.
data: l_netpr type i value '20'.


out_par-value = l_netpr.

write:/ 'Check this out,  OUT_PAR-VALUE is way out there --->'.
write:/ l_netpr.
write:/ out_par-value.

skip 2.

write:/ 'Getting rid of the space will fix it'.
shift out_par-value left deleting leading space.
write:/ l_netpr.
write:/ out_par-value.

check sy-subrc  = 0.


Regards,

Rich Heilman

Read only

0 Likes
1,462

Thanks once again...

Read only

Former Member
0 Likes
1,462

hi

why dont you try this

wa_outpar type itcsy.

read table out_par into wa_outpar with key 'W_PRICE'.

wa_outpar-value = lv_netpr.

modify outpar from wa_outpar transporting value.

Hope this works