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

plz check the code

Former Member
0 Likes
622

Hi,

Can anyone please tell me why the 'matnr' field values is not getting appended into the table gt_out.

points for sure.

My code :

SELECT mblnr mjahr budat

FROM mkpf

INTO TABLE gt_mkpf

WHERE budat IN s_budat .

IF NOT gt_mkpf[] IS INITIAL.

SELECT mblnr mjahr zeile bwart matnr shkzg menge meins charg

FROM mseg

INTO TABLE gt_mseg

FOR ALL ENTRIES IN gt_mkpf

WHERE mblnr = gt_mkpf-mblnr AND mjahr = gt_mkpf-mjahr.

ENDIF.

IF NOT gt_mseg[] IS INITIAL.

SELECT matnr matkl

FROM mara

INTO TABLE gt_mara

FOR ALL ENTRIES IN gt_mseg

WHERE matnr = gt_mseg-matnr AND matkl IN s_matkl.

ENDIF.

LOOP AT gt_mkpf .

CLEAR gt_out.

LOOP AT gt_mseg WHERE mblnr = gt_mkpf-mblnr AND mjahr = gt_mkpf-mjahr.

gt_out-menge = gt_mseg-menge.

gt_out-meins = gt_mseg-meins.

gt_out-charg = gt_mseg-charg.

IF gt_mseg-shkzg = 'H'.

gt_out-menge = ( -1 ) * gt_out-menge.

ENDIF.

READ TABLE gt_mara WITH KEY matnr = gt_mseg-matnr .

IF sy-subrc EQ 0.

gt_out-matnr = gt_mara-matnr.

ENDIF.

ENDLOOP.

gt_out-budat = gt_mkpf-budat.

APPEND gt_out.

ENDLOOP.

Regards

rose

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
598

Hi Rose,

Your code is looking fine.

Just check in the debugging mode.

READ TABLE gt_mara WITH KEY matnr = gt_mseg-matnr .

IF sy-subrc EQ 0.

gt_out-matnr = gt_mara-matnr.

ENDIF.

Are you getting matching record in gt_mara for the gt_mseg.

Check sy-subrc. Is it 0 for any record

5 REPLIES 5
Read only

Former Member
0 Likes
599

Hi Rose,

Your code is looking fine.

Just check in the debugging mode.

READ TABLE gt_mara WITH KEY matnr = gt_mseg-matnr .

IF sy-subrc EQ 0.

gt_out-matnr = gt_mara-matnr.

ENDIF.

Are you getting matching record in gt_mara for the gt_mseg.

Check sy-subrc. Is it 0 for any record

Read only

0 Likes
598

Hi Mukesh,

I checked the sy-subrc value.the value is 4.

What am i supposed to do.

Can u please help me..

Regards

rose

Read only

0 Likes
598

hi rose,

that means that there is not any matching record in gt_mara and gt_mseg so no matnr will come. it should match so select any material that is present in mseg and mara both for the selection condition.

Debug the code carefully you will get what is the problem and how to solve it.

Read only

0 Likes
598

Hi Rose Preethi

follow the code of parul she is absolutely right if it still not working then remove the inner loop and follow the code:

sort gt_mara by matnr.

sort gt_mseg by mblnr mjahr.

LOOP AT gt_mkpf .

CLEAR gt_out.

refresh gtout._

read table gt_mseg with key mblnr = gt_mkpf-mblnr AND mjahr = gt_mkpf-mjahr binary search.

gt_out-menge = gt_mseg-menge.

gt_out-meins = gt_mseg-meins.

gt_out-charg = gt_mseg-charg.

IF gt_mseg-shkzg = 'H'.

gt_out-menge = ( -1 ) * gt_out-menge.

ENDIF.

READ TABLE gt_mara WITH KEY matnr = gt_mseg-matnr binary search .

IF sy-subrc EQ 0.

gt_out-matnr = gt_mara-matnr.

ENDIF.

gt_out-budat = gt_mkpf-budat.

APPEND gt_out.

modify gt_out.

clear gt_out.

ENDLOOP.

Reaward if helpful

Read only

Former Member
0 Likes
598

Hi,

Your values are not getting appended because..after the read statement you are not appending the values, before the ending of inner loop.

LOOP AT gt_mkpf .

CLEAR gt_out.

LOOP AT gt_mseg WHERE mblnr = gt_mkpf-mblnr AND mjahr = gt_mkpf-mjahr.

gt_out-menge = gt_mseg-menge.

gt_out-meins = gt_mseg-meins.

gt_out-charg = gt_mseg-charg.

IF gt_mseg-shkzg = 'H'.

gt_out-menge = ( -1 ) * gt_out-menge.

ENDIF.

READ TABLE gt_mara WITH KEY matnr = gt_mseg-matnr .

IF sy-subrc EQ 0.

gt_out-matnr = gt_mara-matnr.

Append gt_out.

ENDIF.

ENDLOOP.

gt_out-budat = gt_mkpf-budat.

APPEND gt_out.

Modify gt_out transporting budat.

ENDLOOP.

hope it will help u.

Reward points if helpful.

Thanks,

Parul.