SAP Yeni Abap Syntax’ larıyla beraber kod okuma ve yazma daha pratik ve eğlenceli bir hale geldi. S4Hana projelerinde de yazılımcılar Yeni Abap Syntax’ ını sıklıkla kullanabiliyor. Internal tabloların Yeni Abap Syntax’ ına göre nasıl kullanıldığına dair örnekleri aşağıda bulabilirsiniz.

Internal tablolarda,

* Gruplayarak toplam alma,
* Gruplayarak sayaç artırma,
* Filter işlemleri,
* Miktar toplama,
* Minimum miktarı bulma,
* Maksimum miktarı bulma,
* Gruplayarak aralık değişkeni oluşturma,

örneklerini bulabilirsiniz.


"Internal ana tablo yapısı için tip oluşturulması
TYPES:
BEGIN OF ty_purchasing,
  document_number TYPE vbeln_va,
  material_number TYPE matnr,
  quantity        TYPE bstmg,
  unit_of_measure TYPE bstme,
END OF ty_purchasing.
TYPES: tt_purchasing TYPE HASHED TABLE OF ty_purchasing WITH UNIQUE KEY document_number.
" 'material_number' ve 'unit_of_measure' alanları bazında gruplama yapmak için tip oluşturulması
TYPES:
BEGIN OF ty_material_group,
  material_number TYPE matnr,
  quantity        TYPE bstmg,
  unit_of_measure TYPE bstme,
  END OF ty_material_group.
TYPES: tt_material_group TYPE HASHED TABLE OF ty_material_group WITH UNIQUE KEY material_number, unit_of_measure.
" 'material_number' alanı bazında gruplama yapmak için tip oluşturulması
TYPES:
BEGIN OF ty_material_count,
  material_number TYPE matnr,
  count           TYPE i,
END OF ty_material_count.
TYPES: tt_material_count TYPE HASHED TABLE OF ty_material_count WITH UNIQUE KEY material_number.
" Internal tabloyu manuel doldurma
DATA(lt_purchasing) =  VALUE tt_purchasing(

( document_number = '1000002021' material_number = 'Material_A' quantity = '10.101' unit_of_measure = 'ST' )
( document_number = '1000002022' material_number = 'Material_A' quantity = '20.501' unit_of_measure = 'ST' )
( document_number = '1000002023' material_number = 'Material_B' quantity = '01.820' unit_of_measure = 'KG' )
( document_number = '1000002024' material_number = 'Material_B' quantity = '01.010' unit_of_measure = 'KG' )
( document_number = '1000002025' material_number = 'Material_A' quantity = '4012312312.501' unit_of_measure = 'ST' )
( document_number = '1000002026' material_number = 'Material_A' quantity = '10.050' unit_of_measure = 'ST' ) ).

cl_demo_output=>display_data( lt_purchasing ).





" Internal tabloyu 'material_number' ve 'unit_of_measure' bazında gruplayarak miktarları toplama
DATA(lt_material_group) = VALUE tt_material_group(
                            FOR GROUPS purchasing_grp OF <ls_purchasing> IN lt_purchasing
                          GROUP BY ( material_number = <ls_purchasing>-material_number
                                     unit_of_measure = <ls_purchasing>-unit_of_measure )
                            LET purchasing_line = REDUCE #(
                                                    INIT line TYPE ty_material_group FOR <member> IN GROUP purchasing_grp
                                                    NEXT line-material_number = <member>-material_number
                                                         line-unit_of_measure = <member>-unit_of_measure
                                                         line-quantity        = line-quantity + <member>-quantity )
                                                      IN ( purchasing_line ) ) .
                                                
cl_demo_output=>display_data( lt_material_group ).





" Internal tabloyu 'material_number' bazında gruplayarak sayaç artırma
DATA(lt_material_count) = VALUE tt_material_count(
                            FOR GROUPS purchasing_grp OF <ls_purchasing> IN lt_purchasing
                          GROUP BY ( material_number = <ls_purchasing>-material_number )
                            LET purchasing_line = REDUCE #(
                                                    INIT line TYPE ty_material_count FOR <member> IN GROUP purchasing_grp
                                                    NEXT line-material_number = <member>-material_number
                                                         line-count = line-count + 1 )
                                                      IN ( purchasing_line ) ) .
                                                  
cl_demo_output=>display_data( lt_material_count ).





" Internal tabloyu 'material_number' bazında gruplayarak sayaç artırma
DATA(lt_material_count) = VALUE tt_material_count(
                            FOR GROUPS purchasing_grp OF <ls_purchasing> IN lt_purchasing
                          GROUP BY ( material_number = <ls_purchasing>-material_number )
                            LET purchasing_line = REDUCE #(
                                                    INIT line TYPE ty_material_count FOR <member> IN GROUP purchasing_grp
                                                    NEXT line-material_number = <member>-material_number
                                                         line-count = line-count + 1 )
                                                      IN ( purchasing_line ) ) .
                                                  
cl_demo_output=>display_data( lt_material_count ).





" Internal tablodaki ölçü birimi 'KG' olanlar için sayaç artırma
DATA(lv_lines_kg) = REDUCE i( INIT x_lines_kg = 0 FOR wa_lines_kg IN lt_purchasing
                     WHERE ( unit_of_measure = 'KG' ) NEXT x_lines_kg = x_lines_kg + 1 ).
                     
cl_demo_output=>display_data( lv_lines_kg ).






" Internal tablodaki ölçü birimi 'ST' olanlar için miktar toplama
DATA(lv_sum_quantity_kg) = REDUCE bstmg( INIT x_lines_kg = '0000000000000' FOR wa_lines_kg IN lt_purchasing
                            WHERE ( unit_of_measure = 'ST' ) NEXT x_lines_kg = x_lines_kg + wa_lines_kg-quantity ).
                          
cl_demo_output=>display_data( lv_sum_quantity_kg ).





" Internal tablodaki ölçü birimi 'KG' olanlar için sayaç artırma
DATA(lv_lines_kg) = REDUCE i( INIT x_lines_kg = 0 FOR wa_lines_kg IN lt_purchasing
                     WHERE ( unit_of_measure = 'KG' ) NEXT x_lines_kg = x_lines_kg + 1 ).
                      
cl_demo_output=>display_data( lv_lines_kg ).





" Internal tablodaki ölçü birimi 'ST' olanlar için miktar toplama
DATA(lv_sum_quantity_kg) = REDUCE bstmg( INIT x_lines_kg = '0000000000000' FOR wa_lines_kg IN lt_purchasing
                            WHERE ( unit_of_measure = 'ST' ) NEXT x_lines_kg = x_lines_kg + wa_lines_kg-quantity ).
                            
cl_demo_output=>display_data( lv_sum_quantity_kg ).





" Internal tablodaki minimum miktarı bulma
DATA(min_quantity) = REDUCE bstmg( INIT res = '9999999999999' FOR purchasing_min IN lt_purchasing
                       NEXT res = COND #( WHEN purchasing_min-quantity < res THEN purchasing_min-quantity ELSE res ) ).

cl_demo_output=>display_data( min_quantity ).





" Internal tablodaki maksimum miktarı bulma
DATA(max_quantity) = REDUCE bstmg( INIT res = '00000000000000' FOR purchasing_max IN lt_purchasing
                       NEXT res = COND #( WHEN purchasing_max-quantity > res THEN purchasing_max-quantity ELSE res ) ).

cl_demo_output=>display_data( max_quantity ).





" Internal tabloyu 'material_number' bazında gruplayarak aralık değişkeni oluşturma
DATA(ltr_material) = VALUE ranges_matnr(
                       FOR GROUPS purchasing_grp OF <purchasing> IN lt_purchasing
                     GROUP BY ( material_number = <purchasing>-material_number )
                   ( VALUE #( sign = 'I' option = 'EQ' low = purchasing_grp-material_number ) ) ).
                    SELECT matnr, meins
                      FROM mara
                     WHERE matnr IN @ltr_material
                      INTO TABLE @DATA(ltr_mara).
                      
cl_demo_output=>display_data( ltr_material ).
                      

Tags:

Comments are closed