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 debug this code

Former Member
0 Likes
638

...the value of sy-subrc is 4 after extraction of data, but the data is not coming on the output screen:----

REPORT Y_GR_DETAIL.

TABLES : ZMM_MIGOHD,

MKPF,

MSEG,

KNA1.

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-000.

PARAMETERS :

COMP_COD LIKE MSEG-BUKRS ,

VEND_NO LIKE KNA1-KUNNR.

selection-screen skip 1.

SELECT-OPTIONS :

POST_DAT FOR MKPF-BUDAT,

DOC_NO FOR MSEG-MBLNR.

SELECTION-SCREEN END OF BLOCK BLK1.

DATA : BEGIN OF itab1 OCCURS 0,

MBLNR LIKE MSEG-MBLNR,

DMBTR LIKE MSEG-DMBTR,

MJAHR LIKE MSEG-MJAHR,

BNBTR LIKE MSEG-BNBTR,

BLDAT LIKE MKPF-BLDAT,

ORT01 LIKE KNA1-ORT01,

GATNO LIKE ZMM_MIGOHD-GATNO,

VEHNO LIKE ZMM_MIGOHD-VEHNO,

TNAME LIKE ZMM_MIGOHD-TNAME,

kunnr like mseg-kunnr,

END OF itab1.

SELECT mblnr dmbtr mjahr bnbtr kunnr FROM mseg into corresponding fields of table itab1

WHERE mblnr IN post_dat

AND bukrs = comp_cod.

write : sy-subrc.

select bldat from mkpf into corresponding fields of table itab1

for all entries in itab1 where mblnr = itab1-mblnr.

select gatno vehno tname from zmm_migohd into corresponding fields of table itab1

for all entries in itab1 where mblnr = itab1-mblnr.

select name1 from kna1 into corresponding fields of table itab1

for all entries in itab1 where kunnr = itab1-kunnr.

loop at itab1.

write : / itab1-mblnr,

itab1-dmbtr,

itab1-mjahr,

itab1-bnbtr,

itab1-bldat,

itab1-ort01,

itab1-gatno,

itab1-vehno,

itab1-tname.

endloop.

AT LINE-SELECTION.

IF ITAB1-mblnr <> SPACE.

SET PARAMETER ID 'MBN' FIELD ITAB1-mblnr.

CALL TRANSACTION 'MIGO' AND SKIP FIRST SCREEN.

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
599

If sy-subrc returns 4 then the select statement is not retirveing any values.

5 REPLIES 5
Read only

Former Member
0 Likes
600

If sy-subrc returns 4 then the select statement is not retirveing any values.

Read only

Former Member
0 Likes
599

>the value of sy-subrc is 4 after extraction of data, but the data is not coming on the output screen:----

sy-subrc is 4 means , select failed.

REPORT Y_GR_DETAIL.

TABLES : ZMM_MIGOHD,
MKPF,
MSEG,
KNA1.

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-000.

PARAMETERS :
COMP_COD LIKE MSEG-BUKRS ,
VEND_NO LIKE KNA1-KUNNR.
selection-screen skip 1.
SELECT-OPTIONS :
POST_DAT FOR MKPF-BUDAT,
DOC_NO FOR MSEG-MBLNR.
SELECTION-SCREEN END OF BLOCK BLK1.

DATA : BEGIN OF itab1 OCCURS 0,
MBLNR LIKE MSEG-MBLNR,
DMBTR LIKE MSEG-DMBTR,
MJAHR LIKE MSEG-MJAHR,
BNBTR LIKE MSEG-BNBTR,
BLDAT LIKE MKPF-BLDAT,
ORT01 LIKE KNA1-ORT01,
GATNO LIKE ZMM_MIGOHD-GATNO,
VEHNO LIKE ZMM_MIGOHD-VEHNO,
TNAME LIKE ZMM_MIGOHD-TNAME,
kunnr like mseg-kunnr,
END OF itab1.

SELECT mblnr dmbtr mjahr bnbtr kunnr FROM mseg into corresponding fields of table itab1
WHERE mblnr IN post_dat
AND bukrs = comp_cod.
write : sy-subrc.
if not itab1[] is initial. "<-----add this logic here
" you are using the itab1 table as for all entries and moving data to the same table
"instead you can have separate tables and using read you can write the data.

select bldat from mkpf into corresponding fields of table itab1
for all entries in itab1 where mblnr = itab1-mblnr.
select gatno vehno tname from zmm_migohd into corresponding fields of table itab1
for all entries in itab1 where mblnr = itab1-mblnr.
select name1 from kna1 into corresponding fields of table itab1
for all entries in itab1 where kunnr = itab1-kunnr.
endif.
loop at itab1.
write : / itab1-mblnr,
itab1-dmbtr,
itab1-mjahr,
itab1-bnbtr,
itab1-bldat,
itab1-ort01,
itab1-gatno,
itab1-vehno,
itab1-tname.
endloop.

AT LINE-SELECTION.
IF ITAB1-mblnr SPACE.
SET PARAMETER ID 'MBN' FIELD ITAB1-mblnr.
CALL TRANSACTION 'MIGO' AND SKIP FIRST SCREEN.
ENDIF.

Read only

Former Member
0 Likes
599

hi mathew,

your approach to club fields from 4 database table is wrong.

i have for all entries in two tables field, the same way do it for your 4 dbtables fields.

1. create separate internal table for fields of particular database table. In your case u r fetching data fram 4 dbtables so create 4 internal tables.

2. what u have created is actually final internal table where you need to move data after fetching from respective tables and doing for all entries.

i have created program for two tables the same way create for your four tables:

data: begin of it_vbak occurs 0,

vbeln TYPE vbak-vbeln,

erdat TYPE vbak-erdat,

kunnr TYPE vbak-kunnr,

ernam TYPE vbak-ernam,

end of it_vbak.

****************************************************

data: begin of it_vbap occurs 0,

VBELN type vbap-VBELN, "sales order

MATNR type vbap-MATNR, "material no

ARKTX type vbap-ARKTX, "material description

ntgew type vbap-ntgew, "quantity

gewei type vbap-gewei, "quantity unit

NETWR type vbap-NETWR, "currency

WAERK type vbap-WAERK, "currency unit

WERKS type vbap-WERKS, "plant

end of it_vbap.

****************************************************

data: begin of it_final occurs 0,

vbeln TYPE vbak-vbeln,

erdat TYPE vbak-erdat,

kunnr TYPE vbak-kunnr,

ernam TYPE vbak-ernam,

MATNR type vbap-MATNR, "material no

ARKTX type vbap-ARKTX, "material description

ntgew type vbap-ntgew, "quantity

gewei type vbap-gewei, "quantity unit

NETWR type vbap-NETWR, "currency

WAERK type vbap-WAERK, "currency unit

WERKS type vbap-WERKS, "plant

end of it_final.

****************************************************

select-options: s_werks for vbap-werks,

s_matnr for vbap-matnr,

s_kunnr for vbak-kunnr,

s_vbeln for vbak-vbeln.

select vbeln

erdat

kunnr

ernam from vbak into table it_vbak where vbeln in s_vbeln.

select VBELN

MATNR

ARKTX

ntgew

gewei

NETWR

WAERK

WERKS from vbap into table it_vbap for all entries in it_vbak where vbeln eq it_vbak-vbeln.

loop at it_vbak.

move it_vbak-VBELN to it_final-VBELN.

move it_vbak-erdat to it_final-erdat.

move it_vbak-KUNNR to it_final-KUNNR.

move it_vbak-ernam to it_final-ernam.

read table it_vbap into wa_vbap with key vbeln = wa_vbak-vbeln.

move it_vbap-MATNR to it_final-MATNR.

move it_vbap-ARKTX to it_final-ARKTX.

move it_vbap-ntgew to it_final-ntgew.

move it_vbap-gewei to it_final-gewei.

move it_vbap-NETWR to it_final-NETWR.

move it_vbap-WAERK to it_final-WAERK.

move it_vbap-WERKS to it_final-WERKS.

append it_final.

endloop.

hope this will help u.

Read only

Former Member
0 Likes
599

Hi,

If sy-subrc = 0.

The data is retrieved from the database table into the internal table.

if sy-subrc = 4.

then no data is retrieved.

Thanks & Regards,

Y.R.Prem Kumar

Read only

Former Member
0 Likes
599

hi,

try to follow this code :

TABLES : ZMM_MIGOHD,

MKPF,

MSEG,

KNA1.

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-000.

PARAMETERS :

COMP_COD LIKE MSEG-BUKRS ,

VEND_NO LIKE KNA1-KUNNR.

selection-screen skip 1.

SELECT-OPTIONS :

POST_DAT FOR MKPF-BUDAT,

DOC_NO FOR MSEG-MBLNR.

SELECTION-SCREEN END OF BLOCK BLK1.

DATA : BEGIN OF it_mseg OCCURS 0,

MBLNR LIKE MSEG-MBLNR,

DMBTR LIKE MSEG-DMBTR,

MJAHR LIKE MSEG-MJAHR,

BNBTR LIKE MSEG-BNBTR,

kunnr like mseg-kunnr,

END OF it_mseg.

DATA : BEGIN OF it_mkpf OCCURS 0,

MBLNR LIKE MKPF-MBLNR,

BLDAT LIKE MKPF-BLDAT,

END OF it_mkpf.

DATA : BEGIN OF it_ZMM_MIGOHD OCCURS 0,

MBLNR LIKE ZMM_MIGOHD-MBLNR,

GATNO LIKE ZMM_MIGOHD-GATNO,

VEHNO LIKE ZMM_MIGOHD-VEHNO,

TNAME LIKE ZMM_MIGOHD-TNAME,

END OF it_ZMM_MIGOHD.

DATA : BEGIN OF it_KNA1 OCCURS 0,

kunnr like KNA1-kunnr,

ORT01 LIKE KNA1-ORT01,

END OF it_KNA1.

DATA : BEGIN OF itab1 OCCURS 0,

MBLNR LIKE MSEG-MBLNR,

DMBTR LIKE MSEG-DMBTR,

MJAHR LIKE MSEG-MJAHR,

BNBTR LIKE MSEG-BNBTR,

BLDAT LIKE MKPF-BLDAT,

ORT01 LIKE KNA1-ORT01,

GATNO LIKE ZMM_MIGOHD-GATNO,

VEHNO LIKE ZMM_MIGOHD-VEHNO,

TNAME LIKE ZMM_MIGOHD-TNAME,

kunnr like mseg-kunnr,

END OF itab1.

SELECT mblnr dmbtr mjahr bnbtr kunnr FROM mseg into corresponding fields of table it_mseg

WHERE mblnr IN post_dat

AND bukrs = comp_cod.

write : sy-subrc.

select bldat from mkpf into corresponding fields of table it_mkpf

for all entries in it_mseg where mblnr = it_mseg-mblnr.

select gatno vehno tname from zmm_migohd into corresponding fields of table it_zmm_migohd

for all entries in it_mseg where mblnr = it_mseg-mblnr.

select ORT01 from kna1 into corresponding fields of table it_KNA1

for all entries in it_mseg where kunnr = it_mseg-kunnr.

loop at it_mseg.

refresh itab1[].

MOVE-CORRESPONDING it_mseg TO itab1.

read table it_mkpf with key mblnr = it_mseg-mblnr.

MOVE-CORRESPONDING it_mkpf TO itab1.

read table it_zmm_migohd with key mblnr = it_mseg-mblnr.

MOVE-CORRESPONDING it_zmm_migohd TO itab1.

read table it_KNA1 with key kunnr = it_mseg-kunnr.

MOVE-CORRESPONDING it_KNA1 TO itab1.

append itab1.

endloop.

loop at itab1.

write : / itab1-mblnr,

itab1-dmbtr,

itab1-mjahr,

itab1-bnbtr,

itab1-bldat,

itab1-ort01,

itab1-gatno,

itab1-vehno,

itab1-tname.

endloop.

AT LINE-SELECTION.

IF ITAB1-mblnr SPACE.

SET PARAMETER ID 'MBN' FIELD ITAB1-mblnr.

CALL TRANSACTION 'MIGO' AND SKIP FIRST SCREEN.

ENDIF.