Sapscript – Local class to easily manage data in performs

Sapscript – Local class to easily manage data in performs

Local class :


TYPES : ti_itcsy TYPE STANDARD TABLE OF itcsy WITH DEFAULT KEY.

CLASS lcl_sapscript DEFINITION.
*------------------------------
* Public section
*------------------------------
  PUBLIC SECTION.
    CLASS-METHODS init_tables IMPORTING input_table  TYPE ti_itcsy
                                        output_table TYPE ti_itcsy.
    CLASS-METHODS get_input_value IMPORTING iv_field        TYPE tdtprgname
                                  RETURNING VALUE(rv_value) TYPE tdsymvalue.
    CLASS-METHODS get_output_table RETURNING VALUE(rt_output) TYPE ti_itcsy.
    CLASS-METHODS set_output_value IMPORTING iv_field         TYPE tdtprgname
                                             iv_value         TYPE tdsymvalue
                                   RETURNING VALUE(rt_output) TYPE ti_itcsy.
  PRIVATE SECTION.
    CLASS-DATA : it_static_tbl_input  TYPE ti_itcsy,
                 it_static_tbl_output TYPE ti_itcsy.
ENDCLASS.

CLASS lcl_sapscript IMPLEMENTATION.
  METHOD init_tables.
    CLEAR : it_static_tbl_input, it_static_tbl_output.
    it_static_tbl_input = input_table.
    it_static_tbl_output = output_table.
  ENDMETHOD.
  METHOD get_input_value.
    READ TABLE it_static_tbl_input INTO DATA(ls_table) WITH KEY name = iv_field.
    IF sy-subrc = 0.
      rv_value = ls_table-value.
    ENDIF.
  ENDMETHOD.
  METHOD set_output_value.
    READ TABLE it_static_tbl_output ASSIGNING FIELD-SYMBOL(<fs_output>) WITH KEY name = iv_field.
    IF sy-subrc = 0.
      <fs_output>-value = iv_value.
    ENDIF.
    rt_output = it_static_tbl_output.
  ENDMETHOD.
  METHOD get_output_table.
    rt_output = it_static_tbl_output.
  ENDMETHOD.
ENDCLASS.

Example of use :


FORM get_head_infos TABLES input output.

  DATA : ls_ltak    TYPE ltak,
         lv_val_ext TYPE char10.
		 " [...]
		 
  " A appeler à chaque début de forms
  lcl_sapscript=>init_tables( input_table  = input[]
                              output_table = output[] ).

  DATA(lv_lgnum) = lcl_sapscript=>get_input_value( 'LTAK-LGNUM' ).
  DATA(lv_tanum) = lcl_sapscript=>get_input_value( 'LTAK-TANUM' ).

  ls_ltak-betyp  = lcl_sapscript=>get_input_value( 'LTAK-BETYP' ).
  ls_ltak-bname  = lcl_sapscript=>get_input_value( 'LTAK-BNAME' ).
  ls_ltak-bzeit  = lcl_sapscript=>get_input_value( 'LTAK-BZEIT' ).

  ls_ltak-vbeln = lcl_sapscript=>get_input_value( 'LTAK-VBELN' ).
  ls_ltak-vbeln = |{ ls_ltak-vbeln ALPHA = IN }|.

  lv_val_ext     = lcl_sapscript=>get_input_value( 'LTAK-BDATU' ).
  ls_ltak-bdatu  = |{ lv_val_ext+6(4) }{ lv_val_ext+3(2) }{ lv_val_ext(2) }|.



  " Treat data
  " ----------
  
  " [...]
  
  " Return data
  " -----------
  
    lcl_sapscript=>set_output_value( iv_field = 'V_LABEL_REF'
                                     iv_value = 'Ref:'(001)  ).


    lcl_sapscript=>set_output_value( iv_field = 'V_LABEL_CDE'
                                     iv_value = 'N° CDE'(002)  ).

    lcl_sapscript=>set_output_value( iv_field = 'V_COMMANDE'
                                     iv_value = |{ ls_lips-vgbel ALPHA = OUT }|  ).


    lcl_sapscript=>set_output_value( iv_field = 'V_LABEL_CDE'
                                     iv_value = 'Besoin'(l02)  ).

    lcl_sapscript=>set_output_value( iv_field = 'V_COMMANDE'
                                     iv_value = |{ ls_ltak-benum ALPHA = OUT }|  ).



  " Repasser les infos en sortie
  output[] = lcl_sapscript=>get_output_table( ).

ENDFORM. " GET_HEAD_INFOS

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

Leave a Reply