Monday 29 April 2019

Hybrid Programming – OOP ALV CDS Fiori

I haven’t been on here in awhile. But today I was looking out my window in April in Michigan at the snow.  For those of you reading it not thinking that is a big deal. It’s been since the 1800s since we’ve gotten snow this late in April. And yes, I’m inside looking at that snow.  Take a look at the ground – yes lovely green grass and my pine tree looks happy.  It’s a bit of a hybrid out there spring and winter on the ground.

SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Study Materials, SAP ABAP Learning

So I’m learning.  Yes, never stop learning. But I’m trying to cram as much information into my brain as possible. Then I remind myself when I started with SAP – I was cramming then too.  Anyway, while cramming things into my brain, I still have due dates.  So being me, I want to use the newer stuff.  So I have been taking a hybrid approach. Perhaps not the best way, but it’s been what I can do.

We have HANA on-premise.  What makes this important is we still can use older techniques and then simply call them from FIORI.  In a pinch I can use all old programming.  I thought I’d give an example of my “Hybrid” programming.  OOP ALV has been my friend for a long time.  It’s so easy to use to present information.

So here are some bits and pieces of my program. (Watch me go back and fourth to Eclipse, I’ll eventually learn all the short cuts there, but haven’t yet.  My piece of wisdom for you – learn Eciplse as soon as possible.

The Requirement:

A way to pull together ingredient contracts and the sales order relating to them.  Next if they are checked, remove them from the balance.  Yes, the simple requirements usually end up being a problem.  <Laughing>

Part 1 – getting the data. For this I got to use some of the new “stuff”! Yes, I used Eclipse.

   INTERFACES: if_amdp_marker_hdb.

    CLASS-METHODS get_so_co_detail
      IMPORTING
        VALUE(iv_where)  TYPE string
        VALUE(iv_client) TYPE mandt
      EXPORTING
        VALUE(et_log)    TYPE ztt_ingrd_all.

 METHOD get_so_co_detail BY DATABASE PROCEDURE
                                 FOR HDB
                                 LANGUAGE SQLSCRIPT
                                 OPTIONS READ-ONLY
                                 USING   vbak vbap
                                 vbkd vbep tvagt
                                 vbpa kna1.

    tmp1 = apply_filter( vbap, :iv_where);

     et_log = select
            a.MANDT,
            a.VBELN ,
            b.POSNR,
            b.matnr,
              case
                 when b.gbsta = 'A'
                  then 'Open'
                when b.gbsta= 'B'
                   then 'Open'
                  when b.gbsta = 'C'
                     then 'Closed'
               end as stat,
           c.bezei as rej,
           concat( b.werks, concat( '/', b.lgort ) ) as werk_sloc,
           b.ERDAT,
           a.VKORG,
           b.ERNAM,
           vbep.EDATU,
           b.KWMENG,
           b.VRKME,
           vbkd.BSTKD,
           ship.kunnr as shipto,
           kna1.name1 as shipto_name,
           kna1.ORT01 as city,
           kna1.regio as region,
           merch.kunnr as merch,
           z2_kna1.name1 as merch_name,
           a.kunnr as soldto,
           soldto.name1 as soldto_name
           from
             :tmp1 as b

           inner join vbak as a on a.vbeln = b.vbeln

           left outer join tvagt as c
               on b.abgru = c.abgru and
                  c.spras = 'E'

             left outer join vbep as vbep
                 on b.vbeln = vbep.vbeln and
                    b.posnr = vbep.posnr and
                    vbep.bmeng > 0

             left outer join vbkd as vbkd
                  on b.vbeln = vbkd.vbeln and
                     vbkd.posnr = '000000'

             left outer join vbpa as ship
              on a.vbeln = ship.vbeln and
                 ship.posnr = '000000' and
                 ship.parvw = 'WE'

            left outer join kna1 as kna1
                 on ship.kunnr = kna1.kunnr

            left outer join vbpa as merch
              on a.vbeln = merch.vbeln and
                 b.posnr = merch.posnr and
                 merch.parvw = 'Z2'

           left outer join kna1 as z2_kna1
               on merch.kunnr = z2_kna1.kunnr


            left outer join kna1 as soldto
                 on a.kunnr = soldto.kunnr
                     ;

  ENDMETHOD.

For those of you wondering if you can use new and old methods – yes you can. You can only change them in Eclipse.

  method fill_dates.
    data: lv_from        type dats,
          lv_to          type dats,
          lv_one(10),
          lv_between(30).

    lv_from = im_from.
    lv_to = im_to.
*  Explode BOM
        CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
          EXPORTING
            auskz                 = abap_true
            brems                 = abap_true
            capid                 = 'PP01'
            datuv                 = sy-datlo    " Valid-From Date
            mktls                 = abap_true
            mehrs                 = abap_true
            mtnrv                 = ls_stko-matnr
            stlal                 = ls_stko-stlal
            stlan                 = ls_stko-stlan
            werks                 = ls_stko-werks
          TABLES
            stb                   = lt_stb

So yes – a bit of a hybrid there.  Now we can take a peak at how I called them.

* CONVERT the SELECTION to where clause
  DATA(lv_where) = cl_shdb_seltab=>combine_seltabs(
   it_named_seltabs = VALUE #(
    ( name = 'VBELN'      dref = REF #( s_vbeln[] ) )
    ( name = 'POSNR'      dref = REF #( s_item[] ) )
    )
  iv_client_field = 'MANDT'
    ).

* Get contract details
  TRY.
      zcl_get_ingred_log=>get_so_co_detail(
      EXPORTING
          iv_where = lv_where
          iv_client = sy-mandt
      IMPORTING
          et_log = DATA(lt_result) ).
    CATCH cx_amdp_error INTO DATA(amdp_error).
      cl_demo_output=>display( amdp_error->get_text( ) ).
      RETURN.
  ENDTRY.

OK, we’ve got our data – yes – not my total program.  But just snippets.  The fun part of my ALV – not the entire thing.

   gs_variant-report = sy-repid.
    DATA: it_fieldcat TYPE lvc_t_fcat,
          x_fieldcat  TYPE lvc_s_fcat.
    x_fieldcat-col_pos = 1.
    x_fieldcat-seltext = 'APPLIED'.
    x_fieldcat-fieldname = 'APPLIED'.
    x_fieldcat-edit = abap_true.
    x_fieldcat-checkbox = abap_true.
    x_fieldcat-tabname = 'GT_SALES_DETAIL'.
    APPEND x_fieldcat TO it_fieldcat.

 CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_bypassing_buffer   = abap_true
        i_structure_name     = 'ZINGRD_CONTRACT'
        is_print             = gs_print
        is_layout            = gs_layout
        it_toolbar_excluding = lt_exc
        i_save               = gv_save
        is_variant           = gs_variant
      CHANGING
        it_fieldcatalog      = it_fieldcat
        it_outtab            = gt_sales_detail.
    gv_check = abap_true.

    CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid1.

Last thing to do is to create the FIORI tile. Yes a lot different than normal.Security is based a lot on where you place your tile. You will want to download the Step by Step guide to do this.  And since it is amazing, I won’t share the step by step here.

So my lovely FIORI report.  Yes, you can’t see much of it.  Just the headings. Why? No company information.

SAP ABAP Tutorials and Materials, SAP ABAP Guides, SAP ABAP Study Materials, SAP ABAP Learning

That’s my hybrid approach. Now a challenge for you.

No comments:

Post a Comment