Abap Personel-Çocuk İlişkisi Örneği

Ana program

&———————————————————————
& Report ZMK_PER_COCUK
*&———————————————————————

&
*&———————————————————————

REPORT zmk_per_cocuk.

*
INCLUDE zmk_per_cocuk_top.
INCLUDE zmk_per_cocuk_f01.

START-OF-SELECTION.

PERFORM select_data.

PERFORM create_fieldcat USING ‘ZMK_SG_ST_PER’ CHANGING gt_fieldcat.

PERFORM display_alv TABLES gt_personel CHANGING gt_fieldcat.

START-OF-SELECTION.

Top Kısmı Kodları

&———————————————————————
& Include ZMK_PER_COCUK_TOP
*&———————————————————————

TABLES: zmk_sg_personel,
zmk_sg_cocuk.

TYPE-POOLS: slis.

DATA: toplam_yas TYPE i value 0.
DATA: gt_personel TYPE TABLE OF zmk_sg_personel WITH HEADER LINE.
DATA: gt_cocuk type TABLE OF zmk_sg_cocuk WITH HEADER LINE.
DATA: gt_per TYPE TABLE OF zmk_sg_st_per .

*DATA: gt_per TYPE TABLE OF zmk_sg_st_per .

SELECT-OPTIONS: s_id FOR gt_personel-personel_id .

DATA: gs_layout TYPE slis_layout_alv,
gs_fieldcat TYPE slis_fieldcat_alv,
gs_structure LIKE dd02l-tabname VALUE ‘ZMK_SG_ST_PER’,
gs_sort TYPE slis_sortinfo_alv.

DATA: ok_code TYPE sy-ucomm.
ok_code = sy-ucomm.

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
wa_fieldcat1 TYPE slis_fieldcat_alv.

F01 Kodları

&———————————————————————
& Include ZMK_PER_COCUK_F01
*&———————————————————————

FORM select_data.

SELECT * FROM zmk_sg_personel
  INTO CORRESPONDING FIELDS OF TABLE gt_per
  WHERE personel_id in s_id.

  SELECT * from zmk_sg_cocuk FOR ALL ENTRIES IN @gt_personel
    WHERE PERSONEL_ID eq @gt_personel-personel_id
    INTO TABLE @gt_cocuk."@data(gt_cocuk).

LOOP AT gt_per INTO DATA(gs_per).

clear toplam_yas.

LOOP AT gt_cocuk WHERE PERSONEL_ID = gs_per-personel_id.

   toplam_yas = toplam_yas + gt_cocuk-cocuk_yas.

CASE gt_cocuk-cocuk_cinsiyet.
  WHEN 'ERKEK'.
   gs_per-toplam_erkek = gs_per-toplam_erkek  + 1.

  WHEN 'KIZ'.
   gs_per-toplam_kiz = gs_per-toplam_kiz  + 1.

  WHEN OTHERS.

ENDCASE.

ENDLOOP.

gs_per-toplam_cocuk = gs_per-toplam_kiz + gs_per-toplam_erkek.

MODIFY gt_per FROM gs_per.


 gs_per-yas_ortalama = toplam_yas /  gs_per-toplam_cocuk.

  MODIFY gt_per FROM gs_per.

ENDLOOP.

ENDFORM.

FORM create_fieldcat USING p_structure CHANGING gt_fieldcat TYPE slis_t_fieldcat_alv.

CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
i_program_name = sy-repid
i_structure_name = p_structure
CHANGING
ct_fieldcat = gt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.

IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

ENDFORM.

FORM display_alv TABLES gt_personel CHANGING gt_fieldcat TYPE slis_t_fieldcat_alv.

gs_layout-colwidth_optimize = ‘X’.
gs_layout-zebra = ‘X’.
* gs_layout-edit = ‘X’.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = ‘PF_STATUS_SET’
i_callback_user_command = ‘F_USER_COMMAND ‘
is_layout = gs_layout
it_fieldcat = gt_fieldcat

TABLES
  t_outtab                 = gt_per
EXCEPTIONS
  program_error            = 1
  OTHERS                   = 2.

ENDFORM.

FORM f_user_command USING r_ucomm LIKE sy-ucomm
is_selfield TYPE slis_selfield.

is_selfield-refresh = ‘X’.

CASE ok_code.
WHEN ‘BACK’.
LEAVE PROGRAM.
WHEN ‘CANCEL’.
LEAVE PROGRAM.
WHEN ‘EXIT’.
LEAVE PROGRAM.

WHEN OTHERS.

ENDCASE.

ENDFORM.

FORM pf_status_set USING rt_extab TYPE slis_t_extab.

SET PF-STATUS ‘STATUS_STANDARD’.

ENDFORM.

Mehdi Kapsal

Bilgisayar Mühendisi

Sence de böyle mi?

%d blogcu bunu beğendi: