Skip to Content
0

Correct my code using new open SQL statement

Feb 26 at 01:22 PM

20

avatar image
Former Member

Hi,

Here below, I am sending you my code using new open sql statement,

Actually the problem is I am getting the data using fetch_data, once its going to process_data, the data is clearing of my first subroutine.

*******************************************
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

REPORT Z_TEST2.

data : gv_kunnr type kna1-kunnr.
data : lv_lines type i,
count type i.

data : it_final type table of Zstr,
wa_final type ZSTR,
it_kna1 type table of kna1,
it_knb1 type table of knb1,
it_vbak type table of vbak,
it_vbap type table of vbap.

data : it_fcat type slis_t_fieldcat_alv,
wa_fcat type slis_fieldcat_alv,
wa_layout type slis_layout_alv.

SELECT-OPTIONS : s_kunnr for gv_kunnr.

START-OF-SELECTION.
perform fetch_data .
perform process_data .
if it_final is not INITIAL.
perform field_cat.
perform display_data.
else.
message 'Data does not Exist' type 'E'.
endif.

*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*

FORM fetch_data .
select kunnr,land1,name1,ort01 from kna1 into TABLE
@data(it_kna1) where kunnr in @s_kunnr.

sort it_kna1 by kunnr.


select kunnr,bukrs,pernr,akont from knb1 into table
@data(it_knb1) for ALL ENTRIES IN @it_kna1 where kunnr = @it_kna1-kunnr.

select vbeln,erdat,erzet,ernam,kunnr from vbak into table
@data(it_vbak) for ALL ENTRIES IN @it_kna1 where kunnr = @it_kna1-kunnr.

select vbeln,posnr,matnr,netwr from vbap into table
@data(it_vbap) for ALL ENTRIES IN @it_vbak where vbeln = @it_vbak-vbeln.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*

FORM process_data .


loop at it_kna1 into data(wa_kna1).
wa_final-kunnr = wa_kna1-kunnr.
wa_final-land1 = wa_kna1-land1.
wa_final-name1 = wa_kna1-name1.
wa_final-ort01 = wa_kna1-ort01.

read table it_knb1 into data(wa_knb1) with key kunnr = wa_kna1-kunnr.
if sy-subrc eq 0 .
wa_final-bukrs = wa_knb1-bukrs.
wa_final-pernr = wa_knb1-pernr.
wa_final-akont = wa_knb1-akont.
endif.

read table it_vbak into data(wa_vbak) WITH KEY kunnr = wa_kna1-kunnr.
if sy-subrc eq 0.
wa_final-vbeln = wa_vbak-vbeln.
wa_final-erdat = wa_vbak-erdat.
wa_final-erzet = wa_vbak-erzet.
wa_final-ernam = wa_vbak-ernam.
endif.

read table it_vbap into data(wa_vbap) with key vbeln = wa_vbak-vbeln.
if sy-subrc eq 0.
wa_final-posnr = wa_vbap-posnr.
wa_final-matnr = wa_vbap-matnr.
wa_final-netwr = wa_vbap-netwr.
endif.

append wa_final to it_final.
clear : wa_final.
endloop.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FIELD_CAT
*&---------------------------------------------------------------------*

FORM field_cat .
clear wa_fcat.
refresh it_fcat.

count = count + 1.
wa_fcat-fieldname = 'KUNNR'.
wa_fcat-seltext_m = 'Customer Number'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'LAND1'.
wa_fcat-seltext_m = 'Country Name'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'NAME1'.
wa_fcat-seltext_m = 'Customer Name'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'ORT01'.
wa_fcat-seltext_m = 'City'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-seltext_m = 'Document Number'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-seltext_m = 'Date'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-seltext_m = 'Time'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-seltext_m = 'Person Name'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-seltext_m = 'Document Item'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_m = 'Material Number'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-seltext_m = 'Net Price'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'BUKRS'.
wa_fcat-seltext_m = 'Company Code'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'PERNR'.
wa_fcat-seltext_m = 'Personnel Number'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.

count = count + 1.
wa_fcat-fieldname = 'AKONT'.
wa_fcat-seltext_m = 'Gernal Ledger'.
wa_fcat-tabname = 'IT_FINAL'.
append wa_fcat to it_fcat.
clear wa_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*

FORM display_data .

wa_layout-colwidth_optimize = 'X'.
wa_layout-zebra = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IS_LAYOUT = wa_layout
IT_FIELDCAT = it_fcat
I_SAVE = 'A'
TABLES
t_outtab = it_final
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

SQL
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers