Abap Müşteri Fatura Örneği

Ana Program

&———————————————————————
& Report ZMK_ALV_SECIM
*&———————————————————————

&-
*&———————————————————————

REPORT ZMK_ALV_SECIM.

include ZMK_ALV_SECIM_TOP.
INCLUDE ZMK_ALV_SECIM_F01.

Top Kod Bloğu

&———————————————————————
& Include ZMK_ALV_SECIM_TOP
*&———————————————————————

TYPES: BEGIN OF t_show,
old type i,
new TYPE c,
END OF t_show.

TABLES: zkm_t_musteri,
zkm_t_fatura,
sscrfields.

DATA: gt_musteri TYPE TABLE OF zkm_t_musteri,
gt_musteri_backup TYPE TABLE OF zkm_t_musteri,
wa_musteri type zkm_t_musteri,
wa_musteri_backup TYPE zkm_t_musteri,
st_musteri TYPE zkm_t_musteri,
st_musteri_backup type zkm_t_musteri,
st_fatura TYPE zkm_t_fatura,
gt_fatura type TABLE OF zkm_st_fatura,
gt_structure LIKE dd02l-tabname VALUE ‘ZKM_ST_MUSTERI’,
lt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_show TYPE TABLE OF t_show WITH HEADER LINE,
wa_show TYPE t_show.

CONSTANTS :gc_x TYPE xfeld VALUE ‘X’.

SELECTION-SCREEN BEGIN OF BLOCK 100 WITH FRAME TITLE TEXT-001.
PARAMETERS :
p_new RADIOBUTTON GROUP rb1,
p_del RADIOBUTTON GROUP rb1,
p_show RADIOBUTTON GROUP rb1.
SELECTION-SCREEN PUSHBUTTON /10(10) TEXT-002 USER-COMMAND click1.
SELECTION-SCREEN END OF BLOCK 100.

SELECTION-SCREEN BEGIN OF SCREEN 200 AS WINDOW TITLE TEXT-006.
SELECTION-SCREEN BEGIN OF BLOCK radios WITH FRAME TITLE TEXT-005.
PARAMETERS :
p_mus RADIOBUTTON GROUP rb2 DEFAULT ‘X’ USER-COMMAND rb,
p_fat RADIOBUTTON GROUP rb2.
SELECTION-SCREEN END OF BLOCK radios.

SELECTION-SCREEN BEGIN OF BLOCK paras WITH FRAME TITLE TEXT-004.

PARAMETERS: p_id TYPE zkm_t_musteri-musteri_id MODIF ID MUS.
PARAMETERS: p_no TYPE zkm_t_musteri-vergi_no MODIF ID MUS.
PARAMETERS: p_name TYPE zkm_t_musteri-musteri_ad MODIF ID MUS.
PARAMETERS: p_adr TYPE zkm_t_musteri-musteri_mail MODIF ID MUS.
PARAMETERS: p_tel TYPE zkm_t_musteri-musteri_tel MODIF ID MUS.

PARAMETERS: p_fno TYPE zkm_t_fatura-fatura_no MODIF ID FAT.
PARAMETERS: p_mid TYPE zkm_t_fatura-musteri_id MODIF ID FAT.
PARAMETERS: p_ftut TYPE zkm_t_fatura-fatura_tutari MODIF ID FAT.
PARAMETERS: p_kdv TYPE zkm_t_fatura-kdv_orani MODIF ID FAT.
PARAMETERS: p_ktu TYPE zkm_t_fatura-kdvsiz_tutar MODIF ID FAT.

SELECTION-SCREEN PUSHBUTTON /10(20) TEXT-003 USER-COMMAND cli_add.
SELECTION-SCREEN END OF BLOCK paras.
SELECTION-SCREEN END OF SCREEN 200.

SELECTION-SCREEN BEGIN OF SCREEN 300 AS WINDOW TITLE TEXT-007.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-005.
PARAMETERS :
p_musd RADIOBUTTON GROUP rb3 DEFAULT ‘X’ USER-COMMAND rb,
p_fatd RADIOBUTTON GROUP rb3.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK params WITH FRAME TITLE TEXT-004.
PARAMETERS: p_mnod TYPE zkm_t_musteri-musteri_id MODIF ID MUS MATCHCODE OBJECT zkm_t_musteri_esh02.
PARAMETERS: p_fnod TYPE zkm_t_fatura-fatura_no MODIF ID FAT MATCHCODE OBJECT zkm_t_fat_esh01.

SELECTION-SCREEN PUSHBUTTON /10(10) TEXT-008 USER-COMMAND cli_fetch.
PARAMETERS: p_idp TYPE zkm_t_musteri-musteri_id MODIF ID MUS.
PARAMETERS: p_namep TYPE zkm_t_musteri-musteri_ad MODIF ID MUS.
PARAMETERS: p_adrp TYPE zkm_t_musteri-musteri_mail MODIF ID MUS.
PARAMETERS: p_telp TYPE zkm_t_musteri-musteri_tel MODIF ID MUS.
PARAMETERS: p_verp TYPE zkm_t_musteri-vergi_no MODIF ID MUS.

PARAMETERS: p_fnop TYPE zkm_t_fatura-fatura_no MODIF ID FAT.
PARAMETERS: p_fmidp TYPE zkm_t_fatura-musteri_id MODIF ID FAT.
PARAMETERS: p_ftutp TYPE zkm_t_fatura-fatura_tutari MODIF ID FAT.
PARAMETERS: p_fkdvp TYPE zkm_t_fatura-kdv_orani MODIF ID FAT.
PARAMETERS: p_fktup TYPE zkm_t_fatura-kdvsiz_tutar MODIF ID FAT.

SELECTION-SCREEN PUSHBUTTON /10(20) TEXT-009 USER-COMMAND cli_del .
SELECTION-SCREEN END OF BLOCK params.
SELECTION-SCREEN END OF SCREEN 300.

F01 Kod Bloğu

&———————————————————————
& Include ZMK_ALV_SECIM_F01
*&———————————————————————

AT SELECTION-SCREEN OUTPUT .

IF sy-dynnr EQ ‘0200’.

LOOP AT SCREEN .
  CASE gc_x.
    WHEN p_mus.
      IF screen-group1 = 'MUS' .
        screen-active = 1.
      ELSEIF screen-group1 = 'FAT' .
        screen-active = 0.
      ENDIF.
    WHEN P_FAT.
      IF screen-group1 = 'MUS' .
        screen-active = 0.
      ELSEIF screen-group1 = 'FAT' .
        screen-active = 1.
      ENDIF.
  ENDCASE.
  MODIFY SCREEN.
ENDLOOP.

ELSEIF sy-dynnr EQ ‘0300’.
LOOP AT SCREEN.
CASE gc_x.
WHEN p_musd.
IF screen-group1 = ‘MUS’ .
screen-active = 1.
ELSEIF screen-group1 = ‘FAT’ .
screen-active = 0.
ENDIF.
WHEN P_FATD.
IF screen-group1 = ‘MUS’ .
screen-active = 0.
ELSEIF screen-group1 = ‘FAT’ .
screen-active = 1.
ENDIF.
ENDCASE.
IF NOT ( screen-name = ‘P_NOD’ OR
screen-name = ‘P_DNOD’ OR
screen-group3 = ‘PBU’ OR
screen-name = ‘P_MUSD’ OR
screen-name = ‘P_FATD’).
screen-input = 1.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
&———————————————————————
& AT SELECTION-SCREEN
*&———————————————————————

* this ‘At selection-screen’ for other screens
———————————————————————-
AT SELECTION-SCREEN .
PERFORM f_sel_screen_output.

FORM f_sel_screen_output .
CASE sscrfields-ucomm.
WHEN ‘CLICK1’.

  CASE gc_x.
    WHEN p_new.
      IF  sy-dynnr  NE  '0200'.
        CALL SELECTION-SCREEN 200 STARTING AT 5 5.
      ENDIF.
    WHEN p_del.
      IF  sy-dynnr  NE  '0200'.
        CALL SELECTION-SCREEN 300 STARTING AT 5 5.
      ENDIF.
    WHEN p_show.
      PERFORM f_data_retrieval.
      PERFORM create_fieldcat.
      PERFORM modify_fieldcat.
      gt_musteri_backup = gt_musteri.
      PERFORM f_display_alv.

  ENDCASE.
WHEN 'CLI_ADD'.
  PERFORM f_add_new.
WHEN 'CLI_FETCH'.
  PERFORM f_fetch.
WHEN 'CLI_DEL'.
  PERFORM f_delete.

* WHEN ‘PUSH1’.
* TAB-DYNNR = 001.
* WHEN ‘PUSH2’.
* TAB-DYNNR = 002.
ENDCASE.
* CLEAR : sscrfields-ucomm.
ENDFORM.
&———————————————————————
& FORM f_add_new
*&———————————————————————

* adding new record
———————————————————————-

FORM f_add_new.
CASE gc_x.
WHEN p_mus.
CLEAR st_musteri.
st_musteri-vergi_no = p_no .
st_musteri-musteri_id = p_id .
st_musteri-musteri_ad = p_name .
st_musteri-musteri_mail = p_adr .
st_musteri-musteri_tel = p_tel .

  INSERT zkm_t_musteri FROM st_musteri.
  IF sy-subrc EQ 0.
    MESSAGE 'Yeni kayıt başarıyla eklenmiştir.' TYPE 'I'.
    p_no          = ''.
    p_id        = ''.
    p_name       = ''.
    p_adr       = ''.
    p_tel       = ''.

  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
WHEN p_fat.
   st_fatura-fatura_no     =    p_fno   .
   st_fatura-musteri_id     =    p_mid .
   st_fatura-fatura_tutari    =    p_ftut .
   st_fatura-kdv_orani     =    p_kdv   .
   st_fatura-kdvsiz_tutar    =    p_ktu .

  INSERT zkm_t_fatura FROM st_fatura.
  IF sy-subrc EQ 0.
    MESSAGE 'Yeni kayıt başarıyla eklenmiştir.' TYPE 'I'.
    p_fno          = ''.
    p_mid        = ''.
    p_ftut        = ''.
    p_kdv          = ''.
    p_ktu       = ''.

  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
WHEN OTHERS.

ENDCASE.

ENDFORM.
&———————————————————————
& FORM f_fetch
*&———————————————————————

* fetching record for delete
———————————————————————-
FORM f_fetch.
CASE gc_x.
WHEN p_musd.
CLEAR st_musteri.
SELECT SINGLE *
FROM zkm_t_musteri
INTO st_musteri
WHERE MUSTERI_ID = p_mnod.
IF sy-subrc NE 0.
message s000(zgg) WITH ‘There is no such a record!!!’.” DISPLAY LIKE ‘S’.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
p_mnod = st_musteri-musteri_id.
* p_idp = st_musteri-musteri_id.
p_namep = st_musteri-musteri_ad.
p_adrp = st_musteri-musteri_mail.
p_telp = st_musteri-musteri_tel.
p_verp = st_musteri-vergi_no.

  ENDIF.
WHEN p_fatd.
  CLEAR st_fatura.
  SELECT SINGLE *
    FROM zkm_t_fatura
    INTO st_fatura
    WHERE FATURA_NO = p_fnod.
    IF sy-subrc NE 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
     p_fnop   = st_fatura-fatura_no    .
     p_fmidp  = st_fatura-musteri_id .
     p_fktup  = st_fatura-kdvsiz_tutar .
     p_ftutp   = st_fatura-fatura_tutari   .
     p_fkdvp  = st_fatura-kdv_orani .

    ENDIF.

ENDCASE.
ENDFORM.

&———————————————————————
& FORM f_delete
*&———————————————————————

* deleting the fetched record
———————————————————————-
FORM f_delete.
IF sy-dynnr EQ ‘0300’ .”and p_madid <> ”.
CASE gc_x.
WHEN p_musd.
DELETE zkm_t_musteri FROM st_musteri .
IF sy-subrc EQ 0.
MESSAGE ‘Kayıt başarıyla silinmiştir.’ TYPE ‘I’.
p_idp = ”.
p_verp = ”.
p_namep = ”.
p_adrp = ”.
p_telp = ”.

    ELSE.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  WHEN p_fatd.
    DELETE zkm_t_fatura FROM st_fatura .
    IF sy-subrc EQ 0.
      MESSAGE 'Kayıt başarıyla silinmiştir.' TYPE 'I'.
      p_fnop         = ''.
      p_fmidp      = ''.
      p_fktup       = ''.
      p_ftutp         = ''.
      p_fkdvp       = ''.

    ELSE.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
ENDCASE.

* else.
* MESSAGE ‘Böyle bir kayıt bulunamadı!’ TYPE ‘W’.
ENDIF.
ENDFORM.
&———————————————————————
& FORM f_display_alv
*&———————————————————————

* display alv
———————————————————————-
FORM f_display_alv.
* refresh lt_fieldcat.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = ‘F_USER_COMMAND’
i_callback_pf_status_set = ‘SET_PF_STATUS’
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_musteri
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
&———————————————————————
& FORM f_data_retrieval
*&———————————————————————

*
———————————————————————-
FORM f_data_retrieval.
SELECT * FROM zkm_t_musteri INTO CORRESPONDING FIELDS OF table gt_musteri.
ENDFORM. ” f_data_retrieval
&———————————————————————
& FORM SET_PF_STATUS
*&———————————————————————

*
———————————————————————-
FORM set_pf_status USING rt_extab TYPE slis_t_extab.

SET PF-STATUS ‘STATUS_0001’ EXCLUDING rt_extab.

ENDFORM.
&———————————————————————
& FORM f_user_command
*&———————————————————————

* user command for alv
———————————————————————-
FORM f_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.”USING p_ucomm LIKE sy-ucomm.

DATA: ok_code TYPE sy-ucomm.

ok_code = sy-ucomm.

CASE ok_code.

WHEN 'BACK'.

  LEAVE PROGRAM.

WHEN 'CANCEL'.

  LEAVE PROGRAM.

WHEN 'EXIT'.

  LEAVE PROGRAM.

ENDCASE.

DATA: gd_repid LIKE sy-repid, “Exists
ref_grid TYPE REF TO cl_gui_alv_grid.
IF ref_grid IS INITIAL.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data.
ENDIF.

CASE r_ucomm.

WHEN 'SAVE'.

*
modify zkm_t_musteri from table gt_musteri.
modify zkm_t_fatura from table gt_fatura.

  MESSAGE 'Kaydetme işlemi gerçekleştirilmiştir.' TYPE 'I'.

* READ TABLE gt_patient INDEX rs_selfield-tabindex INTO wa_patient2.
* IF sy-subrc = 0.
* READ TABLE gt_patient_backup INDEX rs_selfield-tabindex INTO wa_patient_backup2.
* IF sy-subrc = 0.
* IF wa_patient2 <> wa_patient_backup2.
*
* MODIFY zpatient FROM wa_patient2 .
* ENDIF.
* ENDIF.
* ENDIF.

  PERFORM f_data_retrieval.
  rs_selfield-refresh = 'X'.

ENDCASE.

ENDFORM.

FORM create_fieldcat.
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
i_program_name = sy-repid
i_structure_name = gt_structure
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.

ENDIF.
ENDFORM.

FORM modify_fieldcat.
LOOP AT lt_fieldcat INTO wa_fieldcat.
wa_fieldcat-edit = ‘X’.
MODIFY lt_fieldcat FROM wa_fieldcat.
ENDLOOP.
ENDFORM.

Mehdi Kapsal

Bilgisayar Mühendisi

Sence de böyle mi?

%d blogcu bunu beğendi: